Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT')
-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.java109
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java3595
-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.java320
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderEvent.java86
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderListener.java45
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PaletteData.java213
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PathData.java32
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java107
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java224
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java345
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java77
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java197
-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.java251
-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.java604
-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.java6360
-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.java1876
-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.java182
-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.java573
-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
-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.java672
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java324
-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.java235
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormAttachment.java300
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormData.java343
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormLayout.java383
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java561
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java742
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowData.java124
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java467
-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/widgets/Dialog.java249
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java219
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java136
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java184
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Layout.java103
-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.java84
-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.java183
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Tray.java146
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java239
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/package.html16
-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.java420
-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.java337
-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.properties73
-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.java106
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolBar.java1184
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolItem.java650
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandBar.java566
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandItem.java389
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Path.java358
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Pattern.java173
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Transform.java305
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabFolder.java1194
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabItem.java422
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/textlayout/org/eclipse/swt/graphics/TextLayout.java1720
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/tooltip/org/eclipse/swt/widgets/ToolTip.java614
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/tray/org/eclipse/swt/widgets/TrayItem.java279
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Table.java4035
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableColumn.java739
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableItem.java1965
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Tree.java4126
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeColumn.java715
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeItem.java2878
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java299
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java457
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java831
-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.java291
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java429
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java132
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java3652
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java53
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java1188
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java590
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java1692
-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.java756
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java332
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java496
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java157
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java1674
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java1282
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java3717
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java750
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java284
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java3819
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java705
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java601
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java514
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java220
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java288
-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.java570
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java717
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java1539
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java933
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java870
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java191
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java243
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java428
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java372
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java700
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java372
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java1691
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java568
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java1068
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java686
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java341
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java3321
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java658
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java1193
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java1956
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java452
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java1039
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java759
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java963
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java448
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java3091
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java643
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java1582
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java1478
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java349
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java438
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java937
-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.java532
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java647
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java122
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java4244
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java59
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java1441
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java569
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/TextLayout.java1767
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java404
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java804
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java285
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java475
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java462
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java1630
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java1496
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java3308
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java795
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java342
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java3706
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java570
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java1172
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java343
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java632
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Link.java670
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java1564
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java887
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java980
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java420
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java374
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java440
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java380
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java701
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java360
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java1863
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java537
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Spinner.java930
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java1586
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java512
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java1151
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java962
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java1222
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Color.java249
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Cursor.java461
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Device.java589
-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.java276
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontData.java455
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontMetrics.java173
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GC.java3441
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GCData.java44
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Image.java1064
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Region.java646
-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.java605
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Canvas.java264
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Caret.java497
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ColorDialog.java147
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Combo.java1348
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Composite.java1131
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Control.java2853
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Decorations.java632
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/DirectoryDialog.java172
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java2659
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FileDialog.java290
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FontDialog.java207
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Group.java219
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java453
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Link.java674
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/List.java1256
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Menu.java818
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java915
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MessageBox.java205
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ProgressBar.java242
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Sash.java409
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scale.java373
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ScrollBar.java722
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scrollable.java242
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java1290
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Slider.java555
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Spinner.java732
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabFolder.java712
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabItem.java306
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Text.java1532
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java485
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolItem.java954
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Tracker.java1047
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Widget.java1243
-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.java336
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java474
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java819
-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.java263
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontData.java646
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java182
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java4437
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java48
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java2086
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Path.java497
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java226
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java605
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java2221
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java316
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/BidiUtil.java652
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java1117
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java338
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java554
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java218
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java2289
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java1485
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java4148
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java1189
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java714
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java1759
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DirectoryDialog.java305
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java4076
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java762
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java487
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FileDialog.java443
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java287
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Group.java411
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ImageList.java427
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java674
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Link.java929
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java1542
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java1362
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java1168
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MessageBox.java247
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java366
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java417
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java500
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java904
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java407
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java2128
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java784
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Spinner.java1343
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java933
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabItem.java331
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java5519
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java850
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java1143
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java2160
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java1341
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java955
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java540
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java1077
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TrayItem.java469
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java6407
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java749
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java1580
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java2347
325 files changed, 0 insertions, 254980 deletions
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 ec64415ea7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Drawable.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 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 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 c40e34bba1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/GlyphMetrics.java
+++ /dev/null
@@ -1,109 +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 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
- *
- * @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.
- *
- * @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 da358c2679..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java
+++ /dev/null
@@ -1,3595 +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.*;
-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
- */
-
-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 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 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 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;
- 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.
- *
- * @param x the x coodinate 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>.
- *
- * @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.
- *
- * @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>.
- *
- * @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;
- }
- /*** 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;
-
- // 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 a1d5d8e1b7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java
+++ /dev/null
@@ -1,320 +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.*;
-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>
- */
-
-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 23d7f4c9e6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderEvent.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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
- */
-
-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 874977194e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderListener.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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/PaletteData.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PaletteData.java
deleted file mode 100755
index 8c63995d1e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PaletteData.java
+++ /dev/null
@@ -1,213 +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.*;
-
-/**
- * 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
- */
-
-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 b4938ec027..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PathData.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.graphics;
-
-
-/**
- * Instances of this class describe device-independent paths.
- *
- * @see Path
- *
- * @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 765c6eafe1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java
+++ /dev/null
@@ -1,107 +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.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
- */
-
-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 ab1fff0c94..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java
+++ /dev/null
@@ -1,224 +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.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
- */
-
-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 9892b24252..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java
+++ /dev/null
@@ -1,345 +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.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
- */
-
-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 b3d91ba0b3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java
+++ /dev/null
@@ -1,77 +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.*;
-
-/**
- * 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
- *
- * @since 3.1
- */
-public abstract class Resource {
-
- /**
- * the device where this resource was created
- */
- Device device;
-
-/**
- * Disposes of the operating system resources associated with
- * this resource. Applications must dispose of all resources
- * which they allocate.
- */
-public abstract void dispose();
-
-/**
- * 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;
-}
-
-/**
- * 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 56f6fbd271..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/TextStyle.java
+++ /dev/null
@@ -1,197 +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 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
- *
- * @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
- *
- * @since 3.1
- */
- public boolean underline;
-
- /**
- * the strikeout flag of the style
- *
- * @since 3.1
- */
- public boolean strikeout;
-
- /**
- * the GlyphMetrics of the style
- *
- * @since 3.2
- */
- public GlyphMetrics metrics;
-
- /**
- * the baseline rise of the style.
- *
- * @since 3.2
- */
- public int rise;
-
-/**
- * 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;
-}
-
-/**
- * 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 (strikeout != style.strikeout) return false;
- if (rise != style.rise) 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;
- return hash;
-}
-
-/**
- * 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 {");
- int startLength = buffer.length();
- if (font != null) {
- if (buffer.length() > startLength) buffer.append(", ");
- buffer.append("font=");
- buffer.append(font);
- }
- if (foreground != null) {
- if (buffer.length() > startLength) buffer.append(", ");
- buffer.append("foreground=");
- buffer.append(foreground);
- }
- if (background != null) {
- if (buffer.length() > startLength) buffer.append(", ");
- buffer.append("background=");
- buffer.append(background);
- }
- if (underline) {
- if (buffer.length() > startLength) buffer.append(", ");
- buffer.append("underlined");
- }
- if (strikeout) {
- if (buffer.length() > startLength) buffer.append(", ");
- buffer.append("striked out");
- }
- if (rise != 0) {
- if (buffer.length() > startLength) buffer.append(", ");
- buffer.append("rise=");
- buffer.append(rise);
- }
- if (metrics != null) {
- if (buffer.length() > startLength) buffer.append(", ");
- buffer.append("metrics=");
- buffer.append(metrics);
- }
- buffer.append("}");
- 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 145d49c2f5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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;
-
- /* Load the SWT library */
- static {
- Library.loadLibrary ("swt"); //$NON-NLS-1$
- }
-
- static final int PTR_SIZEOF = PTR_sizeof();
- static final String PTR_SIGNATURE = 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);
-}
-
-static final native int PTR_sizeof ();
-
-/**
- * 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 22273cfc74..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java
+++ /dev/null
@@ -1,604 +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 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 new String(signature).equals("GIF"); //$NON-NLS-1$
- } 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[] signatureBytes = new byte[3];
- byte[] versionBytes = new byte[3];
- byte[] block = new byte[7];
- try {
- inputStream.read(signatureBytes);
- signature = new String(signatureBytes);
- if (!signature.equals("GIF")) //$NON-NLS-1$
- 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 size of block = 0x0B.
- inputStream.read();
- // Read application identifier.
- byte[] applicationBytes = new byte[8];
- inputStream.read(applicationBytes);
- String application = new String(applicationBytes);
- // Read authentication code.
- byte[] authenticationBytes = new byte[3];
- inputStream.read(authenticationBytes);
- String authentication = new String(authenticationBytes);
- // 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.
- if (application.equals("NETSCAPE") && authentication.equals("2.0") && 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 5c54492537..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 fb4b9a305f..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 dfb5c0f8b9..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 1ecfff9636..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGDecoder.java
+++ /dev/null
@@ -1,6360 +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.*;
-
-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:
- if (RGB_PIXELSIZE != 3) {
- cinfo.out_color_components = RGB_PIXELSIZE;
- break;
- }
- //FALLTHROUGH
- 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 && RGB_PIXELSIZE == 3) {
- 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, 0, Math.min(cinfo.buffer.length, inputStream.available()));
- 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 df40f1febe..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 94825bcc54..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java
+++ /dev/null
@@ -1,1876 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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.*;
-
-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 int[] CrRTable, CbBTable, CrGTable, CbGTable;
- public static int[] RYTable, GYTable, BYTable,
- RCbTable, GCbTable, BCbTable, RCrTable, GCrTable, BCrTable, NBitsTable;
- static {
- initialize();
- }
-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 - 1] & 0xFF;
- for (int i = 0; i < delta; i++) {
- imageComponent[dstOfs + i] = (byte)dataValue;
- }
- }
- }
- if (compressedHeight < componentHeight) {
- int srcOfs = (compressedHeight - 1) * componentWidth;
- for (int yPos = compressedHeight; 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();
-}
-static void initialize() {
- initializeRGBYCbCrTables();
- initializeYCbCrRGBTables();
- initializeBitCountTable();
-}
-static void initializeBitCountTable() {
- int nBits = 1;
- int power2 = 2;
- NBitsTable = new int[2048];
- NBitsTable[0] = 0;
- for (int i = 1; i < NBitsTable.length; i++) {
- if (!(i < power2)) {
- nBits++;
- power2 *= 2;
- }
- NBitsTable[i] = nBits;
- }
-}
-static void initializeRGBYCbCrTables() {
- RYTable = new int[256];
- GYTable = new int[256];
- BYTable = new int[256];
- RCbTable = new int[256];
- GCbTable = new int[256];
- BCbTable = new int[256];
- RCrTable = BCbTable;
- GCrTable = new int[256];
- 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;
- }
-}
-static void initializeYCbCrRGBTables() {
- CrRTable = new int[256];
- CbBTable = new int[256];
- CrGTable = new int[256];
- 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;
- }
-}
-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 9fea253c8c..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 bd722fe488..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 3d1b733684..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 fde151a5dd..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 a8052f32bc..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 7bef3b6da1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataInputStream.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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();
- position++;
- if (pos < buf.length) return (buf[pos++] & 0xFF);
- return in.read();
- }
-
- /**
- * 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) << 8) |
- (buf[2] & 0xFF)) << 8) |
- (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 e24bff1fee..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 e0af60781e..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, 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 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 205d585d2b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java
+++ /dev/null
@@ -1,573 +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.*;
-import org.eclipse.swt.internal.*;
-
-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) {
- /* We do not currently support writing png. */
- SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
-}
-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);
- 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 = new BufferedInputStream(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 15f4777990..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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/PngFileReadState.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngFileReadState.java
deleted file mode 100755
index 3ad40e06c6..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, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 655c78541a..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, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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];
-}
-
-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 09bd04ef3d..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 d05db3742d..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, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 770b34d40f..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, 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.*;
-
-/**
- * Baseline TIFF decoder revision 6.0
- * Extension T4-encoding CCITT T.4 1D
- */
-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 6a62184b43..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 3d00cdb5ae..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 0a8b8cc656..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java
+++ /dev/null
@@ -1,672 +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 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);
- 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) { // 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);
- int bitCount = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 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);
- this.compression = (infoHeader[16] & 0xFF) | ((infoHeader[17] & 0xFF) << 8) | ((infoHeader[18] & 0xFF) << 16) | ((infoHeader[19] & 0xFF) << 24);
- 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) return new PaletteData(0x7C00, 0x3E0, 0x1F);
- if (depth == 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 += 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 ae06872947..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java
+++ /dev/null
@@ -1,324 +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 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);
- 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 ff395846c3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java
+++ /dev/null
@@ -1,235 +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.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>
- */
-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 b57c16b689..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormAttachment.java
+++ /dev/null
@@ -1,300 +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.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
- *
- * @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>TOP: Attach the side to the top side of the specified control.</li>
- * <li>BOTTOM : Attach the side to the bottom side of the specified control.</li>
- * <li>LEFT: Attach the side to the left side of the specified control.</li>
- * <li>RIGHT: Attach the side to the right side of the specified control.</li>
- * <li>CENTER: Attach the side at a position which will center the control on the specified control.</li>
- * <li>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.
- *
- * @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
- */
-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 2484534eff..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormData.java
+++ /dev/null
@@ -1,343 +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.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
- *
- * @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 ae93112212..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormLayout.java
+++ /dev/null
@@ -1,383 +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.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
- *
- * @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 attatched 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). Similarily, 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 001463c22f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java
+++ /dev/null
@@ -1,561 +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.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
- */
-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
- * @param verticalAlignment how control will be positioned vertically within a cell
- * @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
- * @param verticalAlignment how control will be positioned vertically within a cell
- * @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 c0785bb75a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java
+++ /dev/null
@@ -1,742 +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.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
- */
-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 postion 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 postion 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 2ecf5d1298..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowData.java
+++ /dev/null
@@ -1,124 +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.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
- */
-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 c2a1a9cd55..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java
+++ /dev/null
@@ -1,467 +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.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
- */
-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;
-
- /**
- * 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)) {
- 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)) wraps [i - 1] = maxHeight;
- x = marginLeft + marginWidth;
- y += spacing + maxHeight;
- if (pack) maxHeight = 0;
- }
- if (pack || fill) {
- maxHeight = Math.max (maxHeight, childHeight);
- }
- if (move) {
- int childX = x + clientX, childY = y + clientY;
- if (justify || fill) {
- 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)) {
- 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) {
- 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];
- }
- 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;
- }
- 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)) {
- 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)) wraps [i - 1] = maxWidth;
- x += spacing + maxWidth;
- y = marginTop + marginHeight;
- if (pack) maxWidth = 0;
- }
- if (pack || fill) {
- maxWidth = Math.max (maxWidth, childWidth);
- }
- if (move) {
- int childX = x + clientX, childY = y + clientY;
- if (justify || fill) {
- 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)) {
- 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) {
- 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];
- }
- 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;
- }
- 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/widgets/Dialog.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Dialog.java
deleted file mode 100755
index 4e5ef574ed..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Dialog.java
+++ /dev/null
@@ -1,249 +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.*;
-
-/**
- * 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</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
- */
-
-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 ();
-}
-
-/**
- * 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 c7759e5975..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java
+++ /dev/null
@@ -1,219 +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.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
- */
-
-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 which are pending which may always be zero
- * on some platforms or the number of lines or pages to
- * scroll using the mouse wheel
- */
- 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 has no effect.
- */
- 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 25f0202be4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java
+++ /dev/null
@@ -1,136 +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.*;
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Instances of this class implement a simple
- * look up mechanism that maps an event type
- * to a listener. Muliple listeners for the
- * same event type are supported.
- */
-
-class EventTable {
- int [] types;
- Listener [] listeners;
- int level;
-
-public void hook (int eventType, Listener listener) {
- if (types == null) types = new int [4];
- if (listeners == null) listeners = new Listener [4];
- 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 + 4];
- System.arraycopy (types, 0, newTypes, 0, length);
- types = newTypes;
- Listener [] newListeners = new Listener [length + 4];
- 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 ba35a80166..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java
+++ /dev/null
@@ -1,184 +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.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>
- */
-
-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 2006733446..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Layout.java
+++ /dev/null
@@ -1,103 +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.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)
- */
-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 aa29db1ab1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Monitor.java
+++ /dev/null
@@ -1,84 +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.graphics.*;
-
-/**
- * Instances of this class are descriptions of monitors.
- *
- * @see Display
- *
- * @since 3.0
- */
-public final class Monitor {
- int 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.
- *
- * @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 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 cbd4e58328..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/RunnableLock.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, 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 asynchonous 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 da7707081b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Synchronizer.java
+++ /dev/null
@@ -1,183 +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.*;
-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
- */
-public class Synchronizer {
- Display display;
- int messageCount;
- RunnableLock [] messages;
- Object messageLock = new Object ();
- Thread syncThread;
-
-/**
- * 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 [4];
- if (messageCount == messages.length) {
- RunnableLock[] newMessages = new RunnableLock [messageCount + 4];
- 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) {
- 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 > 64) 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 occured when executing the runnable</li>
- * </ul>
- *
- * @see #asyncExec
- */
-protected void syncExec (Runnable runnable) {
- if (display.isValidThread ()) {
- if (runnable != null) runnable.run ();
- return;
- }
- if (runnable == null) {
- display.wake ();
- return;
- }
- RunnableLock lock = new RunnableLock (runnable);
- /*
- * Only remember the syncThread for syncExec.
- */
- lock.thread = Thread.currentThread();
- synchronized (lock) {
- addLast (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 b0dd6e7c06..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Tray.java
+++ /dev/null
@@ -1,146 +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.*;
-
-/**
- * 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
- *
- * @since 3.0
- */
-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 58851a82a4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java
+++ /dev/null
@@ -1,239 +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.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
- */
-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.Paint: {
- /* Field set by Control */
- PaintEvent event = new PaintEvent (e);
- ((PaintListener) eventListener).paintControl (event);
- e.gc = event.gc;
- 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.DefaultSelection: {
- ((SelectionListener)eventListener).widgetDefaultSelected(new SelectionEvent(e));
- break;
- }
- case SWT.Dispose: {
- ((DisposeListener) eventListener).widgetDisposed(new DisposeEvent(e));
- break;
- }
- case SWT.FocusIn: {
- ((FocusListener) eventListener).focusGained(new FocusEvent(e));
- break;
- }
- case SWT.FocusOut: {
- ((FocusListener) eventListener).focusLost(new FocusEvent(e));
- break;
- }
- case SWT.Hide: {
- ((MenuListener) eventListener).menuHidden(new MenuEvent(e));
- break;
- }
- case SWT.Show: {
- ((MenuListener) eventListener).menuShown(new MenuEvent(e));
- break;
- }
- case SWT.KeyDown: {
- KeyEvent event = new KeyEvent(e);
- ((KeyListener) eventListener).keyPressed(event);
- e.doit = event.doit;
- break;
- }
- case SWT.KeyUp: {
- KeyEvent event = new KeyEvent(e);
- ((KeyListener) eventListener).keyReleased(event);
- e.doit = event.doit;
- break;
- }
- case SWT.MouseDown: {
- ((MouseListener) eventListener).mouseDown(new MouseEvent(e));
- break;
- }
- case SWT.MouseUp: {
- ((MouseListener) eventListener).mouseUp(new MouseEvent(e));
- break;
- }
- case SWT.MouseDoubleClick: {
- ((MouseListener) eventListener).mouseDoubleClick(new MouseEvent(e));
- break;
- }
- case SWT.MouseMove: {
- ((MouseMoveListener) eventListener).mouseMove(new MouseEvent(e));
- return;
- }
- case SWT.Resize: {
- ((ControlListener) eventListener).controlResized(new ControlEvent(e));
- break;
- }
- case SWT.Move: {
- ((ControlListener) eventListener).controlMoved(new ControlEvent(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.Activate: {
- ((ShellListener) eventListener).shellActivated(new ShellEvent(e));
- break;
- }
- case SWT.Deactivate: {
- ((ShellListener) eventListener).shellDeactivated(new ShellEvent(e));
- break;
- }
- case SWT.Iconify: {
- ((ShellListener) eventListener).shellIconified(new ShellEvent(e));
- break;
- }
- case SWT.Deiconify: {
- ((ShellListener) eventListener).shellDeiconified(new ShellEvent(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.Collapse: {
- if (eventListener instanceof TreeListener) {
- ((TreeListener) eventListener).treeCollapsed(new TreeEvent(e));
- } else {
- ((ExpandListener) eventListener).itemCollapsed(new ExpandEvent(e));
- }
- break;
- }
- case SWT.Modify: {
- ((ModifyListener) eventListener).modifyText(new ModifyEvent(e));
- 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;
- }
- case SWT.Help: {
- ((HelpListener) eventListener).helpRequested (new HelpEvent (e));
- break;
- }
- case SWT.Arm: {
- ((ArmListener) eventListener).widgetArmed (new ArmEvent (e));
- break;
- }
- case SWT.MouseExit: {
- ((MouseTrackListener) eventListener).mouseExit (new MouseEvent (e));
- break;
- }
- case SWT.MouseEnter: {
- ((MouseTrackListener) eventListener).mouseEnter (new MouseEvent (e));
- break;
- }
- case SWT.MouseHover: {
- ((MouseTrackListener) eventListener).mouseHover (new MouseEvent (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;
- }
-
- }
-}
-
-}
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_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 b5d5d099cb..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 03d1564be8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/Compatibility.java
+++ /dev/null
@@ -1,420 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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;
-}
-
-/**
- * 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.2.1
- */
-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();
-}
-
-/**
- * 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 57d3f28df2..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 f3b73ca805..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 a2d8245c9c..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 78e939108f..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 226794e42e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/Compatibility.java
+++ /dev/null
@@ -1,337 +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.*;
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.zip.InflaterInputStream;
-
-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 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;
-}
-
-/**
- * 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.2.1
- */
-public static InputStream newInflaterInputStream(InputStream stream) throws IOException {
- return 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 f7036a3eb5..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 92ba54f11d..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, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 e7fdf88e62..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages.properties
+++ /dev/null
@@ -1,73 +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
-###############################################################################
-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_Selection=Selection
-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
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 dd5e66ae4f..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, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 5a92bd5458..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/bidi/org/eclipse/swt/internal/BidiUtil.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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;
-
-/*
- * 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) {
-}
-/*
- * 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) {
-}
-/*
- * Not implemented.
- */
-public static void setKeyboardLanguage(int language) {
-}
-/*
- * Not implemented.
- */
-public static boolean setOrientation(int /*long*/ hwnd, 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 fc63ba4fce..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolBar.java
+++ /dev/null
@@ -1,1184 +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.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>
- */
-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 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);
- }
-}
-private 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;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- Rectangle trim = computeTrim(0, 0, width, height);
- return fixPoint(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.
- */
-void insertItemIntoRow(CoolItem item, int rowIndex, int x_root) {
- int barWidth = getWidth();
- int rowY = items[rowIndex][0].internalGetBounds().y;
- int x = Math.max(0, 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.internalGetBounds().height;
- 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);
- }
- Rectangle bounds = item.internalGetBounds();
- item.requestedWidth = bounds.width;
- internalRedraw(bounds.x, bounds.y, item.internalGetMinimumWidth(), bounds.height);
-}
-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;
- boolean resize = false;
- if (items[oldRowIndex].length == 1) {
- resize = true;
- /* 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;
- removeItemFromRow(item, oldRowIndex, false);
- Rectangle old = item.internalGetBounds();
- internalRedraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height);
- if (newRowIndex == items.length) {
- /* Create a new bottom row for the item. */
- CoolItem[][] newRows = new CoolItem[items.length + 1][];
- System.arraycopy(items, 0, newRows, 0, items.length);
- int row = items.length;
- newRows[row] = new CoolItem[1];
- newRows[row][0] = item;
- items = newRows;
- resize = true;
- item.wrap = true;
- } else {
- 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;
- boolean resize = false;
- if (items[oldRowIndex].length == 1) {
- resize = true;
- /* If this is the only item in the top row, don't move it. */
- if (oldRowIndex == 0) return;
- }
- removeItemFromRow(item, oldRowIndex, false);
- Rectangle old = item.internalGetBounds();
- internalRedraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height);
- int newRowIndex = Math.max(0, oldRowIndex - 1);
- if (oldRowIndex == 0) {
- /* Create a new top row for the item. */
- CoolItem[][] newRows = new CoolItem[items.length + 1][];
- System.arraycopy(items, 0, newRows, 1, items.length);
- newRows[0] = new CoolItem[1];
- newRows[0][0] = item;
- items = newRows;
- resize = true;
- item.wrap = true;
- } else {
- 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, event.y)).x - itemXOffset;
- 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) {
- _setCursor(null);
- dragging = 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.
- */
-void removeItemFromRow(CoolItem item, int rowIndex, boolean disposed) {
- int index = findItem(item).x;
- int newLength = items[rowIndex].length - 1;
- Rectangle itemBounds = item.internalGetBounds();
- 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;
- }
- 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;
- }
- }
-}
-/**
- * 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.internalGetBounds().height);
- 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 a22672aa1e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolItem.java
+++ /dev/null
@@ -1,650 +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.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>
- */
-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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
- 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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;
- }
- 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/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 ace81d82ee..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandBar.java
+++ /dev/null
@@ -1,566 +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.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
- *
- * @since 3.2
- */
-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 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.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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) {
- 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) {
- int x = event.x;
- int y = event.y;
- if (focusItem == null) return;
- 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 0eb7947d25..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/expand/org/eclipse/swt/widgets/ExpandItem.java
+++ /dev/null
@@ -1,389 +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.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
- *
- * @since 3.2
- */
-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 7a9a24e823..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Path.java
+++ /dev/null
@@ -1,358 +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 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>
- *
- * @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.
- *
- * @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 SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained/li>
- * </ul>
- *
- * @see #dispose()
- */
-public Path (Device device) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- SWT.error(SWT.ERROR_NO_GRAPHICS_LIBRARY);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the Path. Applications must dispose of all Paths that
- * they allocate.
- */
-public void dispose() {
- if (handle == 0) return;
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = null;
-}
-
-/**
- * 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 206a67c1cd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Pattern.java
+++ /dev/null
@@ -1,173 +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 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>
- *
- * @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.
- *
- * @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 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.device = device;
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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.
- *
- * @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 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.
- *
- * @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 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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 = device;
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the Pattern. Applications must dispose of all Patterns that
- * they allocate.
- */
-public void dispose() {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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 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 e8c624a64d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/graphics/org/eclipse/swt/graphics/Transform.java
+++ /dev/null
@@ -1,305 +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 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>
- *
- * @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.
- *
- * @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 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.
- *
- * @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 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.
- *
- * @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 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- SWT.error(SWT.ERROR_NO_GRAPHICS_LIBRARY);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
-
-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.
- */
-public void dispose() {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * 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 invertable</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);
-}
-
-/**
- * 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/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 0afd01173e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,1194 +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.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>
- */
-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 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 receiver's selection changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 -= xClient + CLIENT_MARGIN_WIDTH + 1;
- 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 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 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(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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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) {
-
- 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 19c8d87c02..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,422 +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.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>
- */
-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;
- }
-}
-/**
- * Return the bounds of the TabItem.
- */
-Rectangle getBounds () {
- 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);
- if (index != parent.getSelectionIndex ()) {
- if (newControl != null) 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 no tool tip text should be shown.
- *
- * @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 7f6a8fb4e7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/textlayout/org/eclipse/swt/graphics/TextLayout.java
+++ /dev/null
@@ -1,1720 +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 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>
- *
- * @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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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$
- if (device.tracking) device.new_Object(this);
-}
-
-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();
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the text layout. Applications must dispose of all allocated text layouts.
- */
-public void dispose () {
- if (device == null) return;
- freeRuns();
- font = null;
- text = null;
- tabs = null;
- styles = null;
- lineOffset = null;
- lineY = null;
- lineWidth = null;
- if (device.tracking) device.dispose_Object(this);
- device = 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) {
- 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.
- *
- * @return the bounds of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-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 charecter 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> or <code>SWT.MOVEMENT_WORD</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>.
- *
- * @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);
- if (this.font == font) return;
- if (font != null && font.equals(this.font)) return;
- freeRuns();
- this.font = font;
-}
-
-/**
- * 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.
- *
- * @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 90702f093a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tooltip/org/eclipse/swt/widgets/ToolTip.java
+++ /dev/null
@@ -1,614 +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.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>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @since 3.2
- */
-public class ToolTip extends Widget {
- Shell parent, tip;
- int x, y;
- int [] borderPolygon;
- boolean spikeAbove, autohide;
- Listener listener;
- 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#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);
-}
-
-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's value changes, by sending
- * it one of the messages defined in the <code>SelectionListener</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 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 ();
- if (x == -1 || y == -1) {
- Point 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) {
- 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's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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) {
- 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 dad1fe27a7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/tray/org/eclipse/swt/widgets/TrayItem.java
+++ /dev/null
@@ -1,279 +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.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>
- *
- * @since 3.0
- */
-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 receiver is selected, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 ();
-}
-
-/**
- * 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 receiver is selected.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 ();
- this.toolTip = toolTip;
-}
-
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that no tool tip text should be shown.
- *
- * @param value 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 b51c42b8b4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Table.java
+++ /dev/null
@@ -1,4035 +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.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 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>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL</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>
- */
-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 Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Table (Composite parent, int style) {
- super (parent, checkStyle (style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED));
- setForeground (display.getSystemColor (SWT.COLOR_LIST_FOREGROUND));
- setBackground (display.getSystemColor (SWT.COLOR_LIST_BACKGROUND));
- 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);
-
- 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 vBar = getVerticalBar ();
- ScrollBar hBar = getHorizontalBar ();
- vBar.setValues (0, 0, 1, 1, 1, 1);
- hBar.setValues (0, 0, 1, 1, 1, 1);
- vBar.setVisible (false);
- hBar.setVisible (false);
- vBar.addListener (SWT.Selection, listener);
- hBar.addListener (SWT.Selection, listener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's selection changes, 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 <code>SWT.CHECK</code> style set 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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) {
- 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++;
- getVerticalBar ().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 ();
- 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;
- getVerticalBar ().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's.
- *
- * @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.
- * <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);
- 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;
- }
- 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.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 == getVerticalBar ()) {
- onScrollVertical (event);
- } else {
- onScrollHorizontal (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 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 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 (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 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 (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 visibility 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++;
- getVerticalBar ().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++;
- getVerticalBar ().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;
- getHorizontalBar ().setSelection (horizontalOffset);
-}
-void onArrowRight (int stateMask) {
- ScrollBar hBar = getHorizontalBar ();
- 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--;
- getVerticalBar ().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--;
- getVerticalBar ().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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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 ();
- 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 ();
- int hBarMaximum = hBar.getMaximum ();
- thumb = Math.min (clientArea.width, hBarMaximum);
- hBar.setThumb (thumb);
- hBar.setPageIncrement (thumb);
- horizontalOffset = hBar.getSelection ();
- 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) {
- int newSelection = getHorizontalBar ().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) {
- int newSelection = getVerticalBar ().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.checked = !focusItem.checked;
- if (focusItem.isInViewport ()) {
- Rectangle bounds = focusItem.getCheckboxBounds ();
- redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
- }
- 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);
- sort (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 ();
- vBar.setMaximum (1);
- vBar.setVisible (false);
- if (columns.length == 0) {
- horizontalOffset = 0;
- ScrollBar hBar = getHorizontalBar ();
- hBar.setMaximum (1);
- hBar.setVisible (false);
- }
-
- setRedraw (true);
-}
-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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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;
- }
-}
-/**
- * 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 ();
- 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.
- * <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 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});
-}
-/**
- * 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);
- 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);
- }
- }
- 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;
- getVerticalBar ().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;
- }
- getHorizontalBar ().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 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 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 ();
- 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 ();
- 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;
-
- newRightX += horizontalOffset;
- ScrollBar hBar = getHorizontalBar ();
- 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;
-
- int pageSize = (clientArea.height - getHeaderHeight ()) / itemHeight;
- int maximum = Math.max (1, itemsCount); /* setting a value of 0 here is ignored */
- ScrollBar vBar = getVerticalBar ();
- 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 d337a360b2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableColumn.java
+++ /dev/null
@@ -1,739 +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.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>
- */
-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>
- *
- * @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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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>.
- *
- * @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 ()) {
- parent.header.redraw (x, 0, width, parent.getHeaderHeight (), 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 ()) {
- parent.header.redraw (getX (), 0, width, parent.getHeaderHeight (), 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 ()) {
- parent.header.redraw (getX (), 0, width, parent.getHeaderHeight (), 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 ()) {
- parent.header.redraw (getX (), 0, width, parent.getHeaderHeight (), false);
- }
-}
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that no tool tip text should be shown.
- *
- * @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 ();
- value = Math.max (value, 0);
- 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 64e1569b0e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableItem.java
+++ /dev/null
@@ -1,1965 +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.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>
- */
-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 - 1);
-}
-/**
- * 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) {
- if (parent.hooks (SWT.PaintItem)) {
- x = getContentX (0);
- } else {
- x = getTextX (0);
- }
- } else {
- x = -parent.horizontalOffset;
- }
- } else {
- if (parent.hooks (SWT.PaintItem)) {
- x = getContentX (0);
- } 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 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;
- boolean drawBackground = background != null || (cellBackgrounds != null && cellBackgrounds [columnIndex] != null);
- boolean drawForeground = true;
- boolean drawSelection = isSelected;
- boolean drawFocus = isFocusItem;
- if (parent.hooks (SWT.EraseItem)) {
- 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 value) {
- checkWidget ();
- if (value != null && value.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (background == value) return;
- if (background != null && background.equals (value)) return;
- background = value;
- 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 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 (cellBackgrounds == null) {
- cellBackgrounds = new Color [validColumnCount];
- }
- if (cellBackgrounds [columnIndex] == value) return;
- if (cellBackgrounds [columnIndex] != null && cellBackgrounds [columnIndex].equals (value)) return;
- cellBackgrounds [columnIndex] = value;
- 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 ()) {
- 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 value) {
- checkWidget ();
- if (value != null && value.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (font == value) return;
- if (value != null && value.equals (font)) return;
-
- Rectangle bounds = getBounds (false);
- int oldRightX = bounds.x + bounds.width;
- font = value;
- 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 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 (cellFonts == null) {
- if (value == null) return;
- cellFonts = new Font [validColumnCount];
- }
- if (cellFonts [columnIndex] == value) return;
- if (cellFonts [columnIndex] != null && cellFonts [columnIndex].equals (value)) return;
- cellFonts [columnIndex] = value;
- 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 value) {
- checkWidget ();
- if (value != null && value.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (foreground == value) return;
- if (foreground != null && foreground.equals (value)) return;
- foreground = value;
- 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 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) {
- cellForegrounds = new Color [validColumnCount];
- }
- if (cellForegrounds [columnIndex] == value) return;
- if (cellForegrounds [columnIndex] != null && cellForegrounds [columnIndex].equals (value)) return;
- cellForegrounds [columnIndex] = value;
- 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,
- true);
- }
- 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 b79286b448..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Tree.java
+++ /dev/null
@@ -1,4126 +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.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 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>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL</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>
- */
-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 Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tree (Composite parent, int style) {
- super (parent, checkStyle (style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED));
- setForeground (display.getSystemColor (SWT.COLOR_LIST_FOREGROUND));
- setBackground (display.getSystemColor (SWT.COLOR_LIST_BACKGROUND));
- 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);
-
- 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 vBar = getVerticalBar ();
- ScrollBar hBar = getHorizontalBar ();
- vBar.setValues (0, 0, 1, 1, 1, 1);
- hBar.setValues (0, 0, 1, 1, 1, 1);
- vBar.setVisible (false);
- hBar.setVisible (false);
- vBar.addListener (SWT.Selection, listener);
- hBar.addListener (SWT.Selection, listener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's selection changes, 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 <code>SWT.CHECK</code> style set 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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) {
- 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 < items.length; i++) {
- Rectangle itemBounds = items [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 () + items.length * 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++;
- getVerticalBar ().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 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 ();
- 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;
- getVerticalBar ().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.
- * <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 ();
- TreeItem[] result = new TreeItem [selectedItems.length];
- System.arraycopy (selectedItems, 0, result, 0, selectedItems.length);
- 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 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.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 == getVerticalBar ()) {
- onScrollVertical (event);
- } else {
- onScrollHorizontal (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 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 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.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 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>
- *
- * @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++;
- getVerticalBar ().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++;
- getVerticalBar ().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;
- getHorizontalBar ().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 ();
- 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--;
- getVerticalBar ().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--;
- getVerticalBar ().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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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 ();
- 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 ();
- int hBarMaximum = hBar.getMaximum ();
- thumb = Math.min (clientArea.width, hBarMaximum);
- hBar.setThumb (thumb);
- hBar.setPageIncrement (thumb);
- horizontalOffset = hBar.getSelection ();
- 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) {
- int newSelection = getHorizontalBar ().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) {
- int newSelection = getVerticalBar ().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.checked = !focusItem.checked;
- if (focusItem.isInViewport ()) {
- Rectangle bounds = focusItem.getCheckboxBounds ();
- redraw (bounds.x, bounds.y, bounds.width, bounds.height, false);
- }
- }
- 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 ();
- vBar.setMaximum (1);
- vBar.setVisible (false);
- if (columns.length == 0) {
- horizontalOffset = 0;
- ScrollBar hBar = getHorizontalBar ();
- hBar.setMaximum (1);
- hBar.setVisible (false);
- }
-
- setRedraw (true);
-}
-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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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;
- }
-}
-/**
- * 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 ();
- 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 ();
-}
-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.
- * <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 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});
-}
-/**
- * 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);
- 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);
- }
- }
- }
- 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;
- getVerticalBar ().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;
- }
- getHorizontalBar ().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 ();
- 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 ();
- 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;
-
- newRightX += horizontalOffset;
- ScrollBar hBar = getHorizontalBar ();
- 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;
-
- int pageSize = (clientArea.height - getHeaderHeight ()) / itemHeight;
- int maximum = Math.max (1, availableItemsCount);
- ScrollBar vBar = getVerticalBar ();
- 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 3306f017df..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeColumn.java
+++ /dev/null
@@ -1,715 +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.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>
- *
- * @since 3.1
- */
-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>
- *
- * @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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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>.
- *
- * @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 ()) {
- parent.header.redraw (x, 0, width, parent.getHeaderHeight (), 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 ()) {
- parent.header.redraw (getX (), 0, width, parent.getHeaderHeight (), 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 ()) {
- parent.header.redraw (getX (), 0, width, parent.getHeaderHeight (), 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 ()) {
- parent.header.redraw (getX (), 0, width, parent.getHeaderHeight (), false);
- }
-}
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that no tool tip text should be shown.
- *
- * @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 ();
- value = Math.max (value, 0);
- 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 c3a6a4c9af..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeItem.java
+++ /dev/null
@@ -1,2878 +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.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>
- */
-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++;
- parent.getVerticalBar ().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);
-}
-/**
- * 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 - 1);
-}
-/**
- * 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;
- if (parent.hooks (SWT.PaintItem)) {
- x = getContentX (orderedCol0index);
- } else {
- 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 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 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>
- *
- * @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;
- boolean drawBackground = background != null || (cellBackgrounds != null && cellBackgrounds [columnIndex] != null);
- boolean drawForeground = true;
- boolean drawSelection = isSelected;
- boolean drawFocus = isFocusItem;
- if (parent.hooks (SWT.EraseItem)) {
- 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 value) {
- checkWidget ();
- if (value != null && value.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (background == value) return;
- if (background != null && background.equals (value)) return;
- background = value;
- 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 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 (cellBackgrounds == null) {
- cellBackgrounds = new Color [validColumnCount];
- }
- if (cellBackgrounds [columnIndex] == value) return;
- if (cellBackgrounds [columnIndex] != null && cellBackgrounds [columnIndex].equals (value)) return;
- cellBackgrounds [columnIndex] = value;
- 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 ()) {
- 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;
- parent.getVerticalBar ().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;
- parent.getVerticalBar ().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 value) {
- checkWidget ();
- if (value != null && value.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (font == value) return;
- if (value != null && value.equals (font)) return;
-
- Rectangle bounds = getBounds (false);
- int oldRightX = bounds.x + bounds.width;
- font = value;
- 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 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 (cellFonts == null) {
- if (value == null) return;
- cellFonts = new Font [validColumnCount];
- }
- if (cellFonts [columnIndex] == value) return;
- if (cellFonts [columnIndex] != null && cellFonts [columnIndex].equals (value)) return;
- cellFonts [columnIndex] = value;
- 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 value) {
- checkWidget ();
- if (value != null && value.isDisposed ()) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (foreground == value) return;
- if (foreground != null && foreground.equals (value)) return;
- foreground = value;
- 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) {
- cellForegrounds = new Color [validColumnCount];
- }
- if (cellForegrounds [columnIndex] == value) return;
- if (cellForegrounds [columnIndex] != null && cellForegrounds [columnIndex].equals (value)) return;
- cellForegrounds [columnIndex] = value;
- 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 d10a9df321..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,299 +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.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
- */
-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() {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, red, green, blue);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, rgb.red, rgb.green, rgb.blue);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the color. Applications must dispose of all colors which
- * they allocate.
- */
-public void dispose() {
- if (handle == null) return;
- if (device.isDisposed()) return;
- 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;
- if (device.tracking) device.dispose_Object(this);
- device = 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) {
- if (device == null) device = Device.getDevice();
- Color color = new Color();
- color.handle = gdkColor;
- color.device = device;
- return color;
-}
-
-void init(Device device, int red, int green, int blue) {
- this.device = device;
- 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 8c74fd0d44..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,457 +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.*;
-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>
- */
-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 () {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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, source.type,
- source.x, source.y, source.disposalMethod, source.delayTime);
-
- /* 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, 0, 0, 0,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, 0, 0, 0,
- false, false);
- else ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, null, null, null,
- 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);
- if (device.tracking) device.new_Object(this);
-}
-
-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;
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the cursor. Applications must dispose of all cursors which
- * they allocate.
- */
-public void dispose() {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- OS.gdk_cursor_destroy(handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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;
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- Cursor cursor = new Cursor();
- cursor.handle = handle;
- cursor.device = device;
- 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 7bcd3fe96c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,831 +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 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.
- */
-public abstract class Device implements Drawable {
- /**
- * the handle to the X Display
- */
- int /*long*/ xDisplay;
- int /*long*/ shellHandle;
-
- /* Debugging */
- public static boolean DEBUG;
- boolean debug = DEBUG;
- boolean tracking = DEBUG;
- Error [] errors;
- Object [] objects;
-
- /* 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;
-
- static final Object CREATE_LOCK = new Object();
-
- /*
- * 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.
- *
- * This code will be removed in the future.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName ("org.eclipse.swt.widgets.Display");
- } catch (Throwable 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 (CREATE_LOCK) {
- if (data != null) {
- debug = data.debug;
- tracking = data.tracking;
- }
- if (tracking) {
- errors = new Error [128];
- objects = new Object [128];
- }
- 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 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 () {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- deregister (this);
- xDisplay = 0;
- disposed = true;
- if (tracking) {
- objects = null;
- errors = null;
- }
-}
-
-void dispose_Object (Object object) {
- 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;
- int count = 0, length = 0;
- if (tracking) 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++;
- }
- }
- 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 (OS.GDK_WINDOWING_X11()) {
- xDisplay = OS.GDK_DISPLAY ();
- 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 (OS.GDK_WINDOWING_X11()) {
- /* 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 */
- 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);
-}
-
-/**
- * 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 () {
- return disposed;
-}
-
-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) {
- 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;
- 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 */
- 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;
- 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;
- 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 7578eabfbe..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 8d06c6fe63..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,291 +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.*;
-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
- */
-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() {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, fd.getName(), fd.getHeight(), fd.getStyle(), fd.string);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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(device,fd.getName(), fd.getHeight(), fd.getStyle(), fd.string);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, name, height, style, null);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the font. Applications must dispose of all fonts which
- * they allocate.
- */
-public void dispose() {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- OS.pango_font_description_free(handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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;
- 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));
- int height = OS.PANGO_PIXELS(OS.pango_font_description_get_size(handle));
- 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) {
- if (device == null) device = Device.getDevice();
- Font font = new Font();
- font.handle = handle;
- font.device = device;
- 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(Device device, String name, int height, int style, byte[] fontString) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.device = device;
- 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);
- OS.pango_font_description_set_size(handle, 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 1138da13a6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,429 +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.*;
-
-/**
- * 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
- */
-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;
-
- /**
- * 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 un-initialized 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("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);
-}
-
-/**
- * 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
- */
-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.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();
- buffer.append("1|");
- buffer.append(getName());
- buffer.append("|");
- buffer.append(getHeight());
- 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 946fc7a330..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,132 +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;
-
-
-/**
- * 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
- */
-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 cbe5b6d33d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,3652 +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 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>
- * 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
- */
-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[] LINE_DOT = new int[]{1, 1};
- static final int[] LINE_DASH = new int[]{3, 1};
- static final int[] LINE_DASHDOT = new int[]{3, 1, 1, 1};
- static final int[] LINE_DASHDOTDOT = new int[]{3, 1, 1, 1, 1, 1};
- static final int[] LINE_DOT_ZERO = new int[]{3, 3};
- static final int[] LINE_DASH_ZERO = new int[]{18, 6};
- static final int[] LINE_DASHDOT_ZERO = new int[]{9, 6, 3, 6};
- static final int[] LINE_DASHDOTDOT_ZERO = new int[]{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 and background color 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>
- * </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 and background color 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>
- * </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);
- if (device.tracking) device.new_Object(this);
-}
-
-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);
- 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(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;
-}
-
-/**
- * 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, 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);
- }
- int /*long*/ font = data.font;
- if (font != 0) OS.pango_layout_set_font_description(layout, font);
-}
-
-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;
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the graphics context. Applications must dispose of all GCs
- * which they allocate.
- */
-public void dispose() {
- if (handle == 0) return;
- if (data.device.isDisposed()) return;
-
- 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 */
- Device device = data.device;
- drawable.internal_dispose_GC(handle, data);
-
- data.drawable = data.clipRgn = 0;
- drawable = null;
- handle = 0;
- data.image = null;
- data.string = null;
- if (device.tracking) device.dispose_Object(this);
- data.device = 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);
- 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) {
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- if (width == height) {
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(cairo, x + offset + width / 2f, y + offset + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(cairo, x + offset + width / 2f, y + offset + 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 + offset + width / 2f, y + offset + 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);
- 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);
- Cairo.cairo_rectangle(cairo, destX + 0.5, destY + 0.5, destWidth, destHeight);
- Cairo.cairo_clip(cairo);
- Cairo.cairo_translate(cairo, destX - srcX + 0.5, destY - srcY + 0.5);
- 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);
- Cairo.cairo_pattern_set_filter(pattern, filter);
- Cairo.cairo_pattern_set_extend(pattern, Cairo.CAIRO_EXTEND_REFLECT);
- 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) {
- 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);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- Cairo.cairo_move_to(cairo, x1 + offset, y1 + offset);
- Cairo.cairo_line_to(cairo, x2 + offset, y2 + offset);
- 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);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- if (width == height) {
- Cairo.cairo_arc_negative(cairo, x + offset + width / 2f, y + offset + height / 2f, width / 2f, 0, -2 * (float)Compatibility.PI);
- } else {
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x + offset + width / 2f, y + offset + 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.
- *
- * @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>
- * </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();
- int /*long*/ cairo = data.cairo;
- Cairo.cairo_save(cairo);
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- Cairo.cairo_translate(cairo, offset, offset);
- 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);
- 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);
- 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);
- 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;
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- Cairo.cairo_move_to(cairo, pointArray[0] + offset, pointArray[1] + offset);
- for (int i = 1, j=2; i < count; i++, j += 2) {
- Cairo.cairo_line_to(cairo, pointArray[j] + offset, pointArray[j + 1] + offset);
- }
- 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);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- Cairo.cairo_rectangle(cairo, x + offset, y + offset, 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);
- 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) {
- float naw2 = naw / 2f;
- float nah2 = nah / 2f;
- float fw = nw / naw2;
- float fh = nh / nah2;
- Cairo.cairo_save(cairo);
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- Cairo.cairo_translate(cairo, nx + offset, ny + offset);
- 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 specifing 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
- 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);
- GdkColor background = null;
- GdkGCValues values = null;
- if ((flags & SWT.DRAW_TRANSPARENT) == 0) {
- values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- background = new GdkColor();
- background.pixel = values.background_pixel;
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_query_color(colormap, background.pixel, background);
- }
- if (cairo != 0) {
- if ((flags & SWT.DRAW_TRANSPARENT) == 0) {
- int[] width = new int[1], height = new int[1];
- OS.pango_layout_get_size(data.layout, width, height);
- Cairo.cairo_rectangle(cairo, x, y, OS.PANGO_PIXELS(width[0]), OS.PANGO_PIXELS(height[0]));
- Cairo.cairo_save(cairo);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.handle);
- } else {
- Cairo.cairo_set_source_rgba(cairo, (background.red & 0xFFFF) / (float)0xFFFF, (background.green & 0xFFFF) / (float)0xFFFF, (background.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- }
- Cairo.cairo_fill(cairo);
- Cairo.cairo_restore(cairo);
- }
- Cairo.cairo_move_to(cairo, x, y);
- OS.pango_cairo_show_layout(cairo, data.layout);
- return;
- }
- if (!data.xorMode) {
- OS.gdk_draw_layout_with_colors(data.drawable, handle, x, y, data.layout, null, background);
- } else {
- int /*long*/ layout = data.layout;
- int[] w = new int[1], h = new int[1];
- OS.pango_layout_get_size(layout, w, h);
- int width = OS.PANGO_PIXELS(w[0]);
- int height = OS.PANGO_PIXELS(h[0]);
- 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);
- GdkColor foreground = new GdkColor();
- OS.gdk_gc_set_foreground(gdkGC, foreground);
- OS.gdk_draw_rectangle(pixmap, gdkGC, 1, 0, 0, width, height);
- if (values == null) {
- values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- }
- foreground.pixel = values.foreground_pixel;
- OS.gdk_gc_set_foreground(gdkGC, 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, width, height);
- 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);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- 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_save(cairo);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.handle);
- } else {
- OS.gdk_colormap_query_color(OS.gdk_colormap_get_system(), color.pixel, color);
- 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_fill(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- OS.gdk_gc_set_foreground(handle, color);
- OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, startAngle * 64, arcAngle * 64);
- color.pixel = values.foreground_pixel;
- OS.gdk_gc_set_foreground(handle, color);
-}
-
-/**
- * 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 */
-
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
-
- 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);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- 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_save(cairo);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.handle);
- } else {
- OS.gdk_colormap_query_color(OS.gdk_colormap_get_system(), color.pixel, color);
- 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_fill(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- OS.gdk_gc_set_foreground(handle, color);
- OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, 0, 23040);
- color.pixel = values.foreground_pixel;
- OS.gdk_gc_set_foreground(handle, color);
-}
-
-/**
- * Fills the path described by the parameter.
- *
- * @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>
- * </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();
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- int /*long*/ cairo = data.cairo;
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_query_color(colormap, color.pixel, color);
- Cairo.cairo_save(cairo);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.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);
- }
- 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);
- Cairo.cairo_restore(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);
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_query_color(colormap, color.pixel, color);
- Cairo.cairo_save(cairo);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.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);
- }
- drawPolyline(cairo, pointArray, true);
- Cairo.cairo_fill(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- OS.gdk_gc_set_foreground(handle, color);
- OS.gdk_draw_polygon(data.drawable, handle, 1, pointArray, pointArray.length / 2);
- color.pixel = values.foreground_pixel;
- OS.gdk_gc_set_foreground(handle, color);
-}
-
-/**
- * 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) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_query_color(colormap, color.pixel, color);
- Cairo.cairo_save(cairo);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.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);
- }
- Cairo.cairo_rectangle(cairo, x, y, width, height);
- Cairo.cairo_fill(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- OS.gdk_gc_set_foreground(handle, color);
- OS.gdk_draw_rectangle(data.drawable, handle, 1, x, y, width, height);
- color.pixel = values.foreground_pixel;
- OS.gdk_gc_set_foreground(handle, color);
-}
-
-/**
- * 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);
- 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;
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- float naw2 = naw / 2f;
- float nah2 = nah / 2f;
- float fw = nw / naw2;
- float fh = nh / nah2;
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_query_color(colormap, color.pixel, color);
- Cairo.cairo_save(cairo);
- 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);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.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);
- }
- Cairo.cairo_fill(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- int naw2 = naw / 2;
- int nah2 = nah / 2;
- OS.gdk_gc_set_foreground(handle, color);
- 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);
- }
- }
- color.pixel = values.foreground_pixel;
- OS.gdk_gc_set_foreground(handle, color);
-}
-
-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.
- *
- * @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);
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.background_pixel;
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_query_color(colormap, color.pixel, color);
- return Color.gtk_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);
- //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);
- int[] width = new int[1], height = new int[1];
- OS.gdk_drawable_get_size(data.drawable, width, height);
- int /*long*/ clipRgn = data.clipRgn;
- if (clipRgn == 0) {
- return new Rectangle(0, 0, width[0], height[0]);
- } else {
- int /*long*/ rgn = OS.gdk_region_new();
- GdkRectangle rect = new GdkRectangle();
- rect.width = width[0];
- rect.height = height[0];
- OS.gdk_region_union_with_rect(rgn, rect);
- OS.gdk_region_intersect(rgn, clipRgn);
- OS.gdk_region_get_clipbox(rgn, rect);
- OS.gdk_region_destroy(rgn);
- return new Rectangle(rect.x, rect.y, rect.width, rect.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*/ hRegion = region.handle;
- OS.gdk_region_subtract(hRegion, hRegion);
- int /*long*/ clipRgn = data.clipRgn;
- if (clipRgn == 0) {
- int[] width = new int[1], height = new int[1];
- OS.gdk_drawable_get_size(data.drawable, width, height);
- GdkRectangle rect = new GdkRectangle();
- rect.x = rect.y = 0;
- rect.width = width[0];
- rect.height = height[0];
- OS.gdk_region_union_with_rect(hRegion, rect);
- } else {
- OS.gdk_region_union(hRegion, clipRgn);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double[] matrix = new double[]{1, 0, 0, 1, 0, 0};
- Cairo.cairo_get_matrix(cairo, matrix);
- if (!isIdentity(matrix)) return;
- }
- }
- if (data.damageRgn != 0) {
- OS.gdk_region_intersect(hRegion, data.damageRgn);
- }
-}
-
-/**
- * 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 Font.gtk_new(data.device, 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();
- int /*long*/ context = data.context;
- int /*long*/ lang = OS.pango_context_get_language(context);
- int /*long*/ metrics = OS.pango_context_get_metrics(context, data.font, 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);
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.foreground_pixel;
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_query_color(colormap, color.pixel, color);
- return Color.gtk_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
- */
-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 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);
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- int cap = SWT.CAP_FLAT;
- switch (values.cap_style) {
- case OS.GDK_CAP_ROUND: cap = SWT.CAP_ROUND; break;
- case OS.GDK_CAP_BUTT: cap = SWT.CAP_FLAT; break;
- case OS.GDK_CAP_PROJECTING: cap = SWT.CAP_SQUARE; break;
- }
- return cap;
-}
-
-/**
- * Returns the receiver's line dash style. The default value is
- * <code>null</code>.
- *
- * @return the lin 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);
- int[] dash_list = data.dashes;
- if (dash_list == null) return null;
- int[] dashes = new int[dash_list.length];
- System.arraycopy(dash_list, 0, dashes, 0, dashes.length);
- 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);
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- int join = SWT.JOIN_MITER;
- switch (values.join_style) {
- case OS.GDK_JOIN_MITER: join = SWT.JOIN_MITER; break;
- case OS.GDK_JOIN_ROUND: join = SWT.JOIN_ROUND; break;
- case OS.GDK_JOIN_BEVEL: join = SWT.JOIN_BEVEL; break;
- }
- return join;
-}
-
-/**
- * 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);
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- return values.line_width;
-}
-
-/**
- * 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);
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- return values.function == OS.GDK_XOR;
-}
-
-/**
- * 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;
-}
-
-void init(Drawable drawable, GCData data, int /*long*/ gdkGC) {
- GdkColor foreground = data.foreground;
- if (foreground != null) OS.gdk_gc_set_foreground(gdkGC, foreground);
- GdkColor background = data.background;
- if (background != null) OS.gdk_gc_set_background(gdkGC, background);
-
- 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;
-}
-
-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 {
- 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);
- Cairo.cairo_set_fill_rule(cairo, Cairo.CAIRO_FILL_RULE_EVEN_ODD);
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.foreground_pixel;
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_query_color(colormap, color.pixel, color);
- 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, Math.max(1, values.line_width));
- int cap = Cairo.CAIRO_LINE_CAP_BUTT;
- switch (values.cap_style) {
- case OS.GDK_CAP_ROUND: cap = Cairo.CAIRO_LINE_CAP_ROUND; break;
- case OS.GDK_CAP_BUTT: cap = Cairo.CAIRO_LINE_CAP_BUTT; break;
- case OS.GDK_CAP_PROJECTING: cap = Cairo.CAIRO_LINE_CAP_SQUARE; break;
- }
- Cairo.cairo_set_line_cap(cairo, cap);
- int join = Cairo.CAIRO_LINE_JOIN_MITER;
- switch (values.join_style) {
- case OS.GDK_JOIN_MITER: join = Cairo.CAIRO_LINE_JOIN_MITER; break;
- case OS.GDK_JOIN_ROUND: join = Cairo.CAIRO_LINE_JOIN_ROUND; break;
- case OS.GDK_JOIN_BEVEL: join = Cairo.CAIRO_LINE_JOIN_BEVEL; break;
- }
- Cairo.cairo_set_line_join(cairo, join);
- if (data.dashes != null) {
- double[] dashes = new double[data.dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- dashes[i] = data.dashes[i];
- }
- Cairo.cairo_set_dash(cairo, dashes, dashes.length, 0);
- }
- if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) {
- setCairoFont(cairo, data.font);
- }
- setCairoClip(cairo, 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 #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;
- setClipping(0);
- }
-}
-
-/**
- * Sets the receiver's alpha value.
- *
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @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;
- if (data.foregroundPattern == null) {
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.foreground_pixel;
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_query_color(colormap, color.pixel, color);
- int /*long*/ cairo = data.cairo;
- 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);
- }
-}
-
-/**
- * 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.
- *
- * @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>
- * </ul>
- *
- * @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);
- OS.gdk_gc_set_background(handle, color.handle);
- data.backgroundPattern = null;
-}
-
-/**
- * Sets the background pattern. The default value is <code>null</code>.
- *
- * @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>
- * </ul>
- *
- * @see Pattern
- *
- * @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();
- data.backgroundPattern = pattern;
-}
-
-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 setCairoClip(int /*long*/ cairo, int /*long*/ clipRgn) {
- Cairo.cairo_reset_clip(cairo);
- if (clipRgn == 0) return;
- int[] nRects = new int[1];
- int /*long*/[] rects = new int /*long*/[1];
- OS.gdk_region_get_rectangles(clipRgn, 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);
- }
- Cairo.cairo_clip(cairo);
- Cairo.cairo_new_path(cairo);
- 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 setClipping(int /*long*/ clipRgn) {
- if (clipRgn == 0) {
- if (data.clipRgn != 0) {
- OS.gdk_region_destroy(data.clipRgn);
- data.clipRgn = 0;
- } else {
- return;
- }
- 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);
- 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);
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- setCairoClip(cairo, clipRgn);
- }
-}
-
-/**
- * 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.
- *
- * @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>
- * </ul>
- *
- * @see Path
- *
- * @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 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 = data.device.systemFont;
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int /*long*/ fontHandle = data.font = font.handle;
- if (data.layout != 0) {
- OS.pango_layout_set_font_description(data.layout, fontHandle);
- }
- data.stringWidth = data.stringHeight = -1;
- if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) {
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- setCairoFont(cairo, fontHandle);
- }
- }
-}
-
-/**
- * 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);
- OS.gdk_gc_set_foreground(handle, color.handle);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- GdkColor gdkColor = color.handle;
- Cairo.cairo_set_source_rgba(cairo, (gdkColor.red & 0xFFFF) / (float)0xFFFF, (gdkColor.green & 0xFFFF) / (float)0xFFFF, (gdkColor.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- }
- data.foregroundPattern = null;
-}
-
-/**
- * Sets the foreground pattern. The default value is <code>null</code>.
- *
- * @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>
- * </ul>
- *
- * @see Pattern
- *
- * @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();
- int /*long*/ cairo = data.cairo;
- if (pattern != null) {
- Cairo.cairo_set_source(cairo, pattern.handle);
- } else {
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- GdkColor color = new GdkColor();
- color.pixel = values.foreground_pixel;
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_colormap_query_color(colormap, color.pixel, color);
- 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);
- }
- data.foregroundPattern = pattern;
-}
-
-/**
- * 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>.
- *
- * @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>
- * </ul>
- *
- * @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 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);
- int cap_style = 0, cairo_style = 0;
- switch (cap) {
- case SWT.CAP_ROUND:
- cap_style = OS.GDK_CAP_ROUND;
- cairo_style = Cairo.CAIRO_LINE_CAP_ROUND;
- break;
- case SWT.CAP_FLAT:
- cap_style = OS.GDK_CAP_BUTT;
- cairo_style = Cairo.CAIRO_LINE_CAP_BUTT;
- break;
- case SWT.CAP_SQUARE:
- cap_style = OS.GDK_CAP_PROJECTING;
- cairo_style = Cairo.CAIRO_LINE_CAP_SQUARE;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- int line_style = data.lineStyle == SWT.LINE_SOLID ? OS.GDK_LINE_SOLID : OS.GDK_LINE_ON_OFF_DASH;
- OS.gdk_gc_set_line_attributes(handle, values.line_width, line_style, cap_style, values.join_style);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_set_line_cap(cairo, cairo_style);
- }
-}
-
-/**
- * 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[] dash_list = new byte[dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- int dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- dash_list[i] = (byte)dash;
- }
- OS.gdk_gc_set_dashes(handle, 0, dash_list, dash_list.length);
- data.dashes = new int[dashes.length];
- System.arraycopy(dashes, 0, data.dashes, 0, dashes.length);
- data.lineStyle = SWT.LINE_CUSTOM;
- } else {
- data.dashes = null;
- data.lineStyle = SWT.LINE_SOLID;
- }
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- int line_style = data.lineStyle == SWT.LINE_SOLID ? OS.GDK_LINE_SOLID : OS.GDK_LINE_ON_OFF_DASH;
- OS.gdk_gc_set_line_attributes(handle, values.line_width, line_style, values.cap_style, values.join_style);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (data.dashes != null) {
- double[] cairoDashes = new double[data.dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- cairoDashes[i] = data.dashes[i];
- }
- Cairo.cairo_set_dash(cairo, cairoDashes, cairoDashes.length, 0);
- } else {
- Cairo.cairo_set_dash(cairo, null, 0, 0);
- }
- }
-}
-
-/**
- * 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);
- int join_style = 0, cairo_style = 0;
- switch (join) {
- case SWT.JOIN_MITER:
- join_style = OS.GDK_JOIN_MITER;
- cairo_style = Cairo.CAIRO_LINE_JOIN_MITER;
- break;
- case SWT.JOIN_ROUND:
- join_style = OS.GDK_JOIN_ROUND;
- cairo_style = Cairo.CAIRO_LINE_JOIN_ROUND;
- break;
- case SWT.JOIN_BEVEL:
- join_style = OS.GDK_JOIN_BEVEL;
- cairo_style = Cairo.CAIRO_LINE_JOIN_BEVEL;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- int line_style = data.lineStyle == SWT.LINE_SOLID ? OS.GDK_LINE_SOLID : OS.GDK_LINE_ON_OFF_DASH;
- OS.gdk_gc_set_line_attributes(handle, values.line_width, line_style, values.cap_style, join_style);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_set_line_join(cairo, cairo_style);
- }
-}
-
-/**
- * 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);
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- int[] dashes = null;
- int width = values.line_width;
- switch (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.dashes;
- if (dashes == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineStyle = lineStyle;
- OS.gdk_gc_set_line_attributes(handle, values.line_width, dashes != null ? OS.GDK_LINE_ON_OFF_DASH : OS.GDK_LINE_SOLID, values.cap_style, values.join_style);
- if (dashes != null) {
- byte[] dash_list = new byte[dashes.length];
- for (int i = 0; i < dash_list.length; i++) {
- dash_list[i] = (byte)(width == 0 ? dashes[i] : dashes[i] * width);
- }
- OS.gdk_gc_set_dashes(handle, 0, dash_list, dash_list.length);
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (dashes != null) {
- double[] cairoDashes = new double[dashes.length];
- for (int i = 0; i < cairoDashes.length; i++) {
- cairoDashes[i] = width == 0 ? dashes[i] : dashes[i] * width;
- }
- Cairo.cairo_set_dash(cairo, cairoDashes, cairoDashes.length, 0);
- } else {
- Cairo.cairo_set_dash(cairo, null, 0, 0);
- }
- }
-}
-
-/**
- * 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);
- GdkGCValues values = new GdkGCValues();
- OS.gdk_gc_get_values(handle, values);
- int line_style = data.lineStyle == SWT.LINE_SOLID ? OS.GDK_LINE_SOLID : OS.GDK_LINE_ON_OFF_DASH;
- OS.gdk_gc_set_line_attributes(handle, lineWidth, line_style, values.cap_style, values.join_style);
- data.lineWidth = lineWidth;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_set_line_width(cairo, Math.max (1, lineWidth));
- }
- switch (data.lineStyle) {
- case SWT.LINE_DOT:
- case SWT.LINE_DASH:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- setLineStyle(data.lineStyle);
- }
-}
-
-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.
- *
- * @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>
- * </ul>
- *
- * @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.
- *
- * @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>
- * </ul>
- *
- * @see Transform
- *
- * @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);
- }
- //TODO - round off problems
- int /*long*/ clipRgn = data.clipRgn;
- if (clipRgn != 0) {
- double[] matrix = new double[]{1, 0, 0, 1, 0, 0};
- Cairo.cairo_get_matrix(cairo, matrix);
- Cairo.cairo_matrix_invert(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(clipRgn, 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)Math.round(x[0]);
- pointArray[1] = (int)Math.round(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)Math.round(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)Math.round(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]);
- OS.gdk_region_destroy(clipRgn);
- data.clipRgn = newRgn;
- }
-}
-
-/**
- * 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 specifing 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
- 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);
- if (data.stringWidth != -1) return new Point(data.stringWidth, data.stringHeight);
- int[] width = new int[1], height = new int[1];
- OS.pango_layout_get_size(data.layout, width, height);
- return new Point(data.stringWidth = OS.PANGO_PIXELS(width[0]), data.stringHeight = OS.PANGO_PIXELS(height[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 "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 a76468d281..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java
+++ /dev/null
@@ -1,53 +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.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>
- */
-public final class GCData {
- public Device device;
- public int style;
- public Image image;
- public int /*long*/ drawable;
- public GdkColor foreground;
- public GdkColor background;
- public Pattern foregroundPattern;
- public Pattern backgroundPattern;
- public int /*long*/ font;
- public int /*long*/ context;
- public int /*long*/ layout;
- public int /*long*/ clipRgn, damageRgn;
- public int lineWidth;
- public int lineStyle = SWT.LINE_SOLID;
- public int[] dashes;
- public boolean xorMode;
- public int alpha = 0xFF;
- public int interpolation = SWT.DEFAULT;
-
- public int /*long*/ cairo;
-
- public String string;
- public int stringWidth = -1;
- public int stringHeight = -1;
- public int drawFlags;
-}
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 db4ce13887..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,1188 +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 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
- */
-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() {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, width, height);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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>IMAGE_COPY</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>IMAGE_DISABLE</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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);
- }
- this.device = 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);
- }
-
- /* 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);
- if (device.tracking) device.new_Object(this);
- return;
- }
-
- /* 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);
- }
- 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;
- }
- }
-
- /* 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);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, bounds.width, bounds.height);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, data);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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(device, image);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new ImageData(stream));
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- 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) {
- 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);
- boolean hasAlpha = OS.gdk_pixbuf_get_has_alpha(pixbuf);
- if (hasAlpha) {
- 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];
- }
- }
- if (device.useXRender) {
- mask = OS.gdk_pixmap_new(0, width, height, 8);
- if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- GdkImage gdkImage = new GdkImage();
- int /*long*/ imagePtr = OS.gdk_drawable_get_image(mask, 0, 0, width, height);
- OS.memmove(gdkImage, imagePtr);
- if (gdkImage.bpl == width) {
- OS.memmove(gdkImage.mem, alphaData, alphaData.length);
- } else {
- 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);
- }
- }
- int /*long*/ gc = OS.gdk_gc_new(mask);
- if (gc == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.gdk_draw_image(mask, gc, imagePtr, 0, 0, 0, 0, width, height);
- OS.g_object_unref(imagePtr);
- OS.g_object_unref(gc);
- }
- }
- OS.g_object_unref (pixbuf);
- return;
- }
- } catch (SWTException e) {}
- init(device, new ImageData(filename));
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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;
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the image. Applications must dispose of all images which
- * they allocate.
- */
-public void dispose () {
- if (pixmap == 0) return;
- if (device.isDisposed()) return;
- 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;
- if (device.tracking) device.dispose_Object(this);
- device = 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);
- data.data = 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) {
- if (device == null) device = Device.getDevice();
- Image image = new Image();
- image.type = type;
- image.pixmap = pixmap;
- image.mask = mask;
- image.device = device;
- 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(Device device, int width, int height) {
- if (width <= 0 || height <= 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.device = device;
- 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(Device device, ImageData image) {
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- 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);
- }
- 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);
- 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);
- }
- }
- 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;
- }
- data.device = device;
- data.drawable = pixmap;
- data.background = device.COLOR_WHITE.handle;
- data.foreground = device.COLOR_BLACK.handle;
- data.font = device.systemFont.handle;
- 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 0702989763..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,590 +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.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>
- */
-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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- handle = OS.gdk_region_new();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
-
-Region(Device device, int /*long*/ handle) {
- this.device = 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);
- 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);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the region. Applications must dispose of all regions which
- * they allocate.
- */
-public void dispose() {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- OS.gdk_region_destroy(handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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 (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);
- 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 d6d325e730..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java
+++ /dev/null
@@ -1,1692 +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 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>
- *
- * @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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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_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();
- if (device.tracking) device.new_Object(this);
-}
-
-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) {
- int /*long*/ iter = OS.pango_layout_get_iter(layout);
- if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- 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, count = 0;
- do {
- int bytePos = OS.pango_layout_iter_get_index(iter);
- /* Note: The length in bytes of ZWS and ZWNBS are both equals to 3 */
- int offset = count * 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 + count * 2] = ZWS;
- chars[pos + count * 2 + 1] = ZWNBS;
- segmentsText.getChars(oldPos, pos, chars, oldPos + count * 2);
- oldPos = pos;
- count++;
- } while (OS.pango_layout_iter_next_line(iter));
- OS.pango_layout_iter_free (iter);
- segmentsText.getChars(oldPos, segementsLength, chars, oldPos + count * 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);
- 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()) {
- 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 /*long*/ attr = OS.pango_attr_underline_new(OS.PANGO_UNDERLINE_SINGLE);
- 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) {
- 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);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the text layout. Applications must dispose of all allocated text layouts.
- */
-public void dispose() {
- if (layout == 0) return;
- 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;
- if (device.tracking) device.dispose_Object(this);
- device = 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) {
- 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) return;
- boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1;
- GCData data = gc.data;
- int /*long*/ cairo = data.cairo;
- if (!hasSelection) {
- if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) {
- Cairo.cairo_move_to(cairo, x, y);
- OS.pango_cairo_show_layout(cairo, layout);
- } else {
- OS.gdk_draw_layout(data.drawable, gc.handle, x, y, layout);
- }
- } 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);
- drawWithCairo(cairo, x, y, 0, OS.strlen(ptr), fullSelection, selectionBackground.handle, selectionForeground.handle);
- } else {
- OS.gdk_draw_layout_with_colors(data.drawable, gc.handle, x, y, layout, selectionForeground.handle, selectionBackground.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)) {
- drawWithCairo(cairo, x, y, byteSelStart, byteSelEnd, fullSelection, selectionBackground.handle, selectionForeground.handle);
- } else {
- Region clipping = new Region();
- gc.getClipping(clipping);
- OS.gdk_draw_layout(data.drawable, gc.handle, x, y, layout);
- 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);
- gc.setClipping(clipping);
- clipping.dispose();
- }
- }
- }
-}
-
-void drawWithCairo(int /*long*/ cairo, int x, int y, int byteSelStart, int byteSelEnd, boolean fullSelection, GdkColor selectionBackground, GdkColor selectionForeground) {
- Cairo.cairo_save(cairo);
- if (!fullSelection) {
- Cairo.cairo_move_to(cairo, x, y);
- OS.pango_cairo_show_layout(cairo, layout);
- }
- 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_cairo_region(cairo, rgn);
- Cairo.cairo_clip(cairo);
- OS.gdk_cairo_set_source_color(cairo, selectionBackground);
- Cairo.cairo_paint(cairo);
- OS.gdk_region_destroy(rgn);
- }
- OS.gdk_cairo_set_source_color(cairo, selectionForeground);
- Cairo.cairo_move_to(cairo, x, y);
- OS.pango_cairo_show_layout(cairo, layout);
- 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);
- switch (align) {
- case OS.PANGO_ALIGN_CENTER: return SWT.CENTER;
- case OS.PANGO_ALIGN_RIGHT: 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.
- *
- * @return the bounds of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-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);
- int width = OS.PANGO_PIXELS(wrapWidth != -1 ? wrapWidth : w[0]);
- int height = OS.PANGO_PIXELS(h[0]);
- if (ascent != -1 && descent != -1) {
- height = Math.max (height, ascent + descent);
- }
- 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);
- 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 charecter 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);
- }
- 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);
- int /*long*/ iter = OS.pango_layout_get_iter(layout);
- if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int i = 0;
- do {
- int bytePos = OS.pango_layout_iter_get_index(iter);
- int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos);
- offsets[i++] = untranslateOffset(pos);
- } while (OS.pango_layout_iter_next_line(iter));
- OS.pango_layout_iter_free(iter);
- 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;
- return new Point(OS.PANGO_PIXELS(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> or <code>SWT.MOVEMENT_WORD</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) && (logAttr.is_word_start || logAttr.is_sentence_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);
-
- /*
- * 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>.
- *
- * @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;
- int align = OS.PANGO_ALIGN_LEFT;
- switch (alignment) {
- case SWT.CENTER: align = OS.PANGO_ALIGN_CENTER; break;
- case SWT.RIGHT: align = 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);
- if (this.font == font) return;
- if (font != null && font.equals(this.font)) return;
- this.font = font;
- OS.pango_layout_set_font_description(layout, font != null ? font.handle : 0);
-}
-
-
-/**
- * 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);
-}
-
-/**
- * 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.
- *
- * @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();
- OS.pango_layout_set_width(layout, width == -1 ? -1 : 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;
-}
-
-}
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 648e808699..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/Converter.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 bf81ef7933..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
+++ /dev/null
@@ -1,756 +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.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>
- */
-public class Button extends Control {
- int /*long*/ boxHandle, labelHandle, imageHandle, arrowHandle, groupHandle;
- boolean selected;
- 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#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 sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected.
- * <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) == 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 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 ();
- }
- }
- 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
- /* Aligmennt not honoured when image and text are visbible */
- 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);
- OS.gtk_widget_modify_fg (fixedHandle, OS.GTK_STATE_NORMAL, color);
- if (labelHandle != 0) OS.gtk_widget_modify_fg (labelHandle, OS.GTK_STATE_NORMAL, color);
- if (imageHandle != 0) OS.gtk_widget_modify_fg (imageHandle, OS.GTK_STATE_NORMAL, color);
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * <code>null</code> indicating that no image should be displayed.
- *
- * @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 (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.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 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.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.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 999fb82a97..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java
+++ /dev/null
@@ -1,332 +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.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
- */
-public class Canvas extends Composite {
- Caret caret;
-
-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);
-}
-
-/**
- * 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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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);
-}
-
-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;
-}
-
-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;
- }
- 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 /*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);
-}
-
-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 3cdddb5bfd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java
+++ /dev/null
@@ -1,496 +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.*;
-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>
- */
-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 /*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);
- OS.gdk_draw_drawable(window, gc, image.pixmap, 0, 0, x, y, width[0], height[0]);
- } else {
- int nWidth = width, nHeight = height;
- if (nWidth <= 0) nWidth = 1;
- OS.gdk_draw_rectangle (window, gc, 1, x, 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);
- }
- 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;
- 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 b4796dc6ba..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java
+++ /dev/null
@@ -1,157 +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.*;
-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>
- */
-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.NONE);
-}
-/**
- * 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, 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);
- 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);
- }
- }
- 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);
- int response = OS.gtk_dialog_run (handle);
- 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);
- }
- 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 f21037bacd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java
+++ /dev/null
@@ -1,1674 +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.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</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
- */
-public class Combo extends Composite {
- int /*long*/ arrowHandle, entryHandle, listHandle;
- int lastEventTime, visibleCount = 5;
- int /*long*/ gdkEventKey = 0;
- int fixStart = -1, fixEnd = -1;
- String [] items = new String [0];
- boolean ignoreSelect, lockText;
-
- static final int INNER_BORDER = 2;
-
- /**
- * 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;
- /*
- * 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;
- 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);
- OS.gtk_widget_modify_fg (label, OS.GTK_STATE_NORMAL, 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 receiver's selection changes, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the combo's list selection changes.
- * <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 position = OS.gtk_editable_get_position (entryHandle);
- OS.gtk_editable_select_region (entryHandle, position, 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];
- int /*long*/ layout = OS.gtk_entry_get_layout (entryHandle);
- OS.pango_layout_get_size (layout, w, h);
- int xborder = INNER_BORDER, yborder = 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 (arrowHandle, 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 ();
- 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);
- 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;
-
- /*
- * 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) {
- arrowHandle = 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 ();
- OS.gtk_editable_cut_clipboard (entryHandle);
-}
-
-void deregister () {
- super.deregister ();
- if (arrowHandle != 0) display.removeWidget (arrowHandle);
- display.removeWidget (entryHandle);
- 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;
-}
-
-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 (entryHandle != 0) return entryHandle;
- return super.focusHandle ();
-}
-
-boolean hasFocus () {
- if (super.hasFocus ()) return true;
- if (OS.GTK_WIDGET_HAS_FOCUS (entryHandle)) return true;
- if (OS.GTK_WIDGET_HAS_FOCUS (listHandle)) return true;
- return false;
-}
-
-void hookEvents () {
- //TODO - fix multiple enter/exit
- super.hookEvents ();
- 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);
- int eventMask = 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;
- int /*long*/ [] handles = new int /*long*/ [] {arrowHandle, 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);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_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 != entryHandle) {
- 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 OS.GTK_ENTRY_IM_CONTEXT (entryHandle);
-}
-
-/**
- * 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;
- 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();
- ignoreSelect = true;
- OS.gtk_list_unselect_all (listHandle);
- OS.gtk_entry_set_text (entryHandle, new byte[1]);
- ignoreSelect = false;
-}
-
-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 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];
- int [] end = new int [1];
- 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();
- 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();
- int /*long*/ address = OS.gtk_entry_get_text (entryHandle);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- return new String (Converter.mbcsToWcs (null, buffer));
-}
-
-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();
- return fontHeight (getFontDescription (), entryHandle != 0 ? entryHandle : handle) + 8;
-}
-
-/**
- * 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 = OS.gtk_entry_get_max_length (entryHandle);
- 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_changed (int /*long*/ widget) {
- 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_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);
- newEnd [0] = pos [0];
- }
- pos [0] = newEnd [0];
- if (newStart [0] != newEnd [0] && newEnd [0] != pos [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;
- return result;
-}
-
-int /*long*/ gtk_popup_menu (int /*long*/ widget) {
- 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;
-}
-
-/**
- * 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;
-}
-
-/**
- * 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 ();
- OS.gtk_editable_paste_clipboard (entryHandle);
-}
-
-int /*long*/ parentingHandle() {
- return fixedHandle;
-}
-
-void register () {
- super.register ();
- if (arrowHandle != 0) display.addWidget (arrowHandle, this);
- display.addWidget (entryHandle, this);
- display.addWidget (listHandle, this);
- int /*long*/ imContext = imContext ();
- if (imContext != 0) display.addWidget (imContext, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- entryHandle = listHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- 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;
- 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;
- 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();
- ignoreSelect = true;
- OS.gtk_list_clear_items (listHandle, 0, -1);
- OS.gtk_entry_set_text (entryHandle, new byte[1]);
- items = new String[0];
- 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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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;
- ignoreSelect = true;
- OS.gtk_list_select_item (listHandle, index);
- ignoreSelect = false;
-}
-
-void setBackgroundColor (GdkColor color) {
- super.setBackgroundColor (color);
- if (entryHandle != 0) 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 = resize ? getTextHeight () : height;
- return super.setBounds (x, y, width, newHeight, move, resize);
-}
-
-void setFontDescription (int /*long*/ font) {
- super.setFontDescription (font);
- if (entryHandle != 0) 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 (entryHandle != 0) OS.gtk_widget_modify_text (entryHandle, 0, color);
- if (listHandle != 0) {
- OS.gtk_widget_modify_text (listHandle, 0, 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));
- OS.gtk_widget_modify_fg (widget, OS.GTK_STATE_NORMAL, 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. This is equivalent
- * to removing the old item at the index, and then adding the new
- * item at that index.
- *
- * @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;
- ignoreSelect = true;
- byte [] buffer = Converter.wcsToMbcs (null, string, 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);
- }
- 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);
- OS.gtk_widget_modify_fg (label, OS.GTK_STATE_NORMAL, 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++;
- }
- this.items = new String [items.length];
- System.arraycopy (items, 0, this.items, 0, i);
- lockText = ignoreSelect = false;
- OS.gtk_entry_set_text (entryHandle, new byte[1]);
-}
-
-void setOrientation() {
- super.setOrientation();
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- OS.gtk_widget_set_direction (listHandle, OS.GTK_TEXT_DIR_RTL);
- OS.gtk_widget_set_direction (entryHandle, 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) {
- 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);
- OS.gtk_widget_set_direction (listHandle, dir);
- OS.gtk_widget_set_direction (entryHandle, 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);
- }
-}
-
-/**
- * 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.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>
- * 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;
- }
- /*
- * 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);
- 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);
- 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);
- OS.gtk_entry_set_max_length (entryHandle, limit);
-}
-
-void setToolTipText (Shell shell, String newString, String oldString) {
- shell.setToolTipText (entryHandle, newString, oldString);
- shell.setToolTipText (arrowHandle, newString, oldString);
-}
-
-/**
- * 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 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 38c59e16e3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java
+++ /dev/null
@@ -1,1282 +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.widgets;
-
-
-import org.eclipse.swt.*;
-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. The <code>EMBEDDED</code> style
- * is for use by other widget toolkits and should normally never be used.
- * </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
- */
-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 Widget#getStyle
- */
-public Composite (Composite parent, int style) {
- super (parent, 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);
-}
-
-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 (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 && (style & SWT.NO_FOCUS) == 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) {
- 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) {
- 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);
- gc.fillRectangle (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 {
- gc.setBackground (control.getBackground ());
- gc.fillRectangle (x, y, width, height);
- GdkColor color = new GdkColor ();
- color.pixel = values.background_pixel;
- OS.gdk_gc_set_background (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 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();
-}
-
-/**
- * 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;
- 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);
- }
- if ((state & PARENT_BACKGROUND) == 0 && (style & SWT.NO_BACKGROUND) != 0) {
- OS.g_signal_connect_closure_by_id (handle, display.signalIds [STYLE_SET], 0, display.closures [STYLE_SET], 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>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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>
- *
- * @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>
- *
- * @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.
- *
- * @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);
-}
-
-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 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 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 28561a9651..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
+++ /dev/null
@@ -1,3717 +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.widgets;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.Converter;
-import org.eclipse.swt.internal.accessibility.gtk.ATK;
-import org.eclipse.swt.internal.gtk.*;
-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>FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse,
- * DragDetect, MenuDetect</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>
- */
-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;
- String toolTipText;
- Object layoutData;
- Accessible accessible;
-
-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 Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Control (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (0);
-}
-
-int /*long*/ defaultFont () {
- return display.getSystemFont ().handle;
-}
-
-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;
- 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*/ 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 (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 it to any GtkFixed widgets
- * that are direct children of an SWT TabFolder.
- */
- int /*long*/ childStyle = parent.childStyle ();
- if (childStyle != 0) {
- OS.gtk_widget_set_style (handle, childStyle);
- }
-}
-
-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.GDK_ENTER_NOTIFY_MASK |
- OS.GDK_LEAVE_NOTIFY_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 [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false);
- OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [SCROLL_EVENT], 0, display.closures [SCROLL_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);
- }
-
- if ((state & PARENT_BACKGROUND) != 0) {
- OS.g_signal_connect_closure_by_id (handle, 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);
-}
-
-/**
- * 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);
-}
-
-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 ();
-}
-
-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;
-}
-
-int /*long*/ childStyle () {
- return parent.childStyle ();
-}
-
-void createWidget (int index) {
- checkOrientation (parent);
- super.createWidget (index);
- checkBackground ();
- checkBuffered ();
- showWidget ();
- setInitialBounds ();
- setZOrder (null, false, false);
- setRelations ();
- 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 ();
- OS.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 ();
- OS.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 ();
- int flags = OS.GTK_WIDGET_FLAGS (topHandle);
- OS.GTK_WIDGET_SET_FLAGS (topHandle, OS.GTK_VISIBLE);
- GtkRequisition requisition = new GtkRequisition ();
- OS.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);
- if ((flags & OS.GTK_VISIBLE) == 0) {
- OS.GTK_WIDGET_UNSET_FLAGS (topHandle, OS.GTK_VISIBLE);
- }
-}
-
-/**
- * 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);
- 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 moveHandle (int x, int y) {
- int /*long*/ topHandle = topHandle ();
- int /*long*/ parentHandle = parent.parentingHandle ();
- OS.gtk_fixed_move (parentHandle, topHandle, x, y);
-}
-
-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 ();
- int flags = OS.GTK_WIDGET_FLAGS (topHandle);
- OS.GTK_WIDGET_SET_FLAGS (topHandle, OS.GTK_VISIBLE);
- 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);
- }
- }
- 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 && !(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 ();
- OS.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);
- }
- if ((flags & OS.GTK_VISIBLE) == 0) {
- OS.GTK_WIDGET_UNSET_FLAGS (topHandle, OS.GTK_VISIBLE);
- }
- /*
- * 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);
- }
- }
- }
- 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);
- }
- 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);
- 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);
-}
-
-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);
-}
-
-/*
- * 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;
-}
-
-/**
- * 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);
-}
-
-/**
- * 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);
- return new Point (x - origin_x [0], y - origin_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();
- 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);
- return new Point (origin_x [0] + x, origin_y [0] + 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 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.
- *
- * @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 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 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 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 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 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);
-}
-
-boolean dragDetect (int x, int y) {
- return hooks (SWT.DragDetect);
-}
-
-boolean dragOverride () {
- return false;
-}
-
-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;
-}
-
-/**
- * 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) {
- 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) 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.
- *
- * @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;
-}
-
-/**
- * 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();
- if (font != null) return font;
- return Font.gtk_new (display, 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;
- 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 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) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- if (gdkEvent.type == OS.GDK_3BUTTON_PRESS) return 0;
- Shell shell = _getShell ();
- if ((shell.style & SWT.ON_TOP) != 0) shell.forceActive ();
- display.dragStartX = (int) gdkEvent.x;
- display.dragStartY = (int) gdkEvent.y;
- display.dragging = display.dragOverride = false;
- int type = gdkEvent.type != OS.GDK_2BUTTON_PRESS ? SWT.MouseDown : SWT.MouseDoubleClick;
- int /*long*/ result = sendMouseEvent (type, gdkEvent.button, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
- if (isDisposed ()) return 1;
- if (gdkEvent.button == 1 && gdkEvent.type == OS.GDK_BUTTON_PRESS) {
- display.dragOverride = dragOverride () && dragDetect (display.dragStartX, display.dragStartY);
- if (display.dragOverride) result = 1;
- }
- if ((state & MENU) != 0) {
- if (gdkEvent.button == 3 && gdkEvent.type == OS.GDK_BUTTON_PRESS) {
- if (showMenu ((int)gdkEvent.x_root, (int)gdkEvent.y_root)) {
- result = 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, 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) {
- 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;
- if (gdkEvent.subwindow != 0) return 0;
- return sendMouseEvent (SWT.MouseEnter, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
-}
-
-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;
- 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 (widget != focusHandle ()) break;
- GdkEventFocus gdkEventFocus = new GdkEventFocus ();
- OS.memmove (gdkEventFocus, gdkEvent, GdkEventFocus.sizeof);
- 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;
- 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) {
- display.removeMouseHoverTimeout (handle);
- 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;
- if (gdkEvent.subwindow != 0) return 0;
- return sendMouseEvent (SWT.MouseExit, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1;
-}
-
-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 (!display.dragging) {
- if ((gdkEvent.state & OS.GDK_BUTTON1_MASK) != 0) {
- if (dragDetect (display.dragStartX, display.dragStartY)) {
- if (OS.gtk_drag_check_threshold (handle, display.dragStartX, display.dragStartY, (int) gdkEvent.x, (int) gdkEvent.y)) {
- display.dragging = true;
- sendDragEvent (display.dragStartX, display.dragStartY);
- if (isDisposed ()) return 1;
- }
- }
- }
- }
- if (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;
- if (display.dragOverride) result = 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);
- showMenu (x [0], y [0]);
- return 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 ((state & PARENT_BACKGROUND) != 0 && (state & BACKGROUND) == 0 && backgroundImage == null) {
- setParentBackground ();
- }
- 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 ((state & PARENT_BACKGROUND) != 0 && (state & BACKGROUND) == 0 && backgroundImage == null) {
- setParentBackground ();
- }
- 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;
-}
-
-/**
- * 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);
- }
- 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.handle : 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 = 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();
- if (this == display.focusControl) return true;
- 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
- */
-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
- */
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget();
- if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return;
- 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 ();
- 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;
-}
-
-boolean sendDragEvent (int x, int y) {
- Event event = new Event ();
- event.x = x;
- event.y = y;
- 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 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];
- }
- 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.
- *
- * @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);
- OS.gtk_widget_modify_style (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.
- *
- * @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.
- *
- * @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);
- }
- }
-}
-
-/**
- * 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.parentingHandle ();
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (parentHandle);
- Rectangle rect = getBounds ();
- GdkWindowAttr attributes = new GdkWindowAttr ();
- attributes.x = rect.x;
- attributes.y = rect.y;
- 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, OS.GDK_WA_X | OS.GDK_WA_Y);
- if (enableWindow != 0) {
- int /*long*/ topHandle = topHandle ();
- 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 ();
- } 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.
- *
- * @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) {
- OS.gtk_widget_modify_fg (handle, OS.GTK_STATE_NORMAL, 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 ();
- 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;
- 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*/ topHandle = topHandle ();
- int /*long*/ newParent = parent.parentingHandle();
- int x = OS.GTK_WIDGET_X (topHandle);
- int y = OS.GTK_WIDGET_Y (topHandle);
- 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 () {
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (handle);
- if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, true);
- if (fixedHandle != 0) {
- window = OS.GTK_WIDGET_WINDOW (fixedHandle);
- if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, true);
- }
-}
-
-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 setTabGroupFocus (boolean next) {
- return setTabItemFocus (next);
-}
-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 no tool tip text should be shown.
- *
- * @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);
- toolTipText = string;
-}
-
-void setToolTipText (Shell shell, String newString, String oldString) {
- shell.setToolTipText (eventHandle (), newString, oldString);
-}
-
-/**
- * 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);
- OS.gtk_widget_modify_style (fixedHandle, style);
- }
- int /*long*/ style = OS.gtk_widget_get_modifier_style (handle);
- OS.gtk_widget_modify_style (handle, style);
-}
-
-boolean 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 ()) {
- 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;
- 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 ();
- 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 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.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 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);
-}
-
-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/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 1d7a2dd445..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java
+++ /dev/null
@@ -1,750 +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.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
- */
-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;
-}
-
-Control 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
- */
-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 0509b84ead..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java
+++ /dev/null
@@ -1,284 +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.*;
-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>
- */
-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.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.
- * </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, 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 ();
- int /*long*/ 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);
- 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);
- OS.gtk_file_chooser_set_current_folder (handle, buffer);
- }
- 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;
- int response = OS.gtk_dialog_run (handle);
- 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.substring (answer.lastIndexOf (SEPARATOR) + 1);
- }
- }
- }
- }
- 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);
- }
- }
- 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);
- }
- int response = OS.gtk_dialog_run (handle);
- 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);
- }
- }
- 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 7a884ff559..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
+++ /dev/null
@@ -1,3819 +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.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</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
- */
-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";
- static final String DISPATCH_EVENT_KEY = "org.eclipse.swt.internal.gtk.dispatchEvent";
- static final String ADD_WIDGET_KEY = "org.eclipse.swt.internal.addWidget";
- int /*long*/ [] closures;
- int [] signalIds;
- int /*long*/ shellMapProcClosure;
-
- /* Widget Table */
- int freeSlot;
- int [] indexTable;
- 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);
- SWT_OBJECT_INDEX = OS.g_quark_from_string (buffer);
- buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX1", true);
- SWT_OBJECT_INDEX1 = OS.g_quark_from_string (buffer);
- buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX2", true);
- SWT_OBJECT_INDEX2 = OS.g_quark_from_string (buffer);
- }
-
- /* Focus */
- int focusEvent;
- Control focusControl;
- Shell activeShell;
- boolean activePending;
-
- /* 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;
-
- /* Shell map callback */
- int /*long*/ shellMapProc;
- Callback shellMapCallback;
-
- /* GtkTreeView callbacks */
- int[] treeSelection;
- int treeSelectionLength;
- int /*long*/ treeSelectionProc;
- Callback treeSelectionCallback;
- int /*long*/ cellDataProc;
- Callback cellDataCallback;
-
- /* Set direction callback */
- int /*long*/ setDirectionProc;
- Callback setDirectionCallback;
-
- /* Settings callbacks */
- int /*long*/ styleSetProc;
- Callback styleSetCallback;
- int /*long*/ shellHandle;
- boolean settingsChanged, runSettings;
-
- /* Entry focus behaviour */
- boolean entrySelectOnFocus;
-
- /* 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];
-
- /* Drag Detect */
- int dragStartX,dragStartY;
- boolean dragging, dragOverride;
-
- /* 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;
-
- /* Timestamp of the Last Received Events */
- int lastEventTime, lastUserEventTime;
-
- /* Fixed Subclass */
- static int /*long*/ fixed_type;
- static int /*long*/ fixed_info_ptr;
- static Callback fixedClassInitCallback, fixedMapCallback;
- static int /*long*/ fixedClassInitProc, fixedMapProc;
-
- /* 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.";
- /* 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);
-// }
-
- /*
- * In order to support CLDC, .class cannot be used because
- * it does not compile on some Java compilers when they are
- * targeted for CLDC. Use Class.forName() instead.
- */
- static final Class OS_LOCK;
- static {
- Class lock = null;
- try {
- lock = Class.forName ("org.eclipse.swt.internal.gtk.OS");
- } catch (Throwable th) {
- }
- OS_LOCK = lock;
- }
-
- /* GTK Version */
- static final int MAJOR = 2;
- static final int MINOR = 0;
- static final int MICRO = 6;
-
- /* 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++;
-}
-
-/**
- * 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 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) {
- 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 () {
- 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 synchronized void checkDisplay (Thread thread, boolean multiple) {
- 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);
- }
- }
-}
-
-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);
-}
-
-/**
- * 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 ();
- if (Default == null) Default = this;
-}
-
-synchronized 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]");
- }
- 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)));
- System.out.println ("***WARNING: SWT requires GTK " + MAJOR+ "." + MINOR + "." + MICRO);
- int major = OS.gtk_major_version (), minor = OS.gtk_minor_version (), micro = OS.gtk_micro_version ();
- System.out.println ("***WARNING: Detected: " + major + "." + minor + "." + micro);
- }
- if (fixed_type == 0) {
- byte [] type_name = Converter.wcsToMbcs (null, "SwtFixed", true);
- fixedClassInitCallback = new Callback (getClass (), "fixedClassInitProc", 2);
- fixedClassInitProc = fixedClassInitCallback.getAddress ();
- if (fixedClassInitProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- fixedMapCallback = new Callback (getClass (), "fixedMapProc", 1);
- fixedMapProc = fixedMapCallback.getAddress ();
- if (fixedMapProc == 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);
- rendererClassInitProc = rendererClassInitCallback.getAddress ();
- if (rendererClassInitProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- }
- if (rendererRenderProc == 0) {
- rendererRenderCallback = new Callback (getClass (), "rendererRenderProc", 7);
- rendererRenderProc = rendererRenderCallback.getAddress ();
- if (rendererRenderProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- }
- if (rendererGetSizeProc == 0) {
- rendererGetSizeCallback = new Callback (getClass (), "rendererGetSizeProc", 7);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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;
-}
-
-synchronized void deregister () {
- for (int i=0; i<Displays.length; i++) {
- if (this == 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 ();
- destroyDisplay ();
-}
-
-void destroyDisplay () {
-}
-
-/**
- * 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 synchronized Display findDisplay (Thread thread) {
- 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;
- }
-
- Control control = null;
- int /*long*/ window = 0;
- switch (eventType) {
- case OS.GDK_KEY_PRESS:
- case OS.GDK_KEY_RELEASE:
- case OS.GDK_ENTER_NOTIFY:
- case OS.GDK_LEAVE_NOTIFY:
- case OS.GDK_BUTTON_PRESS:
- case OS.GDK_2BUTTON_PRESS:
- case OS.GDK_3BUTTON_PRESS:
- case OS.GDK_BUTTON_RELEASE:
- case OS.GDK_MOTION_NOTIFY: {
- window = OS.GDK_EVENT_WINDOW (event);
- int /*long*/ [] user_data = new int /*long*/ [1];
- do {
- OS.gdk_window_get_user_data (window, user_data);
- int /*long*/ handle = user_data [0];
- if (handle != 0) {
- Widget widget = getWidget (handle);
- if (widget != null && widget instanceof Control) {
- control = (Control) widget;
- break;
- }
- }
- } while ((window = OS.gdk_window_get_parent (window)) != 0);
- }
- }
- Shell shell = null;
- if (control != null ) {
- shell = control.getShell ();
- if ((shell.style & SWT.ON_TOP) != 0) {
- OS.gtk_grab_add (shell.shellHandle);
- }
- }
- OS.gtk_main_do_event (event);
- if (dispatchEvents == null) putGdkEvents ();
- if (control != null ) {
- if (shell != null && !shell.isDisposed () && (shell.style & SWT.ON_TOP) != 0) {
- OS.gtk_grab_remove (shell.shellHandle);
- }
- }
- 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 id) {
- 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;
- 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*/ 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.
- *
- * @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 synchronized Display getCurrent () {
- Thread current = Thread.currentThread ();
- for (int i=0; i<Displays.length; i++) {
- Display display = Displays [i];
- if (display != null && display.thread == current) return display;
- }
- return null;
-}
-
-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*/ window = OS.gdk_window_at_pointer (x,y);
- if (window == 0) return null;
- int /*long*/ [] user_data = new int /*long*/ [1];
- OS.gdk_window_get_user_data (window, user_data);
- int /*long*/ handle = user_data [0];
- 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;
-}
-
-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;
- }
- }
- }
- return 0;
-}
-
-/**
- * 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 (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 synchronized Display getDefault () {
- 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 ();
- 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 ();
- 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 ();
-}
-
-/**
- * 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);
- 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;
-}
-
-/**
- * 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 () {
- 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");
- }
- return errorImage;
- case SWT.ICON_INFORMATION:
- case SWT.ICON_WORKING:
- if (infoImage == null) {
- infoImage = createImage ("gtk-dialog-info");
- }
- return infoImage;
- case SWT.ICON_QUESTION:
- if (questionImage == null) {
- questionImage = createImage ("gtk-dialog-question");
- }
- return questionImage;
- case SWT.ICON_WARNING:
- if (warningImage == null) {
- warningImage = createImage ("gtk-dialog-warning");
- }
- 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);
- 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 () {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return thread;
-}
-
-Widget getWidget (int /*long*/ handle) {
- if (handle == 0) return null;
- int /*long*/ index = OS.g_object_get_qdata (handle, SWT_OBJECT_INDEX) - 1;
- if (0 <= index && index < widgetTable.length) return widgetTable [(int)/*64*/index];
- return null;
-}
-
-/**
- * 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 ();
- 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);
- 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.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.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);
- 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.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);
-
- windowCallback4 = new Callback (this, "windowProc", 4);
- 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.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);
-
- windowCallback5 = new Callback (this, "windowProc", 5);
- 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);
- timerProc = timerCallback.getAddress ();
- if (timerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- windowTimerCallback = new Callback (this, "windowTimerProc", 1);
- windowTimerProc = windowTimerCallback.getAddress ();
- if (windowTimerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- mouseHoverCallback = new Callback (this, "mouseHoverProc", 1);
- mouseHoverProc = mouseHoverCallback.getAddress ();
- if (mouseHoverProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- caretCallback = new Callback(this, "caretProc", 1);
- caretProc = caretCallback.getAddress();
- if (caretProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- menuPositionCallback = new Callback(this, "menuPositionProc", 5);
- menuPositionProc = menuPositionCallback.getAddress();
- if (menuPositionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- sizeAllocateCallback = new Callback(this, "sizeAllocateProc", 3);
- sizeAllocateProc = sizeAllocateCallback.getAddress();
- if (sizeAllocateProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- shellMapCallback = new Callback(this, "shellMapProc", 3);
- 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);
- treeSelectionProc = treeSelectionCallback.getAddress();
- if (treeSelectionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- cellDataCallback = new Callback (this, "cellDataProc", 5);
- cellDataProc = cellDataCallback.getAddress ();
- if (cellDataProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- setDirectionCallback = new Callback (this, "setDirectionProc", 2);
- setDirectionProc = setDirectionCallback.getAddress ();
- if (setDirectionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- checkIfEventCallback = new Callback (this, "checkIfEventProc", 3);
- checkIfEventProc = checkIfEventCallback.getAddress ();
- if (checkIfEventProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-}
-
-void initializeSystemSettings () {
- styleSetCallback = new Callback (this, "styleSetProc", 3);
- 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 = "";
- 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 ().handle;
- }
- 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 != 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);
- 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];
- }
- 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 != 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);
- 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];
- }
- return rect;
-}
-
-int /*long*/ mouseHoverProc (int /*long*/ handle) {
- Widget widget = getWidget (handle);
- if (widget == null) return 0;
- return widget.hoverProc (handle);
-}
-
-/**
- * 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>
- * </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) {
- 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 = wcsToMbcs (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;
- if (button < 1 || button > 3) return false;
- OS.XTestFakeButtonEvent (xDisplay, button, type == SWT.MouseDown, 0);
- }
- return true;
- }
- }
- 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 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 runAsyncMessages (false);
-}
-
-synchronized void register () {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] == null) {
- Displays [i] = this;
- return;
- }
- }
- Display [] newDisplays = new Display [Displays.length + 4];
- System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
- newDisplays [Displays.length] = this;
- 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 */
- 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;
-
- /* Dispose the shell map callback */
- shellMapCallback.dispose (); shellMapCallback = null;
- shellMapProc = 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 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_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;
-
- /* Release the sleep resources */
- max_priority = timeout = null;
- if (fds != 0) OS.g_free (fds);
- fds = 0;
-
- popups = null;
- thread = null;
- activeShell = 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;
-}
-
-/**
- * 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 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 #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;
- 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 () {
- /*
- * 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 ()) {
- 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 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 ();
- 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.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 (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);
- }
- }
-
- /* 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_CONTAINER (widget)) {
- OS.gtk_container_forall (widget, setDirectionProc, direction);
- }
- return 0;
-}
-
-/**
- * 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 (this.synchronizer != null) {
- this.synchronizer.runAsyncMessages(true);
- }
- this.synchronizer = synchronizer;
-}
-
-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 ());
- OS.gtk_widget_modify_fg (preeditLabel, OS.GTK_STATE_NORMAL, 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*/ 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 occured when executing the runnable</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void syncExec (Runnable runnable) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- 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 () {
- 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 bf57ea4dbe..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java
+++ /dev/null
@@ -1,705 +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.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
- *
- * @since 3.2
- */
-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 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);
- int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER;
- OS.gtk_scrolled_window_set_policy (scrolledHandle, OS.GTK_POLICY_NEVER, vsp);
- OS.gtk_container_add (fixedHandle, scrolledHandle);
- OS.gtk_scrolled_window_add_with_viewport (scrolledHandle, handle);
- } 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();
-}
-
-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*/ 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.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 4f6221c6e9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
+++ /dev/null
@@ -1,601 +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.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
- *
- * @since 3.2
- */
-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)) {
- int /*long*/ widget = OS.gtk_expander_get_label_widget (handle);
- return OS.GTK_WIDGET_HEIGHT (widget);
- }
- 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;
-}
-
-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);
- }
-}
-
-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;
- 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) {
- OS.gtk_widget_modify_fg (handle, OS.GTK_STATE_NORMAL, color);
- if (labelHandle != 0) OS.gtk_widget_modify_fg (labelHandle, OS.GTK_STATE_NORMAL, color);
- if (imageHandle != 0) OS.gtk_widget_modify_fg (imageHandle, OS.GTK_STATE_NORMAL, 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 ();
- }
- }
-}
-
-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);
-}
-} \ No newline at end of file
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 5d7698d390..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java
+++ /dev/null
@@ -1,514 +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.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>
- */
-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 /*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.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.
- * </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 FileDialog (Shell parent, int style) {
- super (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 = 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 = 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*/ 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);
- fullPath = new String (chars);
- fileNames = new String [1];
- fileNames[0] = fullPath.substring (fullPath.lastIndexOf (SEPARATOR) + 1);
- }
- }
- }
- }
- if (fullPath != null) {
- int separatorIndex = fullPath.lastIndexOf (SEPARATOR);
- fileName = fullPath.substring (separatorIndex + 1);
- filterPath = fullPath.substring (0, separatorIndex);
- }
- return fullPath;
-}
-String computeResultClassicDialog () {
- 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;
-}
-/**
- * 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;
-}
-/**
- * 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 ();
- 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);
- 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);
- }
- presetChooserDialog ();
- String answer = null;
- if (OS.gtk_dialog_run (handle) == OS.GTK_RESPONSE_OK) {
- answer = computeResultChooserDialog ();
- }
- 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);
- }
- }
- presetClassicDialog ();
- String answer = null;
- if (OS.gtk_dialog_run (handle) == OS.GTK_RESPONSE_OK) {
- answer = computeResultClassicDialog ();
- }
- 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 (filterPath.length () > 0) {
- StringBuffer stringBuffer = new StringBuffer ();
- /* filename must be a full path */
- if (filterPath.charAt (0) != SEPARATOR) {
- stringBuffer.append (SEPARATOR);
- }
- stringBuffer.append (filterPath);
- if (filterPath.charAt (filterPath.length () - 1) != SEPARATOR) {
- stringBuffer.append (SEPARATOR);
- }
- if (fileName.length () > 0) {
- stringBuffer.append (fileName);
- } else {
- /* go into the specified directory */
- stringBuffer.append ('.');
- }
- byte [] buffer = Converter.wcsToMbcs (null, stringBuffer.toString (), true);
- OS.gtk_file_chooser_set_filename (handle, buffer);
- }
- if ((style & SWT.SAVE) != 0 && fileName.length () > 0) {
- byte [] buffer = Converter.wcsToMbcs (null, fileName, true);
- OS.gtk_file_chooser_set_current_name (handle, buffer);
- }
-
- /* Set the extension filters */
- if (filterNames == null) filterNames = new String [0];
- if (filterExtensions == null) filterExtensions = new String [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);
- }
- }
- 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
- * Windows, an extension filter string is typically of
- * the form "*.extension", where "*.*" matches all files.
- * </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;
-}
-/**
- * Sets the 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;
-}
-}
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 6759457d19..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java
+++ /dev/null
@@ -1,220 +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.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>
- */
-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.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.
- * </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, 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);
- 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);
- }
- }
- if (fontData != null) {
- Display display = parent != null ? parent.display : Display.getCurrent ();
- 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);
- }
- int response = OS.gtk_dialog_run(handle);
- 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);
- Display display = parent != null ? parent.display : Display.getCurrent ();
- Font font = Font.gtk_new (display, fontDesc);
- fontData = font.getFontData () [0];
- OS.pango_font_description_free (fontDesc);
- }
- 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 3c87319357..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java
+++ /dev/null
@@ -1,288 +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.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>
- */
-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);
- OS.gtk_widget_modify_fg (labelHandle, OS.GTK_STATE_NORMAL, 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/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 8d277bdd25..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
+++ /dev/null
@@ -1,570 +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.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.
- * <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>
- */
-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;
- }
- }
- boolean fixWrap = labelHandle != 0 && (style & SWT.WRAP) != 0;
- if (fixWrap || frameHandle != 0) forceResize ();
- int [] labelWidth = new int [1], labelHeight = new int [1];
- if (fixWrap) {
- OS.gtk_widget_get_size_request (labelHandle, labelWidth, labelHeight);
- OS.gtk_widget_set_size_request (labelHandle, wHint, hHint);
- }
- Point size;
- 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);
- }
- if (fixWrap) {
- OS.gtk_widget_set_size_request (labelHandle, labelWidth [0], labelHeight [0]);
- }
- /*
- * 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 ((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 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);
- boolean isRTL = (style & SWT.RIGHT_TO_LEFT) != 0;
- if ((style & SWT.LEFT) != 0) {
- OS.gtk_misc_set_alignment (labelHandle, 0.0f, 0.0f);
- OS.gtk_label_set_justify (labelHandle, isRTL ? OS.GTK_JUSTIFY_RIGHT : 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, isRTL ? OS.GTK_JUSTIFY_LEFT : 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);
- OS.gtk_widget_modify_fg (fixedHandle, OS.GTK_STATE_NORMAL, color);
- if (labelHandle != 0) OS.gtk_widget_modify_fg (labelHandle, OS.GTK_STATE_NORMAL, color);
- if (imageHandle != 0) OS.gtk_widget_modify_fg (imageHandle, OS.GTK_STATE_NORMAL, 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);
- if ((style & SWT.LEAD) != 0) {
- if (labelHandle != 0) OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_RIGHT);
- }
- if ((style & SWT.TRAIL) != 0) {
- if (labelHandle != 0) OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_LEFT);
- }
- }
-}
-
-/**
- * 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 555f726751..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java
+++ /dev/null
@@ -1,717 +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.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>
- *
- * @since 3.1
- */
-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 sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected.
- * <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);
- 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 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;
-}
-
-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;
- 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;
- 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;
- 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 ((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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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, linkStart, index, 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 tag can be used to distinguish between them. The string may
- * include the mnemonic character and line delimiters.
- * </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 ();
-}
-
-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 dad63df7e1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java
+++ /dev/null
@@ -1,1539 +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.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>
- */
-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 receiver's selection changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
-}
-
-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);
-}
-
-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_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 visibility 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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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;
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- OS.gtk_widget_modify_text (handle, 0, color);
-}
-
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument. This is equivalent
- * to <code>remove</code>'ing the old item at the index, and then
- * <code>add</code>'ing the new item at that index.
- *
- * @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 9846552332..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
+++ /dev/null
@@ -1,933 +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.*;
-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>
- */
-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.
- *
- * @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>
- *
- * @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 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.
- *
- * @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.
- *
- * @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);
-}
-
-public void _setVisible (boolean visible) {
- if (visible == OS.GTK_WIDGET_MAPPED (handle)) return;
- if (visible) {
- sendEvent (SWT.Show);
- if (getItemCount () != 0) {
- 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) {
- display.activeShell = getShell ();
- }
- sendEvent (SWT.Hide);
- return 0;
-}
-
-int /*long*/ gtk_show (int /*long*/ widget) {
- if ((style & SWT.POP_UP) != 0) {
- 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 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 (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 ();
- 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 - requisition.height >= 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 11e947867a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
+++ /dev/null
@@ -1,870 +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.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>
- */
-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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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;
-}
-
-/**
- * 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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).
- * </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) {
- accelString = string.substring (index, string.length());
- 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;
- 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 7ba29bc34c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,191 +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.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>
- */
-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>
- */
-public MessageBox (Shell parent, int style) {
- super(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);
- }
- }
- createButtons();
- buffer = Converter.wcsToMbcs(null, title, true);
- OS.gtk_window_set_title(handle,buffer);
- int result = OS.gtk_dialog_run(handle);
- OS.gtk_widget_destroy(handle);
- return result;
-}
-
-private void createButtons() {
- if ((style & SWT.OK) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-ok", true), SWT.OK);
- if ((style & SWT.CANCEL) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-cancel", true), SWT.CANCEL);
- 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.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.IGNORE) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Ignore"), true), SWT.IGNORE);
-}
-
-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 e8f9c61cbb..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,243 +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.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * Instances of the receiver represent is 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>
- */
-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 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;
-}
-
-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;
-}
-
-/**
- * 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);
-}
-
-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.
- */
- OS.gdk_flush ();
- int /*long*/ window = paintWindow ();
- OS.gdk_window_process_updates (window, false);
-}
-}
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 0134c1be91..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,428 +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.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>
- */
-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 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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;
- }
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return 0;
- if (event.doit) {
- dragging = true;
- lastX = event.x;
- lastY = event.y;
- parent.update (true, (style & SWT.SMOOTH) == 0);
- 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 /*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);
- 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;
- 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 ((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;
- }
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return 0;
- if (event.doit) {
- lastX = event.x;
- lastY = event.y;
- }
- parent.update (true, (style & SWT.SMOOTH) == 0);
- drawBand (lastX, lastY, width, height);
- if ((style & SWT.SMOOTH) != 0) {
- setBounds (lastX, 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 2fe42efb04..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,372 +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.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>
- */
-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 receiver's value changes, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control's value changes.
- * <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 receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 3f4b7df339..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,700 +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.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
- */
-public class ScrollBar extends Widget {
- Scrollable parent;
- int /*long*/ adjustmentHandle;
- int detail;
-
-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 receiver's value changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
-}
-
-/**
- * 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_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 ();
- 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;
- postEvent (SWT.Selection, event);
- parent.updateScrollBarValue (this);
- return 0;
-}
-
-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);
-}
-
-/**
- * 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 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 receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
-}
-
-/**
- * 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 ();
- parent.setScrollBarVisible (this, visible);
-}
-
-}
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 7e7480f73f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,372 +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.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>
- */
-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.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);
-}
-
-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;
-}
-
-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]);
- bar.sendEvent (visible ? SWT.Show : SWT.Hide);
- sendEvent (SWT.Resize);
- 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) {
- parent.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 f742cfebdc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,1691 +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.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</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
- */
-public class Shell extends Decorations {
- int /*long*/ shellHandle, tooltipsHandle, tooltipWindow;
- boolean mapped, moved, resized, opened;
- int oldX, oldY, oldWidth, oldHeight;
- int minWidth, minHeight;
- Control lastActive;
- Region region;
-
- 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#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
-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#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
-public Shell (Display display, int style) {
- this (display, null, style, 0);
-}
-
-Shell (Display display, Shell parent, int style, int /*long*/ handle) {
- 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.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
- */
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.display : null, parent, style, 0);
-}
-
-public static Shell gtk_new (Display display, int /*long*/ handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle);
-}
-
-static int checkStyle (int style) {
- style = Decorations.checkStyle (style);
- if ((style & SWT.ON_TOP) != 0) style &= ~SWT.SHELL_TRIM;
- 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;
-}
-
-/**
- * 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 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 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.RESIZE)) == 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 (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);
- }
- }
- /*
- * 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.RESIZE)) == 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);
- }
- int bits = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- boolean modal = (style & bits) != 0;
- //TEMPORARY CODE
- if ((style & SWT.ON_TOP) == 0) modal |= (parent != null && (parent.style & bits) != 0);
- OS.gtk_window_set_modal (shellHandle, modal);
- /*
- * 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);
-}
-
-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 [MAP_EVENT], 0, display.closures [MAP_EVENT], false);
- OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [UNMAP_EVENT], 0, display.closures [UNMAP_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 [FOCUS_IN_EVENT], 0, display.closures [FOCUS_IN_EVENT], false);
- OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_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);
-}
-
-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, toolTipText);
- control.setToolTipText (newShell, toolTipText, null);
- }
-}
-
-void fixStyle (int /*long*/ handle) {
-}
-
-void forceResize () {
- forceResize (OS.GTK_WIDGET_WIDTH (vboxHandle), OS.GTK_WIDGET_HEIGHT (vboxHandle));
-}
-
-void forceResize (int width, int height) {
- int flags = OS.GTK_WIDGET_FLAGS (vboxHandle);
- OS.GTK_WIDGET_SET_FLAGS (vboxHandle, OS.GTK_VISIBLE);
- GtkRequisition requisition = new GtkRequisition ();
- OS.gtk_widget_size_request (vboxHandle, requisition);
- GtkAllocation allocation = new GtkAllocation ();
- allocation.width = width;
- allocation.height = height;
- OS.gtk_widget_size_allocate (vboxHandle, allocation);
- if ((flags & OS.GTK_VISIBLE) == 0) {
- OS.GTK_WIDGET_UNSET_FLAGS (vboxHandle, OS.GTK_VISIBLE);
- }
-}
-
-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]);
-}
-
-/**
- * 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);
-}
-
-public Point getSize () {
- checkWidget ();
- int width = OS.GTK_WIDGET_WIDTH (vboxHandle);
- int height = OS.GTK_WIDGET_HEIGHT (vboxHandle);
- return new Point (width + trimWidth (), height + trimHeight ());
-}
-
-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 () {
- 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
- * descendents 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_focus_in_event (int /*long*/ widget, int /*long*/ event) {
- if (widget != shellHandle) {
- return super.gtk_focus_in_event (widget, event);
- }
- if (tooltipsHandle != 0) OS.gtk_tooltips_enable (tooltipsHandle);
- display.activeShell = this;
- display.activePending = false;
- sendEvent (SWT.Activate);
- return 0;
-}
-
-int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) {
- if (widget != shellHandle) {
- return super.gtk_focus_out_event (widget, event);
- }
- 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;
- }
- return 0;
-}
-
-int /*long*/ gtk_map_event (int /*long*/ widget, int /*long*/ event) {
- minimized = false;
- sendEvent (SWT.Deiconify);
- return 0;
-}
-
-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_unmap_event (int /*long*/ widget, int /*long*/ event) {
- minimized = true;
- sendEvent (SWT.Iconify);
- return 0;
-}
-
-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;
- 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
- * @see Shell#setActive
- * @see Shell#forceActive
- */
-public void open () {
- checkWidget ();
- bringToTop (false);
- setVisible (true);
- if (isDisposed ()) return;
- if (!restoreFocus () && !traverseGroup (true)) setFocus ();
-}
-
-/**
- * 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
- * @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);
- }
- }
-}
-
-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) {
- /*
- * 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 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 () {
- Monitor monitor = getMonitor ();
- Rectangle rect = monitor.getClientArea ();
- int width = rect.width * 5 / 8;
- int height = rect.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 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);
- int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle);
- int /*long*/ shape_region = (region == null) ? 0 : region.handle;
- OS.gdk_window_shape_combine_region (window, shape_region, 0, 0);
- this.region = 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();
- if ((OS.GTK_WIDGET_MAPPED (shellHandle) == visible)) return;
- if (visible) {
- 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.
- */
- if (!OS.GTK_IS_PLUG (shellHandle)) {
- mapped = false;
- OS.gtk_widget_show (shellHandle);
- 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;
-
- int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- 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 () {
- 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 [] x = new int [1], y = new int [1];
- OS.gdk_window_get_pointer (0, x, y, null);
- OS.gtk_window_move (handle, x [0], y [0] + 16);
- 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;
- 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;
- 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 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
- * @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);
- return new Rectangle (x [0], y [0], width + trimWidth (), height + trimHeight ());
-}
-
-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);
- }
- }
- super.releaseChildren (destroy);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- destroyAccelGroup ();
- if (display.activeShell == this) display.activeShell = null;
- if (tooltipsHandle != 0) OS.g_object_unref (tooltipsHandle);
- tooltipsHandle = 0;
- region = null;
- lastActive = null;
-}
-
-void setToolTipText (int /*long*/ widget, String newString, String oldString) {
- byte [] buffer = null;
- if (newString != null && newString.length () > 0) {
- buffer = Converter.wcsToMbcs (null, newString, 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;
- }
- OS.gtk_tooltips_set_tip (tooltipsHandle, widget, buffer, null);
-
- /*
- * Bug in GTK. If the cursor is inside the window when a new
- * tooltip is set and the old tooltip is null, the new tooltip
- * is not displayed until the mouse enters the window. The
- * fix is to cause and enter/leave event to happen by creating
- * a temporary INPUT_ONLY GDK window.
- */
- if ((OS.GTK_WIDGET_FLAGS (widget) & OS.GTK_REALIZED) == 0) return;
- if ((OS.GTK_WIDGET_FLAGS (widget) & OS.GTK_VISIBLE) == 0) return;
- if (oldString == null || oldString.length () == 0) {
- if (newString != null && newString.length () != 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 (widget == user_data [0]) {
- int /*long*/ data = OS.gtk_tooltips_data_get (widget);
- OS.GTK_TOOLTIPS_SET_ACTIVE (tooltipsHandle, data);
- OS.gtk_tooltips_set_tip (tooltipsHandle, widget, 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 3e0881dc59..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,568 +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.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
- */
-public class Slider extends Control {
- int detail;
-
-/**
- * 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 receiver's value changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
- OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS);
- OS.gtk_container_add (fixedHandle, handle);
-}
-
-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 ();
- 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;
- postEvent (SWT.Selection, event);
- return 0;
-}
-
-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 receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 96b3b722e6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,1068 +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.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>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, Modify</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @since 3.1
- */
-public class Spinner extends Composite {
- static final int INNER_BORDER = 2;
- static final int MIN_ARROW_WIDTH = 6;
- int lastEventTime = 0;
- int /*long*/ gdkEventKey = 0;
- int fixStart = -1, fixEnd = -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#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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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];
- 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);
- }
- xborder += INNER_BORDER;
- yborder += INNER_BORDER;
- 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));
- 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);
-}
-
-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);
- for (int i = 0; i < digits; i++) adjustment.step_increment *= 10;
- 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_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;
- 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_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.lower *= 10;
- return (int) adjustment.lower;
-}
-
-/**
- * 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);
- for (int i = 0; i < digits; i++) adjustment.page_increment *= 10;
- return (int) adjustment.page_increment;
-}
-
-/**
- * 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);
- for (int i = 0; i < digits; i++) adjustment.value *= 10;
- return (int) adjustment.value;
-}
-
-/**
- * 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) {
- /*
- * 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);
- newEnd [0] = pos [0];
- }
- pos [0] = newEnd [0];
- if (newStart [0] != newEnd [0] && newEnd [0] != pos [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_popup_menu (int /*long*/ widget) {
- 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_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);
- 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- OS.gtk_widget_modify_text (handle, 0, 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;
- 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 ();
- if (value < 0) 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;
- 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 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 /*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 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 (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);
- 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 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;
- }
- 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 f80924f5ed..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,686 +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.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>
- */
-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 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 () {
- 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 receiver's selection changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 fixedHandle;
-}
-
-/**
- * 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 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 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 (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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 != -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 (boolean next) {
- OS.g_signal_emit_by_name (handle, OS.change_current_page, next ? 1 : -1);
- 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 dfc6719389..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,341 +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.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>
- */
-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 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_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);
-}
-
-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);
- if (index != parent.getSelectionIndex ()) {
- if (newControl != null) 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) {
- OS.gtk_widget_modify_fg (labelHandle, OS.GTK_STATE_NORMAL, color);
- OS.gtk_widget_modify_fg (imageHandle, OS.GTK_STATE_NORMAL, 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 no tool tip text should be shown.
- *
- * @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 23e7ec2c81..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
+++ /dev/null
@@ -1,3321 +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.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 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>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL</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>
- */
-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;
- boolean ownerDraw, ignoreSize;
-
- 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 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) {
- /*
- * To be compatible with Windows, force the H_SCROLL
- * and V_SCROLL style bits. On Windows, it is not
- * possible to create a table without scroll bars.
- */
- 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 receiver's selection changes, 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 <code>SWT.CHECK</code> style set 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
- 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;
- }
- /* Set the search column whenever the model changes */
- if ((style & SWT.VIRTUAL) != 0) {
- /* Disable searching when using VIRTUAL */
- OS.gtk_tree_view_set_enable_search (handle, false);
- } else {
- 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);
- 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);
- }
- /* Disable searching when using VIRTUAL */
- 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;
- }
- }
- }
- }
-}
-
-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);
-}
-
-/**
- * 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 == 1) {
- item.cellFont = null;
- } else {
- 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 (index == 0) {
- TableColumn checkColumn = columns [0];
- createRenderers (checkColumn.handle, checkColumn.modelIndex, true, checkColumn.style);
- }
- }
- /* Set the search column whenever the model changes */
- if ((style & SWT.VIRTUAL) != 0) {
- /* Disable searching when using VIRTUAL */
- OS.gtk_tree_view_set_enable_search (handle, false);
- } else {
- 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 ();
-}
-
-int /*long*/ eventWindow () {
- return paintWindow ();
-}
-
-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.toolTipText);
- column.setToolTipText(newShell, column.toolTipText, null);
- }
- }
-}
-
-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);
-}
-
-/**
- * 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's.
- *
- * @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];
- OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h);
- 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.
- * <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_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 /*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 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);
- }
-}
-
-/**
- * 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 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 (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 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 (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 visibility 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);
-}
-
-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 ());
- OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, start);
- int index = start;
- while (index <= end) {
- 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++;
- }
- OS.g_free (iter);
- 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 ());
- 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;
- }
- }
- 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;
-
- /*
- * Bug in GTK. In version 2.3.2, when the property fixed-height-mode
- * is set and there are items in the list, OS.gtk_list_store_clear()
- * segment faults. The fix is to create a new empty model instead.
- */
- 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);
- int /*long*/ oldModel = modelHandle;
- int /*long*/[] types = getColumnTypes (Math.max (1,columnCount));
- int /*long*/ newModel = OS.gtk_list_store_newv (types.length, types);
- if (newModel == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_tree_view_set_model (handle, newModel);
- OS.g_object_unref (oldModel);
- modelHandle = newModel;
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
-
- resetCustomDraw ();
- /* Set the search column whenever the model changes */
- if ((style & SWT.VIRTUAL) != 0) {
- /* Disable searching when using VIRTUAL */
- OS.gtk_tree_view_set_enable_search (handle, false);
- } else {
- 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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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;
- 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)) {
- if ((drawState & SWT.SELECTED) != 0) {
- 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));
- 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);
- gc.dispose();
- 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);
- }
- }
- }
- }
- 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);
- 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));
- gc.setForeground (item.getForeground (columnIndex));
- }
- gc.setFont (item.getFont (columnIndex));
- 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);
- }
- }
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- OS.gtk_widget_modify_text (handle, 0, color);
-}
-
-/**
- * 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);
- for (int i=itemCount; i<count; i++) {
- OS.gtk_list_store_append (modelHandle, iter);
- }
- 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.
- * <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);
-}
-
-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 1eb5eb24b3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java
+++ /dev/null
@@ -1,658 +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.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>
- */
-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>
- *
- * @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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 doublc click by remembering the last click time and mouse button
- * and testing for the double click interval.
- */
- boolean doubleClick = false;
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof);
- 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;
- }
- }
- OS.gdk_event_free (eventPtr);
- }
- postEvent (doubleClick ? SWT.DefaultSelection : SWT.Selection);
- 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);
- 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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>.
- *
- * @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 no tool tip text should be shown.
- *
- * @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);
- toolTipText = string;
-}
-
-void setToolTipText (Shell shell, String newString, String oldString) {
- shell.setToolTipText (buttonHandle, newString, oldString);
-}
-
-/**
- * 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) {
- useFixedWidth = true;
- /*
- * 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.
- */
- OS.gtk_widget_realize (parent.handle);
- boolean sendResize = false;
- if (!OS.gtk_tree_view_column_get_visible (handle)) {
- sendResize = OS.gtk_tree_view_column_get_fixed_width (handle) == width;
- }
- OS.gtk_tree_view_column_set_fixed_width (handle, width);
- OS.gtk_tree_view_column_set_visible (handle, true);
- if (sendResize) sendEvent (SWT.Resize);
- } else {
- if (OS.gtk_tree_view_column_get_visible (handle)) {
- OS.gtk_tree_view_column_set_visible (handle, false);
- 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 64e63ca012..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java
+++ /dev/null
@@ -1,1193 +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.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>
- */
-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;
-}
-
-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);
- 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);
-}
-
-/**
- * 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);
- 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);
- }
- }
- return new Rectangle (rect.x, rect.y, rect.width + 1, 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);
- 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);
-}
-
-/**
- * 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 (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];
- }
- }
- return new Rectangle (rect.x, rect.y, rect.width + 1, 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;
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, Table.CHECKED_COLUMN, ptr, -1);
- return ptr [0] != 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)) 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);
- 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);
-}
-
-/**
- *
- * 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 ();
- 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);
-}
-
-/**
- * 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);
- 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);
-}
-
-/**
- * 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);
-
- /*
- * 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];
- }
- return new Rectangle (rect.x, rect.y, rect.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);
- 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));
-}
-
-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);
- }
- 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);
- }
- 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;
- 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);
- }
- if (this.font == font) return;
- if (this.font != null && this.font.equals (font)) return;
- this.font = font;
- 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) {
- cellFont = new Font [count];
- }
- if (cellFont [index] == font) return;
- if (cellFont [index] != null && cellFont [index].equals (font)) return;
- cellFont [index] = font;
-
- 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);
- }
- 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);
- }
- 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;
- 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);
- }
- 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);
- OS.gtk_widget_modify_style (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);
- 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 e974c8ba9c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,1956 +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.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.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CENTER, LEFT, MULTI, PASSWORD, 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.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
-public class Text extends Scrollable {
- int /*long*/ bufferHandle;
- int tabs = 8, lastEventTime = 0;
- int /*long*/ gdkEventKey = 0;
- int fixStart = -1, fixEnd = -1;
- boolean doubleClick;
-
- static final int INNER_BORDER = 2;
- static final int ITER_SIZEOF = OS.GtkTextIter_sizeof();
-
- /**
- * 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 Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- 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;
- 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_WRAP_WORD);
- 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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) {
- 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]);
- 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);
- }
- xborder += INNER_BORDER;
- yborder += INNER_BORDER;
- } 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;
- 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) {
- 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) return false;
- if (end < start) {
- int temp = end;
- end = start;
- start = temp;
- }
- int offset = -1;
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ layout = OS.gtk_entry_get_layout (handle);
- int [] index = new int [1];
- int [] trailing = new int [1];
- 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);
- offset = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]);
- } else {
- byte [] position = new byte [ITER_SIZEOF];
- OS.gtk_text_view_get_iter_at_location (handle, position, x, y);
- offset = OS.gtk_text_iter_get_offset (position);
- }
- return offset > start && offset < end;
-}
-
-boolean dragOverride () {
- return true;
-}
-
-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 1;
- 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 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.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 "";
- start = Math.max (0, start);
- int /*long*/ address;
- if ((style & SWT.SINGLE) != 0) {
- 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);
- 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_button_release_event (int /*long*/ widget, int /*long*/ event) {
- if (display.dragOverride && !display.dragging) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, event, GdkEventButton.sizeof);
- int x = (int)gdkEvent.x, y = (int)gdkEvent.y;
-
- int offset;
- if ((style & SWT.SINGLE) != 0) {
- int /*long*/ layout = OS.gtk_entry_get_layout (handle);
- int [] index = new int [1];
- int [] trailing = new int [1];
- 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);
- offset = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]);
- } else {
- byte [] position = new byte [ITER_SIZEOF];
- OS.gtk_text_view_get_iter_at_location (handle, position, x, y);
- offset = OS.gtk_text_iter_get_offset (position);
- }
- if ((style & SWT.SINGLE) != 0) {
- OS.gtk_editable_set_position (handle, offset);
- } else {
- byte [] position = new byte [ITER_SIZEOF];
- OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, position, offset);
- 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);
- }
- }
- return super.gtk_button_release_event (widget, event);
-}
-
-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.
- */
- if ((style & SWT.SINGLE) != 0) {
- 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) {
- 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) {
- 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_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);
- }
- 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);
- newEnd [0] = pos [0];
- }
- pos [0] = newEnd [0];
- if (newStart [0] != newEnd [0] && newEnd [0] != pos [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_popup_menu (int /*long*/ widget) {
- 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_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);
- int start = OS.gtk_text_iter_get_offset (position);
- 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, start);
- 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);
- } 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);
- }
- 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 (style & SWT.SINGLE) != 0 ? OS.GTK_ENTRY_IM_CONTEXT (handle) : 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));
- }
- }
-}
-
-/**
- * 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- OS.gtk_widget_modify_text (handle, 0, color);
-}
-
-/**
- * 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 f37bafefb8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,452 +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.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>
- */
-public class ToolBar extends Composite {
- ToolItem lastFocus;
- 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);
-}
-
-int /*long*/ eventHandle () {
- return fixedHandle;
-}
-
-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.toolTipText);
- item.setToolTipText(newShell, item.toolTipText, null);
- }
- }
- }
-}
-
-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();
- int /*long*/ list = OS.gtk_container_get_children (handle);
- if (list == 0) return new ToolItem [0];
- int count = OS.g_list_length (list);
- ToolItem [] result = new ToolItem [count];
- for (int i=0; i<count; i++) {
- int /*long*/ data = OS.g_list_nth_data (list, i);
- Widget widget = display.getWidget (data);
- result [i] = (ToolItem) widget;
- }
- OS.g_list_free (list);
- 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();
- /* On GTK, toolbars cannot wrap */
- return 1;
-}
-
-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);
- item.postEvent (SWT.Selection, event);
- return result;
- }
- }
- //FALL THROUGH
- }
- case OS.GDK_Right: next = true; break;
- default: return result;
- }
- 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 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;
- String oldString = string == null ? null : items [i].toolTipText;
- shell.setToolTipText (items [i].handle, newString, oldString);
- }
-}
-
-}
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 b9ef443197..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,1039 +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.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>
- */
-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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 ();
-}
-
-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);
- }
- 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 ((((state & SWT.RIGHT_TO_LEFT) == 0) && x <= (int)x_win [0])
- || (((state & 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);
- 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) {
- 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) {
- 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 ();
-}
-
-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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
- 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 disbled 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) {
- OS.gtk_widget_modify_fg (handle, OS.GTK_STATE_NORMAL, color);
- if (labelHandle != 0) OS.gtk_widget_modify_fg (labelHandle, OS.GTK_STATE_NORMAL, color);
- if (imageHandle != 0) OS.gtk_widget_modify_fg (imageHandle, OS.GTK_STATE_NORMAL, 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);
-}
-
-/**
- * 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 no tool tip text should be shown.
- *
- * @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);
- }
- toolTipText = string;
-}
-
-void setToolTipText (Shell shell, String newString, String oldString) {
- shell.setToolTipText (handle, newString, oldString);
-}
-
-/**
- * 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;
- OS.gtk_widget_set_size_request (handle, width, -1);
- 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 6e7c53fe20..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java
+++ /dev/null
@@ -1,759 +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.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>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @since 3.2
- */
-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#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);
-}
-
-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's value changes, by sending
- * it one of the messages defined in the <code>SelectionListener</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 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};
- 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};
- 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};
- 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};
- 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);
- } 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 ();
- 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;
- 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's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
- 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);
- 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) {
- 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 3089b9bc06..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,963 +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.*;
-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>
- */
-public class Tracker extends Widget {
- Composite parent;
- int /*long*/ cursor, lastCursor, window;
- boolean tracking, cancelled, grabbed, stippled;
- Rectangle [] rectangles, proportions;
- 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
- */
-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 () {
- 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 () {
- 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 () {
- 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 ();
- 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];
- OS.gdk_draw_rectangle (window, gc, 0, rect.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();
- 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;
-}
-
-boolean grab () {
- 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 ((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 ();
- 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 ();
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
- }
- return result;
-}
-
-int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ eventPtr) {
- 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 ();
- 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 (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;
- 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;
- }
-
- Point cursorPos;
- int mask = OS.GDK_BUTTON1_MASK | OS.GDK_BUTTON2_MASK | OS.GDK_BUTTON3_MASK;
- boolean mouseDown = (state [0] & mask) != 0;
- if (!mouseDown) {
- if ((style & SWT.RESIZE) != 0) {
- cursorPos = adjustResizeCursor ();
- } else {
- cursorPos = adjustMoveCursor ();
- }
- oldX [0] = cursorPos.x;
- oldY [0] = cursorPos.y;
- }
- this.oldX = oldX [0];
- this.oldY = oldY [0];
-
- grabbed = grab ();
- lastCursor = cursor;
-
- /* 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;
-}
-
-/**
- * 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 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 = 0;
- if (value != null) cursor = value.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;
-}
-
-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 07e7c8fd23..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java
+++ /dev/null
@@ -1,448 +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.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>
- *
- * @since 3.0
- */
-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 receiver is selected, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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;
- 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_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);
- 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;
-}
-
-void hookEvents () {
- 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 ();
- return OS.GTK_WIDGET_VISIBLE (handle);
-}
-
-void register () {
- super.register ();
- display.addWidget (imageHandle, this);
-}
-
-void releaseHandle () {
- if (handle != 0) 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 receiver is selected.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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) {
- Rectangle rect = image.getBounds ();
- OS.gtk_widget_set_size_request (handle, rect.width, rect.height);
- 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);
- OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf);
- OS.gtk_widget_show (imageHandle);
- } else {
- OS.gtk_widget_set_size_request (handle, 1, 1);
- 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 no tool tip text should be shown.
- *
- * @param value 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);
- }
- 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_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;
- OS.gtk_widget_show (handle);
- } else {
- OS.gtk_widget_hide (handle);
- sendEvent (SWT.Hide);
- }
-}
-}
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 b75d122b0d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
+++ /dev/null
@@ -1,3091 +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.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 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>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL</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>
- */
-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;
- boolean ownerDraw, ignoreSize;
-
- 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 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) {
- /*
- * To be compatible with Windows, force the H_SCROLL
- * and V_SCROLL style bits. On Windows, it is not
- * possible to create a tree without scroll bars.
- */
- 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 receiver's selection changes, 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 <code>SWT.CHECK</code> style set 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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) {
- 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];
- if (OS.gtk_tree_view_get_expander_column (handle) == column) {
- 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);
- 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;
- }
- /* Set the search column whenever the model changes */
- if ((style & SWT.VIRTUAL) != 0) {
- /* Disable searching when using VIRTUAL */
- OS.gtk_tree_view_set_enable_search (handle, false);
- } else {
- 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);
- 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);
- }
- /* Disable searching when using VIRTUAL */
- 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);
-}
-
-/**
- * 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 == 1) {
- item.cellFont = null;
- } else {
- 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 (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);
- }
- }
- /* Set the search column whenever the model changes */
- if ((style & SWT.VIRTUAL) != 0) {
- /* Disable searching when using VIRTUAL */
- OS.gtk_tree_view_set_enable_search (handle, false);
- } else {
- 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;
-}
-
-int /*long*/ eventWindow () {
- return paintWindow ();
-}
-
-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.toolTipText);
- column.setToolTipText(newShell, column.toolTipText, null);
- }
- }
-}
-
-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);
-}
-
-/**
- * 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);
- 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;
- 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_model_iter_n_children (modelHandle, iter) > 0) {
- for (int i = 0; i <= columnCount; i++) {
- int /*long*/ column = OS.gtk_tree_view_get_column (handle, i);
- if (column != 0) {
- int[] buffer = new int [1];
- GdkRectangle rect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, path [0], column, rect);
- OS.gtk_widget_style_get (handle, OS.expander_size, buffer, 0);
- int expanderSize = buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING;
- overExpander = rect.x - 1 <= point.x && point.x < rect.x + expanderSize;
- }
- }
- }
- 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];
- OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h);
- 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.
- * <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_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 /*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 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);
- }
-}
-
-/**
- * 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 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.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 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>
- *
- * @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);
-}
-
-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 ());
- int index = start;
- for (int i = start; i <= end; i++) {
- 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);
- 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);
- }
- }
- 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];
- /*
- * Bug in GTK. In version 2.3.2, when the property fixed-height-mode
- * is set and there are items in the list, OS.gtk_tree_store_clear()
- * segment faults. The fix is to create a new empty model instead.
- */
- 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);
- // TODO verify if true for tree store
- //OS.gtk_tree_store_clear (modelHandle);
- int /*long*/ oldModel = modelHandle;
- int /*long*/[] types = getColumnTypes (Math.max (1,columnCount));
- int /*long*/ newModel = OS.gtk_tree_store_newv (types.length, types);
- if (newModel == 0) error (SWT.ERROR_NO_HANDLES);
- OS.gtk_tree_view_set_model (handle, newModel);
- OS.g_object_unref (oldModel);
- modelHandle = newModel;
- OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
-
- /* Set the search column whenever the model changes */
- if ((style & SWT.VIRTUAL) != 0) {
- /* Disable searching when using VIRTUAL */
- OS.gtk_tree_view_set_enable_search (handle, false);
- } else {
- 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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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;
- 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)) {
- if ((drawState & SWT.SELECTED) != 0) {
- 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));
- 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);
- gc.dispose();
- 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);
- }
- }
- }
- }
- 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);
- 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_cell_area (handle, path, columnHandle, rect);
- OS.gtk_tree_path_free (path);
- if (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));
- gc.setForeground (item.getForeground (columnIndex));
- }
- gc.setFont (item.getFont (columnIndex));
- 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;
-}
-
-/**
- * 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_unset_rows_drag_dest(handle);
- 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) {
- 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);
- }
- } 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 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);
- }
- }
-}
-
-void setForegroundColor (GdkColor color) {
- super.setForegroundColor (color);
- OS.gtk_widget_modify_text (handle, 0, color);
-}
-
-/**
- * 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.
- * <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);
-}
-
-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);
- 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 1370cc2a93..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
+++ /dev/null
@@ -1,643 +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.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>
- *
- * @since 3.1
- */
-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>
- *
- * @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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
- 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 doublc click by remembering the last click time and mouse button
- * and testing for the double click interval.
- */
- boolean doubleClick = false;
- int /*long*/ eventPtr = OS.gtk_get_current_event ();
- if (eventPtr != 0) {
- GdkEventButton gdkEvent = new GdkEventButton ();
- OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof);
- 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;
- }
- }
- OS.gdk_event_free (eventPtr);
- }
- postEvent (doubleClick ? SWT.DefaultSelection : SWT.Selection);
- 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);
- 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));
- } 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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>.
- *
- * @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);
-}
-
-/**
- * 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 no tool tip text should be shown.
- *
- * @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);
- toolTipText = string;
-}
-
-void setToolTipText (Shell shell, String newString, String oldString) {
- shell.setToolTipText (buttonHandle, newString, oldString);
-}
-
-/**
- * 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) {
- useFixedWidth = true;
- /*
- * 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.
- */
- OS.gtk_widget_realize (parent.handle);
- boolean sendResize = false;
- if (!OS.gtk_tree_view_column_get_visible (handle)) {
- sendResize = OS.gtk_tree_view_column_get_fixed_width (handle) == width;
- }
- OS.gtk_tree_view_column_set_fixed_width (handle, width);
- OS.gtk_tree_view_column_set_visible (handle, true);
- if (sendResize) sendEvent (SWT.Resize);
- } else {
- if (OS.gtk_tree_view_column_get_visible (handle)) {
- OS.gtk_tree_view_column_set_visible (handle, false);
- 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 cdc25a547d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java
+++ /dev/null
@@ -1,1582 +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.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>
- */
-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);
-}
-
-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);
- 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);
-}
-
-/**
- * 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 ();
- 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);
-}
-
-/**
- * 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);
- OS.gtk_tree_path_free (path);
-
- if (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?
- }
-
- 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];
- }
- }
- return new Rectangle (rect.x, rect.y, rect.width + 1, 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);
- OS.gtk_tree_path_free (path);
- 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);
- }
- }
- return new Rectangle (rect.x, rect.y, rect.width + 1, 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;
- int /*long*/ [] ptr = new int /*long*/ [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, Tree.CHECKED_COLUMN, ptr, -1);
- return ptr [0] != 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*/ 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);
- 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);
-}
-
-/**
- *
- * 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 ();
- 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);
-}
-
-/**
- * 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);
- 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);
-}
-
-/**
- * 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);
- OS.gtk_tree_path_free (path);
-
- if (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;
- }
-
- /*
- * 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];
- }
- return new Rectangle (rect.x, rect.y, rect.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);
- 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));
-}
-
-/**
- * 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>
- *
- * @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 length = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle);
- if (length == 0) return;
- int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- int [] index = new int [1];
- while (OS.gtk_tree_model_iter_children (parent.modelHandle, iter, handle)) {
- OS.gtk_tree_model_get (parent.modelHandle, iter, Tree.ID_COLUMN, index, -1);
- if (index [0] != -1) {
- TreeItem item = parent.items [index [0]];
- if (item != null && !item.isDisposed ()) {
- item.dispose ();
- }
- }
- }
- 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);
- }
- 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);
- }
- 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;
- 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);
- }
- if (this.font == font) return;
- if (this.font != null && this.font.equals (font)) return;
- this.font = font;
- 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) {
- cellFont = new Font [count];
- }
- if (cellFont [index] == font) return;
- if (cellFont [index] != null && cellFont [index].equals (font)) return;
- cellFont [index] = font;
-
- 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);
- }
- 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);
- }
- 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;
- 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);
- }
- 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);
- OS.gtk_widget_modify_style (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);
- 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 a7cbbd7366..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,1478 +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.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
- */
-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;
-
- /* 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 POPUP_MENU = 37;
- static final int PREEDIT_CHANGED = 38;
- static final int REALIZE = 39;
- static final int ROW_ACTIVATED = 40;
- static final int SCROLL_CHILD = 41;
- static final int SCROLL_EVENT = 42;
- static final int SELECT = 43;
- static final int SHOW = 44;
- static final int SHOW_HELP = 45;
- static final int SIZE_ALLOCATE = 46;
- static final int STYLE_SET = 47;
- static final int SWITCH_PAGE = 48;
- static final int TEST_COLLAPSE_ROW = 49;
- static final int TEST_EXPAND_ROW = 50;
- static final int TEXT_BUFFER_INSERT_TEXT = 51;
- static final int TOGGLED = 52;
- static final int UNMAP = 53;
- static final int UNMAP_EVENT = 54;
- static final int UNREALIZE = 55;
- static final int VALUE_CHANGED = 56;
- static final int VISIBILITY_NOTIFY_EVENT = 57;
- static final int WINDOW_STATE_EVENT = 58;
- static final int ACTIVATE_INVERSE = 59;
- static final int LAST_SIGNAL = 60;
-
-/**
- * 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 #removeListener
- * @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);
-}
-
-/**
- * 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 descendents. After this method has
- * been invoked, the receiver and all descendents 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 descendents
- * 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;
-}
-
-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_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_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_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_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_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);
-}
-
-boolean filters (int eventType) {
- return display.filters (eventType);
-}
-
-int /*long*/ fixedMapProc (int /*long*/ widget) {
- return 0;
-}
-
-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];
- 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 <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;
-}
-
-/**
- * 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 #removeListener
- */
-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 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 #addListener
- * @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 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 #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 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 #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;
- }
- }
- }
- }
-}
-
-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 () {
-}
-
-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;
-}
-
-/**
- * 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 HIDE: return gtk_hide (handle);
- case GRAB_FOCUS: return gtk_grab_focus (handle);
- case MAP: return gtk_map (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 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);
- 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 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);
- 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 20bb83e373..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,349 +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.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
- */
-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() {
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, red, green, blue);
- if (device.tracking) device.new_Object(this);
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, rgb.red, rgb.green, rgb.blue);
- if (device.tracking) device.new_Object(this);
-}
-/**
- * Disposes of the operating system resources associated with
- * the color. Applications must dispose of all colors which
- * they allocate.
- */
-public void dispose() {
- if (handle == null) return;
- if (device.isDisposed()) return;
- 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;
- if (device.tracking) device.dispose_Object(this);
- device = 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(Device device, int red, int green, int blue) {
- this.device = device;
- 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) {
- if (device == null) device = Device.getDevice();
- Color color = new Color();
- color.handle = xColor;
- color.device = device;
- 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 3177b8ecc4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,438 +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.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>
- */
-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 () {
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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(device.xDisplay, shape);
- }
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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);
- if (device.tracking) device.new_Object(this);
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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, source.type,
- source.x, source.y, source.disposalMethod, source.delayTime);
-
- /* 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, 0, 0, 0,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, 0, 0, 0,
- false, false);
- else ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, null, null, null,
- 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);
- if (device.tracking) device.new_Object(this);
-}
-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;
-}
-/**
- * Disposes of the operating system resources associated with
- * the cursor. Applications must dispose of all cursors which
- * they allocate.
- */
-public void dispose () {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- OS.XFreeCursor(device.xDisplay, handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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;
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- Cursor cursor = new Cursor();
- cursor.device = 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 2e93cb3a1e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,937 +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 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.
- */
-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;
-
- /* 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];
-
- static final Object CREATE_LOCK = new Object();
-
- /* 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.
- *
- * This code will be removed in the future.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName ("org.eclipse.swt.widgets.Display");
- } catch (Throwable 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 (CREATE_LOCK) {
- 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];
- }
- 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 () {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- deregister (this);
- xDisplay = 0;
- if (tracking) {
- objects = null;
- errors = null;
- }
-}
-
-void dispose_Object (Object object) {
- 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;
- int count = 0, length = 0;
- if (tracking) 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++;
- }
- }
- 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 () {
- return xDisplay == 0;
-}
-
-void new_Object (Object object) {
- 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;
-
- 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 17a8a34062..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 cf63dc82b3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,532 +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.*;
-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
- */
-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 () {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new FontData[] {fd});
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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(device, fds);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new FontData[]{new FontData(name, height, style)});
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the font. Applications must dispose of all fonts which
- * they allocate.
- */
-public void dispose () {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- if (handle == device.systemFont.handle) return;
- OS.XmFontListFree (handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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 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 ());
- }
- }
- }
- }
- 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 (Device device, FontData[] fds) {
- this.device = device;
-
- /* 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) {
- if (device == null) device = Device.getDevice();
- Font font = new Font();
- font.device = 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 ba5f2a16aa..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,647 +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.*;
-
-/**
- * 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
- */
-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 un-initialized 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);
- int height = 0;
- try {
- height = 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) 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";
-}
-/**
- * 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
- */
-public int getHeight() {
- return points / 10;
-}
-/**
- * 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;
-}
-/**
- * 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 + "|" + getHeight() + "|" + 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 f0a1423bbd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,122 +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;
-
-
-/**
- * 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
- */
-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 df1f06429e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,4244 +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 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>
- * 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
- */
-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[] LINE_DOT = new int[]{1, 1};
- static final int[] LINE_DASH = new int[]{3, 1};
- static final int[] LINE_DASHDOT = new int[]{3, 1, 1, 1};
- static final int[] LINE_DASHDOTDOT = new int[]{3, 1, 1, 1, 1, 1};
- static final int[] LINE_DOT_ZERO = new int[]{3, 3};
- static final int[] LINE_DASH_ZERO = new int[]{18, 6};
- static final int[] LINE_DASHDOT_ZERO = new int[]{9, 6, 3, 6};
- static final int[] LINE_DASHDOTDOT_ZERO = new int[]{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 and background color 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>
- * </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 and background color 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>
- * </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);
- if (device.tracking) device.new_Object(this);
-}
-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);
-}
-/**
- * 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);
-}
-/**
- * Disposes of the operating system resources associated with
- * the graphics context. Applications must dispose of all GCs
- * which they allocate.
- */
-public void dispose () {
- if (handle == 0) return;
- if (data.device.isDisposed()) return;
-
- 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 */
- Device device = data.device;
- 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;
- if (device.tracking) device.dispose_Object(this);
- data.device = 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);
- 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) {
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- if (width == height) {
- if (arcAngle >= 0) {
- Cairo.cairo_arc_negative(cairo, x + offset + width / 2f, y + offset + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180);
- } else {
- Cairo.cairo_arc(cairo, x + offset + width / 2f, y + offset + 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 + offset + width / 2f, y + offset + 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;
- }
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (xDisplay, handle, OS.GCForeground, values);
- OS.XSetForeground (xDisplay, handle, highlightColor);
- OS.XDrawRectangle (xDisplay, xDrawable, handle, x, y, width - 1, height - 1);
- OS.XSetForeground (xDisplay, handle, values.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 + 0.5, destY + 0.5, destWidth, destHeight);
- Cairo.cairo_clip(cairo);
- Cairo.cairo_translate(cairo, destX - srcX + 0.5, destY - srcY + 0.5);
- 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);
- Cairo.cairo_pattern_set_filter(pattern, filter);
- Cairo.cairo_pattern_set_extend(pattern, Cairo.CAIRO_EXTEND_REFLECT);
- 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);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- Cairo.cairo_move_to(cairo, x1 + offset, y1 + offset);
- Cairo.cairo_line_to(cairo, x2 + offset, y2 + offset);
- 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);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- if (width == height) {
- Cairo.cairo_arc_negative(cairo, x + offset + width / 2f, y + offset + height / 2f, width / 2f, 0, -2 * (float)Compatibility.PI);
- } else {
- Cairo.cairo_save(cairo);
- Cairo.cairo_translate(cairo, x + offset + width / 2f, y + offset + 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.
- *
- * @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>
- * </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();
- int /*long*/ cairo = data.cairo;
- Cairo.cairo_save(cairo);
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- Cairo.cairo_translate(cairo, offset, offset);
- 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);
- 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);
- 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);
- 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;
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- Cairo.cairo_move_to(cairo, pointArray[0] + offset, pointArray[1] + offset);
- for (int i = 1, j=2; i < count; i++, j += 2) {
- Cairo.cairo_line_to(cairo, pointArray[j] + offset, pointArray[j + 1] + offset);
- }
- 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);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- Cairo.cairo_rectangle(cairo, x + offset, y + offset, 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);
- 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) {
- float naw2 = naw / 2f;
- float nah2 = nah / 2f;
- float fw = nw / naw2;
- float fh = nh / nah2;
- Cairo.cairo_save(cairo);
- float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f;
- Cairo.cairo_translate(cairo, nx + offset, ny + offset);
- 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
- 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_text_path(cairo, buffer);
- Cairo.cairo_fill(cairo);
- return;
- }
- setString(string);
- 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 specifing 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
- 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);
- 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);
- 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 xDisplay = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- 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_save(cairo);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.handle);
- } else {
- XColor color = new XColor();
- color.pixel = values.background;
- OS.XQueryColor(xDisplay, data.colormap, color);
- 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_fill(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- OS.XSetForeground (xDisplay, handle, values.background);
- OS.XFillArc(xDisplay, data.drawable, handle, x, y, width, height, startAngle * 64, arcAngle * 64);
- OS.XSetForeground (xDisplay, handle, values.foreground);
-}
-
-/**
- * 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 xDisplay = data.display;
- int xScreenNum = OS.XDefaultScreen(xDisplay);
- XGCValues values = new XGCValues();
- int fromColor, toColor;
- OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- fromColor = values.foreground;
- toColor = values.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 = fromColor;
- fromColor = toColor;
- toColor = t;
- }
- if (fromColor == toColor) {
- OS.XFillRectangle(xDisplay, data.drawable, handle, 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
- */
- 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);
-
- XColor xColor = new XColor();
- xColor.pixel = fromColor;
- OS.XQueryColor(xDisplay, data.colormap, xColor);
- final RGB fromRGB = new RGB((xColor.red & 0xffff) >>> 8, (xColor.green & 0xffff) >>> 8, (xColor.blue & 0xffff) >>> 8);
- xColor.pixel = toColor;
- OS.XQueryColor(xDisplay, data.colormap, xColor);
- final RGB toRGB = new RGB((xColor.red & 0xffff) >>> 8, (xColor.green & 0xffff) >>> 8, (xColor.blue & 0xffff) >>> 8);
- 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);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int display = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (display, handle, OS.GCForeground | OS.GCBackground, values);
- 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_save(cairo);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.handle);
- } else {
- XColor color = new XColor();
- color.pixel = values.background;
- OS.XQueryColor(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, data.alpha / (float)0xFF);
- }
- Cairo.cairo_fill(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- OS.XSetForeground (display, handle, values.background);
- OS.XFillArc (display, data.drawable, handle, x, y, width, height, 0, 23040);
- OS.XSetForeground (display, handle, values.foreground);
-}
-/**
- * Fills the path described by the parameter.
- *
- * @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>
- * </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();
- int display = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (display, handle, OS.GCForeground | OS.GCBackground, values);
- XColor color = new XColor();
- color.pixel = values.background;
- OS.XQueryColor(display, data.colormap, color);
- int /*long*/ cairo = data.cairo;
- Cairo.cairo_save(cairo);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.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);
- }
- 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);
- Cairo.cairo_restore(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);
- int xDisplay = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- XColor color = new XColor();
- color.pixel = values.background;
- OS.XQueryColor(xDisplay, data.colormap, color);
- Cairo.cairo_save(cairo);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.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);
- }
- drawPolyline(cairo, pointArray, true);
- Cairo.cairo_fill(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- short[] xPoints = new short[pointArray.length];
- for (int i = 0; i<pointArray.length;i++) {
- xPoints[i] = (short) pointArray[i];
- }
- OS.XSetForeground (xDisplay, handle, values.background);
- OS.XFillPolygon(xDisplay, data.drawable, handle,xPoints, xPoints.length / 2, OS.Complex, OS.CoordModeOrigin);
- OS.XSetForeground (xDisplay, handle, values.foreground);
-}
-/**
- * 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) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int xDisplay = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- XColor color = new XColor();
- color.pixel = values.background;
- OS.XQueryColor(xDisplay, data.colormap, color);
- Cairo.cairo_save(cairo);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.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);
- }
- Cairo.cairo_rectangle(cairo, x, y, width, height);
- Cairo.cairo_fill(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- OS.XSetForeground (xDisplay, handle, values.background);
- OS.XFillRectangle (xDisplay, data.drawable, handle, x, y, width, height);
- OS.XSetForeground (xDisplay, handle, values.foreground);
-}
-/**
- * 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);
- 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 xDisplay = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- float naw2 = naw / 2f;
- float nah2 = nah / 2f;
- float fw = nw / naw2;
- float fh = nh / nah2;
- XColor color = new XColor();
- color.pixel = values.background;
- OS.XQueryColor(xDisplay, data.colormap, color);
- Cairo.cairo_save(cairo);
- Cairo.cairo_save(cairo);
- 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);
- if (data.backgroundPattern != null) {
- Cairo.cairo_set_source(cairo, data.backgroundPattern.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);
- }
- Cairo.cairo_fill(cairo);
- Cairo.cairo_restore(cairo);
- return;
- }
- int naw2 = naw / 2;
- int nah2 = nah / 2;
- int xDrawable = data.drawable;
- OS.XSetForeground(xDisplay, handle, values.background);
- 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);
- }
- }
- OS.XSetForeground(xDisplay, handle, values.foreground);
-}
-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);
- 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 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.cairo != 0;
-}
-/**
- * Returns the receiver's alpha value.
- *
- * @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);
- int xDisplay = data.display;
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCBackground, values);
- XColor xColor = new XColor();
- xColor.pixel = values.background;
- OS.XQueryColor(xDisplay,data.colormap,xColor);
- return Color.motif_new(data.device, xColor);
-
-}
-/**
- * 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);
- 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 0;
-}
-/**
- * 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[] 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);
- int clipRgn = data.clipRgn;
- if (clipRgn == 0) {
- return new Rectangle(0, 0, width[0], height[0]);
- } else {
- int rgn = OS.XCreateRegion ();
- XRectangle rect = new XRectangle();
- rect.width = (short)width[0];
- rect.height = (short)height[0];
- OS.XUnionRectWithRegion(rect, rgn, rgn);
- OS.XIntersectRegion(rgn, clipRgn, rgn);
- OS.XClipBox(rgn, rect);
- OS.XDestroyRegion(rgn);
- return new Rectangle(rect.x, rect.y, rect.width, rect.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 hRegion = region.handle;
- OS.XSubtractRegion (hRegion, hRegion, hRegion);
- 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, hRegion, hRegion);
- } else {
- OS.XUnionRegion (hRegion, clipRgn, hRegion);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- double[] matrix = new double[]{1, 0, 0, 1, 0, 0};
- Cairo.cairo_get_matrix(cairo, matrix);
- if (!isIdentity(matrix)) return;
- }
- }
- if (data.damageRgn != 0) {
- OS.XIntersectRegion(hRegion, data.damageRgn, hRegion);
- }
-}
-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);
- 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);
- int xDisplay = data.display;
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCForeground, values);
- XColor xColor = new XColor();
- xColor.pixel = values.foreground;
- OS.XQueryColor(xDisplay,data.colormap,xColor);
- return Color.motif_new(data.device, xColor);
-
-}
-/**
- * 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
- */
-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 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);
- XGCValues values = new XGCValues();
- OS.XGetGCValues(data.display, handle, OS.GCCapStyle, values);
- int cap = SWT.CAP_FLAT;
- switch (values.cap_style) {
- case OS.CapRound: cap = SWT.CAP_ROUND; break;
- case OS.CapButt: cap = SWT.CAP_FLAT; break;
- case OS.CapProjecting: cap = SWT.CAP_SQUARE; break;
- }
- return cap;
-}
-/**
- * Returns the receiver's line dash style. The default value is
- * <code>null</code>.
- *
- * @return the lin 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);
- int[] dash_list = data.dashes;
- if (dash_list == null) return null;
- int[] dashes = new int[dash_list.length];
- System.arraycopy(dash_list, 0, dashes, 0, dashes.length);
- 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);
- XGCValues values = new XGCValues();
- OS.XGetGCValues(data.display, handle, OS.GCJoinStyle, values);
- int join = SWT.JOIN_MITER;
- switch (values.join_style) {
- case OS.JoinMiter: join = SWT.JOIN_MITER; break;
- case OS.JoinRound: join = SWT.JOIN_ROUND; break;
- case OS.JoinBevel: join = SWT.JOIN_BEVEL; break;
- }
- return join;
-}
-/**
- * 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);
- XGCValues values = new XGCValues();
- OS.XGetGCValues(data.display, handle, OS.GCLineWidth, values);
- return values.line_width;
-}
-/**
- * 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) {
- int xDisplay = data.display;
- int foreground = data.foreground;
- if (foreground != -1) OS.XSetForeground (xDisplay, xGC, foreground);
- int background = data.background;
- if (background != -1) OS.XSetBackground (xDisplay, xGC, background);
- 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);
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCBackground | OS.GCCapStyle | OS.GCForeground | OS.GCJoinStyle | OS.GCLineWidth, values);
- XColor color = new XColor();
- color.pixel = values.foreground;
- OS.XQueryColor(xDisplay, data.colormap, color);
- 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, Math.max(1, values.line_width));
- int cap = Cairo.CAIRO_LINE_CAP_BUTT;
- switch (values.cap_style) {
- case OS.CapRound: cap = Cairo.CAIRO_LINE_CAP_ROUND; break;
- case OS.CapButt: cap = Cairo.CAIRO_LINE_CAP_BUTT; break;
- case OS.CapProjecting: cap = Cairo.CAIRO_LINE_CAP_SQUARE; break;
- }
- Cairo.cairo_set_line_cap(cairo, cap);
- int join = Cairo.CAIRO_LINE_JOIN_MITER;
- switch (values.join_style) {
- case OS.JoinMiter: join = Cairo.CAIRO_LINE_JOIN_MITER; break;
- case OS.JoinRound: join = Cairo.CAIRO_LINE_JOIN_ROUND; break;
- case OS.JoinBevel: join = Cairo.CAIRO_LINE_JOIN_BEVEL; break;
- }
- Cairo.cairo_set_line_join(cairo, join);
- if (data.dashes != null) {
- double[] dashes = new double[data.dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- dashes[i] = data.dashes[i];
- }
- Cairo.cairo_set_dash(cairo, dashes, dashes.length, 0);
- }
- setCairoFont(cairo, data.font);
- setCairoClip(cairo, 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 #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;
- setClipping(0);
- }
-}
-/**
- * Sets the receiver's alpha value.
- *
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @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;
- if (data.foregroundPattern == null) {
- int xDisplay = data.display;
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCForeground, values);
- XColor color = new XColor();
- color.pixel = values.foreground;
- OS.XQueryColor(xDisplay, data.colormap, color);
- int /*long*/ cairo = data.cairo;
- 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);
- }
-}
-/**
- * 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.
- *
- * @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>
- * </ul>
- *
- * @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);
- OS.XSetBackground(data.display, handle, color.handle.pixel);
- data.backgroundPattern = null;
-}
-/**
- * Sets the background pattern. The default value is <code>null</code>.
- *
- * @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>
- * </ul>
- *
- * @see Pattern
- *
- * @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();
- data.backgroundPattern = pattern;
-}
-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;
- byte[] buffer = Converter.wcsToMbcs(null, fd.getName(), true);
- Cairo.cairo_select_font_face(cairo, buffer, slant, weight);
- Cairo.cairo_set_font_size(cairo, fd.getHeight());
-}
-static void setCairoClip(int /*long*/ cairo, int /*long*/ clipRgn) {
- Cairo.cairo_reset_clip(cairo);
- if (clipRgn == 0) return;
- //TODO - get rectangles from region instead of clip box
- XRectangle rect = new XRectangle();
- OS.XClipBox(clipRgn, rect);
- Cairo.cairo_rectangle(cairo, rect.x, rect.y, rect.width, rect.height);
- Cairo.cairo_clip(cairo);
- Cairo.cairo_new_path(cairo);
-}
-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 setClipping(int clipRgn) {
- if (clipRgn == 0) {
- if (data.clipRgn != 0) {
- OS.XDestroyRegion (data.clipRgn);
- data.clipRgn = 0;
- } else {
- return;
- }
- 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);
- 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);
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- setCairoClip(cairo, clipRgn);
- }
-}
-/**
- * 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.
- *
- * @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>
- * </ul>
- *
- * @see Path
- *
- * @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 = data.device.systemFont;
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.font = font;
- if (data.renderTable != 0) OS.XmRenderTableFree(data.renderTable);
- data.renderTable = 0;
- data.stringWidth = data.stringHeight = data.textWidth = data.textHeight = -1;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- setCairoFont(cairo, 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);
- OS.XSetForeground(data.display, handle, color.handle.pixel);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- XColor xColor = color.handle;
- Cairo.cairo_set_source_rgba(cairo, (xColor.red & 0xFFFF) / (float)0xFFFF, (xColor.green & 0xFFFF) / (float)0xFFFF, (xColor.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF);
- }
- data.foregroundPattern = null;
-}
-/**
- * Sets the foreground pattern. The default value is <code>null</code>.
- *
- * @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>
- * </ul>
- *
- * @see Pattern
- *
- * @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();
- int /*long*/ cairo = data.cairo;
- if (pattern != null) {
- Cairo.cairo_set_source(cairo, pattern.handle);
- } else {
- int display = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (display, handle, OS.GCForeground, values);
- XColor color = new XColor();
- color.pixel = values.foreground;
- OS.XQueryColor(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, data.alpha / (float)0xFF);
- }
- data.foregroundPattern = pattern;
-}
-/**
- * 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>.
- *
- * @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>
- * </ul>
- *
- * @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 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);
- int cap_style = 0, cairo_style = 0;
- switch (cap) {
- case SWT.CAP_ROUND:
- cap_style = OS.CapRound;
- cairo_style = Cairo.CAIRO_LINE_CAP_ROUND;
- break;
- case SWT.CAP_FLAT:
- cap_style = OS.CapButt;
- cairo_style = Cairo.CAIRO_LINE_CAP_BUTT;
- break;
- case SWT.CAP_SQUARE:
- cap_style = OS.CapProjecting;
- cairo_style = Cairo.CAIRO_LINE_CAP_SQUARE;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int xDisplay = data.display;
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCLineWidth | OS.GCJoinStyle, values);
- int line_style = data.lineStyle == SWT.LINE_SOLID ? OS.LineSolid : OS.LineOnOffDash;
- OS.XSetLineAttributes(xDisplay, handle, values.line_width, line_style, cap_style, values.join_style);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_set_line_cap(cairo, cairo_style);
- }
-}
-/**
- * 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);
- int xDisplay = data.display;
- if (dashes != null && dashes.length != 0) {
- byte[] dash_list = new byte[dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- int dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- dash_list[i] = (byte)dash;
- }
- OS.XSetDashes(xDisplay, handle, 0, dash_list, dash_list.length);
- data.dashes = new int[dashes.length];
- System.arraycopy(dashes, 0, data.dashes, 0, dashes.length);
- data.lineStyle = SWT.LINE_CUSTOM;
- } else {
- data.dashes = null;
- data.lineStyle = SWT.LINE_SOLID;
- }
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCLineWidth | OS.GCCapStyle | OS.GCJoinStyle, values);
- int line_style = data.lineStyle == SWT.LINE_SOLID ? OS.LineSolid : OS.LineOnOffDash;
- OS.XSetLineAttributes(xDisplay, handle, values.line_width, line_style, values.cap_style, values.join_style);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (data.dashes != null) {
- double[] cairoDashes = new double[data.dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- cairoDashes[i] = data.dashes[i];
- }
- Cairo.cairo_set_dash(cairo, cairoDashes, cairoDashes.length, 0);
- } else {
- Cairo.cairo_set_dash(cairo, null, 0, 0);
- }
- }
-}
-/**
- * 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);
- int join_style = 0, cairo_style = 0;
- switch (join) {
- case SWT.JOIN_MITER:
- join_style = OS.JoinMiter;
- cairo_style = Cairo.CAIRO_LINE_JOIN_MITER;
- break;
- case SWT.JOIN_ROUND:
- join_style = OS.JoinRound;
- cairo_style = Cairo.CAIRO_LINE_JOIN_ROUND;
- break;
- case SWT.JOIN_BEVEL:
- join_style = OS.JoinBevel;
- cairo_style = Cairo.CAIRO_LINE_JOIN_BEVEL;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int xDisplay = data.display;
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCLineWidth | OS.GCCapStyle, values);
- int line_style = data.lineStyle == SWT.LINE_SOLID ? OS.LineSolid : OS.LineOnOffDash;
- OS.XSetLineAttributes(xDisplay, handle, values.line_width, line_style, values.cap_style, join_style);
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_set_line_join(cairo, cairo_style);
- }
-}
-/**
- * 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);
- int xDisplay = data.display;
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCLineWidth | OS.GCCapStyle | OS.GCJoinStyle, values);
- int[] dashes = null;
- int width = values.line_width;
- switch (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.dashes;
- if (dashes == null) lineStyle = SWT.LINE_SOLID;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineStyle = lineStyle;
- OS.XSetLineAttributes(xDisplay, handle, values.line_width, dashes != null ? OS.LineOnOffDash : OS.LineSolid, values.cap_style, values.join_style);
- if (dashes != null) {
- byte[] dash_list = new byte[dashes.length];
- for (int i = 0; i < dash_list.length; i++) {
- dash_list[i] = (byte)(width == 0 ? dashes[i] : dashes[i] * width);
- }
- OS.XSetDashes(xDisplay, handle, 0, dash_list, dash_list.length);
- }
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- if (dashes != null) {
- double[] cairoDashes = new double[dashes.length];
- for (int i = 0; i < cairoDashes.length; i++) {
- cairoDashes[i] = width == 0 ? dashes[i] : dashes[i] * width;
- }
- Cairo.cairo_set_dash(cairo, cairoDashes, cairoDashes.length, 0);
- } else {
- Cairo.cairo_set_dash(cairo, null, 0, 0);
- }
- }
-}
-/**
- * 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);
- int xDisplay = data.display;
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCLineWidth | OS.GCCapStyle | OS.GCJoinStyle, values);
- int line_style = data.lineStyle == SWT.LINE_SOLID ? OS.LineSolid : OS.LineOnOffDash;
- OS.XSetLineAttributes(data.display, handle, lineWidth, line_style, values.cap_style, values.join_style);
- data.lineWidth = lineWidth;
- int /*long*/ cairo = data.cairo;
- if (cairo != 0) {
- Cairo.cairo_set_line_width(cairo, Math.max(1, lineWidth));
- }
- switch (data.lineStyle) {
- case SWT.LINE_DOT:
- case SWT.LINE_DASH:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- setLineStyle(data.lineStyle);
- }
-}
-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.
- *
- * @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>
- * </ul>
- *
- * @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.
- *
- * @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>
- * </ul>
- *
- * @see Transform
- *
- * @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);
- }
- //TODO - round off problems
- int /*long*/ clipRgn = data.clipRgn;
- if (clipRgn != 0) {
- double[] matrix = new double[]{1, 0, 0, 1, 0, 0};
- Cairo.cairo_get_matrix(cairo, matrix);
- Cairo.cairo_matrix_invert(matrix);
- int /*long*/ newRgn = OS.XCreateRegion();
- //TODO - get rectangles from region instead of clip box
- XRectangle rect = new XRectangle();
- OS.XClipBox(clipRgn, 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)Math.round(x[0]);
- pointArray[1] = (short)Math.round(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)Math.round(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)Math.round(x[0]);
- pointArray[7] = (short)Math.round(y[0]);
- int /*long*/ polyRgn = OS.XPolygonRegion(pointArray, pointArray.length / 2, OS.EvenOddRule);
- OS.XUnionRegion(handle, polyRgn, handle);
- OS.XDestroyRegion(polyRgn);
- OS.XDestroyRegion(clipRgn);
- data.clipRgn = newRgn;
- }
-}
-/**
- * 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);
- setString(string);
- 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 specifing 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);
- setText(string, flags);
- 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 8c1a5faca2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.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.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>
- */
-public final class GCData {
- public Device device;
- public int style;
- public Image image;
- public int display;
- public int drawable;
- public int foreground = -1;
- public int background = -1;
- public Image backgroundImage;
- public Pattern foregroundPattern;
- public Pattern backgroundPattern;
- public Font font;
- public int colormap;
- public int clipRgn, damageRgn;
- public int lineStyle = SWT.LINE_SOLID;
- public int lineWidth;
- public int[] dashes;
- public int renderTable;
- public int alpha = 0xFF;
- public int interpolation = SWT.DEFAULT;
-
- public int /*long*/ cairo;
-
- 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 7c5eb12cbf..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,1441 +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 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
- */
-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() {
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, width, height);
- if (device.tracking) device.new_Object(this);
-}
-/**
- * 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>IMAGE_COPY</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>IMAGE_DISABLE</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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);
- }
- if (device.tracking) device.new_Object(this);
- return;
- 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);
- }
- this.pixmap = destPixmap;
- if (device.tracking) device.new_Object(this);
- return;
- 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 (device, newData);
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (device.tracking) device.new_Object(this);
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, bounds.width, bounds.height);
- if (device.tracking) device.new_Object(this);
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, image);
- if (device.tracking) device.new_Object(this);
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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(device, image);
- if (device.tracking) device.new_Object(this);
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new ImageData(stream));
- if (device.tracking) device.new_Object(this);
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new ImageData(filename));
- if (device.tracking) device.new_Object(this);
-}
-/**
- * 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]);
-}
-/**
- * Disposes of the operating system resources associated with
- * the image. Applications must dispose of all images which
- * they allocate.
- */
-public void dispose () {
- if (pixmap == 0) return;
- if (device.isDisposed()) return;
- 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;
- if (device.tracking) device.dispose_Object(this);
- device = 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);
- data.data = 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(Device device, int width, int height) {
- this.device = device;
- 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(Device device, ImageData image) {
- this.device = device;
- 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);
- }
- if (device.useXRender && (alpha != -1 || alphaData != null)) {
- mask = OS.XCreatePixmap(xDisplay, drawable, alpha != -1 ? 1 : image.width, alpha != -1 ? 1 : image.height, 8);
- if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- 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, image.width, image.height, OS.AllPlanes, OS.ZPixmap);
- XImage xImage = new XImage();
- OS.memmove(xImage, imagePtr, XImage.sizeof);
- if (xImage.bytes_per_line == image.width) {
- OS.memmove(xImage.data, alphaData, alphaData.length);
- } else {
- byte[] line = new byte[xImage.bytes_per_line];
- for (int y = 0; y < image.height; y++) {
- System.arraycopy(alphaData, image.width * y, line, 0, image.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, image.width, image.height);
- OS.XDestroyImage(imagePtr);
- }
- OS.XFreeGC(xDisplay, gc);
- }
- }
- 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.pixel;
- data.foreground = device.COLOR_BLACK.handle.pixel;
- 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) {
- if (device == null) device = Device.getDevice();
- Image image = new Image();
- image.device = 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 6e13930710..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,569 +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.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>
- */
-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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- handle = OS.XCreateRegion ();
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
-Region (Device device, int handle) {
- this.device = 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);
-}
-/**
- * Disposes of the operating system resources associated with
- * the region. Applications must dispose of all regions which
- * they allocate.
- */
-public void dispose () {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- OS.XDestroyRegion(handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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 (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 188349ecd2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/TextLayout.java
+++ /dev/null
@@ -1,1767 +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 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>
- *
- * @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 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- wrapWidth = ascent = descent = -1;
- lineSpacing = 0;
- orientation = SWT.LEFT_TO_RIGHT;
- XFontStruct fontStruct = getFontHeigth(device.getSystemFont());
- defaultAscent = fontStruct.ascent;
- defaultDescent = fontStruct.descent;
- styles = new StyleItem[2];
- styles[0] = new StyleItem();
- styles[1] = new StyleItem();
- text = ""; //$NON-NLS-1$
- if (device.tracking) device.new_Object(this);
-}
-
-void checkLayout () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-}
-
-int stringWidth (StyleItem run, char[] ch) {
- if (ch.length == 0) return 0;
- int fontList = getItemFont(run).handle;
- byte[] buffer = Converter.wcsToMbcs(null, 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);
- }
- }
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the text layout. Applications must dispose of all allocated text layouts.
- */
-public void dispose () {
- if (device == null) return;
- freeRuns();
- font = null;
- text = null;
- tabs = null;
- styles = null;
- lineOffset = null;
- lineY = null;
- lineWidth = null;
- if (device.tracking) device.dispose_Object(this);
- device = 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) {
- 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) return;
- 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].baseline);
- }
- int lineHeight = lineY[line+1] - lineY[line];
- 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;
- 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);
- gc.drawString(string, drawX, drawRunY, true);
- if (run.style != null && run.style.underline) {
- int underlineY = drawRunY + run.baseline + 1 - run.style.rise;
- gc.drawLine (drawX, underlineY, drawX + run.width, underlineY);
- }
- if (run.style != null && run.style.strikeout) {
- int strikeoutY = drawRunY + run.height - run.height/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.height);
- }
- if (!run.tab) {
- Color fg = foreground;
- if (run.style != null && run.style.foreground != null) fg = run.style.foreground;
- gc.setForeground(fg);
- 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.baseline + 1 - run.style.rise;
- gc.drawLine (drawX, underlineY, drawX + run.width, underlineY);
- }
- if (run.style != null && run.style.strikeout) {
- int strikeoutY = drawRunY + run.height - run.height/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.baseline + 1 - run.style.rise;
- gc.drawLine (selX, underlineY, selX + selWidth, underlineY);
- }
- if (run.style != null && run.style.strikeout) {
- int strikeoutY = drawRunY + run.height - run.height/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.
- *
- * @return the bounds of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-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 charecter 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> or <code>SWT.MOVEMENT_WORD</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 (!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>.
- *
- * @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 (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);
- int fontList = getItemFont(run).handle;
- byte[] buffer = Converter.wcsToMbcs(null, 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);
- if (this.font == font) return;
- if (font != null && font.equals(this.font)) return;
- freeRuns();
- this.font = font;
- 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.
- *
- * @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 894353fd14..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java
+++ /dev/null
@@ -1,404 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 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 d8ce18df90..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java
+++ /dev/null
@@ -1,804 +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.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>
- */
-public class Button extends Control {
- String text = "";
- Image image, bitmap, disabled;
- 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#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 sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected.
- * <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 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 receiver's image to the argument, which may be
- * <code>null</code> indicating that no image should be displayed.
- *
- * @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 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.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 5a6cddb0c9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java
+++ /dev/null
@@ -1,285 +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.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
- */
-public class Canvas extends Composite {
- Caret caret;
-
-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);
- 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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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;
-}
-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;
- }
- 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);
-}
-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 db91b50e34..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java
+++ /dev/null
@@ -1,475 +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.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>
- */
-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 b281364368..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java
+++ /dev/null
@@ -1,462 +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.*;
-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>
- */
-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.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
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ColorDialog(Shell parent, int style) {
- super(parent, style | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
- 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 e30abdb34c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java
+++ /dev/null
@@ -1,1630 +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.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</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
- */
-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 receiver's selection changes, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the combo's list selection changes.
- * <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;
-}
-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 ();
- /*
- * 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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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;
- }
-}
-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. This is equivalent
- * to removing the old item at the index, and then adding the new
- * item at that index.
- *
- * @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);
-}
-/**
- * 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>
- * 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 5b1f0d0d11..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java
+++ /dev/null
@@ -1,1496 +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.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 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. The <code>EMBEDDED</code> style
- * is for use by other widget toolkits and should normally never be used.
- * </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
- */
-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 Widget#getStyle
- */
-public Composite (Composite parent, int style) {
- super (parent, 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) {
- 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);
- gc.fillRectangle (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.GCBackground, values);
- gc.setBackground (control.getBackground ());
- gc.fillRectangle (x, y, width, height);
- OS.XSetBackground (xDisplay, xGC, values.background);
- }
- } 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>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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>
- *
- * @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>
- *
- * @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.
- *
- * @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.min (client.width, rect.x + rect.width);
- int height = 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 0ae9b7a5d4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java
+++ /dev/null
@@ -1,3308 +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.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>FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse,
- * DragDetect, MenuDetect</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>
- */
-public abstract class Control extends Widget implements Drawable {
- int drawCount, redrawWindow;
- Composite parent;
- Cursor cursor;
- Menu menu;
- Image backgroundImage;
- Font font;
- 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 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 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.
- *
- * @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 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 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) {
- 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)) {
- 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;
-}
-boolean dragDetect (int x, int y) {
- return hooks (SWT.DragDetect);
-}
-boolean dragOverride () {
- return false;
-}
-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.
- *
- * @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 <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 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;
- data.foreground = getForegroundPixel ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- data.background = control.getBackgroundPixel ();
- 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 = 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);
-}
-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
- */
-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
- */
-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;
-}
-/**
- * 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 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 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 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 x, int y) {
- Event event = new Event ();
- event.x = x;
- event.y = y;
- postEvent (SWT.DragDetect, event);
- if (isDisposed ()) return false;
- return event.doit;
-}
-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, 0, 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.
- *
- * @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.
- *
- * @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.
- *
- * @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);
-}
-/**
- * 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.
- *
- * @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);
- }
- }
- }
-}
-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 no tool tip text should be shown.
- *
- * @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.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 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 ();
- if ((shell.style & SWT.ON_TOP) != 0) shell.forceActive ();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- boolean dispatch = sendMouseEvent (SWT.MouseDown, xEvent);
- if (isDisposed ()) return 1;
- if (xEvent.button == 2) {
- boolean dragDetect = dragDetect (xEvent.x, xEvent.y);
- if (dragDetect) {
- sendDragEvent (xEvent.x, xEvent.y);
- if (isDisposed ()) return 1;
- }
- if (dragOverride () && dragDetect) 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;
- }
- 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) {
- dispatch = sendMouseEvent (SWT.MouseDoubleClick, xEvent);
- // widget could be disposed at this point
- }
- display.lastTime = eventTime == 0 ? 1 : eventTime;
- display.lastButton = eventButton;
- 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);
- }
- Display display = this.display;
- display.focusEvent = SWT.FocusIn;
- sendEvent (SWT.FocusIn);
- // widget could be disposed at this point
- display.focusEvent = SWT.None;
- 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);
- }
- }
-
- /* Issue the focus out event */
- if (display.postFocusOut) {
- postEvent (SWT.FocusOut);
- } else {
- Display display = this.display;
- display.focusEvent = SWT.FocusOut;
- sendEvent (SWT.FocusOut);
- // widget could be disposed at this point
- display.focusEvent = SWT.None;
- }
-
- /* 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 95685dd8e7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java
+++ /dev/null
@@ -1,795 +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.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
- */
-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
- */
-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 b7c082a47a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java
+++ /dev/null
@@ -1,342 +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.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>
- */
-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.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.
- * </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, 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 e6675f88c7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java
+++ /dev/null
@@ -1,3706 +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.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</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
- */
-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";
- static final String SHELL_HANDLE_KEY = "org.eclipse.swt.internal.motif.shellHandle";
- 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;
-
- /* 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;
-
- /* 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.";
- /*
- * 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);
-// }
-
- /*
- * In order to support CLDC, .class cannot be used because
- * it does not compile on some Java compilers when they are
- * targeted for CLDC. Use Class.forName() instead.
- */
- static final Class OS_LOCK;
- static {
- Class lock = null;
- try {
- lock = Class.forName ("org.eclipse.swt.internal.motif.OS");
- } catch (Throwable th) {
- }
- OS_LOCK = lock;
- }
-
- /* 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) {
- 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 synchronized void checkDisplay (Thread thread, boolean multiple) {
- 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 (!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 */
- int [] argc = new int [] {0};
- int xtContext = OS.XtCreateApplicationContext ();
- OS.XtSetLanguageProc (xtContext, 0, 0);
-
- xEvent = OS.XtMalloc (XEvent.sizeof);
-
- /*
- * 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-*-*-*-*-*-*:";
- 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);
- 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);
- pixmap = OS.XmGetPixmap (screen, buffer, fgPixel, bgPixel);
- if (pixmap == OS.XmUNSPECIFIED_PIXMAP) pixmap = 0;
- } else {
- pixmap = 0;
- }
- }
- }
- return pixmap;
-}
-synchronized static void deregister (Display display) {
- 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) {
- 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 synchronized 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 synchronized Display findDisplay (Thread thread) {
- 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 synchronized Display getDefault () {
- 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;
-}
-/**
- * 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 () {
- 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");
- errorMask = createMask (errorPixmap);
- }
- imagePixmap = errorPixmap;
- maskPixmap = errorMask;
- break;
- case SWT.ICON_INFORMATION:
- if (infoPixmap == 0) {
- infoPixmap = createPixmap ("xm_information");
- infoMask = createMask (infoPixmap);
- }
- imagePixmap = infoPixmap;
- maskPixmap = infoMask;
- break;
- case SWT.ICON_QUESTION:
- if (questionPixmap == 0) {
- questionPixmap = createPixmap ("xm_question");
- questionMask = createMask (questionPixmap);
- }
- imagePixmap = questionPixmap;
- maskPixmap = questionMask;
- break;
- case SWT.ICON_WARNING:
- if (warningPixmap == 0) {
- warningPixmap = createPixmap ("xm_warning");
- warningMask = createMask (warningPixmap);
- }
- imagePixmap = warningPixmap;
- maskPixmap = warningMask;
- break;
- case SWT.ICON_WORKING:
- if (workingPixmap == 0) {
- workingPixmap = createPixmap ("xm_working");
- 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 () {
- 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);
- 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);
- focusProc = focusCallback.getAddress ();
- if (focusProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- windowCallback = new Callback (this, "windowProc", 4);
- windowProc = windowCallback.getAddress ();
- if (windowProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- windowTimerCallback = new Callback (this, "windowTimerProc", 2);
- windowTimerProc = windowTimerCallback.getAddress ();
- if (windowTimerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- timerCallback = new Callback (this, "timerProc", 2);
- timerProc = timerCallback.getAddress ();
- if (timerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- caretCallback = new Callback (this, "caretProc", 2);
- caretProc = caretCallback.getAddress ();
- if (caretProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- mouseHoverCallback = new Callback (this, "mouseHoverProc", 2);
- mouseHoverProc = mouseHoverCallback.getAddress ();
- if (mouseHoverProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- checkExposeCallback = new Callback (this, "checkExposeProc", 3);
- checkExposeProc = checkExposeCallback.getAddress ();
- if (checkExposeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- checkResizeCallback = new Callback (this, "checkResizeProc", 3);
- checkResizeProc = checkResizeCallback.getAddress ();
- if (checkResizeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- wakeCallback = new Callback (this, "wakeProc", 3);
- 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);
- 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;
- case OS.Mod2MapIndex: numLock = "Mod2"; break;
- case OS.Mod3MapIndex: numLock = "Mod3"; break;
- case OS.Mod4MapIndex: numLock = "Mod4"; break;
- case OS.Mod5MapIndex: numLock = "Mod5"; break;
- default: numLock = "Mod2";
- }
- 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");
- arrowTranslations = OS.XtParseTranslationTable (buffer1);
- byte [] buffer2 = Converter.wcsToMbcs (null, "~Meta ~Alt <Key>Tab:\nShift ~Meta ~Alt <Key>Tab:\0");
- tabTranslations = OS.XtParseTranslationTable (buffer2);
- byte [] buffer3 = Converter.wcsToMbcs (null, "<Btn2Down>:\0");
- 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.pixel;
- data.foreground = getSystemColor (SWT.COLOR_BLACK).handle.pixel;
- 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 != 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 != 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>
- * </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) {
- 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 = wcsToMbcs (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;
-}
-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 runAsyncMessages (false);
-}
-static synchronized void register (Display display) {
- 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;
-}
-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 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 #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 () {
- /*
- * 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 ()) {
- 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 true;
-}
-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 ();
- 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);
- }
-}
-/**
- * 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 (this.synchronizer != null) {
- this.synchronizer.runAsyncMessages(true);
- }
- this.synchronizer = synchronizer;
-}
-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;
- /* Use the character encoding for the default locale */
- byte [] buffer = Converter.wcsToMbcs (null, toolTipText, 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 occured when executing the runnable</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void syncExec (Runnable runnable) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- 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 () {
- 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";
- 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 57e4423955..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java
+++ /dev/null
@@ -1,570 +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.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>
- */
-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;
- 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.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.
- * </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 FileDialog (Shell parent, int style) {
- super (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;
-}
-
-/**
- * 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;
-}
-
-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);
-
- 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
- * Windows, an extension filter string is typically of
- * the form "*.extension", where "*.*" matches all files.
- * </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;
-}
-
-/**
- * Sets the 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;
-}
-}
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 5eeacd229d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java
+++ /dev/null
@@ -1,1172 +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.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>
- */
-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.NONE);
-}
-
-/**
- * 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, style | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
- 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 bbaeb78eb0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java
+++ /dev/null
@@ -1,343 +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.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>
- */
-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.XmNchildHorizontalSpacing, 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 x = marginWidth + thickness;
- int y = marginHeight + thickness;
- int width = argList [1] - ((marginWidth + thickness) * 2) - 1;
- int height = argList [3] - ((marginHeight + thickness) * 2) - 1;
- 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) - 1;
- }
- 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 9c67451c8a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java
+++ /dev/null
@@ -1,632 +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.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.
- * <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>
- */
-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 b34d223aa2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Link.java
+++ /dev/null
@@ -1,670 +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.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>
- *
- * @since 3.1
- */
-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 sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected.
- * <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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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, linkStart, index, 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 tag can be used to distinguish between them. The string may
- * include the mnemonic character and line delimiters.
- * </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;
- XRectangle xrect = new XRectangle ();
- xrect.x = (short) xEvent.x;
- xrect.y = (short) xEvent.y;
- xrect.width = (short) xEvent.width;
- xrect.height = (short) xEvent.height;
- int damageRgn = OS.XCreateRegion ();
- OS.XUnionRectWithRegion (xrect, damageRgn, 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);
- }
- }
- if (hooks (SWT.Paint) || filters (SWT.Paint)) {
- Event event = new Event ();
- event.count = xEvent.count;
- event.x = xEvent.x;
- event.y = xEvent.y;
- event.width = xEvent.width;
- event.height = xEvent.height;
- event.gc = GC.motif_new (this, data);
- 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) {
- 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 6c36de9e0d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java
+++ /dev/null
@@ -1,1564 +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.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>
- */
-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 receiver's selection changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 visibility 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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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. This is equivalent
- * to <code>remove</code>'ing the old item at the index, and then
- * <code>add</code>'ing the new item at that index.
- *
- * @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 d0aaf203ba..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java
+++ /dev/null
@@ -1,887 +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.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>
- */
-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.
- *
- * @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>
- *
- * @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 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.
- *
- * @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.
- *
- * @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 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 (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 ();
- 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 9cc067c0c4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java
+++ /dev/null
@@ -1,980 +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.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>
- */
-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;
- /*
- * 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 9bb0c7cf43..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,420 +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.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>
- */
-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>
- */
-public MessageBox (Shell parent, int style) {
- super (parent, checkStyle (style));
- checkSubclass ();
-}
-int activate (int widget, int client, int call) {
- OS.XtUnmanageChild (widget);
- button = client;
- return 0;
-}
-static int checkStyle (int style) {
- if ((style & (SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) == 0) style |= SWT.APPLICATION_MODAL;
- 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 38453867d3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,374 +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.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of the receiver represent is 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>
- */
-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 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);
-}
-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 ();
-}
-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 3731408963..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,440 +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.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>
- */
-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 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 0fb6132258..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,380 +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.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>
- */
-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 receiver's value changes, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control's value changes.
- * <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 receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 07bfcc413c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,701 +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.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
- */
-public class ScrollBar extends Widget {
- Scrollable parent;
-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 receiver's value changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
-}
-/**
- * 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);
-}
-/**
- * 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 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 receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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();
- parent.setScrollBarVisible (this, visible);
-}
-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) {
- 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) {
- 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 0e1590130f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,360 +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.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>
- */
-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 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);
- if (argList1 [1] != argList3 [1] || argList1 [3] != argList3 [3]) {
- sendEvent (SWT.Resize);
- return true;
- }
- return false;
-}
-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 c4220fbf6a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,1863 +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.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</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
- */
-public class Shell extends Decorations {
- int shellHandle, focusProxy;
- boolean reparented, realized, moved, resized, opened;
- int oldX, oldY, oldWidth, oldHeight;
- Control lastActive;
- Region region;
-
- 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");
-/**
- * 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#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
-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#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
-public Shell (Display display, int style) {
- this (display, null, style, 0);
-}
-Shell (Display display, Shell parent, int style, int handle) {
- 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.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
- */
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.display : null, parent, style, 0);
-}
-
-static int checkStyle (int style) {
- style = Decorations.checkStyle (style);
- if ((style & SWT.ON_TOP) != 0) style &= ~SWT.SHELL_TRIM;
- 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;
-}
-
-public static Shell motif_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.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 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.RESIZE)) == 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;
- 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);
-
- /*
- * 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.RESIZE)) == 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
- * @see Shell#open
- * @see Shell#setActive
- */
-public void forceActive () {
- checkWidget ();
- bringToTop (true);
-}
-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 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);
-}
-/**
- * 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 () {
- checkWidget ();
- return region;
-}
-public Shell getShell () {
- checkWidget();
- return this;
-}
-/**
- * Returns an array containing all shells which are
- * descendents 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 () {
- 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
- * @see Shell#setActive
- * @see Shell#forceActive
- */
-public void open () {
- checkWidget();
- bringToTop (false);
- setVisible (true);
- if (isDisposed ()) return;
- if (!restoreFocus () && !traverseGroup (true)) setFocus ();
-}
-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;
- region = 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
- * @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 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);
- }
-}
-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;
- int[] type = new int[1], format = new int[1], nitems = new int[1], bytes_after = new int[1], atomsPtr = new int[1];
- OS.XGetWindowProperty (xDisplay, xWindow, property, 0, Integer.MAX_VALUE, false, OS.XA_ATOM, type, format, nitems, bytes_after, atomsPtr);
- if (type [0] == OS.None) return;
- int[] atoms = new int [nitems [0]];
- OS.memmove (atoms, atomsPtr [0], nitems [0] * 4);
-
- if (maximized) {
- boolean hasHmax = false;
- boolean hasVmax = false;
- for (int i = 0; i < nitems [0]; i++) {
- int atom = atoms [i];
- if (atom == hMaxAtom) hasHmax = true;
- if (atom == vMaxAtom) hasVmax = true;
- }
- if (!hasHmax) {
- int[] temp = new int [atoms.length + 1];
- System.arraycopy (atoms, 0, temp, 0, atoms.length);
- temp [atoms.length] = hMaxAtom;
- atoms = temp;
- }
- if (!hasVmax) {
- int[] temp = new int [atoms.length + 1];
- System.arraycopy (atoms, 0, temp, 0, atoms.length);
- temp [atoms.length] = vMaxAtom;
- atoms = temp;
- }
- } else {
- int[] temp = new int [nitems [0]];
- int index = 0;
- for (int i = 0; i < nitems [0]; i++) {
- int atom = atoms [i];
- if (atom != hMaxAtom && atom != vMaxAtom) {
- temp [index++] = atom;
- }
- }
- atoms = new int [index];
- System.arraycopy (temp, 0, atoms, 0, index);
- }
-
- OS.XChangeProperty (xDisplay, xWindow, property, OS.XA_ATOM, 32, OS.PropModeReplace, atoms, atoms.length);
-}
-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);
-}
-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);
- if (!OS.XtIsRealized (shellHandle)) realizeWidget ();
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (shellHandle);
- 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;
-}
-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) {
- 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:
- if (display.postFocusOut) {
- postEvent (SWT.Deactivate);
- } else {
- sendEvent (SWT.Deactivate);
- }
- 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 4eb1ff6151..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,537 +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.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
- */
-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));
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's value changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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) {
- 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) {
- 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 f95d18ffba..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,930 +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.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>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, Modify</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @since 3.1
- */
-public class Spinner extends 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 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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];
-}
-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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 ();
- if (value < 0) return;
- 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 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 [] 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 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 [] 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) {
- String wholePart = string.substring (0, index);
- 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;
- } else {
- value = Integer.parseInt (string);
- }
- } else {
- value = Integer.parseInt (string);
- }
- if (argList [3] <= value && value <= argList [5]) {
- position = value;
- }
- } catch (NumberFormatException e) {
- }
- }
- if (position == argList [7]) {
- String string = String.valueOf (position);
- if (digits > 0) {
- String decimalSeparator = getDecimalSeparator ();
- 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 ();
- }
- 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.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;
- }
- 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 2bc549b6a9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,1586 +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.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.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CENTER, LEFT, MULTI, PASSWORD, 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.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
-public class Text extends Scrollable {
- char echoCharacter;
- boolean ignoreChange;
- String hiddenText;
- int drawCount;
-
- 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;
-
- /*
- * 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 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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.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);
- }
- 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 && (style & SWT.SINGLE) != 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 = "";
- if ((style & SWT.PASSWORD) != 0) setEchoChar ('*');
-}
-/**
- * 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) {
- if (hooks (SWT.DragDetect)) {
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (handle, start, end);
- if (start [0] == end [0]) return false;
- int pos = OS.XmTextXYToPos(handle, (short) x, (short) y);
- return pos > start [0] && pos < end [0];
- }
- return false;
-}
-boolean dragOverride () {
- return true;
-}
-/**
- * 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;
-}
-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);
-}
-/**
- * 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 "";
- start = Math.max (0, start);
- end = Math.min (end, length - 1);
- 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 = 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 xFocusIn (XFocusChangeEvent xEvent) {
- super.xFocusIn (xEvent);
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if ((style & SWT.READ_ONLY) != 0) return 0;
- if ((style & SWT.MULTI) != 0) return 0;
- int [] argList = {OS.XmNcursorPositionVisible, 1};
- OS.XtSetValues (handle, argList, argList.length / 2);
- 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) != 0) return 0;
- if ((style & SWT.MULTI) != 0) return 0;
- int [] argList = {OS.XmNcursorPositionVisible, 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
- 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 481ad7a668..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,512 +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.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>
- */
-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 3795d093b9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,1151 +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.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>
- */
-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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 disbled 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 no tool tip text should be shown.
- *
- * @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 696458cf74..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,962 +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.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>
- */
-public class Tracker extends Widget {
- Composite parent;
- boolean tracking, cancelled, stippled;
- Rectangle [] rectangles, proportions;
- Rectangle bounds;
- int cursorOrientation = SWT.NONE;
- int cursor, 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
- */
-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 () {
- 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 () {
- 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 () {
- 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 ();
- 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();
- 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 moveRectangles (int xChange, int yChange) {
- 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;
- 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;
- }
-
- Point cursorPos;
- int mouseMasks = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask;
- boolean mouseDown = (mask [0] & mouseMasks) != 0;
- if (!mouseDown) {
- if ((style & SWT.RESIZE) != 0) {
- cursorPos = adjustResizeCursor ();
- } else {
- cursorPos = adjustMoveCursor ();
- }
- 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 resizeRectangles (int xChange, int yChange) {
- /*
- * 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 = 0;
- if (value != null) cursor = value.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;
-}
-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 ();
- }
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
- }
- return result;
-}
-
-int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) {
- if (cursor != 0) {
- int xDisplay = display.xDisplay;
- OS.XChangeActivePointerGrab (xDisplay,
- OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
- cursor, 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 ();
- 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 f875cd1611..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,1222 +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.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
- */
-public abstract class Widget {
- /**
- * the handle to the OS resource
- * (WARNING: This field is platform dependend)
- */
- 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;
-
- /* 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 #removeListener
- * @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 descendents. After this method has
- * been invoked, the receiver and all descendents 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 descendents
- * 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);
-}
-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;
-}
-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 #removeListener
- */
-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 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 #addListener
- * @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 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 #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 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 #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 a94be4b8a6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,249 +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.*;
-
-/**
- * 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
- */
-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() {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, red, green, blue);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, rgb.red, rgb.green, rgb.blue);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the color. Applications must dispose of all colors which
- * they allocate.
- */
-public void dispose() {
- if (handle == -1) return;
- if (device.isDisposed()) return;
-
- handle = -1;
- if (device.tracking) device.dispose_Object(this);
- device = 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;
- 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(Device device, 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.device = device;
- 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) {
- if (device == null) device = Device.getDevice();
- Color color = new Color();
- color.handle = handle;
- color.device = device;
- 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 5e83bc2eca..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,461 +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.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>
- */
-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() {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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, source.type,
- source.x, source.y, source.disposalMethod, source.delayTime);
-
- /* 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, 0, 0, 0,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, 0, 0, 0,
- false, false);
- else ImageData.blit(ImageData.BLIT_SRC,
- source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, null, null, null,
- 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);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the cursor. Applications must dispose of all cursors which
- * they allocate.
- */
-public void dispose () {
- if (type == 0) return;
- if (device.isDisposed()) return;
- if (type == OS.Ph_CURSOR_BITMAP && bitmap != 0) {
- OS.free(bitmap);
- }
- type = bitmap = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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 && 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) {
- if (device == null) device = Device.getDevice();
- Cursor cursor = new Cursor();
- cursor.type = type;
- cursor.bitmap = bitmap;
- cursor.device = device;
- 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 70d7b87134..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,589 +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.*;
-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.
- */
-public abstract class Device implements Drawable {
-
- /* Debugging */
- public static boolean DEBUG;
- boolean debug = DEBUG;
- boolean tracking = DEBUG;
- Error [] errors;
- Object [] objects;
-
- boolean disposed;
-
- byte[] systemFont;
-
- static final Object CREATE_LOCK = new Object();
-
- /*
- * 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.
- *
- * This code will be removed in the future.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName ("org.eclipse.swt.widgets.Display");
- } catch (Throwable 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 (CREATE_LOCK) {
- if (data != null) {
- debug = data.debug;
- tracking = data.tracking;
- }
- create (data);
- init ();
- if (tracking) {
- errors = new Error [128];
- objects = new Object [128];
- }
-
- /* Initialize the system font slot */
- systemFont = getSystemFont ().handle;
- }
-}
-
-/**
- * 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 () {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- disposed = true;
- if (tracking) {
- objects = null;
- errors = null;
- }
-}
-
-void dispose_Object (Object object) {
- 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;
- int count = 0, length = 0;
- if (tracking) 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++;
- }
- }
- 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 Font.photon_new (this, 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 () {
-}
-
-/**
- * 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 () {
- return disposed;
-}
-
-void new_Object (Object object) {
- 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 593b25584d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 e98b5b25f0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,276 +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.*;
-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
- */
-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() {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, fd.getName(), fd.getHeight(), fd.getStyle(), fd.stem);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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(device,fd.getName(), fd.getHeight(), fd.getStyle(), fd.stem);
- if (device.tracking) device.new_Object(this);
-}
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, name, height, style, null);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the font. Applications must dispose of all fonts which
- * they allocate.
- */
-public void dispose() {
- if (handle == null) return;
- if (device.isDisposed()) return;
-
- handle = null;
- if (device.tracking) device.dispose_Object(this);
- device = 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(Device device, String name, int height, int style, byte[] stem) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.device = device;
- 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;
- 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) {
- if (device == null) device = Device.getDevice();
- Font font = new Font();
- font.init(device, 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 784e3d5c6f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,455 +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.*;
-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
- */
-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 un-initialized 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
- */
-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 b41f9c9494..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,173 +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.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
- */
-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 c261e0fbfc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,3441 +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 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>
- * 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
- */
-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 and background color 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>
- * </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 and background color 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>
- * </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);
- if (device.tracking) device.new_Object(this);
- } 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();
- 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 clipRects = data.clipRects;
- int child_clip = getClipping(widget, data.topWidget, true, true, null);
- if (clipRects == 0 && child_clip == 0) {
- OS.PtBlit(widget, rect, delta);
- } else {
- int srcTile = OS.PhGetTile();
- OS.memmove(srcTile, rect, PhRect_t.sizeof);
- int clip = child_clip;
- if (clipRects != 0) {
- clip = OS.PhRectsToTiles(clipRects, data.clipRectsCount);
- if (child_clip != 0) {
- short[] unused = new short[1];
- int newClip = OS.PhIntersectTilings(clip, child_clip, unused);
- OS.PhFreeTiles(child_clip);
- OS.PhFreeTiles(clip);
- clip = newClip;
- }
- }
- OS.PtClippedBlit(widget, srcTile, delta, clip);
- OS.PhFreeTiles(clip);
- }
- }
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the graphics context. Applications must dispose of all GCs
- * which they allocate.
- */
-public void dispose() {
- int flags = OS.PtEnter(0);
- try {
- if (handle == 0) return;
- if (data.device.isDisposed()) return;
-
- 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.
- */
- Device device = data.device;
- drawable.internal_dispose_GC(handle, data);
- drawable = null;
- handle = 0;
- data.image = null;
- data.font = null;
- data.rid = data.widget = data.topWidget = 0;
- if (device.tracking) device.dispose_Object(this);
- data.device = null;
- 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();
- 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();
- 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();
- 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();
- 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();
- 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.
- *
- * @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>
- * </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();
- 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();
- 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();
- 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();
- 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();
- 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();
- 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) {
- PhRect_t rect = new PhRect_t();
- OS.PfExtentText(rect, null, data.font, 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(data.font);
- 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 specifing 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();
- 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();
- 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();
- 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.
- *
- * @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>
- * </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();
- 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();
- 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();
- 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.
- *
- * @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 Font.photon_new(data.device, 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, 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
- */
-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 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 lin 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 #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.
- *
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @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.
- *
- * @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>
- * </ul>
- *
- * @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>.
- *
- * @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>
- * </ul>
- *
- * @see Pattern
- *
- * @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.
- *
- * @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>
- * </ul>
- *
- * @see Path
- *
- * @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.handle;
- 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>.
- *
- * @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>
- * </ul>
- *
- * @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>.
- *
- * @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>
- * </ul>
- *
- * @see Pattern
- *
- * @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 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) {
- OS.PfLoadMetrics(data.font);
- OS.PgSetFont(data.font);
- }
- 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 (rid == OS.Ph_DEV_RID) OS.PgSetRegion(rid);
- else if (widget != 0) OS.PgSetRegion(OS.PtWidgetRid(widget));
- else if (data.image != null) return;
-
- /* NOTE: PgSetRegion resets the clipping rectangle */
- OS.PgSetMultiClip(data.clipRectsCount, data.clipRects);
-
- if (widget == 0 || data.paint) return;
-
- 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(PhRect_t.sizeof);
- OS.memset(clip_rects, 0, PhRect_t.sizeof);
- }
- OS.PgSetClipping((short)clip_rects_count[0], clip_rects);
- OS.free(clip_rects);
-}
-
-int getClipping(int widget, int topWidget, boolean clipChildren, boolean clipSiblings, int[] child_tiles) {
- 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) {
- 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;
- }
- 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.
- *
- * @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>
- * </ul>
- *
- * @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.
- *
- * @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>
- * </ul>
- *
- * @see Transform
- *
- * @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, 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 specifing 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 b1e3371e50..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GCData.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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>
- */
-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 byte[] 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 1575420719..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,1064 +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 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
- */
-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 () {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, width, height);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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>IMAGE_COPY</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>IMAGE_DISABLE</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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;
- if (device.tracking) device.new_Object(this);
- return;
- 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 (device, newData);
- if (device.tracking) device.new_Object(this);
- return;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, bounds.width, bounds.height);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, data);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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(device, image);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new ImageData(stream));
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new ImageData(filename));
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the image. Applications must dispose of all images which
- * they allocate.
- */
-public void dispose () {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- if (memGC != null) memGC.dispose();
- destroyImage(handle);
- handle = 0;
- memGC = null;
- if (device.tracking) device.dispose_Object(this);
- device = 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(Device device, int width, int height) {
- if (width <= 0 || height <= 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.device = device;
- 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(Device device, ImageData i) {
- if (i == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
-
- /*
- * 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) {
- if (device == null) device = Device.getDevice();
- Image image = new Image();
- image.type = type;
- image.handle = handle;
- image.device = device;
- 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 3c41b996ec..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,646 +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.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>
- */
-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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- handle = EMPTY_REGION;
- if (device.tracking) device.new_Object(this);
-}
-
-Region(Device device, int handle) {
- this.device = 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);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the region. Applications must dispose of all regions which
- * they allocate.
- */
-public void dispose () {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- if (handle != EMPTY_REGION) OS.PhFreeTiles (handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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 (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 8f14dc84ad..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/Converter.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 9f6379eb6e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Button.java
+++ /dev/null
@@ -1,605 +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.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>
- */
-public class Button 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#ARROW
- * @see SWT#CHECK
- * @see SWT#PUSH
- * @see SWT#RADIO
- * @see SWT#TOGGLE
- * @see SWT#FLAT
- * @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 sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected.
- * <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 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 receiver's image to the argument, which may be
- * <code>null</code> indicating that no image should be displayed.
- *
- * @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 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.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 ca8ea676d2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Canvas.java
+++ /dev/null
@@ -1,264 +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.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
- */
-public class Canvas extends Composite {
- Caret caret;
-
-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);
-}
-
-/**
- * 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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 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;
- }
- 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);
-}
-}
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 a73f89ba56..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Caret.java
+++ /dev/null
@@ -1,497 +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.*;
-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>
- */
-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);
- OS.PgSetRegion (OS.PtWidgetRid (handle));
- 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);
- 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 03ec945842..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ColorDialog.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * 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>
- */
-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.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.
- * </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, 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 06333953a1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Combo.java
+++ /dev/null
@@ -1,1348 +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.*;
-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</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
- */
-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 receiver's selection changes, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the combo's list selection changes.
- * <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;
-}
-
-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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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. This is equivalent
- * to removing the old item at the index, and then adding the new
- * item at that index.
- *
- * @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);
-}
-
-/**
- * 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>
- * 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 7dd9d23a80..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Composite.java
+++ /dev/null
@@ -1,1131 +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.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. The <code>EMBEDDED</code> style
- * is for use by other widget toolkits and should normally never be used.
- * </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
- */
-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 Widget#getStyle
- */
-public Composite (Composite parent, int style) {
- super (parent, 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>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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>
- *
- * @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>
- *
- * @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.
- *
- * @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 c6ab9813ef..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Control.java
+++ /dev/null
@@ -1,2853 +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.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>FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse,
- * DragDetect, MenuDetect</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>
- */
-public abstract class Control extends Widget implements Drawable {
- Composite parent;
- Menu menu;
- Object layoutData;
- String toolTipText;
- Image backgroundImage;
- 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 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 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.
- *
- * @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 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 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;
-}
-
-int drawProc (int widget, int damage) {
- drawWidget (widget, damage);
- if (!hooks(SWT.Paint) && !filters (SWT.Paint)) return OS.Pt_CONTINUE;
-
- /* Translate the damage to widget coordinates */
- short [] widgetX = new short [1];
- short [] widgetY = new short [1];
- OS.PtGetAbsPosition (handle, widgetX, widgetY);
- short [] shellX = new short [1];
- short [] shellY = new short [1];
- int shellHandle = OS.PtFindDisjoint (handle);
- OS.PtGetAbsPosition (shellHandle, shellX, shellY);
- PhPoint_t pt = new PhPoint_t ();
- pt.x = (short) (shellX [0] - widgetX [0]);
- pt.y = (short) (shellY [0] - widgetY [0]);
- damage = OS.PhCopyTiles (damage);
- damage = OS.PhTranslateTiles (damage, pt);
-
- /* Send the paint event */
- PhTile_t tile = new PhTile_t ();
- OS.memmove (tile, damage, PhTile_t.sizeof);
- boolean noMerge = (style & SWT.NO_MERGE_PAINTS) != 0 && (state & CANVAS) != 0;
- if (tile.next != 0 && noMerge) {
- while (tile.next != 0) {
- OS.memmove (tile, tile.next, PhTile_t.sizeof);
- if (tile.rect_ul_x != tile.rect_lr_x || tile.rect_ul_y != tile.rect_lr_y) {
- Event event = new Event ();
- event.x = tile.rect_ul_x;
- event.y = tile.rect_ul_y;
- event.width = tile.rect_lr_x - tile.rect_ul_x + 1;
- event.height = tile.rect_lr_y - tile.rect_ul_y + 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 = event.gc = GC.photon_new (this, data);
- gc.setClipping (event.x, event.y, event.width, event.height);
- sendEvent (SWT.Paint, event);
- if (isDisposed ()) break;
- gc.dispose ();
- event.gc = null;
- }
- }
- } else {
- if (tile.rect_ul_x != tile.rect_lr_x || tile.rect_ul_y != tile.rect_lr_y) {
- Event event = new Event ();
- event.x = tile.rect_ul_x;
- event.y = tile.rect_ul_y;
- event.width = tile.rect_lr_x - tile.rect_ul_x + 1;
- event.height = tile.rect_lr_y - tile.rect_ul_y + 1;
- Region region = Region.photon_new (display, tile.next);
- 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 = event.gc = GC.photon_new (this, data);
- gc.setClipping (region);
- sendEvent (SWT.Paint, event);
- gc.dispose ();
- event.gc = null;
- }
- }
- 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.
- *
- * @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();
- 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 <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 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;
- data.topWidget = topHandle ();
- data.foreground = args [1];
- data.background = args [4];
- data.font = getFont ().handle;
- 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 ();
-}
-
-boolean isFocusAncestor () {
- Control control = display.getFocusControl ();
- while (control != null && control != this) {
- 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 == 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));
-}
-
-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.time = ev.timestamp;
- setMouseState (event, SWT.MouseDown, pe, ev);
- postEvent (SWT.MouseDown, event);
- if (pe.click_count == 2) {
- Event clickEvent = new Event ();
- 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.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;
- layoutData = 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
- */
-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
- */
-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 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 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 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.
- *
- * @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;
- }
- 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);
- }
-}
-
-/**
- * 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.
- *
- * @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.
- *
- * @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 ();
- }
- 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.
- *
- * @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 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 no tool tip text should be shown.
- *
- * @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.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 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 6e9256633a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Decorations.java
+++ /dev/null
@@ -1,632 +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.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
- */
-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
- */
-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 c9fc2f160e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/DirectoryDialog.java
+++ /dev/null
@@ -1,172 +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.*;
-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>
- */
-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.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.
- * </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, 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 3b2fe120b5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java
+++ /dev/null
@@ -1,2659 +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.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</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
- */
-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) {
- 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 synchronized void checkDisplay (Thread thread, boolean multiple) {
- 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 ();
- if (Default == null) Default = this;
-}
-
-void createDisplay (DeviceData data) {
- OS.PtInit (null);
- OS.PgSetDrawBufferSize (DrawBufferSize);
- app_context = OS.PtCreateAppContext ();
-}
-
-synchronized void deregister () {
- for (int i=0; i<Displays.length; i++) {
- if (this == 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 ();
- 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 synchronized Display findDisplay (Thread thread) {
- 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) {
- 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 synchronized Display getCurrent () {
- Thread current = Thread.currentThread ();
- for (int i=0; i<Displays.length; i++) {
- Display display = Displays [i];
- if (display != null && display.thread == current) return display;
- }
- 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 synchronized Display getDefault () {
- 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;
-}
-
-/**
- * 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 () {
- 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 () {
- 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 != 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 != 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>
- * </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) {
- 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 result;
-}
-
-synchronized void register () {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] == null) {
- Displays [i] = this;
- return;
- }
- }
- Display [] newDisplays = new Display [Displays.length + 4];
- System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
- newDisplays [Displays.length] = this;
- 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 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 #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 () {
- /*
- * 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 ()) {
- 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 true;
-}
-
-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 (this.synchronizer != null) {
- this.synchronizer.runAsyncMessages(true);
- }
- this.synchronizer = synchronizer;
-}
-
-/**
- * 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 occured when executing the runnable</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void syncExec (Runnable runnable) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- 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 () {
- 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 6d5337de1a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FileDialog.java
+++ /dev/null
@@ -1,290 +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.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>
- */
-public class FileDialog extends Dialog {
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String filterPath = "", fileName = "";
- 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.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.
- * </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 FileDialog (Shell parent, int style) {
- super (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;
-}
-
-/**
- * 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;
-}
-
-/**
- * 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);
- }
- 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
- * Windows, an extension filter string is typically of
- * the form "*.extension", where "*.*" matches all files.
- * </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;
-}
-
-/**
- * Sets the 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;
-}
-
-}
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 bb59bd64c4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FontDialog.java
+++ /dev/null
@@ -1,207 +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.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>
- */
-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.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.
- * </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, 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 f6ae2d9721..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Group.java
+++ /dev/null
@@ -1,219 +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.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>
- */
-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 08c4b7d14b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java
+++ /dev/null
@@ -1,453 +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.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.
- * <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>
- */
-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 2384f27c94..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Link.java
+++ /dev/null
@@ -1,674 +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.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>
- *
- * @since 3.1
- */
-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 sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected.
- * <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, linkStart, index, 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 tag can be used to distinguish between them. The string may
- * include the mnemonic character and line delimiters.
- * </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 0a6f0c0582..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/List.java
+++ /dev/null
@@ -1,1256 +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.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>
- */
-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 receiver's selection changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 visibility 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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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. This is equivalent
- * to <code>remove</code>'ing the old item at the index, and then
- * <code>add</code>'ing the new item at that index.
- *
- * @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 15940aa9b6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Menu.java
+++ /dev/null
@@ -1,818 +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.*;
-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>
- */
-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.
- *
- * @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>
- *
- * @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 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.
- *
- * @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.
- *
- * @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 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 (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 ();
- 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 5d87854e1a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java
+++ /dev/null
@@ -1,915 +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.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>
- */
-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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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).
- * </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 18b8dc57cc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,205 +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.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>
- */
-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>
- */
-public MessageBox (Shell parent, int style) {
- super (parent, checkStyle (style));
- checkSubclass ();
-}
-static int checkStyle (int style) {
- if ((style & (SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) == 0) style |= SWT.APPLICATION_MODAL;
- 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 965fc6fbc5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,242 +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.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of the receiver represent is 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>
- */
-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 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];
-}
-
-/**
- * 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);
-}
-
-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 c302342d0d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,409 +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.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>
- */
-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 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
- OS.PgSetRegion (OS.PtWidgetRid (parentHandle));
- 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 040c50d992..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,373 +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.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>
- */
-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 receiver's value changes, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control's value changes.
- * <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 receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 9fbe8b8be3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,722 +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.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
- */
-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 receiver's value changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 c824ecc5db..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,242 +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.*;
-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>
- */
-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 ebcbb4a3bf..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,1290 +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.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</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
- */
-public class Shell extends Decorations {
- int shellHandle;
- Menu activeMenu;
- int blockedList;
- Control lastActive;
- Region region;
-
-/**
- * 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#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
-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#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
-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
- */
-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);
- 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
- * @see Shell#open
- * @see Shell#setActive
- */
-public void forceActive () {
- checkWidget ();
- bringToTop (true);
-}
-
-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 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]);
-}
-
-/**
- * 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 () {
- checkWidget ();
- return region;
-}
-
-public Shell getShell () {
- checkWidget();
- return this;
-}
-
-/**
- * Returns an array containing all shells which are
- * descendents 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
- * @see Shell#setActive
- * @see Shell#forceActive
- */
-public void open () {
- checkWidget();
- setVisible (true);
- if (isDisposed ()) return;
- traverseGroup (true);
-}
-
-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;
- region = 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
- * @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);
- }
- }
-}
-
-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 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 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);
- // TODO implement setRegion
- this.region = 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 a5a7cc0ec5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,555 +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.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
- */
-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 receiver's value changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 6d3fe7684e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,732 +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.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>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, Modify</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @since 3.1
- */
-public class Spinner extends 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 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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];
-}
-
-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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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;
- 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 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 0cbd957e28..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,712 +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.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>
- */
-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 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 receiver's selection changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
- /* Check for versions >= 6.2.1 */
- if (OS.QNX_MAJOR > 6 || (OS.QNX_MAJOR == 6 && (OS.QNX_MINOR > 2 || (OS.QNX_MINOR == 2 && OS.QNX_MICRO >= 1)))) {
- PhRect_t rect = new PhRect_t();
- OS.PtCalcCanvas (handle, rect);
- return new Rectangle (rect.ul_x, rect.ul_y, rect.lr_x - rect.ul_x + 1, rect.lr_y - rect.ul_y + 1);
- }
- int clientHandle = OS.PtWidgetChildBack (handle);
- OS.PtWidgetArea (clientHandle, area);
- 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 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 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 (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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 7806d987bd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,306 +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.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>
- */
-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 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);
- if (index != parent.getSelectionIndex ()) {
- if (newControl != null) 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 no tool tip text should be shown.
- *
- * @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 807be77b5b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,1532 +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.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.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CENTER, LEFT, MULTI, PASSWORD, 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.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
-public class Text extends Scrollable {
- char echoCharacter;
- boolean ignoreChange;
- String hiddenText;
- 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 Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- 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 = "";
- 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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];
-}
-
-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 ();
- start = Math.max (0, start);
- end = Math.min (end, length - 1);
- /*
- * 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 = 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 ff0c2311b3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,485 +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.*;
-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>
- */
-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 9dadf357be..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,954 +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.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>
- */
-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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 disbled 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 no tool tip text should be shown.
- *
- * @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 c08ab27d12..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,1047 +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.*;
-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>
- */
-public class Tracker extends Widget {
- Composite parent;
- boolean tracking, stippled;
- Rectangle [] rectangles, proportions;
- Rectangle bounds;
- int resizeCursor, clientCursor, clientBitmap;
- 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
- */
-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 () {
- 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 () {
- 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 == 0) {
- 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 () {
- 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 ();
- 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();
- 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 moveRectangles (int xChange, int yChange) {
- 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;
-
- 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, oldY;
- int size = PhEvent_t.sizeof + 1024;
- int buffer = OS.malloc (size);
- PhEvent_t phEvent = new PhEvent_t ();
- Event event = new Event ();
- Point cursorPos;
-
- // 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);
- if ((style & SWT.MENU) == 0) {
- oldX = info.pos_x;
- oldY = info.pos_y;
- } else {
- if ((style & SWT.RESIZE) != 0) {
- cursorPos = adjustResizeCursor ();
- } else {
- cursorPos = adjustMoveCursor ();
- }
- 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 ();
- 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 ();
- }
- 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;
- display = null;
- rectangles = 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 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();
- int type = 0;
- int bitmap = 0;
- if (cursor != null) {
- if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- type = cursor.type;
- bitmap = cursor.bitmap;
- }
- clientCursor = type;
- clientBitmap = bitmap;
-}
-
-void setCursor (int cursorHandle) {
- if (cursorHandle == 0) return;
- int type = 0;
- int bitmap = 0;
- if (clientCursor != 0) {
- type = clientCursor;
- bitmap = clientBitmap;
- } 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);
- 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 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 829cd567f7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,1243 +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.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
- */
-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 #removeListener
- * @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 descendents. After this method has
- * been invoked, the receiver and all descendents 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 descendents
- * 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;
-}
-
-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 #removeListener
- */
-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 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 #addListener
- * @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 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 #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 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 #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 93c2ab668e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/WidgetTable.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * 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 446759929a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,336 +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.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
- */
-
-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() {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, red, green, blue);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, rgb.red, rgb.green, rgb.blue);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the color. Applications must dispose of all colors which
- * they allocate.
- */
-public void dispose() {
- if (handle == -1) return;
- if (device.isDisposed()) return;
-
- /*
- * 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 hPal = device.hPalette;
- if (hPal != 0) {
- int index = OS.GetNearestPaletteIndex(hPal, handle);
- int[] colorRefCount = device.colorRefCount;
- if (colorRefCount[index] > 0) {
- colorRefCount[index]--;
- }
- }
- handle = -1;
- if (device.tracking) device.dispose_Object(this);
- device = 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;
- 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(Device device, 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.device = device;
- handle = 0x02000000 | (red & 0xFF) | ((green & 0xFF) << 8) | ((blue & 0xFF) << 16);
-
- /* If this is not a palette-based device, return */
- int 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) {
- if (device == null) device = Device.getDevice();
- Color color = new Color();
- color.handle = handle;
- color.device = device;
- 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 5c8a96acd4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,474 +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.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>
- */
-
-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;
-
- 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() {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- int 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 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);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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 = 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);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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[] result = Image.init(device, null, source, mask);
- int hBitmap = result[0];
- int 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;
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the cursor. Applications must dispose of all cursors which
- * they allocate.
- */
-public void dispose () {
- if (handle == 0) return;
- if (device.isDisposed()) return;
-
- /*
- * 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;
- if (device.tracking) device.dispose_Object(this);
- device = 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;
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- Cursor cursor = new Cursor();
- cursor.handle = handle;
- cursor.device = device;
- 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 4b19d39429..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,819 +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.*;
-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.
- */
-public abstract class Device implements Drawable {
-
- /* Debugging */
- public static boolean DEBUG;
- boolean debug = DEBUG;
- boolean tracking = DEBUG;
- Error [] errors;
- Object [] objects;
-
- /**
- * 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 hPalette = 0;
- int [] colorRefCount;
-
- /* System Font */
- int systemFont;
-
- /* Font Enumeration */
- int nFonts = 256;
- LOGFONT [] logFonts;
- TEXTMETRIC metrics;
- int[] pixels;
-
- /* Scripts */
- int [] scripts;
-
- /* Advanced Graphics */
- int [] gdipToken;
-
- boolean disposed;
-
- final static Object CREATE_LOCK = new Object();
-
- /*
- * 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.
- *
- * This code will be removed in the future.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName ("org.eclipse.swt.widgets.Display"); //$NON-NLS-1$
- } catch (Throwable 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 (CREATE_LOCK) {
- if (data != null) {
- debug = data.debug;
- tracking = data.tracking;
- }
- create (data);
- init ();
- if (tracking) {
- errors = new Error [128];
- objects = new Object [128];
- }
-
- /* Initialize the system font slot */
- systemFont = getSystemFont().handle;
- }
-}
-
-/**
- * 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;
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- int oldErrorMode = OS.SetErrorMode (OS.SEM_FAILCRITICALERRORS);
- try {
- int [] token = new int [1];
- GdiplusStartupInput input = new GdiplusStartupInput ();
- input.GdiplusVersion = 1;
- if (Gdip.GdiplusStartup (token, input, 0) == 0) {
- gdipToken = token;
- }
- } catch (Throwable t) {
- SWT.error (SWT.ERROR_NO_GRAPHICS_LIBRARY, t, " [GDI+ is required]"); //$NON-NLS-1$
- } finally {
- 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(int height) {
- int hDC = internal_new_GC (null);
- int pixels = -Compatibility.round(height * OS.GetDeviceCaps(hDC, OS.LOGPIXELSY), 72);
- internal_dispose_GC (hDC, null);
- return pixels;
-}
-
-int computePoints(LOGFONT logFont, int hFont) {
- int 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 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 Compatibility.round(pixels * 72, 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 () {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- disposed = true;
- if (tracking) {
- objects = null;
- errors = null;
- }
-}
-
-void dispose_Object (Object object) {
- for (int i=0; i<objects.length; i++) {
- if (objects [i] == object) {
- objects [i] = null;
- errors [i] = null;
- return;
- }
- }
-}
-
-int EnumFontFamProc (int lpelfe, int lpntme, int FontType, int lParam) {
- boolean isScalable = (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 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;
- int count = 0, length = 0;
- if (tracking) 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++;
- }
- }
- 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 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 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 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 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 = nFonts - offset;
- FontData [] result = new FontData [count];
- for (int i=0; i<count; i++) {
- int index = i + offset;
- result [i] = FontData.win32_new (logFonts [index], Compatibility.round(pixels [index] * 72, logPixelsY));
- }
-
- /* 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[] buffer = new int[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 = 0x02000000;
- switch (id) {
- case SWT.COLOR_WHITE: pixel = 0x02FFFFFF; break;
- case SWT.COLOR_BLACK: pixel = 0x02000000; break;
- case SWT.COLOR_RED: pixel = 0x020000FF; break;
- case SWT.COLOR_DARK_RED: pixel = 0x02000080; break;
- case SWT.COLOR_GREEN: pixel = 0x0200FF00; break;
- case SWT.COLOR_DARK_GREEN: pixel = 0x02008000; break;
- case SWT.COLOR_YELLOW: pixel = 0x0200FFFF; break;
- case SWT.COLOR_DARK_YELLOW: pixel = 0x02008080; break;
- case SWT.COLOR_BLUE: pixel = 0x02FF0000; break;
- case SWT.COLOR_DARK_BLUE: pixel = 0x02800000; break;
- case SWT.COLOR_MAGENTA: pixel = 0x02FF00FF; break;
- case SWT.COLOR_DARK_MAGENTA: pixel = 0x02800080; break;
- case SWT.COLOR_CYAN: pixel = 0x02FFFF00; break;
- case SWT.COLOR_DARK_CYAN: pixel = 0x02808000; break;
- case SWT.COLOR_GRAY: pixel = 0x02C0C0C0; break;
- case SWT.COLOR_DARK_GRAY: pixel = 0x02808080; 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 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 scripts list */
- if (!OS.IsWinCE) {
- int [] ppSp = new int [1];
- int [] piNumScripts = new int [1];
- OS.ScriptGetProperties (ppSp, piNumScripts);
- scripts = new int [piNumScripts [0]];
- OS.MoveMemory (scripts, ppSp [0], scripts.length * 4);
- }
-
- /*
- * If we're not on a device which supports palettes,
- * don't create one.
- */
- int 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 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 () {
- return disposed;
-}
-
-void new_Object (Object object) {
- 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 (gdipToken != null) {
- Gdip.GdiplusShutdown (gdipToken);
- }
- 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 593b25584d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this 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 609dd8e6f6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,263 +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.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
- */
-
-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;
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Font() {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, fd);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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(device, fds[0]);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new FontData (name, height, style));
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the font. Applications must dispose of all fonts which
- * they allocate.
- */
-public void dispose() {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- OS.DeleteObject(handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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 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 handle;
-}
-
-void init (Device device, FontData fd) {
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- 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 handle) {
- if (device == null) device = Device.getDevice();
- Font font = new Font();
- font.handle = handle;
- font.device = device;
- 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 4a41c9ffb0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,646 +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.*;
-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
- */
-
-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 int height;
-
- /**
- * The locales of the font
- */
- String lang, country, variant;
-
-/**
- * Constructs a new un-initialized 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, int 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);
- 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);
- 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;
-}
-
-/**
- * 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 EnumLocalesProc(int 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
- */
-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() {
- 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 ^ height ^ 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;
-}
-
-/**
- * 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 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();
- 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("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(getName());
- 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, int 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 ebd356fedb..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,182 +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.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
- */
-
-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 cede85e03f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,4437 +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 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>
- * 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
- */
-
-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 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 and background color 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>
- * </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 and background color 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>
- * </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);
- if (device.tracking) device.new_Object(this);
-}
-
-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);
-
- /* Get the HDC for the device */
- Device device = data.device;
- int hDC = device.internal_new_GC(null);
-
- /* Copy the bitmap area */
- Rectangle rect = image.getBounds();
- int memHdc = OS.CreateCompatibleDC(hDC);
- int 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);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
-}
-
-/**
- * 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 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);
- }
- }
- }
- }
- }
-}
-
-int createGdipBrush() {
- int colorRef = OS.GetBkColor (handle);
- int rgb = ((colorRef >> 16) & 0xFF) | (colorRef & 0xFF00) | ((colorRef & 0xFF) << 16);
- int color = Gdip.Color_new(data.alpha << 24 | rgb);
- if (color == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int brush = Gdip.SolidBrush_new(color);
- if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- Gdip.Color_delete(color);
- return brush;
-}
-
-int createGdipFont() {
- return createGdipFont(handle, OS.GetCurrentObject(handle, OS.OBJ_FONT));
-}
-
-static int createGdipFont(int hDC, int hFont) {
- int font = Gdip.Font_new(hDC, hFont);
- if (font == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- 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);
- font = Gdip.Font_new(buffer, size, style, Gdip.UnitPixel, 0);
- }
- if (font == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- return font;
-}
-
-int createGdipPen() {
- int style, colorRef, width, size, hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
- if ((size = OS.GetObject(hPen, 0, (LOGPEN)null)) == LOGPEN.sizeof) {
- LOGPEN logPen = new LOGPEN();
- OS.GetObject(hPen, LOGPEN.sizeof, logPen);
- colorRef = logPen.lopnColor;
- width = logPen.x;
- style = logPen.lopnStyle;
- /*
- * Feature in Windows. The default end caps is PS_ENDCAP_ROUND
- * and the default line join is PS_JOIN_ROUND which are different
- * from other platforms. The fix is to change these values when
- * line width is widened.
- */
- if (width <= 1) {
- style |= OS.PS_ENDCAP_FLAT | OS.PS_JOIN_MITER;
- }
- } else {
- EXTLOGPEN logPen = new EXTLOGPEN();
- if (size <= EXTLOGPEN.sizeof) {
- OS.GetObject(hPen, size, logPen);
- } else {
- int hHeap = OS.GetProcessHeap();
- int ptr = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, size);
- OS.GetObject(hPen, size, ptr);
- OS.MoveMemory(logPen, ptr, EXTLOGPEN.sizeof);
- OS.HeapFree(hHeap, 0, ptr);
- }
- colorRef = logPen.elpColor;
- width = logPen.elpWidth;
- style = logPen.elpPenStyle;
- }
- int rgb = ((colorRef >> 16) & 0xFF) | (colorRef & 0xFF00) | ((colorRef & 0xFF) << 16);
- int color = Gdip.Color_new(data.alpha << 24 | rgb);
- int pen = Gdip.Pen_new(color, Math.max (1, width));
- Gdip.Color_delete(color);
- if (data.foregroundPattern != null) Gdip.Pen_SetBrush(pen, data.foregroundPattern.handle);
- float[] dashes = null;
- int dashStyle = Gdip.DashStyleSolid;
- switch (style & OS.PS_STYLE_MASK) {
- case OS.PS_SOLID: break;
- case OS.PS_DOT: dashStyle = Gdip.DashStyleDot; if (width == 0) dashes = LINE_DOT_ZERO; break;
- case OS.PS_DASH: dashStyle = Gdip.DashStyleDash; if (width == 0) dashes = LINE_DASH_ZERO; break;
- case OS.PS_DASHDOT: dashStyle = Gdip.DashStyleDashDot; if (width == 0) dashes = LINE_DASHDOT_ZERO; break;
- case OS.PS_DASHDOTDOT: dashStyle = Gdip.DashStyleDashDotDot; if (width == 0) dashes = LINE_DASHDOTDOT_ZERO; break;
- case OS.PS_USERSTYLE: {
- if (data.dashes != null) {
- dashes = new float[data.dashes.length * 2];
- for (int i = 0; i < data.dashes.length; i++) {
- float dash = (float)data.dashes[i] / Math.max (1, width);
- dashes[i] = dash;
- dashes[i + data.dashes.length] = dash;
- }
- }
- }
- }
- if (dashes != null) {
- Gdip.Pen_SetDashPattern(pen, dashes, dashes.length);
- Gdip.Pen_SetDashStyle(pen, Gdip.DashStyleCustom);
- } else {
- Gdip.Pen_SetDashStyle(pen, dashStyle);
- }
- int joinStyle = 0;
- switch (style & OS.PS_JOIN_MASK) {
- case OS.PS_JOIN_MITER: joinStyle = Gdip.LineJoinMiter; break;
- case OS.PS_JOIN_BEVEL: joinStyle = Gdip.LineJoinBevel; break;
- case OS.PS_JOIN_ROUND: joinStyle = Gdip.LineJoinRound; break;
- }
- Gdip.Pen_SetLineJoin(pen, joinStyle);
- int dashCap = Gdip.DashCapFlat, capStyle = 0;
- switch (style & OS.PS_ENDCAP_MASK) {
- case OS.PS_ENDCAP_FLAT: capStyle = Gdip.LineCapFlat; break;
- case OS.PS_ENDCAP_ROUND: capStyle = Gdip.LineCapRound; dashCap = Gdip.DashCapRound; break;
- case OS.PS_ENDCAP_SQUARE: capStyle = Gdip.LineCapSquare; break;
- }
- Gdip.Pen_SetLineCap(pen, capStyle, capStyle, dashCap);
- return pen;
-}
-
-void destroyGdipBrush(int 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.
- */
-public void dispose() {
- if (handle == 0) return;
- if (data.device.isDisposed()) return;
-
- if (data.gdipGraphics != 0) Gdip.Graphics_delete(data.gdipGraphics);
- if (data.gdipPen != 0) Gdip.Pen_delete(data.gdipPen);
- if (data.gdipBrush != 0) destroyGdipBrush(data.gdipBrush);
- data.gdipBrush = data.gdipPen = data.gdipGraphics = 0;
-
- /* Select stock pen and brush objects and free resources */
- if (data.hPen != 0) {
- int nullPen = OS.GetStockObject(OS.NULL_PEN);
- OS.SelectObject(handle, nullPen);
- OS.DeleteObject(data.hPen);
- data.hPen = 0;
- }
- if (data.hBrush != 0) {
- int nullBrush = OS.GetStockObject(OS.NULL_BRUSH);
- OS.SelectObject(handle, nullBrush);
- 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 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.
- */
- Device device = data.device;
- if (drawable != null) drawable.internal_dispose_GC(handle, data);
- drawable = null;
- handle = 0;
- data.image = null;
- data.ps = null;
- if (device.tracking) device.dispose_Object(this);
- data.device = 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);
- 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 gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- initGdip(true, false);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- if (width == height) {
- Gdip.Graphics_DrawArc(gdipGraphics, data.gdipPen, x, y, width, height, -startAngle, -arcAngle);
- } else {
- int path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate);
- if (path == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int 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);
- }
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- return;
- }
- /*
- * 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;
- }
- int nullBrush = OS.GetStockObject(OS.NULL_BRUSH);
- int oldBrush = OS.SelectObject(handle, nullBrush);
- OS.Arc(handle, x, y, x + width + 1, y + height + 1, x1, y1, x2, y2);
- OS.SelectObject(handle, oldBrush);
- }
-}
-
-/**
- * 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);
- RECT rect = new RECT();
- OS.SetRect(rect, x, y, x + width, y + height);
- OS.DrawFocusRect(handle, rect);
-}
-
-/**
- * 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[] gdipImage = srcImage.createGdipImage();
- int 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 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);
- }
- Gdip.Graphics_DrawImage(data.gdipGraphics, img, rect, srcX, srcY, srcWidth, srcHeight, Gdip.UnitPixel, attrib, 0, 0);
- Gdip.ImageAttributes_delete(attrib);
- Gdip.Bitmap_delete(img);
- if (gdipImage[1] != 0) {
- int 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;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(5, 1)) {
- flags |= OS.DI_NOMIRROR;
- } 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) {
- OS.DrawIconEx(handle, destX, destY, srcImage.handle, 0, 0, 0, 0, flags);
- 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 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 */
- OS.DrawIconEx(handle, destX, destY, srcImage.handle, 0, 0, 0, 0, flags);
- } else {
- /* Create the icon info and HDC's */
- ICONINFO newIconInfo = new ICONINFO();
- newIconInfo.fIcon = true;
- int srcHdc = OS.CreateCompatibleDC(handle);
- int dstHdc = OS.CreateCompatibleDC(handle);
-
- /* Blt the color bitmap */
- int srcColorY = srcY;
- int srcColor = srcIconInfo.hbmColor;
- if (srcColor == 0) {
- srcColor = srcIconInfo.hbmMask;
- srcColorY += iconHeight;
- }
- int oldSrcBitmap = OS.SelectObject(srcHdc, srcColor);
- newIconInfo.hbmColor = OS.CreateCompatibleBitmap(srcHdc, destWidth, destHeight);
- if (newIconInfo.hbmColor == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int 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 hIcon = OS.CreateIconIndirect(newIconInfo);
- if (hIcon == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.DrawIconEx(handle, destX, destY, hIcon, destWidth, destHeight, 0, 0, flags);
- 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 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 srcHdc = OS.CreateCompatibleDC(handle);
- int 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 memDib = Image.createDIB(srcWidth, srcHeight, 32);
- if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int memHdc = OS.CreateCompatibleDC(handle);
- int 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 srcHdc = OS.CreateCompatibleDC(handle);
- int oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle);
- int memHdc = OS.CreateCompatibleDC(handle);
- int memDib = Image.createDIB(Math.max(srcWidth, destWidth), Math.max(srcHeight, destHeight), 32);
- if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int 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 tempHdc = OS.CreateCompatibleDC(handle);
- int tempDib = Image.createDIB(destWidth, destHeight, 32);
- if (tempDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int 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 srcHdc, int 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 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 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 tmpRgn = OS.ExtCreateRegion(lpXform, nBytes, lpRgnData);
- OS.DeleteObject(rgn);
- rgn = tmpRgn;
- }
- OS.OffsetRgn(rgn, destX, destY);
- int 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 srcColor, int 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 srcHdc = OS.CreateCompatibleDC(handle);
- int oldSrcBitmap = OS.SelectObject(srcHdc, srcColor);
- int destHdc = handle, x = destX, y = destY;
- int 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. */
- int transBlue = 0, transGreen = 0, transRed = 0;
- boolean isDib = bm.bmBits != 0;
- int hBitmap = srcImage.handle;
- int srcHdc = OS.CreateCompatibleDC(handle);
- int oldSrcBitmap = OS.SelectObject(srcHdc, hBitmap);
- byte[] originalColors = null;
- 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;
- boolean fixPalette = false;
- 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;
- }
- }
-
- int transparentColor = transBlue << 16 | transGreen << 8 | transRed;
- 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 maskHdc = OS.CreateCompatibleDC(handle);
- int maskBitmap = OS.CreateBitmap(imgWidth, imgHeight, 1, 1, null);
- int 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 tempHdc = OS.CreateCompatibleDC(handle);
- int tempBitmap = OS.CreateCompatibleBitmap(handle, destWidth, destHeight);
- int 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 srcHdc = OS.CreateCompatibleDC(handle);
- int 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);
- int gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- initGdip(true, false);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- Gdip.Graphics_DrawLine(gdipGraphics, data.gdipPen, x1, y1, x2, y2);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- return;
- }
- 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, OS.GetTextColor (handle));
- }
-}
-
-/**
- * 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);
- int gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- initGdip(true, false);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- Gdip.Graphics_DrawEllipse(gdipGraphics, data.gdipPen, x, y, width, height);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- return;
- }
- // Check performance impact of always setting null brush. If the user has not
- // set the background color, we may not have to do this work?
- int nullBrush = OS.GetStockObject(OS.NULL_BRUSH);
- int oldBrush = OS.SelectObject(handle, nullBrush);
- OS.Ellipse(handle, x, y, x + width + 1, y + height + 1);
- OS.SelectObject(handle,oldBrush);
-}
-
-/**
- * Draws the path described by the parameter.
- *
- * @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>
- * </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(true, false);
- int gdipGraphics = data.gdipGraphics;
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- Gdip.Graphics_DrawPath(gdipGraphics, data.gdipPen, path.handle);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
-}
-
-/**
- * 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) {
- initGdip(true, false);
- int brush = Gdip.Pen_GetBrush(data.gdipPen);
- Gdip.Graphics_FillRectangle(data.gdipGraphics, brush, x, y, 1, 1);
- destroyGdipBrush(brush);
- return;
- }
- OS.SetPixel (handle, x, y, OS.GetTextColor (handle));
-}
-
-/**
- * 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);
- int gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- initGdip(true, false);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- Gdip.Graphics_DrawPolygon(gdipGraphics, data.gdipPen, pointArray, pointArray.length / 2);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- return;
- }
- int nullBrush = OS.GetStockObject(OS.NULL_BRUSH);
- int oldBrush = OS.SelectObject(handle, nullBrush);
- OS.Polygon(handle, pointArray, pointArray.length / 2);
- OS.SelectObject(handle, oldBrush);
-}
-
-/**
- * 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);
- int gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- initGdip(true, false);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, pointArray, pointArray.length / 2);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- return;
- }
- 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], OS.GetTextColor (handle));
- }
- }
-}
-
-/**
- * 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 gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- initGdip(true, false);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height);
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- return;
- }
- int hOld = OS.SelectObject (handle, OS.GetStockObject (OS.NULL_BRUSH));
- OS.Rectangle (handle, x, y, x + width + 1, y + height + 1);
- OS.SelectObject (handle, hOld);
-}
-
-/**
- * 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 (data.gdipGraphics != 0) {
- initGdip(true, false);
- drawRoundRectangleGdip(data.gdipGraphics, data.gdipPen, x, y, width, height, arcWidth, arcHeight);
- return;
- }
- 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 {
- int nullBrush = OS.GetStockObject(OS.NULL_BRUSH);
- int oldBrush = OS.SelectObject(handle, nullBrush);
- OS.RoundRect(handle, x,y,x+width+1,y+height+1, arcWidth, arcHeight);
- OS.SelectObject(handle,oldBrush);
- }
-}
-
-void drawRoundRectangleGdip (int gdipGraphics, int 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;
-
- int naw2 = naw / 2;
- int nah2 = nah / 2;
-
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- if (nw > naw) {
- if (nh > nah) {
- Gdip.Graphics_DrawArc(gdipGraphics, brush, nx, ny, naw, nah, -90, -90);
- Gdip.Graphics_DrawLine(gdipGraphics, brush, nx + naw2, ny, nx + nw - naw2, ny);
- Gdip.Graphics_DrawArc(gdipGraphics, brush, nx + nw - naw, ny, naw, nah, 0, -90);
- Gdip.Graphics_DrawLine(gdipGraphics, brush, nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
- Gdip.Graphics_DrawArc(gdipGraphics, brush, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90);
- Gdip.Graphics_DrawLine(gdipGraphics, brush, nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
- Gdip.Graphics_DrawArc(gdipGraphics, brush, nx, ny + nh - nah, naw, nah, -180, -90);
- Gdip.Graphics_DrawLine(gdipGraphics, brush, nx, ny + nah2, nx, ny + nh - nah2);
- } else {
- Gdip.Graphics_DrawArc(gdipGraphics, brush, nx, ny, naw, nh, -90, -180);
- Gdip.Graphics_DrawLine(gdipGraphics, brush, nx + naw2, ny, nx + nw - naw2, ny);
- Gdip.Graphics_DrawArc(gdipGraphics, brush, nx + nw - naw, ny, naw, nh, -270, -180);
- Gdip.Graphics_DrawLine(gdipGraphics, brush, nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
- }
- } else {
- if (nh > nah) {
- Gdip.Graphics_DrawArc(gdipGraphics, brush, nx, ny, nw, nah, 0, -180);
- Gdip.Graphics_DrawLine(gdipGraphics, brush, nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
- Gdip.Graphics_DrawArc(gdipGraphics, brush, nx, ny + nh - nah, nw, nah, -180, -180);
- Gdip.Graphics_DrawLine(gdipGraphics, brush, nx, ny + nah2, nx, ny + nh - nah2);
- } else {
- Gdip.Graphics_DrawArc(gdipGraphics, brush, nx, ny, nw, nh, 0, 360);
- }
- }
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
-}
-
-/**
- * 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);
- if (data.gdipGraphics != 0) {
- initGdip(true, !isTransparent);
- int font = createGdipFont();
- PointF pt = new PointF();
- pt.X = x;
- pt.Y = y;
- int brush = Gdip.Pen_GetBrush(data.gdipPen);
- int format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic());
- Gdip.StringFormat_SetFormatFlags(format, Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces);
- if (!isTransparent) {
- RectF bounds = new RectF();
- Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, length, font, pt, format, bounds);
- Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, (int)bounds.X, (int)bounds.Y, Math.round(bounds.Width), Math.round(bounds.Height));
- }
- Gdip.Graphics_DrawString(data.gdipGraphics, buffer, length, font, pt, format, brush);
- Gdip.StringFormat_delete(format);
- destroyGdipBrush(brush);
- Gdip.Font_delete(font);
- return;
- }
- int rop2 = 0;
- if (OS.IsWinCE) {
- rop2 = OS.SetROP2(handle, OS.R2_COPYPEN);
- OS.SetROP2(handle, rop2);
- } else {
- rop2 = OS.GetROP2(handle);
- }
- int oldBkMode = OS.SetBkMode(handle, isTransparent ? OS.TRANSPARENT : OS.OPAQUE);
- if (rop2 != OS.R2_XORPEN) {
- OS.ExtTextOutW(handle, x, y, 0, null, buffer, length, null);
- } else {
- int foreground = OS.GetTextColor(handle);
- if (isTransparent) {
- SIZE size = new SIZE();
- OS.GetTextExtentPoint32W(handle, buffer, length, size);
- int width = size.cx, height = size.cy;
- int hBitmap = OS.CreateCompatibleBitmap(handle, width, height);
- if (hBitmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int memDC = OS.CreateCompatibleDC(handle);
- int 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, 0, null, 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 specifing 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;
- if (data.gdipGraphics != 0) {
- initGdip(true, (flags & SWT.DRAW_TRANSPARENT) == 0);
- int length = string.length();
- char[] buffer = new char [length];
- string.getChars(0, length, buffer, 0);
- int font = createGdipFont();
- PointF pt = new PointF();
- pt.X = x;
- pt.Y = y;
- int brush = Gdip.Pen_GetBrush(data.gdipPen);
- int format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic());
- Gdip.StringFormat_SetFormatFlags(format, Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces);
- float[] tabs = (flags & SWT.DRAW_TAB) != 0 ? new float[]{measureSpace(font, 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);
- if ((flags & SWT.DRAW_TRANSPARENT) == 0) {
- RectF bounds = new RectF();
- Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, length, font, pt, format, bounds);
- Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, (int)bounds.X, (int)bounds.Y, Math.round(bounds.Width), Math.round(bounds.Height));
- }
- Gdip.Graphics_DrawString(data.gdipGraphics, buffer, length, font, pt, format, brush);
- Gdip.StringFormat_delete(format);
- destroyGdipBrush(brush);
- Gdip.Font_delete(font);
- 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;
- int rop2 = 0;
- if (OS.IsWinCE) {
- rop2 = OS.SetROP2(handle, OS.R2_COPYPEN);
- OS.SetROP2(handle, rop2);
- } else {
- rop2 = OS.GetROP2(handle);
- }
- 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 hBitmap = OS.CreateCompatibleBitmap(handle, width, height);
- if (hBitmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int memDC = OS.CreateCompatibleDC(handle);
- int 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);
- 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 gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- initGdip(false, true);
- 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;
- }
-
- /*
- * 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;
- }
- int nullPen = OS.GetStockObject(OS.NULL_PEN);
- int oldPen = OS.SelectObject(handle, nullPen);
- OS.Polygon(handle, points, points.length / 2);
- OS.SelectObject(handle, oldPen);
- } 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;
- }
-
- int nullPen = OS.GetStockObject(OS.NULL_PEN);
- int oldPen = OS.SelectObject(handle, nullPen);
- OS.Pie(handle, x, y, x + width + 1, y + height + 1, x1, y1, x2, y2);
- OS.SelectObject(handle, oldPen);
- }
-}
-
-/**
- * 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 = OS.GetTextColor(handle);
- if (fromColor == OS.CLR_INVALID) {
- fromColor = OS.GetSysColor(OS.COLOR_WINDOWTEXT);
- }
- int toColor = OS.GetBkColor(handle);
- if (toColor == OS.CLR_INVALID) {
- toColor = OS.GetSysColor(OS.COLOR_WINDOW);
- }
- 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 = fromColor;
- fromColor = toColor;
- toColor = t;
- }
- int rop2 = 0;
- if (OS.IsWinCE) {
- rop2 = OS.SetROP2(handle, OS.R2_COPYPEN);
- OS.SetROP2(handle, rop2);
- } else {
- rop2 = OS.GetROP2(handle);
- }
- final RGB fromRGB = new RGB(fromColor & 0xff, (fromColor >>> 8) & 0xff, (fromColor >>> 16) & 0xff);
- final RGB toRGB = new RGB(toColor & 0xff, (toColor >>> 8) & 0xff, (toColor >>> 16) & 0xff);
- if (fromRGB.red == toRGB.red && fromRGB.green == toRGB.green && fromRGB.blue == toRGB.blue) {
- if (data.gdipGraphics != 0) {
- initGdip(false, true);
- Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height);
- } else {
- int dwRop = rop2 == OS.R2_XORPEN ? OS.PATINVERT : OS.PATCOPY;
- OS.PatBlt(handle, x, y, width, height, dwRop);
- }
- return;
- }
- if (data.gdipGraphics != 0) {
- initGdip(false, true);
- 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 = ((fromColor >> 16) & 0xFF) | (fromColor & 0xFF00) | ((fromColor & 0xFF) << 16);
- int fromGpColor = Gdip.Color_new(data.alpha << 24 | rgb);
- if (fromGpColor == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- rgb = ((toColor >> 16) & 0xFF) | (toColor & 0xFF00) | ((toColor & 0xFF) << 16);
- int toGpColor = Gdip.Color_new(data.alpha << 24 | rgb);
- if (toGpColor == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int 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.
- */
- if (OS.IsWinNT && rop2 != OS.R2_XORPEN && OS.GetDeviceCaps(handle, OS.TECHNOLOGY) != OS.DT_RASPRINTER) {
- final int hHeap = OS.GetProcessHeap();
- final int pMesh = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, GRADIENT_RECT.sizeof + TRIVERTEX.sizeof * 2);
- final int 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);
- if (data.gdipGraphics != 0) {
- initGdip(false, true);
- Gdip.Graphics_FillEllipse(data.gdipGraphics, data.gdipBrush, x, y, width, height);
- return;
- }
- /* Assumes that user sets the background color. */
- int nullPen = OS.GetStockObject(OS.NULL_PEN);
- int oldPen = OS.SelectObject(handle, nullPen);
- OS.Ellipse(handle, x, y, x + width + 1, y + height + 1);
- OS.SelectObject(handle,oldPen);
-}
-
-/**
- * Fills the path described by the parameter.
- *
- * @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>
- * </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(false, true);
- 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);
- if (data.gdipGraphics != 0) {
- initGdip(false, true);
- int mode = OS.GetPolyFillMode(handle) == OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate;
- Gdip.Graphics_FillPolygon(data.gdipGraphics, data.gdipBrush, pointArray, pointArray.length / 2, mode);
- return;
- }
- int nullPen = OS.GetStockObject(OS.NULL_PEN);
- int oldPen = OS.SelectObject(handle, nullPen);
- OS.Polygon(handle, pointArray, pointArray.length / 2);
- OS.SelectObject(handle,oldPen);
-}
-
-/**
- * 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 (data.gdipGraphics != 0) {
- initGdip(false, true);
- 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);
- if (data.gdipGraphics != 0) {
- initGdip(false, true);
- fillRoundRectangleGdip(data.gdipGraphics, data.gdipBrush, x, y, width, height, arcWidth, arcHeight);
- return;
- }
- int nullPen = OS.GetStockObject(OS.NULL_PEN);
- int oldPen = OS.SelectObject(handle, nullPen);
- OS.RoundRect(handle, x,y,x+width+1,y+height+1,arcWidth, arcHeight);
- OS.SelectObject(handle,oldPen);
-}
-
-void fillRoundRectangleGdip (int gdipGraphics, int 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;
-
- int naw2 = naw / 2;
- int nah2 = nah / 2;
-
- if (nw > naw) {
- if (nh > nah) {
- Gdip.Graphics_FillPie(gdipGraphics, brush, nx, ny, naw, nah, -90, -90);
- Gdip.Graphics_FillRectangle(gdipGraphics, brush, nx + naw2, ny, nw - naw2 * 2, nah2);
- Gdip.Graphics_FillPie(gdipGraphics, brush, nx + nw - naw, ny, naw, nah, 0, -90);
- Gdip.Graphics_FillRectangle(gdipGraphics, brush, nx, ny + nah2, nw, nh - nah2 * 2);
- Gdip.Graphics_FillPie(gdipGraphics, brush, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90);
- Gdip.Graphics_FillRectangle(gdipGraphics, brush, nx + naw2, ny + nh - nah2, nw - naw2 * 2, nah2);
- Gdip.Graphics_FillPie(gdipGraphics, brush, nx, ny + nh - nah, naw, nah, -180, -90);
- } else {
- Gdip.Graphics_FillPie(gdipGraphics, brush, nx, ny, naw, nh, -90, -180);
- Gdip.Graphics_FillRectangle(gdipGraphics, brush, nx + naw2, ny, nw - naw2 * 2, nh);
- Gdip.Graphics_FillPie(gdipGraphics, brush, nx + nw - naw, ny, naw, nh, -270, -180);
- }
- } else {
- if (nh > nah) {
- Gdip.Graphics_FillPie(gdipGraphics, brush, nx, ny, nw, nah, 0, -180);
- Gdip.Graphics_FillRectangle(gdipGraphics, brush, nx, ny + nah2, nw, nh - nah2 * 2);
- Gdip.Graphics_FillPie(gdipGraphics, brush, nx, ny + nh - nah, nw, nah, -180, -180);
- } else {
- Gdip.Graphics_FillPie(gdipGraphics, brush, nx, ny, nw, nh, 0, 360);
- }
- }
-}
-
-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 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);
- 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.
- *
- * @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);
- int color = OS.GetBkColor(handle);
- if (color == OS.CLR_INVALID) {
- color = OS.GetSysColor(OS.COLOR_WINDOW);
- }
- return Color.win32_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);
-
- /* 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 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 gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone);
- int rgn = Gdip.Region_new();
- Gdip.Graphics_GetClip(data.gdipGraphics, rgn);
- if (Gdip.Region_IsInfinite(rgn, gdipGraphics)) {
- Rect rect = new Rect();
- Gdip.Graphics_GetVisibleClipBounds(gdipGraphics, rect);
- OS.SetRectRgn(region.handle, rect.X, rect.Y, rect.Width, rect.Height);
- } else {
- int matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
- int identity = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
- Gdip.Graphics_GetTransform(gdipGraphics, matrix);
- Gdip.Graphics_SetTransform(gdipGraphics, identity);
- int hRgn = Gdip.Region_GetHRGN(rgn, data.gdipGraphics);
- Gdip.Graphics_SetTransform(gdipGraphics, matrix);
- Gdip.Matrix_delete(identity);
- Gdip.Matrix_delete(matrix);
- OS.CombineRgn(region.handle, hRgn, 0, OS.RGN_COPY);
- OS.DeleteObject(hRgn);
- }
- Gdip.Region_delete(rgn);
- Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf);
- 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 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 hwnd = data.hwnd;
- if (hwnd != 0 && data.ps != null) {
- int 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 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];
-}
-
-/**
- * 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);
- int hFont = OS.GetCurrentObject(handle, OS.OBJ_FONT);
- return Font.win32_new(data.device, hFont);
-}
-
-/**
- * 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);
- 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);
- int color = OS.GetTextColor(handle);
- if (color == OS.CLR_INVALID) {
- color = OS.GetSysColor(OS.COLOR_WINDOWTEXT);
- }
- return Color.win32_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
- */
-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 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);
- int style, size;
- int hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
- if ((size = OS.GetObject(hPen, 0, (LOGPEN)null)) == LOGPEN.sizeof) {
- LOGPEN logPen = new LOGPEN();
- OS.GetObject(hPen, LOGPEN.sizeof, logPen);
- style = logPen.lopnStyle | OS.PS_ENDCAP_FLAT;
- } else {
- EXTLOGPEN logPen = new EXTLOGPEN();
- if (size <= EXTLOGPEN.sizeof) {
- OS.GetObject(hPen, size, logPen);
- } else {
- int hHeap = OS.GetProcessHeap();
- int ptr = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, size);
- OS.GetObject(hPen, size, ptr);
- OS.MoveMemory(logPen, ptr, EXTLOGPEN.sizeof);
- OS.HeapFree(hHeap, 0, ptr);
- }
- style = logPen.elpPenStyle & OS.PS_ENDCAP_MASK;
- }
- int cap = SWT.CAP_ROUND;
- switch (style) {
- case OS.PS_ENDCAP_ROUND: cap = SWT.CAP_ROUND; break;
- case OS.PS_ENDCAP_FLAT: cap = SWT.CAP_FLAT; break;
- case OS.PS_ENDCAP_SQUARE: cap = SWT.CAP_SQUARE; break;
- }
- return cap;
-}
-
-/**
- * Returns the receiver's line dash style. The default value is
- * <code>null</code>.
- *
- * @return the lin 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.dashes == null) return null;
- int[] dashes = new int[data.dashes.length];
- System.arraycopy(data.dashes, 0, dashes, 0, dashes.length);
- 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);
- int style, size;
- int hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
- if ((size = OS.GetObject(hPen, 0, (LOGPEN)null)) == LOGPEN.sizeof) {
- LOGPEN logPen = new LOGPEN();
- OS.GetObject(hPen, LOGPEN.sizeof, logPen);
- style = logPen.lopnStyle | OS.PS_JOIN_MITER;
- } else {
- EXTLOGPEN logPen = new EXTLOGPEN();
- if (size <= EXTLOGPEN.sizeof) {
- OS.GetObject(hPen, size, logPen);
- } else {
- int hHeap = OS.GetProcessHeap();
- int ptr = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, size);
- OS.GetObject(hPen, size, ptr);
- OS.MoveMemory(logPen, ptr, EXTLOGPEN.sizeof);
- OS.HeapFree(hHeap, 0, ptr);
- }
- style = logPen.elpPenStyle & OS.PS_JOIN_MASK;
- }
- int join = SWT.JOIN_ROUND;
- switch (style) {
- case OS.PS_JOIN_MITER: join = SWT.JOIN_MITER; break;
- case OS.PS_JOIN_ROUND: join = SWT.JOIN_ROUND; break;
- case OS.PS_JOIN_BEVEL: join = SWT.JOIN_BEVEL; break;
- }
- return join;
-}
-
-/**
- * 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);
- int style, size;
- int hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
- if ((size = OS.GetObject(hPen, 0, (LOGPEN)null)) == LOGPEN.sizeof) {
- LOGPEN logPen = new LOGPEN();
- OS.GetObject(hPen, LOGPEN.sizeof, logPen);
- style = logPen.lopnStyle;
- } else {
- EXTLOGPEN logPen = new EXTLOGPEN();
- if (size <= EXTLOGPEN.sizeof) {
- OS.GetObject(hPen, size, logPen);
- } else {
- int hHeap = OS.GetProcessHeap();
- int ptr = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, size);
- OS.GetObject(hPen, size, ptr);
- OS.MoveMemory(logPen, ptr, EXTLOGPEN.sizeof);
- OS.HeapFree(hHeap, 0, ptr);
- }
- style = logPen.elpPenStyle & OS.PS_STYLE_MASK;
- }
- switch (style) {
- case OS.PS_SOLID: return SWT.LINE_SOLID;
- case OS.PS_DASH: return SWT.LINE_DASH;
- case OS.PS_DOT: return SWT.LINE_DOT;
- case OS.PS_DASHDOT: return SWT.LINE_DASHDOT;
- case OS.PS_DASHDOTDOT: return SWT.LINE_DASHDOTDOT;
- case OS.PS_USERSTYLE: return SWT.LINE_CUSTOM;
- default: return SWT.LINE_SOLID;
- }
-}
-
-/**
- * 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);
- int size;
- int hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
- if ((size = OS.GetObject(hPen, 0, (LOGPEN)null)) == LOGPEN.sizeof) {
- LOGPEN logPen = new LOGPEN();
- OS.GetObject(hPen, LOGPEN.sizeof, logPen);
- return logPen.x;
- } else {
- EXTLOGPEN logPen = new EXTLOGPEN();
- if (size <= EXTLOGPEN.sizeof) {
- OS.GetObject(hPen, size, logPen);
- } else {
- int hHeap = OS.GetProcessHeap();
- int ptr = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, size);
- OS.GetObject(hPen, size, ptr);
- OS.MoveMemory(logPen, ptr, EXTLOGPEN.sizeof);
- OS.HeapFree(hHeap, 0, ptr);
- }
- return logPen.elpWidth;
- }
-}
-
-/**
- * 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 gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- Gdip.Graphics_GetTransform(gdipGraphics, 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);
- 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(boolean draw, boolean fill) {
- data.device.checkGDIP();
- int gdipGraphics = data.gdipGraphics;
- if (gdipGraphics == 0) {
- /*
- * 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 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);
- 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 (result == 1) setClipping(hRgn);
- OS.DeleteObject(hRgn);
- }
- if (draw && data.gdipPen == 0) data.gdipPen = createGdipPen();
- if (fill && data.gdipBrush == 0) data.gdipBrush = createGdipBrush();
-}
-
-void init(Drawable drawable, GCData data, int hDC) {
- int foreground = data.foreground;
- if (foreground != -1 && OS.GetTextColor(hDC) != foreground) {
- OS.SetTextColor(hDC, foreground);
- int newPen = OS.CreatePen(OS.PS_SOLID, 0, foreground);
- OS.SelectObject(hDC, newPen);
- if (data.hPen != 0) OS.DeleteObject(data.hPen);
- data.hPen = newPen;
- }
- int background = data.background;
- if (background != -1 && OS.GetBkColor(hDC) != background) {
- OS.SetBkColor(hDC, background);
- int newBrush = OS.CreateSolidBrush(background);
- OS.SelectObject(hDC, newBrush);
- if (data.hBrush != 0) OS.DeleteObject (data.hBrush);
- data.hBrush = newBrush;
- }
- int hFont = data.hFont;
- if (hFont != 0) OS.SelectObject (hDC, hFont);
- int 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 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 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 font, int 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 #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(false, false);
- } catch (SWTException e) {}
- } else {
- int foreground = OS.GetTextColor(handle);
- int background = OS.GetBkColor(handle);
- if (data.gdipGraphics != 0) Gdip.Graphics_delete(data.gdipGraphics);
- if (data.gdipPen != 0) Gdip.Pen_delete(data.gdipPen);
- if (data.gdipBrush != 0) destroyGdipBrush(data.gdipBrush);
- data.gdipGraphics = data.gdipBrush = data.gdipPen = 0;
- data.alpha = 0xFF;
- data.backgroundPattern = data.foregroundPattern = null;
- setClipping(0);
- OS.SetTextColor(handle, foreground);
- OS.SetBkColor(handle, background);
- if (data.hPen != 0) OS.SelectObject(handle, data.hPen);
- if (data.hBrush != 0) OS.SelectObject(handle, data.hBrush);
- }
-}
-
-/**
- * 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.
- *
- * @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>
- * </ul>
- *
- * @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(false, false);
- Gdip.Graphics_SetSmoothingMode(data.gdipGraphics, mode);
-}
-
-/**
- * Sets the receiver's alpha value.
- *
- * @param alpha the alpha value
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @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(false, false);
- data.alpha = alpha & 0xFF;
- if (data.gdipPen != 0) {
- Gdip.Pen_delete(data.gdipPen);
- data.gdipPen = 0;
- }
- if (data.gdipBrush != 0) {
- destroyGdipBrush(data.gdipBrush);
- data.gdipBrush = 0;
- }
-}
-
-/**
- * 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) {
- if (data.gdipBrush != 0) {
- destroyGdipBrush(data.gdipBrush);
- data.gdipBrush = 0;
- }
- data.backgroundPattern = null;
- }
- if (OS.GetBkColor(handle) == color.handle) return;
- data.background = color.handle;
- OS.SetBkColor (handle, color.handle);
- int newBrush = OS.CreateSolidBrush (color.handle);
- OS.SelectObject (handle, newBrush);
- if (data.hBrush != 0) OS.DeleteObject (data.hBrush);
- data.hBrush = newBrush;
- if (data.gdipBrush != 0) {
- destroyGdipBrush(data.gdipBrush);
- data.gdipBrush = 0;
- }
-}
-
-/**
- * Sets the background pattern. The default value is <code>null</code>.
- *
- * @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>
- * </ul>
- *
- * @see Pattern
- *
- * @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(false, false);
- if (data.gdipBrush != 0) destroyGdipBrush(data.gdipBrush);
- if (pattern != null) {
- data.gdipBrush = Gdip.Brush_Clone(pattern.handle);
- } else {
- data.gdipBrush = 0;
- }
- data.backgroundPattern = pattern;
-}
-
-void setClipping(int clipRgn) {
- int hRgn = clipRgn;
- int gdipGraphics = data.gdipGraphics;
- if (gdipGraphics != 0) {
- if (hRgn != 0) {
- int 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 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.
- *
- * @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>
- * </ul>
- *
- * @see Path
- *
- * @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(false, false);
- int mode = OS.GetPolyFillMode(handle) == OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate;
- Gdip.GraphicsPath_SetFillMode(path.handle, mode);
- Gdip.Graphics_SetClip(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) {
- OS.SelectObject(handle, data.device.systemFont);
- } else {
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.SelectObject(handle, font.handle);
- }
-}
-
-/**
- * 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) {
- if (data.gdipPen != 0) {
- Gdip.Pen_delete(data.gdipPen);
- data.gdipPen = 0;
- }
- data.foregroundPattern = null;
- }
- if (OS.GetTextColor(handle) == color.handle) return;
- data.foreground = color.handle;
- OS.SetTextColor(handle, color.handle);
- setPen(color.handle, -1, -1, -1, -1, data.dashes);
-}
-
-/**
- * Sets the foreground pattern. The default value is <code>null</code>.
- *
- * @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>
- * </ul>
- *
- * @see Pattern
- *
- * @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(false, false);
- if (pattern != null) {
- if (data.gdipPen != 0) Gdip.Pen_SetBrush(data.gdipPen, pattern.handle);
- } else {
- if (data.gdipPen != 0) {
- Gdip.Pen_delete(data.gdipPen);
- data.gdipPen = 0;
- }
- }
- data.foregroundPattern = pattern;
-}
-
-/**
- * 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>.
- *
- * @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>
- * </ul>
- *
- * @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(false, false);
- Gdip.Graphics_SetInterpolationMode(data.gdipGraphics, mode);
-}
-
-/**
- * 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);
- int capStyle = 0;
- switch (cap) {
- 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;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- setPen(-1, -1, -1, capStyle, -1, data.dashes);
-}
-
-/**
- * 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) {
- data.dashes = new int[dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- int dash = dashes[i];
- if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.dashes[i] = dash;
- }
- } else {
- data.dashes = null;
- }
- setPen(-1, -1, data.dashes == null ? OS.PS_SOLID : OS.PS_USERSTYLE, -1, -1, data.dashes);
-}
-
-/**
- * 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);
- int joinStyle = 0;
- switch (join) {
- 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;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- setPen(-1, -1, -1, -1, joinStyle, data.dashes);
-}
-
-/**
- * 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);
- int style = -1;
- switch (lineStyle) {
- case SWT.LINE_SOLID: style = OS.PS_SOLID; break;
- case SWT.LINE_DASH: style = OS.PS_DASH; break;
- case SWT.LINE_DOT: style = OS.PS_DOT; break;
- case SWT.LINE_DASHDOT: style = OS.PS_DASHDOT; break;
- case SWT.LINE_DASHDOTDOT: style = OS.PS_DASHDOTDOT; break;
- case SWT.LINE_CUSTOM: style = data.dashes == null ? OS.PS_SOLID : OS.PS_USERSTYLE; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- OS.SetBkMode (handle, style == OS.PS_SOLID ? OS.OPAQUE : OS.TRANSPARENT);
- setPen(-1, -1, style, -1, -1, data.dashes);
-}
-
-/**
- * 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);
- setPen(-1, lineWidth, -1, -1, -1, data.dashes);
-}
-
-void setPen(int newColor, int newWidth, int lineStyle, int capStyle, int joinStyle, int[] dashes) {
- boolean extPen = false, changed = false;
- int style, color, width, size, hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
- if ((size = OS.GetObject(hPen, 0, (LOGPEN)null)) == LOGPEN.sizeof) {
- LOGPEN logPen = new LOGPEN();
- OS.GetObject(hPen, LOGPEN.sizeof, logPen);
- color = logPen.lopnColor;
- width = logPen.x;
- style = logPen.lopnStyle;
- /*
- * Feature in Windows. The default end caps is PS_ENDCAP_ROUND
- * and the default line join is PS_JOIN_ROUND which are different
- * from other platforms. The fix is to change these values when
- * line width is widened.
- */
- if (width < 1 && (newWidth >= 1 || lineStyle == OS.PS_USERSTYLE)) {
- if (capStyle == -1) capStyle = OS.PS_ENDCAP_FLAT;
- if (joinStyle == -1) joinStyle = OS.PS_JOIN_MITER;
- }
- } else {
- EXTLOGPEN logPen = new EXTLOGPEN();
- if (size <= EXTLOGPEN.sizeof) {
- OS.GetObject(hPen, size, logPen);
- } else {
- int hHeap = OS.GetProcessHeap();
- int ptr = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, size);
- OS.GetObject(hPen, size, ptr);
- OS.MoveMemory(logPen, ptr, EXTLOGPEN.sizeof);
- OS.HeapFree(hHeap, 0, ptr);
- }
- color = logPen.elpColor;
- width = logPen.elpWidth;
- style = logPen.elpPenStyle;
- extPen = true;
- if (newWidth == 0) {
- if (dashes == null && (style & OS.PS_ENDCAP_MASK) == OS.PS_ENDCAP_FLAT && (style & OS.PS_JOIN_MASK) == OS.PS_JOIN_MITER) {
- style &= ~(OS.PS_ENDCAP_MASK | OS.PS_JOIN_MASK | OS.PS_TYPE_MASK);
- extPen = false;
- }
- }
- }
- if (newColor != -1) {
- if (newColor != color) {
- color = newColor;
- changed = true;
- }
- }
- if (newWidth != -1) {
- if (newWidth != width) {
- width = newWidth;
- changed = true;
- }
- }
- if (lineStyle != -1) {
- if ((style & OS.PS_STYLE_MASK) != lineStyle || (style & OS.PS_STYLE_MASK) == OS.PS_USERSTYLE) {
- style = (style & ~OS.PS_STYLE_MASK) | lineStyle;
- changed = true;
- }
- }
- if (capStyle != -1) {
- if ((style & OS.PS_ENDCAP_MASK) != capStyle) {
- style = (style & ~OS.PS_ENDCAP_MASK) | capStyle;
- changed = true;
- }
- }
- if (joinStyle != -1) {
- if ((style & OS.PS_JOIN_MASK) != joinStyle) {
- style = (style & ~OS.PS_JOIN_MASK) | joinStyle;
- changed = true;
- }
- }
- if (!changed) return;
- if ((style & OS.PS_STYLE_MASK) != OS.PS_USERSTYLE) dashes = null;
- /*
- * 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 newPen;
- if (!OS.IsWinCE && (extPen || width >= 1 || (style & OS.PS_STYLE_MASK) == OS.PS_USERSTYLE)) {
- 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);
- } else {
- newPen = OS.CreatePen(style, width, color);
- }
- OS.SelectObject(handle, newPen);
- if (data.hPen != 0) OS.DeleteObject(data.hPen);
- data.hPen = newPen;
- data.lineWidth = width;
- if (data.gdipPen != 0) {
- Gdip.Pen_delete(data.gdipPen);
- data.gdipPen = 0;
- }
-}
-
-/**
- * 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.
- *
- * @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>
- * </ul>
- *
- * @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(false, false);
- 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.
- *
- * @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>
- * </ul>
- *
- * @see Transform
- *
- * @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(false, false);
- if (transform != null) {
- Gdip.Graphics_SetTransform(data.gdipGraphics, transform.handle);
- } else {
- int identity = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
- Gdip.Graphics_SetTransform(data.gdipGraphics, identity);
- Gdip.Matrix_delete(identity);
- }
-}
-
-/**
- * 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 length = string.length();
- if (data.gdipGraphics != 0) {
- int font = createGdipFont();
- PointF pt = new PointF();
- RectF bounds = new RectF();
- char[] buffer;
- if (length != 0) {
- buffer = new char [length];
- string.getChars(0, length, buffer, 0);
- } else {
- buffer = new char[]{' '};
- }
- int format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic());
- Gdip.StringFormat_SetFormatFlags(format, Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces);
- Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, buffer.length, font, pt, format, bounds);
- Gdip.StringFormat_delete(format);
- Gdip.Font_delete(font);
- 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 specifing 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 (data.gdipGraphics != 0) {
- int font = createGdipFont();
- 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 format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic());
- Gdip.StringFormat_SetFormatFlags(format, Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces);
- float[] tabs = (flags & SWT.DRAW_TAB) != 0 ? new float[]{measureSpace(font, 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, font, pt, format, bounds);
- Gdip.StringFormat_delete(format);
- Gdip.Font_delete(font);
- 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 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 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/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 9d9be4cc4c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.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.graphics;
-
-
-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>
- */
-
-public final class GCData {
- public Device device;
- public int style;
- public Image image;
- public int foreground = -1;
- public int background = -1;
- public int hPen;
- public int lineWidth;
- public int[] dashes;
- public int hBrush;
- public int hFont;
- public int hNullBitmap;
- public int hwnd;
- public PAINTSTRUCT ps;
- public int layout = -1;
- public int alpha = 0xFF;
- public int gdipGraphics;
- public int gdipPen;
- public int gdipBrush;
- public Pattern foregroundPattern;
- public Pattern backgroundPattern;
-}
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 a4d5b3386a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,2086 +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 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
- */
-
-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 () {
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, width, height);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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>IMAGE_COPY</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>IMAGE_DISABLE</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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: {
- this.type = srcImage.type;
- switch (type) {
- case SWT.BITMAP:
- /* Get the HDC for the device */
- int hDC = device.internal_new_GC(null);
-
- /* Copy the bitmap */
- int hdcSource = OS.CreateCompatibleDC(hDC);
- int hdcDest = OS.CreateCompatibleDC(hDC);
- int 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 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(device, 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);
- }
- if (device.tracking) device.new_Object(this);
- return;
- }
- 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 (device, newData);
- if (device.tracking) device.new_Object(this);
- return;
- }
- 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 (device, newData);
- if (device.tracking) device.new_Object(this);
- return;
- }
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, bounds.width, bounds.height);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, data);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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(device, this, source, mask);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new ImageData(stream));
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- try {
- device.checkGDIP();
- int length = filename.length();
- char[] chars = new char[length+1];
- filename.getChars(0, length, chars, 0);
- int bitmap = Gdip.Bitmap_new(chars, false);
- int status = Gdip.Image_GetLastStatus(bitmap);
- if (bitmap != 0 && status == 0) {
- int transparentColor = -1;
- int error = SWT.ERROR_NO_HANDLES;
- int width = Gdip.Image_GetWidth(bitmap);
- int height = Gdip.Image_GetHeight(bitmap);
- if (filename.toLowerCase().endsWith(".ico")) {
- this.type = SWT.ICON;
- int[] hicon = new int[1];
- Gdip.Bitmap_GetHICON(bitmap, hicon);
- this.handle = hicon[0];
- } else {
- this.type = SWT.BITMAP;
- int pixelFormat = Gdip.Image_GetPixelFormat(bitmap);
- switch (pixelFormat) {
- case Gdip.PixelFormat32bppARGB:
- int lockedBitmapData = Gdip.BitmapData_new();
- if (lockedBitmapData == 0) break;
- Gdip.Bitmap_LockBits(bitmap, 0, 0, pixelFormat, lockedBitmapData);
- BitmapData bitmapData = new BitmapData();
- Gdip.MoveMemory(bitmapData, lockedBitmapData, BitmapData.sizeof);
- int stride = bitmapData.Stride;
- int pixels = bitmapData.Scan0;
- byte[] line = new byte[stride];
- alphaData = new byte[width * height];
- for (int y = 0; y < height; y++) {
- OS.MoveMemory(line, pixels + (y * stride), stride);
- for (int x = 0; x < width; x++) {
- alphaData[y*width+x] = line[x*4 + 3];
- }
- }
- Gdip.Bitmap_UnlockBits(bitmap, lockedBitmapData);
- Gdip.BitmapData_delete(lockedBitmapData);
- this.handle = createDIB(width, height, 32);
- break;
- case Gdip.PixelFormat1bppIndexed:
- case Gdip.PixelFormat4bppIndexed:
- case Gdip.PixelFormat8bppIndexed:
- int paletteSize = Gdip.Image_GetPaletteSize(bitmap);
- int hHeap = OS.GetProcessHeap();
- int palette = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, paletteSize);
- if (palette == 0) break;
- 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);
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = width;
- bmiHeader.biHeight = -height;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = (short)8;
- bmiHeader.biCompression = OS.BI_RGB;
- byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + colorPalette.Count * 4];
- OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
- int offset = BITMAPINFOHEADER.sizeof;
- for (int i = 0; i < entries.length; i++) {
- if (((entries[i] >> 24) & 0xFF) == 0 && (colorPalette.Flags & Gdip.PaletteFlagsHasAlpha) != 0) {
- transparentPixel = i;
- transparentColor = entries[i] & 0xFFFFFF;
- }
- bmi[offset] = (byte)((entries[i] & 0xFF) >> 0);
- bmi[offset + 1] = (byte)((entries[i] & 0xFF00) >> 8);
- bmi[offset + 2] = (byte)((entries[i] & 0xFF0000) >> 16);
- bmi[offset + 3] = 0;
- offset += 4;
- }
- int[] pBits = new int[1];
- this.handle = OS.CreateDIBSection(0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- break;
- case Gdip.PixelFormat16bppGrayScale:
- case Gdip.PixelFormat16bppRGB555:
- case Gdip.PixelFormat16bppRGB565:
- this.handle = createDIB(width, height, 16);
- break;
- case Gdip.PixelFormat24bppRGB:
- this.handle = createDIB(width, height, 24);
- break;
- default:
- this.handle = createDIB(width, height, 32);
- }
- if (handle != 0) {
- int hDC = device.internal_new_GC(null);
- int srcHDC = OS.CreateCompatibleDC(hDC);
- int oldSrcBitmap = OS.SelectObject(srcHDC, handle);
- int graphics = Gdip.Graphics_new(srcHDC);
- if (graphics != 0) {
- if (transparentColor != -1) {
- int color = Gdip.Color_new(transparentColor | 0xFF000000);
- if (color != 0) {
- int brush = Gdip.SolidBrush_new(color);
- if (brush != 0) {
- Gdip.Graphics_FillRectangle(graphics, brush, 0, 0, width, height);
- Gdip.SolidBrush_delete(brush);
- }
- Gdip.Color_delete(color);
- }
- }
- 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);
- handle = 0;
- }
- Gdip.Graphics_delete(graphics);
- }
- OS.SelectObject(srcHDC, oldSrcBitmap);
- OS.DeleteDC(srcHDC);
- device.internal_dispose_GC(hDC, null);
- }
- }
- Gdip.Bitmap_delete(bitmap);
- if (handle == 0) SWT.error(error);
- return;
- }
- } catch (SWTException e) {}
- init(device, new ImageData(filename));
- if(device.tracking) device.new_Object(this);
-}
-
-/**
- * Create a DIB from a DDB without using GetDIBits. Note that
- * the DDB should not be selected into a HDC.
- */
-int createDIBFromDDB(int hDC, int 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[] pBits = new int[1];
- int 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 hdcSource = OS.CreateCompatibleDC(hDC);
- int hdcDest = OS.CreateCompatibleDC(hDC);
- int hOldSrc = OS.SelectObject(hdcSource, hBitmap);
- int 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[] 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 hDC = device.internal_new_GC(null);
- int srcHdc = OS.CreateCompatibleDC(hDC);
- int oldSrcBitmap = OS.SelectObject(srcHdc, handle);
- int memHdc = OS.CreateCompatibleDC(hDC);
- int memDib = createDIB(imgWidth, imgHeight, 32);
- if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int 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);
- 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 hHeap = OS.GetProcessHeap();
- int pixels = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, srcData.length);
- OS.MoveMemory(pixels, srcData, sizeInBytes);
- return new int[]{Gdip.Bitmap_new(imgWidth, imgHeight, dibBM.bmWidthBytes, Gdip.PixelFormat32bppARGB, pixels), pixels};
- }
- return new int[]{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 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 img = 0, pixels = 0;
- if (imgWidth > imgHeight) {
- int hDC = device.internal_new_GC(null);
- int srcHdc = OS.CreateCompatibleDC(hDC);
- int oldSrcBitmap = OS.SelectObject(srcHdc, hBitmap);
- int memHdc = OS.CreateCompatibleDC(hDC);
- int memDib = createDIB(imgWidth, imgHeight, 32);
- if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int 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 = 0; y < imgHeight; ++y) {
- for (int x = 0; x < imgWidth; ++x) {
- if (OS.GetPixel(srcHdc, x, y) != 0) {
- srcData[dp + 3] = (byte)0;
- } else {
- srcData[dp + 3] = (byte)0xFF;
- }
- dp += 4;
- }
- }
- OS.SelectObject(srcHdc, oldSrcBitmap);
- OS.DeleteObject(srcHdc);
- device.internal_dispose_GC(hDC, null);
- int hHeap = OS.GetProcessHeap();
- pixels = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, srcData.length);
- 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[]{img, pixels};
- }
- default: SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- return null;
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the image. Applications must dispose of all images which
- * they allocate.
- */
-public void dispose () {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- 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;
- if (device.tracking) device.dispose_Object(this);
- device = 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 hDC = device.internal_new_GC(null);
-
- /* Compute the background color */
- BITMAP bm = new BITMAP();
- OS.GetObject(handle, BITMAP.sizeof, bm);
- int hdcMem = OS.CreateCompatibleDC(hDC);
- int 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, 0x02000000 | (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 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 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 hDC = device.internal_new_GC(null);
-
- /* Create the DC and select the bitmap */
- int hBitmapDC = OS.CreateCompatibleDC(hDC);
- int hOldBitmap = OS.SelectObject(hBitmapDC, hBitmap);
- /* Select the palette if necessary */
- int oldPalette = 0;
- if (depth <= 8) {
- int 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 hHeap = OS.GetProcessHeap();
- int lpvBits = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, imageSize);
- 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 lpvMaskBits = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, imageSize);
- 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 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 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 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 hBitmapDC = OS.CreateCompatibleDC(hDC);
- int hOldBitmap = OS.SelectObject(hBitmapDC, handle);
- /* Select the palette if necessary */
- int oldPalette = 0;
- if (!isDib && depth <= 8) {
- int 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 hHeap = OS.GetProcessHeap();
- int lpvBits = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, imageSize);
- 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 handle;
-}
-
-void init(Device device, int width, int height) {
- if (width <= 0 || height <= 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.device = device;
- type = SWT.BITMAP;
- int 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 memDC = OS.CreateCompatibleDC(hDC);
- int 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 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[] pBits = new int[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[] result = init(image.device, null, image.data);
- info.hbmColor = result[0];
- info.hbmMask = result[1];
-}
-
-static int[] init(Device device, Image image, ImageData i) {
- if (image != null) image.device = device;
-
- /*
- * 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[] pBits = new int[1];
- int 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[] result = null;
- if (i.getTransparencyType() == SWT.TRANSPARENCY_MASK) {
- /* Get the HDC for the device */
- int hDC = device.internal_new_GC(null);
-
- /* Create the color bitmap */
- int hdcSrc = OS.CreateCompatibleDC(hDC);
- OS.SelectObject(hdcSrc, hDib);
- int hBitmap = OS.CreateCompatibleBitmap(hDC, i.width, i.height);
- if (hBitmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int 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 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[]{hBitmap, hMask};
- } else {
- /* Create the icon */
- ICONINFO info = new ICONINFO();
- info.fIcon = true;
- info.hbmColor = hBitmap;
- info.hbmMask = hMask;
- int 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[]{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[] 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(Device device, 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 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 hDC = device.internal_new_GC(null);
- int 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.hFont = 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 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;
-
- /* Get the HDC for the device */
- int hDC = device.internal_new_GC(null);
-
- /* Change the background color in the image */
- BITMAP bm = new BITMAP();
- OS.GetObject(handle, BITMAP.sizeof, bm);
- int 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 handle) {
- if (device == null) device = Device.getDevice();
- Image image = new Image();
- image.type = type;
- image.handle = handle;
- image.device = device;
- 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 29584907ce..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Path.java
+++ /dev/null
@@ -1,497 +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 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>
- *
- * @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;
-
- PointF currentPoint = new PointF(), startPoint = new PointF();
-
-/**
- * Constructs a new empty Path.
- *
- * @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 SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained/li>
- * </ul>
- *
- * @see #dispose()
- */
-public Path (Device device) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- device.checkGDIP();
- handle = Gdip.GraphicsPath_new(Gdip.FillModeAlternate);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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 path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate);
- if (path == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int 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 hDC = device.internal_new_GC(null);
- int gdipFont = GC.createGdipFont(hDC, font.handle);
- PointF point = new PointF();
- point.X = x - (Gdip.Font_GetSize(gdipFont) / 6);
- point.Y = y;
- int family = Gdip.FontFamily_new();
- Gdip.Font_GetFamily(gdipFont, family);
- int style = Gdip.Font_GetStyle(gdipFont);
- float size = Gdip.Font_GetSize(gdipFont);
- Gdip.GraphicsPath_AddString(handle, buffer, length, family, style, size, point, 0);
- Gdip.GraphicsPath_GetLastPoint(handle, currentPoint);
- Gdip.FontFamily_delete(family);
- 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(outline, false);
- 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);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the Path. Applications must dispose of all Paths that
- * they allocate.
- */
-public void dispose() {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- Gdip.GraphicsPath_delete(handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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);
- 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);
-}
-
-/**
- * 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 8f1ad45463..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java
+++ /dev/null
@@ -1,226 +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 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>
- *
- * @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.
- *
- * @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 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.device = device;
- device.checkGDIP();
- int[] gdipImage = image.createGdipImage();
- int 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 hHeap = OS.GetProcessHeap ();
- OS.HeapFree(hHeap, 0, gdipImage[1]);
- }
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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.
- *
- * @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 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.
- *
- * @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 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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 = device;
- device.checkGDIP();
- int colorRef1 = color1.handle;
- int rgb = ((colorRef1 >> 16) & 0xFF) | (colorRef1 & 0xFF00) | ((colorRef1 & 0xFF) << 16);
- int foreColor = Gdip.Color_new((alpha1 & 0xFF) << 24 | rgb);
- int colorRef2 = color2.handle;
- rgb = ((colorRef2 >> 16) & 0xFF) | (colorRef2 & 0xFF00) | ((colorRef2 & 0xFF) << 16);
- int 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 midColor = Gdip.Color_new(a << 24 | r << 16 | g << 8 | b);
- Gdip.LinearGradientBrush_SetInterpolationColors(handle, new int[]{foreColor, midColor, backColor}, new float[]{0, 0.5f, 1}, 3);
- Gdip.Color_delete(midColor);
- }
- Gdip.Color_delete(foreColor);
- Gdip.Color_delete(backColor);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the Pattern. Applications must dispose of all Patterns that
- * they allocate.
- */
-public void dispose() {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- 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;
- if (device.tracking) device.dispose_Object(this);
- device = 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 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 5e5ae6f17d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,605 +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.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>
- */
-
-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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- handle = OS.CreateRectRgn (0, 0, 0, 0);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * 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) {
- this.device = 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 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 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);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the region. Applications must dispose of all regions which
- * they allocate.
- */
-public void dispose () {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- OS.DeleteObject(handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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 (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 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.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 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 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 9a8df9e93e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java
+++ /dev/null
@@ -1,2221 +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 org.eclipse.swt.internal.*;
-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>
- *
- * @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;
-
- StyleItem[] allRuns;
- StyleItem[][] runs;
- int[] lineOffset, lineY, lineWidth;
- int 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);
- }
-
- class StyleItem {
- TextStyle style;
- int start, length;
- boolean lineBreak, softBreak, tab;
-
- /*Script cache and analysis */
- SCRIPT_ANALYSIS analysis;
- int psc = 0;
-
- /*Shape info (malloc when the run is shaped) */
- int glyphs;
- int glyphCount;
- int clusters;
- int visAttrs;
-
- /*Place info (malloc when the run is placed) */
- int advances;
- int goffsets;
- int width;
- int ascent;
- int descent;
- int leading;
- int x;
-
- /* Justily info (malloc during computeRuns) */
- int justify;
-
- /* ScriptBreak */
- int psla;
-
- int fallbackFont;
-
- void free() {
- int 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) {
- if (mLangFontLink2 != 0) {
- /* ReleaseFont() */
- OS.VtblCall(8, mLangFontLink2, 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = 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$
- int[] ppv = new int[1];
- OS.OleInitialize(0);
- if (OS.CoCreateInstance(CLSID_CMultiLanguage, 0, OS.CLSCTX_INPROC_SERVER, IID_IMLangFontLink2, ppv) == OS.S_OK) {
- mLangFontLink2 = ppv[0];
- }
- if (device.tracking) device.new_Object(this);
-}
-
-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 hHeap = OS.GetProcessHeap();
- run.psla = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, SCRIPT_LOGATTR.sizeof * chars.length);
- OS.ScriptBreak(chars, chars.length, run.analysis, run.psla);
-}
-
-void checkItem (int hDC, StyleItem item) {
- if (item.fallbackFont != 0) {
- /*
- * Feature in Windows. The fallback font returned by the MLang service
- * can be disposed by some other client running in the same thread.
- * For example, disposing a Browser widget internally releases all fonts
- * in the MLang cache. The fix is to use GetObject() to detect if the
- * font was disposed and reshape the run.
- */
- LOGFONT logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA();
- if (OS.GetObject(item.fallbackFont, LOGFONT.sizeof, logFont) == 0) {
- item.free();
- OS.SelectObject(hDC, getItemFont(item));
- shape(hDC, item);
- }
- }
-}
-
-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 hDC = gc != null ? gc.handle : device.internal_new_GC(null);
- int 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 (run.length == 1) {
- char ch = segmentsText.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;
- break;
- }
- case '\r': {
- run.lineBreak = true;
- StyleItem next = allRuns[i + 1];
- if (next.length != 0 && segmentsText.charAt(next.start) == '\n') {
- run.length += 1;
- next.free();
- i++;
- }
- break;
- }
- }
- }
- 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) {
- 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 = run.analysis;
- run.free();
- run.length = start;
- OS.SelectObject(srcHdc, getItemFont(run));
- shape (srcHdc, run);
- OS.SelectObject(srcHdc, getItemFont(newRun));
- 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) {
- 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 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);
- 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;
-
- runs[line] = reorder(runs[line]);
- StyleItem 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] = lastRun.start + lastRun.length;
- 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);
-}
-
-/**
- * Disposes of the operating system resources associated with
- * the text layout. Applications must dispose of all allocated text layouts.
- */
-public void dispose () {
- if (device == null) return;
- 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();
- if (device.tracking) device.dispose_Object(this);
- device = 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) {
- 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) return;
- int hdc = gc.handle;
- 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);
- selectionStart = translateOffset(selectionStart);
- selectionEnd = translateOffset(selectionEnd);
- }
- int foreground = OS.GetTextColor(hdc);
- int state = OS.SaveDC(hdc);
- RECT rect = new RECT();
- int selBrush = 0, selPen = 0;
- if (hasSelection) {
- selBrush = OS.CreateSolidBrush(selectionBackground.handle);
- selPen = OS.CreatePen(OS.BS_SOLID, 1, selectionForeground.handle);
- }
- int rop2 = 0;
- if (OS.IsWinCE) {
- rop2 = OS.SetROP2(hdc, OS.R2_COPYPEN);
- OS.SetROP2(hdc, rop2);
- } else {
- rop2 = OS.GetROP2(hdc);
- }
- int dwRop = rop2 == OS.R2_XORPEN ? OS.PATINVERT : OS.PATCOPY;
- OS.SetBkMode(hdc, OS.TRANSPARENT);
- Rectangle clip = gc.getClipping();
- for (int line=0; line<runs.length; line++) {
- int drawX = x + getLineIndent(line);
- int drawY = y + lineY[line];
- if (drawX > clip.x + clip.width) continue;
- if (drawX + lineWidth[line] < clip.x) continue;
- StyleItem[] lineRuns = runs[line];
- 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];
- 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) {
- int end = run.start + run.length - 1;
- boolean fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end;
- if (fullSelection) {
- OS.SelectObject(hdc, selBrush);
- OS.PatBlt(hdc, drawX, drawY, run.width, lineHeight - lineSpacing, dwRop);
- } else {
- if (run.style != null && run.style.background != null) {
- int bg = run.style.background.handle;
- int drawRunY = drawY + (baseline - run.ascent);
- int hBrush = OS.CreateSolidBrush (bg);
- int oldBrush = OS.SelectObject(hdc, hBrush);
- OS.PatBlt(hdc, drawX, drawRunY, run.width, run.ascent + run.descent, dwRop);
- OS.SelectObject(hdc, oldBrush);
- OS.DeleteObject(hBrush);
- }
- boolean partialSelection = hasSelection && !(selectionStart > end || run.start > selectionEnd);
- if (partialSelection) {
- OS.SelectObject(hdc, selBrush);
- 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 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 = drawX + runX;
- rect.top = drawY;
- 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 = drawX + runX;
- rect.bottom = drawY + lineHeight - lineSpacing;
- OS.PatBlt(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, dwRop);
- }
- }
- }
- }
- drawX += run.width;
- }
- drawX = alignmentX;
- 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.tab && (!run.lineBreak || run.softBreak) && !(run.style != null && run.style.metrics != null)) {
- int end = run.start + run.length - 1;
- int fg = foreground;
- boolean fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end;
- if (fullSelection) {
- fg = selectionForeground.handle;
- } else {
- if (run.style != null && run.style.foreground != null) fg = run.style.foreground.handle;
- }
- OS.SetTextColor(hdc, fg);
- checkItem(hdc, run);
- OS.SelectObject(hdc, getItemFont(run));
- int drawRunY = drawY + (baseline - run.ascent);
- OS.ScriptTextOut(hdc, run.psc, drawX, drawRunY, 0, null, run.analysis , 0, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets);
- if ((run.style != null) && (run.style.underline || run.style.strikeout)) {
- int newPen = hasSelection && fg == selectionForeground.handle ? selPen : OS.CreatePen(OS.BS_SOLID, 1, fg);
- int oldPen = OS.SelectObject(hdc, newPen);
- if (run.style.underline) {
- int underlineY = drawY + baseline + 1 - run.style.rise;
- OS.MoveToEx(hdc, drawX, underlineY, 0);
- OS.LineTo(hdc, drawX + run.width, underlineY);
- }
- if (run.style.strikeout) {
- int strikeoutY = drawRunY + run.leading + (run.ascent - run.style.rise) / 2;
- OS.MoveToEx(hdc, drawX, strikeoutY, 0);
- OS.LineTo(hdc, drawX + run.width, strikeoutY);
- }
- OS.SelectObject(hdc, oldPen);
- if (!hasSelection || fg != selectionForeground.handle) OS.DeleteObject(newPen);
- }
- boolean partialSelection = hasSelection && !(selectionStart > end || run.start > selectionEnd);
- if (!fullSelection && partialSelection && fg != selectionForeground.handle) {
- OS.SetTextColor(hdc, selectionForeground.handle);
- 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 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 = drawX + runX;
- rect.top = drawY;
- 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 = drawX + runX;
- rect.bottom = drawY + lineHeight;
- OS.ScriptTextOut(hdc, run.psc, drawX, drawRunY, OS.ETO_CLIPPED, rect, run.analysis , 0, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets);
- if ((run.style != null) && (run.style.underline || run.style.strikeout)) {
- int oldPen = OS.SelectObject(hdc, selPen);
- if (run.style.underline) {
- int underlineY = drawY + baseline + 1 - run.style.rise;
- OS.MoveToEx(hdc, rect.left, underlineY, 0);
- OS.LineTo(hdc, rect.right, underlineY);
- }
- if (run.style.strikeout) {
- int strikeoutY = drawRunY + run.leading + (run.ascent - run.style.rise) / 2;
- OS.MoveToEx(hdc, rect.left, strikeoutY, 0);
- OS.LineTo(hdc, rect.right, strikeoutY);
- }
- OS.SelectObject(hdc, oldPen);
- }
- }
- }
- }
- drawX += run.width;
- }
- }
- OS.RestoreDC(hdc, state);
- if (selBrush != 0) OS.DeleteObject (selBrush);
- if (selPen != 0) OS.DeleteObject (selPen);
-}
-
-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.
- *
- * @return the bounds of the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-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;
- int lineIndex = 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 (run.lineBreak) lineIndex++;
- 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 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 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;
- }
- }
- left = Math.min(left, runLead);
- right = Math.max(right, runTrail);
- top = Math.min(top, lineY[run.lineBreak ? lineIndex - 1 : lineIndex]);
- bottom = Math.max(bottom, lineY[run.lineBreak ? lineIndex : 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 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;
-}
-
-/**
- * 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 charecter 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 hDC = device.internal_new_GC(null);
- int srcHdc = OS.CreateCompatibleDC(hDC);
- TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
- OS.SelectObject(srcHdc, font != null ? font.handle : device.systemFont);
- 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);
- 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.style != null && run.style.metrics != null) {
- GlyphMetrics metrics = run.style.metrics;
- width += metrics.width * (offset - run.start + (trailing ? 1 : 0));
- result = new Point(width, lineY[line]);
- } else if (run.tab) {
- if (trailing || (offset == length)) width += run.width;
- result = new Point(width, lineY[line]);
- } else {
- int runOffset = offset - run.start;
- int cChars = run.length;
- int gGlyphs = run.glyphCount;
- int[] piX = new int[1];
- int advances = run.justify != 0 ? run.justify : run.advances;
- OS.ScriptCPtoX(runOffset, trailing, cChars, gGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piX);
- if ((orientation & SWT.RIGHT_TO_LEFT) != 0) {
- result = new Point(width + (run.width - piX[0]), lineY[line]);
- } else {
- result = new Point(width + piX[0], lineY[line]);
- }
- }
- break;
- }
- width += run.width;
- }
- }
- if (result == null) result = new Point(0, 0);
- result.x += getLineIndent(line);
- return result;
-}
-
-/**
- * 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> or <code>SWT.MOVEMENT_WORD</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: {
- 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;
- }
- }
- 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);
- x -= getLineIndent(line);
- StyleItem[] lineRuns = runs[line];
- if (x >= lineWidth[line]) x = lineWidth[line] - 1;
- if (x < 0) x = 0;
- int width = 0;
- for (int i = 0; i < lineRuns.length; i++) {
- StyleItem run = lineRuns[i];
- if (run.lineBreak && !run.softBreak) return untranslateOffset(run.start);
- if (width + run.width > x) {
- int xRun = x - width;
- 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 < (width + 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 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]);
- }
- width += run.width;
- }
- if (trailing != null) trailing[0] = 0;
- 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;
-}
-
-/**
- * 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>.
- *
- * @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;
-}
-
-/**
- * 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 hHeap = OS.GetProcessHeap();
- int pItems = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, MAX_ITEM * SCRIPT_ITEM.sizeof);
- 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 items, int itemCount) {
- int count = 0, start = 0, end = segmentsText.length(), itemIndex = 0, styleIndex = 0;
- StyleItem[] runs = new StyleItem[itemCount + styles.length];
- SCRIPT_ITEM scriptItem = new SCRIPT_ITEM();
- boolean linkBefore = false;
- 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;
- if (linkBefore) {
- item.analysis.fLinkBefore = true;
- linkBefore = false;
- }
- scriptItem.a = new SCRIPT_ANALYSIS();
- OS.MoveMemory(scriptItem, items + (itemIndex + 1) * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof);
- int 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.isWhitespace(pChar) && !Compatibility.isWhitespace(tChar)) {
- item.analysis.fLinkAfter = true;
- linkBefore = true;
- }
- }
- }
- if (itemLimit <= styleLimit) {
- itemIndex++;
- start = itemLimit;
- }
- 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) {
- 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) {
- for (int i = 0; i < (length - 1) / 2 ; i++) {
- StyleItem tmp = result[i];
- result[i] = result[length - i - 2];
- result[length - i - 2] = 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);
- if (this.font == font) return;
- if (font != null && font.equals(this.font)) return;
- freeRuns();
- this.font = font;
-}
-
-/**
- * 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.
- *
- * @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;
-}
-
-boolean shape (int hdc, StyleItem run, char[] chars, int[] glyphCount, int maxGlyphs) {
- 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 (hr != OS.USP_E_SCRIPT_NOT_IN_FONT) {
- 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, glyphCount, 4);
- }
- run.glyphCount = 0;
- return false;
-}
-
-/*
- * Generate glyphs for one Run.
- */
-void shape (final int hdc, final StyleItem run) {
- int[] buffer = new int[1];
- char[] chars = new char[run.length];
- segmentsText.getChars(run.start, run.start + run.length, chars, 0);
- int maxGlyphs = (chars.length * 3 / 2) + 16;
- int hHeap = OS.GetProcessHeap();
- run.glyphs = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2);
- run.clusters = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2);
- run.visAttrs = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * SCRIPT_VISATTR_SIZEOF);
- run.psc = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, 4);
- if (!shape(hdc, run, chars, buffer, maxGlyphs)) {
- if (mLangFontLink2 != 0) {
- int[] dwCodePages = new int[1];
- int[] cchCodePages = new int[1];
- /* GetStrCodePages() */
- OS.VtblCall(4, mLangFontLink2, chars, chars.length, 0, dwCodePages, cchCodePages);
- int[] hNewFont = new int[1];
- /* MapFont() */
- if (OS.VtblCall(10, mLangFontLink2, hdc, dwCodePages[0], chars[0], hNewFont) == OS.S_OK) {
- int hFont = OS.SelectObject(hdc, hNewFont[0]);
- if (shape(hdc, run, chars, buffer, maxGlyphs)) {
- run.fallbackFont = hNewFont[0];
- } else {
- /* ReleaseFont() */
- OS.VtblCall(8, mLangFontLink2, hNewFont[0]);
- OS.SelectObject(hdc, hFont);
- 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);
- run.goffsets = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, run.glyphCount * GOFFSET_SIZEOF);
- OS.ScriptPlace(hdc, run.psc, run.glyphs, run.glyphCount, run.visAttrs, run.analysis, run.advances, run.goffsets, abc);
- if (run.style != null && run.style.metrics != null) {
- GlyphMetrics metrics = run.style.metrics;
- /*
- * Bug in Windows, on a Japanese machine, Uniscribe returns glyphcount
- * equals zero for FFFC (possibily 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 {
- run.width = abc[0] + abc[1] + abc[2];
- 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;
- }
- if (run.style != null) {
- run.ascent += run.style.rise;
- run.descent -= +run.style.rise;
- }
-}
-
-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 004bdd5f15..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java
+++ /dev/null
@@ -1,316 +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 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>
- *
- * @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.
- *
- * @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 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.
- *
- * @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 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.
- *
- * @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 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) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- device.checkGDIP();
- handle = Gdip.Matrix_new(m11, m12, m21, m22, dx, dy);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
-
-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.
- */
-public void dispose() {
- if (handle == 0) return;
- if (device.isDisposed()) return;
- Gdip.Matrix_delete(handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = 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);
- Gdip.Matrix_GetElements(handle, elements);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * 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 invertable</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);
-}
-
-/**
- * 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 70476a9c5a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/BidiUtil.java
+++ /dev/null
@@ -1,652 +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.Hashtable;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.internal.win32.*;
-/*
- * 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;
- // 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 hwnd, Runnable runnable) {
- languageMap.put(new Integer(hwnd), runnable);
- subclass(hwnd);
-}
-/**
- * Proc used for OS.EnumSystemLanguageGroups call during isBidiPlatform test.
- */
-static int EnumSystemLanguageGroupsProc(int lpLangGrpId, int lpLangGrpIdString, int lpLangGrpName, int options, int lParam) {
- if (lpLangGrpId == OS.LGRPID_HEBREW) {
- isBidiPlatform = 1;
- return 0;
- }
- if (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 paramteter
- * @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 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 lpOrder = result.lpOrder = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount * 4);
- int lpDx = result.lpDx = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount * 4);
- int lpClass = result.lpClass = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- int 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 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 lpOrder = result.lpOrder = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount * 4);
- int 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 layout = OS.GetKeyboardLayout(0);
- // only interested in low 2 bytes, which is the primary
- // language identifier
- layout = layout & 0x000000FF;
- if (layout == LANG_HEBREW) return KEYBOARD_BIDI;
- if (layout == LANG_ARABIC) return KEYBOARD_BIDI;
- // return non-bidi for all other languages
- return 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[] getKeyboardLanguageList() {
- int maxSize = 10;
- int[] tempList = new int[maxSize];
- int size = OS.GetKeyboardLayoutList(maxSize, tempList);
- int[] list = new int[size];
- System.arraycopy(tempList, 0, list, 0, size);
- return list;
-}
-/**
- * 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 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[] list = getKeyboardLanguageList();
- for (int i=0; i<list.length; i++) {
- int id = list[i] & 0x000000FF;
- if ((id == LANG_ARABIC) || (id == LANG_HEBREW)) {
- 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 hwnd) {
- languageMap.remove(new Integer(hwnd));
- unsubclass(hwnd);
-}
-/**
- * Switch the keyboard language to the specified language type. We do
- * not distinguish between mulitple 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) {
- // don't switch the keyboard if it doesn't need to be
- if (language == getKeyboardLanguage()) return;
-
- if (language == KEYBOARD_BIDI) {
- // get the list of active languages
- int[] list = getKeyboardLanguageList();
- // set to first bidi language
- for (int i=0; i<list.length; i++) {
- int id = list[i] & 0x000000FF;
- if ((id == LANG_ARABIC) || (id == LANG_HEBREW)) {
- OS.ActivateKeyboardLayout(list[i], 0);
- return;
- }
- }
- } else {
- // get the list of active languages
- int[] list = getKeyboardLanguageList();
- // set to the first non-bidi language (anything not
- // hebrew or arabic)
- for (int i=0; i<list.length; i++) {
- int id = list[i] & 0x000000FF;
- if ((id != LANG_HEBREW) && (id != LANG_ARABIC)) {
- 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 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;
-}
-/**
- * Override the window proc.
- *
- * @param hwnd control to override the window proc of
- */
-static void subclass(int hwnd) {
- Integer key = new Integer(hwnd);
- if (oldProcMap.get(key) == null) {
- int oldProc = OS.GetWindowLong(hwnd, OS.GWL_WNDPROC);
- oldProcMap.put(key, new Integer(oldProc));
- OS.SetWindowLong(hwnd, OS.GWL_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 hwnd) {
- Integer key = new Integer(hwnd);
- if (languageMap.get(key) == null && keyMap.get(key) == null) {
- Integer proc = (Integer) oldProcMap.remove(key);
- if (proc == null) return;
- OS.SetWindowLong(hwnd, OS.GWL_WNDPROC, proc.intValue());
- }
-}
-/**
- * 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 windowProc (int hwnd, int msg, int wParam, int lParam) {
- Integer key = new Integer (hwnd);
- switch (msg) {
- case 0x51 /*OS.WM_INPUTLANGCHANGE*/:
- Runnable runnable = (Runnable) languageMap.get (key);
- if (runnable != null) runnable.run ();
- break;
- }
- Integer oldProc = (Integer)oldProcMap.get(key);
- return OS.CallWindowProc (oldProc.intValue(), hwnd, msg, wParam, lParam);
-}
-
-}
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 9e57d7f30d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java
+++ /dev/null
@@ -1,1117 +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.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>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>
- */
-
-public class Button extends Control {
- String text = "";
- Image image, image2, disabledImage;
- ImageList imageList;
- boolean ignoreMouse;
- static final int MARGIN = 4;
- static final int CHECK_WIDTH, CHECK_HEIGHT;
- static final int ICON_WIDTH = 128, ICON_HEIGHT = 128;
- static final int ButtonProc;
- static final TCHAR ButtonClass = new TCHAR (0, "BUTTON", true);
- static {
- int 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#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 (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 hImage = 0, 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 hDC = OS.GetDC (handle);
- int dstHdc = OS.CreateCompatibleDC (hDC);
- int hBitmap = OS.CreateCompatibleBitmap (hDC, rect.width, rect.height);
- int oldBitmap = OS.SelectObject (dstHdc, hBitmap);
- OS.SetLayout (dstHdc, OS.LAYOUT_RTL);
- if (fImageType == OS.IMAGE_BITMAP) {
- int srcHdc = OS.CreateCompatibleDC (hDC);
- int 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 newBrush = OS.CreateSolidBrush (control.getBackgroundPixel ());
- int 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 append a space to 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 sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected.
- * <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 callWindowProc (int hwnd, int msg, int wParam, int 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, 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 oldFont = 0;
- int hDC = OS.GetDC (handle);
- int 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);
- }
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- width += border * 2; height += border * 2;
- return new Point (width, height);
- }
- int extra = 0;
- boolean hasImage = image != null, hasText = true;
- if (OS.COMCTL32_MAJOR < 6) {
- 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 oldFont = 0;
- int hDC = OS.GetDC (handle);
- int 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 () {
- super.createHandle ();
- if ((style & SWT.PUSH) == 0) state |= THEME_BACKGROUND;
- if (OS.COMCTL32_MAJOR >= 6) {
- if ((style & SWT.RADIO) != 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 append a space to 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 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 state = OS.SendMessage (handle, OS.BM_GETCHECK, 0, 0);
- return (state & OS.BST_CHECKED) != 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 ();
- if ((style & SWT.ARROW) != 0) return "";
- return text;
-}
-
-boolean isTabItem () {
- //TEMPORARY CODE
- //if ((style & SWT.PUSH) != 0) return true;
- 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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.
- *
- * @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);
-}
-
-boolean setRadioFocus () {
- if ((style & SWT.RADIO) == 0 || !getSelection ()) return false;
- return 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;
- /*
- * 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);
- OS.SendMessage (handle, OS.BM_SETCHECK, flags, 0);
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
-}
-
-/**
- * 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 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.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);
-}
-
-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;
- return bits | OS.BS_PUSHBUTTON | OS.WS_TABSTOP;
-}
-
-TCHAR windowClass () {
- return ButtonClass;
-}
-
-int windowProc () {
- return ButtonProc;
-}
-
-
-LRESULT WM_ERASEBKGND (int wParam, int 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 || !OS.IsAppThemed ()) {
- if ((style & (SWT.RADIO | SWT.CHECK)) != 0) {
- if (findImageControl () != null) {
- drawBackground (wParam);
- return LRESULT.ONE;
- }
- }
- }
- return result;
-}
-
-LRESULT WM_GETDLGCODE (int wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- if ((style & SWT.PUSH) != 0 && getDefault ()) {
- menuShell ().setDefaultButton (null, false);
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
- if (ignoreMouse) return null;
- return super.WM_LBUTTONDOWN (wParam, lParam);
-}
-
-LRESULT WM_LBUTTONUP (int wParam, int lParam) {
- if (ignoreMouse) return null;
- return super.WM_LBUTTONUP (wParam, lParam);
-}
-
-LRESULT WM_SETFOCUS (int wParam, int 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 wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
- if (result != null) return result;
- if (image2 != null) _setImage (image);
- return result;
-}
-
-LRESULT wmCommandChild (int wParam, int lParam) {
- int code = wParam >> 16;
- 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 wParam, int 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 || !OS.IsAppThemed ()) {
- 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 wParam, int 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 hTheme = OS.OpenThemeData (handle, SCROLLBAR);
- 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;
- }
- /*
- * 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 (hTheme, struct.hDC, OS.SBP_ARROWBTN, iStateId, rect, null);
- OS.CloseThemeData (hTheme);
- } 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 02ccbd6e8c..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java
+++ /dev/null
@@ -1,338 +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.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
- */
-
-public class Canvas extends Composite {
- Caret caret;
-
-/**
- * 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 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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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;
-}
-
-void releaseChildren (boolean destroy) {
- if (caret != null) {
- caret.release (false);
- caret = null;
- }
- super.releaseChildren (destroy);
-}
-
-/**
- * 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 hDC = gc.handle;
- int pixel = background == -1 ? OS.GetBkColor (hDC) : -1;
- drawBackground (hDC, rect, pixel);
-}
-
-/**
- * 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);
-}
-
-LRESULT WM_INPUTLANGCHANGE (int wParam, int lParam) {
- LRESULT result = super.WM_INPUTLANGCHANGE (wParam, lParam);
- if (caret != null && caret.isFocusCaret ()) {
- caret.setIMEFont ();
- caret.resizeIME ();
- }
- return result;
-}
-
-LRESULT WM_KILLFOCUS (int wParam, int lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- if (caret != null) caret.killFocus ();
- return result;
-}
-
-LRESULT WM_SETFOCUS (int wParam, int lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if (caret != null) caret.setFocus ();
- return result;
-}
-
-LRESULT WM_SIZE (int wParam, int lParam) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (caret != null && caret.isFocusCaret ()) caret.resizeIME ();
- return result;
-}
-
-LRESULT WM_WINDOWPOSCHANGED (int wParam, int 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 wParam, int 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 f5ae930e3f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java
+++ /dev/null
@@ -1,554 +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.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>
- */
-
-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 defaultFont () {
- int hwnd = parent.handle;
- int hwndIME = OS.ImmGetDefaultIMEWnd (hwnd);
- int 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);
- }
- 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 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);
- }
- 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 hwnd = parent.handle;
- 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;
- int hIMC = OS.ImmGetContext (hwnd);
- 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 hwnd = parent.handle;
- OS.DestroyCaret ();
- int hBitmap = image != null ? image.handle : 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 hwnd = parent.handle;
- int 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 hwnd = parent.handle;
- int hBitmap = 0;
- if (image != null) hBitmap = image.handle;
- 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 hFont = 0;
- if (font != null) hFont = font.handle;
- if (hFont == 0) hFont = defaultFont ();
- int hwnd = parent.handle;
- int 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 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 12099920ba..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java
+++ /dev/null
@@ -1,218 +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.*;
-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>
- */
-
-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.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.
- * </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, style);
- checkSubclass ();
-}
-
-int CCHookProc (int hdlg, int uiMsg, int lParam, int lpData) {
- switch (uiMsg) {
- case OS.WM_INITDIALOG:
- 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;
- }
- 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 hwndOwner = parent.handle;
-
- /* Create the CCHookProc */
- Callback callback = new Callback (this, "CCHookProc", 4); //$NON-NLS-1$
- int lpfnHook = callback.getAddress ();
- if (lpfnHook == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Allocate the Custom Colors */
- Display display = parent.display;
- if (display.lpCustColors == 0) {
- int 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;
- 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 */
- Shell oldModal = null;
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- oldModal = display.getModalDialogShell ();
- display.setModalDialogShell (parent);
- }
-
- /* Open the dialog */
- boolean success = OS.ChooseColor (lpcc);
-
- /* Clear the temporary dialog modal parent */
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- display.setModalDialogShell (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);
-
- /*
- * 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 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 3e44b737d2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java
+++ /dev/null
@@ -1,2289 +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.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 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</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
- */
-
-public class Combo extends Composite {
- boolean noSelection, ignoreModify, ignoreCharacter;
- int scrollWidth, 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 = 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 EditProc, ListProc;
-
- static final int 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 = 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 = 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 = 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 receiver's selection changes, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the combo's list selection changes.
- * <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 callWindowProc (int hwnd, int msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- if (hwnd == handle) {
- return OS.CallWindowProc (ComboProc, hwnd, msg, wParam, lParam);
- }
- int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwnd == hwndText) {
- return OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam);
- }
- int hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwnd == hwndList) {
- return OS.CallWindowProc (ListProc, hwnd, msg, wParam, lParam);
- }
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
-}
-
-boolean checkHandle (int 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 newFont, oldFont = 0;
- int hDC = OS.GetDC (handle);
- newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int count = 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 = 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 = 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 = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- int itemHeight = 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 hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) {
- int margins = OS.SendMessage (hwndText, OS.EM_GETMARGINS, 0, 0);
- int marginWidth = (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF);
- 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 = 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 () {
- super.createHandle ();
- state &= ~(CANVAS | THEME_BACKGROUND);
-
- /* Get the text and list window procs */
- int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0 && EditProc == 0) {
- EditProc = OS.GetWindowLong (hwndText, OS.GWL_WNDPROC);
- }
- int hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0 && ListProc == 0) {
- ListProc = OS.GetWindowLong (hwndList, OS.GWL_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 hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) display.removeControl (hwndText);
- int 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 = 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
-}
-
-/**
- * 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 = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, index, 0);
- if (length != OS.CB_ERR) {
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer);
- if (result != OS.CB_ERR) return buffer.toString (0, length);
- }
- int count = 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 = 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 = 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;
-}
-
-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) {
- 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 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 = 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 hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText == 0) return LIMIT;
- return OS.SendMessage (hwndText, OS.EM_GETLIMITTEXT, 0, 0);
-}
-
-/**
- * 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 hwndFocus = OS.GetFocus ();
- if (hwndFocus == handle) return true;
- if (hwndFocus == 0) return false;
- int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndFocus == hwndText) return true;
- int 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 = 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 = 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 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 hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) display.addControl (hwndText, this);
- int 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 ();
- TCHAR buffer = null;
- if ((style & SWT.H_SCROLL) != 0) {
- int length = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, index, 0);
- if (length == OS.CB_ERR) {
- int count = 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 = OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer);
- if (result == OS.CB_ERR) {
- int count = 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 = OS.SendMessage (handle, OS.CB_DELETESTRING, index, 0);
- if (code == OS.CB_ERR) {
- int count = 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 (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 = 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 = 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 hDC = 0, oldFont = 0, newFont = 0, 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 = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, start, 0);
- if (length == OS.CB_ERR) break;
- buffer = new TCHAR (cp, length + 1);
- int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, start, buffer);
- if (result == OS.CB_ERR) break;
- }
- int result = 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 = 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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 wParam, int 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 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 = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (0 <= index && index < count) {
- int selection = OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);
- int code = 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 hBitmap) {
- super.setBackgroundImage (hBitmap);
- int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) OS.InvalidateRect (hwndText, null, true);
- int hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0) OS.InvalidateRect (hwndList, null, true);
-}
-
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) OS.InvalidateRect (hwndText, null, true);
- int 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 hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) OS.InvalidateRect (hwndText, null, true);
- int 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. This is equivalent
- * to removing the old item at the index, and then adding the new
- * item at that index.
- *
- * @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 = OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);
- remove (index);
- if (isDisposed ()) return;
- add (string, index);
- if (selection != -1) {
- OS.SendMessage (handle, OS.CB_SETCURSEL, selection, 0);
- }
-}
-
-/**
- * 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 hDC = 0, oldFont = 0, newFont = 0, 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 = 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 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 newFont, oldFont = 0;
- int 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 = 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 = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, i, 0);
- if (length != OS.CB_ERR) {
- TCHAR buffer = new TCHAR (cp, length + 1);
- int result = 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 = 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 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;
- }
- 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);
- }
-}
-
-void setScrollWidth (TCHAR buffer, boolean grow) {
- RECT rect = new RECT ();
- int newFont, oldFont = 0;
- int 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 bits = start | (end << 16);
- OS.SendMessage (handle, OS.CB_SETEDITSEL, 0, bits);
-}
-
-/**
- * Sets the contents of the receiver's text field to the
- * given string.
- * <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;
- }
- 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 hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- int 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 newProc = display.windowProc;
- int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) {
- OS.SetWindowLong (hwndText, OS.GWL_WNDPROC, newProc);
- }
- int hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0) {
- OS.SetWindowLong (hwndList, OS.GWL_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 (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 ();
-}
-
-void unsubclass () {
- super.unsubclass ();
- int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0 && EditProc != 0) {
- OS.SetWindowLong (hwndText, OS.GWL_WNDPROC, EditProc);
- }
- int hwndList = OS.GetDlgItem (handle, CBID_LIST);
- if (hwndList != 0 && ListProc != 0) {
- OS.SetWindowLong (hwndList, OS.GWL_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 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 windowProc () {
- return ComboProc;
-}
-
-int windowProc (int hwnd, int msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- if (hwnd != handle) {
- int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- int 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 (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 wParam, int lParam) {
- return wmColorChild (wParam, lParam);
-}
-
-LRESULT WM_GETDLGCODE (int wParam, int lParam) {
- int code = callWindowProc (handle, OS.WM_GETDLGCODE, wParam, lParam);
- return new LRESULT (code | OS.DLGC_WANTARROWS);
-}
-
-LRESULT WM_KILLFOCUS (int wParam, int 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 wParam, int 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 = 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 = 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 wParam, int lParam) {
- /*
- * Return NULL - Focus notification is
- * done by WM_COMMAND with CBN_SETFOCUS.
- */
- return null;
-}
-
-LRESULT WM_SIZE (int wParam, int lParam) {
- /*
- * 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 hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0) OS.InvalidateRect (hwndText, null, true);
- int 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 remember the original
- * text and reset it after the widget is resized.
- */
- LRESULT result = null;
- if ((style & SWT.READ_ONLY) != 0) {
- result = super.WM_SIZE (wParam, lParam);
- } else {
- int index = OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);
- boolean redraw = false;
- TCHAR buffer = null;
- int [] start = null, end = null;
- if (index == OS.CB_ERR) {
- int length = OS.GetWindowTextLength (handle);
- if (length != 0) {
- buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (handle, buffer, length + 1);
- start = new int [1]; end = new int [1];
- OS.SendMessage (handle, OS.CB_GETEDITSEL, start, end);
- redraw = drawCount == 0 && OS.IsWindowVisible (handle);
- if (redraw) setRedraw (false);
- }
- }
- 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 (buffer != null) {
- OS.SetWindowText (handle, buffer);
- int bits = start [0] | (end [0] << 16);
- OS.SendMessage (handle, OS.CB_SETEDITSEL, 0, bits);
- if (redraw) setRedraw (true);
- }
- }
- /*
- * 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 wmChar (int hwnd, int wParam, int 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 (wParam) {
- case SWT.TAB: return LRESULT.ZERO;
- case SWT.CR:
- postEvent (SWT.DefaultSelection);
- // 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 hwndText, int msg, int wParam, int 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 oldText = null, 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.SendMessage (hwndText, OS.EM_GETSEL, start, end);
- 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);
- ignoreModify = false;
- }
- break;
- case OS.WM_SETTEXT:
- end [0] = OS.GetWindowTextLength (hwndText);
- oldText = getText ();
- 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 && !newText.equals (oldText)) {
- 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 hHeap = OS.GetProcessHeap ();
- int byteCount = buffer.length () * TCHAR.sizeof;
- int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- int 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 wParam, int lParam) {
- int code = wParam >> 16;
- 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 = 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 hwnd, int wParam, int lParam) {
-
- /* Process a DBCS character */
- Display display = this.display;
- display.lastKey = 0;
- display.lastAscii = 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 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 wmSysKeyDown (int hwnd, int wParam, int 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 = 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 code = callWindowProc (hwnd, OS.WM_SYSKEYDOWN, wParam, lParam);
- int newSelection = 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 db9a286ce4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java
+++ /dev/null
@@ -1,1485 +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.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. The <code>EMBEDDED</code> style
- * is for use by other widget toolkits and should normally never be used.
- * </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
- */
-
-public class Composite extends Scrollable {
- Layout layout;
- int font;
- 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 Widget#getStyle
- */
-public Composite (Composite parent, int style) {
- super (parent, style);
-}
-
-Control [] _getChildren () {
- int count = 0;
- int 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 ();
- }
-}
-
-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 () {
- super.createHandle ();
- state |= CANVAS;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- state |= THEME_BACKGROUND;
- }
-}
-
-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 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>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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>
- *
- * @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>
- *
- * @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.
- *
- * @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 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;
- 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 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 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);
- sendEvent (SWT.Resize);
- 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 ();
- }
-}
-
-boolean setFixedFocus () {
- checkWidget ();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.setRadioFocus ()) 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 ()) 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 {
- 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 ()) return true;
- }
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.isTabItem () && child.setTabItemFocus ()) return true;
- }
- return false;
-}
-
-String toolTipText (NMTTDISPINFO hdr) {
- if ((hdr.uFlags & OS.TTF_IDISHWND) == 0) {
- String string = null;
- Shell shell = getShell ();
- ToolTip toolTip = shell.findToolTip (hdr.idFrom);
- if (toolTip != null) {
- string = toolTip.message;
- if (string == null || string.length () == 0) string = " ";
- }
- return string;
- }
- int hwnd = hdr.idFrom;
- if (hwnd == 0) return null;
- Control control = display.getControl (hwnd);
- OS.SendMessage (hdr.hwndFrom, OS.TTM_SETTITLE, 0, 0);
- OS.SendMessage (hdr.hwndFrom, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
- 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 && (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);
- 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);
- }
- }
-}
-
-int widgetStyle () {
- /* Force clipping of children by setting WS_CLIPCHILDREN */
- return super.widgetStyle () | OS.WS_CLIPCHILDREN;
-}
-
-LRESULT WM_ERASEBKGND (int wParam, int 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) != 0) return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT WM_GETDLGCODE (int wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_GETFONT (wParam, lParam);
- if (result != null) return result;
- int 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_LBUTTONDOWN (int wParam, int 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_NCPAINT (int wParam, int lParam) {
- LRESULT result = super.WM_NCPAINT (wParam, lParam);
- if (result != null) return result;
- if ((state & CANVAS) != 0) {
- result = wmNCPaint (handle, wParam, lParam);
- }
- return result;
-}
-
-LRESULT WM_NOTIFY (int wParam, int lParam) {
- if (!OS.IsWinCE) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- 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 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 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);
- int length = string.length ();
- char [] chars = new char [length + 1];
- string.getChars (0, length, chars, 0);
-
- /*
- * Ensure that the orientation of the tool tip matches
- * the orientation of the control.
- */
- int hwnd = hdr.idFrom;
- if (hwnd != 0 && ((lpnmtdi.uFlags & OS.TTF_IDISHWND) != 0)) {
- Control control = display.getControl (hwnd);
- if (control != null) {
- if ((control.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 (OS.CP_ACP, 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.WM_NOTIFY (wParam, lParam);
-}
-
-LRESULT WM_PARENTNOTIFY (int wParam, int lParam) {
- if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) {
- if ((wParam & 0xFFFF) == 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 wParam, int lParam) {
- if ((state & CANVAS) == 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)) {
-
- /* 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 sysRgn = 0;
- if ((style & (SWT.NO_MERGE_PAINTS | SWT.DOUBLE_BUFFERED)) != 0) {
- sysRgn = OS.CreateRectRgn (0, 0, 0, 0);
- if (OS.GetRandomRgn (gc.handle, sysRgn, OS.SYSRGN) == 1) {
- if (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 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) != 0) {
- image = new Image (display, width, height);
- paintGC = gc;
- gc = new GC (image, paintGC.getStyle () & SWT.RIGHT_TO_LEFT);
- gc.setForeground (getForeground ());
- gc.setBackground (getBackground ());
- gc.setFont (getFont ());
- 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) != 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)) == 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)) == 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) != 0) {
- gc.dispose();
- if (!isDisposed ()) {
- paintGC.drawImage (image, ps.left, ps.top);
- }
- image.dispose ();
- gc = paintGC;
- }
- }
-
- /* Dispose the paint GC */
- gc.dispose ();
- if (sysRgn != 0) OS.DeleteObject (sysRgn);
- } else {
- int hDC = OS.BeginPaint (handle, ps);
- if ((style & SWT.NO_BACKGROUND) == 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 wParam, int 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) == 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.hFont = OS.SendMessage (handle, OS.WM_GETFONT, 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 wParam, int lParam) {
- if (lParam != 0) OS.InvalidateRect (handle, null, true);
- return super.WM_SETFONT (font = wParam, lParam);
-}
-
-LRESULT WM_SIZE (int wParam, int lParam) {
-
- /* Begin deferred window positioning */
- setResizeChildren (false);
-
- /* Resize and Layout */
- 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;
- 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), lParam & 0xFFFF, lParam >> 16);
- }
- return result;
-}
-
-LRESULT WM_SYSCOLORCHANGE (int wParam, int lParam) {
- LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
- if (result != null) return result;
- int 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 wParam, int 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.
- */
- 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 = 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 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 wmNCPaint (int hwnd, int wParam, int lParam) {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- int bits = OS.GetWindowLong (hwnd, OS.GWL_EXSTYLE);
- if ((bits & OS.WS_EX_CLIENTEDGE) != 0) {
- int code = callWindowProc (hwnd, OS.WM_NCPAINT, wParam, lParam);
- int 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);
- int hTheme = OS.OpenThemeData (hwnd, EDIT);
- OS.DrawThemeBackground (hTheme, hDC, OS.EP_EDITTEXT, OS.ETS_NORMAL, rect, null);
- OS.CloseThemeData (hwnd);
- OS.ReleaseDC (hwnd, hDC);
- return new LRESULT (code);
- }
- }
- return null;
-}
-
-}
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 1352b780b5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
+++ /dev/null
@@ -1,4148 +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.widgets;
-
-
-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>FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse,
- * DragDetect, MenuDetect</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>
- */
-
-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;
- Cursor cursor;
- Menu menu;
- String toolTipText;
- Object layoutData;
- Accessible accessible;
- Image backgroundImage;
- 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 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 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.
- *
- * @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 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 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 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;
-}
-
-boolean checkHandle (int 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);
-}
-
-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 createHandle () {
- int 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.SetWindowLong (handle, OS.GWL_ID, handle);
- }
- if (OS.IsDBLocale && hwndParent != 0) {
- int hIMC = OS.ImmGetContext (hwndParent);
- OS.ImmAssociateContext (handle, hIMC);
- OS.ImmReleaseContext (hwndParent, hIMC);
- }
-}
-
-void createWidget () {
- foreground = background = -1;
- checkOrientation (parent);
- createHandle ();
- checkBackground ();
- checkBuffered ();
- 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 defaultFont () {
- return display.getSystemFont ().handle;
-}
-
-int defaultForeground () {
- return OS.GetSysColor (OS.COLOR_WINDOWTEXT);
-}
-
-void deregister () {
- display.removeControl (handle);
-}
-
-void destroyWidget () {
- int hwnd = topHandle ();
- releaseHandle ();
- if (hwnd != 0) {
- OS.DestroyWindow (hwnd);
- }
-}
-
-void drawBackground (int hDC) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- drawBackground (hDC, rect);
-}
-
-void drawBackground (int hDC, RECT rect) {
- drawBackground (hDC, rect, -1);
-}
-
-void drawBackground (int 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 hDC, int hwnd, int hBitmap, RECT rect) {
- RECT rect2 = new RECT ();
- OS.GetClientRect (hwnd, rect2);
- OS.MapWindowPoints (hwnd, handle, rect2, 2);
- int 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 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 hDC, int hwnd, RECT rect) {
- /* Do nothing */
-}
-
-void enableWidget (boolean enabled) {
- OS.EnableWindow (handle, enabled);
-}
-
-void fillBackground (int hDC, int pixel, RECT rect) {
- if (rect.left > rect.right || rect.top > rect.bottom) return;
- int 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 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 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 findBrush (int 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.
- *
- * @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 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 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 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 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 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 <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 ();
- int 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 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
- *
- * @since 3.0
- */
-public Monitor getMonitor () {
- checkWidget ();
- if (OS.IsWinCE || OS.WIN32_VERSION < OS.VERSION (4, 10)) {
- return display.getPrimaryMonitor ();
- }
- int 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 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 (drawCount != 0) 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 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 internal_new_GC (GCData data) {
- checkWidget();
- int hwnd = handle;
- if (data != null && data.hwnd != 0) hwnd = data.hwnd;
- if (data != null) data.hwnd = hwnd;
- int 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;
- data.foreground = getForegroundPixel ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- data.background = control.getBackgroundPixel ();
- data.hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 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 hDC, GCData data) {
- checkWidget ();
- int 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 () {
- 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 ();
- if (this == display.focusControl) return true;
- return hasFocus ();
-}
-
-boolean isFocusAncestor (Control control) {
- while (control != null && control != this) {
- 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 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 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 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 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 topHandle = topHandle (), hwndAbove = OS.HWND_TOP;
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- int 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 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 ();
- }
- 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));
-}
-
-/**
- * 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
- */
-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
- */
-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 ();
- }
- menu = null;
- cursor = null;
- deregister ();
- unsubclass ();
- layoutData = null;
- if (accessible != null) {
- accessible.internal_dispose_Accessible ();
- }
- accessible = 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 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 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 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) {
- 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 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.
- *
- * @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.
- *
- * @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 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) {
- int topHandle = topHandle ();
- if (defer && parent != null) {
- forceResize ();
- if (OS.GetWindow (handle, OS.GW_CHILD) == 0) {
- if (findImageControl () != null) {
- flags |= OS.SWP_NOCOPYBITS;
- } else {
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- if (findThemeControl () != null) flags |= OS.SWP_NOCOPYBITS;
- }
- }
- }
- WINDOWPOS [] lpwp = parent.lpwp;
- if (lpwp == null) {
- SetWindowPos (topHandle, 0, x, y, width, height, flags);
- } else {
- int index = 0;
- 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;
- }
- } else {
- 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.
- *
- * @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 lParam = OS.HTCLIENT | (OS.WM_MOUSEMOVE << 16);
- 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 hCursor = cursor != null ? cursor.handle : 0;
- OS.SetCursor (hCursor);
- return;
- }
- int hwndCursor = OS.GetCapture ();
- if (hwndCursor == 0) {
- POINT pt = new POINT ();
- if (!OS.GetCursorPos (pt)) return;
- int 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 hFont = display.getSystemFont ().handle;
- OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
-}
-
-/**
- * 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 hFont = 0;
- if (font != null) {
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- hFont = font.handle;
- }
- 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.
- *
- * @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 () {
- 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) {
- 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);
- }
- }
-}
-
-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 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 no tool tip text should be shown.
- *
- * @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 (drawCount != 0) {
- 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 (drawCount != 0) {
- 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 oldProc = windowProc ();
- int newProc = display.windowProc;
- if (oldProc == newProc) return;
- OS.SetWindowLong (handle, OS.GWL_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 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 hwnd = msg.hwnd;
- if (OS.GetKeyState (OS.VK_MENU) >= 0) {
- int 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 = 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 hwnd = msg.hwnd;
- int key = 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 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 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 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;
- }
- }
- if (parent != null && (parent.style & SWT.MIRRORED) != 0) {
- if (key == OS.VK_LEFT || key == OS.VK_RIGHT) next = !next;
- }
- 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 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;
- 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 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 ();
- 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) {
- 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 newProc = windowProc ();
- int oldProc = display.windowProc;
- if (oldProc == newProc) return;
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, newProc);
-}
-
-/**
- * Forces all outstanding paint requests for the widget
- * to be processed before this method returns.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 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 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 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 windowProc ();
-
-int windowProc (int hwnd, int msg, int wParam, int 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_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_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 wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_CAPTURECHANGED (int wParam, int lParam) {
- return wmCaptureChanged (handle, wParam, lParam);
-}
-
-LRESULT WM_CHAR (int wParam, int lParam) {
- return wmChar (handle, wParam, lParam);
-}
-
-LRESULT WM_CLEAR (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_CLOSE (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_COMMAND (int wParam, int 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 = wParam & 0xFFFF;
- 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 wParam, int lParam) {
- return wmContextMenu (handle, wParam, lParam);
-}
-
-LRESULT WM_CTLCOLOR (int wParam, int lParam) {
- int 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 wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_DESTROY (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_DRAWITEM (int wParam, int 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 wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_ENTERIDLE (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_ERASEBKGND (int wParam, int 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 wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_GETFONT (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_GETOBJECT (int wParam, int lParam) {
- if (accessible != null) {
- int result = accessible.internal_WM_GETOBJECT (wParam, lParam);
- if (result != 0) return new LRESULT (result);
- }
- return null;
-}
-
-LRESULT WM_GETMINMAXINFO (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_HOTKEY (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_HELP (int wParam, int 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 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 wParam, int lParam) {
- if (lParam == 0) return null;
- Control control = display.getControl (lParam);
- if (control == null) return null;
- return control.wmScrollChild (wParam, lParam);
-}
-
-LRESULT WM_IME_CHAR (int wParam, int lParam) {
- return wmIMEChar (handle, wParam, lParam);
-}
-
-LRESULT WM_IME_COMPOSITION (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_INITMENUPOPUP (int wParam, int 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 ((lParam >> 16) == 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 wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_KEYDOWN (int wParam, int lParam) {
- return wmKeyDown (handle, wParam, lParam);
-}
-
-LRESULT WM_KEYUP (int wParam, int lParam) {
- return wmKeyUp (handle, wParam, lParam);
-}
-
-LRESULT WM_KILLFOCUS (int wParam, int lParam) {
- return wmKillFocus (handle, wParam, lParam);
-}
-
-LRESULT WM_LBUTTONDBLCLK (int wParam, int lParam) {
- return wmLButtonDblClk (handle, wParam, lParam);
-}
-
-LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
- return wmLButtonDown (handle, wParam, lParam);
-}
-
-LRESULT WM_LBUTTONUP (int wParam, int lParam) {
- return wmLButtonUp (handle, wParam, lParam);
-}
-
-LRESULT WM_MBUTTONDBLCLK (int wParam, int lParam) {
- return wmMButtonDblClk (handle, wParam, lParam);
-}
-
-LRESULT WM_MBUTTONDOWN (int wParam, int lParam) {
- return wmMButtonDown (handle, wParam, lParam);
-}
-
-LRESULT WM_MBUTTONUP (int wParam, int lParam) {
- return wmMButtonUp (handle, wParam, lParam);
-}
-
-LRESULT WM_MEASUREITEM (int wParam, int 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 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 wParam, int 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 = wParam >> 16;
- if (type == 0 || type == OS.MF_SYSMENU) {
- display.mnemonicKeyHit = false;
- return new LRESULT (OS.MNC_CLOSE << 16);
- }
- return null;
-}
-
-LRESULT WM_MENUSELECT (int wParam, int lParam) {
- int code = wParam >> 16;
- Shell shell = getShell ();
- if (code == -1 && 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 = wParam & 0xFFFF;
- 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 = wParam & 0xFFFF;
- 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 ();
- }
- /*
- * 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 wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_MOUSEHOVER (int wParam, int lParam) {
- return wmMouseHover (handle, wParam, lParam);
-}
-
-LRESULT WM_MOUSELEAVE (int wParam, int lParam) {
- return wmMouseLeave (handle, wParam, lParam);
-}
-
-LRESULT WM_MOUSEMOVE (int wParam, int lParam) {
- return wmMouseMove (handle, wParam, lParam);
-}
-
-LRESULT WM_MOUSEWHEEL (int wParam, int lParam) {
- return wmMouseWheel (handle, wParam, lParam);
-}
-
-LRESULT WM_MOVE (int wParam, int lParam) {
- 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 ();
- }
- }
- }
- }
- sendEvent (SWT.Move);
- // widget could be disposed at this point
- return null;
-}
-
-LRESULT WM_NCACTIVATE (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_NCCALCSIZE (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_NCHITTEST (int wParam, int lParam) {
- if (!OS.IsWindowEnabled (handle)) return null;
- if (!isActive ()) return new LRESULT (OS.HTTRANSPARENT);
- return null;
-}
-
-LRESULT WM_NCLBUTTONDOWN (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_NCPAINT (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_NOTIFY (int wParam, int lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- int hwnd = hdr.hwndFrom;
- if (hwnd == 0) return null;
- Control control = display.getControl (hwnd);
- if (control == null) return null;
- return control.wmNotifyChild (wParam, lParam);
-}
-
-LRESULT WM_PAINT (int wParam, int lParam) {
- return super.wmPaint (handle, wParam, lParam);
-}
-
-LRESULT WM_PALETTECHANGED (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_PARENTNOTIFY (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_PASTE (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_PRINT (int wParam, int lParam) {
- return wmPrint (handle, wParam, lParam);
-}
-
-LRESULT WM_PRINTCLIENT (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_QUERYENDSESSION (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_QUERYNEWPALETTE (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_QUERYOPEN (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_RBUTTONDBLCLK (int wParam, int lParam) {
- return wmRButtonDblClk (handle, wParam, lParam);
-}
-
-LRESULT WM_RBUTTONDOWN (int wParam, int lParam) {
- return wmRButtonDown (handle, wParam, lParam);
-}
-
-LRESULT WM_RBUTTONUP (int wParam, int lParam) {
- return wmRButtonUp (handle, wParam, lParam);
-}
-
-LRESULT WM_SETCURSOR (int wParam, int lParam) {
- int hitTest = (short) (lParam & 0xFFFF);
- 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 wParam, int lParam) {
- return wmSetFocus (handle, wParam, lParam);
-}
-
-LRESULT WM_SETTINGCHANGE (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_SETFONT (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_SETREDRAW (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_SHOWWINDOW (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_SIZE (int wParam, int lParam) {
- sendEvent (SWT.Resize);
- // widget could be disposed at this point
- return null;
-}
-
-LRESULT WM_SYSCHAR (int wParam, int lParam) {
- return wmSysChar (handle, wParam, lParam);
-}
-
-LRESULT WM_SYSCOLORCHANGE (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_SYSCOMMAND (int wParam, int 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.
- */
- if ((wParam & 0xF000) == 0) {
- Decorations shell = menuShell ();
- if (shell.isEnabled ()) {
- MenuItem item = display.getMenuItem (wParam & 0xFFFF);
- if (item != null) item.wmCommandChild (wParam, lParam);
- }
- return LRESULT.ZERO;
- }
-
- /* Process the System Command */
- int cmd = wParam & 0xFFF0;
- switch (cmd) {
- case OS.SC_CLOSE:
- int 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 (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 wParam, int lParam) {
- return wmSysKeyDown (handle, wParam, lParam);
-}
-
-LRESULT WM_SYSKEYUP (int wParam, int lParam) {
- return wmSysKeyUp (handle, wParam, lParam);
-}
-
-LRESULT WM_TIMER (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_UNDO (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_UPDATEUISTATE (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_VSCROLL (int wParam, int lParam) {
- if (lParam == 0) return null;
- Control control = display.getControl (lParam);
- if (control == null) return null;
- return control.wmScrollChild (wParam, lParam);
-}
-
-LRESULT WM_WINDOWPOSCHANGED (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int wParam, int 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 (drawCount != 0) {
- 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 hwndParent = parent == null ? 0 : parent.handle;
- OS.MapWindowPoints (0, hwndParent, rect, 2);
- OS.InvalidateRect (hwndParent, rect, true);
- }
- }
- }
- return null;
-}
-
-LRESULT WM_XBUTTONDBLCLK (int wParam, int lParam) {
- return wmXButtonDblClk (handle, wParam, lParam);
-}
-
-LRESULT WM_XBUTTONDOWN (int wParam, int lParam) {
- return wmXButtonDown (handle, wParam, lParam);
-}
-
-LRESULT WM_XBUTTONUP (int wParam, int lParam) {
- return wmXButtonUp (handle, wParam, lParam);
-}
-
-LRESULT wmColorChild (int wParam, int 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 hwnd = control.handle;
- int 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 hBrush = findBrush (hBitmap, OS.BS_PATTERN);
- if ((state & DRAW_BACKGROUND) != 0) {
- int 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 hBrush = findBrush (backPixel, OS.BS_SOLID);
- if ((state & DRAW_BACKGROUND) != 0) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int 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 wParam, int lParam) {
- return null;
-}
-
-LRESULT wmDrawChild (int wParam, int lParam) {
- return null;
-}
-
-LRESULT wmMeasureChild (int wParam, int lParam) {
- return null;
-}
-
-LRESULT wmNotifyChild (int wParam, int lParam) {
- return null;
-}
-
-LRESULT wmScrollChild (int wParam, int 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 0c520df6a7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java
+++ /dev/null
@@ -1,1189 +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.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>
- */
-
-public class CoolBar extends Composite {
- CoolItem [] items;
- CoolItem [] originalItems;
- boolean locked;
- boolean ignoreResize;
- static final int 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 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 callWindowProc (int hwnd, int msg, int wParam, int 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 = 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 = drawCount == 0;
- 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 hFont = OS.GetStockObject (OS.SYSTEM_FONT);
- OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
-}
-
-void createItem (CoolItem item, int index) {
- int count = 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 hHeap = OS.GetProcessHeap ();
- int 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 = OS.SendMessage (handle, OS.RB_IDTOINDEX, item.id, 0);
- int count = 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 tof 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 hDC, int 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 = 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 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 = 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 = 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 = 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 = 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 = 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 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 = 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 (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, OS.SendMessage (handle, OS.RB_GETBKCOLOR, 0, 0));
-}
-
-void setItemColors (int foreColor, int backColor) {
- int count = 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 = 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 = 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 = 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 = 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 windowProc () {
- return ReBarProc;
-}
-
-LRESULT WM_COMMAND (int wParam, int 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 wParam, int 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 wParam, int 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 wParam, int 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 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 wParam, int lParam) {
- if (ignoreResize) {
- int 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 (int wParam, int lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- switch (hdr.code) {
- case OS.RBN_BEGINDRAG: {
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT ();
- pt.x = (short) (pos & 0xFFFF);
- pt.y = (short) (pos >> 16);
- OS.ScreenToClient (handle, pt);
- if (!sendDragEvent (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 = 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 (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 fe507af287..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java
+++ /dev/null
@@ -1,714 +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.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>
- */
-
-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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 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 hwnd = parent.handle;
- int 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 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 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 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 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 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 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 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 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 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java
deleted file mode 100755
index 7c8d1d2480..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java
+++ /dev/null
@@ -1,1759 +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.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
- */
-
-public class Decorations extends Canvas {
- Image image, smallImage, largeImage;
- Image [] images;
- Menu menuBar;
- Menu [] menus;
- Control savedFocus;
- Button defaultButton, saveDefault;
- int swFlags, hAccel, nAccel;
- 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 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 checkOpened () {
- if (!opened) resized = false;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int callWindowProc (int hwnd, int msg, int wParam, int 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;
-}
-
-Control 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)) {
- 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 ();
- }
-}
-
-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 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
- */
-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) {
- 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 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 ();
- 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 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);
- }
-}
-
-/**
- * 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 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 ();
- 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 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 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.SetWindowLong (handle, OS.GWL_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 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);
- OS.SetWindowText (handle, buffer);
-}
-
-public void setVisible (boolean visible) {
- checkWidget ();
- if (drawCount != 0) {
- 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 hwndCB = menuBar.hwndCB;
- OS.CommandBar_DrawMenuBar (hwndCB, 0);
- }
- }
- if (drawCount != 0) {
- state &= ~HIDDEN;
- } else {
- if (OS.IsWinCE) {
- OS.ShowWindow (handle, OS.SW_SHOW);
- } else {
- if (menuBar != null) {
- display.removeBar (menuBar);
- OS.DrawMenuBar (handle);
- }
- 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;
- }
- 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 {
- if (handle == OS.GetActiveWindow ()) {
- swFlags = OS.SW_RESTORE;
- } else {
- swFlags = OS.SW_SHOWNOACTIVATE;
- }
- }
- }
- }
- if (drawCount != 0) {
- 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 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 (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 (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 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 windowProc (int hwnd, int msg, int wParam, int 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 wParam, int 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 ((wParam & 0xFFFF) != 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 ((wParam >> 16) != 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 wParam, int lParam) {
- LRESULT result = super.WM_CLOSE (wParam, lParam);
- if (result != null) return result;
- if (isEnabled () && isActive ()) closeWidget ();
- return LRESULT.ZERO;
-}
-
-LRESULT WM_HOTKEY (int wParam, int 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 (((lParam >> 16) & 0xFFFF) == 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 wParam, int lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- saveFocus ();
- return result;
-}
-
-LRESULT WM_MOVE (int wParam, int 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 wParam, int 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 hwndShell = getShell().handle;
- OS.SendMessage (hwndShell, OS.WM_NCACTIVATE, wParam, lParam);
- }
- return result;
-}
-
-LRESULT WM_QUERYOPEN (int wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if (savedFocus != this) restoreFocus ();
- return result;
-}
-
-LRESULT WM_SIZE (int wParam, int lParam) {
- LRESULT result = null;
- boolean changed = true;
- if (resized) {
- int newWidth = 0, newHeight = 0;
- switch (wParam) {
- case OS.SIZE_RESTORED:
- case OS.SIZE_MAXIMIZED:
- newWidth = lParam & 0xFFFF;
- newHeight = lParam >> 16;
- 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 wParam, int lParam) {
- LRESULT result = super.WM_SYSCOMMAND (wParam, lParam);
- if (result != null) return result;
- if (!(this instanceof Shell)) {
- int cmd = 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 wParam, int 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 14ab6bcb7b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DirectoryDialog.java
+++ /dev/null
@@ -1,305 +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.*;
-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>
- */
-
-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.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.
- * </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, style);
- checkSubclass ();
-}
-
-int BrowseCallbackProc (int hwnd, int uMsg, int lParam, int lpData) {
- switch (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 hHeap = OS.GetProcessHeap ();
-
- /* Get the owner HWND for the dialog */
- int hwndOwner = 0;
- if (parent != null) hwndOwner = parent.handle;
-
- /* Copy the message to OS memory */
- int 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 address = callback.getAddress ();
- if (address == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Make the parent shell be temporary modal */
- Shell oldModal = null;
- Display display = parent.getDisplay ();
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- oldModal = display.getModalDialogShell ();
- display.setModalDialogShell (parent);
- }
-
- 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 = address;
- /*
- * 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 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.setModalDialogShell (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 [] ppMalloc = new int [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 985921dfdc..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
+++ /dev/null
@@ -1,4076 +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.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</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
- */
-
-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 windowProc, threadId;
- TCHAR windowClass, windowShadowClass;
- static int WindowClassCount;
- static final String WindowName = "SWT_Window"; //$NON-NLS-1$
- static final String WindowShadowName = "SWT_WindowShadow"; //$NON-NLS-1$
- EventTable eventTable, filterTable;
-
- /* Widget Table */
- int freeSlot;
- int [] indexTable;
- 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;
- }
- }
-
- /* 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 msgFilterProc, filterHook;
- MSG hookMsg = new MSG ();
-
- /* Idle Hook */
- Callback foregroundIdleCallback;
- int foregroundIdleProc, idleHook;
-
- /* Message Hook and Embedding */
- boolean ignoreNextKey;
- Callback getMsgCallback, embeddedCallback;
- int getMsgProc, msgHook, embeddedHwnd, embeddedProc;
- static final String AWT_WINDOW_CLASS = "SunAwtWindow";
- static final short [] ACCENTS = new short [] {'~', '`', '\'', '^', '"'};
-
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer = new Synchronizer (this);
- boolean runMessages = true, runMessagesInIdle = false;
- static final String RUN_MESSAGES_IN_IDLE_KEY = "org.eclipse.swt.internal.win32.runMessagesInIdle"; //$NON-NLS-1$
- Thread thread;
-
- /* Display Shutdown */
- Runnable [] disposeList;
-
- /* System Tray */
- Tray tray;
- int nextTrayId;
-
- /* Timers */
- int [] timerIds;
- Runnable [] timerList;
- int nextTimerId = SETTINGS_ID + 1;
- static final int SETTINGS_ID = 100;
- static final int SETTINGS_DELAY = 2000;
-
- /* Keyboard and Mouse */
- RECT clickRect;
- int clickCount, lastTime, lastButton, lastHwnd;
- int lastKey, lastAscii, lastMouse;
- boolean lastVirtual, lastNull, lastDead;
- byte [] keyboard = new byte [256];
- boolean accelKeyHit, mnemonicKeyHit;
- boolean lockActiveWindow, captureChanged;
-
- /* Tool Tips */
- int nextToolTipId;
-
- /* MDI */
- boolean ignoreRestoreFocus;
- Control lastHittestControl;
- int lastHittest;
-
- /* Message Only Window */
- Callback messageCallback;
- int 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 lpCustColors;
-
- /* Sort Indicators */
- Image upArrow, downArrow;
-
- /* 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 */
- static Monitor[] monitors = null;
- static int monitorCount = 0;
-
- /* Modality */
- Shell [] modalShells;
- Shell modalDialogShell;
- 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 int SWT_TASKBARCREATED;
-
- /* 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 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.SetWindowLong (handle, OS.GWL_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) {
- 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 ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-static synchronized void checkDisplay (Thread thread, boolean multiple) {
- 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 ();
-}
-
-int controlKey (int key) {
- int upper = 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 create32bitDIB (int 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 hDC = OS.GetDC (0);
- int srcHdc = OS.CreateCompatibleDC (hDC);
- int oldSrcBitmap = OS.SelectObject (srcHdc, hBitmap);
- int 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 [] pBits = new int [1];
- int memDib = OS.CreateDIBSection (0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- if (memDib == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- int 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 hMask, hBitmap;
- int hDC = device.internal_new_GC (null);
- int 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 srcHdc = OS.CreateCompatibleDC (hDC);
- int 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 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 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 hMask = OS.CreateBitmap (srcWidth, srcHeight, 1, 1, mask.data);
- if (srcWidth != destWidth || srcHeight != destHeight) {
- int hdc = OS.GetDC (0);
- int hdc1 = OS.CreateCompatibleDC (hdc);
- OS.SelectObject (hdc1, hMask);
- int hdc2 = OS.CreateCompatibleDC (hdc);
- int 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 synchronized void deregister (Display display) {
- 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 embeddedProc (int hwnd, int msg, int wParam, int lParam) {
- switch (msg) {
- case SWT_KEYMSG: {
- MSG keyMsg = new MSG ();
- OS.MoveMemory (keyMsg, lParam, MSG.sizeof);
- OS.TranslateMessage (keyMsg);
- OS.DispatchMessage (keyMsg);
- int 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, 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 handle) {
- if (handle == 0) return null;
- int 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 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 handle, int id) {
- Control control = getControl (handle);
- return control != null ? control.findItem (id) : null;
-}
-
-int foregroundIdleProc (int code, int wParam, int lParam) {
- if (runMessages) {
- if (code >= 0) {
- if (getMessageCount () != 0) {
- if (runMessagesInIdle) runAsyncMessages (false);
- wakeThread ();
- }
- }
- }
- return OS.CallNextHookEx (idleHook, 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 synchronized Display findDisplay (Thread thread) {
- 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.
- *
- * @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 synchronized Display getCurrent () {
- return findDisplay (Thread.currentThread ());
-}
-
-int getClickCount (int type, int button, int hwnd, int lParam) {
- switch (type) {
- case SWT.MouseDown:
- case SWT.MouseDoubleClick:
- int eventTime = OS.GetMessageTime ();
- int doubleClick = OS.GetDoubleClickTime ();
- if (clickRect == null) clickRect = new RECT ();
- POINT pt = new POINT ();
- pt.x = (short) (lParam & 0xFFFF);
- pt.y = (short) (lParam >> 16);
- int deltaTime = Math.abs (lastTime - eventTime);
- if (lastHwnd == hwnd && lastButton == button && (deltaTime <= doubleClick) && OS.PtInRect (clickRect, pt)) {
- clickCount++;
- } else {
- clickCount = 0;
- }
- lastHwnd = hwnd;
- lastButton = button;
- lastTime = eventTime;
- int xInset = OS.GetSystemMetrics (OS.SM_CXDOUBLECLK) / 2;
- int yInset = OS.GetSystemMetrics (OS.SM_CYDOUBLECLK) / 2;
- OS.SetRect (clickRect, pt.x - xInset, pt.y - yInset, pt.x + xInset, pt.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 handle) {
- if (handle == 0) return null;
- int index;
- if (USE_PROPERTY) {
- index = OS.GetProp (handle, SWT_OBJECT_INDEX) - 1;
- } else {
- index = OS.GetWindowLong (handle, OS.GWL_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)) {
- 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 synchronized Display getDefault () {
- 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 ();
- 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 [] 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 = {128};
-
- /* Use the character encoding for the default locale */
- TCHAR lpData = new TCHAR (0, lpcbData [0]);
- TCHAR buffer2 = new TCHAR (0, "Shell Icon BPP", true); //$NON-NLS-1$
-
- 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;
-}
-
-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 ();
- 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 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 getMsgProc (int code, int wParam, int lParam) {
- if (embeddedHwnd == 0) {
- int 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.SetWindowLong (embeddedHwnd, OS.GWL_WNDPROC, embeddedProc);
- }
- if (code >= 0 && wParam != OS.PM_NOREMOVE) {
- 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 hHeap = OS.GetProcessHeap ();
- int keyMsg = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, MSG.sizeof);
- OS.MoveMemory (keyMsg, msg, MSG.sizeof);
- OS.PostMessage (hwndMessage, SWT_KEYMSG, wParam, keyMsg);
- msg.message = OS.WM_NULL;
- OS.MoveMemory (lParam, msg, MSG.sizeof);
- }
- }
- }
- }
- return OS.CallNextHookEx (msgHook, 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 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;
-}
-
-/**
- * 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 () {
- 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 = 0x02000000;
- 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 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 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 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 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 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 () {
- 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);
- int 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.hFont = getSystemFont ().handle;
- }
- 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);
- WindowClassCount++;
-
- /* Register the SWT window class */
- int hHeap = OS.GetProcessHeap ();
- int 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);
- 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);
-
- /* Register the SWT drop shadow window class */
- if (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);
-
- /* 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.SetWindowLong (hwndMessage, OS.GWL_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 the task bar created message */
- SWT_TASKBARCREATED = OS.RegisterWindowMessage (new TCHAR (0, "TaskbarCreated", true));
-
- /* Initialize OLE */
- if (!OS.IsWinCE) {
- OS.OleInitialize (0);
- }
-
- /* 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;
-}
-
-/**
- * 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 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 [] phKey = new int [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);
- int hwndFrom = from != null ? from.handle : 0;
- int 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);
- int hwndFrom = from != null ? from.handle : 0;
- int 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 messageProc (int hwnd, int msg, int wParam, int lParam) {
- switch (msg) {
- 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) {
- /*
- * 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 (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;
- }
- }
- }
- }
- }
- }
- }
- 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: ignoreNextKey = accentKey;
- }
- }
- if (consumed) {
- int 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, 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 ()) {
- if (modalDialogShell != null && modalDialogShell.isDisposed ()) modalDialogShell = null;
- Shell modal = modalDialogShell != null ? modalDialogShell : getModalShell ();
- if (modal != null) {
- int hwndModal = modal.handle;
- if (OS.IsWindowEnabled (hwndModal)) {
- modal.bringToTop ();
- if (modal.isDisposed ()) break;
- }
- int 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.
- */
- 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_SETTINGCHANGE: {
- switch (wParam) {
- case 0:
- case 1:
- case OS.SPI_SETHIGHCONTRAST:
- OS.SetTimer (hwndMessage, SETTINGS_ID, SETTINGS_DELAY, 0);
- }
- break;
- }
- case OS.WM_TIMER: {
- if (wParam == SETTINGS_ID) {
- OS.KillTimer (hwndMessage, SETTINGS_ID);
- runSettings ();
- } else {
- runTimer (wParam);
- }
- break;
- }
- default: {
- if (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, msg, wParam, lParam);
-}
-
-int monitorEnumProc (int hmonitor, int hdc, int lprcMonitor, int 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 msgFilterProc (int code, int wParam, int lParam) {
- if (runMessages) {
- /*
- * 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.
- */
- switch (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: {
- 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 ();
- }
- }
- }
- }
- }
- return OS.CallNextHookEx (filterHook, 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>
- * </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) {
- 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;
-}
-
-/**
- * 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 ();
- 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 runMessages && runAsyncMessages (false);
-}
-
-static synchronized void register (Display display) {
- 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);
- }
-
- /* 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;
- }
-
- /* 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 hHeap = OS.GetProcessHeap ();
- int hInstance = OS.GetModuleHandle (null);
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, windowClass, lpWndClass);
- OS.UnregisterClass (windowClass, hInstance);
- OS.HeapFree (hHeap, 0, lpWndClass.lpszClassName);
-
- /* Unregister the SWT drop shadow window class */
- OS.GetClassInfo (0, windowShadowClass, lpWndClass);
- OS.UnregisterClass (windowShadowClass, hInstance);
- OS.HeapFree (hHeap, 0, lpWndClass.lpszClassName);
- windowClass = windowShadowClass = 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 ();
- }
-
- /* Release references */
- thread = null;
- msg = null;
- keyboard = null;
- modalDialogShell = null;
- modalShells = null;
- data = null;
- keys = null;
- values = null;
- bars = popups = null;
- indexTable = null;
- controlTable = null;
- lastHittestControl = null;
- imageList = toolImageList = toolHotImageList = toolDisabledImageList = null;
-}
-
-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 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 #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 handle) {
- if (handle == 0) return null;
- Control control = null;
- int index;
- if (USE_PROPERTY) {
- index = OS.RemoveProp (handle, SWT_OBJECT_INDEX) - 1;
- } else {
- index = OS.GetWindowLong (handle, OS.GWL_USERDATA) - 1;
- }
- if (0 <= index && index < controlTable.length) {
- control = controlTable [index];
- controlTable [index] = null;
- indexTable [index] = freeSlot;
- freeSlot = index;
- if (!USE_PROPERTY) {
- OS.SetWindowLong (handle, OS.GWL_USERDATA, 0);
- }
- }
- 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 () {
- /*
- * 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 ()) {
- 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 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 ();
- 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 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;
- }
-
- /* 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 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 (this.synchronizer != null) {
- this.synchronizer.runAsyncMessages(true);
- }
- this.synchronizer = synchronizer;
-}
-
-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 occured when executing the runnable</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #asyncExec
- */
-public void syncExec (Runnable runnable) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- 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 [4];
- int index = 0;
- while (index < timerList.length) {
- if (timerList [index] == runnable) break;
- index++;
- }
- int 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 [] newTimerIds = new int [timerIds.length + 4];
- System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length);
- timerIds = newTimerIds;
- }
- }
- int 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 (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 (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 () {
- 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 windowProc (int hwnd, int msg, int wParam, int lParam) {
- /*
- * 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 (msg == OS.WM_NCHITTEST) {
- if (hitCount++ >= 1024) {
- try {Thread.sleep (1);} catch (Throwable t) {}
- }
- } else {
- hitCount = 0;
- }
- int index;
- if (USE_PROPERTY) {
- index = OS.GetProp (hwnd, SWT_OBJECT_INDEX) - 1;
- } else {
- index = OS.GetWindowLong (hwnd, OS.GWL_USERDATA) - 1;
- }
- if (0 <= index && index < controlTable.length) {
- Control control = controlTable [index];
- if (control != null) {
- return control.windowProc (hwnd, msg, wParam, lParam);
- }
- }
- return OS.DefWindowProc (hwnd, 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 abc71a3548..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandBar.java
+++ /dev/null
@@ -1,762 +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.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
- *
- * @since 3.2
- */
-public class ExpandBar extends Composite {
- ExpandItem[] items;
- int itemCount;
- ExpandItem focusItem;
- int spacing;
- int yCurrentScroll;
- int 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 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 callWindowProc (int hwnd, int msg, int wParam, int 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 hDC = OS.GetDC (handle);
- int hTheme = 0;
- if (isAppThemed ()) {
- hTheme = OS.OpenThemeData (handle, EXPLORERBAR);
- }
- int 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 (hTheme != 0) OS.CloseThemeData (hTheme);
- }
- }
- 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 hDC, int hwnd, RECT rect) {
- RECT rect2 = new RECT ();
- OS.GetClientRect (handle, rect2);
- OS.MapWindowPoints (handle, hwnd, rect2, 2);
- int hTheme = OS.OpenThemeData (handle, EXPLORERBAR);
- OS.DrawThemeBackground (hTheme, hDC, OS.EBP_NORMALGROUPBACKGROUND, 0, rect2, null);
- OS.CloseThemeData (hTheme);
-}
-
-void drawWidget (GC gc, RECT clipRect) {
- int hTheme = 0;
- if (isAppThemed ()) {
- hTheme = OS.OpenThemeData (handle, EXPLORERBAR);
- }
- 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 = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- drawFocus = (uiState & OS.UISF_HIDEFOCUS) == 0;
- }
- int hCaptionFont = 0, oldFont = 0;
- if (hTheme == 0) {
- if (!OS.IsWinCE && hFont == 0) {
- 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;
- hCaptionFont = OS.CreateFontIndirect (logFont);
- oldFont = OS.SelectObject (gc.handle, hCaptionFont);
- }
- }
- }
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items[i];
- item.drawItem (gc, hTheme, clipRect, item == focusItem && drawFocus);
- }
- if (hCaptionFont != 0) {
- OS.SelectObject (gc.handle, oldFont);
- OS.DeleteObject (hCaptionFont);
- }
- if (hTheme != 0) OS.CloseThemeData (hTheme);
-}
-
-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 hDC = OS.GetDC (handle);
- int 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);
-}
-
-public void setFont (Font font) {
- super.setFont (font);
- hFont = font != null ? font.handle : 0;
- layoutItems (0, true);
-}
-
-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);
- }
-}
-
-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.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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);
-}
-
-TCHAR windowClass () {
- return display.windowClass;
-}
-
-int windowProc () {
- return display.windowProc;
-}
-
-LRESULT WM_KEYDOWN (int wParam, int lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- if (focusItem == null) return result;
- switch (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);
- 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);
- return LRESULT.ZERO;
- }
- break;
- }
- }
- return result;
-}
-
-LRESULT WM_KILLFOCUS (int wParam, int lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- if (focusItem != null) focusItem.redraw (true);
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
- LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
- int x = (short) (lParam & 0xFFFF);
- int y = (short) (lParam >> 16);
- 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 wParam, int lParam) {
- LRESULT result = super.WM_LBUTTONUP (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
- if (focusItem == null) return result;
- int x = (short) (lParam & 0xFFFF);
- int y = (short) (lParam >> 16);
- 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 wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_MOUSEMOVE (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
- int x = (short) (lParam & 0xFFFF);
- int y = (short) (lParam >> 16);
- 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_PAINT (int wParam, int 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 wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_SETCURSOR (wParam, lParam);
- if (result != null) return result;
- int hitTest = lParam & 0xFFFF;
- if (hitTest == OS.HTCLIENT) {
- for (int i = 0; i < itemCount; i++) {
- ExpandItem item = items [i];
- if (item.hover) {
- int hCursor = OS.LoadCursor (0, OS.IDC_HAND);
- OS.SetCursor (hCursor);
- return LRESULT.ONE;
- }
- }
- }
- return result;
-}
-
-LRESULT WM_SETFOCUS (int wParam, int lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if (focusItem != null) focusItem.redraw (true);
- return result;
-}
-
-LRESULT WM_SIZE (int wParam, int 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 hwnd, int msg, int wParam, int 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;
-}
-} \ No newline at end of file
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 75fcf1d5d4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ExpandItem.java
+++ /dev/null
@@ -1,487 +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.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
- *
- * @since 3.2
- */
-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 hDC, RECT rect) {
- int 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 hPen = OS.CreatePen (OS.PS_SOLID, 1, parent.foreground);
- int 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 whitePen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DHILIGHT));
- int 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 hTheme, RECT clipRect, boolean drawFocus) {
- int 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 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 pen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_BTNFACE));
- int 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 hTheme, int 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 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 a1c8c79456..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FileDialog.java
+++ /dev/null
@@ -1,443 +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.widgets;
-
-
-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>
- */
-public class FileDialog extends Dialog {
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String [] fileNames = new String [0];
- String filterPath = "", fileName = "";
- static final String FILTER = "*.*";
- static int BUFFER_SIZE = 1024 * 32;
-
-/**
- * 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.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.
- * </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 FileDialog (Shell parent, int style) {
- super (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;
-}
-
-/**
- * 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;
-}
-
-/**
- * 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 hHeap = OS.GetProcessHeap ();
-
- /* Get the owner HWND for the dialog */
- int hwndOwner = 0;
- if (parent != null) hwndOwner = parent.handle;
-
- /* 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 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 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 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 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;
- if ((style & SWT.MULTI) != 0) {
- struct.Flags |= OS.OFN_ALLOWMULTISELECT | OS.OFN_EXPLORER;
- }
- struct.hwndOwner = hwndOwner;
- struct.lpstrTitle = lpstrTitle;
- struct.lpstrFile = lpstrFile;
- struct.nMaxFile = nMaxFile;
- struct.lpstrInitialDir = lpstrInitialDir;
- struct.lpstrFilter = lpstrFilter;
- struct.nFilterIndex = 0;
-
- /*
- * 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 lpstrDefExt = 0;
- boolean save = (style & SWT.SAVE) != 0;
- if (save) {
- lpstrDefExt = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
- struct.lpstrDefExt = lpstrDefExt;
- }
-
- /* Make the parent shell be temporary modal */
- Shell oldModal = null;
- Display display = parent.getDisplay ();
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- oldModal = display.getModalDialogShell ();
- display.setModalDialogShell (parent);
- }
-
- /*
- * 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);
- if (OS.CommDlgExtendedError () == OS.FNERR_INVALIDFILENAME) {
- OS.MoveMemory (lpstrFile, new TCHAR (0, "", true), TCHAR.sizeof);
- success = (save) ? OS.GetSaveFileName (struct) : OS.GetOpenFileName (struct);
- }
- display.runMessagesInIdle = oldRunMessagesInIdle;
-
- /* Clear the temporary dialog modal parent */
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- display.setModalDialogShell (oldModal);
- }
-
- /* 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;
- }
- }
- }
-
- /* 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);
-
- /*
- * 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
- * Windows, an extension filter string is typically of
- * the form "*.extension", where "*.*" matches all files.
- * </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;
-}
-
-/**
- * Sets the 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;
-}
-
-}
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 4853f6106d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java
+++ /dev/null
@@ -1,287 +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.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.Compatibility;
-
-/**
- * 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>
- */
-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.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.
- * </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, 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 hwndOwner = 0;
- if (parent != null) hwndOwner = parent.handle;
-
- /* Open the dialog */
- int hHeap = OS.GetProcessHeap ();
- CHOOSEFONT lpcf = new CHOOSEFONT ();
- lpcf.lStructSize = CHOOSEFONT.sizeof;
- lpcf.hwndOwner = hwndOwner;
- lpcf.Flags = OS.CF_SCREENFONTS | OS.CF_EFFECTS;
- int 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 hDC = OS.GetDC (0);
- int pixels = -Compatibility.round (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 */
- Shell oldModal = null;
- Display display = null;
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- display = parent.getDisplay ();
- oldModal = display.getModalDialogShell ();
- display.setModalDialogShell (parent);
- }
-
- /* Open the dialog */
- boolean success = OS.ChooseFont (lpcf);
-
- /* Clear the temporary dialog modal parent */
- if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
- display.setModalDialogShell (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 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 hFont = OS.CreateFontIndirect(logFont);
- int 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);
-
- int points = Compatibility.round(pixels * 72, 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);
-
- /*
- * 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 b4a13902d1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Group.java
+++ /dev/null
@@ -1,411 +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.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>
- */
-
-public class Group extends Composite {
- static final int CLIENT_INSET = 3;
- static final int 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 hInstance = OS.GetModuleHandle (null);
- if (!OS.GetClassInfo (hInstance, GroupClass, lpWndClass)) {
- int hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~(OS.CS_HREDRAW | OS.CS_VREDRAW);
- int byteCount = GroupClass.length () * TCHAR.sizeof;
- int 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 callWindowProc (int hwnd, int msg, int wParam, int 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 = OS.GetWindowTextLength (handle);
- if (length != 0) {
- /*
- * If the group has text, and the text is wider than the
- * client area, pad the width so the text is not clipped.
- */
- TCHAR buffer1 = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (handle, buffer1, length + 1);
- int newFont, oldFont = 0;
- int 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, buffer1, length, rect, flags);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- size.x = Math.max (size.x, rect.right - rect.left + CLIENT_INSET * 6);
- }
- return size;
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget ();
- Rectangle trim = super.computeTrim (x, y, width, height);
- int newFont, oldFont = 0;
- int 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);
- trim.x -= CLIENT_INSET;
- trim.y -= tm.tmHeight;
- trim.width += CLIENT_INSET * 2;
- trim.height += tm.tmHeight + CLIENT_INSET;
- return trim;
-}
-
-void createHandle () {
- super.createHandle ();
- state |= DRAW_BACKGROUND;
- state &= ~CANVAS;
-}
-
-public Rectangle getClientArea () {
- checkWidget ();
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int newFont, oldFont = 0;
- int 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 x = CLIENT_INSET, y = tm.tmHeight;
- 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 ();
- 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);
-}
-
-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);
-}
-
-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);
- 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 windowProc () {
- return GroupProc;
-}
-
-LRESULT WM_ERASEBKGND (int wParam, int lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- if (result != null) return result;
- /*
- * Feaure 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 wParam, int 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 code = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam);
- if (code == OS.HTTRANSPARENT) code = OS.HTCLIENT;
- return new LRESULT (code);
-}
-
-LRESULT WM_MOUSEMOVE (int wParam, int 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 wParam, int 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 code = callWindowProc (handle, OS.WM_PRINTCLIENT, wParam, lParam);
- OS.RestoreDC (wParam, nSavedDC);
- return new LRESULT (code);
- }
- return result;
-}
-
-LRESULT WM_SIZE (int wParam, int lParam) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (OS.IsWinCE) return result;
- OS.InvalidateRect (handle, null, true);
- return result;
-}
-
-LRESULT WM_UPDATEUISTATE (int wParam, int 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.
- *
- * NOTE: The DefWindowProc() must be called in order to
- * broadcast WM_UPDATEUISTATE message to the children.
- */
- 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 code = OS.DefWindowProc (handle, OS.WM_UPDATEUISTATE, wParam, lParam);
- return new LRESULT (code);
- }
- return result;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ImageList.java
deleted file mode 100755
index cc4d7867d1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ImageList.java
+++ /dev/null
@@ -1,427 +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.widgets;
-
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-class ImageList {
- int handle, 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 && OS.IsAppThemed ()) {
- flags |= OS.ILC_COLOR32;
- } else {
- int 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;
-}
-
-int addRef() {
- return ++refCount;
-}
-
-int copyBitmap (int hImage, int width, int height) {
- BITMAP bm = new BITMAP ();
- OS.GetObject (hImage, BITMAP.sizeof, bm);
- int hDC = OS.GetDC (0);
- int hdc1 = OS.CreateCompatibleDC (hDC);
- OS.SelectObject (hdc1, hImage);
- int 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 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[] pBits = new int[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 copyIcon (int hImage, int width, int height) {
- if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- int hIcon = OS.CopyImage (hImage, OS.IMAGE_ICON, width, height, 0);
- return hIcon != 0 ? hIcon : hImage;
-}
-
-int copyWithAlpha (int 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 hdc = OS.GetDC (0);
- int srcHdc = OS.CreateCompatibleDC (hdc);
- int oldSrcBitmap = OS.SelectObject (srcHdc, hBitmap);
- int 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 [] pBits = new int [1];
- int memDib = OS.CreateDIBSection (0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- if (memDib == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- int 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 [] pBits2 = new int [1];
- int memDib2 = OS.CreateDIBSection (0, bmi2, OS.DIB_RGB_COLORS, pBits2, 0, 0);
- int memHdc2 = OS.CreateCompatibleDC (hdc);
- int 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 createMask (int 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 hMask = OS.CreateBitmap (destWidth, destHeight, 1, 1, null);
- int hDC = OS.GetDC (0);
- int 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 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 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 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;
-}
-
-int removeRef() {
- return --refCount;
-}
-
-void set (int index, Image image, int count) {
- int 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 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 = Display.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 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/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java
deleted file mode 100755
index 86f561b9e2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java
+++ /dev/null
@@ -1,674 +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.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.
- * <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>
- */
-public class Label extends Control {
- String text = "";
- Image image;
- static final int MARGIN = 4;
- static final boolean IMAGE_AND_TEXT = false;
- static final int 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 callWindowProc (int hwnd, int msg, int wParam, int 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 hDC = OS.GetDC (handle);
- int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- int 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 || !OS.IsAppThemed ()) {
- 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 windowProc () {
- return LabelProc;
-}
-
-LRESULT WM_ERASEBKGND (int wParam, int 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 || !OS.IsAppThemed ()) {
- if (findImageControl () != null) {
- drawBackground (wParam);
- return LRESULT.ONE;
- }
- }
- return result;
-}
-
-LRESULT WM_SIZE (int wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_UPDATEUISTATE (wParam, lParam);
- /*
- * 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_CTLCOLORBTN, 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);
- return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT wmColorChild (int wParam, int 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 || !OS.IsAppThemed ()) {
- 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 wParam, int 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 wParam, int 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 474dfc0f61..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Link.java
+++ /dev/null
@@ -1,929 +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.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>
- *
- * @since 3.1
- */
-public class Link extends Control {
- String text;
- TextLayout layout;
- Color linkColor, disabledColor;
- Point [] offsets;
- Point selection;
- String [] ids;
- int [] mnemonics;
- int focusIndex, mouseDownIndex;
- int font;
- static final RGB LINK_FOREGROUND = new RGB (0, 51, 153);
- static final int 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;
- } 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 sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control is selected.
- * <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 callWindowProc (int hwnd, int msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- if (LinkProc != 0) 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 hDC = OS.GetDC (handle);
- int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- int oldFont = OS.SelectObject (hDC, newFont);
- TCHAR buffer = new TCHAR (getCodePage (), parse (text), false);
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT;
- 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;
- 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);
- 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, linkStart, index, 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 tag can be used to distinguish between them. The string may
- * include the mnemonic character and line delimiters.
- * </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);
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SetWindowText (handle, buffer);
- parse (string);
- enableWidget (enabled);
- } else {
- layout.setText (parse (string));
- 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 windowProc () {
- return LinkProc != 0 ? LinkProc : display.windowProc;
-}
-
-LRESULT WM_CHAR (int wParam, int lParam) {
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
- if (OS.COMCTL32_MAJOR < 6) {
- if (focusIndex == -1) return result;
- switch (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 (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 code = callWindowProc (handle, OS.WM_KEYDOWN, wParam, lParam);
- return new LRESULT (code);
- }
-
- }
- return result;
-}
-
-LRESULT WM_GETDLGCODE (int wParam, int lParam) {
- LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
- if (result != null) return result;
- int index, count, 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 wParam, int lParam) {
- LRESULT result = super.WM_GETFONT (wParam, lParam);
- if (result != null) return result;
- int 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 wParam, int lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- if (OS.COMCTL32_MAJOR >= 6) {
- switch (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 wParam, int lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- if (OS.COMCTL32_MAJOR < 6) redraw ();
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int wParam, int 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 = lParam & 0xFFFF;
- int y = lParam >> 16;
- 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 wParam, int 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 = lParam & 0xFFFF;
- int y = lParam >> 16;
- 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_MOUSEMOVE (int wParam, int lParam) {
- LRESULT result = super.WM_MOUSEMOVE (wParam, lParam);
- if (OS.COMCTL32_MAJOR < 6) {
- int x = lParam & 0xFFFF;
- int y = lParam >> 16;
- 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 wParam, int 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 wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if (OS.COMCTL32_MAJOR < 6) redraw ();
- return result;
-}
-
-LRESULT WM_SETFONT (int wParam, int 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 wParam, int 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 wParam, int 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 hBrush = findBrush (backPixel, OS.BS_SOLID);
- return new LRESULT (hBrush);
- }
- }
- }
- return result;
-}
-
-LRESULT wmNotifyChild (int wParam, int lParam) {
- if (OS.COMCTL32_MAJOR >= 6) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- 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 (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 467b652bb0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java
+++ /dev/null
@@ -1,1542 +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.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>
- */
-
-public class List extends Scrollable {
- static final int 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 = 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 = 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 = 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 receiver's selection changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 callWindowProc (int hwnd, int msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (ListProc, hwnd, msg, wParam, lParam);
-}
-
-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 = OS.SendMessage (handle, OS.LB_GETHORIZONTALEXTENT, 0, 0);
- } else {
- int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- int newFont, oldFont = 0;
- int 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 = 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 = 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 = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- int itemHeight = 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 + 3;
- 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 = 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 = 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 = 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 = 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 = OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
- if (result == 0) {
- int count = 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 = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0);
- if (length != OS.LB_ERR) {
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer);
- if (result != OS.LB_ERR) return buffer.toString (0, length);
- }
- int count = 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 = 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 = 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 = OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- if (result == OS.LB_ERR) return 0;
- return 1;
- }
- int result = 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 OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- }
- int count = 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 = OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
- int result = 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 = 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 = OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- if (result == OS.LB_ERR) return new int [0];
- return new int [] {result};
- }
- int length = 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 = 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 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 = 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 = 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 visibility 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 = 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 = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (!(0 <= start && start <= end && end < count)) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- RECT rect = null;
- int hDC = 0, oldFont = 0, newFont = 0, 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 = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0);
- if (length == OS.LB_ERR) break;
- buffer = new TCHAR (cp, length + 1);
- int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer);
- if (result == OS.LB_ERR) break;
- }
- int result = 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 = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0);
- if (length == OS.LB_ERR) {
- int count = 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 = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer);
- if (result == OS.LB_ERR) {
- int count = 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 = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- int result = OS.SendMessage (handle, OS.LB_DELETESTRING, index, 0);
- if (result == OS.LB_ERR) {
- int count = 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 = 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 = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- RECT rect = null;
- int hDC = 0, oldFont = 0, newFont = 0, 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 = OS.SendMessage (handle, OS.LB_GETTEXTLEN, start, 0);
- if (length == OS.LB_ERR) break;
- buffer = new TCHAR (cp, length + 1);
- int result = OS.SendMessage (handle, OS.LB_GETTEXT, start, buffer);
- if (result == OS.LB_ERR) break;
- }
- int result = 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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 = 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 = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- RECT itemRect = new RECT (), selectedRect = null;
- OS.SendMessage (handle, OS.LB_GETITEMRECT, index, itemRect);
- boolean redraw = drawCount == 0 && 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 = 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 = 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 = 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 = 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. This is equivalent
- * to <code>remove</code>'ing the old item at the index, and then
- * <code>add</code>'ing the new item at that index.
- *
- * @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 oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, ListProc);
- boolean redraw = drawCount == 0 && OS.IsWindowVisible (handle);
- if (redraw) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- RECT rect = null;
- int hDC = 0, oldFont = 0, newFont = 0, 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 = 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 + 3, 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.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
- if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED);
-}
-
-void setScrollWidth () {
- int newWidth = 0;
- RECT rect = new RECT ();
- int newFont, oldFont = 0;
- int 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 = 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 = OS.SendMessage (handle, OS.LB_GETTEXTLEN, i, 0);
- if (length != OS.LB_ERR) {
- TCHAR buffer = new TCHAR (cp, length + 1);
- int result = 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 + 3, 0);
-}
-
-void setScrollWidth (TCHAR buffer, boolean grow) {
- RECT rect = new RECT ();
- int newFont, oldFont = 0;
- int 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) {
- int width = OS.SendMessage (handle, OS.LB_GETHORIZONTALEXTENT, 0, 0);
- if (grow) {
- if (newWidth <= width) return;
- OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, newWidth + 3, 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 = 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 = OS.SendMessage (handle, OS.LB_SETTOPINDEX, index, 0);
- if (result == OS.LB_ERR) {
- int count = 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 = OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0);
- } else {
- int [] indices = new int [1];
- int result = OS.SendMessage (handle, OS.LB_GETSELITEMS, 1, indices);
- index = indices [0];
- if (result != 1) index = -1;
- }
- if (index == -1) return;
- int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- if (count == 0) return;
- int height = OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0);
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int topIndex = 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 windowProc () {
- return ListProc;
-}
-
-LRESULT WM_SIZE (int wParam, int 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 = 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 = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0);
- if (oldIndex != newIndex) OS.InvalidateRect (handle, null, true);
- }
- return result;
-}
-
-LRESULT wmCommandChild (int wParam, int lParam) {
- int code = wParam >> 16;
- 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 696012c9c7..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java
+++ /dev/null
@@ -1,1362 +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.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 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>
- */
-
-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 handle;
-
- int x, y, hwndCB, id0, id1;
- 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.
- *
- * @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>
- *
- * @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 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.
- *
- * @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.
- *
- * @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;
- /*
- * 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 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 = (short) (pos & 0xFFFF);
- nY = (short) (pos >> 16);
- }
- /*
- * 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=0xFFFF0000, 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, 0xFFFF0000, 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 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 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 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 lParam = dwMask << 16 | 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 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 hHeap = OS.GetProcessHeap ();
- TCHAR buffer = new TCHAR (0, " ", true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- int 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 = 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);
-}
-
-/*
-* Currently not used.
-*/
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_MENU);
-}
-
-/*
-* Currently not used.
-*/
-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 = 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 = 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 () {
- int hMenu = handle, hCB = hwndCB;
- releaseHandle ();
- if (OS.IsWinCE && hCB != 0) {
- OS.CommandBar_Destroy (hCB);
- } 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 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 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 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 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 = 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 = 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 (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 handle) {
- if (OS.IsWinCE) {
- if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) {
- return OS.IsSP ? 2 : 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 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 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 (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 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 ();
- 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;
-}
-
-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 (cascade != null) cascade.releaseMenu ();
- 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 ();
- 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;
- 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 ();
- 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.
- */
- if (!OS.IsWin95) {
- 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) {
- info.hbmpItem = hasImage ? 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);
-}
-
-}
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 d3adfcb786..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
+++ /dev/null
@@ -1,1168 +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.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>
- */
-
-public class MenuItem extends Item {
- Menu parent, menu;
- 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 ();
-}
-
-void fillAccel (ACCEL accel) {
- accel.fVirt = 0;
- accel.cmd = accel.key = 0;
- if (accelerator == 0 || !getEnabled ()) return;
- 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;
- if (OS.IsWinCE) {
- key = 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;
-}
-
-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 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 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 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;
- }
- int 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 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 releaseMenu () {
- if (!OS.IsSP) setMenu (null);
- menu = null;
-}
-
-void releaseParent () {
- super.releaseParent ();
- if (menu != null) menu.dispose ();
- menu = null;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 {
- int 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).
- * </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 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 (image != null) info.hbmpItem = OS.HBMMENU_CALLBACK;
- int 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);
- }
- }
-
- /* 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 hwndCB = parent.hwndCB;
- int hMenu = menu == null ? 0 : menu.handle;
- OS.SendMessage (hwndCB, OS.SHCMBM_SETSUBMENU, id, hMenu);
- }
- if (OS.IsSP) error (SWT.ERROR_CANNOT_SET_MENU);
- } 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 ().
- */
- int 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;
- boolean hasBitmap = false, success = false;
-
- /*
- * 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 to temporarily remove the bitmap and restore it after
- * the text and submenu have been set.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- info.fMask = OS.MIIM_BITMAP;
- OS.GetMenuItemInfo (hMenu, index, true, info);
- hasBitmap = info.hbmpItem != 0;
- if (hasBitmap) {
- info.hbmpItem = 0;
- success = OS.SetMenuItemInfo (hMenu, id, false, info);
- }
- }
-
- int cch = 128;
- int hHeap = OS.GetProcessHeap ();
- int byteCount = cch * TCHAR.sizeof;
- int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- info.fMask = OS.MIIM_STATE | OS.MIIM_ID | OS.MIIM_TYPE | OS.MIIM_DATA;
- info.dwTypeData = pszText;
- info.cch = cch;
- success = OS.GetMenuItemInfo (hMenu, index, true, info);
- if (menu != null) {
- menu.cascade = this;
- info.fMask |= OS.MIIM_SUBMENU;
- info.hSubMenu = menu.handle;
- }
- OS.RemoveMenu (hMenu, index, OS.MF_BYPOSITION);
- if (OS.IsWinCE) {
- /*
- * 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 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 {
- success = OS.InsertMenuItem (hMenu, index, true, info);
- /*
- * Restore the bitmap that was removed to work around a problem
- * in GetMenuItemInfo() and menu items that have bitmaps set with
- * MIIM_BITMAP.
- */
- if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- if (hasBitmap) {
- info.fMask = OS.MIIM_BITMAP;
- info.hbmpItem = OS.HBMMENU_CALLBACK;
- success = OS.SetMenuItemInfo (hMenu, id, false, 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 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 hHeap = OS.GetProcessHeap ();
- int 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 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 hMenu = parent.handle;
-
- /*
- * 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 reset both MIIM_BITMAP.
- * Note, this does not happen on Windows 98.
- */
- boolean hasBitmap = false;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- info.fMask = OS.MIIM_BITMAP;
- OS.GetMenuItemInfo (hMenu, id, false, info);
- hasBitmap = info.hbmpItem != 0;
- }
-
- /* 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);
- info.fMask = OS.MIIM_TYPE;
- info.fType = widgetStyle ();
- info.dwTypeData = pszText;
- success = OS.SetMenuItemInfo (hMenu, id, false, info);
-
- /*
- * Restore the bitmap that was removed to work around a problem
- * in GetMenuItemInfo() and menu items that have bitmaps set with
- * MIIM_BITMAP.
- */
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
- if (hasBitmap) {
- info.fMask = OS.MIIM_BITMAP;
- info.hbmpItem = OS.HBMMENU_CALLBACK;
- 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 wParam, int 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 wParam, int 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 ();
- }
- return null;
-}
-
-LRESULT wmMeasureChild (int wParam, int 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 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 03074cdd1b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MessageBox.java
+++ /dev/null
@@ -1,247 +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.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>
- */
-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>
- */
-public MessageBox (Shell parent, int style) {
- super (parent, checkStyle (style));
- checkSubclass ();
-}
-
-static int checkStyle (int style) {
- if ((style & (SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) == 0) style |= SWT.APPLICATION_MODAL;
- 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;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null && (parent.style & SWT.MIRRORED) != 0) {
- bits |= OS.MB_RTLREADING;
- }
- }
-
- /*
- * 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;
- }
-
- /*
- * 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 hwndOwner = parent != null ? parent.handle : 0;
- Shell oldModal = null;
- Display display = null;
- if ((bits & OS.MB_TASKMODAL) != 0) {
- display = parent.getDisplay ();
- oldModal = display.getModalDialogShell ();
- display.setModalDialogShell (parent);
- }
-
- /* 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.setModalDialogShell (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 ef67b1341f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java
+++ /dev/null
@@ -1,366 +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.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of the receiver represent is 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>
- */
-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 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 mean 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 hInstance = OS.GetModuleHandle (null);
- int hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~OS.CS_GLOBALCLASS;
- lpWndClass.style |= OS.CS_DBLCLKS;
- int byteCount = ProgressBarClass.length () * TCHAR.sizeof;
- int 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 Widget#checkSubclass
- * @see Widget#getStyle
- */
-public ProgressBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int callWindowProc (int hwnd, int msg, int wParam, int 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 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 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 OS.SendMessage (handle, OS.PBM_GETPOS, 0, 0);
-}
-
-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 = 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 = 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 ();
- OS.SendMessage (handle, OS.PBM_SETPOS, value, 0);
-}
-
-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 windowProc () {
- return ProgressBarProc;
-}
-
-LRESULT WM_GETDLGCODE (int wParam, int 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 wParam, int 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 wParam, int 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 5b715ec94d..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java
+++ /dev/null
@@ -1,417 +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.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>
- */
-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 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 callWindowProc (int hwnd, int msg, int wParam, int 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 hwndTrack = parent.handle;
- byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0};
- int stippleBitmap = OS.CreateBitmap (8, 8, 1, 1, bits);
- int stippleBrush = OS.CreatePatternBrush (stippleBitmap);
- int hDC = OS.GetDCEx (hwndTrack, 0, OS.DCX_CACHE);
- int 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 windowProc () {
- return display.windowProc;
-}
-
-LRESULT WM_ERASEBKGND (int wParam, int lParam) {
- super.WM_ERASEBKGND (wParam, lParam);
- drawBackground (wParam);
- return LRESULT.ONE;
-}
-
-LRESULT WM_KEYDOWN (int wParam, int lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- switch (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 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 wParam, int lParam) {
- return new LRESULT (OS.DLGC_STATIC);
-}
-
-LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
- LRESULT result = super.WM_LBUTTONDOWN (wParam, lParam);
- if (result == LRESULT.ZERO) return result;
-
- /* Compute the banding rectangle */
- int hwndTrack = parent.handle;
- POINT pt = new POINT ();
- pt.x = (short) (lParam & 0xFFFF);
- pt.y = (short) (lParam >> 16);
- 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 wParam, int 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 wParam, int 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 ();
- pt.x = (short) (lParam & 0xFFFF);
- pt.y = (short) (lParam >> 16);
- int 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 wParam, int lParam) {
- LRESULT result = super.WM_SETCURSOR (wParam, lParam);
- if (result != null) return result;
- int hitTest = lParam & 0xFFFF;
- if (hitTest == OS.HTCLIENT) {
- int 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 13c51e09ee..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java
+++ /dev/null
@@ -1,500 +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.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>
- */
-
-public class Scale extends Control {
- boolean ignoreResize;
- static final int 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 mean 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 hInstance = OS.GetModuleHandle (null);
- int hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~OS.CS_GLOBALCLASS;
- lpWndClass.style |= OS.CS_DBLCLKS;
- int byteCount = TrackBarClass.length () * TCHAR.sizeof;
- int 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 receiver's value changes, by sending
- * it one of the messages defined in the <code>SelectionListener</code>
- * interface.
- * <p>
- * <code>widgetSelected</code> is called when the control's value changes.
- * <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 callWindowProc (int hwnd, int msg, int wParam, int 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 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 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 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 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 OS.SendMessage (handle, OS.TBM_GETPOS, 0, 0);
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 hImage) {
- super.setBackgroundPixel (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;
-}
-
-/**
- * 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 = OS.SendMessage (handle, OS.TBM_GETRANGEMIN, 0, 0);
- int maximum = 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 = 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 = 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 = OS.SendMessage (handle, OS.TBM_GETRANGEMIN, 0, 0);
- int maximum = 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 windowProc () {
- return TrackBarProc;
-}
-
-LRESULT WM_PAINT (int wParam, int 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 = drawCount == 0 && 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, true);
- }
- }
- return super.WM_PAINT (wParam, lParam);
-}
-
-LRESULT WM_SIZE (int wParam, int lParam) {
- if (ignoreResize) return null;
- return super.WM_SIZE (wParam, lParam);
-}
-
-LRESULT wmScrollChild (int wParam, int lParam) {
-
- /* Do nothing when scrolling is ending */
- int code = wParam & 0xFFFF;
- switch (code) {
- case OS.TB_ENDTRACK:
- case OS.TB_THUMBPOSITION:
- return null;
- }
-
- 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 81a478aee5..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java
+++ /dev/null
@@ -1,904 +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.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
- */
-
-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 receiver's value changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 intial 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 hwnd = hwndScrollBar (), 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);
- }
- releaseHandle ();
-}
-
-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 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 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 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 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();
- return (state & HIDDEN) == 0;
-}
-
-int 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 receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 hwnd = hwndScrollBar (), 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 hwnd = hwndScrollBar (), 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 hwnd = hwndScrollBar (), 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 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.
- */
- if ((state & (DISABLED | HIDDEN)) != 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 ((state & HIDDEN) != 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) {
- ScrollBar bar = null;
- switch (flags) {
- case OS.SB_HORZ:
- bar = parent.getVerticalBar ();
- break;
- case OS.SB_VERT:
- bar = parent.getHorizontalBar ();
- break;
- }
- boolean both = bar != null && !bar.getVisible ();
- OS.ShowScrollBar (hwnd, both ? OS.SB_BOTH : flags, 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 hwnd = hwndScrollBar (), 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 hwnd = hwndScrollBar (), 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 hwnd = hwndScrollBar (), 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();
- boolean isVisible = (state & HIDDEN) == 0;
- if (isVisible == visible) 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 hwnd = hwndScrollBar (), 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 hwnd = hwndScrollBar (), 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 wParam, int lParam) {
-
- /* Do nothing when scrolling is ending */
- int code = wParam & 0xFFFF;
- 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 9472986ed4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java
+++ /dev/null
@@ -1,407 +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.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>
- */
-
-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 callWindowProc (int hwnd, int msg, int wParam, int 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 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);
-}
-
-/**
- * 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 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 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 windowProc () {
- return display.windowProc;
-}
-
-LRESULT WM_HSCROLL (int wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_MOUSEWHEEL (wParam, lParam);
- if (result != null) return result;
-
- /*
- * Translate WM_MOUSEWHEEL to WM_VSCROLL or WM_HSCROLL.
- */
- if ((state & CANVAS) != 0) {
- 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 [] value = new int [1];
- OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, value, 0);
- int delta = (short) (wParam >> 16);
- int code = 0, count = 0;
- if (value [0] == OS.WHEEL_PAGESCROLL) {
- code = delta < 0 ? OS.SB_PAGEDOWN : OS.SB_PAGEUP;
- count = Math.abs (delta / OS.WHEEL_DELTA);
- } else {
- code = delta < 0 ? OS.SB_LINEDOWN : OS.SB_LINEUP;
- delta = Math.abs (delta);
- if (delta < OS.WHEEL_DELTA) return result;
- if (msg == OS.WM_VSCROLL) {
- count = value [0] * delta / OS.WHEEL_DELTA;
- } else {
- count = 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
- * explicity send the event.
- */
- int vPosition = verticalBar == null ? 0 : verticalBar.getSelection ();
- int hPosition = horizontalBar == null ? 0 : horizontalBar.getSelection ();
- int 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 WM_SIZE (int wParam, int lParam) {
- int 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 wParam, int 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 wmScroll (ScrollBar bar, boolean update, int hwnd, int msg, int wParam, int 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 = wParam & 0xFFFF;
- 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 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 7e9b9493f8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java
+++ /dev/null
@@ -1,2128 +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.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</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
- */
-public class Shell extends Decorations {
- Menu activeMenu;
- ToolTip [] toolTips;
- int hIMC, hwndMDIClient, lpstrTip, toolTipHandle, balloonTipHandle;
- int minWidth = SWT.DEFAULT, minHeight = SWT.DEFAULT;
- int [] brushes;
- boolean showWithParent;
- Control lastActive;
- SHACTIVATEINFO psai;
- Region region;
- static /*final*/ int ToolTipProc;
- static final int 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#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
-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#NO_TRIM
- * @see SWT#SHELL_TRIM
- * @see SWT#DIALOG_TRIM
- * @see SWT#MODELESS
- * @see SWT#PRIMARY_MODAL
- * @see SWT#APPLICATION_MODAL
- * @see SWT#SYSTEM_MODAL
- */
-public Shell (Display display, int style) {
- this (display, null, style, 0);
-}
-
-Shell (Display display, Shell parent, int style, int handle) {
- 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.style = checkStyle (style);
- this.parent = parent;
- this.display = display;
- this.handle = 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
- */
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.display : null, parent, style, 0);
-}
-
-/**
- * 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 win32_new (Display display, int handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle);
-}
-
-static int checkStyle (int style) {
- style = Decorations.checkStyle (style);
- 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;
-}
-
-/**
- * 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 balloonTipHandle () {
- if (balloonTipHandle == 0) createBalloonTipHandle ();
- return balloonTipHandle;
-}
-
-int callWindowProc (int hwnd, int msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- if (hwnd == toolTipHandle || hwnd == balloonTipHandle) {
- return OS.CallWindowProc (ToolTipProc, 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);
- }
- if (hwndMDIClient != 0) {
- return OS.DefFrameProc (hwnd, hwndMDIClient, msg, wParam, lParam);
- }
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
-}
-
-/**
- * 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_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.GetWindowLong (balloonTipHandle, OS.GWL_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.SetWindowLong (balloonTipHandle, OS.GWL_WNDPROC, display.windowProc);
-}
-
-void createHandle () {
- boolean embedded = 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;
- super.createHandle ();
-
- /*
- * 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.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.GetWindowLong (toolTipHandle, OS.GWL_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.SetWindowLong (toolTipHandle, OS.GWL_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;
-}
-
-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 findBrush (int 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 [BRUSHES_SIZE];
- LOGBRUSH logBrush = new LOGBRUSH ();
- for (int i=0; i<brushes.length; i++) {
- int 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 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 (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 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);
- }
-}
-
-/**
- * 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
- * @see Shell#open
- * @see Shell#setActive
- */
-public void forceActive () {
- checkWidget ();
- if(!isVisible()) return;
- OS.SetForegroundWindow (handle);
-}
-
-void forceResize () {
- /* Do nothing */
-}
-
-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 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 (lpti.uId);
- }
- }
- return null;
-}
-
-public boolean getEnabled () {
- checkWidget ();
- return (state & DISABLED) == 0;
-}
-
-/**
- * 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 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);
-}
-
-/**
- * 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);
-}
-
-/**
- * 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 () {
- 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
- * descendents 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 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
- * @see Shell#setActive
- * @see Shell#forceActive
- */
-public void open () {
- checkWidget ();
- 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 explicitely 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 ();
-}
-
-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 hHeap = OS.GetProcessHeap ();
- OS.HeapFree (hHeap, 0, lpstrTip);
- }
- lpstrTip = 0;
- toolTipHandle = balloonTipHandle = 0;
- if (OS.IsDBLocale) {
- if (hIMC != 0) OS.ImmDestroyContext (hIMC);
- }
- lastActive = null;
- region = 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 hPalette) {
- int hDC = OS.GetDC (handle);
- int 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;
-}
-
-/**
- * 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
- * @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);
- }
- }
-}
-
-void setBounds (int x, int y, int width, int height, int flags, boolean defer) {
- 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 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 && mode != SWT.ROMAN;
- int 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) != 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);
-}
-
-void setItemEnabled (int cmd, boolean enabled) {
- int 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;
- if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- int 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;
-}
-
-void setToolTipText (int hwnd, String text) {
- if (OS.IsWinCE) return;
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.hwnd = handle;
- lpti.uId = hwnd;
- int 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 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 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;
-}
-
-public void setVisible (boolean visible) {
- checkWidget ();
- if (drawCount != 0) {
- if (((state & HIDDEN) == 0) == visible) return;
- } else {
- if (visible == OS.IsWindowVisible (handle)) return;
- }
-
- /*
- * 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);
- 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 ();
- }
-
- /*
- * 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);
- }
- super.setVisible (visible);
- if (isDisposed ()) return;
- if (showWithParent == visible) return;
- showWithParent = visible;
- if (visible) {
- if (!OS.IsWinCE) OS.ShowOwnedPopups (handle, true);
- }
-}
-
-void subclass () {
- super.subclass ();
- if (ToolTipProc != 0) {
- int newProc = display.windowProc;
- if (toolTipHandle != 0) {
- OS.SetWindowLong (toolTipHandle, OS.GWL_WNDPROC, newProc);
- }
- if (balloonTipHandle != 0) {
- OS.SetWindowLong (balloonTipHandle, OS.GWL_WNDPROC, newProc);
- }
- }
-}
-
-int 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.SetWindowLong (toolTipHandle, OS.GWL_WNDPROC, ToolTipProc);
- }
- if (toolTipHandle != 0) {
- OS.SetWindowLong (toolTipHandle, OS.GWL_WNDPROC, ToolTipProc);
- }
- }
-}
-
-void updateModal () {
- if (Display.TrimEnabled) {
- setItemEnabled (OS.SC_CLOSE, isActive ());
- } else {
- OS.EnableWindow (handle, isActive ());
- }
-}
-
-CREATESTRUCT widgetCreateStruct () {
- return null;
-}
-
-int 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 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) super.windowProc ();
- }
- return parent != null ? DialogProc : super.windowProc ();
-}
-
-int windowProc (int hwnd, int msg, int wParam, int 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 wParam, int 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 = wParam & 0xFFFF;
- int 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 ((wParam & 0xFFFF) != 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 close the IME to cause
- * the composition string to be committed.
- *
- * Note. The IME needs to be reopened in order to preserve
- * the input method status.
- */
- if (OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
- if ((wParam & 0xFFFF) == 0 && OS.IsDBLocale && hIMC != 0) {
- if (OS.ImmGetOpenStatus(hIMC)) {
- OS.ImmSetOpenStatus (hIMC, false);
- OS.ImmSetOpenStatus (hIMC, true);
- }
- }
- }
-
- /* Process WM_ACTIVATE */
- LRESULT result = super.WM_ACTIVATE (wParam, lParam);
- if ((wParam & 0xFFFF) == 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 wParam, int 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 = wParam & 0xFFFF;
- 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 hwndCB = menuBar.hwndCB;
- if (lParam != 0 && hwndCB != 0) {
- if (lParam == hwndCB) {
- return super.WM_COMMAND (wParam, 0);
- } else {
- int 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 wParam, int 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_ENTERIDLE (int wParam, int lParam) {
- LRESULT result = super.WM_ENTERIDLE (wParam, lParam);
- if (result != null) return result;
- if (OS.IsWinCE && display.runMessages) {
- if (display.runAsyncMessages (true)) display.wakeThread ();
- }
- return result;
-}
-
-LRESULT WM_GETMINMAXINFO (int wParam, int 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 wParam, int 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) (lParam & 0xFFFF);
- 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 ();
- pt.x = (short) (pos & 0xFFFF);
- pt.y = (short) (pos >> 16);
- }
- int 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);
- }
- }
- }
- }
-
- setActiveControl (control);
- return null;
-}
-
-LRESULT WM_MOVE (int wParam, int 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 wParam, int lParam) {
- if (!OS.IsWindowEnabled (handle)) return null;
- if (!isEnabled () || !isActive ()) {
- if (!Display.TrimEnabled) return new LRESULT (OS.HTNOWHERE);
- int 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 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 wParam, int lParam) {
- LRESULT result = super.WM_NCLBUTTONDOWN (wParam, lParam);
- if (result != null) return result;
- /*
- * When the normal activation was interruped 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 hwndActive = 0;
- boolean fixActive = OS.IsWin95 && display.lastHittest == OS.HTCAPTION;
- if (fixActive) hwndActive = OS.SetActiveWindow (handle);
- display.lockActiveWindow = true;
- int 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 wParam, int lParam) {
- if (wParam != handle) {
- int hPalette = display.hPalette;
- if (hPalette != 0) return selectPalette (hPalette);
- }
- return super.WM_PALETTECHANGED (wParam, lParam);
-}
-
-LRESULT WM_QUERYNEWPALETTE (int wParam, int lParam) {
- int hPalette = display.hPalette;
- if (hPalette != 0) return selectPalette (hPalette);
- return super.WM_QUERYNEWPALETTE (wParam, lParam);
-}
-
-LRESULT WM_SETCURSOR (int wParam, int 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 = (short) (lParam >> 16);
- if (msg == OS.WM_LBUTTONDOWN) {
- if (!Display.TrimEnabled) {
- Shell modalShell = display.getModalShell ();
- if (modalShell != null && !isActive ()) {
- int hwndModal = modalShell.handle;
- if (OS.IsWindowEnabled (hwndModal)) {
- OS.SetActiveWindow (hwndModal);
- }
- }
- }
- if (!OS.IsWindowEnabled (handle)) {
- if (!OS.IsWinCE) {
- int 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) (lParam & 0xFFFF);
- if (hitTest == OS.HTERROR) {
- if (!getEnabled ()) {
- Control control = display.getControl (wParam);
- if (control == this && cursor != null) {
- POINT pt = new POINT ();
- if (OS.GetCursorPos (pt)) {
- 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 wParam, int 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 wParam, int 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 wParam, int 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 = 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 wParam, int 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 a0773560c3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java
+++ /dev/null
@@ -1,784 +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.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
- */
-public class Slider extends Control {
- int increment, pageIncrement;
- boolean ignoreFocus;
- static final int 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 receiver's value changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 callWindowProc (int hwnd, int msg, int wParam, int 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 intial 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 receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 windowProc () {
- return ScrollBarProc;
-}
-
-LRESULT WM_KEYDOWN (int wParam, int 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 (wParam) {
- case OS.VK_LEFT:
- case OS.VK_RIGHT: {
- int key = wParam == OS.VK_LEFT ? OS.VK_RIGHT : OS.VK_LEFT;
- int code = callWindowProc (handle, OS.WM_KEYDOWN, key, lParam);
- return new LRESULT (code);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDBLCLK (int wParam, int 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 wParam, int 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 wParam, int lParam) {
- if (ignoreFocus) return null;
- return super.WM_SETFOCUS (wParam, lParam);
-}
-
-LRESULT wmScrollChild (int wParam, int lParam) {
-
- /* Do nothing when scrolling is ending */
- int code = wParam & 0xFFFF;
- 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 3d809a6d63..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Spinner.java
+++ /dev/null
@@ -1,1343 +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.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>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, Modify</dd>
- * </dl>
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @since 3.1
- */
-public class Spinner extends Composite {
- int hwndText, hwndUpDown;
- boolean ignoreModify;
- int pageIncrement, digits;
- static final int EditProc;
- static final TCHAR EditClass = new TCHAR (0, "EDIT", true);
- static final int 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;
- }
-
-/**
- * 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 callWindowProc (int hwnd, int msg, int wParam, int 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 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 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.SetWindowLong (hwndText, OS.GWL_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.SetWindowLong (hwndUpDown, OS.GWL_ID, hwndUpDown);
- if (OS.IsDBLocale) {
- int 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 newFont, oldFont = 0;
- int 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 ();
- 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 margins = OS.SendMessage (hwndText, OS.EM_GETMARGINS, 0, 0);
- x -= margins & 0xFFFF;
- width += (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF);
- 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 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.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF;
- } else {
- return OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
- }
-}
-
-int getSelectionText () {
- 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) {
- String wholePart = string.substring (0, index);
- 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;
- } else {
- value = Integer.parseInt (string);
- }
- } 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) {
- }
- return -1;
-}
-
-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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 wParam, int 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 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.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF;
- } else {
- pos = 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 hHeap = OS.GetProcessHeap ();
- int count = OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, 0, (UDACCEL)null);
- int 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 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 ();
- if (value < 0) return;
- 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.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF;
- } else {
- pos = 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 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 [] max = new int [1];
- OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, max);
- if (value >= max [0]) return;
- int pos;
- if (OS.IsWinCE) {
- pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF;
- } else {
- pos = 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 = String.valueOf (value);
- if (digits > 0) {
- String decimalSeparator = getDecimalSeparator ();
- 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 ();
- }
- 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);
- }
- if (notify) postEvent (SWT.Selection);
-}
-
-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 (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);
- 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 newProc = display.windowProc;
- OS.SetWindowLong (hwndText, OS.GWL_WNDPROC, newProc);
- OS.SetWindowLong (hwndUpDown, OS.GWL_WNDPROC, newProc);
-}
-
-void unsubclass () {
- super.unsubclass ();
- OS.SetWindowLong (hwndText, OS.GWL_WNDPROC, EditProc);
- OS.SetWindowLong (hwndUpDown, OS.GWL_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;
- }
- 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 windowProc (int hwnd, int msg, int wParam, int 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 wParam, int lParam) {
- super.WM_ERASEBKGND (wParam, lParam);
- drawBackground (wParam);
- return LRESULT.ONE;
-}
-
-LRESULT WM_KILLFOCUS (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_SETFOCUS (int wParam, int lParam) {
- OS.SetFocus (hwndText);
- return null;
-}
-
-LRESULT WM_SETFONT (int wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_SIZE (wParam, lParam);
- if (isDisposed ()) return result;
- int width = lParam & 0xFFFF, height = lParam >> 16;
- 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 hwnd, int wParam, int 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 (wParam) {
- case SWT.CR:
- postEvent (SWT.DefaultSelection);
- // FALL THROUGH
- case SWT.TAB:
- case SWT.ESC: return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT wmClipboard (int hwndText, int msg, int wParam, int 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 oldText = null, 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.SendMessage (hwndText, OS.EM_GETSEL, start, end);
- 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);
- ignoreModify = false;
- }
- break;
- }
- if (newText != null && !newText.equals (oldText)) {
- 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 hHeap = OS.GetProcessHeap ();
- int byteCount = buffer.length () * TCHAR.sizeof;
- int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- int 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 wParam, int lParam) {
- int code = wParam >> 16;
- switch (code) {
- case OS.EN_CHANGE:
- if (ignoreModify) break;
- int value = getSelectionText ();
- if (value != -1) {
- int pos;
- if (OS.IsWinCE) {
- pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF;
- } else {
- pos = 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 hwnd, int wParam, int 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 (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) {
- int value = getSelectionText ();
- if (value != -1) {
- if (OS.IsWinCE) {
- value = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF;
- } else {
- value = 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 (wParam) {
- case OS.VK_UP:
- case OS.VK_DOWN:
- return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT wmKillFocus (int hwnd, int wParam, int lParam) {
- int value = getSelectionText ();
- if (value == -1) {
- if (OS.IsWinCE) {
- value = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF;
- } else {
- value = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
- }
- setSelection (value, false, true, false);
- }
- return super.wmKillFocus (hwnd, wParam, lParam);
-}
-
-LRESULT wmNotifyChild(int wParam, int lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- 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 explicity 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 (wParam, lParam);
-}
-
-LRESULT wmScrollChild (int wParam, int lParam) {
- int code = wParam & 0xFFFF;
- 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 77a713d28e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java
+++ /dev/null
@@ -1,933 +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.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 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>
- */
-public class TabFolder extends Composite {
- TabItem [] items;
- ImageList imageList;
- static final int 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 hInstance = OS.GetModuleHandle (null);
- int hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~(OS.CS_HREDRAW | OS.CS_VREDRAW | OS.CS_GLOBALCLASS);
- int byteCount = TabFolderClass.length () * TCHAR.sizeof;
- int 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 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 receiver's selection changes, 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 callWindowProc (int hwnd, int msg, int wParam, int 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 = 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 = 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 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 = 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 = 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 hDC, int hwnd, RECT rect) {
- RECT rect2 = new RECT ();
- OS.GetClientRect (handle, rect2);
- OS.MapWindowPoints (handle, hwnd, rect2, 2);
- int hTheme = OS.OpenThemeData (handle, TAB);
- OS.DrawThemeBackground (hTheme, hDC, OS.TABP_BODY, 0, rect2, null);
- OS.CloseThemeData (hTheme);
-}
-
-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 = OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index < count)) 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 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 = 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 = 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 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 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 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 (TabItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = 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 = 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 = 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 = 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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 = 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 = 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 = OS.SendMessage (handle, OS.TCM_GETCURSEL, 0, 0);
- 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 = 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 = hdr.idFrom;
- int hwndToolTip = OS.SendMessage (handle, OS.TCM_GETTOOLTIPS, 0, 0);
- if (hwndToolTip == hdr.hwndFrom) {
- 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 windowProc () {
- return TabFolderProc;
-}
-
-LRESULT WM_GETDLGCODE (int wParam, int 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);
-}
-
-LRESULT WM_NCHITTEST (int wParam, int 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 hittest = OS.DefWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam);
- return new LRESULT (hittest);
-}
-
-LRESULT WM_NOTIFY (int wParam, int 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 wParam, int 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 = wParam & 0xFFFF;
- switch (code) {
- case OS.WM_CREATE: {
- int id = (wParam >> 16), 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 wParam, int 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 = 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 wParam, int 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 (int wParam, int lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- int code = hdr.code;
- switch (code) {
- case OS.TCN_SELCHANGE:
- case OS.TCN_SELCHANGING:
- TabItem item = null;
- int index = 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 (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 040584bf2e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabItem.java
+++ /dev/null
@@ -1,331 +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.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>
- */
-
-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 hwnd = parent.handle;
- int hHeap = OS.GetProcessHeap ();
- TCHAR buffer = new TCHAR (parent.getCodePage (), string, true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- int 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 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);
- if (index != parent.getSelectionIndex ()) {
- if (newControl != null) 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 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 no tool tip text should be shown.
- *
- * @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 57686d13af..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java
+++ /dev/null
@@ -1,5519 +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.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 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 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>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL</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>
- */
-
-public class Table extends Composite {
- TableItem [] items;
- TableColumn [] columns;
- int columnCount, customCount;
- ImageList imageList, headerImageList;
- TableItem currentItem;
- TableColumn sortColumn;
- boolean ignoreCustomDraw, ignoreDrawForeground, ignoreDrawBackground, ignoreDrawSelection;
- boolean customDraw, dragStarted, fixScrollWidth, tipRequested, wasSelected, wasResized;
- boolean ignoreActivate, ignoreSelect, ignoreShrink, ignoreResize, ignoreColumnMove, ignoreColumnResize;
- int headerToolTipHandle, itemHeight, lastIndexOf, lastWidth, sortDirection, resizeCount, selectionForeground;
- static /*final*/ int 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 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 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:
- customDraw = true;
- style |= SWT.DOUBLE_BUFFERED;
- setBackgroundTransparent (true);
- //TODO - LVS_EX_LABELTIP causes white rectangles (turn it off)
- 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 receiver's selection changes, 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 <code>SWT.CHECK</code> style set 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 callWindowProc (int hwnd, int msg, int wParam, int lParam) {
- return callWindowProc (hwnd, msg, wParam, lParam, false);
-}
-
-int callWindowProc (int hwnd, int msg, int wParam, int lParam, boolean forceSelect) {
- if (handle == 0) return 0;
- if (handle != hwnd) {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwnd == hwndHeader) {
- 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 && drawCount == 0 && 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:
- checkSelection = true;
- //FALL THROUGH
-
- /* Other messages */
- case OS.WM_SETFONT:
- case OS.WM_TIMER: {
- if (findImageControl () != null) {
- topIndex = OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0);
- }
- }
- }
- boolean oldSelected = wasSelected;
- if (checkSelection) wasSelected = false;
- if (checkActivate) ignoreActivate = true;
- int code = OS.CallWindowProc (TableProc, hwnd, msg, wParam, lParam);
- if (checkActivate) ignoreActivate = false;
- if (checkSelection) {
- if (wasSelected || forceSelect) {
- Event event = new Event ();
- int index = 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.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.InvalidateRect (handle, null, true);
- int 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);
- }
- }
- }
- }
- return code;
-}
-
-static int checkStyle (int style) {
- /*
- * But in Windows. For some reason, when a table
- * has the LVS_OWNERDATA style and does not have
- * the LVS_EX_FULLROWSELECT extended style, Windows
- * clips the selected item and shows '...'. The
- * fix is to force LVS_EX_FULLROWSELECT.
- *
- * NOTE: This only happens on Vista.
- */
- //TEMPORARY CODE
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
- if ((style & SWT.VIRTUAL) != 0) style |= SWT.FULL_SELECTION;
- }
- /*
- * Feature in Windows. It is not possible to create
- * a table that does not have scroll bars. Therefore,
- * no matter what style bits are specified, set the
- * H_SCROLL and V_SCROLL bits so that the SWT style
- * will match the widget that Windows creates.
- */
- style |= SWT.H_SCROLL | SWT.V_SCROLL;
- return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
-}
-
-LRESULT CDDS_ITEMPREPAINT (int wParam, int lParam) {
- return new LRESULT (OS.CDRF_NOTIFYSUBITEMDRAW | OS.CDRF_NOTIFYPOSTPAINT);
-}
-
-LRESULT CDDS_POSTPAINT (int wParam, int 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 ((style & SWT.FULL_SELECTION) != 0) {
- if (OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) {
- int dwExStyle = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((dwExStyle & OS.LVS_EX_FULLROWSELECT) == 0) {
- int bits = OS.LVS_EX_FULLROWSELECT;
- 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 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);
- }
- }
- }
- }
- }
- return null;
-}
-
-LRESULT CDDS_PREPAINT (int wParam, int 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 ((style & SWT.FULL_SELECTION) != 0) {
- if (OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) {
- int dwExStyle = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((dwExStyle & OS.LVS_EX_FULLROWSELECT) != 0) {
- int bits = OS.LVS_EX_FULLROWSELECT;
- 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 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);
- }
- }
- }
- }
- }
- if (OS.IsWindowVisible (handle)) {
- Control control = findBackgroundControl ();
- if (control != null && control.backgroundImage != null) {
- NMLVCUSTOMDRAW nmcd = new NMLVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMLVCUSTOMDRAW.sizeof);
- RECT rect = new RECT ();
- OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- fillImageBackground (nmcd.hdc, control, rect);
- } else {
- if (OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) == OS.CLR_NONE) {
- if (OS.IsWindowEnabled (handle)) {
- NMLVCUSTOMDRAW nmcd = new NMLVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMLVCUSTOMDRAW.sizeof);
- 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);
- }
- }
- }
- }
- return new LRESULT (OS.CDRF_NOTIFYITEMDRAW | OS.CDRF_NOTIFYPOSTPAINT);
-}
-
-LRESULT CDDS_SUBITEMPOSTPAINT (int wParam, int lParam) {
- if (ignoreCustomDraw) return null;
- NMLVCUSTOMDRAW nmcd = new NMLVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMLVCUSTOMDRAW.sizeof);
- int hDC = nmcd.hdc;
- if (ignoreDrawForeground) OS.RestoreDC (hDC, -1);
- if (OS.IsWindowVisible (handle)) {
- if (hooks (SWT.PaintItem)) {
- TableItem item = _getItem (nmcd.dwItemSpec);
- sendPaintItemEvent (item, nmcd);
- //widget could be disposed at this point
- }
- }
- return null;
-}
-
-LRESULT CDDS_SUBITEMPREPAINT (int wParam, int lParam) {
- NMLVCUSTOMDRAW nmcd = new NMLVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMLVCUSTOMDRAW.sizeof);
- /*
- * 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 (nmcd.dwItemSpec);
- if (item == null) return null;
- if (ignoreCustomDraw) {
- int hDC = nmcd.hdc;
- int hFont = item.cellFont != null ? item.cellFont [nmcd.iSubItem] : -1;
- if (hFont == -1) hFont = item.font;
- if (hFont != -1) OS.SelectObject (hDC, hFont);
- return new LRESULT (hFont == -1 ? OS.CDRF_DODEFAULT : OS.CDRF_NEWFONT);
- }
- int code = OS.CDRF_DODEFAULT;
- selectionForeground = -1;
- ignoreDrawForeground = ignoreDrawSelection = ignoreDrawBackground = false;
- if (OS.IsWindowVisible (handle)) {
- if (hooks (SWT.MeasureItem)) {
- sendMeasureItemEvent (item, nmcd.dwItemSpec, nmcd.iSubItem, nmcd.hdc);
- if (isDisposed () || item.isDisposed ()) return null;
- }
- if (hooks (SWT.EraseItem)) {
- sendEraseItemEvent (item, nmcd, lParam);
- if (isDisposed () || item.isDisposed ()) return null;
- code |= OS.CDRF_NOTIFYPOSTPAINT;
- }
- if (ignoreDrawForeground || hooks (SWT.PaintItem)) code |= OS.CDRF_NOTIFYPOSTPAINT;
- }
- int hDC = nmcd.hdc;
- int hFont = item.cellFont != null ? item.cellFont [nmcd.iSubItem] : -1;
- if (hFont == -1) hFont = item.font;
- 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 (!ignoreDrawSelection && (style & SWT.FULL_SELECTION) != 0) {
- int bits = 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 = nmcd.dwItemSpec;
- int result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- if ((result != 0 && (lvItem.state & OS.LVIS_SELECTED) != 0)) {
- if (OS.GetFocus () == handle) {
- clrText = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT);
- clrTextBk = OS.GetSysColor (OS.COLOR_HIGHLIGHT);
- } else {
- if ((style & SWT.HIDE_SELECTION) == 0) {
- clrTextBk = OS.GetSysColor (OS.COLOR_3DFACE);
- }
- }
- if (clrTextBk != -1 && nmcd.iSubItem == 0) {
- RECT itemRect = new RECT ();
- itemRect.left = OS.LVIR_SELECTBOUNDS;
- ignoreCustomDraw = true;
- result = OS.SendMessage (handle, OS. LVM_GETITEMRECT, nmcd.dwItemSpec, itemRect);
- ignoreCustomDraw = false;
- if (result != 0) {
- RECT headerRect = new RECT ();
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, 0, headerRect) != 0) {
- OS.MapWindowPoints (hwndHeader, handle, headerRect, 2);
- itemRect.left = itemRect.right;
- itemRect.right = headerRect.right;
- fillBackground (hDC, clrTextBk, itemRect);
- }
- }
- }
- }
- }
- }
- }
- if (!ignoreDrawForeground) {
- /*
- * Bug in Windows. When the attibutes 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 hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int count = 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) {
- nmcd.clrTextBk = control.getBackgroundPixel ();
- }
- }
- } else {
- nmcd.clrTextBk = selectionForeground != -1 ? OS.CLR_NONE : clrTextBk;
- }
- OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
- }
- code |= OS.CDRF_NEWFONT;
- }
- }
- /*
- * 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.
- */
- if (!OS.IsWindowEnabled (handle)) {
- 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 hwnd) {
- if (hwnd == handle) return true;
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- return hwnd == hwndHeader;
-}
-
-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 = 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 && drawCount == 0 && 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 = 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 && drawCount == 0 && 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 = 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 && drawCount == 0 && 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 = 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 && drawCount == 0 && 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);
- int 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 = 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 result = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, -1, bits | 0xFFFF0000);
- int width = result & 0xFFFF;
- int empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
- int oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
- int itemHeight = (oneItem >> 16) - (empty >> 16);
- height += 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);
-
- /* Get the header window proc */
- if (HeaderProc == 0) {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- HeaderProc = OS.GetWindowLong (hwndHeader, OS.GWL_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 recomended 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 empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
- int oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
- int width = (oneItem >> 16) - (empty >> 16), 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 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 hHeap = OS.GetProcessHeap ();
- int 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_SUBITEMIMAGES | 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)) return;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- int 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);
- }
-}
-
-void createHeaderToolTips () {
- if (OS.IsWinCE) return;
- if (headerToolTipHandle != 0) return;
- headerToolTipHandle = OS.CreateWindowEx (
- 0,
- new TCHAR (0, OS.TOOLTIPS_CLASS, true),
- null,
- 0,
- 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 = 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 = 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) {
- int [] cellFont = item.cellFont;
- int [] temp = new int [columnCount + 1];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index + 1, columnCount - index);
- temp [index] = -1;
- 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 hHeap = OS.GetProcessHeap ();
- int byteCount = cchTextMax * TCHAR.sizeof;
- int 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);
- }
- if ((parent.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 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 = 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 = drawCount == 0 && 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 = true;
- int result = OS.SendMessage (handle, OS.LVM_INSERTITEM, 0, lvItem);
- ignoreSelect = 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 = -1;
- items = new TableItem [4];
- columns = new TableColumn [4];
- /*
- * Force virtual tables to use custom draw. This
- * is necessary to support colors and fonts for table
- * items. When the application is queried for data,
- * setting the custom draw flag at that time is too
- * late. The current item is not redrawn in order
- * to avoid recursion and NM_CUSTOMDRAW has already
- * been avoided because at the time of the message,
- * there were no items that required custom drawing.
- */
- if ((style & SWT.VIRTUAL) != 0) customDraw = true;
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_WINDOW);
-}
-
-void deregister () {
- super.deregister ();
- int 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 = 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 = 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 hHeap = OS.GetProcessHeap ();
- int byteCount = cchTextMax * TCHAR.sizeof;
- int 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 hHeap = OS.GetProcessHeap ();
- int 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 | OS.HDI_IMAGE;
- hdItem.fmt &= ~(OS.HDF_SORTUP | OS.HDF_SORTDOWN | OS.HDF_IMAGE);
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
- }
- }
- if ((parent.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 = 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 = 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) {
- int [] cellFont = item.cellFont;
- int [] temp = new int [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 = 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 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 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 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 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 = 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 hOldList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);
- if (hOldList != 0) return;
- int 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 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 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 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 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 = 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);
- LVHITTESTINFO pinfo = new LVHITTESTINFO ();
- pinfo.x = point.x; pinfo.y = point.y;
- OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
- if (pinfo.iItem != -1) 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 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's.
- *
- * @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 empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
- int oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
- return (oneItem >> 16) - (empty >> 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 ();
- int count = 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.
- * <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 = 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 = OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0);
- TableItem [] result = new TableItem [count];
- while ((i = 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 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 = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
- int selectedIndex = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_SELECTED);
- if (focusIndex == selectedIndex) return selectedIndex;
- int i = -1;
- while ((i = 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 = OS.SendMessage (handle, OS.LVM_GETSELECTEDCOUNT, 0, 0);
- int [] result = new int [count];
- while ((i = 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;
-}
-
-/**
- * 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, OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0));
-}
-
-boolean hasChildren () {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int hwndChild = OS.GetWindow (handle, OS.GW_CHILD);
- while (hwndChild != 0) {
- if (hwndChild != hwndHeader) return true;
- hwndChild = OS.GetWindow (hwndChild, OS.GW_HWNDNEXT);
- }
- return false;
-}
-
-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.indexOf (image);
- if (index == -1) index = imageList.add (image);
- int 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 hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int 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 hImageList = headerImageList.getHandle ();
- int 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 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 (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 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 (TableItem item) {
- checkWidget ();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int count = 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;
-}
-
-/**
- * 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 visibility 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 result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- return (result != 0) && ((lvItem.state & OS.LVIS_SELECTED) != 0);
-}
-
-void register () {
- super.register ();
- int 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 = 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 hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.HDM_SETIMAGELIST, 0, 0);
- display.releaseImageList (headerImageList);
- }
- imageList = headerImageList = null;
- int 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 = 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 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 = 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 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 = 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 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 = 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 = drawCount == 0 && OS.IsWindowVisible (handle);
- if (redraw) OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- int index = itemCount - 1;
- while (index >= 0) {
- ignoreSelect = ignoreShrink = true;
- int 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 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 receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 = 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 lParam) {
- int hDC = nmcd.hdc;
- int hFont = item.cellFont != null ? item.cellFont [nmcd.iSubItem] : -1;
- if (hFont == -1) hFont = item.font;
- 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;
- /*
- * 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 = nmcd.dwItemSpec;
- int 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;
- if (OS.IsWindowEnabled (handle)) {
- if (selected && (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0)) {
- if (OS.GetFocus () == handle) {
- 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);
- }
- } else {
- drawBackground = clrTextBk != -1;
- /*
- * Bug in Windows. When LVM_SETTEXTBKCOLOR or LVM_SETBKCOLOR
- * 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 background
- * color.
- */
- if (clrTextBk == -1) {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- 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.hPen = OS.CreatePen (OS.PS_SOLID, 0, data.foreground);
- data.hBrush = OS.CreateSolidBrush (data.background);
- data.hFont = hFont;
- int nSavedDC = OS.SaveDC (hDC);
- GC gc = GC.win32_new (hDC, data);
- RECT cellRect = item.getBounds (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 (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) {
- if (handle == OS.GetFocus ()) {
- int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED;
- }
- }
- }
- 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 = OS.GetTextColor (hDC);
- 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;
- } else {
- ignoreDrawForeground = ignoreDrawBackground = ignoreDrawSelection = true;
- }
- if (drawSelected) {
- if (ignoreDrawSelection) {
- if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) {
- selectionForeground = clrSelectionText;
- }
- nmcd.uItemState &= ~(OS.CDIS_SELECTED | OS.CDIS_FOCUS);
- OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
- }
- } else {
- if (ignoreDrawSelection) {
- nmcd.uItemState |= OS.CDIS_SELECTED;
- OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
- }
- }
- if (ignoreDrawForeground) {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- boolean firstColumn = nmcd.iSubItem == OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0);
- boolean fullText = (style & SWT.FULL_SELECTION) != 0 || !firstColumn;
- RECT clipRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, true, fullText, false, hDC);
- if (!ignoreDrawBackground && drawBackground) {
- RECT backgroundRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, false, true, false, hDC);
- fillBackground (hDC, clrTextBk, backgroundRect);
- }
- if (!ignoreDrawSelection && clrSelectionBk != -1) {
- RECT textRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, false, fullText, false, hDC);
- fillBackground (hDC, clrSelectionBk, textRect);
- }
- OS.SaveDC (hDC);
- OS.SelectClipRgn (hDC, 0);
- OS.ExcludeClipRect (hDC, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
- }
-}
-
-Event sendMeasureItemEvent (TableItem item, int row, int column, int hDC) {
- int hFont = item.cellFont != null ? item.cellFont [column] : -1;
- if (hFont == -1) hFont = item.font;
- GCData data = new GCData ();
- data.device = display;
- data.hFont = hFont;
- 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 = OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
- if (event.x + event.width > width) {
- OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, event.x + event.width);
- }
- }
- if (event.height > getItemHeight ()) setItemHeight (event.height);
- }
- return event;
-}
-
-LRESULT sendMouseDownEvent (int type, int button, int msg, int wParam, int lParam) {
- /*
- * 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 = (short) (lParam & 0xFFFF);
- pinfo.y = (short) (lParam >> 16);
- OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
- 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;
- }
-
- /*
- * 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 (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 mark it as selected.
- */
- boolean forceSelect = false;
- int count = 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;
- }
- }
- dragStarted = false;
- int code = callWindowProc (handle, msg, wParam, lParam, forceSelect);
- if (dragStarted) {
- 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);
- }
- }
- dragStarted = false;
- return new LRESULT (code);
-}
-
-void sendPaintItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd) {
- int hDC = nmcd.hdc;
- GCData data = new GCData ();
- data.device = display;
- int hFont = item.cellFont != null ? item.cellFont [nmcd.iSubItem] : -1;
- if (hFont == -1) hFont = item.font;
- data.hFont = hFont;
- /*
- * 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 = nmcd.dwItemSpec;
- int result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- boolean selected = result != 0 && (lvItem.state & OS.LVIS_SELECTED) != 0;
- boolean drawSelected = false, drawBackground = false;
- if (OS.IsWindowEnabled (handle)) {
- if (selected && (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0)) {
- if (OS.GetFocus () == handle) {
- drawSelected = true;
- data.foreground = selectionForeground != -1 ? selectionForeground : 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);
- }
- } 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 or LVM_SETBKCOLOR
- * 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 background
- * color.
- */
- if (clrTextBk == -1) {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- 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.hPen = OS.CreatePen (OS.PS_SOLID, 0, data.foreground);
- data.hBrush = OS.CreateSolidBrush (data.background);
- int nSavedDC = OS.SaveDC (hDC);
- GC gc = GC.win32_new (hDC, data);
- RECT itemRect = item.getBounds (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 (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) {
- if (handle == OS.GetFocus ()) {
- int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED;
- }
- }
- }
- 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 (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);
- event.gc = null;
- gc.dispose ();
- OS.RestoreDC (hDC, nSavedDC);
-}
-
-void setBackgroundImage (int hBitmap) {
- super.setBackgroundImage (hBitmap);
- setBackgroundTransparent (hBitmap != 0);
-}
-
-void setBackgroundPixel (int newPixel) {
- if (findImageControl () != null) return;
- if (newPixel == -1) newPixel = defaultBackground ();
- int oldPixel = OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0);
- 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 = 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 ((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) {
- setBackgroundPixel (control.getBackgroundPixel ());
- }
- /* Set LVS_EX_FULLROWSELECT */
- if ((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 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 setDeferResize (boolean defer) {
- if (defer) {
- if (resizeCount++ == 0) {
- wasResized = false;
- }
- } else {
- if (--resizeCount == 0) {
- 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 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 hStateList = OS.ImageList_Create (width, height, flags, count, count);
- int hDC = OS.GetDC (handle);
- int memDC = OS.CreateCompatibleDC (hDC);
- int hBitmap = OS.CreateCompatibleBitmap (hDC, width * count, height);
- int 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 hBrush = OS.CreateSolidBrush (clrBackground);
- OS.FillRect (memDC, rect, hBrush);
- OS.DeleteObject (hBrush);
- int 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 hTheme = OS.OpenThemeData (handle, BUTTON);
- 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);
- OS.CloseThemeData (hTheme);
- } 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 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);
- 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 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 = 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 = 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 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 virutal 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 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.
- *
- * @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);
- 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.
- * <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 = 0;
- if (show) {
- newBits = OS.LVS_EX_GRIDLINES;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.LVS_NOCOLUMNHEADER) == 0) fixItemHeight (true);
- }
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_GRIDLINES, newBits);
-}
-
-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 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 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 ();
- }
- }
-}
-
-boolean setScrollWidth (TableItem item, boolean force) {
- return setScrollWidth (item, force, false);
-}
-
-boolean setScrollWidth (TableItem item, boolean force, boolean fixRedraw) {
- if (currentItem != null) {
- if (currentItem != item) fixScrollWidth = true;
- return false;
- }
- if (!force && (drawCount != 0 || !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 = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- while (index < itemCount) {
- String string = null;
- int font = -1;
- if (item != null) {
- string = item.text;
- imageIndent = Math.max (imageIndent, item.imageIndent);
- if (item.cellFont != null) font = item.cellFont [0];
- if (font == -1) font = item.font;
- } else {
- if (items [index] != null) {
- TableItem tableItem = items [index];
- string = tableItem.text;
- imageIndent = Math.max (imageIndent, tableItem.imageIndent);
- if (tableItem.cellFont != null) font = tableItem.cellFont [0];
- if (font == -1) font = tableItem.font;
- }
- }
- if (string != null && string.length () != 0) {
- if (font != -1) {
- int hDC = OS.GetDC (handle);
- int oldFont = OS.SelectObject (hDC, font);
- 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, 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, OS.SendMessage (handle, OS.LVM_GETSTRINGWIDTH, 0, buffer));
- }
- int 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 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 = OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
- if (newWidth > oldWidth) {
- /*
- * 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 = fixRedraw && drawCount == 0 && OS.IsWindowVisible (handle);
- if (redraw) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, newWidth);
- if (redraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- if (OS.IsWinCE) {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwndHeader != 0) OS.InvalidateRect (hwndHeader, null, false);
- OS.InvalidateRect (handle, null, false);
- } else {
- int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- }
- }
- 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 = 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 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 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 hHeaderImageList = headerImageList.getHandle ();
- int 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 ((style & SWT.VIRTUAL) == 0) {
- if (!hooks (SWT.MeasureItem) && !hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) {
- customDraw = false;
- }
- }
- 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 = OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0);
- if (index == topIndex) return;
-
- /*
- * 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 = 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;
- }
- 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);
- }
- }
-}
-
-void showItem (int index) {
- /*
- * 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 = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_SELECTED);
- if (index != -1) showItem (index);
-}
-
-void subclass () {
- super.subclass ();
- if (HeaderProc != 0) {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SetWindowLong (hwndHeader, OS.GWL_WNDPROC, display.windowProc);
- }
-}
-
-String toolTipText (NMTTDISPINFO hdr) {
- int 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 hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.SetWindowLong (hwndHeader, OS.GWL_WNDPROC, HeaderProc);
- }
-}
-
-void updateHeaderToolTips () {
- if (headerToolTipHandle == 0) return;
- int 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 windowProc () {
- return TableProc;
-}
-
-int windowProc (int hwnd, int msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- if (hwnd != handle) {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hwnd == hwndHeader) {
- switch (msg) {
- /* This code is intentionally commented */
-// 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_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);
- }
- }
- }
- return callWindowProc (hwnd, msg, wParam, lParam);
- }
- }
- return super.windowProc (hwnd, msg, wParam, lParam);
-}
-
-LRESULT WM_CHAR (int wParam, int lParam) {
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
- switch (wParam) {
- case ' ':
- if ((style & SWT.CHECK) != 0) {
- int index = 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 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 = 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_ERASEBKGND (int wParam, int lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- if (findImageControl () != null) return LRESULT.ONE;
- if (OS.COMCTL32_MAJOR < 6) {
- if ((style & SWT.DOUBLE_BUFFERED) != 0) {
- int bits = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_DOUBLEBUFFER) == 0) return LRESULT.ONE;
- }
- }
- return result;
-}
-
-LRESULT WM_GETOBJECT (int wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- switch (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_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 oldHeaderProc = 0, oldTableProc = 0;
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- boolean fixSubclass = !hasChildren () && !hooks (SWT.Paint) && !filters (SWT.Paint);
- if (fixSubclass) {
- oldTableProc = OS.SetWindowLong (handle, OS.GWL_WNDPROC, TableProc);
- oldHeaderProc = OS.SetWindowLong (hwndHeader, OS.GWL_WNDPROC, HeaderProc);
- }
- int code = callWindowProc (handle, OS.WM_KEYDOWN, wParam, lParam);
- result = code == 0 ? LRESULT.ZERO : new LRESULT (code);
- if (fixSubclass) {
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldTableProc);
- OS.SetWindowLong (hwndHeader, OS.GWL_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 wParam, int lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- /*
- * Bug in Windows. When LVS_SHOWSELALWAYS is not specified,
- * Windows hides the selection when focus is lost but does
- * not redraw anything other than the text, leaving the image
- * and check box appearing selected. The fix is to redraw
- * the table.
- */
- if ((style & SWT.HIDE_SELECTION) != 0) {
- if (imageList != null || (style & SWT.CHECK) != 0) {
- OS.InvalidateRect (handle, null, false);
- }
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDBLCLK (int wParam, int 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 = (short) (lParam & 0xFFFF);
- pinfo.y = (short) (lParam >> 16);
- int index = 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 wParam, int 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 = (short) (lParam & 0xFFFF);
- pinfo.y = (short) (lParam >> 16);
- /*
- * 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 = 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 wParam, int 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 = 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 wParam, int lParam) {
- if (!ignoreShrink) {
- /* Resize the item array to match the item count */
- int count = 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.COMCTL32_MAJOR < 6) {
- if ((style & SWT.DOUBLE_BUFFERED) != 0 || findImageControl () != null) {
- int bits = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_DOUBLEBUFFER) == 0) {
- GC gc = null;
- int paintDC = 0;
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- if (hooks (SWT.Paint)) {
- 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);
- }
-
- //TODO - only double buffer the damage
-// int x = ps.left, y = ps.top;
-// int width = ps.right - ps.left;
-// int height = ps.bottom - ps.top;
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int x = rect.left, y = rect.top;
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
-
- int hDC = OS.CreateCompatibleDC (paintDC);
- int hBitmap = OS.CreateCompatibleBitmap (paintDC, width, height);
- int hOldBitmap = OS.SelectObject (hDC, hBitmap);
- if (OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0) != OS.CLR_NONE) {
- drawBackground (hDC, rect);
- }
- int code = callWindowProc (handle, OS.WM_PAINT, hDC, 0);
- OS.BitBlt (paintDC, x, y, width, height, hDC, 0, 0, OS.SRCCOPY);
- OS.SelectObject (hDC, hOldBitmap);
- OS.DeleteObject (hBitmap);
- OS.DeleteObject (hDC);
- if (hooks (SWT.Paint)) {
- 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;
- gc.dispose ();
- } else {
- OS.EndPaint (handle, ps);
- }
- return new LRESULT (code);
- }
- }
- }
- return super.WM_PAINT (wParam, lParam);
-}
-
-LRESULT WM_NOTIFY (int wParam, int lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- if (hdr.hwndFrom == hwndHeader) {
- /*
- * 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:
- if (column != null && 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 = 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 = 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 = OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, 0, 0);
- if (lastWidth == 0 && width > 0) {
- int bits = 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;
- }
- }
- }
- LRESULT result = super.WM_NOTIFY (wParam, lParam);
- if (result != null) return result;
- switch (hdr.code) {
- case OS.TTN_GETDISPINFOA:
- case OS.TTN_GETDISPINFOW: {
- tipRequested = true;
- int code = callWindowProc (handle, OS.WM_NOTIFY, wParam, lParam);
- tipRequested = false;
- return new LRESULT (code);
- }
- }
- return result;
-}
-
-LRESULT WM_RBUTTONDBLCLK (int wParam, int 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 = (short) (lParam & 0xFFFF);
- pinfo.y = (short) (lParam >> 16);
- 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 wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- /*
- * 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 = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (count == 0) return result;
- int index = 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 wParam, int lParam) {
- LRESULT result = super.WM_SETFONT (wParam, lParam);
- if (result != null) return result;
- if (headerToolTipHandle != 0) {
- OS.SendMessage (headerToolTipHandle, OS.WM_SETFONT, wParam, lParam);
- }
- return result;
-}
-
-LRESULT WM_SIZE (int wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
- if (result != null) return result;
- if (findBackgroundControl () == null) {
- setBackgroundPixel (defaultBackground ());
- } else {
- if ((style & SWT.CHECK) != 0) {
- fixCheckboxImageListColor (true);
- }
- }
- return result;
-}
-
-LRESULT WM_HSCROLL (int wParam, int 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 = 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;
- }
-
- /*
- * 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 oldHeaderProc = 0, oldTableProc = 0;
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- boolean fixSubclass = !hasChildren () && !hooks (SWT.Paint) && !filters (SWT.Paint);
- if (fixSubclass) {
- oldTableProc = OS.SetWindowLong (handle, OS.GWL_WNDPROC, TableProc);
- oldHeaderProc = OS.SetWindowLong (hwndHeader, OS.GWL_WNDPROC, HeaderProc);
- }
- LRESULT result = super.WM_HSCROLL (wParam, lParam);
- if (fixSubclass) {
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldTableProc);
- OS.SetWindowLong (hwndHeader, OS.GWL_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 wParam, int 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 oldHeaderProc = 0, oldTableProc = 0;
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- boolean fixSubclass = !hasChildren () && !hooks (SWT.Paint) && !filters (SWT.Paint);
- if (fixSubclass) {
- oldTableProc = OS.SetWindowLong (handle, OS.GWL_WNDPROC, TableProc);
- oldHeaderProc = OS.SetWindowLong (hwndHeader, OS.GWL_WNDPROC, HeaderProc);
- }
- LRESULT result = super.WM_VSCROLL (wParam, lParam);
- if (fixSubclass) {
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldTableProc);
- OS.SetWindowLong (hwndHeader, OS.GWL_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 = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_GRIDLINES) != 0) {
- int code = wParam & 0xFFFF;
- 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:
- int headerHeight = 0;
- if (hwndHeader != 0) {
- RECT rect = new RECT ();
- OS.GetWindowRect (hwndHeader, rect);
- headerHeight = rect.bottom - rect.top;
- }
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- rect.top += headerHeight;
- int empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
- int oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
- int itemHeight = (oneItem >> 16) - (empty >> 16);
- if (code == OS.SB_LINEDOWN) {
- rect.top = rect.bottom - itemHeight - GRID_WIDTH;
- } else {
- rect.bottom = rect.top + itemHeight + GRID_WIDTH;
- }
- OS.InvalidateRect (handle, rect, true);
- break;
- case OS.SB_PAGEDOWN:
- case OS.SB_PAGEUP:
- OS.InvalidateRect (handle, null, true);
- break;
- }
- }
- return result;
-}
-
-LRESULT wmMeasureChild (int wParam, int lParam) {
- MEASUREITEMSTRUCT struct = new MEASUREITEMSTRUCT ();
- OS.MoveMemory (struct, lParam, MEASUREITEMSTRUCT.sizeof);
- if (itemHeight == -1) {
- int empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0);
- int oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0);
- struct.itemHeight = (oneItem >> 16) - (empty >> 16);
- } else {
- struct.itemHeight = itemHeight;
- }
- OS.MoveMemory (lParam, struct, MEASUREITEMSTRUCT.sizeof);
- return null;
-}
-
-LRESULT wmNotifyChild (int wParam, int lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- switch (hdr.code) {
- case OS.LVN_ODFINDITEMA:
- case OS.LVN_ODFINDITEMW: {
- if ((style & SWT.VIRTUAL) != 0) return new LRESULT (-1);
- 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);
-
- /*
- * 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, 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.
- */
- if (!tipRequested && string.length () == 0 && plvfi.iSubItem == 0) {
- string = " "; //$NON-NLS-1$
- }
- TCHAR buffer = new TCHAR (getCodePage (), string, false);
- int byteCount = Math.min (buffer.length (), plvfi.cchTextMax - 1) * TCHAR.sizeof;
- OS.MoveMemory (plvfi.pszText, buffer, byteCount);
- OS.MoveMemory (plvfi.pszText + byteCount, new byte [TCHAR.sizeof], TCHAR.sizeof);
- plvfi.cchTextMax = Math.min (plvfi.cchTextMax, string.length () + 1);
- }
- }
- 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);
- }
- 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;
- }
- }
- if ((plvfi.mask & OS.LVIF_INDENT) != 0) {
- if (plvfi.iSubItem == 0) plvfi.iIndent = item.imageIndent;
- }
- OS.MoveMemory (lParam, plvfi, NMLVDISPINFO.sizeof);
- break;
- }
- case OS.NM_CUSTOMDRAW: {
- int 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)) break;
- }
- NMLVCUSTOMDRAW nmcd = new NMLVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMLVCUSTOMDRAW.sizeof);
- switch (nmcd.dwDrawStage) {
- case OS.CDDS_PREPAINT: return CDDS_PREPAINT (wParam, lParam);
- case OS.CDDS_ITEMPREPAINT: return CDDS_ITEMPREPAINT (wParam, lParam);
- case OS.CDDS_SUBITEMPREPAINT: return CDDS_SUBITEMPREPAINT (wParam, lParam);
- case OS.CDDS_SUBITEMPOSTPAINT: return CDDS_SUBITEMPOSTPAINT (wParam, lParam);
- case OS.CDDS_POSTPAINT: return CDDS_POSTPAINT (wParam, lParam);
- }
- break;
- }
- case OS.LVN_MARQUEEBEGIN: return LRESULT.ONE;
- case OS.LVN_BEGINDRAG:
- case OS.LVN_BEGINRDRAG: {
- dragStarted = true;
- if (hdr.code == OS.LVN_BEGINDRAG) {
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT ();
- pt.x = (short) (pos & 0xFFFF);
- pt.y = (short) (pos >> 16);
- OS.ScreenToClient (handle, pt);
- sendDragEvent (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 (!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 hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int count = 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 = 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 (wParam, lParam);
-}
-
-}
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 b58bdef327..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java
+++ /dev/null
@@ -1,850 +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.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>
- */
-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>
- *
- * @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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 hwnd = parent.handle;
- return 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 hwnd = parent.handle;
- int oldWidth = OS.SendMessage (hwnd, OS.LVM_GETCOLUMNWIDTH, index, 0);
- TCHAR buffer = new TCHAR (parent.getCodePage (), text, true);
- int headerWidth = 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.NULL) {
- 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 hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- margin = 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 hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- OS.MapWindowPoints (hwndHeader, hwnd, headerRect, 2);
- int hDC = OS.GetDC (hwnd);
- int oldFont = 0, newFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
- if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
- int count = OS.SendMessage (hwnd, OS.LVM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; i++) {
- TableItem item = parent.items [i];
- if (item != null) {
- int hFont = item.cellFont != null ? item.cellFont [index] : -1;
- if (hFont == -1) hFont = item.font;
- 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 = 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 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 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 = 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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>.
- *
- * @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 hwnd = parent.handle;
- LVCOLUMN lvColumn = new LVCOLUMN ();
- lvColumn.mask = OS.LVCF_FMT | OS.LVCF_IMAGE;
- 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 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.NULL) {
- setImage (image, false, false);
- }
-}
-
-void setImage (Image image, boolean sort, boolean right) {
- int index = parent.indexOf (this);
- if (index == -1) return;
- int hwnd = parent.handle;
- if (OS.COMCTL32_MAJOR < 6) {
- int 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.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 hwnd = parent.handle;
- int 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;
- break;
- case SWT.DOWN:
- hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_SORTUP);
- hdItem.fmt |= OS.HDF_SORTDOWN;
- 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;
- }
- break;
- }
- OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
- /*
- * 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.
- */
- if (OS.SendMessage (hwnd, OS.LVM_GETBKCOLOR, 0, 0) != OS.CLR_NONE) {
- int oldColumn = OS.SendMessage (hwnd, OS.LVM_GETSELECTEDCOLUMN, 0, 0);
- int newColumn = direction == SWT.NONE ? -1 : index;
- OS.SendMessage (hwnd, OS.LVM_SETSELECTEDCOLUMN, newColumn, 0);
- /*
- * 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.
- */
- parent.forceResize ();
- RECT rect = new RECT (), headerRect = new RECT ();
- OS.GetClientRect (hwnd, 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);
- }
- }
- if (newColumn != -1) {
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, newColumn, 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 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 hHeap = OS.GetProcessHeap ();
- TCHAR buffer = new TCHAR (parent.getCodePage (), fixMnemonic (string), true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- lvColumn.mask |= OS.LVCF_TEXT;
- lvColumn.pszText = pszText;
- int 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 no tool tip text should be shown.
- *
- * @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 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 ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- int hwnd = parent.handle;
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, width);
-}
-
-void updateToolTip (int index) {
- int hwndHeaderToolTip = parent.headerToolTipHandle;
- if (hwndHeaderToolTip != 0) {
- int hwnd = parent.handle;
- int 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 3aa24cc374..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java
+++ /dev/null
@@ -1,1143 +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.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>
- */
-
-public class TableItem extends Item {
- Table parent;
- String [] strings;
- Image [] images;
- boolean checked, grayed, cached;
- int imageIndent, background = -1, foreground = -1, font = -1;
- int [] cellBackground, cellForeground, cellFont;
-
-/**
- * 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;
- background = foreground = font = -1;
- cellBackground = cellForeground = cellFont = null;
- if ((parent.style & SWT.VIRTUAL) != 0) cached = false;
-}
-
-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);
- 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 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 hwnd = parent.handle;
- int bits = OS.SendMessage (hwnd, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if (column == 0 && (bits & OS.LVS_EX_FULLROWSELECT) == 0) {
- if (getText && getImage) {
- rect.left = OS.LVIR_SELECTBOUNDS;
- } else {
- rect.left = getText ? OS.LVIR_LABEL : OS.LVIR_ICON;
- }
- parent.ignoreCustomDraw = true;
- int 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 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 documenation 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 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;
- }
- } else {
- rect.left = OS.LVIR_ICON;
- parent.ignoreCustomDraw = true;
- int 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 == -1 ? parent.getFont () : Font.win32_new (display, font);
-}
-
-/**
- * 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 ();
- int hFont = (cellFont != null) ? cellFont [index] : font;
- return hFont == -1 ? getFont () : 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>
- *
- * @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 "";
-}
-
-void redraw () {
- if (parent.currentItem == this || parent.drawCount != 0) return;
- int 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.drawCount != 0) return;
- int 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;
- cellBackground = cellForeground = 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);
- }
- 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.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.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 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);
- }
- int hFont = -1;
- if (font != null) {
- parent.customDraw = true;
- hFont = font.handle;
- }
- if (this.font == hFont) return;
- this.font = hFont;
- 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 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;
- int hFont = -1;
- if (font != null) {
- parent.customDraw = true;
- hFont = font.handle;
- }
- if (cellFont == null) {
- cellFont = new int [count];
- for (int i = 0; i < count; i++) {
- cellFont [i] = -1;
- }
- }
- if (cellFont [index] == hFont) return;
- cellFont [index] = hFont;
- 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 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.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.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.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 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);
-
- 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 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 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 5ee48589a6..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java
+++ /dev/null
@@ -1,2160 +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.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.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>CENTER, LEFT, MULTI, PASSWORD, 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.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
-public class Text extends Scrollable {
- int tabs, oldStart, oldEnd;
- boolean doubleClick, ignoreModify, ignoreVerify, ignoreCharacter;
-
- /**
- * 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 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 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 Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int callWindowProc (int hwnd, int msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam);
-}
-
-void createHandle () {
- super.createHandle ();
- OS.SendMessage (handle, OS.EM_LIMITTEXT, 0, 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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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.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 newFont, oldFont = 0;
- int 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 = 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 (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 margins = OS.SendMessage(handle, OS.EM_GETMARGINS, 0, 0);
- rect.x -= margins & 0xFFFF;
- rect.width += (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF);
- 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 ();
- 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 () {
- return OS.GetSysColor (OS.COLOR_WINDOW);
-}
-
-boolean dragDetect (int x, int y) {
- if (hooks (SWT.DragDetect)) {
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (start[0] < end[0]) {
- int pt = x | y << 16;
- int charFromPos = OS.SendMessage (handle, OS.EM_CHARFROMPOS, 0, pt);
- int position = charFromPos & 0xFFFF;
- return position > start [0] && position < end [0];
- }
- }
- return false;
-}
-
-boolean dragOverride () {
- return true;
-}
-
-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 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 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 ((short) (caretPos & 0xFFFF), (short) (caretPos >> 16));
-}
-
-/**
- * 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 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 = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, start [0], 0);
- int endLine = 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 endPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, end [0], 0);
- if (endPos == -1) {
- int startPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0);
- int startX = (short) (startPos & 0xFFFF);
- if (ptCurrentPos.x > startX) caret = end [0];
- } else {
- int endX = (short) (endPos & 0xFFFF);
- if (ptCurrentPos.x >= endX) caret = end [0];
- }
- }
- }
- }
- }
- } else {
- int caretPos = OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0);
- int caretLine = 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 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 newFont, oldFont = 0;
- int 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 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 oldFont = 0;
- RECT rect = new RECT ();
- int hDC = OS.GetDC (handle);
- int 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);
- start = Math.max (0, start);
- end = Math.min (end, length - 1);
- /*
- * 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 OS.SendMessage (handle, OS.EM_GETLIMITTEXT, 0, 0);
-}
-
-/**
- * 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 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 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 = OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0);
- for (int line=0; line<count; line++) {
- int wcsSize = 0;
- int linePos = OS.SendMessageA (handle, OS.EM_LINEINDEX, line, 0);
- int mbcsSize = 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 = 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);
-}
-
-/**
- * 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 wParam, int 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 = 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 = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, end [0], 0);
- int lineStart = 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 margins = OS.SendMessage (handle, OS.EM_GETMARGINS, 0, 0);
- int marginWidth = (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF);
- 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);
-}
-
-/**
- * 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);
-}
-
-/**
- * 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 (drawCount != 0) 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.GetDialogBaseUnits () & 0xFFFF);
- 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;
- }
- 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.
- */
- if ((style & SWT.MULTI) != 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 = OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0);
- index = Math.min (Math.max (index, 0), count - 1);
- int topIndex = 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 = OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0);
- for (int line=0; line<count; line++) {
- int wcsSize = 0;
- int linePos = OS.SendMessageA (handle, OS.EM_LINEINDEX, line, 0);
- int mbcsSize = 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 = 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) 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 windowProc () {
- return EditProc;
-}
-
-int windowProc (int hwnd, int msg, int wParam, int lParam) {
- if (msg == OS.EM_UNDO) {
- if ((style & SWT.SINGLE) != 0) {
- LRESULT result = wmClipboard (OS.EM_UNDO, wParam, lParam);
- if (result != null) return result.value;
- return callWindowProc (hwnd, OS.EM_UNDO, wParam, lParam);
- }
- }
- return super.windowProc (hwnd, msg, wParam, lParam);
-}
-
-LRESULT WM_CHAR (int wParam, int 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 (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 (wParam) {
- case SWT.CR:
- postEvent (SWT.DefaultSelection);
- // FALL THROUGH
- case SWT.TAB:
- case SWT.ESC: return LRESULT.ZERO;
- }
- }
- return result;
-}
-
-LRESULT WM_CLEAR (int wParam, int lParam) {
- LRESULT result = super.WM_CLEAR (wParam, lParam);
- if (result != null) return result;
- return wmClipboard (OS.WM_CLEAR, wParam, lParam);
-}
-
-LRESULT WM_CUT (int wParam, int lParam) {
- LRESULT result = super.WM_CUT (wParam, lParam);
- if (result != null) return result;
- return wmClipboard (OS.WM_CUT, wParam, lParam);
-}
-
-LRESULT WM_GETDLGCODE (int wParam, int 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 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 wParam, int lParam) {
-
- /* Process a DBCS character */
- Display display = this.display;
- display.lastKey = 0;
- display.lastAscii = 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 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 wParam, int 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 = OS.SendMessage (handle, OS.EM_LINELENGTH, length, 0);
- if (code == 0) return LRESULT.ZERO;
- }
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int wParam, int 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 = (short) (lParam & 0xFFFF);
- int y = (short) (lParam >> 16);
- 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 wParam, int lParam) {
- LRESULT result = super.WM_PASTE (wParam, lParam);
- if (result != null) return result;
- return wmClipboard (OS.WM_PASTE, wParam, lParam);
-}
-
-LRESULT WM_UNDO (int wParam, int 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 wParam, int 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;
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- 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);
- 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 wmCommandChild (int wParam, int lParam) {
- int code = wParam >> 16;
- switch (code) {
- case OS.EN_CHANGE:
- 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 4cb860bfb4..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java
+++ /dev/null
@@ -1,1341 +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.widgets;
-
-
-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>
- */
-public class ToolBar extends Composite {
- int lastFocusId;
- ToolItem [] items;
- boolean ignoreResize, ignoreMouse;
- ImageList imageList, disabledImageList, hotImageList;
- static final int 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 callWindowProc (int hwnd, int msg, int wParam, int 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 toobar 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 = 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 = drawCount == 0 && 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 = 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;
-}
-
-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 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 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 = 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 = -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 = 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;
- items [item.id] = null;
- item.id = -1;
- int count = 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 = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- TBBUTTON lpButton = new TBBUTTON ();
- int 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 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 ();
- int count = 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 OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- }
- return OS.SendMessage (handle, OS.TB_GETROWS, 0, 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);
- return 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 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) {
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_SIZE;
- int size = OS.SendMessage (handle, OS.TB_GETBUTTONSIZE, 0, 0);
- info.cx = (short) (size & 0xFFFF);
- 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 padding = OS.SendMessage (handle, OS.TB_GETPADDING, 0, 0);
- info.cx += (padding & 0xFFFF) * 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 = 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 = 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 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 puropse of DeferWindowPos (). The fix is to end the
- * defered 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 (drawCount == 0 && 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
- * both text and 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 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 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 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;
- OS.SendMessage (handle, OS.TB_SETPARENT, parent.handle, 0);
- 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, (1 << 16) | count, 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;
- }
-}
-
-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 = hdr.idFrom;
- int hwndToolTip = OS.SendMessage (handle, OS.TB_GETTOOLTIPS, 0, 0);
- if (hwndToolTip == hdr.hwndFrom) {
- if (toolTipText != null) return ""; //$NON-NLS-1$
- if (0 <= index && index < items.length) {
- ToolItem item = items [index];
- if (item != null) 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 windowProc () {
- return ToolBarProc;
-}
-
-LRESULT WM_CAPTURECHANGED (int wParam, int 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 in WM_LBUTTONDOWN, the item remains pressed.
- * The fix is unpress the item using TB_SETSTATE.
- */
- if (OS.GetKeyState (OS.VK_LBUTTON) < 0) {
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null) {
- int fsState = 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 null;
-}
-
-LRESULT WM_CHAR (int wParam, int lParam) {
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
- switch (wParam) {
- case ' ':
- int index = OS.SendMessage (handle, OS.TB_GETHOTITEM, 0, 0);
- if (index != -1) {
- TBBUTTON lpButton = new TBBUTTON ();
- int 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 wParam, int 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 wParam, int 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 wParam, int 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);
-}
-
-LRESULT WM_KEYDOWN (int wParam, int lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- switch (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 wParam, int lParam) {
- int index = OS.SendMessage (handle, OS.TB_GETHOTITEM, 0, 0);
- TBBUTTON lpButton = new TBBUTTON ();
- int 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 wParam, int lParam) {
- if (ignoreMouse) return null;
- return super.WM_LBUTTONDOWN (wParam, lParam);
-}
-
-LRESULT WM_LBUTTONUP (int wParam, int lParam) {
- if (ignoreMouse) return null;
- return super.WM_LBUTTONUP (wParam, lParam);
-}
-
-LRESULT WM_NOTIFY (int wParam, int 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 wParam, int lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if (lastFocusId != -1 && handle == OS.GetFocus ()) {
- int index = OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, lastFocusId, 0);
- OS.SendMessage (handle, OS.TB_SETHOTITEM, index, 0);
- }
- return result;
-}
-
-LRESULT WM_SIZE (int wParam, int lParam) {
- if (ignoreResize) {
- int 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 = 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 = 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 wParam, int 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 (drawCount != 0) 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 wParam, int lParam) {
- ToolItem child = items [wParam & 0xFFFF];
- if (child == null) return null;
- return child.wmCommandChild (wParam, lParam);
-}
-
-LRESULT wmNotifyChild (int wParam, int lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- 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 = 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_ARROWKEYS:
- RECT client = new RECT ();
- OS.GetClientRect (handle, client);
- int index = 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;
- }
- break;
- }
- }
- break;
- }
- return super.wmNotifyChild (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 808b191ca9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java
+++ /dev/null
@@ -1,955 +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.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 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>
- */
-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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 hwnd = parent.handle;
- if (OS.GetKeyState (OS.VK_LBUTTON) < 0) return;
- int index = OS.SendMessage (hwnd, OS.TB_COMMANDTOINDEX, id, 0);
- RECT rect = new RECT ();
- OS.SendMessage (hwnd, OS.TB_GETITEMRECT, index, rect);
- int hotIndex = 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 lParam = (dropDown ? rect.right - 1 : rect.left) | (y << 16);
- 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);
- }
-}
-
-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 hwnd = parent.handle;
- int index = 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 hwnd = parent.handle;
- int 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 hwnd = parent.handle;
- int 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 hwnd = parent.handle;
- int index = 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 ();
-}
-
-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 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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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;
- 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;
- 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 hwnd = parent.handle;
- int fsState = 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 disbled 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 hwnd = parent.handle;
- int fsState = 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);
- }
- }
-}
-
-/**
- * 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 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 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 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 no tool tip text should be shown.
- *
- * @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 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 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 wParam, int 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 e7f5ca6181..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java
+++ /dev/null
@@ -1,540 +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.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>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- *
- * @since 3.2
- */
-
-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#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's value changes, by sending
- * it one of the messages defined in the <code>SelectionListener</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 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 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 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 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.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's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 hwnd = parent.handle;
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.uId = id;
- lpti.hwnd = hwnd;
- int hwndToolTip = hwndToolTip ();
- 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;
- TCHAR pszTitle = new TCHAR (parent.getCodePage (), text, true);
- OS.SendMessage (hwndToolTip, OS.TTM_SETTITLE, icon, pszTitle);
- } else {
- OS.SendMessage (hwndToolTip, OS.TTM_SETTITLE, 0, 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 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 lParam = nX | (nY << 16);
- 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 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 = 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_SETTITLE, 0, 0);
- OS.SendMessage (hwndToolTip, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
- 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 a1dd3f96ca..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java
+++ /dev/null
@@ -1,1077 +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.*;
-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>
- */
-public class Tracker extends Widget {
- Control parent;
- boolean tracking, cancelled, stippled;
- Rectangle [] rectangles, proportions;
- Rectangle bounds;
- int resizeCursor, clientCursor, cursorOrientation = SWT.NONE;
- boolean inEvent = false;
- int oldProc, 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
- */
-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 () {
- 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 () {
- 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 == 0) {
- int 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 () {
- 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 ();
- 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) {
- int bandWidth = 1;
- int hwndTrack = OS.GetDesktopWindow ();
- if (parent != null) hwndTrack = parent.handle;
- int hDC = OS.GetDCEx (hwndTrack, 0, OS.DCX_CACHE);
- int 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();
- 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 moveRectangles (int xChange, int yChange) {
- 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;
- 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).
- */
- int hwndTransparent = 0;
- Callback newProc = null;
- boolean mouseDown = OS.GetKeyState(OS.VK_LBUTTON) < 0;
- if (!mouseDown) {
- int width = OS.GetSystemMetrics (OS.SM_CXSCREEN);
- int height = OS.GetSystemMetrics (OS.SM_CYSCREEN);
- hwndTransparent = OS.CreateWindowEx (
- OS.WS_EX_TRANSPARENT,
- display.windowClass,
- null,
- OS.WS_POPUP | OS.WS_VISIBLE,
- 0, 0,
- width, height,
- 0,
- 0,
- OS.GetModuleHandle (null),
- null);
- oldProc = OS.GetWindowLong (hwndTransparent, OS.GWL_WNDPROC);
- newProc = new Callback (this, "transparentProc", 4); //$NON-NLS-1$
- int newProcAddress = newProc.getAddress ();
- if (newProcAddress == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.SetWindowLong (hwndTransparent, OS.GWL_WNDPROC, newProcAddress);
- }
-
- update ();
- drawRectangles (rectangles, stippled);
- Point cursorPos;
- 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 ();
- }
- }
- oldX = cursorPos.x;
- oldY = cursorPos.y;
-
- /* 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 (msg.message == OS.WM_PAINT) {
- update ();
- drawRectangles (rectangles, stippled);
- }
- OS.DispatchMessage (msg);
- if (msg.message == OS.WM_PAINT) {
- drawRectangles (rectangles, stippled);
- }
- }
- if (mouseDown) OS.ReleaseCapture ();
- if (!isDisposed()) {
- update ();
- drawRectangles (rectangles, stippled);
- }
- /*
- * 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);
- }
- if (newProc != null) {
- newProc.dispose ();
- oldProc = 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;
-}
-
-/**
- * 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 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 = 0;
- if (newCursor != null) {
- clientCursor = newCursor.handle;
- if (inEvent) OS.SetCursor (clientCursor);
- }
-}
-
-/**
- * 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;
-}
-
-int transparentProc (int hwnd, int msg, int wParam, int lParam) {
- switch (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 (clientCursor != 0) {
- OS.SetCursor (clientCursor);
- return 1;
- }
- if (resizeCursor != 0) {
- OS.SetCursor (resizeCursor);
- return 1;
- }
- }
- return OS.CallWindowProc (oldProc, hwnd, msg, wParam, lParam);
-}
-
-void update () {
- if (parent != null) {
- if (parent.isDisposed ()) return;
- Shell shell = parent.getShell ();
- shell.update (true);
- } else {
- display.update ();
- }
-}
-
-LRESULT wmKeyDown (int hwnd, int wParam, int 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 (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 ();
- }
- oldX = cursorPos.x;
- oldY = cursorPos.y;
- }
- return result;
-}
-
-LRESULT wmSysKeyDown (int hwnd, int wParam, int lParam) {
- LRESULT result = super.wmSysKeyDown (hwnd, wParam, lParam);
- if (result != null) return result;
- cancelled = true;
- tracking = false;
- return result;
-}
-
-LRESULT wmMouse (int message, int wParam, int lParam) {
- boolean isMirrored = parent != null && (parent.style & SWT.MIRRORED) != 0;
- int newPos = OS.GetMessagePos ();
- int newX = (short) (newPos & 0xFFFF);
- int newY = (short) (newPos >> 16);
- 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 ();
- 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 dec05aefe3..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TrayItem.java
+++ /dev/null
@@ -1,469 +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.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>
- *
- * @since 3.0
- */
-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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 () {
- 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 messageProc (int hwnd, int msg, int wParam, int 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 (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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 (image2 != null) image2.dispose ();
- image2 = null;
- int 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 no tool tip text should be shown.
- *
- * @param value 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;
- 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 8c551b06f1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java
+++ /dev/null
@@ -1,6407 +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.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 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 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>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL</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>
- */
-public class Tree extends Composite {
- TreeItem [] items;
- TreeColumn [] columns;
- ImageList imageList, headerImageList;
- TreeItem currentItem;
- TreeColumn sortColumn;
- int hwndParent, hwndHeader, hAnchor, hInsert, lastID, hSelect;
- int hFirstIndexOf, hLastIndexOf, 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, ignoreDrawSelection;
- boolean ignoreFullSelection;
- int scrollWidth, itemToolTipHandle, headerToolTipHandle, selectionForeground;
- 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 TreeProc;
- static final TCHAR TreeClass = new TCHAR (0, OS.WC_TREEVIEW, true);
- static final int 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 Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tree (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- /*
- * Feature in Windows. It is not possible to create
- * a tree that scrolls and does not have scroll bars.
- * The TVS_NOSCROLL style will remove the scroll bars
- * but the tree will never scroll. Therefore, no matter
- * what style bits are specified, set the H_SCROLL and
- * V_SCROLL bits so that the SWT style will match the
- * widget that Windows creates.
- */
- style |= SWT.H_SCROLL | 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: {
- 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;
- OS.SendMessage (handle, OS.TVM_SETSCROLLTIME, 0, 0);
- int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits;
- newBits |= OS.TVS_NOHSCROLL | OS.TVS_NOTOOLTIPS;
- /*
- * 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) newBits &= ~OS.TVS_FULLROWSELECT;
- }
- if (newBits != oldBits) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- 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
- * explicilty hide the scroll bar.
- */
- int count = OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0);
- if (count != 0) {
- if (!OS.IsWinCE) OS.ShowScrollBar (handle, OS.SB_HORZ, false);
- }
- }
- break;
- }
- }
-}
-
-TreeItem _getItem (int 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, tvItem.lParam);
- }
- return null;
-}
-
-TreeItem _getItem (int 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 = 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);
- OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, newPixel);
- if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
- }
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's selection changes, 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 <code>SWT.CHECK</code> style set 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 borderHandle () {
- return hwndParent != 0 ? hwndParent : handle;
-}
-
-LRESULT CDDS_ITEMPOSTPAINT (int wParam, int lParam) {
- if (ignoreCustomDraw) return null;
- NMTVCUSTOMDRAW nmcd = new NMTVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMTVCUSTOMDRAW.sizeof);
- int hDC = nmcd.hdc;
- OS.RestoreDC (hDC, -1);
-
- /*
- * 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 = 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 = tvItem.lParam;
- }
- }
- TreeItem item = _getItem (nmcd.dwItemSpec, id);
-
- /*
- * 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 (findImageControl () != null || ignoreDrawSelection) {
- OS.SetBkMode (hDC, OS.TRANSPARENT);
- }
- boolean selected = false;
- if (OS.IsWindowEnabled (handle)) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.hItem = item.handle;
- 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 (hDC) != OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT)) {
- selected = false;
- } else {
- if (OS.GetBkColor (hDC) != OS.GetSysColor (OS.COLOR_HIGHLIGHT)) {
- selected = false;
- }
- }
- }
- } else {
- /*
- * 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 (hDC) == OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT)) {
- if (OS.GetBkColor (hDC) == OS.GetSysColor (OS.COLOR_HIGHLIGHT)) {
- selected = true;
- }
- }
- }
- }
- int count = 0;
- int [] order = null;
- RECT clientRect = new RECT (), focusRect = null;
- OS.GetClientRect (scrolledHandle (), clientRect);
- if (hwndHeader != 0) {
- OS.MapWindowPoints (hwndParent, handle, clientRect, 2);
- count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (count != 0) {
- order = new int [count];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, count, 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 ();
- }
- }
- }
- Point size = null;
- int x = 0, gridWidth = linesVisible ? GRID_WIDTH : 0;
- for (int i=0; i<Math.max (1, count); i++) {
- int index = order == null ? i : order [i], width = nmcd.right - nmcd.left;
- if (count > 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) {
- RECT rect = new RECT ();
- if ((style & SWT.FULL_SELECTION) != 0) {
- OS.SetRect (rect, width, nmcd.top, nmcd.right, nmcd.bottom);
- if ((selected || findImageControl () == null) && !ignoreDrawSelection && !ignoreDrawBackground) {
- fillBackground (hDC, OS.GetBkColor (hDC), rect);
- }
- }
- }
- 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) {
- drawItem = drawText = drawBackground = true;
- rect = item.getBounds (index, true, false, false, false, true, hDC);
- if (linesVisible) {
- rect.right++;
- rect.bottom++;
- }
- }
- if (selected && !ignoreDrawSelection && !ignoreDrawBackground) {
- 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 = false;
- OS.SetRect (rect, x, nmcd.top, x + width, nmcd.bottom - gridWidth);
- backgroundRect = rect;
- }
- int clrText = -1, clrTextBk = -1;
- int hFont = item.cellFont != null ? item.cellFont [index] : -1;
- if (hFont == -1) hFont = item.font;
- 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 (index == sortIndex) clrTextBk = clrSortBk;
- }
- } else {
- if (index == sortIndex) {
- drawBackground = true;
- clrTextBk = clrSortBk;
- }
- }
- if (drawItem) {
- if (i != 0) {
- if (hooks (SWT.MeasureItem)) {
- RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC);
- int nSavedDC = OS.SaveDC (hDC);
- GCData data = new GCData ();
- data.device = display;
- data.hFont = hFont;
- GC gc = GC.win32_new (hDC, data);
- Event event = new Event ();
- event.item = item;
- event.index = index;
- event.gc = gc;
- 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 ()) break;
- if (event.height > getItemHeight ()) setItemHeight (event.height);
- }
- 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.hPen = OS.CreatePen (OS.PS_SOLID, 0, data.foreground);
- data.hBrush = OS.CreateSolidBrush (data.background);
- data.hFont = hFont;
- 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 (selected && (style & SWT.FULL_SELECTION) != 0) event.detail |= SWT.SELECTED;
- if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) {
- if (/*nmcd.iSubItem == 0 ||*/ (style & SWT.FULL_SELECTION) != 0) {
- if (handle == OS.GetFocus ()) {
- int uiState = 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 = OS.GetTextColor (hDC);
- 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;
- ignoreDrawSelection = (event.detail & SWT.SELECTED) == 0;
- } else {
- ignoreDrawForeground = ignoreDrawBackground = ignoreDrawSelection = true;
- }
- if ((style & SWT.FULL_SELECTION) != 0) {
- if (ignoreDrawSelection) ignoreFullSelection = true;
- if (!ignoreDrawSelection) {
- if (!selected) {
- selectionForeground = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT);
- } else {
- drawBackground = true;
- ignoreDrawBackground = false;
- if (handle == OS.GetFocus () && OS.IsWindowEnabled (handle)) {
- clrTextBk = OS.GetSysColor (OS.COLOR_HIGHLIGHT);
- } else {
- clrTextBk = OS.GetSysColor (OS.COLOR_3DFACE);
- }
- if (!ignoreFullSelection && index == count - 1) {
- RECT selectionRect = new RECT ();
- OS.SetRect (selectionRect, backgroundRect.left, backgroundRect.top, nmcd.right, backgroundRect.bottom);
- backgroundRect = selectionRect;
- }
- }
- } else {
- if (selected) {
- selectionForeground = newTextClr;
- 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);
- if (!ignoreDrawSelection) {
- if (handle == OS.GetFocus ()) {
- int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
- if ((uiState & OS.UISF_HIDEFOCUS) == 0) {
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem == item.handle) {
- if ((style & SWT.FULL_SELECTION) != 0) {
- focusRect = new RECT ();
- OS.SetRect (focusRect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
- } else {
- focusRect = item.getBounds (index, true, false, false, false, true, hDC);
- }
- }
- }
- }
- }
- } else {
- if (drawBackground) fillImageBackground (hDC, control, rect);
- }
- }
- }
- }
- 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;
- if (image != null) {
- if (index == 0) rect.left = Math.min (rect.right, rect.left + 2);
- Rectangle bounds = image.getBounds ();
- if (size == null) size = getImageSize ();
- //int y = rect.top + (index == 0 ? (getItemHeight () - size.y) / 2 : 0);
- int y = rect.top;
- if (!ignoreDrawForeground) {
- //TODO - share GC, clip the drawing for index == 0
- GCData data = new GCData();
- data.device = display;
- GC gc = GC.win32_new (hDC, data);
- //if (index == 0) { //must clear
- //gc.setClipping (rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
- //}
- gc.drawImage (image, 0, 0, bounds.width, bounds.height, rect.left, y, size.x, size.y);
- gc.dispose ();
- }
- OS.SetRect (rect, rect.left + size.x + INSET, rect.top, rect.right - inset, rect.bottom);
- } else {
- OS.SetRect (rect, rect.left + INSET, rect.top, rect.right - inset, rect.bottom);
- if (i == 0 && OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0) != 0) {
- if (size == null) size = getImageSize ();
- rect.left = Math.min (rect.left + size.x, rect.right);
- }
- }
- }
- 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;
- rect.left = Math.min (rect.right, rect.left + 2);
- } 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.hFont = hFont;
- 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.hPen = OS.CreatePen (OS.PS_SOLID, 0, data.foreground);
- data.hBrush = OS.CreateSolidBrush (data.background);
- OS.SelectObject (hDC, data.hPen);
- OS.SelectObject (hDC, data.hBrush);
- 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 (selected && (i == 0 /*nmcd.iSubItem == 0*/ || (style & SWT.FULL_SELECTION) != 0)) {
- event.detail |= SWT.SELECTED;
- }
- if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) {
- if (i == 0 /*nmcd.iSubItem == 0*/ || (style & SWT.FULL_SELECTION) != 0) {
- if (handle == OS.GetFocus ()) {
- int uiState = 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);
- 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 (hwndHeader != 0) {
- if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0) != 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 (focusRect != null) OS.DrawFocusRect (hDC, focusRect);
- return new LRESULT (OS.CDRF_DODEFAULT);
-}
-
-LRESULT CDDS_ITEMPREPAINT (int wParam, int lParam) {
- NMTVCUSTOMDRAW nmcd = new NMTVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMTVCUSTOMDRAW.sizeof);
- /*
- * 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 = 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 = tvItem.lParam;
- }
- }
- TreeItem item = _getItem (nmcd.dwItemSpec, id);
- if (ignoreCustomDraw) {
- int hDC = nmcd.hdc;
- int index = hwndHeader != 0 ? OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0) : 0;
- int hFont = item.cellFont != null ? item.cellFont [index] : -1;
- if (hFont == -1) hFont = item.font;
- if (hFont != -1) OS.SelectObject (hDC, hFont);
- return new LRESULT (hFont == -1 ? OS.CDRF_DODEFAULT : OS.CDRF_NEWFONT);
- }
- /*
- * 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;
- RECT clipRect = null;
- int index = 0, count = 0;
- if (hwndHeader != 0) {
- index = OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0);
- count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (count != 0 && !printClient) {
- 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;
- int hFont = item.cellFont != null ? item.cellFont [index] : -1;
- if (hFont == -1) hFont = item.font;
- 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) {
- clrTextBk = clrSortBk = getSortColumnPixel ();
- }
- }
- }
- }
- int hDC = nmcd.hdc;
- /*
- * 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.
- */
- boolean selected = false;
- if (OS.IsWindowEnabled (handle)) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.hItem = item.handle;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & (OS.TVIS_SELECTED | OS.TVIS_DROPHILITED)) != 0) {
- selected = true;
- if (handle == OS.GetFocus ()) {
- if (OS.GetTextColor (hDC) != OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT)) {
- selected = false;
- } else {
- if (OS.GetBkColor (hDC) != OS.GetSysColor (OS.COLOR_HIGHLIGHT)) {
- selected = false;
- }
- }
- }
- }
- }
- 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
- if (hooks (SWT.MeasureItem)) {
- RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC);
- int nSavedDC = OS.SaveDC (hDC);
- GCData data = new GCData ();
- data.device = display;
- data.hFont = hFont;
- 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 (count == 0) {
- if (event.x + event.width > scrollWidth) {
- setScrollWidth (scrollWidth = event.x + event.width);
- }
- }
- }
- if (event.height > getItemHeight ()) setItemHeight (event.height);
- }
- selectionForeground = -1;
- ignoreDrawForeground = ignoreDrawSelection = ignoreFullSelection = ignoreDrawBackground = false;
- if (hooks (SWT.EraseItem)) {
- 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.GetBkColor (hDC), rect);
- }
- RECT cellRect = item.getBounds (index, true, true, true, true, true, hDC);
- if (clrSortBk != -1) {
- RECT fullRect = item.getBounds (index, true, true, true, true, true, hDC);
- drawBackground (hDC, fullRect, clrSortBk);
- }
- int nSavedDC = OS.SaveDC (hDC);
- GCData data = new GCData ();
- data.device = display;
- 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.hPen = OS.CreatePen (OS.PS_SOLID, 0, data.foreground);
- data.hBrush = OS.CreateSolidBrush (data.background);
- if (hFont != -1) data.hFont = hFont;
- OS.SelectObject (hDC, data.hPen);
- OS.SelectObject (hDC, data.hBrush);
- 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 (selected) event.detail |= SWT.SELECTED;
- if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) {
- if (/*nmcd.iSubItem == 0 ||*/ (style & SWT.FULL_SELECTION) != 0) {
- if (handle == OS.GetFocus ()) {
- int uiState = 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 = OS.GetTextColor (hDC);
- gc.dispose ();
- OS.RestoreDC (hDC, nSavedDC);
- if (isDisposed () || item.isDisposed ()) return null;
- if (event.doit) {
- ignoreDrawForeground = (event.detail & SWT.FOREGROUND) == 0;
- ignoreDrawSelection = (event.detail & SWT.SELECTED) == 0;
- ignoreDrawBackground = (event.detail & SWT.BACKGROUND) == 0;
- } else {
- ignoreDrawForeground = ignoreDrawSelection = ignoreDrawBackground = true;
- }
- if (!ignoreDrawBackground && clrTextBk != -1) {
- if (count == 0) {
- if ((style & SWT.FULL_SELECTION) != 0) {
- fillBackground (hDC, clrTextBk, rect);
- } else {
- RECT textRect = item.getBounds (index, true, false, true, false, true, hDC);
- fillBackground (hDC, clrTextBk, textRect);
- }
- } else {
- fillBackground (hDC, clrTextBk, cellRect);
- }
- }
- if (ignoreDrawSelection) ignoreFullSelection = true;
- if (!ignoreDrawSelection) {
- if (!selected) {
- selectionForeground = clrText = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT);
- }
- /*
- * 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 && count == 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);
- fillBackground (hDC, OS.GetBkColor (hDC), textRect);
- }
- } else {
- if (selected) {
- selectionForeground = clrText = newTextClr;
- ignoreDrawSelection = true;
- }
- }
- RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC);
- OS.SaveDC (hDC);
- OS.SelectClipRgn (hDC, 0);
- //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, NMLVCUSTOMDRAW.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 (count != 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 ();
- itemRect.left = item.handle;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, itemRect) != 0) {
- rect.left = Math.min (itemRect.left, rect.right);
- }
- }
- if ((style & SWT.FULL_SELECTION) != 0) {
- if (!selected) 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);
- }
- }
- }
- /*
- * 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 (!OS.IsWindowEnabled (handle) && 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 hRgn = OS.CreateRectRgn (clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
- OS.SelectClipRgn (hDC, hRgn);
- OS.DeleteObject (hRgn);
- }
- return result;
-}
-
-LRESULT CDDS_POSTPAINT (int wParam, int 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) {
- NMTVCUSTOMDRAW nmcd = new NMTVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMTVCUSTOMDRAW.sizeof);
- int top = nmcd.top;
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_LASTVISIBLE, 0);
- if (hItem != 0) {
- RECT rect = new RECT ();
- rect.left = hItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect) != 0) {
- 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) {
- NMTVCUSTOMDRAW nmcd = new NMTVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMTVCUSTOMDRAW.sizeof);
- int hDC = nmcd.hdc;
- if (hwndHeader != 0) {
- int x = 0;
- RECT rect = new RECT ();
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_WIDTH;
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; i++) {
- int index = 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 ();
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_LASTVISIBLE, 0);
- if (hItem != 0) {
- rect.left = hItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect) != 0) {
- height = rect.bottom - rect.top;
- }
- }
- if (height == 0) {
- height = 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 (int wParam, int lParam) {
- return new LRESULT (OS.CDRF_NOTIFYITEMDRAW | OS.CDRF_NOTIFYPOSTPAINT);
-}
-
-int callWindowProc (int hwnd, int msg, int wParam, int 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 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 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 && drawCount == 0 && 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 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);
- }
-}
-
-boolean checkData (TreeItem item, boolean redraw) {
- if ((style & SWT.VIRTUAL) == 0) return true;
- TreeItem parentItem = item.getParentItem ();
- return checkData (item, parentItem == null ? indexOf (item) : parentItem.indexOf (item), redraw);
-}
-
-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;
- sendEvent (SWT.SetData, event);
- //widget could be disposed at this point
- currentItem = oldItem;
- if (isDisposed () || item.isDisposed ()) return false;
- if (redraw) item.redraw ();
- }
- return true;
-}
-
-boolean checkHandle (int hwnd) {
- return hwnd == handle || (hwndParent != 0 && hwnd == hwndParent) || (hwndHeader != 0 && hwnd == hwndHeader);
-}
-
-boolean checkScroll (int 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 temporarly 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 (drawCount == 0) return false;
- int hRoot = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- int 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 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 hItem, TVITEM tvItem) {
- tvItem.hItem = hItem;
- TreeItem item = null;
- if (OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem) != 0) {
- item = tvItem.lParam != -1 ? items [tvItem.lParam] : null;
- }
- if (item != null) {
- 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 hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- if (hItem == 0) return;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- clearAll (hItem, tvItem, all);
-}
-
-void clearAll (int hItem, TVITEM tvItem, boolean all) {
- while (hItem != 0) {
- clear (hItem, tvItem);
- int hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- if (all) clearAll (hFirstItem, tvItem, all);
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- }
-}
-
-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;
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; 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 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;
- }
- rect.left = hItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect) != 0) {
- width = Math.max (width, rect.right);
- height += rect.bottom - rect.top;
- }
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, 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);
-
- /*
- * 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 recomended 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 hFont = OS.GetStockObject (OS.SYSTEM_FONT);
- OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
-}
-
-void createHeaderToolTips () {
- if (OS.IsWinCE) return;
- if (headerToolTipHandle != 0) return;
- headerToolTipHandle = OS.CreateWindowEx (
- 0,
- new TCHAR (0, OS.TOOLTIPS_CLASS, true),
- null,
- 0,
- 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 ();
- int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- 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) {
- int [] cellFont = item.cellFont;
- int [] temp = new int [columnCount + 1];
- System.arraycopy (cellFont, 0, temp, 0, index);
- System.arraycopy (cellFont, index, temp, index + 1, columnCount- index);
- temp [index] = -1;
- 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 hHeap = OS.GetProcessHeap ();
- int 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 == 0) {
- scrollWidth = 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
- * explicilty hide the scroll bar explicitly.
- */
- int count = OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0);
- if (count != 0) {
- if (!OS.IsWinCE) OS.ShowScrollBar (handle, OS.SB_HORZ, false);
- }
- }
- setScrollWidth ();
- updateImageList ();
- updateScrollBar ();
-
- /* Redraw to hide the items when the first column is created */
- if (columnCount == 0 && 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 hParent, int hInsertAfter, int 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 (drawCount == 0 && 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 hNewItem = 0;
- int 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;
- }
- hNewItem = OS.SendMessage (handle, OS.TVM_INSERTITEM, 0, tvInsert);
- 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) {
- switch (hInsertAfter) {
- case OS.TVI_FIRST:
- case 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 (drawCount == 0 && OS.IsWindowVisible (handle)) {
- RECT rect = new RECT ();
- rect.left = hParent;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect) != 0) {
- 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 ();
- rect.left = hNewItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect) != 0) {
- 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 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 bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- bits |= OS.TVS_NOTOOLTIPS;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- itemToolTipHandle = OS.CreateWindowEx (
- 0,
- new TCHAR (0, OS.TOOLTIPS_CLASS, true),
- null,
- 0,
- OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
- handle,
- 0,
- OS.GetModuleHandle (null),
- null);
- if (itemToolTipHandle == 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 (itemToolTipHandle, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
- 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.SetWindowLong (hwndParent, OS.GWL_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.SetWindowLong (hwndHeader, OS.GWL_ID, hwndHeader);
- if (OS.IsDBLocale) {
- int hIMC = OS.ImmGetContext (handle);
- OS.ImmAssociateContext (hwndParent, hIMC);
- OS.ImmAssociateContext (hwndHeader, hIMC);
- OS.ImmReleaseContext (handle, hIMC);
- }
- 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 hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- if (hFont != 0) OS.SendMessage (hwndHeader, OS.WM_SETFONT, hFont, 0);
- int 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 hwndFocus = OS.GetFocus ();
- if (hwndFocus == handle) OS.SetFocus (hwndParent);
- OS.SetParent (handle, hwndParent);
- if (hwndFocus == handle) OS.SetFocus (handle);
- register ();
- subclass ();
- createItemToolTips ();
-}
-
-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 hItem, TVITEM tvItem, int hIgnoreItem) {
- while (hItem != 0) {
- if (hItem != hIgnoreItem) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- int 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 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 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 oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int 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.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
- }
-}
-
-void destroyItem (TreeColumn column) {
- if (hwndHeader == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- 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) {
- int [] cellFont = item.cellFont;
- int [] temp = new int [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) && !hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- bits &= ~OS.TVS_NOHSCROLL;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- OS.InvalidateRect (handle, null, true);
- }
- } 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 ();
- 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 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 hParent = 0;
- boolean fixRedraw = false;
- if ((style & SWT.DOUBLE_BUFFERED) == 0) {
- if (drawCount == 0 && OS.IsWindowVisible (handle)) {
- RECT rect = new RECT ();
- rect.left = hItem;
- fixRedraw = OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect) == 0;
- }
- }
- 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;
- }
- 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);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (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 ();
- rect.left = hParent;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect) != 0) {
- OS.InvalidateRect (handle, rect, true);
- }
- }
- }
- int count = 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;
- }
- updateScrollBar ();
-}
-
-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 ();
- 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 ();
-}
-
-int findIndex (int hFirstItem, int hItem) {
- if (hFirstItem == 0) return -1;
- if (hFirstItem == hFirstIndexOf) {
- if (hFirstIndexOf == hItem) {
- hLastIndexOf = hFirstIndexOf;
- return lastIndexOf = 0;
- }
- if (hLastIndexOf == hItem) return lastIndexOf;
- int hPrevItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_PREVIOUS, hLastIndexOf);
- if (hPrevItem == hItem) {
- hLastIndexOf = hPrevItem;
- return --lastIndexOf;
- }
- int 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, 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 hItem) {
- return _getItem (hItem);
-}
-
-int findItem (int 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 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 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, 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 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 ());
-}
-
-/**
- * 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 (hwndHeader == 0) error (SWT.ERROR_INVALID_RANGE);
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index < count)) 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 ();
- if (hwndHeader == 0) return 0;
- return OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
-}
-
-/**
- * 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 (hwndHeader == 0) return new int [0];
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- int [] order = new int [count];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, count, 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 ();
- if (hwndHeader == 0) return new TreeColumn [0];
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- TreeColumn [] result = new TreeColumn [count];
- System.arraycopy (columns, 0, result, 0, count);
- 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 hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- if (hFirstItem == 0) error (SWT.ERROR_INVALID_RANGE);
- int hItem = findItem (hFirstItem, index);
- if (hItem == 0) error (SWT.ERROR_INVALID_RANGE);
- return _getItem (hItem);
-}
-
-/**
- * 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) {
- if ((style & SWT.FULL_SELECTION) != 0 || (lpht.flags & OS.TVHT_ONITEM) != 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 hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- if (hItem == 0) return 0;
- return getItemCount (hItem);
-}
-
-int getItemCount (int hItem) {
- int count = 0, 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 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 hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- if (hItem == 0) return new TreeItem [0];
- return getItems (hItem);
-}
-
-TreeItem [] getItems (int hTreeItem) {
- int count = 0, 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 occurs 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, 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.
- * <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 getNextSelection (int hItem) {
- while (hItem != 0) {
- int state = OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- if ((state & OS.TVIS_SELECTED) != 0) return hItem;
- int hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- int hSelected = getNextSelection (hFirstItem);
- 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 hItem, TVITEM tvItem, TreeItem [] selection, int count) {
- while (hItem != 0) {
- if (tvItem != null && selection != null && count < selection.length) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) != 0) {
- selection [count++] = _getItem (hItem, tvItem.lParam);
- }
- } else {
- int state = OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- if ((state & OS.TVIS_SELECTED) != 0) count++;
- }
- int hFirstItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hItem);
- count = getSelection (hFirstItem, tvItem, selection, count);
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- }
- return count;
-}
-
-/**
- * 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 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, tvItem.lParam)};
- }
- int count = 0;
- TreeItem [] guess = new TreeItem [8];
- int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM | OS.TVIF_STATE;
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- count = getSelection (hItem, tvItem, guess, 0);
- } else {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- int hItem = item.handle;
- int state = 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.SetWindowLong (handle, OS.GWL_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;
- }
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM | OS.TVIF_STATE;
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- getSelection (hItem, tvItem, result, 0);
- } else {
- int index = 0;
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- tvItem.hItem = item.handle;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) != 0) {
- result [index++] = item;
- }
- }
- }
- }
- OS.SetWindowLong (handle, OS.GWL_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 hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem == 0) return 0;
- int state = OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- if ((state & OS.TVIS_SELECTED) == 0) return 0;
- return 1;
- }
- int count = 0;
- int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- count = getSelection (hItem, null, null, 0);
- } else {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null) {
- int hItem = item.handle;
- int state = OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- if ((state & OS.TVIS_SELECTED) != 0) count++;
- }
- }
- }
- OS.SetWindowLong (handle, OS.GWL_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 0x02000000 | (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 hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0);
- return hItem != 0 ? _getItem (hItem) : null;
-}
-
-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) {
- int hImageList = imageList.getHandle ();
- int 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 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 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.1
- */
-public int indexOf (TreeColumn column) {
- checkWidget ();
- if (column == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (hwndHeader == 0) return -1;
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; 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 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>
- *
- * @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 hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- return hItem == 0 ? -1 : findIndex (hItem, item.handle);
-}
-
-void register () {
- super.register ();
- if (hwndParent != 0) display.addControl (hwndParent, this);
- if (hwndHeader != 0) display.addControl (hwndHeader, this);
-}
-
-void releaseItem (int 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 = tvItem.lParam;
- if (release) {
- TreeItem item = items [tvItem.lParam];
- if (item != null) item.release (false);
- }
- items [tvItem.lParam] = null;
- }
- }
-}
-
-void releaseItems (int 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 ingore 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 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 = drawCount == 0 && OS.IsWindowVisible (handle);
- if (redraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- shrink = ignoreShrink = true;
- int result = OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, OS.TVI_ROOT);
- ignoreShrink = false;
- if (redraw) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (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];
- updateScrollBar ();
- scrollWidth = 0;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's selection changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- setItemCount (count, OS.TVGN_ROOT, hItem);
-}
-
-void setItemCount (int count, int hParent, int hItem) {
- boolean redraw = false;
- if (OS.SendMessage (handle, OS.TVM_GETCOUNT, 0, 0) == 0) {
- redraw = drawCount == 0 && OS.IsWindowVisible (handle);
- if (redraw) OS.SendMessage (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++;
- }
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- 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 [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++) {
- createItem (null, hParent, OS.TVI_LAST, 0);
- }
- } 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.SendMessage (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.
- *
- * @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);
- 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.
- * <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 scrolledHandle () {
- if (hwndHeader == 0) return handle;
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- return count == 0 ? handle : hwndParent;
-}
-
-void select (int hItem, TVITEM tvItem) {
- while (hItem != 0) {
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- int 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 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 oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int 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.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
-}
-
-void setBackgroundImage (int 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.COMCTL32_MAJOR < 6) {
- if (OS.SendMessage (handle, OS.TVM_GETBKCOLOR, 0, 0) == -1) {
- OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, -1);
- }
- }
- OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, -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 setBounds (int x, int y, int width, int height, int flags) {
- /*
- * Ensure that the selection is visible when the tree is resized
- * from a zero size to a size that can show the selection.
- */
- boolean fixSelection = false;
- if ((flags & OS.SWP_NOSIZE) == 0 && (width != 0 || height != 0)) {
- if (OS.SendMessage (handle, OS.TVM_GETVISIBLECOUNT, 0, 0) == 0) {
- fixSelection = true;
- }
- }
- super.setBounds (x, y, width, height, flags);
- if (fixSelection) {
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem != 0) showItem (hItem);
- }
-}
-
-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 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);
- int count = 0;
- if (hwndHeader != 0) {
- count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- }
- if (count == 0) {
- if (order.length != 0) error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- if (order.length != count) error (SWT.ERROR_INVALID_ARGUMENT);
- int [] oldOrder = new int [count];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, count, oldOrder);
- boolean reorder = false;
- boolean [] seen = new boolean [count];
- for (int i=0; i<order.length; i++) {
- int index = order [i];
- if (index < 0 || index >= count) 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 [count];
- for (int i=0; i<count; 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 [count];
- System.arraycopy (columns, 0, newColumns, 0, count);
- RECT newRect = new RECT ();
- for (int i=0; i<count; 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 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 = OS.SendMessage (handle, OS.TVM_GETITEMHEIGHT, 0, 0), width = height;
- int hStateList = OS.ImageList_Create (width, height, flags, count, count);
- int hDC = OS.GetDC (handle);
- int memDC = OS.CreateCompatibleDC (hDC);
- int hBitmap = OS.CreateCompatibleBitmap (hDC, width * count, height);
- int 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 hBrush = OS.CreateSolidBrush (clrBackground);
- OS.FillRect (memDC, rect, hBrush);
- OS.DeleteObject (hBrush);
- int 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 hTheme = OS.OpenThemeData (handle, BUTTON);
- 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);
- OS.CloseThemeData (hTheme);
- } 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 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) {
- 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 ();
- /*
- * 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 hItem = 0;
- if (redraw && drawCount == 1) {
- int count = 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);
- }
- }
- super.setRedraw (redraw);
- 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 ();
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; 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 (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 {
- 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 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 w = pos.cx + (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, pos.y + pos.cy, w + left, h, OS.SWP_NOACTIVATE | OS.SWP_NOZORDER);
- ignoreResize = oldIgnore;
-}
-
-void setSelection (int 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 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 hOldItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- int 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);
- }
- hSelect = hNewItem;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hNewItem);
- ignoreSelect = false;
- hSelect = 0;
- if (OS.SendMessage (handle, OS.TVM_GETVISIBLECOUNT, 0, 0) == 0) {
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, hNewItem);
- }
- 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 oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int 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.SetWindowLong (handle, OS.GWL_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 hItem = item.handle;
- 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);
- if (fixScroll) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- updateScrollBar ();
-}
-
-void showItem (int 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);
- 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 ();
- itemRect.left = hItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, itemRect) != 0) {
- 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 ();
- itemRect.left = hItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, itemRect) != 0) {
- 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;
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (0 <= index && index < count) {
- if (hwndParent != 0) {
- 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 hItem = 0;
- if ((style & SWT.SINGLE) != 0) {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem == 0) return;
- int state = OS.SendMessage (handle, OS.TVM_GETITEMSTATE, hItem, OS.TVIS_SELECTED);
- if ((state & OS.TVIS_SELECTED) == 0) return;
- } else {
- int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int hRoot = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- hItem = getNextSelection (hRoot);
- } 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 = OS.SendMessage (handle, OS.TVM_GETITEMSTATE, item.handle, OS.TVIS_SELECTED);
- if ((state & OS.TVIS_SELECTED) != 0) {
- hItem = item.handle;
- break;
- }
- }
- index++;
- }
- }
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
- }
- if (hItem != 0) showItem (hItem);
-}
-
-void showWidget (boolean visible) {
- super.showWidget (visible);
- if (hwndParent != 0) {
- OS.ShowWindow (hwndParent, visible ? OS.SW_SHOW : OS.SW_HIDE);
- }
-}
-
-void subclass () {
- super.subclass ();
- if (hwndHeader != 0) {
- OS.SetWindowLong (hwndHeader, OS.GWL_WNDPROC, display.windowProc);
- }
-}
-
-String toolTipText (NMTTDISPINFO hdr) {
- int hwndToolTip = OS.SendMessage (handle, OS.TVM_GETTOOLTIPS, 0, 0);
- if (hwndToolTip == hdr.hwndFrom && toolTipText != null) return ""; //$NON-NLS-1$
- if (headerToolTipHandle == hdr.hwndFrom) {
- int count = OS.SendMessage(hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; i++) {
- TreeColumn column = columns [i];
- if (column.id == hdr.idFrom) return column.toolTipText;
- }
- return super.toolTipText (hdr);
- }
- if (itemToolTipHandle == hdr.hwndFrom && hwndHeader != 0) {
- if (toolTipText != null) return "";
- if (!hooks (SWT.EraseItem) && !hooks (SWT.PaintItem)) {
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT();
- pt.x = (short) (pos & 0xFFFF);
- pt.y = (short) (pos >> 16);
- 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) {
- 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);
- RECT rect = new RECT ();
- OS.GetClientRect (hwndParent, rect);
- OS.MapWindowPoints (hwndParent, handle, rect, 2);
- TreeItem item = _getItem (lpht.hItem);
- String text = null;
- int index = 0, count = Math.max (1, OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0));
- int [] order = new int [count];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, count, order);
- while (index < count) {
- int hFont = item.cellFont != null ? item.cellFont [order [index]] : -1;
- if (hFont == -1) hFont = item.font;
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- RECT cellRect = item.getBounds (order [index], true, false, true, false, true, hDC);
- if (hFont != -1) OS.SelectObject (hDC, hFont);
- if (cellRect.left > rect.right) break;
- cellRect.right = Math.min (cellRect.right, rect.right);
- if (OS.PtInRect (cellRect, pt)) {
- RECT textRect = item.getBounds (order [index], true, false, false, false, false, hDC);
- if (textRect.right > cellRect.right) {
- if (order [index] == 0) {
- text = item.text;
- } else {
- String[] strings = item.strings;
- if (strings != null) text = strings [order [index]];
- }
- }
- break;
- }
- index++;
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- if (text != null) return text;
- }
- }
- }
- return super.toolTipText (hdr);
-}
-
-int 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) {
- 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;
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; 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 = 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 hImageList = i == items.length ? 0 : imageList.getHandle ();
- int 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) {
- int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (columnCount != 0 || scrollWidth != 0) {
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_ALL;
- int itemCount = 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 (info.nPage == 0) info.nPage = info.nMax + 1;
- OS.SetScrollInfo (hwndParent, OS.SB_VERT, info, true);
- }
- }
- }
-}
-
-void unsubclass () {
- super.unsubclass ();
- if (hwndHeader != 0) {
- OS.SetWindowLong (hwndHeader, OS.GWL_WNDPROC, HeaderProc);
- }
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.TVS_SHOWSELALWAYS | OS.TVS_LINESATROOT | OS.TVS_HASBUTTONS | OS.TVS_NONEVENHEIGHT;
- if ((style & SWT.FULL_SELECTION) != 0) {
- bits |= OS.TVS_FULLROWSELECT;
- } else {
- bits |= OS.TVS_HASLINES;
- }
-// bits |= OS.TVS_NOTOOLTIPS | OS.TVS_DISABLEDRAGDROP;
- return bits | OS.TVS_DISABLEDRAGDROP;
-}
-
-TCHAR windowClass () {
- return TreeClass;
-}
-
-int windowProc () {
- return TreeProc;
-}
-
-int windowProc (int hwnd, int msg, int wParam, int lParam) {
- if (hwndHeader != 0 && hwnd == hwndHeader) {
- switch (msg) {
- /* This code is intentionally commented */
-// 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_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);
- }
- }
- }
- 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 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);
- 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 ((wParam & 0xFFFF) == OS.SB_THUMBTRACK) {
- info.nPos = info.nTrackPos;
- }
- }
- OS.SetScrollInfo (handle, OS.SB_VERT, info, true);
- int 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);
- }
- return super.windowProc (hwnd, msg, wParam, lParam);
-}
-
-LRESULT WM_CHAR (int wParam, int 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 (wParam) {
- case ' ': {
- int 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 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, 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, 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 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 wParam, int 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 wParam, int 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_KEYDOWN (int wParam, int lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- switch (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) {
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- TreeColumn [] newColumns = new TreeColumn [count];
- System.arraycopy (columns, 0, newColumns, 0, count);
- for (int i=0; i<count; 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 ((style & SWT.SINGLE) != 0) break;
- if (OS.GetKeyState (OS.VK_SHIFT) < 0) {
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem != 0) {
- if (hAnchor == 0) hAnchor = hItem;
- ignoreSelect = ignoreDeselect = true;
- int code = callWindowProc (handle, OS.WM_KEYDOWN, wParam, lParam);
- ignoreSelect = ignoreDeselect = false;
- int 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 hDeselectItem = hItem;
- RECT rect1 = new RECT ();
- rect1.left = hAnchor;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect1);
- RECT rect2 = new RECT ();
- rect2.left = hDeselectItem;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect2);
- 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 hSelectItem = hAnchor;
- rect1.left = hNewItem;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect1);
- rect2.left = hSelectItem;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect2);
- 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, tvItem.lParam);
- postEvent (SWT.Selection, event);
- return new LRESULT (code);
- }
- }
- if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
- int 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 hNewItem = 0;
- switch (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 hVisible = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, hNewItem);
- if (hVisible == 0) break;
- rect.left = hVisible;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect);
- 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 && drawCount == 0 && OS.IsWindowVisible (handle);
- if (redraw) {
- OS.UpdateWindow (handle);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (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 ();
- rect1.left = hItem; rect2.left = hNewItem;
- int fItemRect = (style & SWT.FULL_SELECTION) != 0 ? 0 : 1;
- if (hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) fItemRect = 0;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) fItemRect = 0;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, fItemRect, rect1);
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, fItemRect, rect2);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- 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 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 wParam, int lParam) {
- LRESULT result = super.WM_KILLFOCUS (wParam, lParam);
- if ((style & SWT.SINGLE) != 0) return result;
- /*
- * 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 all the
- * visible items when focus is gained or lost.
- */
- OS.InvalidateRect (handle, null, false);
- return result;
-}
-
-LRESULT WM_LBUTTONDBLCLK (int wParam, int lParam) {
- TVHITTESTINFO lpht = new TVHITTESTINFO ();
- lpht.x = (short) (lParam & 0xFFFF);
- lpht.y = (short) (lParam >> 16);
- 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 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, id);
- }
- Event event = new Event ();
- event.item = _getItem (tvItem.hItem, 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) {
- if ((style & SWT.FULL_SELECTION) != 0 || (lpht.flags & OS.TVHT_ONITEM) != 0) {
- Event event = new Event ();
- event.item = _getItem (lpht.hItem);
- postEvent (SWT.DefaultSelection, event);
- }
- }
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int wParam, int 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 = (short) (lParam & 0xFFFF);
- lpht.y = (short) (lParam >> 16);
- 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;
- if (lpht.hItem != 0 && (style & SWT.MULTI) != 0) {
- int hSelection = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hSelection != 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 hNext = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, lpht.hItem);
- while (hNext != 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 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 code = callWindowProc (handle, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (fixSelection) ignoreDeselect = ignoreSelect = lockSelection = false;
- if (dragStarted) {
- if (!display.captureChanged && !isDisposed ()) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- }
- 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 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, id);
- }
- Event event = new Event ();
- event.item = _getItem (tvItem.hItem, tvItem.lParam);
- event.detail = SWT.CHECK;
- postEvent (SWT.Selection, event);
- return LRESULT.ZERO;
- }
- }
-
- /* Process the mouse when an item is not selected */
- if ((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 code = callWindowProc (handle, OS.WM_LBUTTONDOWN, wParam, lParam);
- 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, focused = 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;
- focused = OS.GetFocus () == handle;
- }
-
- /* Get the selected state of the last selected item */
- boolean redraw = false;
- int 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) {
- redraw = focused && drawCount == 0 && OS.IsWindowVisible (handle);
- if (redraw) {
- OS.UpdateWindow (handle);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (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 code = callWindowProc (handle, OS.WM_LBUTTONDOWN, wParam, lParam);
- int hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- /*
- * 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) {
- if (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);
- }
- }
- }
- 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);
- }
- }
- }
- if (redraw) {
- RECT rect1 = new RECT (), rect2 = new RECT ();
- rect1.left = hOldItem; rect2.left = hNewItem;
- int fItemRect = (style & SWT.FULL_SELECTION) != 0 ? 0 : 1;
- if (hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) fItemRect = 0;
- if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) fItemRect = 0;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, fItemRect, rect1);
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, fItemRect, rect2);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- 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 delect/reselect items */
- if ((wParam & OS.MK_CONTROL) == 0) {
- if (!hittestSelected || !dragStarted) {
- tvItem.state = 0;
- int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- if ((style & SWT.VIRTUAL) != 0) {
- int 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.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
- if ((wParam & OS.MK_SHIFT) != 0) {
- RECT rect1 = new RECT ();
- if (hAnchor == 0) hAnchor = hNewItem;
- rect1.left = hAnchor;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect1) != 0) {
- RECT rect2 = new RECT ();
- rect2.left = hNewItem;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect2);
- int flags = rect1.top < rect2.top ? OS.TVGN_NEXTVISIBLE : OS.TVGN_PREVIOUSVISIBLE;
- tvItem.state = OS.TVIS_SELECTED;
- int 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, 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 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.
- */
- if (dragStarted) {
- sendDragEvent ((short) (lParam & 0xFFFF), (short) (lParam >> 16));
- } 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 wParam, int lParam) {
- LRESULT result = super.WM_MOUSEMOVE (wParam, lParam);
- if (result != null) return result;
- if (itemToolTipHandle != 0 && hwndHeader != 0) {
- int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON | OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
- if (((wParam & 0xFFFF) & mask) == 0) {
- TVHITTESTINFO lpht = new TVHITTESTINFO ();
- lpht.x = (short) (lParam & 0xFFFF);
- lpht.y = (short) (lParam >> 16);
- OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht);
- if (lpht.hItem != 0) {
- 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);
- POINT pt = new POINT();
- pt.x = lpht.x;
- pt.y = lpht.y;
- RECT rect = new RECT ();
- OS.GetClientRect (hwndParent, rect);
- OS.MapWindowPoints (hwndParent, handle, rect, 2);
- TreeItem item = _getItem (lpht.hItem);
- int index = 0, count = Math.max (1, OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0));
- int [] order = new int [count];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, count, order);
- while (index < count) {
- int hFont = item.cellFont != null ? item.cellFont [order [index]] : -1;
- if (hFont == -1) hFont = item.font;
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- RECT cellRect = item.getBounds (order [index], true, false, true, false, true, hDC);
- if (hFont != -1) OS.SelectObject (hDC, hFont);
- if (cellRect.left > rect.right) break;
- cellRect.right = Math.min (cellRect.right, rect.right);
- if (OS.PtInRect (cellRect, pt)) {
- RECT textRect = item.getBounds (order [index], true, false, false, false, false, hDC);
- if (textRect.right > cellRect.right) {
- 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.left;
- lpti.top = cellRect.top;
- lpti.right = cellRect.right;
- lpti.bottom = cellRect.bottom;
- OS.SendMessage (itemToolTipHandle, OS.TTM_NEWTOOLRECT, 0, lpti);
- }
- break;
- }
- index++;
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_MOVE (int wParam, int lParam) {
- if (ignoreResize) return null;
- return super.WM_MOVE (wParam, lParam);
-}
-
-LRESULT WM_NOTIFY (int wParam, int lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- if (hdr.hwndFrom == itemToolTipHandle && hwndHeader != 0) {
- if (!OS.IsWinCE) {
- switch (hdr.code) {
- case OS.TTN_SHOW: {
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT();
- pt.x = (short) (pos & 0xFFFF);
- pt.y = (short) (pos >> 16);
- 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) {
- 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);
- LRESULT result = null;
- RECT rect = new RECT ();
- OS.GetClientRect (hwndParent, rect);
- OS.MapWindowPoints (hwndParent, handle, rect, 2);
- TreeItem item = _getItem (lpht.hItem);
- int index = 0, count = Math.max (1, OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0));
- int [] order = new int [count];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, count, order);
- while (index < count) {
- int hFont = item.cellFont != null ? item.cellFont [order [index]] : -1;
- if (hFont == -1) hFont = item.font;
- if (hFont != -1) hFont = OS.SelectObject (hDC, hFont);
- RECT cellRect = item.getBounds (order [index], true, false, true, false, true, hDC);
- if (hFont != -1) OS.SelectObject (hDC, hFont);
- if (cellRect.left > rect.right) break;
- cellRect.right = Math.min (cellRect.right, rect.right);
- if (OS.PtInRect (cellRect, pt)) {
- RECT textRect = item.getBounds (order [index], true, false, false, false, false, hDC);
- if (textRect.right > cellRect.right) {
- OS.MapWindowPoints (handle, 0, textRect, 2);
- int flags = OS.SWP_NOACTIVATE | OS.SWP_NOSIZE | OS.SWP_NOZORDER;
- SetWindowPos (itemToolTipHandle, 0, textRect.left, textRect.top, 0, 0, flags);
- result = LRESULT.ONE;
- }
- break;
- }
- index++;
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- if (result != null) return result;
- }
- }
- }
- }
- }
- if (hdr.hwndFrom == hwndHeader) {
- /*
- * 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) {
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; 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 count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- int [] order = new int [count];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, count, 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);
- RECT headerRect = new RECT ();
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- int index = OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, count - 1, 0);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- rect.right = Math.max (rect.right, headerRect.right);
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, phdn.iItem, headerRect);
- int gridWidth = getLinesVisible () ? GRID_WIDTH : 0;
- rect.left = headerRect.right - gridWidth;
- if (findImageControl () != null || hooks (SWT.EraseItem) || hooks (SWT.PaintItem)) {
- OS.InvalidateRect (handle, rect, true);
- } else {
- HDITEM oldItem = new HDITEM ();
- oldItem.mask = OS.HDI_WIDTH;
- OS.SendMessage (hwndHeader, OS.HDM_GETITEM, phdn.iItem, oldItem);
- int deltaX = newItem.cxy - oldItem.cxy;
- 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 = headerRect.right;
- 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 ((style & SWT.DOUBLE_BUFFERED) == 0) {
- if (ignoreColumnMove) {
- 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;
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- TreeColumn [] newColumns = new TreeColumn [count];
- System.arraycopy (columns, 0, newColumns, 0, count);
- int [] order = new int [count];
- OS.SendMessage (hwndHeader, OS.HDM_GETORDERARRAY, count, order);
- boolean moved = false;
- for (int i=0; i<count; 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 super.WM_NOTIFY (wParam, lParam);
-}
-
-LRESULT WM_RBUTTONDOWN (int wParam, int 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);
- setFocus ();
-
- /*
- * 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 explicity 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 = (short) (lParam & 0xFFFF);
- lpht.y = (short) (lParam >> 16);
- OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht);
- if (lpht.hItem != 0) {
- int flags = OS.TVHT_ONITEMICON | OS.TVHT_ONITEMLABEL;
- if ((style & SWT.FULL_SELECTION) != 0 || (lpht.flags & flags) != 0) {
- 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 wParam, int 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) {
- GC gc = null;
- int paintDC = 0;
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- if (hooks (SWT.Paint)) {
- 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);
- }
-
- //TODO - only double buffer the damage
-// int x = ps.left, y = ps.top;
-// int width = ps.right - ps.left;
-// int height = ps.bottom - ps.top;
- forceResize ();
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- int x = rect.left, y = rect.top;
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
-
- int hDC = OS.CreateCompatibleDC (paintDC);
- int hBitmap = OS.CreateCompatibleBitmap (paintDC, width, height);
- int hOldBitmap = OS.SelectObject (hDC, hBitmap);
- drawBackground (hDC, rect);
- int code = callWindowProc (handle, OS.WM_PAINT, hDC, 0);
- OS.BitBlt (paintDC, x, y, width, height, hDC, 0, 0, OS.SRCCOPY);
- OS.SelectObject (hDC, hOldBitmap);
- OS.DeleteObject (hBitmap);
- OS.DeleteObject (hDC);
- if (hooks (SWT.Paint)) {
- 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;
- gc.dispose ();
- } else {
- OS.EndPaint (handle, ps);
- }
- return new LRESULT (code);
- }
- return super.WM_PAINT (wParam, lParam);
-}
-
-LRESULT WM_PRINTCLIENT (int wParam, int 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 code = callWindowProc (handle, OS.WM_PRINTCLIENT, wParam, lParam);
- printClient = false;
- return new LRESULT (code);
-}
-
-LRESULT WM_SETFOCUS (int wParam, int lParam) {
- LRESULT result = super.WM_SETFOCUS (wParam, lParam);
- if ((style & SWT.SINGLE) != 0) return result;
- /*
- * 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 all the
- * visible items when focus is gained or lost.
- */
- OS.InvalidateRect (handle, null, false);
- return result;
-}
-
-LRESULT WM_SETFONT (int wParam, int lParam) {
- LRESULT result = super.WM_SETFONT (wParam, lParam);
- if (result != null) return result;
- if (hwndHeader != 0) {
- OS.SendMessage (hwndHeader, OS.WM_SETFONT, wParam, lParam);
- }
- if (itemToolTipHandle != 0) {
- OS.SendMessage (itemToolTipHandle, OS.WM_SETFONT, wParam, lParam);
- }
- if (headerToolTipHandle != 0) {
- OS.SendMessage (headerToolTipHandle, OS.WM_SETFONT, wParam, lParam);
- }
- return result;
-}
-
-LRESULT WM_SIZE (int wParam, int lParam) {
- /*
- * Bug in Windows. When TVS_NOHSCROLL is set when the
- * size of the tree is zero, the scrol 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);
- }
- if (ignoreResize) return null;
- return super.WM_SIZE (wParam, lParam);
-}
-
-LRESULT WM_SYSCOLORCHANGE (int wParam, int lParam) {
- LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
- if (result != null) return result;
- if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
- return result;
-}
-
-LRESULT wmColorChild (int wParam, int 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 wmNotifyChild (int wParam, int lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- 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 [lptvdi.lParam] != null && items [lptvdi.lParam].cached) {
- checkVisible = false;
- }
- }
- }
- if (checkVisible) {
- if (drawCount != 0 || !OS.IsWindowVisible (handle)) break;
- RECT itemRect = new RECT ();
- itemRect.left = lptvdi.hItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, itemRect) == 0) {
- 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 = 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 = 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 = 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);
- }
- }
- 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 (wParam, lParam);
- case OS.CDDS_ITEMPREPAINT: return CDDS_ITEMPREPAINT (wParam, lParam);
- case OS.CDDS_ITEMPOSTPAINT: return CDDS_ITEMPOSTPAINT (wParam, lParam);
- case OS.CDDS_POSTPAINT: return CDDS_POSTPAINT (wParam, lParam);
- }
- break;
- }
- case OS.NM_DBLCLK: {
- if (hooks (SWT.DefaultSelection)) return LRESULT.ONE;
- break;
- }
- case OS.TVN_SELCHANGEDA:
- case OS.TVN_SELCHANGEDW: {
- if ((style & SWT.MULTI) != 0) {
- if (lockSelection) {
- /* Restore the old selection state of both items */
- if (oldSelected) {
- TVITEM tvItem = new TVITEM ();
- int offset = NMHDR.sizeof + 4;
- OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof);
- 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) {
- TVITEM tvItem = new TVITEM ();
- int offset = NMHDR.sizeof + 4 + TVITEM.sizeof;
- OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof);
- tvItem.mask = OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- tvItem.state = 0;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- }
- }
- if (!ignoreSelect) {
- TVITEM tvItem = new TVITEM ();
- int offset = NMHDR.sizeof + 4 + TVITEM.sizeof;
- OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof);
- hAnchor = tvItem.hItem;
- Event event = new Event ();
- event.item = _getItem (tvItem.hItem, tvItem.lParam);
- postEvent (SWT.Selection, event);
- }
- updateScrollBar ();
- 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 pItemChange = new NMTVITEMCHANGE ();
- OS.MoveMemory (pItemChange, lParam, NMTVITEMCHANGE.sizeof);
- if (hSelect == pItemChange.hItem) break;
- return LRESULT.ONE;
- }
- if (lockSelection) 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 */
- TVITEM tvItem = new TVITEM ();
- int offset1 = NMHDR.sizeof + 4;
- OS.MoveMemory (tvItem, lParam + offset1, TVITEM.sizeof);
- oldSelected = (tvItem.state & OS.TVIS_SELECTED) != 0;
- int offset2 = NMHDR.sizeof + 4 + TVITEM.sizeof;
- OS.MoveMemory (tvItem, lParam + offset2, TVITEM.sizeof);
- newSelected = (tvItem.state & OS.TVIS_SELECTED) != 0;
- }
- }
- if (!ignoreSelect && !ignoreDeselect) {
- hAnchor = 0;
- if ((style & SWT.MULTI) != 0) deselectAll ();
- }
- break;
- }
- case OS.TVN_ITEMEXPANDINGA:
- case OS.TVN_ITEMEXPANDINGW: {
- 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 && drawCount == 0 && 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) {
- TVITEM tvItem = new TVITEM ();
- int offset = NMHDR.sizeof + 4 + TVITEM.sizeof;
- OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof);
- /*
- * 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, tvItem.lParam);
- if (item == null) break;
- Event event = new Event ();
- event.item = item;
- int [] action = new int [1];
- OS.MoveMemory (action, lParam + NMHDR.sizeof, 4);
- switch (action [0]) {
- 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 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 && drawCount == 0 /*&& 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);
- }
- updateScrollBar ();
- break;
- }
- case OS.TVN_BEGINDRAGA:
- case OS.TVN_BEGINDRAGW:
- case OS.TVN_BEGINRDRAGA:
- case OS.TVN_BEGINRDRAGW: {
- TVITEM tvItem = new TVITEM ();
- int offset = NMHDR.sizeof + 4 + TVITEM.sizeof;
- OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof);
- 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;
- }
- dragStarted = true;
- 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 (wParam, lParam);
-}
-
-}
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 0b3a2262ab..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeColumn.java
+++ /dev/null
@@ -1,749 +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.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>
- *
- * @since 3.1
- */
-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>
- *
- * @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 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
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 hwnd = parent.handle, hwndHeader = parent.hwndHeader;
- RECT headerRect = new RECT ();
- OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect);
- int hDC = OS.GetDC (hwnd);
- int 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 [tvItem.lParam] : null;
- if (item != null) {
- int hFont = item.cellFont != null ? item.cellFont [index] : -1;
- if (hFont == -1) hFont = item.font;
- 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);
- if (parent.hooks (SWT.MeasureItem)) {
- int nSavedDC = OS.SaveDC (hDC);
- GCData data = new GCData ();
- data.device = display;
- data.hFont = hFont;
- 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;
- parent.sendEvent (SWT.MeasureItem, event);
- event.gc = null;
- gc.dispose ();
- OS.RestoreDC (hDC, nSavedDC);
- if (isDisposed () || parent.isDisposed ()) break;
- if (event.height > parent.getItemHeight ()) parent.setItemHeight (event.height);
- //itemRect.left = event.x;
- itemRect.right = event.x + event.width;
- }
- columnWidth = Math.max (columnWidth, itemRect.right - 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.NULL) {
- 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 = 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);
- setWidth (Math.max (headerWidth, columnWidth));
-}
-
-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.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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>.
- *
- * @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 hwndHeader = parent.hwndHeader;
- if (hwndHeader == 0) return;
- 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;
- 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 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.NULL) {
- setImage (image, false, false);
- }
-}
-
-void setImage (Image image, boolean sort, boolean right) {
- int index = parent.indexOf (this);
- if (index == -1) return;
- int 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.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 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;
- break;
- case SWT.DOWN:
- hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_SORTUP);
- hdItem.fmt |= OS.HDF_SORTDOWN;
- 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;
- }
- break;
- }
- OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem);
- if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
- int 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 hHeap = OS.GetProcessHeap ();
- TCHAR buffer = new TCHAR (parent.getCodePage (), fixMnemonic (string), true);
- int byteCount = buffer.length () * TCHAR.sizeof;
- int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- OS.MoveMemory (pszText, buffer, byteCount);
- int hwndHeader = parent.hwndHeader;
- if (hwndHeader == 0) return;
- HDITEM hdItem = new HDITEM ();
- hdItem.mask = OS.HDI_TEXT;
- hdItem.pszText = pszText;
- int 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 no tool tip text should be shown.
- *
- * @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 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 ();
- int index = parent.indexOf (this);
- if (index == -1) return;
- int 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 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 hwndHeaderToolTip = parent.headerToolTipHandle;
- if (hwndHeaderToolTip != 0) {
- int 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 f469f27f83..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java
+++ /dev/null
@@ -1,1580 +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.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>
- */
-
-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 handle;
- Tree parent;
- String [] strings;
- Image [] images;
- boolean cached;
- int background = -1, foreground = -1, font = -1;
- int [] cellBackground, cellForeground, cellFont;
-
-/**
- * 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 hParent, int hInsertAfter, int 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 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 hwnd = parent.handle;
- int hFirstItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- int hItem = parent.findItem (hFirstItem, index - 1);
- if (hItem == 0) SWT.error (SWT.ERROR_INVALID_RANGE);
- return hItem;
-}
-
-static int 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 hwnd = parent.handle, hParent = parentItem.handle;
- int hFirstItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hParent);
- int 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 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 = font = -1;
- cellBackground = cellForeground = 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 hwnd = parent.handle;
- int 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 hwnd = parent.handle;
- int 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 ();
-}
-
-/**
- * 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 hDC) {
- if (!getText && !getImage) return new RECT ();
- int 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, hwndHeader = parent.hwndHeader;
- if (hwndHeader != 0) {
- columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- firstColumn = index == OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0);
- }
- RECT rect = new RECT ();
- if (firstColumn) {
- rect.left = handle;
- boolean full = columnCount == 0 && getText && getImage && fullText && fullImage;
- if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, full ? 0 : 1, rect) == 0) {
- 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) 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 ();
- }
- rect.left = handle;
- if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 0, rect) == 0) {
- return new RECT ();
- }
- rect.left = headerRect.left;
- if (fullText) {
- 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) {
- 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 hNewDC = hDC, hFont = 0;
- if (hDC == 0) {
- hNewDC = OS.GetDC (hwnd);
- hFont = cellFont != null ? cellFont [index] : -1;
- if (hFont == -1) hFont = font;
- 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.getLinesVisible () ? 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 hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_STATEIMAGEMASK;
- tvItem.hItem = handle;
- int 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 ();
- /*
- * 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 hwnd = parent.handle;
- int state = 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 == -1 ? parent.getFont () : Font.win32_new (display, font);
-}
-
-/**
- * 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 ();
- int hFont = (cellFont != null) ? cellFont [index] : font;
- return hFont == -1 ? getFont () : 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>
- *
- * @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 hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_STATEIMAGEMASK;
- tvItem.hItem = handle;
- int 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 hwnd = parent.handle;
- int hFirstItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- if (hFirstItem == 0) error (SWT.ERROR_INVALID_RANGE);
- int 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 hwnd = parent.handle;
- int 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 hwnd = parent.handle;
- int 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 hwnd = parent.handle;
- int 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 "";
-}
-
-/**
- * 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>
- *
- * @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 hwnd = parent.handle;
- int 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.drawCount != 0) return;
- int hwnd = parent.handle;
- if (!OS.IsWindowVisible (hwnd)) return;
- RECT rect = new RECT ();
- rect.left = handle;
- /*
- * 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) {
- int hwndHeader = parent.hwndHeader;
- if (hwndHeader != 0) {
- full = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0) != 0;
- }
- if (!full) {
- if (parent.hooks (SWT.EraseItem) || parent.hooks (SWT.PaintItem)) {
- full = true;
- }
- }
- }
- if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, full ? 0 : 1, rect) != 0) {
- OS.InvalidateRect (hwnd, rect, true);
- }
-}
-
-void redraw (int column, boolean drawText, boolean drawImage) {
- if (parent.currentItem == this || parent.drawCount != 0) return;
- int 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 = 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 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 [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 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);
-}
-
-/**
- * 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 ();
- /*
- * 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
- * seletion 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 notice
- * that the selection has changed and issue the event.
- */
- int hwnd = parent.handle;
- int hOldItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- parent.ignoreExpand = true;
- OS.SendMessage (hwnd, OS.TVM_EXPAND, expanded ? OS.TVE_EXPAND : OS.TVE_COLLAPSE, handle);
- parent.ignoreExpand = false;
- int 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);
- }
- int hFont = -1;
- if (font != null) {
- parent.customDraw = true;
- hFont = font.handle;
- }
- if (this.font == hFont) return;
- this.font = hFont;
- 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;
- }
- if (this != parent.currentItem) {
- int 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;
- int hFont = -1;
- if (font != null) {
- parent.customDraw = true;
- hFont = font.handle;
- }
- if (cellFont == null) {
- cellFont = new int [count];
- for (int i = 0; i < count; i++) {
- cellFont [i] = -1;
- }
- }
- if (cellFont [index] == hFont) return;
- cellFont [index] = hFont;
- 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;
- }
- if (this != parent.currentItem) {
- int 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)
- *
- * @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);
- }
- 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 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);
-}
-
-/**
- * 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;
- }
- if (this != parent.currentItem) {
- int 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 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 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 hwnd = parent.handle;
- int hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- parent.setItemCount (count, handle, hItem);
-}
-
-/**
- * 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;
- }
- if (this != parent.currentItem) {
- int 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);
-}
-
-}
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 fd9200a7cf..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java
+++ /dev/null
@@ -1,2347 +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.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
- */
-
-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 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;
-
- /* Mouse track flag */
- static final int TRACK_MOUSE = 1<<13;
-
- /* Default size for widgets */
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
- /* Windows XP Theme Classes */
- static final char [] BUTTON = new char [] {'B', 'U', 'T', 'T', 'O', 'N', 0};
- static final char [] EDIT = new char [] {'E', 'D', 'I', 'T', 0};
- final static 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 [] TAB = new char [] {'T', 'A', 'B', 0};
-
- /* 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 #removeListener
- * @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 callWindowProc (int hwnd, int msg, int wParam, int 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 ()) 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
- * 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 ();
-}
-
-int DeferWindowPos(int hWinPosInfo, int hWnd, int 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 descendents. After this method has
- * been invoked, the receiver and all descendents 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 descendents
- * 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 x, int y) {
- return hooks (SWT.DragDetect);
-}
-
-boolean dragOverride () {
- return false;
-}
-
-/**
- * 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 id) {
- return null;
-}
-
-char [] fixMnemonic (String string) {
- char [] buffer = new char [string.length ()];
- 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] == '&') {
- buffer [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;
-}
-
-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 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 #removeListener
- */
-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 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;
-}
-
-/*
- * 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 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 #addListener
- * @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 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 #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 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 #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 x, int y) {
- Event event = new Event ();
- event.x = x;
- event.y = y;
- 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 wParam, int 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 wParam, int lParam, Event event) {
- sendEvent (type, event);
- if (isDisposed ()) return false;
- return event.doit;
-}
-
-boolean sendMouseEvent (int type, int button, int hwnd, int msg, int wParam, int lParam) {
- return sendMouseEvent (type, button, 0, 0, false, hwnd, msg, wParam, lParam);
-}
-
-boolean sendMouseEvent (int type, int button, int count, int detail, boolean send, int hwnd, int msg, int wParam, int lParam) {
- if (!hooks (type) && !filters (type)) return true;
- Event event = new Event ();
- event.button = button;
- event.detail = detail;
- event.count = count;
- event.x = (short) (lParam & 0xFFFF);
- event.y = (short) (lParam >> 16);
- 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;
- 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 wParam, int 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 explictly (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 SetWindowPos (int hWnd, int 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);
- 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 hwnd, int wParam, int lParam) {
- display.captureChanged = true;
- return null;
-}
-
-LRESULT wmChar (int hwnd, int wParam, int 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 = 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 hwnd, int wParam, int 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 ();
- x = pt.x = (short) (lParam & 0xFFFF);
- y = pt.y = (short) (lParam >> 16);
- 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 = (short) (pos & 0xFFFF);
- y = (short) (pos >> 16);
- }
-
- /* Show the menu */
- return showMenu (x, y) ? LRESULT.ZERO : null;
-}
-
-LRESULT wmIMEChar (int hwnd, int wParam, int lParam) {
- Display display = this.display;
- display.lastKey = 0;
- display.lastAscii = 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 hwnd, int wParam, int lParam) {
-
- /* Ignore repeating modifier keys by testing key down state */
- switch (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 (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 (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 ? wParam : mapKey;
- return null;
- }
-
- /*
- * Bug in Windows. Somehow, the widget is becoming disposed after
- * calling PeekMessage(). In rare cirucmstances, 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 (wParam) != 0;
- if (display.lastVirtual) {
- display.lastKey = 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 explictly (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 = 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 (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 != 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 (wParam);
- if (display.lastAscii == 0) display.lastAscii = mapKey;
- } else {
- display.lastAscii = 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 hwnd, int wParam, int 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 = 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 (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 (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 (wParam) != 0;
- if (display.lastVirtual) {
- display.lastKey = 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 distingush 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 hwnd, int wParam, int lParam) {
- int 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 hwnd, int wParam, int 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 hwnd, int wParam, int lParam) {
- LRESULT result = null;
- boolean dragging = false, mouseDown = true;
- int x = (short) (lParam & 0xFFFF);
- int y = (short) (lParam >> 16);
- boolean dragDetect = dragDetect (x, y);
- if (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.
- */
- POINT pt = new POINT ();
- pt.x = x;
- pt.y = y;
- OS.ClientToScreen (hwnd, pt);
- dragging = OS.DragDetect (hwnd, pt);
- mouseDown = OS.GetKeyState (OS.VK_LBUTTON) < 0;
- }
- }
- Display display = this.display;
- display.captureChanged = false;
- boolean dragOverride = dragging && dragOverride ();
- boolean dispatch = sendMouseEvent (SWT.MouseDown, 1, hwnd, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (dispatch && !dragOverride) {
- 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 ((short) (lParam & 0xFFFF), (short) (lParam >> 16));
- } else {
- if (dragDetect) {
- /*
- * 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 hwnd, int wParam, int lParam) {
- 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;
- }
- int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON | OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
- if (((wParam & 0xFFFF) & mask) == 0) {
- if (OS.GetCapture () == hwnd) OS.ReleaseCapture ();
- }
- return result;
-}
-
-LRESULT wmMButtonDblClk (int hwnd, int wParam, int 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 hwnd, int wParam, int 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 hwnd, int wParam, int lParam) {
- 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;
- }
- int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON | OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
- if (((wParam & 0xFFFF) & mask) == 0) {
- if (OS.GetCapture () == hwnd) OS.ReleaseCapture ();
- }
- return result;
-}
-
-LRESULT wmMouseHover (int hwnd, int wParam, int lParam) {
- if (!sendMouseEvent (SWT.MouseHover, 0, hwnd, OS.WM_MOUSEHOVER, wParam, lParam)) {
- return LRESULT.ZERO;
- }
- return null;
-}
-
-LRESULT wmMouseLeave (int hwnd, int wParam, int lParam) {
- if (!hooks (SWT.MouseExit) && !filters (SWT.MouseExit)) return null;
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT ();
- pt.x = (short) (pos & 0xFFFF);
- pt.y = (short) (pos >> 16);
- OS.ScreenToClient (hwnd, pt);
- lParam = pt.x | (pt.y << 16);
- if (!sendMouseEvent (SWT.MouseExit, 0, hwnd, OS.WM_MOUSELEAVE, wParam, lParam)) {
- return LRESULT.ZERO;
- }
- return null;
-}
-
-LRESULT wmMouseMove (int hwnd, int wParam, int 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 hwnd, int wParam, int lParam) {
- if (!hooks (SWT.MouseWheel) && !filters (SWT.MouseWheel)) return null;
- int delta = wParam >> 16;
- int [] value = new int [1];
- int count, detail;
- OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, value, 0);
- if (value [0] == OS.WHEEL_PAGESCROLL) {
- detail = SWT.SCROLL_PAGE;
- count = delta / OS.WHEEL_DELTA;
- } else {
- detail = SWT.SCROLL_LINE;
- count = value [0] * delta / OS.WHEEL_DELTA;
- }
- POINT pt = new POINT ();
- pt.x = (short) (lParam & 0xFFFF);
- pt.y = (short) (lParam >> 16);
- OS.ScreenToClient (hwnd, pt);
- lParam = pt.x | (pt.y << 16);
- if (!sendMouseEvent (SWT.MouseWheel, 0, count, detail, true, hwnd, OS.WM_MOUSEWHEEL, wParam, lParam)) {
- return LRESULT.ZERO;
- }
- return null;
-}
-
-LRESULT wmPaint (int hwnd, int wParam, int lParam) {
-
- /* Exit early - don't draw the background */
- if (!hooks (SWT.Paint) && !filters (SWT.Paint)) {
- return null;
- }
-
- /* Issue a paint event */
- int 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 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 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 hwnd, int wParam, int 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 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);
- int hTheme = OS.OpenThemeData (hwnd, EDIT);
- OS.DrawThemeBackground (hTheme, wParam, OS.EP_EDITTEXT, OS.ETS_NORMAL, rect, null);
- OS.CloseThemeData (hwnd);
- return new LRESULT (code);
- }
- }
- }
- return null;
-}
-
-LRESULT wmRButtonDblClk (int hwnd, int wParam, int 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 hwnd, int wParam, int 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 hwnd, int wParam, int lParam) {
- 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;
- }
- int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON | OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
- if (((wParam & 0xFFFF) & mask) == 0) {
- if (OS.GetCapture () == hwnd) OS.ReleaseCapture ();
- }
- return result;
-}
-
-LRESULT wmSetFocus (int hwnd, int wParam, int lParam) {
- int 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 hwnd, int wParam, int lParam) {
- Display display = this.display;
- display.lastAscii = 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 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 hwnd, int wParam, int 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 (wParam) {
- case OS.VK_F4: return null;
- }
-
- /* Ignore repeating modifier keys by testing key down state */
- switch (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 (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 (wParam, 2);
- }
- display.lastVirtual = mapKey == 0 || display.numpadKey (wParam) != 0;
- if (display.lastVirtual) {
- display.lastKey = 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 explictly (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) {
- 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 = 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 hwnd, int wParam, int lParam) {
- return wmKeyUp (hwnd, wParam, lParam);
-}
-
-LRESULT wmXButtonDblClk (int hwnd, int wParam, int 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 = (wParam >> 16 == 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 hwnd, int wParam, int lParam) {
- LRESULT result = null;
- Display display = this.display;
- display.captureChanged = false;
- int button = (wParam >> 16 == 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 hwnd, int wParam, int lParam) {
- LRESULT result = null;
- int button = (wParam >> 16 == 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;
- }
- int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON | OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
- if (((wParam & 0xFFFF) & mask) == 0) {
- if (OS.GetCapture () == hwnd) OS.ReleaseCapture ();
- }
- return result;
-}
-}

Back to the top