summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h24
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java4756
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java220
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java206
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java56
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java62
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java78
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java60
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java82
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java58
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java64
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java76
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java58
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java82
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java58
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java66
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java76
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java118
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java80
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java76
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java58
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java78
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java58
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java62
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java102
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java134
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java100
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java62
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java104
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java102
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java150
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java64
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java76
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java192
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java98
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java130
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java58
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java120
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java238
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java76
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java76
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java58
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java80
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java136
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java108
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java76
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Drawable.java86
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java7094
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java580
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderEvent.java152
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoaderListener.java74
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/PaletteData.java408
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java184
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java214
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java544
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java372
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java214
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/GIFFileFormat.java1048
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGAppn.java42
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGArithmeticConditioningTable.java32
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGComment.java40
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGEndOfImage.java48
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFileFormat.java3778
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFixedSizeSegment.java74
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGFrameHeader.java414
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGHuffmanTable.java522
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGQuantizationTable.java316
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGRestartInterval.java48
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGScanHeader.java232
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGSegment.java102
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGStartOfImage.java56
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGVariableSizeSegment.java62
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataInputStream.java354
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LEDataOutputStream.java100
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWCodec.java950
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/LZWNode.java20
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java1060
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java664
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunkReader.java124
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java256
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngFileReadState.java36
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java240
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTables.java308
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIdatChunk.java68
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIendChunk.java74
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java742
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngLzBlockReader.java330
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java172
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngTrnsChunk.java262
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java1324
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java562
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java216
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormAttachment.java516
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormLayout.java10
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridData.java384
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/GridLayout.java1376
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowData.java100
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java588
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Dialog.java500
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Event.java410
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/EventTable.java254
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java348
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Layout.java160
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Listener.java88
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/RunnableLock.java64
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Synchronizer.java310
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java442
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/version.txt2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/CloneableCompatibility.java46
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/Compatibility.java778
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SWTEventListener.java38
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SWTEventObject.java106
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SerializableCompatibility.java48
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/CloneableCompatibility.java38
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/Compatibility.java600
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTEventListener.java42
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTEventObject.java60
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SWTMessages.properties82
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SerializableCompatibility.java44
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/bidi/org/eclipse/swt/internal/BidiUtil.java164
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolBar.java2104
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/coolbar/org/eclipse/swt/widgets/CoolItem.java1234
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabFolder.java2222
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabItem.java772
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/AbstractTreeItem.java620
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/SelectableItem.java630
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/SelectableItemWidget.java4126
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Table.java5396
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableColumn.java1012
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TableItem.java2400
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Tree.java3308
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeItem.java2710
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeRoots.java312
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java250
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java266
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java366
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java200
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java488
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java92
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java1712
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java62
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java744
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java528
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/Converter.java100
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java410
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java204
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java456
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java276
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java1046
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java288
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java2136
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java1074
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java350
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java1074
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java582
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java336
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java150
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java264
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java1212
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java790
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java866
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java940
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java258
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java710
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java544
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/WidgetTable.java200
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/DefaultGtkStyle.java230
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontData.java868
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java104
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GCData.java28
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Region.java210
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/internal/Converter.java112
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ColorDialog.java164
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Decorations.java322
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/DirectoryDialog.java100
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FileDialog.java136
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FontDialog.java162
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Menu.java522
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/MenuItem.java702
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabFolder.java870
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabItem.java184
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableColumn.java408
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableItem.java740
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ToolBar.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Tracker.java778
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TreeItem.java824
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/WidgetTable.java176
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java386
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java320
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java922
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java44
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java734
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java668
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java108
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java3320
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java42
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java1930
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java180
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java610
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java1260
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java432
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java868
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java822
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java2746
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java1294
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java5450
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java1122
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java556
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java4454
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java886
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java1852
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java540
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java818
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java2862
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java1380
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java1524
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java750
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java702
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java718
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java586
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java1184
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java580
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java2504
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java976
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java2612
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java768
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java72
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java1976
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java1134
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java2120
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java240
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Color.java202
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Cursor.java372
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Device.java568
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/DeviceData.java30
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Font.java308
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontData.java422
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontMetrics.java152
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GC.java3430
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GCData.java42
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Image.java1326
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Region.java298
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/Converter.java92
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Button.java884
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Canvas.java220
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Caret.java526
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ColorDialog.java106
-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.java1248
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Control.java2988
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Decorations.java440
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/DirectoryDialog.java122
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java2778
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FileDialog.java258
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FontDialog.java168
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Group.java252
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java610
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/List.java1180
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Menu.java768
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java1046
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MessageBox.java222
-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.java632
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scale.java328
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ScrollBar.java654
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scrollable.java248
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java1678
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Slider.java444
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabFolder.java890
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabItem.java264
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Text.java1460
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java606
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolItem.java1106
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Tracker.java1210
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Widget.java1580
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/WidgetTable.java212
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Color.java654
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java802
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java1420
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/DeviceData.java30
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java506
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontData.java1380
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java340
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java4604
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GCData.java60
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java3798
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java608
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/BidiUtil.java1056
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Converter.java366
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java1418
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java426
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java1104
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java390
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java2916
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java1654
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java8440
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java1996
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java1324
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java2722
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DirectoryDialog.java478
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java4660
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FileDialog.java816
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java468
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Group.java740
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ImageList.java502
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java1160
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java3074
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java2394
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java1946
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MessageBox.java498
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java552
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java802
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java826
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java2002
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java752
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java2718
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java1592
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java1578
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabItem.java628
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java5018
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java952
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java1416
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java3504
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java1850
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java1656
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java1446
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java3808
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java1362
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java2108
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/WidgetTable.java224
331 files changed, 136586 insertions, 136586 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h b/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h
index 0bdba60b2b..b2af780054 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/library/swt.h
@@ -5,24 +5,24 @@
* http://www.eclipse.org/legal/cpl-v10.html
*/
-/**
- * swt.h
- *
- * This file contains the global macro declarations for the
- * SWT library.
- *
- */
-
+/**
+ * swt.h
+ *
+ * This file contains the global macro declarations for the
+ * SWT library.
+ *
+ */
+
#ifndef INC_swt_H
#define INC_swt_H
#include "jni.h"
-/* For debugging */
+/* For debugging */
#define DEBUG_PRINTF(x)
-/*#define DEBUG_PRINTF(x) printf x; */
-
-/* define this to print out debug statements */
+/*#define DEBUG_PRINTF(x) printf x; */
+
+/* define this to print out debug statements */
/* #define DEBUG_CALL_PRINTS */
/* #define DEBUG_CHECK_NULL_EXCEPTIONS */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
index b605ea0cea..583abe368e 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
@@ -1,2381 +1,2381 @@
-package org.eclipse.swt;
-
-/*
+package org.eclipse.swt;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-
-/**
- * This class provides access to a small number of SWT system-wide
- * methods, and in addition defines the public constants provided
- * by SWT.
- * <p>
- * By defining constants like UP and DOWN in a single class, SWT
- * can share common names and concepts at the same time minimizing
- * the number of classes, names and constants for the application
- * programmer.
- * </p><p>
- * Note that some of the constants provided by this class represent
- * optional, appearance related aspects of widgets which are available
- * either only on some window systems, or for a differing set of
- * widgets on each window system. These constants are marked
- * as <em>HINT</em>s. The set of widgets which support a particular
- * <em>HINT</em> may change from release to release, although we typically
- * will not withdraw support for a <em>HINT</em> once it is made available.
- * </p>
- */
-
-/* NOTE:
- * Good javadoc coding style is to put the values of static final
- * constants in the comments. This reinforces the fact that
- * consumers are allowed to rely on the value (and they must
- * since the values are compiled inline in their code). We
- * can <em>not</em> change the values of these constants between
- * releases.
- */
-public class SWT {
-
- /* Initialize the class */
-// static {
-// /* NOTE: the static initialization is at the end of file */
-// }
-
- /* Widget Event Constants */
-
- /**
- * key down event type (value is 1)
- */
- public static final int KeyDown = 1;
-
- /**
- * key up event type (value is 2)
- */
- public static final int KeyUp = 2;
-
- /**
- * mouse down event type (value is 3)
- */
- public static final int MouseDown = 3;
-
- /**
- * mouse up event type (value is 4)
- */
- public static final int MouseUp = 4;
-
- /**
- * mouse move event type (value is 5)
- */
- public static final int MouseMove = 5;
-
- /**
- * mouse enter event type (value is 6)
- */
- public static final int MouseEnter = 6;
-
- /**
- * Mouse exit event type (value is 7)
- */
- public static final int MouseExit = 7;
-
- /**
- * mouse double click event type (value is 8)
- */
- public static final int MouseDoubleClick = 8;
-
- /**
- * paint event type (value is 9)
- */
- public static final int Paint = 9;
-
- /**
- * move event type (value is 10)
- */
- public static final int Move = 10;
-
- /**
- * resize event type (value is 11)
- */
- public static final int Resize = 11;
-
- /**
- * dispose event type (value is 12)
- */
- public static final int Dispose = 12;
-
- /**
- * selection event type (value is 13)
- */
- public static final int Selection = 13;
-
- /**
- * default selection event type (value is 14)
- */
- public static final int DefaultSelection = 14;
-
- /**
- * focus in event type (value is 15)
- */
- public static final int FocusIn = 15;
-
- /**
- * focus out event type (value is 16)
- */
- public static final int FocusOut = 16;
-
- /**
- * expand event type (value is 17)
- */
- public static final int Expand = 17;
-
- /**
- * collapse event type (value is 18)
- */
- public static final int Collapse = 18;
-
- /**
- * iconify event type (value is 19)
- */
- public static final int Iconify = 19;
-
- /**
- * de-iconify event type (value is 20)
- */
- public static final int Deiconify = 20;
-
- /**
- * close event type (value is 21)
- */
- public static final int Close = 21;
-
- /**
- * show event type (value is 22)
- */
- public static final int Show = 22;
-
- /**
- * hide event type (value is 23)
- */
- public static final int Hide = 23;
-
- /**
- * modify event type (value is 24)
- */
- public static final int Modify = 24;
-
- /**
- * verify event type (value is 25)
- */
- public static final int Verify = 25;
-
- /**
- * activate event type (value is 26)
- */
- public static final int Activate = 26;
-
- /**
- * deactivate event type (value is 27)
- */
- public static final int Deactivate = 27;
-
- /**
- * help event type (value is 28)
- */
- public static final int Help = 28;
-
- /**
- * drag detect event type (value is 29)
- */
- public static final int DragDetect = 29;
-
- /**
- * arm event type (value is 30)
- */
- public static final int Arm = 30;
-
- /**
- * traverse event type (value is 31)
- */
- public static final int Traverse = 31;
-
- /**
- * mouse hover event type (value is 32)
- */
- public static final int MouseHover = 32;
-
- /**
- * hardware key down event type (value is 33)
- */
- public static final int HardKeyDown = 33;
-
- /**
- * hardware key up event type (value is 34)
- */
- public static final int HardKeyUp = 34;
-
- /* Event Details */
-
- /**
- * a constant known to be zero (0), used in operations which
- * take bit flags to indicate that "no bits are set"
- */
- public static final int NONE = 0;
-
- /**
- * indicates that a user-interface component is being dragged,
- * for example dragging the thumb of a scroll bar (value is 1)
- */
- public static final int DRAG = 1;
-
- /**
- * a constant known to be zero (0), used in operations which
- * take pointers to indicate a null argument
- */
- public static final int NULL = 0;
-
- /**
- * indicates that a default should be used (value is -1)
- */
- public static final int DEFAULT = -1;
-
- /**
- * style constant for menu bar behavior (value is 1&lt;&lt;1)
- * <p><b>Used By:</b><ul>
- * <li><code>Menu</code></li>
- * </ul></p>
- */
- public static final int BAR = 1 << 1;
-
- /**
- * style constant for drop down menu/list behavior (value is 1&lt;&lt;2)
- * <p><b>Used By:</b><ul>
- * <li><code>Menu</code></li>
- * <li><code>ToolItem</code></li>
- * <li><code>CoolItem</code></li>
- * <li><code>Combo</code></li>
- * </ul></p>
- */
- public static final int DROP_DOWN = 1 << 2;
-
- /**
- * style constant for pop up menu behavior (value is 1&lt;&lt;3)
- * <p><b>Used By:</b><ul>
- * <li><code>Menu</code></li>
- * </ul></p>
- */
- public static final int POP_UP = 1 << 3;
-
- /**
- * style constant for line separator behavior (value is 1&lt;&lt;1)
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>MenuItem</code></li>
- * <li><code>ToolItem</code></li>
- * </ul></p>
- */
- public static final int SEPARATOR = 1 << 1;
-
- /**
- * style constant for toggle button behavior (value is 1&lt;&lt;1)
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * </ul></p>
- */
- public static final int TOGGLE = 1 << 1;
-
- /**
- * style constant for arrow button behavior (value is 1&lt;&lt;2)
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * </ul></p>
- */
- public static final int ARROW = 1 << 2;
-
- /**
- * style constant for push button behavior (value is 1&lt;&lt;3)
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>MenuItem</code></li>
- * <li><code>ToolItem</code></li>
- * </ul></p>
- */
- public static final int PUSH = 1 << 3;
-
- /**
- * style constant for radio button behavior (value is 1&lt;&lt;4)
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>MenuItem</code></li>
- * <li><code>ToolItem</code></li>
- * </ul></p>
- */
- public static final int RADIO = 1 << 4;
-
- /**
- * style constant for check box behavior (value is 1&lt;&lt;5)
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>MenuItem</code></li>
- * <li><code>ToolItem</code></li>
- * <li><code>Table</code></li>
- * <li><code>Tree</code></li>
- * </ul></p>
- */
- public static final int CHECK = 1 << 5;
-
- /**
- * style constant for cascade behavior (value is 1&lt;&lt;6)
- * <p><b>Used By:</b><ul>
- * <li><code>MenuItem</code></li>
- * </ul></p>
- */
- public static final int CASCADE = 1 << 6;
-
- /**
- * style constant for multi-selection behavior in lists
- * and multiple line support on text fields (value is 1&lt;&lt;1)
- * <p><b>Used By:</b><ul>
- * <li><code>Text</code></li>
- * <li><code>List</code></li>
- * <li><code>FileDialog</code></li>
- * </ul></p>
- */
- public static final int MULTI = 1 << 1;
-
- /**
- * style constant for single selection behavior in lists
- * and single line support on text fields (value is 1&lt;&lt;2)
- * <p><b>Used By:</b><ul>
- * <li><code>Text</code></li>
- * <li><code>List</code></li>
- * <li><code>Table</code></li>
- * <li><code>Tree</code></li>
- * </ul></p>
- */
- public static final int SINGLE = 1 << 2;
-
- /**
- * style constant for read-only behavior (value is 1&lt;&lt;3)
- * <p><b>Used By:</b><ul>
- * <li><code>Combo</code></li>
- * <li><code>Text</code></li>
- * </ul></p>
- */
- public static final int READ_ONLY = 1 << 3;
-
- /**
- * style constant for automatic line wrap behavior (value is 1&lt;&lt;6)
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>Text</code></li>
- * <li><code>ToolBar</code></li>
- * </ul></p>
- */
- public static final int WRAP = 1 << 6;
-
- /**
- * style constant for simple (not drop down) behavior (value is 1&lt;&lt;6)
- * <p><b>Used By:</b><ul>
- * <li><code>Combo</code></li>
- * </ul></p>
- */
- public static final int SIMPLE = 1 << 6;
-
- /**
- * style constant for shadow in behavior (value is 1&lt;&lt;2)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>Group</code></li>
- * </ul></p>
- */
- public static final int SHADOW_IN = 1 << 2;
-
- /**
- * style constant for shadow out behavior (value is 1&lt;&lt;3)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>Group</code></li>
- * <li><code>ToolBar</code></li>
- * </ul></p>
- */
- public static final int SHADOW_OUT = 1 << 3;
-
- /**
- * style constant for shadow etched in behavior (value is 1&lt;&lt;4)
- * <br>Note that this is a <em>HINT</em>. It is ignored on all platforms except Motif.
- * <p><b>Used By:</b><ul>
- * <li><code>Group</code></li>
- * </ul></p>
- */
- public static final int SHADOW_ETCHED_IN = 1 << 4;
-
- /**
- * style constant for shadow etched out behavior (value is 1&lt;&lt;6)
- * <br>Note that this is a <em>HINT</em>. It is ignored on all platforms except Motif.
- * <p><b>Used By:</b><ul>
- * <li><code>Group</code></li>
- * </ul></p>
- */
- public static final int SHADOW_ETCHED_OUT = 1 << 6;
-
- /**
- * style constant for no shadow behavior (value is 1&lt;&lt;5)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>Group</code></li>
- * </ul></p>
- */
- public static final int SHADOW_NONE = 1 << 5;
-
- /**
- * style constant for progress bar behavior (value is 1&lt;&lt;1)
- * <p><b>Used By:</b><ul>
- * <li><code>ProgressBar</code></li>
- * </ul></p>
- */
- public static final int INDETERMINATE = 1 << 1;
-
- /**
- * style constant for tool window behavior (value is 1&lt;&lt;2)
- * <p>
- * A tool window is a window intended to be used as a floating toolbar.
- * It typically has a title bar that is shorter than a normal title bar,
- * and the window title is typically drawn using a smaller font.
- * <br>Note that this is a <em>HINT</em>.
- * </p><p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int TOOL = 1 << 2;
-
- /**
- * style constant to ensure no trimmings are used (value is 1&lt;&lt;3)
- * <br>Note that this overrides all other trim styles.
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int NO_TRIM = 1 << 3;
-
- /**
- * style constant for resize box trim (value is 1&lt;&lt;4)
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * <li><code>Tracker</code></li>
- * </ul></p>
- */
- public static final int RESIZE = 1 << 4;
-
- /**
- * style constant for title area trim (value is 1&lt;&lt;5)
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int TITLE = 1 << 5;
-
- /**
- * style constant for close box trim (value is 1&lt;&lt;6,
- * since we do not distinguish between CLOSE style and MENU style)
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int CLOSE = 1 << 6;
-
- /**
- * style constant for shell menu trim (value is 1&lt;&lt;6,
- * since we do not distinguish between CLOSE style and MENU style)
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int MENU = CLOSE;
-
- /**
- * style constant for minimize box trim (value is 1&lt;&lt;7)
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int MIN = 1 << 7;
-
- /**
- * style constant for maximize box trim (value is 1&lt;&lt;10)
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code> and subclasses</li>
- * </ul></p>
- */
- public static final int MAX = 1 << 10;
-
- /**
- * style constant for horizontal scrollbar behavior (value is 1&lt;&lt;8)
- * <p><b>Used By:</b><ul>
- * <li><code>Scrollable</code> and subclasses</li>
- * </ul></p>
- */
- public static final int H_SCROLL = 1 << 8;
-
- /**
- * style constant for vertical scrollbar behavior (value is 1&lt;&lt;9)
- * <p><b>Used By:</b><ul>
- * <li><code>Scrollable</code> and subclasses</li>
- * </ul></p>
- */
- public static final int V_SCROLL = 1 << 9;
-
- /**
- * style constant for bordered behavior (value is 1&lt;&lt;11)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code> and subclasses</li>
- * </ul></p>
- */
- public static final int BORDER = 1 << 11;
-
- /**
- * style constant indicating that the window manager should clip
- * a widget's children with respect to its viewable area. (value is 1&lt;&lt;12)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code> and subclasses</li>
- * </ul></p>
- */
- public static final int CLIP_CHILDREN = 1 << 12;
-
- /**
- * style constant indicating that the window manager should clip
- * a widget's siblings with respect to its viewable area. (value is 1&lt;&lt;13)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code> and subclasses</li>
- * </ul></p>
- */
- public static final int CLIP_SIBLINGS = 1 << 13;
-
- /**
- * style constant for always on top behavior (value is 1&lt;&lt;14)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Decorations</code>and subclasses</li>
- * </ul></p>
- */
- public static final int ON_TOP = 1 << 14;
-
- /**
- * trim style convenience constant for the most common top level shell appearance
- * (value is CLOSE|TITLE|MIN|MAX|RESIZE)
- * <p><b>Used By:</b><ul>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int SHELL_TRIM = CLOSE | TITLE | MIN | MAX | RESIZE;
-
- /**
- * trim style convenience constant for the most common dialog shell appearance
- * (value is CLOSE|TITLE|BORDER)
- * <p><b>Used By:</b><ul>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int DIALOG_TRIM = TITLE | CLOSE | BORDER;
-
- /**
- * style constant for modeless behavior (value is 0)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Dialog</code></li>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int MODELESS = 0;
-
- /**
- * style constant for primary modal behavior (value is 1&lt;&lt;15)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Dialog</code></li>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int PRIMARY_MODAL = 1 << 15;
-
- /**
- * style constant for application modal behavior (value is 1&lt;&lt;16)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Dialog</code></li>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int APPLICATION_MODAL = 1 << 16;
-
- /**
- * style constant for system modal behavior (value is 1&lt;&lt;17)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Dialog</code></li>
- * <li><code>Shell</code></li>
- * </ul></p>
- */
- public static final int SYSTEM_MODAL = 1 << 17;
-
- /**
- * style constant for selection hiding behavior. (value is 1&lt;&lt;15)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Table</code></li>
- * </ul></p>
- */
- public static final int HIDE_SELECTION = 1 << 15;
-
- /**
- * style constant for full row selection behavior. (value is 1&lt;&lt;16)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Table</code></li>
- * </ul></p>
- */
- public static final int FULL_SELECTION = 1 << 16;
-
- /**
- * style constant for flat appearance. (value is 1&lt;&lt;23)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>ToolBar</code></li>
- * </ul></p>
- */
- public static final int FLAT = 1 << 23;
-
- /**
- * style constant for flat appearance. (value is 1&lt;&lt;16)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>ProgressBar</code></li>
- * </ul></p>
- */
- public static final int SMOOTH = 1 << 16;
-
- /**
- * style constant for no background behavior (value is 1&lt;&lt;18)
- * <p>
- * By default, before a widget paints, the client area is filled with the current background color.
- * When this style is specified, the background is not filled, and the application is responsible
- * for filling every pixel of the client area.
- * This style might be used as an alternative to "double-buffering" in order to reduce flicker.
- * This style does not mean "transparent" - widgets that are obscured will not draw through.
- * </p><p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * </ul></p>
- */
- public static final int NO_BACKGROUND = 1 << 18;
-
- /**
- * style constant for does not take focus behavior (value is 1&lt;&lt;19)
- * <br>Note that this is a <em>HINT</em>.
- * <p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * </ul></p>
- */
- public static final int NO_FOCUS = 1 << 19;
-
- /**
- * style constant for no redraw on resize behavior (value is 1&lt;&lt;20)
- * <p>
- * This style stops the entire client area from being invalidated when the size
- * of the Canvas changes. Specifically, when the size of the Canvas gets smaller,
- * the SWT.Paint event is not sent. When it gets bigger, an SWT.Paint event is
- * sent with a GC clipped to only the new areas to be painted. Without this
- * style, the entire client area will be repainted.
- * </p><p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * </ul></p>
- */
- public static final int NO_REDRAW_RESIZE = 1 << 20;
-
- /**
- * style constant for no paint event merging behavior (value is 1&lt;&lt;21)
- * <p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * </ul></p>
- */
- public static final int NO_MERGE_PAINTS = 1 << 21;
-
- /**
- * style constant for preventing child radio group behavior (value is 1&lt;&lt;22)
- * <p><b>Used By:</b><ul>
- * <li><code>Composite</code></li>
- * </ul></p>
- */
- public static final int NO_RADIO_GROUP = 1 << 22;
-
- /**
- * style constant for left to right orientation (value is 1&lt;&lt;25)
- * <p>
- * When orientation is not explicitly specified, orientation is
- * inherited. This means that children will be assigned the
- * orientation of their parent. To override this behavior and
- * force an orientation for a child, explicitly set the orientation
- * of the child when that child is created.
- * </p>
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code></li>
- * <li><code>Menu</code></li>
- * </ul></p>
- *
- * <p>
- * <b>NOTE:</b> This API element is part of an interim API that is still under
- * development and is expected to change significantly before reaching stability.
- * It is being made available at this early stage to solicit feedback from
- * pioneering adopters on the understanding that any code that uses this API
- * will almost certainly be broken (repeatedly) as the API evolves.
- * </p>
- *
- * @since 2.1
- */
- public static final int LEFT_TO_RIGHT = 1 << 25;
-
- /**
- * style constant for right to left orientation (value is 1&lt;&lt;26)
- * <p>
- * When orientation is not explicitly specified, orientation is
- * inherited. This means that children will be assigned the
- * orientation of their parent. To override this behavior and
- * force an orientation for a child, explicitly set the orientation
- * of the child when that child is created.
- * </p>
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code></li>
- * <li><code>Menu</code></li>
- * </ul></p>
- *
- * <p>
- * <b>NOTE:</b> This API element is part of an interim API that is still under
- * development and is expected to change significantly before reaching stability.
- * It is being made available at this early stage to solicit feedback from
- * pioneering adopters on the understanding that any code that uses this API
- * will almost certainly be broken (repeatedly) as the API evolves.
- * </p>
- *
- * @since 2.1
- */
- public static final int RIGHT_TO_LEFT = 1 << 26;
-
- /**
- * style constant to indicate coordinate mirroring (value is 1&lt;&lt;27)
- * <p><b>Used By:</b><ul>
- * <li><code>Control</code></li>
- * <li><code>Menu</code></li>
- * </ul></p>
- *
- * <p>
- * <b>NOTE:</b> This API element is part of an interim API that is still under
- * development and is expected to change significantly before reaching stability.
- * It is being made available at this early stage to solicit feedback from
- * pioneering adopters on the understanding that any code that uses this API
- * will almost certainly be broken (repeatedly) as the API evolves.
- * </p>
- *
- * @since 2.1
- */
- public static final int MIRRORED = 1 << 27;
-
- /**
- * style constant for align up behavior (value is 1&lt;&lt;7,
- * since align UP and align TOP are considered the same)
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code> with <code>ARROW</code> style</li>
- * <li><code>Tracker</code></li>
- * </ul></p>
- */
- public static final int UP = 1 << 7;
-
- /**
- * style constant for align top behavior (value is 1&lt;&lt;7,
- * since align UP and align TOP are considered the same)
- * <p><b>Used By:</b><ul>
- * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
- * </ul></p>
- */
- public static final int TOP = UP;
-
- /**
- * style constant for align down behavior (value is 1&lt;&lt;10,
- * since align DOWN and align BOTTOM are considered the same)
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code> with <code>ARROW</code> style</li>
- * <li><code>Tracker</code></li>
- * </ul></p>
- */
- public static final int DOWN = 1 << 10;
-
- /**
- * style constant for align bottom behavior (value is 1&lt;&lt;10,
- * since align DOWN and align BOTTOM are considered the same)
- * <p><b>Used By:</b><ul>
- * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
- * </ul></p>
- */
- public static final int BOTTOM = DOWN;
-
- /**
- * style constant for align left behavior (value is 1&lt;&lt;14)
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>Label</code></li>
- * <li><code>TableColumn</code></li>
- * <li><code>Tracker</code></li>
- * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
- * </ul></p>
- */
- public static final int LEFT = 1 << 14;
-
- /**
- * style constant for align right behavior (value is 1&lt;&lt;17)
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>Label</code></li>
- * <li><code>TableColumn</code></li>
- * <li><code>Tracker</code></li>
- * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
- * </ul></p>
- */
- public static final int RIGHT = 1 << 17;
-
- /**
- * style constant for align center behavior (value is 1&lt;&lt;24)
- * <p><b>Used By:</b><ul>
- * <li><code>Button</code></li>
- * <li><code>Label</code></li>
- * <li><code>TableColumn</code></li>
- * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
- * </ul></p>
- */
- public static final int CENTER = 1 << 24;
-
- /**
- * style constant for horizontal alignment or orientation behavior (value is 1&lt;&lt;8)
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>ProgressBar</code></li>
- * <li><code>Sash</code></li>
- * <li><code>Scale</code></li>
- * <li><code>ScrollBar</code></li>
- * <li><code>Slider</code></li>
- * <li><code>ToolBar</code></li>
- * <li><code>FillLayout</code> type</li>
- * <li><code>RowLayout</code> type</li>
- * </ul></p>
- */
- public static final int HORIZONTAL = 1 << 8;
-
- /**
- * style constant for vertical alignment or orientation behavior (value is 1&lt;&lt;9)
- * <p><b>Used By:</b><ul>
- * <li><code>Label</code></li>
- * <li><code>ProgressBar</code></li>
- * <li><code>Sash</code></li>
- * <li><code>Scale</code></li>
- * <li><code>ScrollBar</code></li>
- * <li><code>Slider</code></li>
- * <li><code>ToolBar</code></li>
- * <li><code>FillLayout</code> type</li>
- * <li><code>RowLayout</code> type</li>
- * </ul></p>
- */
- public static final int VERTICAL = 1 << 9;
-
- /**
- * Input Method Editor style constant for double byte
- * input behavior (value is 1&lt;&lt;1)
- */
- public static final int DBCS = 1 << 1;
-
- /**
- * Input Method Editor style constant for alpha
- * input behavior (value is 1&lt;&lt;2)
- */
- public static final int ALPHA = 1 << 2;
-
- /**
- * Input Method Editor style constant for native
- * input behavior (value is 1&lt;&lt;3)
- */
- public static final int NATIVE = 1 << 3;
-
- /**
- * Input Method Editor style constant for phonetic
- * input behavior (value is 1&lt;&lt;4)
- */
- public static final int PHONETIC = 1 << 4;
-
- /**
- * Input Method Editor style constant for romanicized
- * input behavior (value is 1&lt;&lt;5)
- */
- public static final int ROMAN = 1 << 5;
-
- /**
- * ASCII character convenience constant for the backspace character
- * (value is the <code>char</code> '\b')
- */
- public static final char BS = '\b';
-
- /**
- * ASCII character convenience constant for the carriage return character
- * (value is the <code>char</code> '\r')
- */
- public static final char CR = '\r';
-
- /**
- * ASCII character convenience constant for the delete character
- * (value is the <code>char</code> with value 127)
- */
- public static final char DEL = 0x7F;
-
- /**
- * ASCII character convenience constant for the escape character
- * (value is the <code>char</code> with value 27)
- */
- public static final char ESC = 0x1B;
-
- /**
- * ASCII character convenience constant for the line feed character
- * (value is the <code>char</code> '\n')
- */
- public static final char LF = '\n';
-
- /**
- * ASCII character convenience constant for the tab character
- * (value is the <code>char</code> '\t')
- *
- * @since 2.1
- */
- public static final char TAB = '\t';
-
- /**
- * keyboard and/or mouse event mask indicating that the ALT key
- * was pushed on the keyboard when the event was generated
- * (value is 1&lt;&lt;16)
- */
- public static final int ALT = 1 << 16;
-
- /**
- * keyboard and/or mouse event mask indicating that the SHIFT key
- * was pushed on the keyboard when the event was generated
- * (value is 1&lt;&lt;17)
- */
- public static final int SHIFT = 1 << 17;
-
- /**
- * keyboard and/or mouse event mask indicating that the CTRL key
- * was pushed on the keyboard when the event was generated
- * (value is 1&lt;&lt;18)
- */
- public static final int CTRL = 1 << 18;
-
- /**
- * keyboard and/or mouse event mask indicating that the CTRL key
- * was pushed on the keyboard when the event was generated. This
- * is a synonym for CTRL (value is 1&lt;&lt;18)
- */
- public static final int CONTROL = CTRL;
-
- /**
- * keyboard and/or mouse event mask indicating that the COMMAND key
- * was pushed on the keyboard when the event was generated
- * (value is 1&lt;&lt;22)
- *
- * @since 2.1
- */
- public static final int COMMAND = 1 << 22;
-
- /**
- * keyboard and/or mouse event mask indicating all possible
- * keyboard modifiers. To allow for the future, this mask
- * is intended to be used in place of code that references
- * each individual keyboard mask. For example, the following
- * expression will determine whether any modifer is pressed
- * and will continue to work as new modifier masks are added.
- *
- * <code>(stateMask & SWT.MODIFIER_MASK) != 0</code>.
- *
- * @since 2.1
- */
- public static final int MODIFIER_MASK;
-
- /**
- * keyboard and/or mouse event mask indicating that mouse button one
- * was pushed when the event was generated. (value is 1&lt;&lt;19)
- */
- public static final int BUTTON1 = 1 << 19;
-
- /**
- * keyboard and/or mouse event mask indicating that mouse button two
- * was pushed when the event was generated. (value is 1&lt;&lt;20)
- */
- public static final int BUTTON2 = 1 << 20;
-
- /**
- * keyboard and/or mouse event mask indicating that mouse button three
- * was pushed when the event was generated. (value is 1&lt;&lt;21)
- */
- public static final int BUTTON3 = 1 << 21;
-
- /**
- * keyboard and/or mouse event mask indicating all possible
- * mouse buttons. To allow for the future, this mask
- * is intended to be used in place of code that references
- * each individual button mask. For example, the following
- * expression will determine whether any button is pressed
- * and will continue to work as new button masks are added.
- *
- * <code>(stateMask & SWT.BUTTON_MASK) != 0</code>.
- *
- * @since 2.1
- */
- public static final int BUTTON_MASK;
-
- /**
- * keyboard and/or mouse event mask indicating that the MOD1 key
- * was pushed on the keyboard when the event was generated. This
- * is the primary keyboard modifier for the platform.
- *
- * @since 2.1
- */
- public static final int MOD1;
-
- /**
- * keyboard and/or mouse event mask indicating that the MOD2 key
- * was pushed on the keyboard when the event was generated. This
- * is the secondary keyboard modifier for the platform.
- *
- * @since 2.1
- */
- public static final int MOD2;
-
- /**
- * keyboard and/or mouse event mask indicating that the MOD3 key
- * was pushed on the keyboard when the event was generated.
- *
- * @since 2.1
- */
- public static final int MOD3;
-
- /**
- * keyboard and/or mouse event mask indicating that the MOD4 key
- * was pushed on the keyboard when the event was generated.
- *
- * @since 2.1
- */
- public static final int MOD4;
-
- /**
- * accelerator constant used to differentiate a key code from a
- * unicode character. If this bit is set, then the key stroke
- * portion of an accelerator represents a key code. If this bit
- * is not set, then the key stroke portion of an accelerator is
- * a unicode character.
- *
- * The following expression is false:
- *
- * <code>((SWT.MOD1 | SWT.MOD2 | 'T') & SWT.KEYCODE_BIT) != 0</code>.
- *
- * The following expression is true:
- *
- * <code>((SWT.MOD3 | SWT.F2) & SWT.KEYCODE_BIT) != 0</code>.
- *
- * (value is (1&lt;&lt;24))
- *
- * @since 2.1
- */
- public static final int KEYCODE_BIT = (1 << 24);
-
- /**
- * accelerator constant used to extract the key stroke portion of
- * an accelerator. The key stroke may be a key code or a unicode
- * value. If the key stroke is a key code <code>KEYCODE_BIT</code>
- * will be set.
- *
- * @since 2.1
- */
- public static final int KEY_MASK = KEYCODE_BIT + 0xFFFF;
-
- /**
- * keyboard event constant representing the UP ARROW key
- * (value is (1&lt;&lt;24)+1)
- */
- public static final int ARROW_UP = KEYCODE_BIT + 1;
-
- /**
- * keyboard event constant representing the DOWN ARROW key
- * (value is (1&lt;&lt;24)+2)
- */
- public static final int ARROW_DOWN = KEYCODE_BIT + 2;
-
- /**
- * keyboard event constant representing the LEFT ARROW key
- * (value is (1&lt;&lt;24)+3)
- */
- public static final int ARROW_LEFT = KEYCODE_BIT + 3;
-
- /**
- * keyboard event constant representing the RIGHT ARROW key
- * (value is (1&lt;&lt;24)+4)
- */
- public static final int ARROW_RIGHT = KEYCODE_BIT + 4;
-
- /**
- * keyboard event constant representing the PAGE UP key
- * (value is (1&lt;&lt;24)+5)
- */
- public static final int PAGE_UP = KEYCODE_BIT + 5;
-
- /**
- * keyboard event constant representing the PAGE DOWN key
- * (value is (1&lt;&lt;24)+6)
- */
- public static final int PAGE_DOWN = KEYCODE_BIT + 6;
-
- /**
- * keyboard event constant representing the HOME key
- * (value is (1&lt;&lt;24)+7)
- */
- public static final int HOME = KEYCODE_BIT + 7;
-
- /**
- * keyboard event constant representing the END key
- * (value is (1&lt;&lt;24)+8)
- */
- public static final int END = KEYCODE_BIT + 8;
-
- /**
- * keyboard event constant representing the INSERT key
- * (value is (1&lt;&lt;24)+9)
- */
- public static final int INSERT = KEYCODE_BIT + 9;
-
- /**
- * keyboard event constant representing the F1 key
- * (value is (1&lt;&lt;24)+10)
- */
- public static final int F1 = KEYCODE_BIT + 10;
-
- /**
- * keyboard event constant representing the F2 key
- * (value is (1&lt;&lt;24)+11)
- */
- public static final int F2 = KEYCODE_BIT + 11;
-
- /**
- * keyboard event constant representing the F3 key
- * (value is (1&lt;&lt;24)+12)
- */
- public static final int F3 = KEYCODE_BIT + 12;
-
- /**
- * keyboard event constant representing the F4 key
- * (value is (1&lt;&lt;24)+13)
- */
- public static final int F4 = KEYCODE_BIT + 13;
-
- /**
- * keyboard event constant representing the F5 key
- * (value is (1&lt;&lt;24)+14)
- */
- public static final int F5 = KEYCODE_BIT + 14;
-
- /**
- * keyboard event constant representing the F6 key
- * (value is (1&lt;&lt;24)+15)
- */
- public static final int F6 = KEYCODE_BIT + 15;
-
- /**
- * keyboard event constant representing the F7 key
- * (value is (1&lt;&lt;24)+16)
- */
- public static final int F7 = KEYCODE_BIT + 16;
-
- /**
- * keyboard event constant representing the F8 key
- * (value is (1&lt;&lt;24)+17)
- */
- public static final int F8 = KEYCODE_BIT + 17;
-
- /**
- * keyboard event constant representing the F9 key
- * (value is (1&lt;&lt;24)+18)
- */
- public static final int F9 = KEYCODE_BIT + 18;
-
- /**
- * keyboard event constant representing the F10 key
- * (value is (1&lt;&lt;24)+19)
- */
- public static final int F10 = KEYCODE_BIT + 19;
-
- /**
- * keyboard event constant representing the F11 key
- * (value is (1&lt;&lt;24)+20)
- */
- public static final int F11 = KEYCODE_BIT + 20;
-
- /**
- * keyboard event constant representing the F12 key
- * (value is (1&lt;&lt;24)+21)
- */
- public static final int F12 = KEYCODE_BIT + 21;
-
- /**
- * <code>MessageBox</code> style constant for error icon
- * behavior (value is 1)
- */
- public static final int ICON_ERROR = 1;
-
- /**
- * <code>MessageBox</code> style constant for information icon
- * behavior (value is 1&lt;&lt;1)
- */
- public static final int ICON_INFORMATION = 1 << 1;
-
- /**
- * <code>MessageBox</code> style constant for question icon
- * behavior (value is 1&lt;&lt;2)
- */
- public static final int ICON_QUESTION = 1 << 2;
-
- /**
- * <code>MessageBox</code> style constant for warning icon
- * behavior (value is 1&lt;&lt;3)
- */
- public static final int ICON_WARNING = 1 << 3;
-
- /**
- * <code>MessageBox</code> style constant for "working" icon
- * behavior (value is 1&lt;&lt;4)
- */
- public static final int ICON_WORKING = 1 << 4;
-
- /**
- * <code>MessageBox</code> style constant for an OK button.
- * Valid combinations are OK, OK|CANCEL
- * (value is 1&lt;&lt;5)
- */
- public static final int OK = 1 << 5;
-
- /**
- * <code>MessageBox</code> style constant for YES button.
- * Valid combinations are YES|NO, YES|NO|CANCEL
- * (value is 1&lt;&lt;6)
- */
- public static final int YES = 1 << 6;
-
- /**
- * <code>MessageBox</code> style constant for NO button.
- * Valid combinations are YES|NO, YES|NO|CANCEL
- * (value is 1&lt;&lt;7)
- */
- public static final int NO = 1 << 7;
-
- /**
- * <code>MessageBox</code> style constant for a CANCEL button.
- * Valid combinations are OK|CANCEL, YES|NO|CANCEL, RETRY|CANCEL
- * (value is 1&lt;&lt;8)
- */
- public static final int CANCEL = 1 << 8;
-
- /**
- * <code>MessageBox</code> style constant for an ABORT button.
- * The only valid combination is ABORT|RETRY|IGNORE
- * (value is 1&lt;&lt;9)
- */
- public static final int ABORT = 1 << 9;
-
- /**
- * <code>MessageBox</code> style constant for a RETRY button.
- * Valid combinations are ABORT|RETRY|IGNORE, RETRY|CANCEL
- * (value is 1&lt;&lt;10)
- */
- public static final int RETRY = 1 << 10;
-
- /**
- * <code>MessageBox</code> style constant for an IGNORE button.
- * The only valid combination is ABORT|RETRY|IGNORE
- * (value is 1&lt;&lt;11)
- */
- public static final int IGNORE = 1 << 11;
-
- /**
- * <code>FileDialog</code> style constant for open file dialog behavior
- * (value is 1&lt;&lt;12)
- */
- public static final int OPEN = 1 << 12;
-
- /**
- * <code>FileDialog</code> style constant for save file dialog behavior
- * (value is 1&lt;&lt;13)
- */
- public static final int SAVE = 1 << 13;
-
- /**
- * default color white (value is 1)
- */
- public static final int COLOR_WHITE = 1;
-
- /**
- * default color black (value is 2)
- */
- public static final int COLOR_BLACK = 2;
-
- /**
- * default color red (value is 3)
- */
- public static final int COLOR_RED = 3;
-
- /**
- * default color dark red (value is 4)
- */
- public static final int COLOR_DARK_RED = 4;
-
- /**
- * default color green (value is 5)
- */
- public static final int COLOR_GREEN = 5;
-
- /**
- * default color dark green (value is 6)
- */
- public static final int COLOR_DARK_GREEN = 6;
-
- /**
- * default color yellow (value is 7)
- */
- public static final int COLOR_YELLOW = 7;
-
- /**
- * default color dark yello (value is 8)
- */
- public static final int COLOR_DARK_YELLOW = 8;
-
- /**
- * default color blue (value is 9)
- */
- public static final int COLOR_BLUE = 9;
-
- /**
- * default color dark blue (value is 10)
- */
- public static final int COLOR_DARK_BLUE = 10;
-
- /**
- * default color magenta (value is 11)
- */
- public static final int COLOR_MAGENTA = 11;
-
- /**
- * default color dark magenta (value is 12)
- */
- public static final int COLOR_DARK_MAGENTA = 12;
-
- /**
- * default color cyan (value is 13)
- */
- public static final int COLOR_CYAN = 13;
-
- /**
- * default color dark cyan (value is 14)
- */
- public static final int COLOR_DARK_CYAN = 14;
-
- /**
- * default color gray (value is 15)
- */
- public static final int COLOR_GRAY = 15;
-
- /**
- * default color dark gray (value is 16)
- */
- public static final int COLOR_DARK_GRAY = 16;
-
- /*
- * System Colors
- *
- * Dealing with system colors is an area where there are
- * many platform differences. On some platforms, system
- * colors can change dynamically while the program is
- * running. On other platforms, system colors can be
- * changed for all instances of a particular widget.
- * Therefore, the only truly portable method to obtain
- * a widget color query is to query the color from an
- * instance of the widget.
- *
- * It is expected that the list of supported colors
- * will grow over time.
- */
-
- /**
- * system color used to paint dark shadow areas (value is 17)
- */
- public static final int COLOR_WIDGET_DARK_SHADOW = 17;
-
- /**
- * system color used to paint normal shadow areas (value is 18)
- */
- public static final int COLOR_WIDGET_NORMAL_SHADOW = 18;
-
- /**
- * system color used to paint light shadow areas (value is 19)
- */
- public static final int COLOR_WIDGET_LIGHT_SHADOW = 19;
-
- /**
- * system color used to paint highlight shadow areas (value is 20)
- */
- public static final int COLOR_WIDGET_HIGHLIGHT_SHADOW = 20;
-
- /**
- * system color used to paint foreground areas (value is 21)
- */
- public static final int COLOR_WIDGET_FOREGROUND = 21;
-
- /**
- * system color used to paint background areas (value is 22)
- */
- public static final int COLOR_WIDGET_BACKGROUND = 22;
-
- /**
- * system color used to paint border areas (value is 23)
- */
- public static final int COLOR_WIDGET_BORDER = 23;
-
- /**
- * system color used to paint list foreground areas (value is 24)
- */
- public static final int COLOR_LIST_FOREGROUND = 24;
-
- /**
- * system color used to paint list background areas (value is 25)
- */
- public static final int COLOR_LIST_BACKGROUND = 25;
-
- /**
- * system color used to paint list selection background areas (value is 26)
- */
- public static final int COLOR_LIST_SELECTION = 26;
-
- /**
- * system color used to paint list selected text (value is 27)
- */
- public static final int COLOR_LIST_SELECTION_TEXT = 27;
-
- /**
- * system color used to paint tooltip text (value is 28)
- */
- public static final int COLOR_INFO_FOREGROUND = 28;
-
- /**
- * system color used to paint tooltip background areas (value is 29)
- */
- public static final int COLOR_INFO_BACKGROUND = 29;
-
- /**
- * system color used to paint title text (value is 30)
- */
- public static final int COLOR_TITLE_FOREGROUND = 30;
-
- /**
- * system color used to paint title background areas (value is 31)
- */
- public static final int COLOR_TITLE_BACKGROUND = 31;
-
- /**
- * system color used to paint title background gradient (value is 32)
- */
- public static final int COLOR_TITLE_BACKGROUND_GRADIENT = 32;
-
- /**
- * system color used to paint inactive title text (value is 33)
- */
- public static final int COLOR_TITLE_INACTIVE_FOREGROUND = 33;
-
- /**
- * system color used to paint inactive title background areas (value is 34)
- */
- public static final int COLOR_TITLE_INACTIVE_BACKGROUND = 34;
-
- /**
- * system color used to paint inactive title background gradient (value is 35)
- */
- public static final int COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = 35;
-
- /**
- * draw constant indicating whether the drawing operation
- * should fill the background (value is 1&lt;&lt;0)
- */
- public static final int DRAW_TRANSPARENT = 1 << 0;
-
- /**
- * draw constant indicating whether the string drawing operation
- * should handle line-delimeters (value is 1&lt;&lt;1)
- */
- public static final int DRAW_DELIMITER = 1 << 1;
-
- /**
- * draw constant indicating whether the string drawing operation
- * should expand TAB characters (value is 1&lt;&lt;2)
- */
- public static final int DRAW_TAB = 1 << 2;
-
- /**
- * draw constant indicating whether the string drawing operation
- * should handle mnemonics (value is 1&lt;&lt;3)
- */
- public static final int DRAW_MNEMONIC = 1 << 3;
-
- /**
- * SWT error constant indicating that no error number was specified
- * (value is 1)
- */
- public static final int ERROR_UNSPECIFIED = 1;
-
- /**
- * SWT error constant indicating that no more handles for an
- * operating system resource are available
- * (value is 2)
- */
- public static final int ERROR_NO_HANDLES = 2;
-
- /**
- * SWT error constant indicating that no more callback resources are available
- * (value is 3)
- */
- public static final int ERROR_NO_MORE_CALLBACKS = 3;
-
- /**
- * SWT error constant indicating that a null argument was passed in
- * (value is 4)
- */
- public static final int ERROR_NULL_ARGUMENT = 4;
-
- /**
- * SWT error constant indicating that an invalid argument was passed in
- * (value is 5)
- */
- public static final int ERROR_INVALID_ARGUMENT = 5;
-
- /**
- * SWT error constant indicating that a value was found to be
- * outside the allowable range
- * (value is 6)
- */
- public static final int ERROR_INVALID_RANGE = 6;
-
- /**
- * SWT error constant indicating that a value which can not be
- * zero was found to be
- * (value is 7)
- */
- public static final int ERROR_CANNOT_BE_ZERO = 7;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide the value of an item
- * (value is 8)
- */
- public static final int ERROR_CANNOT_GET_ITEM = 8;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide the selection
- * (value is 9)
- */
- public static final int ERROR_CANNOT_GET_SELECTION = 9;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide the height of an item
- * (value is 11)
- */
- public static final int ERROR_CANNOT_GET_ITEM_HEIGHT = 11;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide the text of a widget
- * (value is 12)
- */
- public static final int ERROR_CANNOT_GET_TEXT = 12;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to set the text of a widget
- * (value is 13)
- */
- public static final int ERROR_CANNOT_SET_TEXT = 13;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to add an item
- * (value is 14)
- */
- public static final int ERROR_ITEM_NOT_ADDED = 14;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to remove an item
- * (value is 15)
- */
- public static final int ERROR_ITEM_NOT_REMOVED = 15;
-
- /**
- * SWT error constant indicating that a particular feature has
- * not been implemented on this platform
- * (value is 20)
- */
- public static final int ERROR_NOT_IMPLEMENTED = 20;
-
- /**
- * SWT error constant indicating that a menu which needed
- * to have the drop down style had some other style instead
- * (value is 21)
- */
- public static final int ERROR_MENU_NOT_DROP_DOWN = 21;
-
- /**
- * SWT error constant indicating that an attempt was made to
- * invoke an SWT operation which can only be executed by the
- * user-interface thread from some other thread
- * (value is 22)
- */
- public static final int ERROR_THREAD_INVALID_ACCESS = 22;
-
- /**
- * SWT error constant indicating that an attempt was made to
- * invoke an SWT operation using a widget which had already
- * been disposed.
- * (value is 24)
- */
- public static final int ERROR_WIDGET_DISPOSED = 24;
-
- /**
- * SWT error constant indicating that a menu item which needed
- * to have the cascade style had some other style instead
- * (value is 27)
- */
- public static final int ERROR_MENUITEM_NOT_CASCADE = 27;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to set the selection of a widget
- * (value is 28)
- */
- public static final int ERROR_CANNOT_SET_SELECTION = 28;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to set the menu
- * (value is 29)
- */
- public static final int ERROR_CANNOT_SET_MENU = 29;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to set the enabled state
- * (value is 30)
- */
- public static final int ERROR_CANNOT_SET_ENABLED = 30;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide enabled/disabled state information
- * (value is 31)
- */
- public static final int ERROR_CANNOT_GET_ENABLED = 31;
-
- /**
- * SWT error constant indicating that a provided widget can
- * not be used as a parent in the current operation
- * (value is 32)
- */
- public static final int ERROR_INVALID_PARENT = 32;
-
- /**
- * SWT error constant indicating that a menu which needed
- * to have the menu bar style had some other style instead
- * (value is 33)
- */
- public static final int ERROR_MENU_NOT_BAR = 33;
-
- /**
- * SWT error constant indicating that the underlying operating
- * system was unable to provide count information
- * (value is 36)
- */
- public static final int ERROR_CANNOT_GET_COUNT = 36;
-
- /**
- * SWT error constant indicating that a menu which needed
- * to have the pop up menu style had some other style instead
- * (value is 37)
- */
- public static final int ERROR_MENU_NOT_POP_UP = 37;
-
- /**
- * SWT error constant indicating that a graphics operation
- * was attempted with an image of an unsupported depth
- * (value is 38)
- */
- public static final int ERROR_UNSUPPORTED_DEPTH = 38;
-
- /**
- * SWT error constant indicating that an input/output operation
- * failed during the execution of an SWT operation
- * (value is 39)
- */
- public static final int ERROR_IO = 39;
-
- /**
- * SWT error constant indicating that a graphics operation
- * was attempted with an image having an invalid format
- * (value is 40)
- */
- public static final int ERROR_INVALID_IMAGE = 40;
-
- /**
- * SWT error constant indicating that a graphics operation
- * was attempted with an image having a valid but unsupported
- * format
- * (value is 42)
- */
- public static final int ERROR_UNSUPPORTED_FORMAT = 42;
-
- /**
- * SWT error constant indicating that an attempt was made
- * to subclass an SWT widget class without implementing the
- * <code>checkSubclass()</code> method. For additional
- * information see the comment in <code>Widget.checkSubclass()</code>
- * (value is 43)
- *
- * @see org.eclipse.swt.widgets.Widget#checkSubclass
- */
- public static final int ERROR_INVALID_SUBCLASS = 43;
-
- /**
- * SWT error constant indicating that an attempt was made to
- * invoke an SWT operation using a graphics object which had
- * already been disposed.
- * (value is 44)
- */
- public static final int ERROR_GRAPHIC_DISPOSED = 44;
-
- /**
- * SWT error constant indicating that an attempt was made to
- * invoke an SWT operation using a device which had already
- * been disposed.
- * (value is 45)
- */
- public static final int ERROR_DEVICE_DISPOSED = 45;
-
- /**
- * SWT error constant indicating that an exception happened
- * when executing a runnable.
- * (value is 46)
- */
- public static final int ERROR_FAILED_EXEC = 46;
-
- /**
- * SWT error constant indicating that an unsatisfied link
- * error occured while attempting to load a library.
- * (value is 47)
- */
- public static final int ERROR_FAILED_LOAD_LIBRARY = 47;
-
- /**
- * traversal event detail field value indicating that no
- * traversal action should be taken.
- * (value is 0)
- */
- public static final int TRAVERSE_NONE = 0;
-
- /**
- * traversal event detail field value indicating that the
- * key which designates that a dialog should be cancelled was
- * pressed; typically, this is the ESC key
- * (value is 1&lt;&lt;1)
- */
- public static final int TRAVERSE_ESCAPE = 1 << 1;
-
- /**
- * traversal event detail field value indicating that the
- * key which activates the default button in a dialog was
- * pressed; typically, this is the ENTER key
- * (value is 1&lt;&lt;2)
- */
- public static final int TRAVERSE_RETURN = 1 << 2;
-
- /**
- * traversal event detail field value indicating that the
- * key which designates that focus should be given to the
- * previous tab group was pressed; typically, this is the
- * SHIFT-TAB key sequence
- * (value is 1&lt;&lt;3)
- */
- public static final int TRAVERSE_TAB_PREVIOUS = 1 << 3;
-
- /**
- * traversal event detail field value indicating that the
- * key which designates that focus should be given to the
- * next tab group was pressed; typically, this is the
- * TAB key
- * (value is 1&lt;&lt;4)
- */
- public static final int TRAVERSE_TAB_NEXT = 1 << 4;
-
- /**
- * traversal event detail field value indicating that the
- * key which designates that focus should be given to the
- * previous tab item was pressed; typically, this is either
- * the LEFT-ARROW or UP-ARROW keys
- * (value is 1&lt;&lt;5)
- */
- public static final int TRAVERSE_ARROW_PREVIOUS = 1 << 5;
-
- /**
- * traversal event detail field value indicating that the
- * key which designates that focus should be given to the
- * previous tab item was pressed; typically, this is either
- * the RIGHT-ARROW or DOWN-ARROW keys
- * (value is 1&lt;&lt;6)
- */
- public static final int TRAVERSE_ARROW_NEXT = 1 << 6;
-
- /**
- * traversal event detail field value indicating that a
- * mnemonic key sequence was pressed
- * (value is 1&lt;&lt;7)
- */
- public static final int TRAVERSE_MNEMONIC = 1 << 7;
-
- /**
- * traversal event detail field value indicating that the
- * key which designates that the previous page of a multi-page
- * window should be shown was pressed; typically, this
- * is the CTRL-PAGEUP key sequence
- * (value is 1&lt;&lt;8)
- */
- public static final int TRAVERSE_PAGE_PREVIOUS = 1 << 8;
-
- /**
- * traversal event detail field value indicating that the
- * key which designates that the next page of a multi-page
- * window should be shown was pressed; typically, this
- * is the CTRL-PAGEDOWN key sequence
- * (value is 1&lt;&lt;9)
- */
- public static final int TRAVERSE_PAGE_NEXT = 1 << 9;
-
- /**
- * constant indicating that an image or operation is of type bitmap (value is 0)
- */
- public static final int BITMAP = 0;
-
- /**
- * constant indicating that an image or operation is of type icon (value is 1)
- */
- public static final int ICON = 1;
-
- /**
- * <code>Image</code> constructor argument indicating that
- * the new image should be a copy of the image provided as
- * an argument (value is 0)
- */
- public static final int IMAGE_COPY = 0;
-
- /**
- * <code>Image</code> constructor argument indicating that
- * the new image should have the appearance of a "disabled"
- * (using the platform's rules for how this should look)
- * copy of the image provided as an argument (value is 1)
- */
- public static final int IMAGE_DISABLE = 1;
-
- /**
- * <code>Image</code> constructor argument indicating that
- * the new image should have the appearance of a "gray scaled"
- * copy of the image provided as an argument (value is 2)
- */
- public static final int IMAGE_GRAY = 2;
-
- /**
- * font style constant indicating a normal weight, non-italic font
- * (value is 0)
- */
- public static final int NORMAL = 0;
-
- /**
- * font style constant indicating a bold weight font
- * (value is 1&lt;&lt;0)
- */
- public static final int BOLD = 1 << 0;
-
- /**
- * font style constant indicating an italic font
- * (value is 1&lt;&lt;1)
- */
- public static final int ITALIC = 1 << 1;
-
- /**
- * system arrow cursor (value is 0)
- */
- public static final int CURSOR_ARROW = 0;
-
- /**
- * system wait cursor (value is 1)
- */
- public static final int CURSOR_WAIT = 1;
-
- /**
- * system cross hair cursor (value is 2)
- */
- public static final int CURSOR_CROSS = 2;
-
- /**
- * system app startup cursor (value is 3)
- */
- public static final int CURSOR_APPSTARTING = 3;
-
- /**
- * system help cursor (value is 4)
- */
- public static final int CURSOR_HELP = 4;
-
- /**
- * system resize all directions cursor (value is 5)
- */
- public static final int CURSOR_SIZEALL = 5;
-
- /**
- * system resize north-east-south-west cursor (value is 6)
- */
- public static final int CURSOR_SIZENESW = 6;
-
- /**
- * system resize north-south cursor (value is 7)
- */
- public static final int CURSOR_SIZENS = 7;
-
- /**
- * system resize north-west-south-east cursor (value is 8)
- */
- public static final int CURSOR_SIZENWSE = 8;
-
- /**
- * system resize west-east cursor (value is 9)
- */
- public static final int CURSOR_SIZEWE = 9;
-
- /**
- * system resize north cursor (value is 10)
- */
- public static final int CURSOR_SIZEN = 10;
-
- /**
- * system resize south cursor (value is 11)
- */
- public static final int CURSOR_SIZES = 11;
-
- /**
- * system resize east cursor (value is 12)
- */
- public static final int CURSOR_SIZEE = 12;
-
- /**
- * system resize west cursor (value is 13)
- */
- public static final int CURSOR_SIZEW = 13;
-
- /**
- * system resize north-east cursor (value is 14)
- */
- public static final int CURSOR_SIZENE = 14;
-
- /**
- * system resize south-east cursor (value is 15)
- */
- public static final int CURSOR_SIZESE = 15;
-
- /**
- * system resize south-west cursor (value is 16)
- */
- public static final int CURSOR_SIZESW = 16;
-
- /**
- * system resize north-west cursor (value is 17)
- */
- public static final int CURSOR_SIZENW = 17;
-
- /**
- * system up arrow cursor (value is 18)
- */
- public static final int CURSOR_UPARROW = 18;
-
- /**
- * system i-beam cursor (value is 19)
- */
- public static final int CURSOR_IBEAM = 19;
-
- /**
- * system "not allowed" cursor (value is 20)
- */
- public static final int CURSOR_NO = 20;
-
- /**
- * system hand cursor (value is 21)
- */
- public static final int CURSOR_HAND = 21;
-
- /**
- * line drawing style for solid lines (value is 1)
- */
- public static final int LINE_SOLID = 1;
-
- /**
- * line drawing style for dashed lines (value is 2)
- */
- public static final int LINE_DASH = 2;
-
- /**
- * line drawing style for dotted lines (value is 3)
- */
- public static final int LINE_DOT = 3;
-
- /**
- * line drawing style for alternating dash-dot lines (value is 4)
- */
- public static final int LINE_DASHDOT = 4;
-
- /**
- * line drawing style for dash-dot-dot lines (value is 5)
- */
- public static final int LINE_DASHDOTDOT = 5;
-
- /**
- * image format constant indicating an unknown image type (value is -1)
- */
- public static final int IMAGE_UNDEFINED = -1;
-
- /**
- * image format constant indicating a Windows BMP format image (value is 0)
- */
- public static final int IMAGE_BMP = 0;
-
- /**
- * image format constant indicating a run-length encoded
- * Windows BMP format image (value is 1)
- */
- public static final int IMAGE_BMP_RLE = 1;
-
- /**
- * image format constant indicating a GIF format image (value is 2)
- */
- public static final int IMAGE_GIF = 2;
-
- /**
- * image format constant indicating a ICO format image (value is 3)
- */
- public static final int IMAGE_ICO = 3;
-
- /**
- * image format constant indicating a JPEG format image (value is 4)
- */
- public static final int IMAGE_JPEG = 4;
-
- /**
- * image format constant indicating a PNG format image (value is 5)
- */
- public static final int IMAGE_PNG = 5;
-
- /**
- * GIF image disposal method constants indicating that the
- * disposal method is unspecified (value is 0)
- */
- public static final int DM_UNSPECIFIED = 0x0;
-
- /**
- * GIF image disposal method constants indicating that the
- * disposal method is to do nothing. That is, to leave the
- * previous image in place (value is 1)
- */
- public static final int DM_FILL_NONE = 0x1;
-
- /**
- * GIF image disposal method constants indicating that the
- * the previous images should be covered with the background
- * color before displaying the next image (value is 2)
- */
- public static final int DM_FILL_BACKGROUND = 0x2;
-
- /**
- * GIF image disposal method constants indicating that the
- * disposal method is to restore the previous picture
- * (value is 3)
- */
- public static final int DM_FILL_PREVIOUS = 0x3;
-
- /**
- * image transparency constant indicating that the image
- * contains no transparency information (value is 0)
- */
- public static final int TRANSPARENCY_NONE = 0x0;
-
- /**
- * image transparency constant indicating that the image
- * contains alpha transparency information (value is 1&lt;&lt;0)
- */
- public static final int TRANSPARENCY_ALPHA = 1 << 0;
-
- /**
- * image transparency constant indicating that the image
- * contains a transparency mask (value is 1&lt;&lt;1)
- */
- public static final int TRANSPARENCY_MASK = 1 << 1;
-
- /**
- * image transparency constant indicating that the image
- * contains a transparent pixel (value is 1&lt;&lt;2)
- */
- public static final int TRANSPARENCY_PIXEL = 1 << 2;
-
-/**
- * Answers a concise, human readable description of the error code.
- *
- * @param code the SWT error code.
- * @return a description of the error code.
- *
- * @see SWT
- */
-static String findErrorText (int code) {
- switch (code) {
- case ERROR_UNSPECIFIED: return "Unspecified error";
- case ERROR_NO_HANDLES: return "No more handles";
- case ERROR_NO_MORE_CALLBACKS: return "No more callbacks";
- case ERROR_NULL_ARGUMENT: return "Argument cannot be null";
- case ERROR_INVALID_ARGUMENT: return "Argument not valid";
- case ERROR_INVALID_RANGE: return "Index out of bounds";
- case ERROR_CANNOT_BE_ZERO: return "Argument cannot be zero";
- case ERROR_CANNOT_GET_ITEM: return "Cannot get item";
- case ERROR_CANNOT_GET_SELECTION: return "Cannot get selection";
- case ERROR_CANNOT_GET_ITEM_HEIGHT: return "Cannot get item height";
- case ERROR_CANNOT_GET_TEXT: return "Cannot get text";
- case ERROR_CANNOT_SET_TEXT: return "Cannot set text";
- case ERROR_ITEM_NOT_ADDED: return "Item not added";
- case ERROR_ITEM_NOT_REMOVED: return "Item not removed";
- case ERROR_NOT_IMPLEMENTED: return "Not implemented";
- case ERROR_MENU_NOT_DROP_DOWN: return "Menu must be a drop down";
- case ERROR_THREAD_INVALID_ACCESS: return "Invalid thread access";
- case ERROR_WIDGET_DISPOSED: return "Widget is disposed";
- case ERROR_MENUITEM_NOT_CASCADE: return "Menu item is not a CASCADE";
- case ERROR_CANNOT_SET_SELECTION: return "Cannot set selection";
- case ERROR_CANNOT_SET_MENU: return "Cannot set menu";
- case ERROR_CANNOT_SET_ENABLED: return "Cannot set the enabled state";
- case ERROR_CANNOT_GET_ENABLED: return "Cannot get the enabled state";
- case ERROR_INVALID_PARENT: return "Widget has the wrong parent";
- case ERROR_MENU_NOT_BAR: return "Menu is not a BAR";
- case ERROR_CANNOT_GET_COUNT: return "Cannot get count";
- case ERROR_MENU_NOT_POP_UP: return "Menu is not a POP_UP";
- case ERROR_UNSUPPORTED_DEPTH: return "Unsupported color depth";
- case ERROR_IO: return "i/o error";
- case ERROR_INVALID_IMAGE: return "Invalid image";
- case ERROR_UNSUPPORTED_FORMAT: return "Unsupported or unrecognized format";
- case ERROR_INVALID_SUBCLASS: return "Subclassing not allowed";
- case ERROR_GRAPHIC_DISPOSED: return "Graphic is disposed";
- case ERROR_DEVICE_DISPOSED: return "Device is disposed";
- case ERROR_FAILED_EXEC: return "Failed to execute runnable";
- case ERROR_FAILED_LOAD_LIBRARY: return "Unable to load library";
- }
- return "Unknown error";
-}
-
-/**
- * Returns the NLS'ed message for the given argument.
- *
- * @param key the key to look up
- * @return the message for the given key
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- */
-public static String getMessage(String key) {
- return Compatibility.getMessage(key);
-}
-
-/**
- * Returns the SWT platform name.
- * Examples: "win32", "motif", "gtk", "photon", "carbon"
- *
- * @return the SWT platform name
- */
-public static String getPlatform () {
- return Callback.getPlatform ();
-}
-
-/**
- * Returns the SWT version number as an integer.
- * Example: "SWT051" == 51
- *
- * @return the SWT version number
- */
-public static int getVersion () {
- return Library.getVersion ();
-}
-
-/**
- * Throws an appropriate exception based on the passed in error code.
- *
- * @param code the SWT error code
- */
-public static void error (int code) {
- error (code, null);
-}
-
-/**
- * Throws an appropriate exception based on the passed in error code.
- * The <code>throwable</code> argument should be either null, or the
- * throwable which caused SWT to throw an exception.
- * <p>
- * In SWT, errors are reported by throwing one of three exceptions:
- * <dl>
- * <dd>java.lang.IllegalArgumentException</dd>
- * <dt>thrown whenever one of the API methods is invoked with an illegal argument</dt>
- * <dd>org.eclipse.swt.SWTException (extends java.lang.RuntimeException)</dd>
- * <dt>thrown whenever a recoverable error happens internally in SWT</dt>
- * <dd>org.eclipse.swt.SWTError (extends java.lang.Error)</dd>
- * <dt>thrown whenever a <b>non-recoverable</b> error happens internally in SWT</dt>
- * </dl>
- * This method provides the logic which maps between error codes
- * and one of the above exceptions.
- * </p>
- *
- * @param code the SWT error code.
- * @param throwable the exception which caused the error to occur.
- *
- * @see SWTError
- * @see SWTException
- * @see IllegalArgumentException
- */
-public static void error (int code, Throwable throwable) {
-
- /*
- * This code prevents the creation of "chains" of SWTErrors and
- * SWTExceptions which in turn contain other SWTErrors and
- * SWTExceptions as their throwable. This can occur when low level
- * code throws an exception past a point where a higher layer is
- * being "safe" and catching all exceptions. (Note that, this is
- * _a_bad_thing_ which we always try to avoid.)
- *
- * On the theory that the low level code is closest to the
- * original problem, we simply re-throw the original exception here.
- */
- if (throwable instanceof SWTError) throw (SWTError) throwable;
- if (throwable instanceof SWTException) throw (SWTException) throwable;
-
- switch (code) {
-
- /* Illegal Arguments (non-fatal) */
- case ERROR_NULL_ARGUMENT:
- case ERROR_CANNOT_BE_ZERO:
- case ERROR_INVALID_ARGUMENT:
- case ERROR_MENU_NOT_BAR:
- case ERROR_MENU_NOT_DROP_DOWN:
- case ERROR_MENU_NOT_POP_UP:
- case ERROR_MENUITEM_NOT_CASCADE:
- case ERROR_INVALID_PARENT:
- case ERROR_INVALID_RANGE: {
- throw new IllegalArgumentException (findErrorText (code));
- }
-
- /* SWT Errors (non-fatal) */
- case ERROR_INVALID_SUBCLASS:
- case ERROR_THREAD_INVALID_ACCESS:
- case ERROR_WIDGET_DISPOSED:
- case ERROR_GRAPHIC_DISPOSED:
- case ERROR_DEVICE_DISPOSED:
- case ERROR_INVALID_IMAGE:
- case ERROR_UNSUPPORTED_DEPTH:
- case ERROR_UNSUPPORTED_FORMAT:
- case ERROR_FAILED_EXEC:
- case ERROR_IO: {
- SWTException exception = new SWTException (code);
- exception.throwable = throwable;
- throw exception;
- }
-
- /* OS Failure/Limit (fatal, may occur only on some platforms) */
- case ERROR_CANNOT_GET_COUNT:
- case ERROR_CANNOT_GET_ENABLED:
- case ERROR_CANNOT_GET_ITEM:
- case ERROR_CANNOT_GET_ITEM_HEIGHT:
- case ERROR_CANNOT_GET_SELECTION:
- case ERROR_CANNOT_GET_TEXT:
- case ERROR_CANNOT_SET_ENABLED:
- case ERROR_CANNOT_SET_MENU:
- case ERROR_CANNOT_SET_SELECTION:
- case ERROR_CANNOT_SET_TEXT:
- case ERROR_ITEM_NOT_ADDED:
- case ERROR_ITEM_NOT_REMOVED:
- case ERROR_NO_HANDLES:
- //FALL THROUGH
-
- /* SWT Failure/Limit (fatal, may occur only on some platforms) */
- case ERROR_FAILED_LOAD_LIBRARY:
- case ERROR_NO_MORE_CALLBACKS:
- case ERROR_NOT_IMPLEMENTED:
- case ERROR_UNSPECIFIED: {
- SWTError error = new SWTError (code);
- error.throwable = throwable;
- throw error;
- }
- }
-
- /* Unknown/Undefined Error */
- SWTError error = new SWTError (code);
- error.throwable = throwable;
- throw error;
-}
-
-static {
- /*
- * These values represent bit masks that may need to
- * expand in the future. Therefore they are not initialized
- * in the declaration to stop the compiler from inlining.
- */
- BUTTON_MASK = BUTTON1 | BUTTON2 | BUTTON3;
- MODIFIER_MASK = ALT | SHIFT | CTRL | COMMAND;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- String platform = getPlatform ();
- if ("carbon".equals (platform)) {
- MOD1 = COMMAND;
- MOD2 = SHIFT;
- MOD3 = ALT;
- MOD4 = CONTROL;
- } else {
- MOD1 = CONTROL;
- MOD2 = SHIFT;
- MOD3 = ALT;
- MOD4 = ALT;
- }
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.*;
+
+/**
+ * This class provides access to a small number of SWT system-wide
+ * methods, and in addition defines the public constants provided
+ * by SWT.
+ * <p>
+ * By defining constants like UP and DOWN in a single class, SWT
+ * can share common names and concepts at the same time minimizing
+ * the number of classes, names and constants for the application
+ * programmer.
+ * </p><p>
+ * Note that some of the constants provided by this class represent
+ * optional, appearance related aspects of widgets which are available
+ * either only on some window systems, or for a differing set of
+ * widgets on each window system. These constants are marked
+ * as <em>HINT</em>s. The set of widgets which support a particular
+ * <em>HINT</em> may change from release to release, although we typically
+ * will not withdraw support for a <em>HINT</em> once it is made available.
+ * </p>
+ */
+
+/* NOTE:
+ * Good javadoc coding style is to put the values of static final
+ * constants in the comments. This reinforces the fact that
+ * consumers are allowed to rely on the value (and they must
+ * since the values are compiled inline in their code). We
+ * can <em>not</em> change the values of these constants between
+ * releases.
+ */
+public class SWT {
+
+ /* Initialize the class */
+// static {
+// /* NOTE: the static initialization is at the end of file */
+// }
+
+ /* Widget Event Constants */
+
+ /**
+ * key down event type (value is 1)
+ */
+ public static final int KeyDown = 1;
+
+ /**
+ * key up event type (value is 2)
+ */
+ public static final int KeyUp = 2;
+
+ /**
+ * mouse down event type (value is 3)
+ */
+ public static final int MouseDown = 3;
+
+ /**
+ * mouse up event type (value is 4)
+ */
+ public static final int MouseUp = 4;
+
+ /**
+ * mouse move event type (value is 5)
+ */
+ public static final int MouseMove = 5;
+
+ /**
+ * mouse enter event type (value is 6)
+ */
+ public static final int MouseEnter = 6;
+
+ /**
+ * Mouse exit event type (value is 7)
+ */
+ public static final int MouseExit = 7;
+
+ /**
+ * mouse double click event type (value is 8)
+ */
+ public static final int MouseDoubleClick = 8;
+
+ /**
+ * paint event type (value is 9)
+ */
+ public static final int Paint = 9;
+
+ /**
+ * move event type (value is 10)
+ */
+ public static final int Move = 10;
+
+ /**
+ * resize event type (value is 11)
+ */
+ public static final int Resize = 11;
+
+ /**
+ * dispose event type (value is 12)
+ */
+ public static final int Dispose = 12;
+
+ /**
+ * selection event type (value is 13)
+ */
+ public static final int Selection = 13;
+
+ /**
+ * default selection event type (value is 14)
+ */
+ public static final int DefaultSelection = 14;
+
+ /**
+ * focus in event type (value is 15)
+ */
+ public static final int FocusIn = 15;
+
+ /**
+ * focus out event type (value is 16)
+ */
+ public static final int FocusOut = 16;
+
+ /**
+ * expand event type (value is 17)
+ */
+ public static final int Expand = 17;
+
+ /**
+ * collapse event type (value is 18)
+ */
+ public static final int Collapse = 18;
+
+ /**
+ * iconify event type (value is 19)
+ */
+ public static final int Iconify = 19;
+
+ /**
+ * de-iconify event type (value is 20)
+ */
+ public static final int Deiconify = 20;
+
+ /**
+ * close event type (value is 21)
+ */
+ public static final int Close = 21;
+
+ /**
+ * show event type (value is 22)
+ */
+ public static final int Show = 22;
+
+ /**
+ * hide event type (value is 23)
+ */
+ public static final int Hide = 23;
+
+ /**
+ * modify event type (value is 24)
+ */
+ public static final int Modify = 24;
+
+ /**
+ * verify event type (value is 25)
+ */
+ public static final int Verify = 25;
+
+ /**
+ * activate event type (value is 26)
+ */
+ public static final int Activate = 26;
+
+ /**
+ * deactivate event type (value is 27)
+ */
+ public static final int Deactivate = 27;
+
+ /**
+ * help event type (value is 28)
+ */
+ public static final int Help = 28;
+
+ /**
+ * drag detect event type (value is 29)
+ */
+ public static final int DragDetect = 29;
+
+ /**
+ * arm event type (value is 30)
+ */
+ public static final int Arm = 30;
+
+ /**
+ * traverse event type (value is 31)
+ */
+ public static final int Traverse = 31;
+
+ /**
+ * mouse hover event type (value is 32)
+ */
+ public static final int MouseHover = 32;
+
+ /**
+ * hardware key down event type (value is 33)
+ */
+ public static final int HardKeyDown = 33;
+
+ /**
+ * hardware key up event type (value is 34)
+ */
+ public static final int HardKeyUp = 34;
+
+ /* Event Details */
+
+ /**
+ * a constant known to be zero (0), used in operations which
+ * take bit flags to indicate that "no bits are set"
+ */
+ public static final int NONE = 0;
+
+ /**
+ * indicates that a user-interface component is being dragged,
+ * for example dragging the thumb of a scroll bar (value is 1)
+ */
+ public static final int DRAG = 1;
+
+ /**
+ * a constant known to be zero (0), used in operations which
+ * take pointers to indicate a null argument
+ */
+ public static final int NULL = 0;
+
+ /**
+ * indicates that a default should be used (value is -1)
+ */
+ public static final int DEFAULT = -1;
+
+ /**
+ * style constant for menu bar behavior (value is 1&lt;&lt;1)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Menu</code></li>
+ * </ul></p>
+ */
+ public static final int BAR = 1 << 1;
+
+ /**
+ * style constant for drop down menu/list behavior (value is 1&lt;&lt;2)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Menu</code></li>
+ * <li><code>ToolItem</code></li>
+ * <li><code>CoolItem</code></li>
+ * <li><code>Combo</code></li>
+ * </ul></p>
+ */
+ public static final int DROP_DOWN = 1 << 2;
+
+ /**
+ * style constant for pop up menu behavior (value is 1&lt;&lt;3)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Menu</code></li>
+ * </ul></p>
+ */
+ public static final int POP_UP = 1 << 3;
+
+ /**
+ * style constant for line separator behavior (value is 1&lt;&lt;1)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Label</code></li>
+ * <li><code>MenuItem</code></li>
+ * <li><code>ToolItem</code></li>
+ * </ul></p>
+ */
+ public static final int SEPARATOR = 1 << 1;
+
+ /**
+ * style constant for toggle button behavior (value is 1&lt;&lt;1)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Button</code></li>
+ * </ul></p>
+ */
+ public static final int TOGGLE = 1 << 1;
+
+ /**
+ * style constant for arrow button behavior (value is 1&lt;&lt;2)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Button</code></li>
+ * </ul></p>
+ */
+ public static final int ARROW = 1 << 2;
+
+ /**
+ * style constant for push button behavior (value is 1&lt;&lt;3)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Button</code></li>
+ * <li><code>MenuItem</code></li>
+ * <li><code>ToolItem</code></li>
+ * </ul></p>
+ */
+ public static final int PUSH = 1 << 3;
+
+ /**
+ * style constant for radio button behavior (value is 1&lt;&lt;4)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Button</code></li>
+ * <li><code>MenuItem</code></li>
+ * <li><code>ToolItem</code></li>
+ * </ul></p>
+ */
+ public static final int RADIO = 1 << 4;
+
+ /**
+ * style constant for check box behavior (value is 1&lt;&lt;5)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Button</code></li>
+ * <li><code>MenuItem</code></li>
+ * <li><code>ToolItem</code></li>
+ * <li><code>Table</code></li>
+ * <li><code>Tree</code></li>
+ * </ul></p>
+ */
+ public static final int CHECK = 1 << 5;
+
+ /**
+ * style constant for cascade behavior (value is 1&lt;&lt;6)
+ * <p><b>Used By:</b><ul>
+ * <li><code>MenuItem</code></li>
+ * </ul></p>
+ */
+ public static final int CASCADE = 1 << 6;
+
+ /**
+ * style constant for multi-selection behavior in lists
+ * and multiple line support on text fields (value is 1&lt;&lt;1)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Text</code></li>
+ * <li><code>List</code></li>
+ * <li><code>FileDialog</code></li>
+ * </ul></p>
+ */
+ public static final int MULTI = 1 << 1;
+
+ /**
+ * style constant for single selection behavior in lists
+ * and single line support on text fields (value is 1&lt;&lt;2)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Text</code></li>
+ * <li><code>List</code></li>
+ * <li><code>Table</code></li>
+ * <li><code>Tree</code></li>
+ * </ul></p>
+ */
+ public static final int SINGLE = 1 << 2;
+
+ /**
+ * style constant for read-only behavior (value is 1&lt;&lt;3)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Combo</code></li>
+ * <li><code>Text</code></li>
+ * </ul></p>
+ */
+ public static final int READ_ONLY = 1 << 3;
+
+ /**
+ * style constant for automatic line wrap behavior (value is 1&lt;&lt;6)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Label</code></li>
+ * <li><code>Text</code></li>
+ * <li><code>ToolBar</code></li>
+ * </ul></p>
+ */
+ public static final int WRAP = 1 << 6;
+
+ /**
+ * style constant for simple (not drop down) behavior (value is 1&lt;&lt;6)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Combo</code></li>
+ * </ul></p>
+ */
+ public static final int SIMPLE = 1 << 6;
+
+ /**
+ * style constant for shadow in behavior (value is 1&lt;&lt;2)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Label</code></li>
+ * <li><code>Group</code></li>
+ * </ul></p>
+ */
+ public static final int SHADOW_IN = 1 << 2;
+
+ /**
+ * style constant for shadow out behavior (value is 1&lt;&lt;3)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Label</code></li>
+ * <li><code>Group</code></li>
+ * <li><code>ToolBar</code></li>
+ * </ul></p>
+ */
+ public static final int SHADOW_OUT = 1 << 3;
+
+ /**
+ * style constant for shadow etched in behavior (value is 1&lt;&lt;4)
+ * <br>Note that this is a <em>HINT</em>. It is ignored on all platforms except Motif.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Group</code></li>
+ * </ul></p>
+ */
+ public static final int SHADOW_ETCHED_IN = 1 << 4;
+
+ /**
+ * style constant for shadow etched out behavior (value is 1&lt;&lt;6)
+ * <br>Note that this is a <em>HINT</em>. It is ignored on all platforms except Motif.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Group</code></li>
+ * </ul></p>
+ */
+ public static final int SHADOW_ETCHED_OUT = 1 << 6;
+
+ /**
+ * style constant for no shadow behavior (value is 1&lt;&lt;5)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Label</code></li>
+ * <li><code>Group</code></li>
+ * </ul></p>
+ */
+ public static final int SHADOW_NONE = 1 << 5;
+
+ /**
+ * style constant for progress bar behavior (value is 1&lt;&lt;1)
+ * <p><b>Used By:</b><ul>
+ * <li><code>ProgressBar</code></li>
+ * </ul></p>
+ */
+ public static final int INDETERMINATE = 1 << 1;
+
+ /**
+ * style constant for tool window behavior (value is 1&lt;&lt;2)
+ * <p>
+ * A tool window is a window intended to be used as a floating toolbar.
+ * It typically has a title bar that is shorter than a normal title bar,
+ * and the window title is typically drawn using a smaller font.
+ * <br>Note that this is a <em>HINT</em>.
+ * </p><p><b>Used By:</b><ul>
+ * <li><code>Decorations</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int TOOL = 1 << 2;
+
+ /**
+ * style constant to ensure no trimmings are used (value is 1&lt;&lt;3)
+ * <br>Note that this overrides all other trim styles.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Decorations</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int NO_TRIM = 1 << 3;
+
+ /**
+ * style constant for resize box trim (value is 1&lt;&lt;4)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Decorations</code> and subclasses</li>
+ * <li><code>Tracker</code></li>
+ * </ul></p>
+ */
+ public static final int RESIZE = 1 << 4;
+
+ /**
+ * style constant for title area trim (value is 1&lt;&lt;5)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Decorations</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int TITLE = 1 << 5;
+
+ /**
+ * style constant for close box trim (value is 1&lt;&lt;6,
+ * since we do not distinguish between CLOSE style and MENU style)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Decorations</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int CLOSE = 1 << 6;
+
+ /**
+ * style constant for shell menu trim (value is 1&lt;&lt;6,
+ * since we do not distinguish between CLOSE style and MENU style)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Decorations</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int MENU = CLOSE;
+
+ /**
+ * style constant for minimize box trim (value is 1&lt;&lt;7)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Decorations</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int MIN = 1 << 7;
+
+ /**
+ * style constant for maximize box trim (value is 1&lt;&lt;10)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Decorations</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int MAX = 1 << 10;
+
+ /**
+ * style constant for horizontal scrollbar behavior (value is 1&lt;&lt;8)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Scrollable</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int H_SCROLL = 1 << 8;
+
+ /**
+ * style constant for vertical scrollbar behavior (value is 1&lt;&lt;9)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Scrollable</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int V_SCROLL = 1 << 9;
+
+ /**
+ * style constant for bordered behavior (value is 1&lt;&lt;11)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Control</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int BORDER = 1 << 11;
+
+ /**
+ * style constant indicating that the window manager should clip
+ * a widget's children with respect to its viewable area. (value is 1&lt;&lt;12)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Control</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int CLIP_CHILDREN = 1 << 12;
+
+ /**
+ * style constant indicating that the window manager should clip
+ * a widget's siblings with respect to its viewable area. (value is 1&lt;&lt;13)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Control</code> and subclasses</li>
+ * </ul></p>
+ */
+ public static final int CLIP_SIBLINGS = 1 << 13;
+
+ /**
+ * style constant for always on top behavior (value is 1&lt;&lt;14)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Decorations</code>and subclasses</li>
+ * </ul></p>
+ */
+ public static final int ON_TOP = 1 << 14;
+
+ /**
+ * trim style convenience constant for the most common top level shell appearance
+ * (value is CLOSE|TITLE|MIN|MAX|RESIZE)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Shell</code></li>
+ * </ul></p>
+ */
+ public static final int SHELL_TRIM = CLOSE | TITLE | MIN | MAX | RESIZE;
+
+ /**
+ * trim style convenience constant for the most common dialog shell appearance
+ * (value is CLOSE|TITLE|BORDER)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Shell</code></li>
+ * </ul></p>
+ */
+ public static final int DIALOG_TRIM = TITLE | CLOSE | BORDER;
+
+ /**
+ * style constant for modeless behavior (value is 0)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Dialog</code></li>
+ * <li><code>Shell</code></li>
+ * </ul></p>
+ */
+ public static final int MODELESS = 0;
+
+ /**
+ * style constant for primary modal behavior (value is 1&lt;&lt;15)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Dialog</code></li>
+ * <li><code>Shell</code></li>
+ * </ul></p>
+ */
+ public static final int PRIMARY_MODAL = 1 << 15;
+
+ /**
+ * style constant for application modal behavior (value is 1&lt;&lt;16)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Dialog</code></li>
+ * <li><code>Shell</code></li>
+ * </ul></p>
+ */
+ public static final int APPLICATION_MODAL = 1 << 16;
+
+ /**
+ * style constant for system modal behavior (value is 1&lt;&lt;17)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Dialog</code></li>
+ * <li><code>Shell</code></li>
+ * </ul></p>
+ */
+ public static final int SYSTEM_MODAL = 1 << 17;
+
+ /**
+ * style constant for selection hiding behavior. (value is 1&lt;&lt;15)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Table</code></li>
+ * </ul></p>
+ */
+ public static final int HIDE_SELECTION = 1 << 15;
+
+ /**
+ * style constant for full row selection behavior. (value is 1&lt;&lt;16)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Table</code></li>
+ * </ul></p>
+ */
+ public static final int FULL_SELECTION = 1 << 16;
+
+ /**
+ * style constant for flat appearance. (value is 1&lt;&lt;23)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Button</code></li>
+ * <li><code>ToolBar</code></li>
+ * </ul></p>
+ */
+ public static final int FLAT = 1 << 23;
+
+ /**
+ * style constant for flat appearance. (value is 1&lt;&lt;16)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>ProgressBar</code></li>
+ * </ul></p>
+ */
+ public static final int SMOOTH = 1 << 16;
+
+ /**
+ * style constant for no background behavior (value is 1&lt;&lt;18)
+ * <p>
+ * By default, before a widget paints, the client area is filled with the current background color.
+ * When this style is specified, the background is not filled, and the application is responsible
+ * for filling every pixel of the client area.
+ * This style might be used as an alternative to "double-buffering" in order to reduce flicker.
+ * This style does not mean "transparent" - widgets that are obscured will not draw through.
+ * </p><p><b>Used By:</b><ul>
+ * <li><code>Composite</code></li>
+ * </ul></p>
+ */
+ public static final int NO_BACKGROUND = 1 << 18;
+
+ /**
+ * style constant for does not take focus behavior (value is 1&lt;&lt;19)
+ * <br>Note that this is a <em>HINT</em>.
+ * <p><b>Used By:</b><ul>
+ * <li><code>Composite</code></li>
+ * </ul></p>
+ */
+ public static final int NO_FOCUS = 1 << 19;
+
+ /**
+ * style constant for no redraw on resize behavior (value is 1&lt;&lt;20)
+ * <p>
+ * This style stops the entire client area from being invalidated when the size
+ * of the Canvas changes. Specifically, when the size of the Canvas gets smaller,
+ * the SWT.Paint event is not sent. When it gets bigger, an SWT.Paint event is
+ * sent with a GC clipped to only the new areas to be painted. Without this
+ * style, the entire client area will be repainted.
+ * </p><p><b>Used By:</b><ul>
+ * <li><code>Composite</code></li>
+ * </ul></p>
+ */
+ public static final int NO_REDRAW_RESIZE = 1 << 20;
+
+ /**
+ * style constant for no paint event merging behavior (value is 1&lt;&lt;21)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Composite</code></li>
+ * </ul></p>
+ */
+ public static final int NO_MERGE_PAINTS = 1 << 21;
+
+ /**
+ * style constant for preventing child radio group behavior (value is 1&lt;&lt;22)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Composite</code></li>
+ * </ul></p>
+ */
+ public static final int NO_RADIO_GROUP = 1 << 22;
+
+ /**
+ * style constant for left to right orientation (value is 1&lt;&lt;25)
+ * <p>
+ * When orientation is not explicitly specified, orientation is
+ * inherited. This means that children will be assigned the
+ * orientation of their parent. To override this behavior and
+ * force an orientation for a child, explicitly set the orientation
+ * of the child when that child is created.
+ * </p>
+ * <p><b>Used By:</b><ul>
+ * <li><code>Control</code></li>
+ * <li><code>Menu</code></li>
+ * </ul></p>
+ *
+ * <p>
+ * <b>NOTE:</b> This API element is part of an interim API that is still under
+ * development and is expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @since 2.1
+ */
+ public static final int LEFT_TO_RIGHT = 1 << 25;
+
+ /**
+ * style constant for right to left orientation (value is 1&lt;&lt;26)
+ * <p>
+ * When orientation is not explicitly specified, orientation is
+ * inherited. This means that children will be assigned the
+ * orientation of their parent. To override this behavior and
+ * force an orientation for a child, explicitly set the orientation
+ * of the child when that child is created.
+ * </p>
+ * <p><b>Used By:</b><ul>
+ * <li><code>Control</code></li>
+ * <li><code>Menu</code></li>
+ * </ul></p>
+ *
+ * <p>
+ * <b>NOTE:</b> This API element is part of an interim API that is still under
+ * development and is expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @since 2.1
+ */
+ public static final int RIGHT_TO_LEFT = 1 << 26;
+
+ /**
+ * style constant to indicate coordinate mirroring (value is 1&lt;&lt;27)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Control</code></li>
+ * <li><code>Menu</code></li>
+ * </ul></p>
+ *
+ * <p>
+ * <b>NOTE:</b> This API element is part of an interim API that is still under
+ * development and is expected to change significantly before reaching stability.
+ * It is being made available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ * </p>
+ *
+ * @since 2.1
+ */
+ public static final int MIRRORED = 1 << 27;
+
+ /**
+ * style constant for align up behavior (value is 1&lt;&lt;7,
+ * since align UP and align TOP are considered the same)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Button</code> with <code>ARROW</code> style</li>
+ * <li><code>Tracker</code></li>
+ * </ul></p>
+ */
+ public static final int UP = 1 << 7;
+
+ /**
+ * style constant for align top behavior (value is 1&lt;&lt;7,
+ * since align UP and align TOP are considered the same)
+ * <p><b>Used By:</b><ul>
+ * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
+ * </ul></p>
+ */
+ public static final int TOP = UP;
+
+ /**
+ * style constant for align down behavior (value is 1&lt;&lt;10,
+ * since align DOWN and align BOTTOM are considered the same)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Button</code> with <code>ARROW</code> style</li>
+ * <li><code>Tracker</code></li>
+ * </ul></p>
+ */
+ public static final int DOWN = 1 << 10;
+
+ /**
+ * style constant for align bottom behavior (value is 1&lt;&lt;10,
+ * since align DOWN and align BOTTOM are considered the same)
+ * <p><b>Used By:</b><ul>
+ * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
+ * </ul></p>
+ */
+ public static final int BOTTOM = DOWN;
+
+ /**
+ * style constant for align left behavior (value is 1&lt;&lt;14)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Button</code></li>
+ * <li><code>Label</code></li>
+ * <li><code>TableColumn</code></li>
+ * <li><code>Tracker</code></li>
+ * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
+ * </ul></p>
+ */
+ public static final int LEFT = 1 << 14;
+
+ /**
+ * style constant for align right behavior (value is 1&lt;&lt;17)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Button</code></li>
+ * <li><code>Label</code></li>
+ * <li><code>TableColumn</code></li>
+ * <li><code>Tracker</code></li>
+ * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
+ * </ul></p>
+ */
+ public static final int RIGHT = 1 << 17;
+
+ /**
+ * style constant for align center behavior (value is 1&lt;&lt;24)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Button</code></li>
+ * <li><code>Label</code></li>
+ * <li><code>TableColumn</code></li>
+ * <li><code>FormAttachment</code> in a <code>FormLayout</code></li>
+ * </ul></p>
+ */
+ public static final int CENTER = 1 << 24;
+
+ /**
+ * style constant for horizontal alignment or orientation behavior (value is 1&lt;&lt;8)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Label</code></li>
+ * <li><code>ProgressBar</code></li>
+ * <li><code>Sash</code></li>
+ * <li><code>Scale</code></li>
+ * <li><code>ScrollBar</code></li>
+ * <li><code>Slider</code></li>
+ * <li><code>ToolBar</code></li>
+ * <li><code>FillLayout</code> type</li>
+ * <li><code>RowLayout</code> type</li>
+ * </ul></p>
+ */
+ public static final int HORIZONTAL = 1 << 8;
+
+ /**
+ * style constant for vertical alignment or orientation behavior (value is 1&lt;&lt;9)
+ * <p><b>Used By:</b><ul>
+ * <li><code>Label</code></li>
+ * <li><code>ProgressBar</code></li>
+ * <li><code>Sash</code></li>
+ * <li><code>Scale</code></li>
+ * <li><code>ScrollBar</code></li>
+ * <li><code>Slider</code></li>
+ * <li><code>ToolBar</code></li>
+ * <li><code>FillLayout</code> type</li>
+ * <li><code>RowLayout</code> type</li>
+ * </ul></p>
+ */
+ public static final int VERTICAL = 1 << 9;
+
+ /**
+ * Input Method Editor style constant for double byte
+ * input behavior (value is 1&lt;&lt;1)
+ */
+ public static final int DBCS = 1 << 1;
+
+ /**
+ * Input Method Editor style constant for alpha
+ * input behavior (value is 1&lt;&lt;2)
+ */
+ public static final int ALPHA = 1 << 2;
+
+ /**
+ * Input Method Editor style constant for native
+ * input behavior (value is 1&lt;&lt;3)
+ */
+ public static final int NATIVE = 1 << 3;
+
+ /**
+ * Input Method Editor style constant for phonetic
+ * input behavior (value is 1&lt;&lt;4)
+ */
+ public static final int PHONETIC = 1 << 4;
+
+ /**
+ * Input Method Editor style constant for romanicized
+ * input behavior (value is 1&lt;&lt;5)
+ */
+ public static final int ROMAN = 1 << 5;
+
+ /**
+ * ASCII character convenience constant for the backspace character
+ * (value is the <code>char</code> '\b')
+ */
+ public static final char BS = '\b';
+
+ /**
+ * ASCII character convenience constant for the carriage return character
+ * (value is the <code>char</code> '\r')
+ */
+ public static final char CR = '\r';
+
+ /**
+ * ASCII character convenience constant for the delete character
+ * (value is the <code>char</code> with value 127)
+ */
+ public static final char DEL = 0x7F;
+
+ /**
+ * ASCII character convenience constant for the escape character
+ * (value is the <code>char</code> with value 27)
+ */
+ public static final char ESC = 0x1B;
+
+ /**
+ * ASCII character convenience constant for the line feed character
+ * (value is the <code>char</code> '\n')
+ */
+ public static final char LF = '\n';
+
+ /**
+ * ASCII character convenience constant for the tab character
+ * (value is the <code>char</code> '\t')
+ *
+ * @since 2.1
+ */
+ public static final char TAB = '\t';
+
+ /**
+ * keyboard and/or mouse event mask indicating that the ALT key
+ * was pushed on the keyboard when the event was generated
+ * (value is 1&lt;&lt;16)
+ */
+ public static final int ALT = 1 << 16;
+
+ /**
+ * keyboard and/or mouse event mask indicating that the SHIFT key
+ * was pushed on the keyboard when the event was generated
+ * (value is 1&lt;&lt;17)
+ */
+ public static final int SHIFT = 1 << 17;
+
+ /**
+ * keyboard and/or mouse event mask indicating that the CTRL key
+ * was pushed on the keyboard when the event was generated
+ * (value is 1&lt;&lt;18)
+ */
+ public static final int CTRL = 1 << 18;
+
+ /**
+ * keyboard and/or mouse event mask indicating that the CTRL key
+ * was pushed on the keyboard when the event was generated. This
+ * is a synonym for CTRL (value is 1&lt;&lt;18)
+ */
+ public static final int CONTROL = CTRL;
+
+ /**
+ * keyboard and/or mouse event mask indicating that the COMMAND key
+ * was pushed on the keyboard when the event was generated
+ * (value is 1&lt;&lt;22)
+ *
+ * @since 2.1
+ */
+ public static final int COMMAND = 1 << 22;
+
+ /**
+ * keyboard and/or mouse event mask indicating all possible
+ * keyboard modifiers. To allow for the future, this mask
+ * is intended to be used in place of code that references
+ * each individual keyboard mask. For example, the following
+ * expression will determine whether any modifer is pressed
+ * and will continue to work as new modifier masks are added.
+ *
+ * <code>(stateMask & SWT.MODIFIER_MASK) != 0</code>.
+ *
+ * @since 2.1
+ */
+ public static final int MODIFIER_MASK;
+
+ /**
+ * keyboard and/or mouse event mask indicating that mouse button one
+ * was pushed when the event was generated. (value is 1&lt;&lt;19)
+ */
+ public static final int BUTTON1 = 1 << 19;
+
+ /**
+ * keyboard and/or mouse event mask indicating that mouse button two
+ * was pushed when the event was generated. (value is 1&lt;&lt;20)
+ */
+ public static final int BUTTON2 = 1 << 20;
+
+ /**
+ * keyboard and/or mouse event mask indicating that mouse button three
+ * was pushed when the event was generated. (value is 1&lt;&lt;21)
+ */
+ public static final int BUTTON3 = 1 << 21;
+
+ /**
+ * keyboard and/or mouse event mask indicating all possible
+ * mouse buttons. To allow for the future, this mask
+ * is intended to be used in place of code that references
+ * each individual button mask. For example, the following
+ * expression will determine whether any button is pressed
+ * and will continue to work as new button masks are added.
+ *
+ * <code>(stateMask & SWT.BUTTON_MASK) != 0</code>.
+ *
+ * @since 2.1
+ */
+ public static final int BUTTON_MASK;
+
+ /**
+ * keyboard and/or mouse event mask indicating that the MOD1 key
+ * was pushed on the keyboard when the event was generated. This
+ * is the primary keyboard modifier for the platform.
+ *
+ * @since 2.1
+ */
+ public static final int MOD1;
+
+ /**
+ * keyboard and/or mouse event mask indicating that the MOD2 key
+ * was pushed on the keyboard when the event was generated. This
+ * is the secondary keyboard modifier for the platform.
+ *
+ * @since 2.1
+ */
+ public static final int MOD2;
+
+ /**
+ * keyboard and/or mouse event mask indicating that the MOD3 key
+ * was pushed on the keyboard when the event was generated.
+ *
+ * @since 2.1
+ */
+ public static final int MOD3;
+
+ /**
+ * keyboard and/or mouse event mask indicating that the MOD4 key
+ * was pushed on the keyboard when the event was generated.
+ *
+ * @since 2.1
+ */
+ public static final int MOD4;
+
+ /**
+ * accelerator constant used to differentiate a key code from a
+ * unicode character. If this bit is set, then the key stroke
+ * portion of an accelerator represents a key code. If this bit
+ * is not set, then the key stroke portion of an accelerator is
+ * a unicode character.
+ *
+ * The following expression is false:
+ *
+ * <code>((SWT.MOD1 | SWT.MOD2 | 'T') & SWT.KEYCODE_BIT) != 0</code>.
+ *
+ * The following expression is true:
+ *
+ * <code>((SWT.MOD3 | SWT.F2) & SWT.KEYCODE_BIT) != 0</code>.
+ *
+ * (value is (1&lt;&lt;24))
+ *
+ * @since 2.1
+ */
+ public static final int KEYCODE_BIT = (1 << 24);
+
+ /**
+ * accelerator constant used to extract the key stroke portion of
+ * an accelerator. The key stroke may be a key code or a unicode
+ * value. If the key stroke is a key code <code>KEYCODE_BIT</code>
+ * will be set.
+ *
+ * @since 2.1
+ */
+ public static final int KEY_MASK = KEYCODE_BIT + 0xFFFF;
+
+ /**
+ * keyboard event constant representing the UP ARROW key
+ * (value is (1&lt;&lt;24)+1)
+ */
+ public static final int ARROW_UP = KEYCODE_BIT + 1;
+
+ /**
+ * keyboard event constant representing the DOWN ARROW key
+ * (value is (1&lt;&lt;24)+2)
+ */
+ public static final int ARROW_DOWN = KEYCODE_BIT + 2;
+
+ /**
+ * keyboard event constant representing the LEFT ARROW key
+ * (value is (1&lt;&lt;24)+3)
+ */
+ public static final int ARROW_LEFT = KEYCODE_BIT + 3;
+
+ /**
+ * keyboard event constant representing the RIGHT ARROW key
+ * (value is (1&lt;&lt;24)+4)
+ */
+ public static final int ARROW_RIGHT = KEYCODE_BIT + 4;
+
+ /**
+ * keyboard event constant representing the PAGE UP key
+ * (value is (1&lt;&lt;24)+5)
+ */
+ public static final int PAGE_UP = KEYCODE_BIT + 5;
+
+ /**
+ * keyboard event constant representing the PAGE DOWN key
+ * (value is (1&lt;&lt;24)+6)
+ */
+ public static final int PAGE_DOWN = KEYCODE_BIT + 6;
+
+ /**
+ * keyboard event constant representing the HOME key
+ * (value is (1&lt;&lt;24)+7)
+ */
+ public static final int HOME = KEYCODE_BIT + 7;
+
+ /**
+ * keyboard event constant representing the END key
+ * (value is (1&lt;&lt;24)+8)
+ */
+ public static final int END = KEYCODE_BIT + 8;
+
+ /**
+ * keyboard event constant representing the INSERT key
+ * (value is (1&lt;&lt;24)+9)
+ */
+ public static final int INSERT = KEYCODE_BIT + 9;
+
+ /**
+ * keyboard event constant representing the F1 key
+ * (value is (1&lt;&lt;24)+10)
+ */
+ public static final int F1 = KEYCODE_BIT + 10;
+
+ /**
+ * keyboard event constant representing the F2 key
+ * (value is (1&lt;&lt;24)+11)
+ */
+ public static final int F2 = KEYCODE_BIT + 11;
+
+ /**
+ * keyboard event constant representing the F3 key
+ * (value is (1&lt;&lt;24)+12)
+ */
+ public static final int F3 = KEYCODE_BIT + 12;
+
+ /**
+ * keyboard event constant representing the F4 key
+ * (value is (1&lt;&lt;24)+13)
+ */
+ public static final int F4 = KEYCODE_BIT + 13;
+
+ /**
+ * keyboard event constant representing the F5 key
+ * (value is (1&lt;&lt;24)+14)
+ */
+ public static final int F5 = KEYCODE_BIT + 14;
+
+ /**
+ * keyboard event constant representing the F6 key
+ * (value is (1&lt;&lt;24)+15)
+ */
+ public static final int F6 = KEYCODE_BIT + 15;
+
+ /**
+ * keyboard event constant representing the F7 key
+ * (value is (1&lt;&lt;24)+16)
+ */
+ public static final int F7 = KEYCODE_BIT + 16;
+
+ /**
+ * keyboard event constant representing the F8 key
+ * (value is (1&lt;&lt;24)+17)
+ */
+ public static final int F8 = KEYCODE_BIT + 17;
+
+ /**
+ * keyboard event constant representing the F9 key
+ * (value is (1&lt;&lt;24)+18)
+ */
+ public static final int F9 = KEYCODE_BIT + 18;
+
+ /**
+ * keyboard event constant representing the F10 key
+ * (value is (1&lt;&lt;24)+19)
+ */
+ public static final int F10 = KEYCODE_BIT + 19;
+
+ /**
+ * keyboard event constant representing the F11 key
+ * (value is (1&lt;&lt;24)+20)
+ */
+ public static final int F11 = KEYCODE_BIT + 20;
+
+ /**
+ * keyboard event constant representing the F12 key
+ * (value is (1&lt;&lt;24)+21)
+ */
+ public static final int F12 = KEYCODE_BIT + 21;
+
+ /**
+ * <code>MessageBox</code> style constant for error icon
+ * behavior (value is 1)
+ */
+ public static final int ICON_ERROR = 1;
+
+ /**
+ * <code>MessageBox</code> style constant for information icon
+ * behavior (value is 1&lt;&lt;1)
+ */
+ public static final int ICON_INFORMATION = 1 << 1;
+
+ /**
+ * <code>MessageBox</code> style constant for question icon
+ * behavior (value is 1&lt;&lt;2)
+ */
+ public static final int ICON_QUESTION = 1 << 2;
+
+ /**
+ * <code>MessageBox</code> style constant for warning icon
+ * behavior (value is 1&lt;&lt;3)
+ */
+ public static final int ICON_WARNING = 1 << 3;
+
+ /**
+ * <code>MessageBox</code> style constant for "working" icon
+ * behavior (value is 1&lt;&lt;4)
+ */
+ public static final int ICON_WORKING = 1 << 4;
+
+ /**
+ * <code>MessageBox</code> style constant for an OK button.
+ * Valid combinations are OK, OK|CANCEL
+ * (value is 1&lt;&lt;5)
+ */
+ public static final int OK = 1 << 5;
+
+ /**
+ * <code>MessageBox</code> style constant for YES button.
+ * Valid combinations are YES|NO, YES|NO|CANCEL
+ * (value is 1&lt;&lt;6)
+ */
+ public static final int YES = 1 << 6;
+
+ /**
+ * <code>MessageBox</code> style constant for NO button.
+ * Valid combinations are YES|NO, YES|NO|CANCEL
+ * (value is 1&lt;&lt;7)
+ */
+ public static final int NO = 1 << 7;
+
+ /**
+ * <code>MessageBox</code> style constant for a CANCEL button.
+ * Valid combinations are OK|CANCEL, YES|NO|CANCEL, RETRY|CANCEL
+ * (value is 1&lt;&lt;8)
+ */
+ public static final int CANCEL = 1 << 8;
+
+ /**
+ * <code>MessageBox</code> style constant for an ABORT button.
+ * The only valid combination is ABORT|RETRY|IGNORE
+ * (value is 1&lt;&lt;9)
+ */
+ public static final int ABORT = 1 << 9;
+
+ /**
+ * <code>MessageBox</code> style constant for a RETRY button.
+ * Valid combinations are ABORT|RETRY|IGNORE, RETRY|CANCEL
+ * (value is 1&lt;&lt;10)
+ */
+ public static final int RETRY = 1 << 10;
+
+ /**
+ * <code>MessageBox</code> style constant for an IGNORE button.
+ * The only valid combination is ABORT|RETRY|IGNORE
+ * (value is 1&lt;&lt;11)
+ */
+ public static final int IGNORE = 1 << 11;
+
+ /**
+ * <code>FileDialog</code> style constant for open file dialog behavior
+ * (value is 1&lt;&lt;12)
+ */
+ public static final int OPEN = 1 << 12;
+
+ /**
+ * <code>FileDialog</code> style constant for save file dialog behavior
+ * (value is 1&lt;&lt;13)
+ */
+ public static final int SAVE = 1 << 13;
+
+ /**
+ * default color white (value is 1)
+ */
+ public static final int COLOR_WHITE = 1;
+
+ /**
+ * default color black (value is 2)
+ */
+ public static final int COLOR_BLACK = 2;
+
+ /**
+ * default color red (value is 3)
+ */
+ public static final int COLOR_RED = 3;
+
+ /**
+ * default color dark red (value is 4)
+ */
+ public static final int COLOR_DARK_RED = 4;
+
+ /**
+ * default color green (value is 5)
+ */
+ public static final int COLOR_GREEN = 5;
+
+ /**
+ * default color dark green (value is 6)
+ */
+ public static final int COLOR_DARK_GREEN = 6;
+
+ /**
+ * default color yellow (value is 7)
+ */
+ public static final int COLOR_YELLOW = 7;
+
+ /**
+ * default color dark yello (value is 8)
+ */
+ public static final int COLOR_DARK_YELLOW = 8;
+
+ /**
+ * default color blue (value is 9)
+ */
+ public static final int COLOR_BLUE = 9;
+
+ /**
+ * default color dark blue (value is 10)
+ */
+ public static final int COLOR_DARK_BLUE = 10;
+
+ /**
+ * default color magenta (value is 11)
+ */
+ public static final int COLOR_MAGENTA = 11;
+
+ /**
+ * default color dark magenta (value is 12)
+ */
+ public static final int COLOR_DARK_MAGENTA = 12;
+
+ /**
+ * default color cyan (value is 13)
+ */
+ public static final int COLOR_CYAN = 13;
+
+ /**
+ * default color dark cyan (value is 14)
+ */
+ public static final int COLOR_DARK_CYAN = 14;
+
+ /**
+ * default color gray (value is 15)
+ */
+ public static final int COLOR_GRAY = 15;
+
+ /**
+ * default color dark gray (value is 16)
+ */
+ public static final int COLOR_DARK_GRAY = 16;
+
+ /*
+ * System Colors
+ *
+ * Dealing with system colors is an area where there are
+ * many platform differences. On some platforms, system
+ * colors can change dynamically while the program is
+ * running. On other platforms, system colors can be
+ * changed for all instances of a particular widget.
+ * Therefore, the only truly portable method to obtain
+ * a widget color query is to query the color from an
+ * instance of the widget.
+ *
+ * It is expected that the list of supported colors
+ * will grow over time.
+ */
+
+ /**
+ * system color used to paint dark shadow areas (value is 17)
+ */
+ public static final int COLOR_WIDGET_DARK_SHADOW = 17;
+
+ /**
+ * system color used to paint normal shadow areas (value is 18)
+ */
+ public static final int COLOR_WIDGET_NORMAL_SHADOW = 18;
+
+ /**
+ * system color used to paint light shadow areas (value is 19)
+ */
+ public static final int COLOR_WIDGET_LIGHT_SHADOW = 19;
+
+ /**
+ * system color used to paint highlight shadow areas (value is 20)
+ */
+ public static final int COLOR_WIDGET_HIGHLIGHT_SHADOW = 20;
+
+ /**
+ * system color used to paint foreground areas (value is 21)
+ */
+ public static final int COLOR_WIDGET_FOREGROUND = 21;
+
+ /**
+ * system color used to paint background areas (value is 22)
+ */
+ public static final int COLOR_WIDGET_BACKGROUND = 22;
+
+ /**
+ * system color used to paint border areas (value is 23)
+ */
+ public static final int COLOR_WIDGET_BORDER = 23;
+
+ /**
+ * system color used to paint list foreground areas (value is 24)
+ */
+ public static final int COLOR_LIST_FOREGROUND = 24;
+
+ /**
+ * system color used to paint list background areas (value is 25)
+ */
+ public static final int COLOR_LIST_BACKGROUND = 25;
+
+ /**
+ * system color used to paint list selection background areas (value is 26)
+ */
+ public static final int COLOR_LIST_SELECTION = 26;
+
+ /**
+ * system color used to paint list selected text (value is 27)
+ */
+ public static final int COLOR_LIST_SELECTION_TEXT = 27;
+
+ /**
+ * system color used to paint tooltip text (value is 28)
+ */
+ public static final int COLOR_INFO_FOREGROUND = 28;
+
+ /**
+ * system color used to paint tooltip background areas (value is 29)
+ */
+ public static final int COLOR_INFO_BACKGROUND = 29;
+
+ /**
+ * system color used to paint title text (value is 30)
+ */
+ public static final int COLOR_TITLE_FOREGROUND = 30;
+
+ /**
+ * system color used to paint title background areas (value is 31)
+ */
+ public static final int COLOR_TITLE_BACKGROUND = 31;
+
+ /**
+ * system color used to paint title background gradient (value is 32)
+ */
+ public static final int COLOR_TITLE_BACKGROUND_GRADIENT = 32;
+
+ /**
+ * system color used to paint inactive title text (value is 33)
+ */
+ public static final int COLOR_TITLE_INACTIVE_FOREGROUND = 33;
+
+ /**
+ * system color used to paint inactive title background areas (value is 34)
+ */
+ public static final int COLOR_TITLE_INACTIVE_BACKGROUND = 34;
+
+ /**
+ * system color used to paint inactive title background gradient (value is 35)
+ */
+ public static final int COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = 35;
+
+ /**
+ * draw constant indicating whether the drawing operation
+ * should fill the background (value is 1&lt;&lt;0)
+ */
+ public static final int DRAW_TRANSPARENT = 1 << 0;
+
+ /**
+ * draw constant indicating whether the string drawing operation
+ * should handle line-delimeters (value is 1&lt;&lt;1)
+ */
+ public static final int DRAW_DELIMITER = 1 << 1;
+
+ /**
+ * draw constant indicating whether the string drawing operation
+ * should expand TAB characters (value is 1&lt;&lt;2)
+ */
+ public static final int DRAW_TAB = 1 << 2;
+
+ /**
+ * draw constant indicating whether the string drawing operation
+ * should handle mnemonics (value is 1&lt;&lt;3)
+ */
+ public static final int DRAW_MNEMONIC = 1 << 3;
+
+ /**
+ * SWT error constant indicating that no error number was specified
+ * (value is 1)
+ */
+ public static final int ERROR_UNSPECIFIED = 1;
+
+ /**
+ * SWT error constant indicating that no more handles for an
+ * operating system resource are available
+ * (value is 2)
+ */
+ public static final int ERROR_NO_HANDLES = 2;
+
+ /**
+ * SWT error constant indicating that no more callback resources are available
+ * (value is 3)
+ */
+ public static final int ERROR_NO_MORE_CALLBACKS = 3;
+
+ /**
+ * SWT error constant indicating that a null argument was passed in
+ * (value is 4)
+ */
+ public static final int ERROR_NULL_ARGUMENT = 4;
+
+ /**
+ * SWT error constant indicating that an invalid argument was passed in
+ * (value is 5)
+ */
+ public static final int ERROR_INVALID_ARGUMENT = 5;
+
+ /**
+ * SWT error constant indicating that a value was found to be
+ * outside the allowable range
+ * (value is 6)
+ */
+ public static final int ERROR_INVALID_RANGE = 6;
+
+ /**
+ * SWT error constant indicating that a value which can not be
+ * zero was found to be
+ * (value is 7)
+ */
+ public static final int ERROR_CANNOT_BE_ZERO = 7;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to provide the value of an item
+ * (value is 8)
+ */
+ public static final int ERROR_CANNOT_GET_ITEM = 8;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to provide the selection
+ * (value is 9)
+ */
+ public static final int ERROR_CANNOT_GET_SELECTION = 9;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to provide the height of an item
+ * (value is 11)
+ */
+ public static final int ERROR_CANNOT_GET_ITEM_HEIGHT = 11;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to provide the text of a widget
+ * (value is 12)
+ */
+ public static final int ERROR_CANNOT_GET_TEXT = 12;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to set the text of a widget
+ * (value is 13)
+ */
+ public static final int ERROR_CANNOT_SET_TEXT = 13;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to add an item
+ * (value is 14)
+ */
+ public static final int ERROR_ITEM_NOT_ADDED = 14;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to remove an item
+ * (value is 15)
+ */
+ public static final int ERROR_ITEM_NOT_REMOVED = 15;
+
+ /**
+ * SWT error constant indicating that a particular feature has
+ * not been implemented on this platform
+ * (value is 20)
+ */
+ public static final int ERROR_NOT_IMPLEMENTED = 20;
+
+ /**
+ * SWT error constant indicating that a menu which needed
+ * to have the drop down style had some other style instead
+ * (value is 21)
+ */
+ public static final int ERROR_MENU_NOT_DROP_DOWN = 21;
+
+ /**
+ * SWT error constant indicating that an attempt was made to
+ * invoke an SWT operation which can only be executed by the
+ * user-interface thread from some other thread
+ * (value is 22)
+ */
+ public static final int ERROR_THREAD_INVALID_ACCESS = 22;
+
+ /**
+ * SWT error constant indicating that an attempt was made to
+ * invoke an SWT operation using a widget which had already
+ * been disposed.
+ * (value is 24)
+ */
+ public static final int ERROR_WIDGET_DISPOSED = 24;
+
+ /**
+ * SWT error constant indicating that a menu item which needed
+ * to have the cascade style had some other style instead
+ * (value is 27)
+ */
+ public static final int ERROR_MENUITEM_NOT_CASCADE = 27;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to set the selection of a widget
+ * (value is 28)
+ */
+ public static final int ERROR_CANNOT_SET_SELECTION = 28;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to set the menu
+ * (value is 29)
+ */
+ public static final int ERROR_CANNOT_SET_MENU = 29;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to set the enabled state
+ * (value is 30)
+ */
+ public static final int ERROR_CANNOT_SET_ENABLED = 30;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to provide enabled/disabled state information
+ * (value is 31)
+ */
+ public static final int ERROR_CANNOT_GET_ENABLED = 31;
+
+ /**
+ * SWT error constant indicating that a provided widget can
+ * not be used as a parent in the current operation
+ * (value is 32)
+ */
+ public static final int ERROR_INVALID_PARENT = 32;
+
+ /**
+ * SWT error constant indicating that a menu which needed
+ * to have the menu bar style had some other style instead
+ * (value is 33)
+ */
+ public static final int ERROR_MENU_NOT_BAR = 33;
+
+ /**
+ * SWT error constant indicating that the underlying operating
+ * system was unable to provide count information
+ * (value is 36)
+ */
+ public static final int ERROR_CANNOT_GET_COUNT = 36;
+
+ /**
+ * SWT error constant indicating that a menu which needed
+ * to have the pop up menu style had some other style instead
+ * (value is 37)
+ */
+ public static final int ERROR_MENU_NOT_POP_UP = 37;
+
+ /**
+ * SWT error constant indicating that a graphics operation
+ * was attempted with an image of an unsupported depth
+ * (value is 38)
+ */
+ public static final int ERROR_UNSUPPORTED_DEPTH = 38;
+
+ /**
+ * SWT error constant indicating that an input/output operation
+ * failed during the execution of an SWT operation
+ * (value is 39)
+ */
+ public static final int ERROR_IO = 39;
+
+ /**
+ * SWT error constant indicating that a graphics operation
+ * was attempted with an image having an invalid format
+ * (value is 40)
+ */
+ public static final int ERROR_INVALID_IMAGE = 40;
+
+ /**
+ * SWT error constant indicating that a graphics operation
+ * was attempted with an image having a valid but unsupported
+ * format
+ * (value is 42)
+ */
+ public static final int ERROR_UNSUPPORTED_FORMAT = 42;
+
+ /**
+ * SWT error constant indicating that an attempt was made
+ * to subclass an SWT widget class without implementing the
+ * <code>checkSubclass()</code> method. For additional
+ * information see the comment in <code>Widget.checkSubclass()</code>
+ * (value is 43)
+ *
+ * @see org.eclipse.swt.widgets.Widget#checkSubclass
+ */
+ public static final int ERROR_INVALID_SUBCLASS = 43;
+
+ /**
+ * SWT error constant indicating that an attempt was made to
+ * invoke an SWT operation using a graphics object which had
+ * already been disposed.
+ * (value is 44)
+ */
+ public static final int ERROR_GRAPHIC_DISPOSED = 44;
+
+ /**
+ * SWT error constant indicating that an attempt was made to
+ * invoke an SWT operation using a device which had already
+ * been disposed.
+ * (value is 45)
+ */
+ public static final int ERROR_DEVICE_DISPOSED = 45;
+
+ /**
+ * SWT error constant indicating that an exception happened
+ * when executing a runnable.
+ * (value is 46)
+ */
+ public static final int ERROR_FAILED_EXEC = 46;
+
+ /**
+ * SWT error constant indicating that an unsatisfied link
+ * error occured while attempting to load a library.
+ * (value is 47)
+ */
+ public static final int ERROR_FAILED_LOAD_LIBRARY = 47;
+
+ /**
+ * traversal event detail field value indicating that no
+ * traversal action should be taken.
+ * (value is 0)
+ */
+ public static final int TRAVERSE_NONE = 0;
+
+ /**
+ * traversal event detail field value indicating that the
+ * key which designates that a dialog should be cancelled was
+ * pressed; typically, this is the ESC key
+ * (value is 1&lt;&lt;1)
+ */
+ public static final int TRAVERSE_ESCAPE = 1 << 1;
+
+ /**
+ * traversal event detail field value indicating that the
+ * key which activates the default button in a dialog was
+ * pressed; typically, this is the ENTER key
+ * (value is 1&lt;&lt;2)
+ */
+ public static final int TRAVERSE_RETURN = 1 << 2;
+
+ /**
+ * traversal event detail field value indicating that the
+ * key which designates that focus should be given to the
+ * previous tab group was pressed; typically, this is the
+ * SHIFT-TAB key sequence
+ * (value is 1&lt;&lt;3)
+ */
+ public static final int TRAVERSE_TAB_PREVIOUS = 1 << 3;
+
+ /**
+ * traversal event detail field value indicating that the
+ * key which designates that focus should be given to the
+ * next tab group was pressed; typically, this is the
+ * TAB key
+ * (value is 1&lt;&lt;4)
+ */
+ public static final int TRAVERSE_TAB_NEXT = 1 << 4;
+
+ /**
+ * traversal event detail field value indicating that the
+ * key which designates that focus should be given to the
+ * previous tab item was pressed; typically, this is either
+ * the LEFT-ARROW or UP-ARROW keys
+ * (value is 1&lt;&lt;5)
+ */
+ public static final int TRAVERSE_ARROW_PREVIOUS = 1 << 5;
+
+ /**
+ * traversal event detail field value indicating that the
+ * key which designates that focus should be given to the
+ * previous tab item was pressed; typically, this is either
+ * the RIGHT-ARROW or DOWN-ARROW keys
+ * (value is 1&lt;&lt;6)
+ */
+ public static final int TRAVERSE_ARROW_NEXT = 1 << 6;
+
+ /**
+ * traversal event detail field value indicating that a
+ * mnemonic key sequence was pressed
+ * (value is 1&lt;&lt;7)
+ */
+ public static final int TRAVERSE_MNEMONIC = 1 << 7;
+
+ /**
+ * traversal event detail field value indicating that the
+ * key which designates that the previous page of a multi-page
+ * window should be shown was pressed; typically, this
+ * is the CTRL-PAGEUP key sequence
+ * (value is 1&lt;&lt;8)
+ */
+ public static final int TRAVERSE_PAGE_PREVIOUS = 1 << 8;
+
+ /**
+ * traversal event detail field value indicating that the
+ * key which designates that the next page of a multi-page
+ * window should be shown was pressed; typically, this
+ * is the CTRL-PAGEDOWN key sequence
+ * (value is 1&lt;&lt;9)
+ */
+ public static final int TRAVERSE_PAGE_NEXT = 1 << 9;
+
+ /**
+ * constant indicating that an image or operation is of type bitmap (value is 0)
+ */
+ public static final int BITMAP = 0;
+
+ /**
+ * constant indicating that an image or operation is of type icon (value is 1)
+ */
+ public static final int ICON = 1;
+
+ /**
+ * <code>Image</code> constructor argument indicating that
+ * the new image should be a copy of the image provided as
+ * an argument (value is 0)
+ */
+ public static final int IMAGE_COPY = 0;
+
+ /**
+ * <code>Image</code> constructor argument indicating that
+ * the new image should have the appearance of a "disabled"
+ * (using the platform's rules for how this should look)
+ * copy of the image provided as an argument (value is 1)
+ */
+ public static final int IMAGE_DISABLE = 1;
+
+ /**
+ * <code>Image</code> constructor argument indicating that
+ * the new image should have the appearance of a "gray scaled"
+ * copy of the image provided as an argument (value is 2)
+ */
+ public static final int IMAGE_GRAY = 2;
+
+ /**
+ * font style constant indicating a normal weight, non-italic font
+ * (value is 0)
+ */
+ public static final int NORMAL = 0;
+
+ /**
+ * font style constant indicating a bold weight font
+ * (value is 1&lt;&lt;0)
+ */
+ public static final int BOLD = 1 << 0;
+
+ /**
+ * font style constant indicating an italic font
+ * (value is 1&lt;&lt;1)
+ */
+ public static final int ITALIC = 1 << 1;
+
+ /**
+ * system arrow cursor (value is 0)
+ */
+ public static final int CURSOR_ARROW = 0;
+
+ /**
+ * system wait cursor (value is 1)
+ */
+ public static final int CURSOR_WAIT = 1;
+
+ /**
+ * system cross hair cursor (value is 2)
+ */
+ public static final int CURSOR_CROSS = 2;
+
+ /**
+ * system app startup cursor (value is 3)
+ */
+ public static final int CURSOR_APPSTARTING = 3;
+
+ /**
+ * system help cursor (value is 4)
+ */
+ public static final int CURSOR_HELP = 4;
+
+ /**
+ * system resize all directions cursor (value is 5)
+ */
+ public static final int CURSOR_SIZEALL = 5;
+
+ /**
+ * system resize north-east-south-west cursor (value is 6)
+ */
+ public static final int CURSOR_SIZENESW = 6;
+
+ /**
+ * system resize north-south cursor (value is 7)
+ */
+ public static final int CURSOR_SIZENS = 7;
+
+ /**
+ * system resize north-west-south-east cursor (value is 8)
+ */
+ public static final int CURSOR_SIZENWSE = 8;
+
+ /**
+ * system resize west-east cursor (value is 9)
+ */
+ public static final int CURSOR_SIZEWE = 9;
+
+ /**
+ * system resize north cursor (value is 10)
+ */
+ public static final int CURSOR_SIZEN = 10;
+
+ /**
+ * system resize south cursor (value is 11)
+ */
+ public static final int CURSOR_SIZES = 11;
+
+ /**
+ * system resize east cursor (value is 12)
+ */
+ public static final int CURSOR_SIZEE = 12;
+
+ /**
+ * system resize west cursor (value is 13)
+ */
+ public static final int CURSOR_SIZEW = 13;
+
+ /**
+ * system resize north-east cursor (value is 14)
+ */
+ public static final int CURSOR_SIZENE = 14;
+
+ /**
+ * system resize south-east cursor (value is 15)
+ */
+ public static final int CURSOR_SIZESE = 15;
+
+ /**
+ * system resize south-west cursor (value is 16)
+ */
+ public static final int CURSOR_SIZESW = 16;
+
+ /**
+ * system resize north-west cursor (value is 17)
+ */
+ public static final int CURSOR_SIZENW = 17;
+
+ /**
+ * system up arrow cursor (value is 18)
+ */
+ public static final int CURSOR_UPARROW = 18;
+
+ /**
+ * system i-beam cursor (value is 19)
+ */
+ public static final int CURSOR_IBEAM = 19;
+
+ /**
+ * system "not allowed" cursor (value is 20)
+ */
+ public static final int CURSOR_NO = 20;
+
+ /**
+ * system hand cursor (value is 21)
+ */
+ public static final int CURSOR_HAND = 21;
+
+ /**
+ * line drawing style for solid lines (value is 1)
+ */
+ public static final int LINE_SOLID = 1;
+
+ /**
+ * line drawing style for dashed lines (value is 2)
+ */
+ public static final int LINE_DASH = 2;
+
+ /**
+ * line drawing style for dotted lines (value is 3)
+ */
+ public static final int LINE_DOT = 3;
+
+ /**
+ * line drawing style for alternating dash-dot lines (value is 4)
+ */
+ public static final int LINE_DASHDOT = 4;
+
+ /**
+ * line drawing style for dash-dot-dot lines (value is 5)
+ */
+ public static final int LINE_DASHDOTDOT = 5;
+
+ /**
+ * image format constant indicating an unknown image type (value is -1)
+ */
+ public static final int IMAGE_UNDEFINED = -1;
+
+ /**
+ * image format constant indicating a Windows BMP format image (value is 0)
+ */
+ public static final int IMAGE_BMP = 0;
+
+ /**
+ * image format constant indicating a run-length encoded
+ * Windows BMP format image (value is 1)
+ */
+ public static final int IMAGE_BMP_RLE = 1;
+
+ /**
+ * image format constant indicating a GIF format image (value is 2)
+ */
+ public static final int IMAGE_GIF = 2;
+
+ /**
+ * image format constant indicating a ICO format image (value is 3)
+ */
+ public static final int IMAGE_ICO = 3;
+
+ /**
+ * image format constant indicating a JPEG format image (value is 4)
+ */
+ public static final int IMAGE_JPEG = 4;
+
+ /**
+ * image format constant indicating a PNG format image (value is 5)
+ */
+ public static final int IMAGE_PNG = 5;
+
+ /**
+ * GIF image disposal method constants indicating that the
+ * disposal method is unspecified (value is 0)
+ */
+ public static final int DM_UNSPECIFIED = 0x0;
+
+ /**
+ * GIF image disposal method constants indicating that the
+ * disposal method is to do nothing. That is, to leave the
+ * previous image in place (value is 1)
+ */
+ public static final int DM_FILL_NONE = 0x1;
+
+ /**
+ * GIF image disposal method constants indicating that the
+ * the previous images should be covered with the background
+ * color before displaying the next image (value is 2)
+ */
+ public static final int DM_FILL_BACKGROUND = 0x2;
+
+ /**
+ * GIF image disposal method constants indicating that the
+ * disposal method is to restore the previous picture
+ * (value is 3)
+ */
+ public static final int DM_FILL_PREVIOUS = 0x3;
+
+ /**
+ * image transparency constant indicating that the image
+ * contains no transparency information (value is 0)
+ */
+ public static final int TRANSPARENCY_NONE = 0x0;
+
+ /**
+ * image transparency constant indicating that the image
+ * contains alpha transparency information (value is 1&lt;&lt;0)
+ */
+ public static final int TRANSPARENCY_ALPHA = 1 << 0;
+
+ /**
+ * image transparency constant indicating that the image
+ * contains a transparency mask (value is 1&lt;&lt;1)
+ */
+ public static final int TRANSPARENCY_MASK = 1 << 1;
+
+ /**
+ * image transparency constant indicating that the image
+ * contains a transparent pixel (value is 1&lt;&lt;2)
+ */
+ public static final int TRANSPARENCY_PIXEL = 1 << 2;
+
+/**
+ * Answers a concise, human readable description of the error code.
+ *
+ * @param code the SWT error code.
+ * @return a description of the error code.
+ *
+ * @see SWT
+ */
+static String findErrorText (int code) {
+ switch (code) {
+ case ERROR_UNSPECIFIED: return "Unspecified error";
+ case ERROR_NO_HANDLES: return "No more handles";
+ case ERROR_NO_MORE_CALLBACKS: return "No more callbacks";
+ case ERROR_NULL_ARGUMENT: return "Argument cannot be null";
+ case ERROR_INVALID_ARGUMENT: return "Argument not valid";
+ case ERROR_INVALID_RANGE: return "Index out of bounds";
+ case ERROR_CANNOT_BE_ZERO: return "Argument cannot be zero";
+ case ERROR_CANNOT_GET_ITEM: return "Cannot get item";
+ case ERROR_CANNOT_GET_SELECTION: return "Cannot get selection";
+ case ERROR_CANNOT_GET_ITEM_HEIGHT: return "Cannot get item height";
+ case ERROR_CANNOT_GET_TEXT: return "Cannot get text";
+ case ERROR_CANNOT_SET_TEXT: return "Cannot set text";
+ case ERROR_ITEM_NOT_ADDED: return "Item not added";
+ case ERROR_ITEM_NOT_REMOVED: return "Item not removed";
+ case ERROR_NOT_IMPLEMENTED: return "Not implemented";
+ case ERROR_MENU_NOT_DROP_DOWN: return "Menu must be a drop down";
+ case ERROR_THREAD_INVALID_ACCESS: return "Invalid thread access";
+ case ERROR_WIDGET_DISPOSED: return "Widget is disposed";
+ case ERROR_MENUITEM_NOT_CASCADE: return "Menu item is not a CASCADE";
+ case ERROR_CANNOT_SET_SELECTION: return "Cannot set selection";
+ case ERROR_CANNOT_SET_MENU: return "Cannot set menu";
+ case ERROR_CANNOT_SET_ENABLED: return "Cannot set the enabled state";
+ case ERROR_CANNOT_GET_ENABLED: return "Cannot get the enabled state";
+ case ERROR_INVALID_PARENT: return "Widget has the wrong parent";
+ case ERROR_MENU_NOT_BAR: return "Menu is not a BAR";
+ case ERROR_CANNOT_GET_COUNT: return "Cannot get count";
+ case ERROR_MENU_NOT_POP_UP: return "Menu is not a POP_UP";
+ case ERROR_UNSUPPORTED_DEPTH: return "Unsupported color depth";
+ case ERROR_IO: return "i/o error";
+ case ERROR_INVALID_IMAGE: return "Invalid image";
+ case ERROR_UNSUPPORTED_FORMAT: return "Unsupported or unrecognized format";
+ case ERROR_INVALID_SUBCLASS: return "Subclassing not allowed";
+ case ERROR_GRAPHIC_DISPOSED: return "Graphic is disposed";
+ case ERROR_DEVICE_DISPOSED: return "Device is disposed";
+ case ERROR_FAILED_EXEC: return "Failed to execute runnable";
+ case ERROR_FAILED_LOAD_LIBRARY: return "Unable to load library";
+ }
+ return "Unknown error";
+}
+
+/**
+ * Returns the NLS'ed message for the given argument.
+ *
+ * @param key the key to look up
+ * @return the message for the given key
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
+ * </ul>
+ */
+public static String getMessage(String key) {
+ return Compatibility.getMessage(key);
+}
+
+/**
+ * Returns the SWT platform name.
+ * Examples: "win32", "motif", "gtk", "photon", "carbon"
+ *
+ * @return the SWT platform name
+ */
+public static String getPlatform () {
+ return Callback.getPlatform ();
+}
+
+/**
+ * Returns the SWT version number as an integer.
+ * Example: "SWT051" == 51
+ *
+ * @return the SWT version number
+ */
+public static int getVersion () {
+ return Library.getVersion ();
+}
+
+/**
+ * Throws an appropriate exception based on the passed in error code.
+ *
+ * @param code the SWT error code
+ */
+public static void error (int code) {
+ error (code, null);
+}
+
+/**
+ * Throws an appropriate exception based on the passed in error code.
+ * The <code>throwable</code> argument should be either null, or the
+ * throwable which caused SWT to throw an exception.
+ * <p>
+ * In SWT, errors are reported by throwing one of three exceptions:
+ * <dl>
+ * <dd>java.lang.IllegalArgumentException</dd>
+ * <dt>thrown whenever one of the API methods is invoked with an illegal argument</dt>
+ * <dd>org.eclipse.swt.SWTException (extends java.lang.RuntimeException)</dd>
+ * <dt>thrown whenever a recoverable error happens internally in SWT</dt>
+ * <dd>org.eclipse.swt.SWTError (extends java.lang.Error)</dd>
+ * <dt>thrown whenever a <b>non-recoverable</b> error happens internally in SWT</dt>
+ * </dl>
+ * This method provides the logic which maps between error codes
+ * and one of the above exceptions.
+ * </p>
+ *
+ * @param code the SWT error code.
+ * @param throwable the exception which caused the error to occur.
+ *
+ * @see SWTError
+ * @see SWTException
+ * @see IllegalArgumentException
+ */
+public static void error (int code, Throwable throwable) {
+
+ /*
+ * This code prevents the creation of "chains" of SWTErrors and
+ * SWTExceptions which in turn contain other SWTErrors and
+ * SWTExceptions as their throwable. This can occur when low level
+ * code throws an exception past a point where a higher layer is
+ * being "safe" and catching all exceptions. (Note that, this is
+ * _a_bad_thing_ which we always try to avoid.)
+ *
+ * On the theory that the low level code is closest to the
+ * original problem, we simply re-throw the original exception here.
+ */
+ if (throwable instanceof SWTError) throw (SWTError) throwable;
+ if (throwable instanceof SWTException) throw (SWTException) throwable;
+
+ switch (code) {
+
+ /* Illegal Arguments (non-fatal) */
+ case ERROR_NULL_ARGUMENT:
+ case ERROR_CANNOT_BE_ZERO:
+ case ERROR_INVALID_ARGUMENT:
+ case ERROR_MENU_NOT_BAR:
+ case ERROR_MENU_NOT_DROP_DOWN:
+ case ERROR_MENU_NOT_POP_UP:
+ case ERROR_MENUITEM_NOT_CASCADE:
+ case ERROR_INVALID_PARENT:
+ case ERROR_INVALID_RANGE: {
+ throw new IllegalArgumentException (findErrorText (code));
+ }
+
+ /* SWT Errors (non-fatal) */
+ case ERROR_INVALID_SUBCLASS:
+ case ERROR_THREAD_INVALID_ACCESS:
+ case ERROR_WIDGET_DISPOSED:
+ case ERROR_GRAPHIC_DISPOSED:
+ case ERROR_DEVICE_DISPOSED:
+ case ERROR_INVALID_IMAGE:
+ case ERROR_UNSUPPORTED_DEPTH:
+ case ERROR_UNSUPPORTED_FORMAT:
+ case ERROR_FAILED_EXEC:
+ case ERROR_IO: {
+ SWTException exception = new SWTException (code);
+ exception.throwable = throwable;
+ throw exception;
+ }
+
+ /* OS Failure/Limit (fatal, may occur only on some platforms) */
+ case ERROR_CANNOT_GET_COUNT:
+ case ERROR_CANNOT_GET_ENABLED:
+ case ERROR_CANNOT_GET_ITEM:
+ case ERROR_CANNOT_GET_ITEM_HEIGHT:
+ case ERROR_CANNOT_GET_SELECTION:
+ case ERROR_CANNOT_GET_TEXT:
+ case ERROR_CANNOT_SET_ENABLED:
+ case ERROR_CANNOT_SET_MENU:
+ case ERROR_CANNOT_SET_SELECTION:
+ case ERROR_CANNOT_SET_TEXT:
+ case ERROR_ITEM_NOT_ADDED:
+ case ERROR_ITEM_NOT_REMOVED:
+ case ERROR_NO_HANDLES:
+ //FALL THROUGH
+
+ /* SWT Failure/Limit (fatal, may occur only on some platforms) */
+ case ERROR_FAILED_LOAD_LIBRARY:
+ case ERROR_NO_MORE_CALLBACKS:
+ case ERROR_NOT_IMPLEMENTED:
+ case ERROR_UNSPECIFIED: {
+ SWTError error = new SWTError (code);
+ error.throwable = throwable;
+ throw error;
+ }
+ }
+
+ /* Unknown/Undefined Error */
+ SWTError error = new SWTError (code);
+ error.throwable = throwable;
+ throw error;
+}
+
+static {
+ /*
+ * These values represent bit masks that may need to
+ * expand in the future. Therefore they are not initialized
+ * in the declaration to stop the compiler from inlining.
+ */
+ BUTTON_MASK = BUTTON1 | BUTTON2 | BUTTON3;
+ MODIFIER_MASK = ALT | SHIFT | CTRL | COMMAND;
+
+ /*
+ * These values can be different on different platforms.
+ * Therefore they are not initialized in the declaration
+ * to stop the compiler from inlining.
+ */
+ String platform = getPlatform ();
+ if ("carbon".equals (platform)) {
+ MOD1 = COMMAND;
+ MOD2 = SHIFT;
+ MOD3 = ALT;
+ MOD4 = CONTROL;
+ } else {
+ MOD1 = CONTROL;
+ MOD2 = SHIFT;
+ MOD3 = ALT;
+ MOD4 = ALT;
+ }
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java
index 1aa1b3b730..8e9566168a 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTError.java
@@ -1,113 +1,113 @@
-package org.eclipse.swt;
-
-/*
+package org.eclipse.swt;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * This error is thrown whenever an unrecoverable error
- * occurs internally in SWT. The message text and error code
- * provide a further description of the problem. The exception
- * has a <code>throwable</code> field which holds the underlying
- * throwable that caused the problem (if this information is
- * available (i.e. it may be null)).
- * <p>
- * SWTErrors are thrown when something fails internally which
- * either leaves SWT in an unknown state (eg. the o/s call to
- * remove an item from a list returns an error code) or when SWT
- * is left in a known-to-be-unrecoverable state (eg. it runs out
- * of callback resources). SWTErrors should not occur in typical
- * programs, although "high reliability" applications should
- * still catch them.
- * </p><p>
- * This class also provides support methods used by SWT to match
- * error codes to the appropriate exception class (SWTError,
- * SWTException, or IllegalArgumentException) and to provide
- * human readable strings for SWT error codes.
- * </p>
- *
- * @see SWTException
- * @see SWT#error
- */
-
-public class SWTError extends Error {
- public int code;
- public Throwable throwable;
-
-/**
- * Constructs a new instance of this class with its
- * walkback filled in. The error code is set to an
- * unspecified value.
- */
-public SWTError () {
- this (SWT.ERROR_UNSPECIFIED);
-}
-
-/**
- * Constructs a new instance of this class with its
- * walkback and message filled in. The error code is
- * set to an unspecified value.
- *
- * @param message the detail message for the exception
- */
-public SWTError (String message) {
- this (SWT.ERROR_UNSPECIFIED, message);
-}
-
-/**
- * Constructs a new instance of this class with its
- * walkback and error code filled in.
- *
- * @param code the SWT error code
- */
-public SWTError (int code) {
- this (code, SWT.findErrorText (code));
-}
-
-/**
- * Constructs a new instance of this class with its
- * walkback, error code and message filled in.
- *
- * @param code the SWT error code
- * @param message the detail message for the exception
- */
-public SWTError (int code, String message) {
- super (message);
- this.code = code;
-}
-
-/**
- * Returns the string describing this SWTError object.
- * <p>
- * It is combined with the message string of the Throwable
- * which caused this SWTError (if this information is available).
- * </p>
- * @return the error message string of this SWTError object
- */
-public String getMessage() {
- if (throwable == null)
- return super.getMessage();
- else
- return super.getMessage() + " (" + throwable.toString() + ")";
-}
-
-/**
- * Outputs a printable representation of this error's
- * walkback on the standard error stream.
- * <p>
- * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
- * are not provided in order to maintain compatibility with CLDC.
- * </p>
- */
-public synchronized void printStackTrace() {
- super.printStackTrace();
- if (throwable != null) {
- System.err.println("*** Stack trace of contained error ***");
- throwable.printStackTrace();
- }
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * This error is thrown whenever an unrecoverable error
+ * occurs internally in SWT. The message text and error code
+ * provide a further description of the problem. The exception
+ * has a <code>throwable</code> field which holds the underlying
+ * throwable that caused the problem (if this information is
+ * available (i.e. it may be null)).
+ * <p>
+ * SWTErrors are thrown when something fails internally which
+ * either leaves SWT in an unknown state (eg. the o/s call to
+ * remove an item from a list returns an error code) or when SWT
+ * is left in a known-to-be-unrecoverable state (eg. it runs out
+ * of callback resources). SWTErrors should not occur in typical
+ * programs, although "high reliability" applications should
+ * still catch them.
+ * </p><p>
+ * This class also provides support methods used by SWT to match
+ * error codes to the appropriate exception class (SWTError,
+ * SWTException, or IllegalArgumentException) and to provide
+ * human readable strings for SWT error codes.
+ * </p>
+ *
+ * @see SWTException
+ * @see SWT#error
+ */
+
+public class SWTError extends Error {
+ public int code;
+ public Throwable throwable;
+
+/**
+ * Constructs a new instance of this class with its
+ * walkback filled in. The error code is set to an
+ * unspecified value.
+ */
+public SWTError () {
+ this (SWT.ERROR_UNSPECIFIED);
+}
+
+/**
+ * Constructs a new instance of this class with its
+ * walkback and message filled in. The error code is
+ * set to an unspecified value.
+ *
+ * @param message the detail message for the exception
+ */
+public SWTError (String message) {
+ this (SWT.ERROR_UNSPECIFIED, message);
+}
+
+/**
+ * Constructs a new instance of this class with its
+ * walkback and error code filled in.
+ *
+ * @param code the SWT error code
+ */
+public SWTError (int code) {
+ this (code, SWT.findErrorText (code));
+}
+
+/**
+ * Constructs a new instance of this class with its
+ * walkback, error code and message filled in.
+ *
+ * @param code the SWT error code
+ * @param message the detail message for the exception
+ */
+public SWTError (int code, String message) {
+ super (message);
+ this.code = code;
+}
+
+/**
+ * Returns the string describing this SWTError object.
+ * <p>
+ * It is combined with the message string of the Throwable
+ * which caused this SWTError (if this information is available).
+ * </p>
+ * @return the error message string of this SWTError object
+ */
+public String getMessage() {
+ if (throwable == null)
+ return super.getMessage();
+ else
+ return super.getMessage() + " (" + throwable.toString() + ")";
+}
+
+/**
+ * Outputs a printable representation of this error's
+ * walkback on the standard error stream.
+ * <p>
+ * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
+ * are not provided in order to maintain compatibility with CLDC.
+ * </p>
+ */
+public synchronized void printStackTrace() {
+ super.printStackTrace();
+ if (throwable != null) {
+ System.err.println("*** Stack trace of contained error ***");
+ throwable.printStackTrace();
+ }
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java
index 74c76f6d41..674a6dd40a 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWTException.java
@@ -1,106 +1,106 @@
-package org.eclipse.swt;
-
-/*
+package org.eclipse.swt;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * This runtime exception is thrown whenever a recoverable error
- * occurs internally in SWT. The message text and error code
- * provide a further description of the problem. The exception
- * has a <code>throwable</code> field which holds the underlying
- * exception that caused the problem (if this information is
- * available (i.e. it may be null)).
- * <p>
- * SWTExceptions are thrown when something fails internally,
- * but SWT is left in a known stable state (eg. a widget call
- * was made from a non-u/i thread, or there is failure while
- * reading an Image because the source file was corrupt).
- * </p>
- *
- * @see SWTError
- */
-
-public class SWTException extends RuntimeException {
- public int code;
- public Throwable throwable;
-
-/**
- * Constructs a new instance of this class with its
- * walkback filled in. The error code is set to an
- * unspecified value.
- */
-public SWTException () {
- this (SWT.ERROR_UNSPECIFIED);
-}
-
-/**
- * Constructs a new instance of this class with its
- * walkback and message filled in. The error code is
- * set to an unspecified value.
- *
- * @param message the detail message for the exception
- */
-public SWTException (String message) {
- this (SWT.ERROR_UNSPECIFIED, message);
-}
-
-/**
- * Constructs a new instance of this class with its
- * walkback and error code filled in.
- *
- * @param code the SWT error code
- */
-public SWTException (int code) {
- this (code, SWT.findErrorText (code));
-}
-
-/**
- * Constructs a new instance of this class with its
- * walkback, error code and message filled in.
- *
- * @param code the SWT error code
- * @param message the detail message for the exception
- */
-public SWTException (int code, String message) {
- super (message);
- this.code = code;
-}
-
-/**
- * Returns the string describing this SWTException object.
- * <p>
- * It is combined with the message string of the Throwable
- * which caused this SWTException (if this information is available).
- * </p>
- * @return the error message string of this SWTException object
- */
-public String getMessage() {
- if (throwable == null)
- return super.getMessage();
- else
- return super.getMessage() + " (" + throwable.toString() + ")";
-}
-
-/**
- * Outputs a printable representation of this exception's
- * walkback on the standard error stream.
- * <p>
- * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
- * are not provided in order to maintain compatibility with CLDC.
- * </p>
- */
-public void printStackTrace() {
- super.printStackTrace();
- if (throwable != null) {
- System.err.println("*** Stack trace of contained exception ***");
- throwable.printStackTrace();
- }
-}
-
-}
-
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * This runtime exception is thrown whenever a recoverable error
+ * occurs internally in SWT. The message text and error code
+ * provide a further description of the problem. The exception
+ * has a <code>throwable</code> field which holds the underlying
+ * exception that caused the problem (if this information is
+ * available (i.e. it may be null)).
+ * <p>
+ * SWTExceptions are thrown when something fails internally,
+ * but SWT is left in a known stable state (eg. a widget call
+ * was made from a non-u/i thread, or there is failure while
+ * reading an Image because the source file was corrupt).
+ * </p>
+ *
+ * @see SWTError
+ */
+
+public class SWTException extends RuntimeException {
+ public int code;
+ public Throwable throwable;
+
+/**
+ * Constructs a new instance of this class with its
+ * walkback filled in. The error code is set to an
+ * unspecified value.
+ */
+public SWTException () {
+ this (SWT.ERROR_UNSPECIFIED);
+}
+
+/**
+ * Constructs a new instance of this class with its
+ * walkback and message filled in. The error code is
+ * set to an unspecified value.
+ *
+ * @param message the detail message for the exception
+ */
+public SWTException (String message) {
+ this (SWT.ERROR_UNSPECIFIED, message);
+}
+
+/**
+ * Constructs a new instance of this class with its
+ * walkback and error code filled in.
+ *
+ * @param code the SWT error code
+ */
+public SWTException (int code) {
+ this (code, SWT.findErrorText (code));
+}
+
+/**
+ * Constructs a new instance of this class with its
+ * walkback, error code and message filled in.
+ *
+ * @param code the SWT error code
+ * @param message the detail message for the exception
+ */
+public SWTException (int code, String message) {
+ super (message);
+ this.code = code;
+}
+
+/**
+ * Returns the string describing this SWTException object.
+ * <p>
+ * It is combined with the message string of the Throwable
+ * which caused this SWTException (if this information is available).
+ * </p>
+ * @return the error message string of this SWTException object
+ */
+public String getMessage() {
+ if (throwable == null)
+ return super.getMessage();
+ else
+ return super.getMessage() + " (" + throwable.toString() + ")";
+}
+
+/**
+ * Outputs a printable representation of this exception's
+ * walkback on the standard error stream.
+ * <p>
+ * Note: printStackTrace(PrintStream) and printStackTrace(PrintWriter)
+ * are not provided in order to maintain compatibility with CLDC.
+ * </p>
+ */
+public void printStackTrace() {
+ super.printStackTrace();
+ if (throwable != null) {
+ System.err.println("*** Stack trace of contained exception ***");
+ throwable.printStackTrace();
+ }
+}
+
+}
+
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java
index df645735e1..f16bf68834 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmEvent.java
@@ -1,31 +1,31 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * a widget such as a menu item being armed.
- *
- * @see ArmListener
- */
-
-public final class ArmEvent extends TypedEvent {
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public ArmEvent(Event e) {
- super(e);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent as a result of
+ * a widget such as a menu item being armed.
+ *
+ * @see ArmListener
+ */
+
+public final class ArmEvent extends TypedEvent {
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public ArmEvent(Event e) {
+ super(e);
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java
index 8df5ab46cc..73b6df6b58 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ArmListener.java
@@ -1,34 +1,34 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the event that is generated when a widget,
- * such as a menu item, is armed.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a widget using the
- * <code>addArmListener</code> method and removed using
- * the <code>removeArmListener</code> method. When the
- * widget is armed, the widgetArmed method will be invoked.
- * </p>
- *
- * @see ArmEvent
- */
-public interface ArmListener extends SWTEventListener {
-
-/**
- * Sent when a widget is armed, or 'about to be selected'.
- *
- * @param e an event containing information about the arm
- */
-public void widgetArmed(ArmEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide a method
+ * that deals with the event that is generated when a widget,
+ * such as a menu item, is armed.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a widget using the
+ * <code>addArmListener</code> method and removed using
+ * the <code>removeArmListener</code> method. When the
+ * widget is armed, the widgetArmed method will be invoked.
+ * </p>
+ *
+ * @see ArmEvent
+ */
+public interface ArmListener extends SWTEventListener {
+
+/**
+ * Sent when a widget is armed, or 'about to be selected'.
+ *
+ * @param e an event containing information about the arm
+ */
+public void widgetArmed(ArmEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java
index 2edaedd813..502a130841 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java
@@ -1,42 +1,42 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>ControlListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>ControlEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see ControlListener
- * @see ControlEvent
- */
-public abstract class ControlAdapter implements ControlListener {
-
-/**
- * Sent when the location (x, y) of a control changes relative
- * to its parent (or relative to the display, for <code>Shell</code>s).
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the move
- */
-public void controlMoved(ControlEvent e) {
-}
-
-/**
- * Sent when the size (width, height) of a control changes.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the resize
- */
-public void controlResized(ControlEvent e) {
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * This adapter class provides default implementations for the
+ * methods described by the <code>ControlListener</code> interface.
+ * <p>
+ * Classes that wish to deal with <code>ControlEvent</code>s can
+ * extend this class and override only the methods which they are
+ * interested in.
+ * </p>
+ *
+ * @see ControlListener
+ * @see ControlEvent
+ */
+public abstract class ControlAdapter implements ControlListener {
+
+/**
+ * Sent when the location (x, y) of a control changes relative
+ * to its parent (or relative to the display, for <code>Shell</code>s).
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the move
+ */
+public void controlMoved(ControlEvent e) {
+}
+
+/**
+ * Sent when the size (width, height) of a control changes.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the resize
+ */
+public void controlResized(ControlEvent e) {
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java
index 6dde2b2614..84934d83a7 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlEvent.java
@@ -1,33 +1,33 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * controls being moved or resized.
- *
- * @see ControlListener
- */
-
-public final class ControlEvent extends TypedEvent {
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public ControlEvent(Event e) {
- super(e);
-}
-
-}
-
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent as a result of
+ * controls being moved or resized.
+ *
+ * @see ControlListener
+ */
+
+public final class ControlEvent extends TypedEvent {
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public ControlEvent(Event e) {
+ super(e);
+}
+
+}
+
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java
index fc44d77263..46679df5d8 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java
@@ -1,44 +1,44 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated by moving
- * and resizing controls.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addControlListener</code> method and removed using
- * the <code>removeControlListener</code> method. When a
- * control is moved or resized, the appropriate method will
- * be invoked.
- * </p>
- *
- * @see ControlAdapter
- * @see ControlEvent
- */
-public interface ControlListener extends SWTEventListener {
-
-/**
- * Sent when the location (x, y) of a control changes relative
- * to its parent (or relative to the display, for <code>Shell</code>s).
- *
- * @param e an event containing information about the move
- */
-public void controlMoved(ControlEvent e);
-
-/**
- * Sent when the size (width, height) of a control changes.
- *
- * @param e an event containing information about the resize
- */
-public void controlResized(ControlEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the events that are generated by moving
+ * and resizing controls.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addControlListener</code> method and removed using
+ * the <code>removeControlListener</code> method. When a
+ * control is moved or resized, the appropriate method will
+ * be invoked.
+ * </p>
+ *
+ * @see ControlAdapter
+ * @see ControlEvent
+ */
+public interface ControlListener extends SWTEventListener {
+
+/**
+ * Sent when the location (x, y) of a control changes relative
+ * to its parent (or relative to the display, for <code>Shell</code>s).
+ *
+ * @param e an event containing information about the move
+ */
+public void controlMoved(ControlEvent e);
+
+/**
+ * Sent when the size (width, height) of a control changes.
+ *
+ * @param e an event containing information about the resize
+ */
+public void controlResized(ControlEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java
index 28db666b51..9fcf3dfb02 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeEvent.java
@@ -1,32 +1,32 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * widgets being disposed.
- *
- * @see DisposeListener
- */
-
-public final class DisposeEvent extends TypedEvent {
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public DisposeEvent(Event e) {
- super(e);
-}
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent as a result of
+ * widgets being disposed.
+ *
+ * @see DisposeListener
+ */
+
+public final class DisposeEvent extends TypedEvent {
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public DisposeEvent(Event e) {
+ super(e);
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java
index 1cc032f89b..cb381854e6 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/DisposeListener.java
@@ -1,35 +1,35 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the event that is generated when a widget
- * is disposed.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a widget using the
- * <code>addDisposeListener</code> method and removed using
- * the <code>removeDisposeListener</code> method. When a
- * widget is disposed, the widgetDisposed method will
- * be invoked.
- * </p>
- *
- * @see DisposeEvent
- */
-public interface DisposeListener extends SWTEventListener {
-
-/**
- * Sent when the widget is disposed.
- *
- * @param e an event containing information about the dispose
- */
-public void widgetDisposed(DisposeEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide a method
+ * that deals with the event that is generated when a widget
+ * is disposed.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a widget using the
+ * <code>addDisposeListener</code> method and removed using
+ * the <code>removeDisposeListener</code> method. When a
+ * widget is disposed, the widgetDisposed method will
+ * be invoked.
+ * </p>
+ *
+ * @see DisposeEvent
+ */
+public interface DisposeListener extends SWTEventListener {
+
+/**
+ * Sent when the widget is disposed.
+ *
+ * @param e an event containing information about the dispose
+ */
+public void widgetDisposed(DisposeEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java
index 309480e9da..520689571e 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusAdapter.java
@@ -1,41 +1,41 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>FocusListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>FocusEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see FocusListener
- * @see FocusEvent
- */
-public abstract class FocusAdapter implements FocusListener {
-
-/**
- * Sent when a control gets focus.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the focus change
- */
-public void focusGained(FocusEvent e) {
-}
-
-/**
- * Sent when a control loses focus.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the focus change
- */
-public void focusLost(FocusEvent e) {
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * This adapter class provides default implementations for the
+ * methods described by the <code>FocusListener</code> interface.
+ * <p>
+ * Classes that wish to deal with <code>FocusEvent</code>s can
+ * extend this class and override only the methods which they are
+ * interested in.
+ * </p>
+ *
+ * @see FocusListener
+ * @see FocusEvent
+ */
+public abstract class FocusAdapter implements FocusListener {
+
+/**
+ * Sent when a control gets focus.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the focus change
+ */
+public void focusGained(FocusEvent e) {
+}
+
+/**
+ * Sent when a control loses focus.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the focus change
+ */
+public void focusLost(FocusEvent e) {
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java
index 5dc9227e09..66fba93a51 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusEvent.java
@@ -1,32 +1,32 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * widgets gaining and losing focus.
- *
- * @see FocusListener
- */
-
-public final class FocusEvent extends TypedEvent {
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public FocusEvent(Event e) {
- super(e);
-}
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent as a result of
+ * widgets gaining and losing focus.
+ *
+ * @see FocusListener
+ */
+
+public final class FocusEvent extends TypedEvent {
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public FocusEvent(Event e) {
+ super(e);
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java
index 75bb0c3692..74250720a6 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/FocusListener.java
@@ -1,44 +1,44 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated as controls
- * gain and lose focus.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addFocusListener</code> method and removed using
- * the <code>removeFocusListener</code> method. When a
- * control gains or loses focus, the appropriate method
- * will be invoked.
- * </p>
- *
- * @see FocusAdapter
- * @see FocusEvent
- */
-public interface FocusListener extends SWTEventListener {
-
-/**
- * Sent when a control gets focus.
- *
- * @param e an event containing information about the focus change
- */
-public void focusGained(FocusEvent e);
-
-/**
- * Sent when a control loses focus.
- *
- * @param e an event containing information about the focus change
- */
-public void focusLost(FocusEvent e);
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the events that are generated as controls
+ * gain and lose focus.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addFocusListener</code> method and removed using
+ * the <code>removeFocusListener</code> method. When a
+ * control gains or loses focus, the appropriate method
+ * will be invoked.
+ * </p>
+ *
+ * @see FocusAdapter
+ * @see FocusEvent
+ */
+public interface FocusListener extends SWTEventListener {
+
+/**
+ * Sent when a control gets focus.
+ *
+ * @param e an event containing information about the focus change
+ */
+public void focusGained(FocusEvent e);
+
+/**
+ * Sent when a control loses focus.
+ *
+ * @param e an event containing information about the focus change
+ */
+public void focusLost(FocusEvent e);
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java
index bbce9429f3..3fbb3e793a 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpEvent.java
@@ -1,32 +1,32 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * help being requested for a widget.
- *
- * @see HelpListener
- */
-
-public final class HelpEvent extends TypedEvent {
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public HelpEvent(Event e) {
- super(e);
-}
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent as a result of
+ * help being requested for a widget.
+ *
+ * @see HelpListener
+ */
+
+public final class HelpEvent extends TypedEvent {
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public HelpEvent(Event e) {
+ super(e);
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java
index b1c6c6f8d1..0a301522c4 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/HelpListener.java
@@ -1,36 +1,36 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the event that is generated when help is
- * requested for a control, typically when the user presses F1.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addHelpListener</code> method and removed using
- * the <code>removeHelpListener</code> method. When help
- * is requested for a control, the helpRequested method
- * will be invoked.
- * </p>
- *
- * @see HelpEvent
- */
-public interface HelpListener extends SWTEventListener {
-
-/**
- * Sent when help is requested for a control, typically
- * when the user presses F1.
- *
- * @param e an event containing information about the help
- */
-public void helpRequested(HelpEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide a method
+ * that deals with the event that is generated when help is
+ * requested for a control, typically when the user presses F1.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addHelpListener</code> method and removed using
+ * the <code>removeHelpListener</code> method. When help
+ * is requested for a control, the helpRequested method
+ * will be invoked.
+ * </p>
+ *
+ * @see HelpEvent
+ */
+public interface HelpListener extends SWTEventListener {
+
+/**
+ * Sent when help is requested for a control, typically
+ * when the user presses F1.
+ *
+ * @param e an event containing information about the help
+ */
+public void helpRequested(HelpEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java
index daeba33f89..2cbc44a3a0 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyAdapter.java
@@ -1,41 +1,41 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>KeyListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>KeyEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see KeyListener
- * @see KeyEvent
- */
-public abstract class KeyAdapter implements KeyListener {
-
-/**
- * Sent when a key is pressed on the system keyboard.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the key press
- */
-public void keyPressed(KeyEvent e) {
-}
-
-/**
- * Sent when a key is released on the system keyboard.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the key release
- */
-public void keyReleased(KeyEvent e) {
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * This adapter class provides default implementations for the
+ * methods described by the <code>KeyListener</code> interface.
+ * <p>
+ * Classes that wish to deal with <code>KeyEvent</code>s can
+ * extend this class and override only the methods which they are
+ * interested in.
+ * </p>
+ *
+ * @see KeyListener
+ * @see KeyEvent
+ */
+public abstract class KeyAdapter implements KeyListener {
+
+/**
+ * Sent when a key is pressed on the system keyboard.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the key press
+ */
+public void keyPressed(KeyEvent e) {
+}
+
+/**
+ * Sent when a key is released on the system keyboard.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the key release
+ */
+public void keyReleased(KeyEvent e) {
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java
index 8142831776..8415afffed 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyEvent.java
@@ -1,62 +1,62 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * keys being pressed and released on the keyboard
- *
- * @see KeyListener
- */
-
-public class KeyEvent extends TypedEvent {
-
- /**
- * the character represented by the key that was typed.
- * This is the final character that results after all modifiers have been
- * applied. For example, when the user types Ctrl+A, the character value
- * is 0x01 (NUL). It is important that applications do not attempt to modify
- * the character value based on a stateMask (such as SWT.CTRL) or the resulting
- * character will not be correct.
- */
- public char character;
-
- /**
- * the key code of the key that was typed,
- * as defined by the key code constants in class <code>SWT</code>.
- * When the character field of the event is ambiguous, this field
- * contains the unicode value of the original character. For example,
- * typing Ctrl+M or Return both result in the character '\r' but the
- * keyCode field will also contain '\r' when Return was typed.
- *
- * @see SWT
- */
- public int keyCode;
-
- /**
- * the state of the keyboard modifier keys at the time
- * the event was generated
- */
- public int stateMask;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public KeyEvent(Event e) {
- super(e);
- this.character = e.character;
- this.keyCode = e.keyCode;
- this.stateMask = e.stateMask;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent as a result of
+ * keys being pressed and released on the keyboard
+ *
+ * @see KeyListener
+ */
+
+public class KeyEvent extends TypedEvent {
+
+ /**
+ * the character represented by the key that was typed.
+ * This is the final character that results after all modifiers have been
+ * applied. For example, when the user types Ctrl+A, the character value
+ * is 0x01 (NUL). It is important that applications do not attempt to modify
+ * the character value based on a stateMask (such as SWT.CTRL) or the resulting
+ * character will not be correct.
+ */
+ public char character;
+
+ /**
+ * the key code of the key that was typed,
+ * as defined by the key code constants in class <code>SWT</code>.
+ * When the character field of the event is ambiguous, this field
+ * contains the unicode value of the original character. For example,
+ * typing Ctrl+M or Return both result in the character '\r' but the
+ * keyCode field will also contain '\r' when Return was typed.
+ *
+ * @see SWT
+ */
+ public int keyCode;
+
+ /**
+ * the state of the keyboard modifier keys at the time
+ * the event was generated
+ */
+ public int stateMask;
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public KeyEvent(Event e) {
+ super(e);
+ this.character = e.character;
+ this.keyCode = e.keyCode;
+ this.stateMask = e.stateMask;
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java
index 4e8270a9b5..61315d5536 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/KeyListener.java
@@ -1,43 +1,43 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated as keys
- * are pressed on the system keyboard.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addKeyListener</code> method and removed using
- * the <code>removeKeyListener</code> method. When a
- * key is pressed or released, the appropriate method will
- * be invoked.
- * </p>
- *
- * @see KeyAdapter
- * @see KeyEvent
- */
-public interface KeyListener extends SWTEventListener {
-
-/**
- * Sent when a key is pressed on the system keyboard.
- *
- * @param e an event containing information about the key press
- */
-public void keyPressed(KeyEvent e);
-
-/**
- * Sent when a key is released on the system keyboard.
- *
- * @param e an event containing information about the key release
- */
-public void keyReleased(KeyEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the events that are generated as keys
+ * are pressed on the system keyboard.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addKeyListener</code> method and removed using
+ * the <code>removeKeyListener</code> method. When a
+ * key is pressed or released, the appropriate method will
+ * be invoked.
+ * </p>
+ *
+ * @see KeyAdapter
+ * @see KeyEvent
+ */
+public interface KeyListener extends SWTEventListener {
+
+/**
+ * Sent when a key is pressed on the system keyboard.
+ *
+ * @param e an event containing information about the key press
+ */
+public void keyPressed(KeyEvent e);
+
+/**
+ * Sent when a key is released on the system keyboard.
+ *
+ * @param e an event containing information about the key release
+ */
+public void keyReleased(KeyEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java
index 209a35353b..e089640377 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java
@@ -1,41 +1,41 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>MenuListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>MenuEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see MenuListener
- * @see MenuEvent
- */
-public abstract class MenuAdapter implements MenuListener {
-
-/**
- * Sent when a menu is hidden.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the menu operation
- */
-public void menuHidden(MenuEvent e) {
-}
-
-/**
- * Sent when a menu is shown.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the menu operation
- */
-public void menuShown(MenuEvent e) {
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * This adapter class provides default implementations for the
+ * methods described by the <code>MenuListener</code> interface.
+ * <p>
+ * Classes that wish to deal with <code>MenuEvent</code>s can
+ * extend this class and override only the methods which they are
+ * interested in.
+ * </p>
+ *
+ * @see MenuListener
+ * @see MenuEvent
+ */
+public abstract class MenuAdapter implements MenuListener {
+
+/**
+ * Sent when a menu is hidden.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the menu operation
+ */
+public void menuHidden(MenuEvent e) {
+}
+
+/**
+ * Sent when a menu is shown.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the menu operation
+ */
+public void menuShown(MenuEvent e) {
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java
index 4f4878e5cd..1a836492ed 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuEvent.java
@@ -1,32 +1,32 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * menus being shown and hidden.
- *
- * @see MenuListener
- */
-
-public final class MenuEvent extends TypedEvent {
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public MenuEvent(Event e) {
- super(e);
-}
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent as a result of
+ * menus being shown and hidden.
+ *
+ * @see MenuListener
+ */
+
+public final class MenuEvent extends TypedEvent {
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public MenuEvent(Event e) {
+ super(e);
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java
index 6dab527839..ae53b2ce09 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java
@@ -1,42 +1,42 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the hiding and showing of menus.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addMenuListener</code> method and removed using
- * the <code>removeMenuListener</code> method. When a
- * menu is hidden or shown, the appropriate method will
- * be invoked.
- * </p>
- *
- * @see MenuAdapter
- * @see MenuEvent
- */
-public interface MenuListener extends SWTEventListener {
-
-/**
- * Sent when a menu is hidden.
- *
- * @param e an event containing information about the menu operation
- */
-public void menuHidden(MenuEvent e);
-
-/**
- * Sent when a menu is shown.
- *
- * @param e an event containing information about the menu operation
- */
-public void menuShown(MenuEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the hiding and showing of menus.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addMenuListener</code> method and removed using
+ * the <code>removeMenuListener</code> method. When a
+ * menu is hidden or shown, the appropriate method will
+ * be invoked.
+ * </p>
+ *
+ * @see MenuAdapter
+ * @see MenuEvent
+ */
+public interface MenuListener extends SWTEventListener {
+
+/**
+ * Sent when a menu is hidden.
+ *
+ * @param e an event containing information about the menu operation
+ */
+public void menuHidden(MenuEvent e);
+
+/**
+ * Sent when a menu is shown.
+ *
+ * @param e an event containing information about the menu operation
+ */
+public void menuShown(MenuEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java
index 35c2637318..11f3575ed4 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyEvent.java
@@ -1,32 +1,32 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * text being modified.
- *
- * @see ModifyListener
- */
-
-public final class ModifyEvent extends TypedEvent {
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public ModifyEvent(Event e) {
- super(e);
-}
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent as a result of
+ * text being modified.
+ *
+ * @see ModifyListener
+ */
+
+public final class ModifyEvent extends TypedEvent {
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public ModifyEvent(Event e) {
+ super(e);
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java
index a32f26e7c0..440b19e99b 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ModifyListener.java
@@ -1,34 +1,34 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the events that are generated when text
- * is modified.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a text widget using the
- * <code>addModifyListener</code> method and removed using
- * the <code>removeModifyListener</code> method. When the
- * text is modified, the modifyText method will be invoked.
- * </p>
- *
- * @see ModifyEvent
- */
-public interface ModifyListener extends SWTEventListener {
-
-/**
- * Sent when the text is modified.
- *
- * @param e an event containing information about the modify
- */
-public void modifyText(ModifyEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide a method
+ * that deals with the events that are generated when text
+ * is modified.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a text widget using the
+ * <code>addModifyListener</code> method and removed using
+ * the <code>removeModifyListener</code> method. When the
+ * text is modified, the modifyText method will be invoked.
+ * </p>
+ *
+ * @see ModifyEvent
+ */
+public interface ModifyListener extends SWTEventListener {
+
+/**
+ * Sent when the text is modified.
+ *
+ * @param e an event containing information about the modify
+ */
+public void modifyText(ModifyEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java
index 9ba388ea78..7f6bea71db 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseAdapter.java
@@ -1,54 +1,54 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>MouseListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>MouseEvent</code>s
- * which occur as mouse buttons are pressed and released can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see MouseListener
- * @see MouseEvent
- */
-public abstract class MouseAdapter implements MouseListener {
-
-/**
- * Sent when a mouse button is pressed twice within the
- * (operating system specified) double click period.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the mouse double click
- *
- * @see org.eclipse.swt.widgets.Display#getDoubleClickTime
- */
-public void mouseDoubleClick(MouseEvent e) {
-}
-
-/**
- * Sent when a mouse button is pressed.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the mouse button press
- */
-public void mouseDown(MouseEvent e) {
-}
-
-/**
- * Sent when a mouse button is released.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the mouse button release
- */
-public void mouseUp(MouseEvent e) {
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * This adapter class provides default implementations for the
+ * methods described by the <code>MouseListener</code> interface.
+ * <p>
+ * Classes that wish to deal with <code>MouseEvent</code>s
+ * which occur as mouse buttons are pressed and released can
+ * extend this class and override only the methods which they are
+ * interested in.
+ * </p>
+ *
+ * @see MouseListener
+ * @see MouseEvent
+ */
+public abstract class MouseAdapter implements MouseListener {
+
+/**
+ * Sent when a mouse button is pressed twice within the
+ * (operating system specified) double click period.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the mouse double click
+ *
+ * @see org.eclipse.swt.widgets.Display#getDoubleClickTime
+ */
+public void mouseDoubleClick(MouseEvent e) {
+}
+
+/**
+ * Sent when a mouse button is pressed.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the mouse button press
+ */
+public void mouseDown(MouseEvent e) {
+}
+
+/**
+ * Sent when a mouse button is released.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the mouse button release
+ */
+public void mouseUp(MouseEvent e) {
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java
index a4b6c71ba1..b03ef7a048 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseEvent.java
@@ -1,70 +1,70 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent whenever mouse
- * related actions occur. This includes mouse buttons
- * being pressed and released, the mouse pointer being
- * moved and the mouse pointer crossing widget boundaries.
- * <p>
- * Note: The <code>button</code> field is an integer that
- * represents the mouse button number. This is not the same
- * as the <code>SWT</code> mask constants <code>BUTTONx</code>.
- * </p>
- *
- * @see MouseListener
- * @see MouseMoveListener
- * @see MouseTrackListener
- */
-
-public final class MouseEvent extends TypedEvent {
-
- /**
- * the button that was pressed or released; 1 for the
- * first button, 2 for the second button, and 3 for the
- * third button, etc.
- */
- public int button;
-
- /**
- * the state of the keyboard modifier keys at the time
- * the event was generated
- */
- public int stateMask;
-
- /**
- * the widget-relative, x coordinate of the pointer
- * at the time the mouse button was pressed or released
- */
- public int x;
-
- /**
- * the widget-relative, y coordinate of the pointer
- * at the time the mouse button was pressed or released
- */
- public int y;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public MouseEvent(Event e) {
- super(e);
- this.x = e.x;
- this.y = e.y;
- this.button = e.button;
- this.stateMask = e.stateMask;
-}
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent whenever mouse
+ * related actions occur. This includes mouse buttons
+ * being pressed and released, the mouse pointer being
+ * moved and the mouse pointer crossing widget boundaries.
+ * <p>
+ * Note: The <code>button</code> field is an integer that
+ * represents the mouse button number. This is not the same
+ * as the <code>SWT</code> mask constants <code>BUTTONx</code>.
+ * </p>
+ *
+ * @see MouseListener
+ * @see MouseMoveListener
+ * @see MouseTrackListener
+ */
+
+public final class MouseEvent extends TypedEvent {
+
+ /**
+ * the button that was pressed or released; 1 for the
+ * first button, 2 for the second button, and 3 for the
+ * third button, etc.
+ */
+ public int button;
+
+ /**
+ * the state of the keyboard modifier keys at the time
+ * the event was generated
+ */
+ public int stateMask;
+
+ /**
+ * the widget-relative, x coordinate of the pointer
+ * at the time the mouse button was pressed or released
+ */
+ public int x;
+
+ /**
+ * the widget-relative, y coordinate of the pointer
+ * at the time the mouse button was pressed or released
+ */
+ public int y;
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public MouseEvent(Event e) {
+ super(e);
+ this.x = e.x;
+ this.y = e.y;
+ this.button = e.button;
+ this.stateMask = e.stateMask;
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java
index 704d58e1ff..35170ccd2e 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseListener.java
@@ -1,53 +1,53 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated as mouse buttons
- * are pressed.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addMouseListener</code> method and removed using
- * the <code>removeMouseListener</code> method. When a
- * mouse button is pressed or released, the appropriate method
- * will be invoked.
- * </p>
- *
- * @see MouseAdapter
- * @see MouseEvent
- */
-public interface MouseListener extends SWTEventListener {
-
-/**
- * Sent when a mouse button is pressed twice within the
- * (operating system specified) double click period.
- *
- * @param e an event containing information about the mouse double click
- *
- * @see org.eclipse.swt.widgets.Display#getDoubleClickTime
- */
-public void mouseDoubleClick(MouseEvent e);
-
-/**
- * Sent when a mouse button is pressed.
- *
- * @param e an event containing information about the mouse button press
- */
-public void mouseDown(MouseEvent e);
-
-/**
- * Sent when a mouse button is released.
- *
- * @param e an event containing information about the mouse button release
- */
-public void mouseUp(MouseEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the events that are generated as mouse buttons
+ * are pressed.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addMouseListener</code> method and removed using
+ * the <code>removeMouseListener</code> method. When a
+ * mouse button is pressed or released, the appropriate method
+ * will be invoked.
+ * </p>
+ *
+ * @see MouseAdapter
+ * @see MouseEvent
+ */
+public interface MouseListener extends SWTEventListener {
+
+/**
+ * Sent when a mouse button is pressed twice within the
+ * (operating system specified) double click period.
+ *
+ * @param e an event containing information about the mouse double click
+ *
+ * @see org.eclipse.swt.widgets.Display#getDoubleClickTime
+ */
+public void mouseDoubleClick(MouseEvent e);
+
+/**
+ * Sent when a mouse button is pressed.
+ *
+ * @param e an event containing information about the mouse button press
+ */
+public void mouseDown(MouseEvent e);
+
+/**
+ * Sent when a mouse button is released.
+ *
+ * @param e an event containing information about the mouse button release
+ */
+public void mouseUp(MouseEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java
index a1338afa50..838057ceb4 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseMoveListener.java
@@ -1,34 +1,34 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the events that are generated as the mouse
- * pointer moves.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addMouseMoveListener</code> method and removed using
- * the <code>removeMouseMoveListener</code> method. As the
- * mouse moves, the mouseMove method will be invoked.
- * </p>
- *
- * @see MouseEvent
- */
-public interface MouseMoveListener extends SWTEventListener {
-
-/**
- * Sent when the mouse moves.
- *
- * @param e an event containing information about the mouse move
- */
-public void mouseMove(MouseEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide a method
+ * that deals with the events that are generated as the mouse
+ * pointer moves.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addMouseMoveListener</code> method and removed using
+ * the <code>removeMouseMoveListener</code> method. As the
+ * mouse moves, the mouseMove method will be invoked.
+ * </p>
+ *
+ * @see MouseEvent
+ */
+public interface MouseMoveListener extends SWTEventListener {
+
+/**
+ * Sent when the mouse moves.
+ *
+ * @param e an event containing information about the mouse move
+ */
+public void mouseMove(MouseEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java
index 172ff0f66c..1b5cbae896 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackAdapter.java
@@ -1,55 +1,55 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>MouseTrackListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>MouseEvent</code>s which
- * occur as the mouse pointer passes (or hovers) over controls can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see MouseTrackListener
- * @see MouseEvent
- */
-public class MouseTrackAdapter implements MouseTrackListener {
-
-/**
- * Sent when the mouse pointer passes into the area of
- * the screen covered by a control.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the mouse enter
- */
-public void mouseEnter(MouseEvent e) {
-}
-
-/**
- * Sent when the mouse pointer passes out of the area of
- * the screen covered by a control.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the mouse exit
- */
-public void mouseExit(MouseEvent e) {
-}
-
-/**
- * Sent when the mouse pointer hovers (that is, stops moving
- * for an (operating system specified) period of time) over
- * a control.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the hover
- */
-public void mouseHover(MouseEvent e) {
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * This adapter class provides default implementations for the
+ * methods described by the <code>MouseTrackListener</code> interface.
+ * <p>
+ * Classes that wish to deal with <code>MouseEvent</code>s which
+ * occur as the mouse pointer passes (or hovers) over controls can
+ * extend this class and override only the methods which they are
+ * interested in.
+ * </p>
+ *
+ * @see MouseTrackListener
+ * @see MouseEvent
+ */
+public class MouseTrackAdapter implements MouseTrackListener {
+
+/**
+ * Sent when the mouse pointer passes into the area of
+ * the screen covered by a control.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the mouse enter
+ */
+public void mouseEnter(MouseEvent e) {
+}
+
+/**
+ * Sent when the mouse pointer passes out of the area of
+ * the screen covered by a control.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the mouse exit
+ */
+public void mouseExit(MouseEvent e) {
+}
+
+/**
+ * Sent when the mouse pointer hovers (that is, stops moving
+ * for an (operating system specified) period of time) over
+ * a control.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the hover
+ */
+public void mouseHover(MouseEvent e) {
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java
index b82e5eae9d..e6ba65f6fa 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MouseTrackListener.java
@@ -1,55 +1,55 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated as the mouse
- * pointer passes (or hovers) over controls.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addMouseTrackListener</code> method and removed using
- * the <code>removeMouseTrackListener</code> method. When the
- * mouse pointer passes into or out of the area of the screen
- * covered by a control or pauses while over a control, the
- * appropriate method will be invoked.
- * </p>
- *
- * @see MouseTrackAdapter
- * @see MouseEvent
- */
-public interface MouseTrackListener extends SWTEventListener {
-
-/**
- * Sent when the mouse pointer passes into the area of
- * the screen covered by a control.
- *
- * @param e an event containing information about the mouse enter
- */
-public void mouseEnter(MouseEvent e);
-
-/**
- * Sent when the mouse pointer passes out of the area of
- * the screen covered by a control.
- *
- * @param e an event containing information about the mouse exit
- */
-public void mouseExit(MouseEvent e);
-
-/**
- * Sent when the mouse pointer hovers (that is, stops moving
- * for an (operating system specified) period of time) over
- * a control.
- *
- * @param e an event containing information about the hover
- */
-public void mouseHover(MouseEvent e);
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the events that are generated as the mouse
+ * pointer passes (or hovers) over controls.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addMouseTrackListener</code> method and removed using
+ * the <code>removeMouseTrackListener</code> method. When the
+ * mouse pointer passes into or out of the area of the screen
+ * covered by a control or pauses while over a control, the
+ * appropriate method will be invoked.
+ * </p>
+ *
+ * @see MouseTrackAdapter
+ * @see MouseEvent
+ */
+public interface MouseTrackListener extends SWTEventListener {
+
+/**
+ * Sent when the mouse pointer passes into the area of
+ * the screen covered by a control.
+ *
+ * @param e an event containing information about the mouse enter
+ */
+public void mouseEnter(MouseEvent e);
+
+/**
+ * Sent when the mouse pointer passes out of the area of
+ * the screen covered by a control.
+ *
+ * @param e an event containing information about the mouse exit
+ */
+public void mouseExit(MouseEvent e);
+
+/**
+ * Sent when the mouse pointer hovers (that is, stops moving
+ * for an (operating system specified) period of time) over
+ * a control.
+ *
+ * @param e an event containing information about the hover
+ */
+public void mouseHover(MouseEvent e);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java
index 3231819e8d..16b0ca2e5c 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintEvent.java
@@ -1,78 +1,78 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.graphics.GC;
-
-/**
- * Instances of this class are sent as a result of
- * visible areas of controls requiring re-painting.
- *
- * @see PaintListener
- */
-
-public final class PaintEvent extends TypedEvent {
-
- /**
- * the graphics context to use when painting
- * that is configured to use the colors, font and
- * damaged region of the control. It is valid
- * only during the paint and must not be disposed
- */
- public GC gc;
-
- /**
- * the x offset of the bounding rectangle of the
- * region that requires painting
- */
- public int x;
-
- /**
- * the y offset of the bounding rectangle of the
- * region that requires painting
- */
- public int y;
-
- /**
- * the width of the bounding rectangle of the
- * region that requires painting
- */
- public int width;
-
- /**
- * the height of the bounding rectangle of the
- * region that requires painting
- */
- public int height;
-
- /**
- * the number of following paint events which
- * are pending which may always be zero on
- * some platforms
- */
- public int count;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public PaintEvent(Event e) {
- super(e);
- this.gc = e.gc;
- this.x = e.x;
- this.y = e.y;
- this.width = e.width;
- this.height = e.height;
- this.count = e.count;
-}
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.graphics.GC;
+
+/**
+ * Instances of this class are sent as a result of
+ * visible areas of controls requiring re-painting.
+ *
+ * @see PaintListener
+ */
+
+public final class PaintEvent extends TypedEvent {
+
+ /**
+ * the graphics context to use when painting
+ * that is configured to use the colors, font and
+ * damaged region of the control. It is valid
+ * only during the paint and must not be disposed
+ */
+ public GC gc;
+
+ /**
+ * the x offset of the bounding rectangle of the
+ * region that requires painting
+ */
+ public int x;
+
+ /**
+ * the y offset of the bounding rectangle of the
+ * region that requires painting
+ */
+ public int y;
+
+ /**
+ * the width of the bounding rectangle of the
+ * region that requires painting
+ */
+ public int width;
+
+ /**
+ * the height of the bounding rectangle of the
+ * region that requires painting
+ */
+ public int height;
+
+ /**
+ * the number of following paint events which
+ * are pending which may always be zero on
+ * some platforms
+ */
+ public int count;
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public PaintEvent(Event e) {
+ super(e);
+ this.gc = e.gc;
+ this.x = e.x;
+ this.y = e.y;
+ this.width = e.width;
+ this.height = e.height;
+ this.count = e.count;
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java
index f8ae91bc58..8e15870f60 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/PaintListener.java
@@ -1,35 +1,35 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated when the
- * control needs to be painted.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addPaintListener</code> method and removed using
- * the <code>removePaintListener</code> method. When a
- * paint event occurs, the paintControl method will be
- * invoked.
- * </p>
- *
- * @see PaintEvent
- */
-public interface PaintListener extends SWTEventListener {
-
-/**
- * Sent when a paint event occurs for the control.
- *
- * @param e an event containing information about the paint
- */
-public void paintControl(PaintEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the events that are generated when the
+ * control needs to be painted.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addPaintListener</code> method and removed using
+ * the <code>removePaintListener</code> method. When a
+ * paint event occurs, the paintControl method will be
+ * invoked.
+ * </p>
+ *
+ * @see PaintEvent
+ */
+public interface PaintListener extends SWTEventListener {
+
+/**
+ * Sent when a paint event occurs for the control.
+ *
+ * @param e an event containing information about the paint
+ */
+public void paintControl(PaintEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java
index c4773a5f39..b5ffd2538d 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionAdapter.java
@@ -1,41 +1,41 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>SelectionListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>SelectionEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see SelectionListener
- * @see SelectionEvent
- */
-public abstract class SelectionAdapter implements SelectionListener {
-
-/**
- * Sent when selection occurs in the control.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the selection
- */
-public void widgetSelected(SelectionEvent e) {
-}
-
-/**
- * Sent when default selection occurs in the control.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the default selection
- */
-public void widgetDefaultSelected(SelectionEvent e) {
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * This adapter class provides default implementations for the
+ * methods described by the <code>SelectionListener</code> interface.
+ * <p>
+ * Classes that wish to deal with <code>SelectionEvent</code>s can
+ * extend this class and override only the methods which they are
+ * interested in.
+ * </p>
+ *
+ * @see SelectionListener
+ * @see SelectionEvent
+ */
+public abstract class SelectionAdapter implements SelectionListener {
+
+/**
+ * Sent when selection occurs in the control.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the selection
+ */
+public void widgetSelected(SelectionEvent e) {
+}
+
+/**
+ * Sent when default selection occurs in the control.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the default selection
+ */
+public void widgetDefaultSelected(SelectionEvent e) {
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java
index 6567ebb84c..9973a17bdf 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionEvent.java
@@ -1,99 +1,99 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class are sent as a result of
- * widgets being selected.
- * <p>
- * Note: The fields that are filled in depend on the widget.
- * </p>
- *
- * @see SelectionListener
- */
-
-public class SelectionEvent extends TypedEvent {
-
- /**
- * the item that was selected
- */
- public Widget item;
-
- /**
- * extra detail information about the selection, depending on the widget
- * <p><b>Sash</b><ul>
- * <li>{@link SWT#DRAG}</li>
- * </ul></p><p><b>ScrollBar and Slider</b><ul>
- * <li>{@link SWT#DRAG}</li>
- * <li>{@link SWT#HOME}</li>
- * <li>{@link SWT#END}</li>
- * <li>{@link SWT#ARROW_DOWN}</li>
- * <li>{@link SWT#ARROW_UP}</li>
- * <li>{@link SWT#PAGE_DOWN}</li>
- * <li>{@link SWT#PAGE_UP}</li>
- * </ul></p><p><b>Table, Tree and TableTree</b><ul>
- * <li>{@link SWT#CHECK}</li>
- * </ul></p><p><b>CoolItem and ToolItem</b><ul>
- * <li>{@link SWT#ARROW}</li>
- * </ul></p>
- */
- public int detail;
-
- /**
- * the x location of the selected area
- */
- public int x;
-
- /**
- * the y location of selected area
- */
- public int y;
-
- /**
- * the width of selected area
- */
- public int width;
-
- /**
- * the height of selected area
- */
- public int height;
-
- /**
- * the state of the keyboard modifier keys at the time
- * the event was generated.
- */
- public int stateMask;
-
- /**
- * a flag indicating whether the operation should be allowed
- */
- public boolean doit;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public SelectionEvent(Event e) {
- super(e);
- this.item = e.item;
- this.x = e.x;
- this.y = e.y;
- this.width = e.width;
- this.height = e.height;
- this.detail = e.detail;
- this.stateMask = e.stateMask;
- this.doit = e.doit;
-}
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.*;
+
+/**
+ * Instances of this class are sent as a result of
+ * widgets being selected.
+ * <p>
+ * Note: The fields that are filled in depend on the widget.
+ * </p>
+ *
+ * @see SelectionListener
+ */
+
+public class SelectionEvent extends TypedEvent {
+
+ /**
+ * the item that was selected
+ */
+ public Widget item;
+
+ /**
+ * extra detail information about the selection, depending on the widget
+ * <p><b>Sash</b><ul>
+ * <li>{@link SWT#DRAG}</li>
+ * </ul></p><p><b>ScrollBar and Slider</b><ul>
+ * <li>{@link SWT#DRAG}</li>
+ * <li>{@link SWT#HOME}</li>
+ * <li>{@link SWT#END}</li>
+ * <li>{@link SWT#ARROW_DOWN}</li>
+ * <li>{@link SWT#ARROW_UP}</li>
+ * <li>{@link SWT#PAGE_DOWN}</li>
+ * <li>{@link SWT#PAGE_UP}</li>
+ * </ul></p><p><b>Table, Tree and TableTree</b><ul>
+ * <li>{@link SWT#CHECK}</li>
+ * </ul></p><p><b>CoolItem and ToolItem</b><ul>
+ * <li>{@link SWT#ARROW}</li>
+ * </ul></p>
+ */
+ public int detail;
+
+ /**
+ * the x location of the selected area
+ */
+ public int x;
+
+ /**
+ * the y location of selected area
+ */
+ public int y;
+
+ /**
+ * the width of selected area
+ */
+ public int width;
+
+ /**
+ * the height of selected area
+ */
+ public int height;
+
+ /**
+ * the state of the keyboard modifier keys at the time
+ * the event was generated.
+ */
+ public int stateMask;
+
+ /**
+ * a flag indicating whether the operation should be allowed
+ */
+ public boolean doit;
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public SelectionEvent(Event e) {
+ super(e);
+ this.item = e.item;
+ this.x = e.x;
+ this.y = e.y;
+ this.width = e.width;
+ this.height = e.height;
+ this.detail = e.detail;
+ this.stateMask = e.stateMask;
+ this.doit = e.doit;
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java
index a782fa697c..522abb37f3 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/SelectionListener.java
@@ -1,52 +1,52 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the events that are generated when selection
- * occurs in a control.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addSelectionListener</code> method and removed using
- * the <code>removeSelectionListener</code> method. When
- * selection occurs in a control the appropriate method
- * will be invoked.
- * </p>
- *
- * @see SelectionAdapter
- * @see SelectionEvent
- */
-public interface SelectionListener extends SWTEventListener {
-
-/**
- * Sent when selection occurs in the control.
- * <p>
- * For example, on some platforms selection occurs in
- * a List when the user selects an item or items.
- * </p>
- *
- * @param e an event containing information about the selection
- */
-public void widgetSelected(SelectionEvent e);
-
-/**
- * Sent when default selection occurs in the control.
- * <p>
- * For example, on some platforms default selection occurs
- * in a List when the user double-clicks an item or types
- * return in a Text.
- * </p>
- *
- * @param e an event containing information about the default selection
- */
-public void widgetDefaultSelected(SelectionEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the events that are generated when selection
+ * occurs in a control.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addSelectionListener</code> method and removed using
+ * the <code>removeSelectionListener</code> method. When
+ * selection occurs in a control the appropriate method
+ * will be invoked.
+ * </p>
+ *
+ * @see SelectionAdapter
+ * @see SelectionEvent
+ */
+public interface SelectionListener extends SWTEventListener {
+
+/**
+ * Sent when selection occurs in the control.
+ * <p>
+ * For example, on some platforms selection occurs in
+ * a List when the user selects an item or items.
+ * </p>
+ *
+ * @param e an event containing information about the selection
+ */
+public void widgetSelected(SelectionEvent e);
+
+/**
+ * Sent when default selection occurs in the control.
+ * <p>
+ * For example, on some platforms default selection occurs
+ * in a List when the user double-clicks an item or types
+ * return in a Text.
+ * </p>
+ *
+ * @param e an event containing information about the default selection
+ */
+public void widgetDefaultSelected(SelectionEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java
index 99af81306d..edbbdaef53 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java
@@ -1,68 +1,68 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>ShellListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>ShellEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see ShellListener
- * @see ShellEvent
- */
-public abstract class ShellAdapter implements ShellListener {
-
-/**
- * Sent when a shell becomes the active window.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the activation
- */
-public void shellActivated(ShellEvent e) {
-}
-
-/**
- * Sent when a shell is closed.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the close
- */
-public void shellClosed(ShellEvent e) {
-}
-
-/**
- * Sent when a shell stops being the active window.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the deactivation
- */
-public void shellDeactivated(ShellEvent e) {
-}
-
-/**
- * Sent when a shell is un-minimized.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the un-minimization
- */
-public void shellDeiconified(ShellEvent e) {
-}
-
-/**
- * Sent when a shell is minimized.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the minimization
- */
-public void shellIconified(ShellEvent e) {
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * This adapter class provides default implementations for the
+ * methods described by the <code>ShellListener</code> interface.
+ * <p>
+ * Classes that wish to deal with <code>ShellEvent</code>s can
+ * extend this class and override only the methods which they are
+ * interested in.
+ * </p>
+ *
+ * @see ShellListener
+ * @see ShellEvent
+ */
+public abstract class ShellAdapter implements ShellListener {
+
+/**
+ * Sent when a shell becomes the active window.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the activation
+ */
+public void shellActivated(ShellEvent e) {
+}
+
+/**
+ * Sent when a shell is closed.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the close
+ */
+public void shellClosed(ShellEvent e) {
+}
+
+/**
+ * Sent when a shell stops being the active window.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the deactivation
+ */
+public void shellDeactivated(ShellEvent e) {
+}
+
+/**
+ * Sent when a shell is un-minimized.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the un-minimization
+ */
+public void shellDeiconified(ShellEvent e) {
+}
+
+/**
+ * Sent when a shell is minimized.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the minimization
+ */
+public void shellIconified(ShellEvent e) {
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java
index 7bd0a87eed..5156f48443 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellEvent.java
@@ -1,32 +1,32 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * operations being performed on shells.
- *
- * @see ShellListener
- */
-
-public final class ShellEvent extends TypedEvent {
-
- /**
- * a flag indicating whether the operation should be allowed
- */
- public boolean doit;
-
-public ShellEvent(Event e) {
- super(e);
- this.doit = e.doit;
-}
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent as a result of
+ * operations being performed on shells.
+ *
+ * @see ShellListener
+ */
+
+public final class ShellEvent extends TypedEvent {
+
+ /**
+ * a flag indicating whether the operation should be allowed
+ */
+ public boolean doit;
+
+public ShellEvent(Event e) {
+ super(e);
+ this.doit = e.doit;
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java
index d118fde7be..85ffb47973 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java
@@ -1,63 +1,63 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with changes in state of <code>Shell</code>s.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addShellListener</code> method and removed using
- * the <code>removeShellListener</code> method. When the
- * state of a shell changes, the appropriate method will
- * be invoked.
- * </p>
- *
- * @see ShellAdapter
- * @see ShellEvent
- */
-public interface ShellListener extends SWTEventListener {
-
-/**
- * Sent when a shell becomes the active window.
- *
- * @param e an event containing information about the activation
- */
-public void shellActivated(ShellEvent e);
-
-/**
- * Sent when a shell is closed.
- *
- * @param e an event containing information about the close
- */
-public void shellClosed(ShellEvent e);
-
-/**
- * Sent when a shell stops being the active window.
- *
- * @param e an event containing information about the deactivation
- */
-public void shellDeactivated(ShellEvent e);
-
-/**
- * Sent when a shell is un-minimized.
- *
- * @param e an event containing information about the un-minimization
- */
-public void shellDeiconified(ShellEvent e);
-
-/**
- * Sent when a shell is minimized.
- *
- * @param e an event containing information about the minimization
- */
-public void shellIconified(ShellEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with changes in state of <code>Shell</code>s.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addShellListener</code> method and removed using
+ * the <code>removeShellListener</code> method. When the
+ * state of a shell changes, the appropriate method will
+ * be invoked.
+ * </p>
+ *
+ * @see ShellAdapter
+ * @see ShellEvent
+ */
+public interface ShellListener extends SWTEventListener {
+
+/**
+ * Sent when a shell becomes the active window.
+ *
+ * @param e an event containing information about the activation
+ */
+public void shellActivated(ShellEvent e);
+
+/**
+ * Sent when a shell is closed.
+ *
+ * @param e an event containing information about the close
+ */
+public void shellClosed(ShellEvent e);
+
+/**
+ * Sent when a shell stops being the active window.
+ *
+ * @param e an event containing information about the deactivation
+ */
+public void shellDeactivated(ShellEvent e);
+
+/**
+ * Sent when a shell is un-minimized.
+ *
+ * @param e an event containing information about the un-minimization
+ */
+public void shellDeiconified(ShellEvent e);
+
+/**
+ * Sent when a shell is minimized.
+ *
+ * @param e an event containing information about the minimization
+ */
+public void shellIconified(ShellEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java
index 90181c3ec1..18faee5489 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseEvent.java
@@ -1,123 +1,123 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.*;
-
-/**
- * Instances of this class are sent as a result of
- * widget traversal actions.
- * <p>
- * The traversal event allows fine control over keyboard traversal
- * in a control both to implement traversal and override the default
- * traversal behavior defined by the system. This is achieved using
- * two fields, <code>detail</code> and <code>doit</code>.
- * </p><p>
- * When a control is traversed, a traverse event is sent. The detail
- * describes the type of traversal and the doit indicates the default
- * behavior of the system. For example, when a right arrow key is pressed
- * in a text control, the detail field is <code>TRAVERSE_ARROW_NEXT</code>
- * and the doit field is <code>false</code>, indicating that the system
- * will not traverse to the next tab item and the arrow key will be
- * delivered to the text control. If the same key is pressed in a radio
- * button, the doit field will be <code>true</code>, indicating that
- * traversal is to proceed to the next tab item, possibly another
- * radio button in the group and that the arrow key is not be delivered
- * to the radio button.
- * </p><p>
- * How can the traversal event be used to implement traversal?
- * When a tab key is pressed in a canvas, the detail field will be
- * <code>TRAVERSE_TAB_NEXT</code> and the doit field will be
- * <code>false</code>. The default behavior of the system is to
- * provide no traversal for canvas controls. This means that by
- * default in a canvas, a key listener will see every key that
- * user types, including traversal keys. To understand why this
- * is so, it is important to understand that only the widget implementor
- * can decide which traversal is appropriate for the widget. Returning
- * to the <code>TRAVERSE_TAB_NEXT</code> example, a text widget implemented
- * by a canvas, would typically want to use the tab key to insert a
- * tab character into the widget. A list widget implementation, on the
- * other hand, would like the system default traversal behavior. Using
- * only the doit flag, both implementations are possible. The text widget
- * implementor sets doit to <code>false</false>, ensuring that the system
- * will not traverse and that the tab key will be delivered to key listeners.
- * The list widget implementor sets doit to <code>true</code>, indicating
- * that the system should perform tab traversal and that the key should not
- * be delivered to the list widget.
- * </p><p>
- * How can the traversal event be used to override system traversal?
- * When the return key is pressed in a single line text control, the
- * detail field is be <code>TRAVERSE_RETURN</code> and the doit field
- * is <code>true</code>. This means that the return key will processed
- * by the default button, not the text widget. If the text widget has
- * a default selection listener, it will not run because the return key
- * will be processed by the default button. Imagine that the text control
- * is being used as an in-place editor and return is used to dispose the
- * widget. Setting doit to <code>false</code> will stop the system from
- * activating the default button but the key will be delivered to the text
- * control, running the key and selection listeners for the text. How
- * can <code>TRAVERSE_RETURN be implemented so that the default button
- * will not be activated and the text widget will not see the return key?
- * This is achieved by setting doit to <code>true</code>, and the detail
- * to <code>TRAVERSE_NONE</code>.
- * </p><p>
- * Note: A widget implementor will typically implement traversal using
- * only the doit flag to either enable or disable system traversal.
- * </p>
- *
- * @see TraverseListener
- */
-
-public class TraverseEvent extends KeyEvent {
-
- /**
- * the type of traversal
- * <p><ul>
- * <li>{@link SWT#TRAVERSE_NONE}</li>
- * <li>{@link SWT#TRAVERSE_ESCAPE}</li>
- * <li>{@link SWT#TRAVERSE_RETURN}</li>
- * <li>{@link SWT#TRAVERSE_TAB_NEXT}</li>
- * <li>{@link SWT#TRAVERSE_TAB_PREVIOUS}</li>
- * <li>{@link SWT#TRAVERSE_ARROW_NEXT}</li>
- * <li>{@link SWT#TRAVERSE_ARROW_PREVIOUS}</li>
- * <li>{@link SWT#TRAVERSE_MNEMONIC}</li>
- * <li>{@link SWT#TRAVERSE_PAGE_NEXT}</li>
- * <li>{@link SWT#TRAVERSE_PAGE_PREVIOUS}</li>
- * </ul></p>
- *
- * Setting this field will change the type of traversal.
- * For example, setting the detail to <code>TRAVERSE_NONE</code>
- * causes no traversal action to be taked. The traversal detail,
- * in conjuction with the <code>doit</code> field can be useful
- * when overriding the default traversal mechanism for a control.
- *
- */
- public int detail;
-
- /**
- * a flag indicating whether the operation should be allowed.
- * Setting this field to <code>false</code> will cancel the operation
- * and allow the traversal key stroke to be delivered to the control.
- * A value of true indicates that the traversal, described by the
- * traversal <code>detail</code> is to be performed.
- */
- public boolean doit;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public TraverseEvent(Event e) {
- super(e);
- this.doit = e.doit;
- this.detail = e.detail;
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.*;
+
+/**
+ * Instances of this class are sent as a result of
+ * widget traversal actions.
+ * <p>
+ * The traversal event allows fine control over keyboard traversal
+ * in a control both to implement traversal and override the default
+ * traversal behavior defined by the system. This is achieved using
+ * two fields, <code>detail</code> and <code>doit</code>.
+ * </p><p>
+ * When a control is traversed, a traverse event is sent. The detail
+ * describes the type of traversal and the doit indicates the default
+ * behavior of the system. For example, when a right arrow key is pressed
+ * in a text control, the detail field is <code>TRAVERSE_ARROW_NEXT</code>
+ * and the doit field is <code>false</code>, indicating that the system
+ * will not traverse to the next tab item and the arrow key will be
+ * delivered to the text control. If the same key is pressed in a radio
+ * button, the doit field will be <code>true</code>, indicating that
+ * traversal is to proceed to the next tab item, possibly another
+ * radio button in the group and that the arrow key is not be delivered
+ * to the radio button.
+ * </p><p>
+ * How can the traversal event be used to implement traversal?
+ * When a tab key is pressed in a canvas, the detail field will be
+ * <code>TRAVERSE_TAB_NEXT</code> and the doit field will be
+ * <code>false</code>. The default behavior of the system is to
+ * provide no traversal for canvas controls. This means that by
+ * default in a canvas, a key listener will see every key that
+ * user types, including traversal keys. To understand why this
+ * is so, it is important to understand that only the widget implementor
+ * can decide which traversal is appropriate for the widget. Returning
+ * to the <code>TRAVERSE_TAB_NEXT</code> example, a text widget implemented
+ * by a canvas, would typically want to use the tab key to insert a
+ * tab character into the widget. A list widget implementation, on the
+ * other hand, would like the system default traversal behavior. Using
+ * only the doit flag, both implementations are possible. The text widget
+ * implementor sets doit to <code>false</false>, ensuring that the system
+ * will not traverse and that the tab key will be delivered to key listeners.
+ * The list widget implementor sets doit to <code>true</code>, indicating
+ * that the system should perform tab traversal and that the key should not
+ * be delivered to the list widget.
+ * </p><p>
+ * How can the traversal event be used to override system traversal?
+ * When the return key is pressed in a single line text control, the
+ * detail field is be <code>TRAVERSE_RETURN</code> and the doit field
+ * is <code>true</code>. This means that the return key will processed
+ * by the default button, not the text widget. If the text widget has
+ * a default selection listener, it will not run because the return key
+ * will be processed by the default button. Imagine that the text control
+ * is being used as an in-place editor and return is used to dispose the
+ * widget. Setting doit to <code>false</code> will stop the system from
+ * activating the default button but the key will be delivered to the text
+ * control, running the key and selection listeners for the text. How
+ * can <code>TRAVERSE_RETURN be implemented so that the default button
+ * will not be activated and the text widget will not see the return key?
+ * This is achieved by setting doit to <code>true</code>, and the detail
+ * to <code>TRAVERSE_NONE</code>.
+ * </p><p>
+ * Note: A widget implementor will typically implement traversal using
+ * only the doit flag to either enable or disable system traversal.
+ * </p>
+ *
+ * @see TraverseListener
+ */
+
+public class TraverseEvent extends KeyEvent {
+
+ /**
+ * the type of traversal
+ * <p><ul>
+ * <li>{@link SWT#TRAVERSE_NONE}</li>
+ * <li>{@link SWT#TRAVERSE_ESCAPE}</li>
+ * <li>{@link SWT#TRAVERSE_RETURN}</li>
+ * <li>{@link SWT#TRAVERSE_TAB_NEXT}</li>
+ * <li>{@link SWT#TRAVERSE_TAB_PREVIOUS}</li>
+ * <li>{@link SWT#TRAVERSE_ARROW_NEXT}</li>
+ * <li>{@link SWT#TRAVERSE_ARROW_PREVIOUS}</li>
+ * <li>{@link SWT#TRAVERSE_MNEMONIC}</li>
+ * <li>{@link SWT#TRAVERSE_PAGE_NEXT}</li>
+ * <li>{@link SWT#TRAVERSE_PAGE_PREVIOUS}</li>
+ * </ul></p>
+ *
+ * Setting this field will change the type of traversal.
+ * For example, setting the detail to <code>TRAVERSE_NONE</code>
+ * causes no traversal action to be taked. The traversal detail,
+ * in conjuction with the <code>doit</code> field can be useful
+ * when overriding the default traversal mechanism for a control.
+ *
+ */
+ public int detail;
+
+ /**
+ * a flag indicating whether the operation should be allowed.
+ * Setting this field to <code>false</code> will cancel the operation
+ * and allow the traversal key stroke to be delivered to the control.
+ * A value of true indicates that the traversal, described by the
+ * traversal <code>detail</code> is to be performed.
+ */
+ public boolean doit;
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public TraverseEvent(Event e) {
+ super(e);
+ this.doit = e.doit;
+ this.detail = e.detail;
+}
+
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java
index 95d4d94714..a8c6bd3a95 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TraverseListener.java
@@ -1,42 +1,42 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the events that are generated when a
- * traverse event occurs in a control.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addTraverseListener</code> method and removed using
- * the <code>removeTraverseListener</code> method. When a
- * traverse event occurs in a control, the keyTraversed method
- * will be invoked.
- * </p>
- *
- * @see TraverseEvent
- */
-public interface TraverseListener extends SWTEventListener {
-
-/**
- * Sent when a traverse event occurs in a control.
- * <p>
- * A traverse event occurs when the user presses a traversal
- * key. Traversal keys are typically tab and arrow keys, along
- * with certain other keys on some platforms. Traversal key
- * constants beginning with <code>TRAVERSE_</code> are defined
- * in the <code>SWT</code> class.
- * </p>
- *
- * @param e an event containing information about the traverse
- */
-public void keyTraversed(TraverseEvent e);
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide a method
+ * that deals with the events that are generated when a
+ * traverse event occurs in a control.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addTraverseListener</code> method and removed using
+ * the <code>removeTraverseListener</code> method. When a
+ * traverse event occurs in a control, the keyTraversed method
+ * will be invoked.
+ * </p>
+ *
+ * @see TraverseEvent
+ */
+public interface TraverseListener extends SWTEventListener {
+
+/**
+ * Sent when a traverse event occurs in a control.
+ * <p>
+ * A traverse event occurs when the user presses a traversal
+ * key. Traversal keys are typically tab and arrow keys, along
+ * with certain other keys on some platforms. Traversal key
+ * constants beginning with <code>TRAVERSE_</code> are defined
+ * in the <code>SWT</code> class.
+ * </p>
+ *
+ * @param e an event containing information about the traverse
+ */
+public void keyTraversed(TraverseEvent e);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java
index f1da6f472c..cfa2817bfb 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java
@@ -1,41 +1,41 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * This adapter class provides default implementations for the
- * methods described by the <code>TreeListener</code> interface.
- * <p>
- * Classes that wish to deal with <code>TreeEvent</code>s can
- * extend this class and override only the methods which they are
- * interested in.
- * </p>
- *
- * @see TreeListener
- * @see TreeEvent
- */
-public abstract class TreeAdapter implements TreeListener {
-
-/**
- * Sent when a tree branch is collapsed.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the tree operation
- */
-public void treeCollapsed(TreeEvent e) {
-}
-
-/**
- * Sent when a tree branch is expanded.
- * The default behavior is to do nothing.
- *
- * @param e an event containing information about the tree operation
- */
-public void treeExpanded(TreeEvent e) {
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * This adapter class provides default implementations for the
+ * methods described by the <code>TreeListener</code> interface.
+ * <p>
+ * Classes that wish to deal with <code>TreeEvent</code>s can
+ * extend this class and override only the methods which they are
+ * interested in.
+ * </p>
+ *
+ * @see TreeListener
+ * @see TreeEvent
+ */
+public abstract class TreeAdapter implements TreeListener {
+
+/**
+ * Sent when a tree branch is collapsed.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the tree operation
+ */
+public void treeCollapsed(TreeEvent e) {
+}
+
+/**
+ * Sent when a tree branch is expanded.
+ * The default behavior is to do nothing.
+ *
+ * @param e an event containing information about the tree operation
+ */
+public void treeExpanded(TreeEvent e) {
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java
index 0776d19dae..23634de5a0 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeEvent.java
@@ -1,32 +1,32 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * trees being expanded and collapsed.
- *
- * @see TreeListener
- */
-
-public final class TreeEvent extends SelectionEvent {
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public TreeEvent(Event e) {
- super(e);
-}
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent as a result of
+ * trees being expanded and collapsed.
+ *
+ * @see TreeListener
+ */
+
+public final class TreeEvent extends SelectionEvent {
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public TreeEvent(Event e) {
+ super(e);
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java
index 82039e035a..b910e12ea4 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java
@@ -1,43 +1,43 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide methods
- * that deal with the expanding and collapsing of tree
- * branches.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a control using the
- * <code>addTreeListener</code> method and removed using
- * the <code>removeTreeListener</code> method. When a branch
- * of a tree is expanded or collapsed, the appropriate method
- * will be invoked.
- * </p>
- *
- * @see TreeAdapter
- * @see TreeEvent
- */
-public interface TreeListener extends SWTEventListener {
-
-/**
- * Sent when a tree branch is collapsed.
- *
- * @param e an event containing information about the tree operation
- */
-public void treeCollapsed(TreeEvent e);
-
-/**
- * Sent when a tree branch is expanded.
- *
- * @param e an event containing information about the tree operation
- */
-public void treeExpanded(TreeEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the expanding and collapsing of tree
+ * branches.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a control using the
+ * <code>addTreeListener</code> method and removed using
+ * the <code>removeTreeListener</code> method. When a branch
+ * of a tree is expanded or collapsed, the appropriate method
+ * will be invoked.
+ * </p>
+ *
+ * @see TreeAdapter
+ * @see TreeEvent
+ */
+public interface TreeListener extends SWTEventListener {
+
+/**
+ * Sent when a tree branch is collapsed.
+ *
+ * @param e an event containing information about the tree operation
+ */
+public void treeCollapsed(TreeEvent e);
+
+/**
+ * Sent when a tree branch is expanded.
+ *
+ * @param e an event containing information about the tree operation
+ */
+public void treeExpanded(TreeEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java
index bea11e8879..7d90cf6ad0 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TypedEvent.java
@@ -1,71 +1,71 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.internal.SWTEventObject;
-
-/**
- * This is the super class for all typed event classes provided
- * by SWT. Typed events contain particular information which is
- * applicable to the event occurance.
- *
- * @see org.eclipse.swt.widgets.Event
- */
-public class TypedEvent extends SWTEventObject {
-
- /**
- * the display where the event occurred
- *
- * @since 2.0
- */
- public Display display;
-
- /**
- * the widget that issued the event
- */
- public Widget widget;
-
- /**
- * the time that the event occurred.
- *
- * NOTE: This field is an unsigned integer and should
- * be AND'ed with 0xFFFFFFFFL so that it can be treated
- * as a signed long.
- */
- public int time;
-
- /**
- * a field for application use
- */
- public Object data;
-
-/**
- * Constructs a new instance of this class.
- *
- * @param source the object that fired the event
- */
-public TypedEvent(Object object) {
- super(object);
-}
-
-/**
- * Constructs a new instance of this class based on the
- * information in the argument.
- *
- * @param e the low level event to initialize the receiver with
- */
-public TypedEvent(Event e) {
- super(e.widget);
- this.display = e.display;
- this.widget = e.widget;
- this.time = e.time;
- this.data = e.data;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.internal.SWTEventObject;
+
+/**
+ * This is the super class for all typed event classes provided
+ * by SWT. Typed events contain particular information which is
+ * applicable to the event occurance.
+ *
+ * @see org.eclipse.swt.widgets.Event
+ */
+public class TypedEvent extends SWTEventObject {
+
+ /**
+ * the display where the event occurred
+ *
+ * @since 2.0
+ */
+ public Display display;
+
+ /**
+ * the widget that issued the event
+ */
+ public Widget widget;
+
+ /**
+ * the time that the event occurred.
+ *
+ * NOTE: This field is an unsigned integer and should
+ * be AND'ed with 0xFFFFFFFFL so that it can be treated
+ * as a signed long.
+ */
+ public int time;
+
+ /**
+ * a field for application use
+ */
+ public Object data;
+
+/**
+ * Constructs a new instance of this class.
+ *
+ * @param source the object that fired the event
+ */
+public TypedEvent(Object object) {
+ super(object);
+}
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the argument.
+ *
+ * @param e the low level event to initialize the receiver with
+ */
+public TypedEvent(Event e) {
+ super(e.widget);
+ this.display = e.display;
+ this.widget = e.widget;
+ this.time = e.time;
+ this.data = e.data;
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java
index b5a0e1bfca..6281209110 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyEvent.java
@@ -1,57 +1,57 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.widgets.Event;
-
-/**
- * Instances of this class are sent as a result of
- * widgets handling keyboard events
- *
- * @see VerifyListener
- */
-
-public final class VerifyEvent extends KeyEvent {
-
- /**
- * the range of text being modified.
- * Setting these fields has no effect.
- */
- public int start, end;
-
- /**
- * the new text that will be inserted.
- * Setting this field will change the text that is about to
- * be inserted or deleted.
- */
- public String text;
-
- /**
- * a flag indicating whether the operation should be allowed.
- * Setting this field to false will cancel the operation.
- */
- public boolean doit;
-
-/**
- * Constructs a new instance of this class based on the
- * information in the given untyped event.
- *
- * @param e the untyped event containing the information
- */
-public VerifyEvent(Event e) {
- super(e);
- this.character = e.character;
- this.keyCode = e.keyCode;
- this.stateMask = e.stateMask;
- this.start = e.start;
- this.end = e.end;
- this.text = e.text;
- this.doit = e.doit;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Instances of this class are sent as a result of
+ * widgets handling keyboard events
+ *
+ * @see VerifyListener
+ */
+
+public final class VerifyEvent extends KeyEvent {
+
+ /**
+ * the range of text being modified.
+ * Setting these fields has no effect.
+ */
+ public int start, end;
+
+ /**
+ * the new text that will be inserted.
+ * Setting this field will change the text that is about to
+ * be inserted or deleted.
+ */
+ public String text;
+
+ /**
+ * a flag indicating whether the operation should be allowed.
+ * Setting this field to false will cancel the operation.
+ */
+ public boolean doit;
+
+/**
+ * Constructs a new instance of this class based on the
+ * information in the given untyped event.
+ *
+ * @param e the untyped event containing the information
+ */
+public VerifyEvent(Event e) {
+ super(e);
+ this.character = e.character;
+ this.keyCode = e.keyCode;
+ this.stateMask = e.stateMask;
+ this.start = e.start;
+ this.end = e.end;
+ this.text = e.text;
+ this.doit = e.doit;
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java
index cbffca9bad..2a2fb493ea 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/VerifyListener.java
@@ -1,41 +1,41 @@
-package org.eclipse.swt.events;
-
-/*
+package org.eclipse.swt.events;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.SWTEventListener;
-
-/**
- * Classes which implement this interface provide a method
- * that deals with the events that are generated when text
- * is about to be modified.
- * <p>
- * After creating an instance of a class that implements
- * this interface it can be added to a text widget using the
- * <code>addVerifyListener</code> method and removed using
- * the <code>removeVerifyListener</code> method. When the
- * text is about to be modified, the verifyText method
- * will be invoked.
- * </p>
- *
- * @see VerifyEvent
- */
-public interface VerifyListener extends SWTEventListener {
-
-/**
- * Sent when the text is about to be modified.
- * <p>
- * A verify event occurs after the user has done something
- * to modify the text (typically typed a key), but before
- * the text is modified. The doit field in the verify event
- * indicates whether or not to modify the text.
- * </p>
- *
- * @param e an event containing information about the verify
- */
-public void verifyText(VerifyEvent e);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.SWTEventListener;
+
+/**
+ * Classes which implement this interface provide a method
+ * that deals with the events that are generated when text
+ * is about to be modified.
+ * <p>
+ * After creating an instance of a class that implements
+ * this interface it can be added to a text widget using the
+ * <code>addVerifyListener</code> method and removed using
+ * the <code>removeVerifyListener</code> method. When the
+ * text is about to be modified, the verifyText method
+ * will be invoked.
+ * </p>
+ *
+ * @see VerifyEvent
+ */
+public interface VerifyListener extends SWTEventListener {
+
+/**
+ * Sent when the text is about to be modified.
+ * <p>
+ * A verify event occurs after the user has done something
+ * to modify the text (typically typed a key), but before
+ * the text is modified. The doit field in the verify event
+ * indicates whether or not to modify the text.
+ * </p>
+ *
+ * @param e an event containing information about the verify
+ */
+public void verifyText(VerifyEvent e);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Drawable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Drawable.java
index 903e9df135..cb647efdba 100755
--- 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
@@ -1,47 +1,47 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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
- *
- * @private
- */
-
-public 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>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
- *
- * @private
- */
-public void internal_dispose_GC (int handle, GCData data);
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
+ *
+ * @private
+ */
+
+public 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>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
+ *
+ * @private
+ */
+public void internal_dispose_GC (int handle, GCData data);
+
}
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
index e7587a4fe7..6d663d23b9 100755
--- 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
@@ -1,3551 +1,3551 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 necessary
- * 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;
-
- /**
- * 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;
-
- /**
- * 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 that the image was read in from,
- * 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, 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</li>
- * <li>ERROR_NULL_ARGUMENT - if the palette is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth argument is not one of 1, 2, 4, 8, 16, 24 or 32</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</li>
- * <li>ERROR_NULL_ARGUMENT - if the palette or data is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth argument is not one of 1, 2, 4, 8, 16, 24 or 32</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.
- * <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>
- *
- * @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_INVALID_IMAGE - if the image file contains invalid data</li>
- * <li>ERROR_IO - if an IO error occurs while reading data</li>
- * </ul>
- *
- * @see ImageLoader#load
- */
-public ImageData(InputStream stream) {
- ImageData[] data = new ImageLoader().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_INVALID_IMAGE - if the image file contains invalid data</li>
- * <li>ERROR_IO if an IO error occurs while reading data</li>
- * </ul>
- */
-public ImageData(String filename) {
- ImageData[] data = new ImageLoader().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);
- }
- 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>
- *
- * @private
- */
-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(),
- Image.DEFAULT_SCANLINE_PAD, 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;
- if (depth == 1) {
- index = (y * bytesPerLine) + (x >> 3);
- theByte = data[index] & 0xFF;
- mask = 1 << (7 - (x & 0x7));
- if ((theByte & mask) == 0) {
- return 0;
- } else {
- return 1;
- }
- }
- if (depth == 2) {
- index = (y * bytesPerLine) + (x >> 2);
- theByte = data[index] & 0xFF;
- int offset = 3 - (x % 4);
- mask = 3 << (offset * 2);
- return (theByte & mask) >> (offset * 2);
- }
- if (depth == 4) {
- index = (y * bytesPerLine) + (x >> 1);
- theByte = data[index] & 0xFF;
- if ((x & 0x1) == 0) {
- return theByte >> 4;
- } else {
- return theByte & 0x0F;
- }
- }
- if (depth == 8) {
- index = (y * bytesPerLine) + x ;
- return data[index] & 0xFF;
- }
- if (depth == 16) {
- index = (y * bytesPerLine) + (x * 2);
- return ((data[index+1] & 0xFF) << 8) + (data[index] & 0xFF);
- }
- if (depth == 24) {
- index = (y * bytesPerLine) + (x * 3);
- return ((data[index] & 0xFF) << 16) + ((data[index+1] & 0xFF) << 8) +
- (data[index+2] & 0xFF);
- }
- if (depth == 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);
- }
- 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;
- if (depth == 1) {
- index = (y * bytesPerLine) + (x >> 3);
- theByte = data[index] & 0xFF;
- while (n > 1) {
- 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- 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;
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- 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, or null if the
- * receiver has no transparency and is not an icon.
- *
- * @return the transparency mask or null if none exists
- */
-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.
- *
- * @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;
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 8) {
- index = (y * bytesPerLine) + x ;
- data[index] = (byte)(pixelValue & 0xFF);
- return;
- }
- if (depth == 16) {
- index = (y * bytesPerLine) + (x * 2);
- data[index + 1] = (byte)((pixelValue >> 8) & 0xFF);
- data[index] = (byte)(pixelValue & 0xFF);
- return;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- 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;
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- 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;
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
-
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- if (depth == 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;
- }
- 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;
-}
-
-/**
- * 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();
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 necessary
+ * 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;
+
+ /**
+ * 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;
+
+ /**
+ * 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 that the image was read in from,
+ * 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, 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</li>
+ * <li>ERROR_NULL_ARGUMENT - if the palette is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_UNSUPPORTED_DEPTH - if the depth argument is not one of 1, 2, 4, 8, 16, 24 or 32</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</li>
+ * <li>ERROR_NULL_ARGUMENT - if the palette or data is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_UNSUPPORTED_DEPTH - if the depth argument is not one of 1, 2, 4, 8, 16, 24 or 32</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.
+ * <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>
+ *
+ * @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_INVALID_IMAGE - if the image file contains invalid data</li>
+ * <li>ERROR_IO - if an IO error occurs while reading data</li>
+ * </ul>
+ *
+ * @see ImageLoader#load
+ */
+public ImageData(InputStream stream) {
+ ImageData[] data = new ImageLoader().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_INVALID_IMAGE - if the image file contains invalid data</li>
+ * <li>ERROR_IO if an IO error occurs while reading data</li>
+ * </ul>
+ */
+public ImageData(String filename) {
+ ImageData[] data = new ImageLoader().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);
+ }
+ 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>
+ *
+ * @private
+ */
+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(),
+ Image.DEFAULT_SCANLINE_PAD, 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;
+ if (depth == 1) {
+ index = (y * bytesPerLine) + (x >> 3);
+ theByte = data[index] & 0xFF;
+ mask = 1 << (7 - (x & 0x7));
+ if ((theByte & mask) == 0) {
+ return 0;
+ } else {
+ return 1;
+ }
+ }
+ if (depth == 2) {
+ index = (y * bytesPerLine) + (x >> 2);
+ theByte = data[index] & 0xFF;
+ int offset = 3 - (x % 4);
+ mask = 3 << (offset * 2);
+ return (theByte & mask) >> (offset * 2);
+ }
+ if (depth == 4) {
+ index = (y * bytesPerLine) + (x >> 1);
+ theByte = data[index] & 0xFF;
+ if ((x & 0x1) == 0) {
+ return theByte >> 4;
+ } else {
+ return theByte & 0x0F;
+ }
+ }
+ if (depth == 8) {
+ index = (y * bytesPerLine) + x ;
+ return data[index] & 0xFF;
+ }
+ if (depth == 16) {
+ index = (y * bytesPerLine) + (x * 2);
+ return ((data[index+1] & 0xFF) << 8) + (data[index] & 0xFF);
+ }
+ if (depth == 24) {
+ index = (y * bytesPerLine) + (x * 3);
+ return ((data[index] & 0xFF) << 16) + ((data[index+1] & 0xFF) << 8) +
+ (data[index+2] & 0xFF);
+ }
+ if (depth == 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);
+ }
+ 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;
+ if (depth == 1) {
+ index = (y * bytesPerLine) + (x >> 3);
+ theByte = data[index] & 0xFF;
+ while (n > 1) {
+ 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ 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;
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ 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, or null if the
+ * receiver has no transparency and is not an icon.
+ *
+ * @return the transparency mask or null if none exists
+ */
+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.
+ *
+ * @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;
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 8) {
+ index = (y * bytesPerLine) + x ;
+ data[index] = (byte)(pixelValue & 0xFF);
+ return;
+ }
+ if (depth == 16) {
+ index = (y * bytesPerLine) + (x * 2);
+ data[index + 1] = (byte)((pixelValue >> 8) & 0xFF);
+ data[index] = (byte)(pixelValue & 0xFF);
+ return;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ 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;
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ 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;
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ if (depth == 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;
+ }
+ 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;
+}
+
+/**
+ * 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();
+}
+
} \ No newline at end of file
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
index e0c9dd4b14..abb4931eb1 100755
--- 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
@@ -1,294 +1,294 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 Bitmap)</li>
- * <li>ICO (Windows Icon)</li>
- * <li>JPEG</li>
- * <li>GIF</li>
- * <li>PNG</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)</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")
- */
- 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_INVALID_IMAGE - if the image file contains invalid data</li>
- * <li>ERROR_IO - if an input/output error occurs while reading data</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_INVALID_IMAGE - if the image file contains invalid data</li>
- * <li>ERROR_IO - if an IO error occurs while reading data</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_INVALID_IMAGE if the image data contains invalid data</li>
- * <li>ERROR_IO if an IO error occurs while writing to the stream</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_INVALID_IMAGE if the image data contains invalid data</li>
- * <li>ERROR_IO if an IO error occurs while writing to the file</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);
-}
-
-/**
- * Adds a listener to receive image loader events.
- * <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 ImageLoaderListener to add
- *
- * @see ImageLoaderListener
- * @see ImageLoaderEvent
- */
-public void addImageLoaderListener(ImageLoaderListener listener) {
- if (imageLoaderListeners == null) {
- imageLoaderListeners = new Vector();
- }
- imageLoaderListeners.addElement(listener);
-}
-
-/**
- * Removes a listener that was receiving image loader events.
- *
- * @param listener the ImageLoaderListener to remove
- *
- * @see #addImageLoaderListener
- */
-public void removeImageLoaderListener(ImageLoaderListener listener) {
- 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
- * @see #removeImageLoaderListener
- */
-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);
- }
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 Bitmap)</li>
+ * <li>ICO (Windows Icon)</li>
+ * <li>JPEG</li>
+ * <li>GIF</li>
+ * <li>PNG</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)</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")
+ */
+ 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_INVALID_IMAGE - if the image file contains invalid data</li>
+ * <li>ERROR_IO - if an input/output error occurs while reading data</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_INVALID_IMAGE - if the image file contains invalid data</li>
+ * <li>ERROR_IO - if an IO error occurs while reading data</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_INVALID_IMAGE if the image data contains invalid data</li>
+ * <li>ERROR_IO if an IO error occurs while writing to the stream</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_INVALID_IMAGE if the image data contains invalid data</li>
+ * <li>ERROR_IO if an IO error occurs while writing to the file</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);
+}
+
+/**
+ * Adds a listener to receive image loader events.
+ * <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 ImageLoaderListener to add
+ *
+ * @see ImageLoaderListener
+ * @see ImageLoaderEvent
+ */
+public void addImageLoaderListener(ImageLoaderListener listener) {
+ if (imageLoaderListeners == null) {
+ imageLoaderListeners = new Vector();
+ }
+ imageLoaderListeners.addElement(listener);
+}
+
+/**
+ * Removes a listener that was receiving image loader events.
+ *
+ * @param listener the ImageLoaderListener to remove
+ *
+ * @see #addImageLoaderListener
+ */
+public void removeImageLoaderListener(ImageLoaderListener listener) {
+ 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
+ * @see #removeImageLoaderListener
+ */
+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
index 012d70d716..10796c777b 100755
--- 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
@@ -1,80 +1,80 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
-
-/**
- * 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 + "}";
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+
+/**
+ * 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 + "}";
+}
+
}
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
index b566ec435d..e6097a02fe 100755
--- 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
@@ -1,41 +1,41 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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);
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index e8aaf581f4..7ee714d91d 100755
--- 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
@@ -1,207 +1,207 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>RBG</code>.
- *
- * @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.
- *
- * @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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>RBG</code>.
+ *
+ * @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.
+ *
+ * @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/Point.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java
index 33eaedd022..7ef2794e7c 100755
--- 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
@@ -1,95 +1,95 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- * 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;
-
-/**
- * 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 which 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 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 + "}";
-}
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>
+ * 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;
+
+/**
+ * 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 which 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 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 + "}";
+}
+
+}
+
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
index 954846ad27..d8bba1da67 100755
--- 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
@@ -1,110 +1,110 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- * 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;
-
-/**
- * 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;
-}
-
-/**
- * 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 which 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 (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 + "}";
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>
+ * 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;
+
+/**
+ * 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;
+}
+
+/**
+ * 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 which 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 (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 + "}";
+}
+
+}
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
index 269c532827..708e5ca03b 100755
--- 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
@@ -1,275 +1,275 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- * 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;
-
-/**
- * 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 which 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 x ^ y ^ width ^ height;
-}
-
-/**
- * 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 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
- * @see #isEmpty
- */
-public boolean intersects (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return (rect == this) || (rect.x < x + width) && (rect.y < y + height) &&
- (rect.x + rect.width > x) && (rect.y + rect.height > y);
-}
-
-/**
- * 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 + "}";
-}
-
-/**
- * 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
- */
-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);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>
+ * 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;
+
+/**
+ * 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 which 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 x ^ y ^ width ^ height;
+}
+
+/**
+ * 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 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
+ * @see #isEmpty
+ */
+public boolean intersects (Rectangle rect) {
+ if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ return (rect == this) || (rect.x < x + width) && (rect.y < y + height) &&
+ (rect.x + rect.width > x) && (rect.y + rect.height > y);
+}
+
+/**
+ * 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 + "}";
+}
+
+/**
+ * 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
+ */
+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/internal/Callback.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java
index 6e02365662..1b9246a8db 100755
--- 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
@@ -1,189 +1,189 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * 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, address;
- boolean isStatic, isArrayBased;
-
- /* Load the SWT library */
- static {
- Library.loadLibrary ("swt");
- }
-
-/**
- * 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) {
-
- /* Set the callback fields */
- this.object = object;
- this.method = method;
- this.argCount = argCount;
- isStatic = object instanceof Class;
- this.isArrayBased = isArrayBased;
-
- /* Inline the common cases */
- if (isArrayBased) {
- signature = "([I)I";
- } else {
- switch (argCount) {
- case 0: signature = "()I"; break;
- case 1: signature = "(I)I"; break;
- case 2: signature = "(II)I"; break;
- case 3: signature = "(III)I"; break;
- case 4: signature = "(IIII)I"; break;
- default:
- signature = "(";
- for (int i=0; i<argCount; i++) signature += "I";
- signature += ")I";
- }
- }
-
- /* Bind the address */
- address = bind (this);
-}
-
-/**
- * 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
- */
-static native synchronized int bind (Callback callback);
-
-/**
- * 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 getAddress () {
- return address;
-}
-
-/**
- * Returns the SWT platform name.
- *
- * @return the platform name of the currently running SWT
- */
-public static native String getPlatform ();
-
-/**
- * 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 ignore true if callbacks should not 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);
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * 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, address;
+ boolean isStatic, isArrayBased;
+
+ /* Load the SWT library */
+ static {
+ Library.loadLibrary ("swt");
+ }
+
+/**
+ * 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) {
+
+ /* Set the callback fields */
+ this.object = object;
+ this.method = method;
+ this.argCount = argCount;
+ isStatic = object instanceof Class;
+ this.isArrayBased = isArrayBased;
+
+ /* Inline the common cases */
+ if (isArrayBased) {
+ signature = "([I)I";
+ } else {
+ switch (argCount) {
+ case 0: signature = "()I"; break;
+ case 1: signature = "(I)I"; break;
+ case 2: signature = "(II)I"; break;
+ case 3: signature = "(III)I"; break;
+ case 4: signature = "(IIII)I"; break;
+ default:
+ signature = "(";
+ for (int i=0; i<argCount; i++) signature += "I";
+ signature += ")I";
+ }
+ }
+
+ /* Bind the address */
+ address = bind (this);
+}
+
+/**
+ * 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
+ */
+static native synchronized int bind (Callback callback);
+
+/**
+ * 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 getAddress () {
+ return address;
+}
+
+/**
+ * Returns the SWT platform name.
+ *
+ * @return the platform name of the currently running SWT
+ */
+public static native String getPlatform ();
+
+/**
+ * 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 ignore true if callbacks should not 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
index 9804a02af7..633f2f2539 100755
--- 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
@@ -1,110 +1,110 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import java.io.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-public abstract class FileFormat {
- static final String FORMAT_PACKAGE = "org.eclipse.swt.internal.image";
- static final String FORMAT_SUFFIX = "FileFormat";
- static final String[] FORMATS = {"WinBMP", "WinBMP", "GIF", "WinICO", "JPEG", "PNG"};
-
- LEDataInputStream inputStream;
- LEDataOutputStream outputStream;
- ImageLoader loader;
- int compression;
-
-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;
-}
-
-/**
- * Return whether or not the specified input stream
- * represents a supported file format.
- */
-abstract boolean isFileFormat(LEDataInputStream stream);
-
-abstract ImageData[] loadFromByteStream();
-
-public ImageData[] loadFromStream(LEDataInputStream stream) {
- try {
- inputStream = stream;
- return loadFromByteStream();
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- return null;
- }
-}
-
-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);
-}
-
-public static void save(OutputStream os, int format, ImageLoader loader) {
- if (format < 0 || format >= FORMATS.length) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (FORMATS[format] == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- /* We do not currently support writing multi-image files,
- * so we use the first image data in the loader's array. */
- ImageData data = loader.data[0];
- 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_INVALID_ARGUMENT);
- }
- if (format == SWT.IMAGE_BMP_RLE) {
- switch (data.depth) {
- case 8: fileFormat.compression = 1; break;
- case 4: fileFormat.compression = 2; break;
- }
- }
- fileFormat.unloadIntoStream(data, stream);
-}
-
-abstract void unloadIntoByteStream(ImageData image);
-
-public void unloadIntoStream(ImageData image, LEDataOutputStream stream) {
- try {
- outputStream = stream;
- unloadIntoByteStream(image);
- outputStream.close();
- } catch (Exception e) {
- try {outputStream.close();} catch (Exception f) {}
- SWT.error(SWT.ERROR_IO, e);
- }
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import java.io.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+public abstract class FileFormat {
+ static final String FORMAT_PACKAGE = "org.eclipse.swt.internal.image";
+ static final String FORMAT_SUFFIX = "FileFormat";
+ static final String[] FORMATS = {"WinBMP", "WinBMP", "GIF", "WinICO", "JPEG", "PNG"};
+
+ LEDataInputStream inputStream;
+ LEDataOutputStream outputStream;
+ ImageLoader loader;
+ int compression;
+
+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;
+}
+
+/**
+ * Return whether or not the specified input stream
+ * represents a supported file format.
+ */
+abstract boolean isFileFormat(LEDataInputStream stream);
+
+abstract ImageData[] loadFromByteStream();
+
+public ImageData[] loadFromStream(LEDataInputStream stream) {
+ try {
+ inputStream = stream;
+ return loadFromByteStream();
+ } catch (Exception e) {
+ SWT.error(SWT.ERROR_IO, e);
+ return null;
+ }
+}
+
+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);
+}
+
+public static void save(OutputStream os, int format, ImageLoader loader) {
+ if (format < 0 || format >= FORMATS.length) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ if (FORMATS[format] == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+
+ /* We do not currently support writing multi-image files,
+ * so we use the first image data in the loader's array. */
+ ImageData data = loader.data[0];
+ 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_INVALID_ARGUMENT);
+ }
+ if (format == SWT.IMAGE_BMP_RLE) {
+ switch (data.depth) {
+ case 8: fileFormat.compression = 1; break;
+ case 4: fileFormat.compression = 2; break;
+ }
+ }
+ fileFormat.unloadIntoStream(data, stream);
+}
+
+abstract void unloadIntoByteStream(ImageData image);
+
+public void unloadIntoStream(ImageData image, LEDataOutputStream stream) {
+ try {
+ outputStream = stream;
+ unloadIntoByteStream(image);
+ outputStream.close();
+ } catch (Exception e) {
+ try {outputStream.close();} 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
index f63aa72196..8b62ec6fce 100755
--- 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
@@ -1,527 +1,527 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.io.*;
-
-final class GIFFileFormat extends FileFormat {
- String signature, version;
- boolean sorted;
- int screenWidth, screenHeight, backgroundPixel, aspect, bitsPerPixel, defaultDepth;
- boolean userInput = false;
- 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;
-
- /**
- * 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");
- } 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"))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
-
- inputStream.read(versionBytes);
- version = new String(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) {
- int colorIndex = controlBlock[3] & 0xFF;
- /* Work around: a customer has a GIF that specifies an
- * invalid color index that is larger than the number
- * of entries in the palette. Detect this case, and
- * ignore the specified color index. */
- if (colorIndex <= 1 << defaultDepth) {
- transparentPixel = colorIndex;
- }
- } 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) {
- 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;
- }
- // 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);
- }
-
- /**
- * Write the specified device independent image
- * to the output stream.
- */
- void unloadIntoByteStream(ImageData image) {
- if (!((image.depth == 1) || (image.depth == 4) || (image.depth == 8))) {
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
- byte bitField = (byte)((0x80 & 0xF8 & 0xF7 & 0x8F) + (image.depth - 1) + ((image.depth - 1) * 16));
- try {
- outputStream.write(new byte[] { (byte)'G', (byte)'I', (byte)'F' });
- outputStream.write(new byte[] { (byte)'8', (byte)'9', (byte)'a' });
- outputStream.writeShort((short)image.width);
- outputStream.writeShort((short)image.height);
- outputStream.writeByte(bitField);
- outputStream.writeByte((byte)0);
- outputStream.writeByte((byte)0);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- writePalette(image.palette, image.depth);
- if (image.transparentPixel != -1 || image.disposalMethod != 0 || image.delayTime != 0) {
- writeGraphicsControlBlock(image);
- }
- writeImageBlock(image);
- }
-
- /**
- * 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);
- outputStream.write(0x04); // size of block
- byte[] gcBlock = new byte[4];
- gcBlock[0] = (byte)0xFD;
- gcBlock[1] = 0;
- gcBlock[2] = 0;
- gcBlock[3] = 0;
- if (image.transparentPixel == -1) {
- gcBlock[0] = (byte)(gcBlock[0] & 0xFE);
- } else {
- gcBlock[0] = (byte)(gcBlock[0] | 0x01);
- gcBlock[3] = (byte)image.transparentPixel;
- }
- if (image.disposalMethod != 0) {
- gcBlock[0] = (byte)(gcBlock[0] | ((image.disposalMethod & 0x07) << 2));
- }
- if (image.delayTime != 0) {
- gcBlock[1] = (byte)(image.delayTime & 0xFF);
- gcBlock[2] = (byte)((image.delayTime >> 8) & 0xFF);
- }
- outputStream.write(gcBlock);
- outputStream.write(0); // block terminator
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-
- /**
- * Write the specified device independent image
- * to the current position in the output stream.
- */
- void writeImageBlock(ImageData image) {
- try {
- outputStream.write(GIF_IMAGE_BLOCK_ID);
- byte[] block = new byte[9];
- block[0] = (byte)(image.x & 0xFF);
- block[1] = (byte)((image.x >> 8) & 0xFF);
- block[2] = (byte)(image.y & 0xFF);
- block[3] = (byte)((image.y >> 8) & 0xFF);
- block[4] = (byte)(image.width & 0xFF);
- block[5] = (byte)((image.width >> 8) & 0xFF);
- block[6] = (byte)(image.height & 0xFF);
- block[7] = (byte)((image.height >> 8) & 0xFF);
- block[8] = 0; // no interlace, no sort, no local palette
- outputStream.write(block);
- outputStream.write(image.depth);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- new LZWCodec().encode(outputStream, image);
- }
-
- /**
- * 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);
- }
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import java.io.*;
+
+final class GIFFileFormat extends FileFormat {
+ String signature, version;
+ boolean sorted;
+ int screenWidth, screenHeight, backgroundPixel, aspect, bitsPerPixel, defaultDepth;
+ boolean userInput = false;
+ 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;
+
+ /**
+ * 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");
+ } 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"))
+ SWT.error(SWT.ERROR_INVALID_IMAGE);
+
+ inputStream.read(versionBytes);
+ version = new String(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) {
+ int colorIndex = controlBlock[3] & 0xFF;
+ /* Work around: a customer has a GIF that specifies an
+ * invalid color index that is larger than the number
+ * of entries in the palette. Detect this case, and
+ * ignore the specified color index. */
+ if (colorIndex <= 1 << defaultDepth) {
+ transparentPixel = colorIndex;
+ }
+ } 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) {
+ 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;
+ }
+ // 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);
+ }
+
+ /**
+ * Write the specified device independent image
+ * to the output stream.
+ */
+ void unloadIntoByteStream(ImageData image) {
+ if (!((image.depth == 1) || (image.depth == 4) || (image.depth == 8))) {
+ SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
+ }
+ byte bitField = (byte)((0x80 & 0xF8 & 0xF7 & 0x8F) + (image.depth - 1) + ((image.depth - 1) * 16));
+ try {
+ outputStream.write(new byte[] { (byte)'G', (byte)'I', (byte)'F' });
+ outputStream.write(new byte[] { (byte)'8', (byte)'9', (byte)'a' });
+ outputStream.writeShort((short)image.width);
+ outputStream.writeShort((short)image.height);
+ outputStream.writeByte(bitField);
+ outputStream.writeByte((byte)0);
+ outputStream.writeByte((byte)0);
+ } catch (IOException e) {
+ SWT.error(SWT.ERROR_IO, e);
+ }
+ writePalette(image.palette, image.depth);
+ if (image.transparentPixel != -1 || image.disposalMethod != 0 || image.delayTime != 0) {
+ writeGraphicsControlBlock(image);
+ }
+ writeImageBlock(image);
+ }
+
+ /**
+ * 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);
+ outputStream.write(0x04); // size of block
+ byte[] gcBlock = new byte[4];
+ gcBlock[0] = (byte)0xFD;
+ gcBlock[1] = 0;
+ gcBlock[2] = 0;
+ gcBlock[3] = 0;
+ if (image.transparentPixel == -1) {
+ gcBlock[0] = (byte)(gcBlock[0] & 0xFE);
+ } else {
+ gcBlock[0] = (byte)(gcBlock[0] | 0x01);
+ gcBlock[3] = (byte)image.transparentPixel;
+ }
+ if (image.disposalMethod != 0) {
+ gcBlock[0] = (byte)(gcBlock[0] | ((image.disposalMethod & 0x07) << 2));
+ }
+ if (image.delayTime != 0) {
+ gcBlock[1] = (byte)(image.delayTime & 0xFF);
+ gcBlock[2] = (byte)((image.delayTime >> 8) & 0xFF);
+ }
+ outputStream.write(gcBlock);
+ outputStream.write(0); // block terminator
+ } catch (IOException e) {
+ SWT.error(SWT.ERROR_IO, e);
+ }
+ }
+
+ /**
+ * Write the specified device independent image
+ * to the current position in the output stream.
+ */
+ void writeImageBlock(ImageData image) {
+ try {
+ outputStream.write(GIF_IMAGE_BLOCK_ID);
+ byte[] block = new byte[9];
+ block[0] = (byte)(image.x & 0xFF);
+ block[1] = (byte)((image.x >> 8) & 0xFF);
+ block[2] = (byte)(image.y & 0xFF);
+ block[3] = (byte)((image.y >> 8) & 0xFF);
+ block[4] = (byte)(image.width & 0xFF);
+ block[5] = (byte)((image.width >> 8) & 0xFF);
+ block[6] = (byte)(image.height & 0xFF);
+ block[7] = (byte)((image.height >> 8) & 0xFF);
+ block[8] = 0; // no interlace, no sort, no local palette
+ outputStream.write(block);
+ outputStream.write(image.depth);
+ } catch (IOException e) {
+ SWT.error(SWT.ERROR_IO, e);
+ }
+ new LZWCodec().encode(outputStream, image);
+ }
+
+ /**
+ * 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
index 9598910863..82046aef0e 100755
--- 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
@@ -1,24 +1,24 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index 6fe82d3ecb..f0ce9f436b 100755
--- 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
@@ -1,19 +1,19 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-final class JPEGArithmeticConditioningTable extends JPEGVariableSizeSegment {
-
- public JPEGArithmeticConditioningTable(LEDataInputStream byteStream) {
- super(byteStream);
- }
-
- public int signature() {
- return JPEGFileFormat.DAC;
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index 7348adeea8..e5bfffa4d8 100755
--- 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
@@ -1,23 +1,23 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-final class JPEGComment extends JPEGVariableSizeSegment {
-
- public JPEGComment(byte[] reference) {
- super(reference);
- }
-
- public JPEGComment(LEDataInputStream byteStream) {
- super(byteStream);
- }
-
- public int signature() {
- return JPEGFileFormat.COM;
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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/JPEGEndOfImage.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/JPEGEndOfImage.java
index 354ed570e8..a70ca5f919 100755
--- 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
@@ -1,27 +1,27 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index 407ec66238..1370110464 100755
--- 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
@@ -1,1892 +1,1892 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- JPEGArithmeticConditioningTable arithmeticTables;
- JPEGHuffmanTable[] acHuffmanTables;
- JPEGHuffmanTable[] dcHuffmanTables;
- int[][] quantizationTables;
- int currentByte;
- int decoderQFactor;
- 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 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 / 65536);
- if ((n < 0) && (n % 65536 != 0)) yComp[i]--;
- n = RCbTable[r] + GCbTable[g] + BCbTable[b];
- cbComp[i] = (byte)(n / 65536);
- if ((n < 0) && (n % 65536 != 0)) cbComp[i]--;
- n = RCrTable[r] + GCrTable[g] + BCrTable[b];
- crComp[i] = (byte)(n / 65536);
- if ((n < 0) && (n % 65536 != 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;
- for (int yPos = 0; yPos < srcHeight; yPos++) {
- for (int xPos = 0; xPos < srcWidth / 2; xPos++) {
- int srcIndex = yPos * (srcWidth / 2) + xPos;
- int dstIndex = yPos * srcWidth + (xPos * 2);
- int value2 = origData[srcIndex] & 0xFF;
- int value1 = value2 / 16;
- value2 = value2 % 16;
- 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 / 65536);
- if ((n < 0) && (n % 65536 != 0)) yComp[i]--;
- n = RCbTable[r] + GCbTable[g] + BCbTable[b];
- cbComp[i] = (byte)(n / 65536);
- if ((n < 0) && (n % 65536 != 0)) cbComp[i]--;
- n = RCrTable[r] + GCrTable[g] + BCrTable[b];
- crComp[i] = (byte)(n / 65536);
- if ((n < 0) && (n % 65536 != 0)) crComp[i]--;
- }
- int dstWidth = image.width;
- int dstHeight = srcHeight;
- int stride = (srcWidth + 3) / 4 * 4;
- 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]) / 65536);
- dataCbComp[dstDataIndex] = (byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) / 65536);
- dataCrComp[dstDataIndex] = (byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) / 65536);
- }
- }
- } 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]) / 65536);
- dataCbComp[dstDataIndex] = (byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) / 65536);
- dataCrComp[dstDataIndex] = (byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) / 65536);
- }
- }
- }
- 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]) / 65536);
- 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;
-}
-byte[] convertYIQToRGB() {
- /* Unsupported CMYK format. Answer an empty byte array. */
- return new byte[0];
-}
-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 = ac + (1 << approxBit);
- }
- } else if (ac < 0) {
- int bit = nextBit();
- if (bit != 0) {
- ac = 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 = 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() {
- int[] compIds = new int[nComponents];
- int compIdsIndex = 0;
- for (int i = 0; i < nComponents; i++) {
- compIds[compIdsIndex] = i + 1;
- compIdsIndex++;
- }
- if ((compIds.length == 3) &&
- (compIds[0] == 1) &&
- (compIds[1] == 2) &&
- (compIds[2] == 3)) {
- return convertYCbCrToRGB();
- }
- if ((compIds.length == 3) &&
- (compIds[0] == 1) &&
- (compIds[1] == 4) &&
- (compIds[2] == 5)) {
- return convertYIQToRGB();
- }
- if (compIds.length == 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];
- j = j + 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 % 256);
- codeBuffer[1] = (byte)((code / 256) % 256);
- codeBuffer[2] = (byte)((code / 65536) % 256);
- codeBuffer[3] = (byte)((code / 16777216) % 256);
- int abs = nBits - (8 - currentBitCount);
- if (abs < 0) abs = -abs;
- if ((abs / 8) > 0) {
- currentByte += codeBuffer[2];
- emitByte((byte)currentByte);
- emitByte((byte)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;
- RGB[] rgbs = 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),
- };
- ImageData src = new ImageData(compWidth, compHeight, 8, new PaletteData(rgbs), 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 scaleFactor1 = ExtendTest[11];
- int scaleFactor2 = ExtendTest[12];
- int n = z1 + (tmp13 * FIX_0_765366865) + scaleFactor1;
- dataUnit[rIndex + 2] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 2]--;
- n = z1 + (tmp12 * (0 - FIX_1_847759065)) + scaleFactor1;
- dataUnit[rIndex + 6] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 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 = tmp4 * FIX_0_298631336; // sqrt(2) * (-c1+c3+c5-c7)
- tmp5 = tmp5 * FIX_2_053119869; // sqrt(2) * ( c1+c3-c5+c7)
- tmp6 = tmp6 * FIX_3_072711026; // sqrt(2) * ( c1+c3+c5-c7)
- tmp7 = tmp7 * FIX_1_501321110; // sqrt(2) * ( c1+c3-c5-c7)
- z1 = z1 * (0 - FIX_0_899976223); // sqrt(2) * (c7-c3)
- z2 = z2 * (0 - FIX_2_562915447); // sqrt(2) * (-c1-c3)
- z3 = z3 * (0 - FIX_1_961570560); // sqrt(2) * (-c3-c5)
- z4 = z4 * (0 - FIX_0_390180644); // sqrt(2) * (c5-c3)
-
- z3 = z3 + z5;
- z4 = z4 + z5;
-
- n = tmp4 + z1 + z3 + scaleFactor1;
- dataUnit[rIndex + 7] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 7]--;
- n = tmp5 + z2 + z4 + scaleFactor1;
- dataUnit[rIndex + 5] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 5]--;
- n = tmp6 + z2 + z3 + scaleFactor1;
- dataUnit[rIndex + 3] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 3]--;
- n = tmp7 + z1 + z4 + scaleFactor1;
- dataUnit[rIndex + 1] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 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 scaleFactor1 = ExtendTest[5];
- int scaleFactor2 = ExtendTest[6];
- int n = tmp10 + tmp11 + scaleFactor1;
- dataUnit[c0] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c0]--;
- n = tmp10 - tmp11 + scaleFactor1;
- dataUnit[c4] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c4]--;
-
- int z1 = (tmp12 + tmp13) * FIX_0_541196100;
- scaleFactor1 = ExtendTest[18];
- scaleFactor2 = ExtendTest[19];
- n = z1 + (tmp13 * FIX_0_765366865) + scaleFactor1;
- dataUnit[c2] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c2]--;
- n = z1 + (tmp12 * (0 - FIX_1_847759065)) + scaleFactor1;
- dataUnit[c6] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 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 = tmp4 * FIX_0_298631336; // sqrt(2) * (-c1+c3+c5-c7)
- tmp5 = tmp5 * FIX_2_053119869; // sqrt(2) * ( c1+c3-c5+c7)
- tmp6 = tmp6 * FIX_3_072711026; // sqrt(2) * ( c1+c3+c5-c7)
- tmp7 = tmp7 * FIX_1_501321110; // sqrt(2) * ( c1+c3-c5-c7)
- z1 = z1 * (0 - FIX_0_899976223); // sqrt(2) * (c7-c3)
- z2 = z2 * (0 - FIX_2_562915447); // sqrt(2) * (-c1-c3)
- z3 = z3 * (0 - FIX_1_961570560); // sqrt(2) * (-c3-c5)
- z4 = z4 * (0 - FIX_0_390180644); // sqrt(2) * (c5-c3)
-
- z3 = z3 + z5;
- z4 = z4 + z5;
-
- n = tmp4 + z1 + z3 + scaleFactor1;
- dataUnit[c7] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c7]--;
- n = tmp5 + z2 + z4 + scaleFactor1;
- dataUnit[c5] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c5]--;
- n = tmp6 + z2 + z3 + scaleFactor1;
- dataUnit[c3] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c3]--;
- n = tmp7 + z1 + z4 + scaleFactor1;
- dataUnit[c1] = n / scaleFactor2;
- if ((n < 0) && (n % scaleFactor2 != 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() {
- JPEGArithmeticConditioningTable dac = new JPEGArithmeticConditioningTable(inputStream);
- arithmeticTables = dac;
-}
-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) / 65536;
- CbBTable[i] = (58065 * x2 + 32768) / 65536;
- 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] * 4;
- for (int i = rIndex; i < rIndex + 8; 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]) * 8192;
- int tmp1 = (dataUnit[rIndex] - dataUnit[rIndex + 4]) * 8192;
- 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 = tmp0 * FIX_0_298631336; /* sqrt(2) * (-c1+c3+c5-c7) */
- tmp1 = tmp1 * FIX_2_053119869; /* sqrt(2) * ( c1+c3-c5+c7) */
- tmp2 = tmp2 * FIX_3_072711026; /* sqrt(2) * ( c1+c3+c5-c7) */
- tmp3 = tmp3 * FIX_1_501321110; /* sqrt(2) * ( c1+c3-c5-c7) */
- z1 = z1 * (0 - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
- z2 = z2 * (0 - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
- z3 = z3 * (0 - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
- z4 = z4 * (0 - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
-
- z3 = z3 + z5;
- z4 = z4 + z5;
- tmp0 = tmp0 + z1 + z3;
- tmp1 = tmp1 + z2 + z4;
- tmp2 = tmp2 + z2 + z3;
- tmp3 = tmp3 + z1 + z4;
-
- int descaleFactor1 = ExtendTest[11];
- int descaleFactor2 = ExtendTest[12];
- dataUnit[rIndex] = (tmp10 + tmp3 + descaleFactor1) / descaleFactor2;
- dataUnit[rIndex + 7] = (tmp10 - tmp3 + descaleFactor1) / descaleFactor2;
- dataUnit[rIndex + 1] = (tmp11 + tmp2 + descaleFactor1) / descaleFactor2;
- dataUnit[rIndex + 6] = (tmp11 - tmp2 + descaleFactor1) / descaleFactor2;
- dataUnit[rIndex + 2] = (tmp12 + tmp1 + descaleFactor1) / descaleFactor2;
- dataUnit[rIndex + 5] = (tmp12 - tmp1 + descaleFactor1) / descaleFactor2;
- dataUnit[rIndex + 3] = (tmp13 + tmp0 + descaleFactor1) / descaleFactor2;
- dataUnit[rIndex + 4] = (tmp13 - tmp0 + descaleFactor1) / descaleFactor2;
- }
- }
- /**
- * 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) / 32;
- 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 z2 = dataUnit[c2];
- int z3 = dataUnit[c6];
- 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[c0] + dataUnit[c4]) * 8192;
- int tmp1 = (dataUnit[c0] - dataUnit[c4]) * 8192;
- 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;
- int z4 = tmp1 + tmp3;
- int z5 = (z3 + z4) * FIX_1_175875602; /* sqrt(2) * c3 */
-
- tmp0 = tmp0 * FIX_0_298631336; /* sqrt(2) * (-c1+c3+c5-c7) */
- tmp1 = tmp1 * FIX_2_053119869; /* sqrt(2) * ( c1+c3-c5+c7) */
- tmp2 = tmp2 * FIX_3_072711026; /* sqrt(2) * ( c1+c3+c5-c7) */
- tmp3 = tmp3 * FIX_1_501321110; /* sqrt(2) * ( c1+c3-c5-c7) */
- z1 = z1 * (0 - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
- z2 = z2 * (0 - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
- z3 = z3 * (0 - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
- z4 = z4 * (0 - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
-
- z3 = z3 + z5;
- z4 = z4 + z5;
-
- tmp0 = tmp0 + z1 + z3;
- tmp1 = tmp1 + z2 + z4;
- tmp2 = tmp2 + z2 + z3;
- tmp3 = tmp3 + z1 + z4;
-
- /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
- int descaleFactor1 = ExtendTest[18];
- int descaleFactor2 = ExtendTest[19];
- dataUnit[c0] = (tmp10 + tmp3 + descaleFactor1) / descaleFactor2;
- dataUnit[c7] = (tmp10 - tmp3 + descaleFactor1) / descaleFactor2;
- dataUnit[c1] = (tmp11 + tmp2 + descaleFactor1) / descaleFactor2;
- dataUnit[c6] = (tmp11 - tmp2 + descaleFactor1) / descaleFactor2;
- dataUnit[c2] = (tmp12 + tmp1 + descaleFactor1) / descaleFactor2;
- dataUnit[c5] = (tmp12 - tmp1 + descaleFactor1) / descaleFactor2;
- dataUnit[c3] = (tmp13 + tmp0 + descaleFactor1) / descaleFactor2;
- dataUnit[c4] = (tmp13 - tmp0 + descaleFactor1) / descaleFactor2;
- }
- }
-}
-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] + dataUnit[col + 16] +
- dataUnit[col + 24] + dataUnit[col + 32] +
- dataUnit[col + 40] + dataUnit[col + 48] +
- dataUnit[col + 56]) == 0;
-}
-boolean isZeroInRow(int[] dataUnit, int rIndex) {
- return (dataUnit[rIndex + 1] + dataUnit[rIndex + 2] +
- dataUnit[rIndex + 3] + dataUnit[rIndex + 4] +
- dataUnit[rIndex + 5] + dataUnit[rIndex + 6] +
- dataUnit[rIndex + 7]) == 0;
-}
-ImageData[] loadFromByteStream() {
- 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);
- }
- }
- }
- }
- }
- }
- 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) % 256)) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- bufferCurrentPosition++;
- if (bufferCurrentPosition > 511) {
- resetInputBuffer();
- bufferCurrentPosition = 0;
- }
- currentByte = dataBuffer[bufferCurrentPosition] & 0xFF;
- currentBitCount = 8;
- restartsToGo = restartInterval;
- nextRestartNumber = (nextRestartNumber + 1) % 8;
- 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 / 2;
- 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) {
- throw new SWTError(SWT.ERROR_INVALID_IMAGE);
- }
- if (!(byteArray[0] == -1 && byteArray[1] != 0 && byteArray[1] != -1)) {
- throw new SWTError(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(ImageData image) {
- 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);
- }
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+ JPEGArithmeticConditioningTable arithmeticTables;
+ JPEGHuffmanTable[] acHuffmanTables;
+ JPEGHuffmanTable[] dcHuffmanTables;
+ int[][] quantizationTables;
+ int currentByte;
+ int decoderQFactor;
+ 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 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 / 65536);
+ if ((n < 0) && (n % 65536 != 0)) yComp[i]--;
+ n = RCbTable[r] + GCbTable[g] + BCbTable[b];
+ cbComp[i] = (byte)(n / 65536);
+ if ((n < 0) && (n % 65536 != 0)) cbComp[i]--;
+ n = RCrTable[r] + GCrTable[g] + BCrTable[b];
+ crComp[i] = (byte)(n / 65536);
+ if ((n < 0) && (n % 65536 != 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;
+ for (int yPos = 0; yPos < srcHeight; yPos++) {
+ for (int xPos = 0; xPos < srcWidth / 2; xPos++) {
+ int srcIndex = yPos * (srcWidth / 2) + xPos;
+ int dstIndex = yPos * srcWidth + (xPos * 2);
+ int value2 = origData[srcIndex] & 0xFF;
+ int value1 = value2 / 16;
+ value2 = value2 % 16;
+ 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 / 65536);
+ if ((n < 0) && (n % 65536 != 0)) yComp[i]--;
+ n = RCbTable[r] + GCbTable[g] + BCbTable[b];
+ cbComp[i] = (byte)(n / 65536);
+ if ((n < 0) && (n % 65536 != 0)) cbComp[i]--;
+ n = RCrTable[r] + GCrTable[g] + BCrTable[b];
+ crComp[i] = (byte)(n / 65536);
+ if ((n < 0) && (n % 65536 != 0)) crComp[i]--;
+ }
+ int dstWidth = image.width;
+ int dstHeight = srcHeight;
+ int stride = (srcWidth + 3) / 4 * 4;
+ 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]) / 65536);
+ dataCbComp[dstDataIndex] = (byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) / 65536);
+ dataCrComp[dstDataIndex] = (byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) / 65536);
+ }
+ }
+ } 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]) / 65536);
+ dataCbComp[dstDataIndex] = (byte)((RCbTable[r] + GCbTable[g] + BCbTable[b]) / 65536);
+ dataCrComp[dstDataIndex] = (byte)((RCrTable[r] + GCrTable[g] + BCrTable[b]) / 65536);
+ }
+ }
+ }
+ 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]) / 65536);
+ 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;
+}
+byte[] convertYIQToRGB() {
+ /* Unsupported CMYK format. Answer an empty byte array. */
+ return new byte[0];
+}
+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 = ac + (1 << approxBit);
+ }
+ } else if (ac < 0) {
+ int bit = nextBit();
+ if (bit != 0) {
+ ac = 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 = 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() {
+ int[] compIds = new int[nComponents];
+ int compIdsIndex = 0;
+ for (int i = 0; i < nComponents; i++) {
+ compIds[compIdsIndex] = i + 1;
+ compIdsIndex++;
+ }
+ if ((compIds.length == 3) &&
+ (compIds[0] == 1) &&
+ (compIds[1] == 2) &&
+ (compIds[2] == 3)) {
+ return convertYCbCrToRGB();
+ }
+ if ((compIds.length == 3) &&
+ (compIds[0] == 1) &&
+ (compIds[1] == 4) &&
+ (compIds[2] == 5)) {
+ return convertYIQToRGB();
+ }
+ if (compIds.length == 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];
+ j = j + 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 % 256);
+ codeBuffer[1] = (byte)((code / 256) % 256);
+ codeBuffer[2] = (byte)((code / 65536) % 256);
+ codeBuffer[3] = (byte)((code / 16777216) % 256);
+ int abs = nBits - (8 - currentBitCount);
+ if (abs < 0) abs = -abs;
+ if ((abs / 8) > 0) {
+ currentByte += codeBuffer[2];
+ emitByte((byte)currentByte);
+ emitByte((byte)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;
+ RGB[] rgbs = 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),
+ };
+ ImageData src = new ImageData(compWidth, compHeight, 8, new PaletteData(rgbs), 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 scaleFactor1 = ExtendTest[11];
+ int scaleFactor2 = ExtendTest[12];
+ int n = z1 + (tmp13 * FIX_0_765366865) + scaleFactor1;
+ dataUnit[rIndex + 2] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 2]--;
+ n = z1 + (tmp12 * (0 - FIX_1_847759065)) + scaleFactor1;
+ dataUnit[rIndex + 6] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 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 = tmp4 * FIX_0_298631336; // sqrt(2) * (-c1+c3+c5-c7)
+ tmp5 = tmp5 * FIX_2_053119869; // sqrt(2) * ( c1+c3-c5+c7)
+ tmp6 = tmp6 * FIX_3_072711026; // sqrt(2) * ( c1+c3+c5-c7)
+ tmp7 = tmp7 * FIX_1_501321110; // sqrt(2) * ( c1+c3-c5-c7)
+ z1 = z1 * (0 - FIX_0_899976223); // sqrt(2) * (c7-c3)
+ z2 = z2 * (0 - FIX_2_562915447); // sqrt(2) * (-c1-c3)
+ z3 = z3 * (0 - FIX_1_961570560); // sqrt(2) * (-c3-c5)
+ z4 = z4 * (0 - FIX_0_390180644); // sqrt(2) * (c5-c3)
+
+ z3 = z3 + z5;
+ z4 = z4 + z5;
+
+ n = tmp4 + z1 + z3 + scaleFactor1;
+ dataUnit[rIndex + 7] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 7]--;
+ n = tmp5 + z2 + z4 + scaleFactor1;
+ dataUnit[rIndex + 5] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 5]--;
+ n = tmp6 + z2 + z3 + scaleFactor1;
+ dataUnit[rIndex + 3] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[rIndex + 3]--;
+ n = tmp7 + z1 + z4 + scaleFactor1;
+ dataUnit[rIndex + 1] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 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 scaleFactor1 = ExtendTest[5];
+ int scaleFactor2 = ExtendTest[6];
+ int n = tmp10 + tmp11 + scaleFactor1;
+ dataUnit[c0] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c0]--;
+ n = tmp10 - tmp11 + scaleFactor1;
+ dataUnit[c4] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c4]--;
+
+ int z1 = (tmp12 + tmp13) * FIX_0_541196100;
+ scaleFactor1 = ExtendTest[18];
+ scaleFactor2 = ExtendTest[19];
+ n = z1 + (tmp13 * FIX_0_765366865) + scaleFactor1;
+ dataUnit[c2] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c2]--;
+ n = z1 + (tmp12 * (0 - FIX_1_847759065)) + scaleFactor1;
+ dataUnit[c6] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 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 = tmp4 * FIX_0_298631336; // sqrt(2) * (-c1+c3+c5-c7)
+ tmp5 = tmp5 * FIX_2_053119869; // sqrt(2) * ( c1+c3-c5+c7)
+ tmp6 = tmp6 * FIX_3_072711026; // sqrt(2) * ( c1+c3+c5-c7)
+ tmp7 = tmp7 * FIX_1_501321110; // sqrt(2) * ( c1+c3-c5-c7)
+ z1 = z1 * (0 - FIX_0_899976223); // sqrt(2) * (c7-c3)
+ z2 = z2 * (0 - FIX_2_562915447); // sqrt(2) * (-c1-c3)
+ z3 = z3 * (0 - FIX_1_961570560); // sqrt(2) * (-c3-c5)
+ z4 = z4 * (0 - FIX_0_390180644); // sqrt(2) * (c5-c3)
+
+ z3 = z3 + z5;
+ z4 = z4 + z5;
+
+ n = tmp4 + z1 + z3 + scaleFactor1;
+ dataUnit[c7] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c7]--;
+ n = tmp5 + z2 + z4 + scaleFactor1;
+ dataUnit[c5] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c5]--;
+ n = tmp6 + z2 + z3 + scaleFactor1;
+ dataUnit[c3] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 0)) dataUnit[c3]--;
+ n = tmp7 + z1 + z4 + scaleFactor1;
+ dataUnit[c1] = n / scaleFactor2;
+ if ((n < 0) && (n % scaleFactor2 != 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() {
+ JPEGArithmeticConditioningTable dac = new JPEGArithmeticConditioningTable(inputStream);
+ arithmeticTables = dac;
+}
+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) / 65536;
+ CbBTable[i] = (58065 * x2 + 32768) / 65536;
+ 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] * 4;
+ for (int i = rIndex; i < rIndex + 8; 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]) * 8192;
+ int tmp1 = (dataUnit[rIndex] - dataUnit[rIndex + 4]) * 8192;
+ 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 = tmp0 * FIX_0_298631336; /* sqrt(2) * (-c1+c3+c5-c7) */
+ tmp1 = tmp1 * FIX_2_053119869; /* sqrt(2) * ( c1+c3-c5+c7) */
+ tmp2 = tmp2 * FIX_3_072711026; /* sqrt(2) * ( c1+c3+c5-c7) */
+ tmp3 = tmp3 * FIX_1_501321110; /* sqrt(2) * ( c1+c3-c5-c7) */
+ z1 = z1 * (0 - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
+ z2 = z2 * (0 - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
+ z3 = z3 * (0 - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
+ z4 = z4 * (0 - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
+
+ z3 = z3 + z5;
+ z4 = z4 + z5;
+ tmp0 = tmp0 + z1 + z3;
+ tmp1 = tmp1 + z2 + z4;
+ tmp2 = tmp2 + z2 + z3;
+ tmp3 = tmp3 + z1 + z4;
+
+ int descaleFactor1 = ExtendTest[11];
+ int descaleFactor2 = ExtendTest[12];
+ dataUnit[rIndex] = (tmp10 + tmp3 + descaleFactor1) / descaleFactor2;
+ dataUnit[rIndex + 7] = (tmp10 - tmp3 + descaleFactor1) / descaleFactor2;
+ dataUnit[rIndex + 1] = (tmp11 + tmp2 + descaleFactor1) / descaleFactor2;
+ dataUnit[rIndex + 6] = (tmp11 - tmp2 + descaleFactor1) / descaleFactor2;
+ dataUnit[rIndex + 2] = (tmp12 + tmp1 + descaleFactor1) / descaleFactor2;
+ dataUnit[rIndex + 5] = (tmp12 - tmp1 + descaleFactor1) / descaleFactor2;
+ dataUnit[rIndex + 3] = (tmp13 + tmp0 + descaleFactor1) / descaleFactor2;
+ dataUnit[rIndex + 4] = (tmp13 - tmp0 + descaleFactor1) / descaleFactor2;
+ }
+ }
+ /**
+ * 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) / 32;
+ 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 z2 = dataUnit[c2];
+ int z3 = dataUnit[c6];
+ 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[c0] + dataUnit[c4]) * 8192;
+ int tmp1 = (dataUnit[c0] - dataUnit[c4]) * 8192;
+ 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;
+ int z4 = tmp1 + tmp3;
+ int z5 = (z3 + z4) * FIX_1_175875602; /* sqrt(2) * c3 */
+
+ tmp0 = tmp0 * FIX_0_298631336; /* sqrt(2) * (-c1+c3+c5-c7) */
+ tmp1 = tmp1 * FIX_2_053119869; /* sqrt(2) * ( c1+c3-c5+c7) */
+ tmp2 = tmp2 * FIX_3_072711026; /* sqrt(2) * ( c1+c3+c5-c7) */
+ tmp3 = tmp3 * FIX_1_501321110; /* sqrt(2) * ( c1+c3-c5-c7) */
+ z1 = z1 * (0 - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
+ z2 = z2 * (0 - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
+ z3 = z3 * (0 - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
+ z4 = z4 * (0 - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
+
+ z3 = z3 + z5;
+ z4 = z4 + z5;
+
+ tmp0 = tmp0 + z1 + z3;
+ tmp1 = tmp1 + z2 + z4;
+ tmp2 = tmp2 + z2 + z3;
+ tmp3 = tmp3 + z1 + z4;
+
+ /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
+ int descaleFactor1 = ExtendTest[18];
+ int descaleFactor2 = ExtendTest[19];
+ dataUnit[c0] = (tmp10 + tmp3 + descaleFactor1) / descaleFactor2;
+ dataUnit[c7] = (tmp10 - tmp3 + descaleFactor1) / descaleFactor2;
+ dataUnit[c1] = (tmp11 + tmp2 + descaleFactor1) / descaleFactor2;
+ dataUnit[c6] = (tmp11 - tmp2 + descaleFactor1) / descaleFactor2;
+ dataUnit[c2] = (tmp12 + tmp1 + descaleFactor1) / descaleFactor2;
+ dataUnit[c5] = (tmp12 - tmp1 + descaleFactor1) / descaleFactor2;
+ dataUnit[c3] = (tmp13 + tmp0 + descaleFactor1) / descaleFactor2;
+ dataUnit[c4] = (tmp13 - tmp0 + descaleFactor1) / descaleFactor2;
+ }
+ }
+}
+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] + dataUnit[col + 16] +
+ dataUnit[col + 24] + dataUnit[col + 32] +
+ dataUnit[col + 40] + dataUnit[col + 48] +
+ dataUnit[col + 56]) == 0;
+}
+boolean isZeroInRow(int[] dataUnit, int rIndex) {
+ return (dataUnit[rIndex + 1] + dataUnit[rIndex + 2] +
+ dataUnit[rIndex + 3] + dataUnit[rIndex + 4] +
+ dataUnit[rIndex + 5] + dataUnit[rIndex + 6] +
+ dataUnit[rIndex + 7]) == 0;
+}
+ImageData[] loadFromByteStream() {
+ 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);
+ }
+ }
+ }
+ }
+ }
+ }
+ 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) % 256)) {
+ SWT.error(SWT.ERROR_INVALID_IMAGE);
+ }
+ bufferCurrentPosition++;
+ if (bufferCurrentPosition > 511) {
+ resetInputBuffer();
+ bufferCurrentPosition = 0;
+ }
+ currentByte = dataBuffer[bufferCurrentPosition] & 0xFF;
+ currentBitCount = 8;
+ restartsToGo = restartInterval;
+ nextRestartNumber = (nextRestartNumber + 1) % 8;
+ 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 / 2;
+ 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) {
+ throw new SWTError(SWT.ERROR_INVALID_IMAGE);
+ }
+ if (!(byteArray[0] == -1 && byteArray[1] != 0 && byteArray[1] != -1)) {
+ throw new SWTError(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(ImageData image) {
+ 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
index 3f168acba1..13c7482385 100755
--- 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
@@ -1,40 +1,40 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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) {
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index 59a1af75e4..c5e4106c08 100755
--- 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
@@ -1,210 +1,210 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 - 1;
- int hi = (reference[ofs + 1] & 0xFF) / 16;
- int vi = (reference[ofs + 1] & 0xFF) % 16;
- 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][];
- System.arraycopy(compSpecParams, 0, newParams, 0, compSpecParams.length);
- compSpecParams = newParams;
- }
- compSpecParams[ci - 1] = 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;
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 - 1;
+ int hi = (reference[ofs + 1] & 0xFF) / 16;
+ int vi = (reference[ofs + 1] & 0xFF) % 16;
+ 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][];
+ System.arraycopy(compSpecParams, 0, newParams, 0, compSpecParams.length);
+ compSpecParams = newParams;
+ }
+ compSpecParams[ci - 1] = 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
index 55f9c581b5..7990ff5583 100755
--- 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
@@ -1,264 +1,264 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * 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[] dhCodes;
- int[] dhCodeLengths;
- 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) / 16; // table class: AC (1) or DC (0)
- int tid = (reference[ofs] & 0xFF) % 16; // 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.dhCodes = huffCodes;
- dhtTable.dhCodeLengths = huffCodeLengths;
- 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;
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * 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[] dhCodes;
+ int[] dhCodeLengths;
+ 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) / 16; // table class: AC (1) or DC (0)
+ int tid = (reference[ofs] & 0xFF) % 16; // 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.dhCodes = huffCodes;
+ dhtTable.dhCodeLengths = huffCodeLengths;
+ 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
index f5c5911914..a41b1d1d7d 100755
--- 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
@@ -1,161 +1,161 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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] & 0xFF) % 16;
- int pq = (reference[ofs] & 0xFF) / 16;
- 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) / 16;
- if (pq == 0) {
- for (int i = 0; i < qk.length; i++) {
- qk[i] = reference[ofs + i + 1];
- }
- 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) % 16;
- int pq = (reference[ofs] & 0xFF) / 16;
- 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 / 256);
- reference[i + 1] = (byte)(temp % 256);
- }
- ofs += 129;
- totalLength -= 129;
- }
- }
-}
-
-public int signature() {
- return JPEGFileFormat.DQT;
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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] & 0xFF) % 16;
+ int pq = (reference[ofs] & 0xFF) / 16;
+ 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) / 16;
+ if (pq == 0) {
+ for (int i = 0; i < qk.length; i++) {
+ qk[i] = reference[ofs + i + 1];
+ }
+ 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) % 16;
+ int pq = (reference[ofs] & 0xFF) / 16;
+ 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 / 256);
+ reference[i + 1] = (byte)(temp % 256);
+ }
+ 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
index 4facb96066..c97510a3a8 100755
--- 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
@@ -1,27 +1,27 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index e69a1eaa1c..604d237d61 100755
--- 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
@@ -1,119 +1,119 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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] & 0xFF) / 16;
-}
-
-public int getApproxBitPositionLow() {
- return (reference[(2 * getNumberOfImageComponents()) + 7] & 0xFF) % 16;
-}
-
-public int getEndOfSpectralSelection() {
- return (reference[(2 * getNumberOfImageComponents()) + 6] & 0xFF);
-}
-
-public int getNumberOfImageComponents() {
- return (reference[4] & 0xFF);
-}
-
-public int getStartOfSpectralSelection() {
- return (reference[(2 * getNumberOfImageComponents()) + 5] & 0xFF);
-}
-
-/* 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) / 16;
- int ac = (reference[ofs + 1] & 0xFF) % 16;
- if (componentParameters.length < cid) {
- int[][] newParams = new int[cid][];
- System.arraycopy(componentParameters, 0, newParams, 0, componentParameters.length);
- componentParameters = newParams;
- }
- componentParameters[cid - 1] = 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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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] & 0xFF) / 16;
+}
+
+public int getApproxBitPositionLow() {
+ return (reference[(2 * getNumberOfImageComponents()) + 7] & 0xFF) % 16;
+}
+
+public int getEndOfSpectralSelection() {
+ return (reference[(2 * getNumberOfImageComponents()) + 6] & 0xFF);
+}
+
+public int getNumberOfImageComponents() {
+ return (reference[4] & 0xFF);
+}
+
+public int getStartOfSpectralSelection() {
+ return (reference[(2 * getNumberOfImageComponents()) + 5] & 0xFF);
+}
+
+/* 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) / 16;
+ int ac = (reference[ofs + 1] & 0xFF) % 16;
+ if (componentParameters.length < cid) {
+ int[][] newParams = new int[cid][];
+ System.arraycopy(componentParameters, 0, newParams, 0, componentParameters.length);
+ componentParameters = newParams;
+ }
+ componentParameters[cid - 1] = 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
index 49ce0e2084..19a986cf0e 100755
--- 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
@@ -1,54 +1,54 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- }
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index d37e024c90..8ea7052946 100755
--- 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
@@ -1,31 +1,31 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index 458ea134d9..ab43a9fde8 100755
--- 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
@@ -1,34 +1,34 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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);
- }
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index 15b7345b9e..d1b2d38393 100755
--- 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
@@ -1,181 +1,181 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 result;
- int left = len;
- result = readData(b, off, len);
- while (true) {
- if (result == -1) return -1;
- position += result;
- if (result == left) return len;
- left -= result;
- off += result;
- result = readData(b, off, left);
- }
- }
-
- /**
- * 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);
- }
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 result;
+ int left = len;
+ result = readData(b, off, len);
+ while (true) {
+ if (result == -1) return -1;
+ position += result;
+ if (result == left) return len;
+ left -= result;
+ off += result;
+ result = readData(b, off, left);
+ }
+ }
+
+ /**
+ * 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);
+ }
} \ No newline at end of file
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
index 96847dab59..b8a8359145 100755
--- 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
@@ -1,53 +1,53 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import java.io.*;
-
-final class LEDataOutputStream extends OutputStream {
- OutputStream out;
-public LEDataOutputStream(OutputStream output) {
- this.out = output;
-}
-public void close() throws IOException {
- out.close();
-}
-public void write(byte b[], int off, int len) throws IOException {
- out.write(b, off, len);
-}
-/**
- * Answer the next byte of the input stream.
- */
-public void write(int b) throws IOException {
- out.write(b);
-}
-/**
- * Answer the next byte of the input stream.
- */
-public void writeByte(byte b) throws IOException {
- out.write(b & 0xFF);
-}
-/**
- * Answer an integer comprised of the next
- * four bytes of the input 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);
-}
-/**
- * Answer an integer comprised of the next
- * two bytes of the input stream.
- */
-public void writeShort(int theShort) throws IOException {
- out.write(theShort & 0xFF);
- out.write((theShort >> 8) & 0xFF);
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import java.io.*;
+
+final class LEDataOutputStream extends OutputStream {
+ OutputStream out;
+public LEDataOutputStream(OutputStream output) {
+ this.out = output;
+}
+public void close() throws IOException {
+ out.close();
+}
+public void write(byte b[], int off, int len) throws IOException {
+ out.write(b, off, len);
+}
+/**
+ * Answer the next byte of the input stream.
+ */
+public void write(int b) throws IOException {
+ out.write(b);
+}
+/**
+ * Answer the next byte of the input stream.
+ */
+public void writeByte(byte b) throws IOException {
+ out.write(b & 0xFF);
+}
+/**
+ * Answer an integer comprised of the next
+ * four bytes of the input 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);
+}
+/**
+ * Answer an integer comprised of the next
+ * two bytes of the input 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
index 42e5a0ef00..51e80f9ce2 100755
--- 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
@@ -1,478 +1,478 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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, buffer;
- byte[] block, lineArray;
- int[] maskTable, stack, suffix, prefix;
- LZWNode[] nodeStack;
- LEDataInputStream inputStream;
- LEDataOutputStream outputStream;
- ImageData image;
- ImageLoader loader;
- boolean interlaced;
-/**
- * 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 = maskTable[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) {
- if (code > currentSlot)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- 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 = maskTable[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 = maskTable[codeSize - 1];
- topSlot *= 2;
- }
- } else {
- nextPutCode(clearCode);
- for (int i = 0; i < nodeStack.length; i++)
- nodeStack[i].children = null;
- codeSize = bitsPerPixel + 1;
- codeMask = maskTable[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;
- maskTable = new int[] {
- 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F,
- 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF
- };
- codeMask = maskTable[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);
- maskTable = new int[] {
- 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F,
- 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF
- };
- 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 & maskTable[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);
- }
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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, buffer;
+ byte[] block, lineArray;
+ int[] maskTable, stack, suffix, prefix;
+ LZWNode[] nodeStack;
+ LEDataInputStream inputStream;
+ LEDataOutputStream outputStream;
+ ImageData image;
+ ImageLoader loader;
+ boolean interlaced;
+/**
+ * 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 = maskTable[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) {
+ if (code > currentSlot)
+ SWT.error(SWT.ERROR_INVALID_IMAGE);
+ 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 = maskTable[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 = maskTable[codeSize - 1];
+ topSlot *= 2;
+ }
+ } else {
+ nextPutCode(clearCode);
+ for (int i = 0; i < nodeStack.length; i++)
+ nodeStack[i].children = null;
+ codeSize = bitsPerPixel + 1;
+ codeMask = maskTable[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;
+ maskTable = new int[] {
+ 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F,
+ 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF
+ };
+ codeMask = maskTable[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);
+ maskTable = new int[] {
+ 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F,
+ 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF
+ };
+ 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 & maskTable[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
index b53e45cf8e..0a0eb64344 100755
--- 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
@@ -1,13 +1,13 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-final class LZWNode {
- public LZWNode left, right, children;
- public int code, prefix, suffix;
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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/PNGFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PNGFileFormat.java
index f1ab0ec561..af955def8a 100755
--- 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
@@ -1,534 +1,534 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import java.io.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-public class PNGFileFormat extends FileFormat {
- static final int SIGNATURE_LENGTH = 8;
- PngDecodingDataStream decodingStream;
- PngIhdrChunk headerChunk;
- PngPlteChunk paletteChunk;
- PngTrnsChunk trnsChunk;
- ImageData imageData;
- byte[] data;
- byte[] alphaPalette;
-
-/**
- * Skip over signature data. This has already been
- * verified in isPNGFile().
- */
-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 imageSize = getAlignedBytesPerRow() * headerChunk.getHeight();
- data = new byte[imageSize];
- imageData = ImageData.internal_new(
- headerChunk.getWidth(),
- headerChunk.getHeight(),
- 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) {
- 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);
- }
- 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(ImageData p1) {
- SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
-}
-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) {
- decodingStream = new PngDecodingDataStream(chunk, chunkReader);
- int interlaceMethod = headerChunk.getInterlaceMethod();
- if (interlaceMethod == PngIhdrChunk.INTERLACE_METHOD_NONE) {
- readNonInterlacedImage();
- } else {
- readInterlacedImage();
- }
- decodingStream.assertImageDataAtEnd();
- decodingStream.checkAdler();
-}
-/**
- * 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(
- int rowInterval,
- int columnInterval,
- int startRow,
- int startColumn,
- int frameCount)
-{
- 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 = decodingStream.getNextDecodedByte();
- for (int col = 0; col < bytesPerRow; col++) {
- currentRow[col] = decodingStream.getNextDecodedByte();
- }
- 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() {
- readInterlaceFrame(8, 8, 0, 0, 0);
- readInterlaceFrame(8, 8, 0, 4, 1);
- readInterlaceFrame(8, 4, 4, 0, 2);
- readInterlaceFrame(4, 4, 0, 2, 3);
- readInterlaceFrame(4, 2, 2, 0, 4);
- readInterlaceFrame(2, 2, 0, 1, 5);
- readInterlaceFrame(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() {
- 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;
- for (int row = 0; row < headerChunk.getHeight(); row++) {
- byte filterType = decodingStream.getNextDecodedByte();
- for (int col = 0; col < bytesPerRow; col++) {
- currentRow[col] = decodingStream.getNextDecodedByte();
- }
- 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;
- }
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import java.io.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+public class PNGFileFormat extends FileFormat {
+ static final int SIGNATURE_LENGTH = 8;
+ PngDecodingDataStream decodingStream;
+ PngIhdrChunk headerChunk;
+ PngPlteChunk paletteChunk;
+ PngTrnsChunk trnsChunk;
+ ImageData imageData;
+ byte[] data;
+ byte[] alphaPalette;
+
+/**
+ * Skip over signature data. This has already been
+ * verified in isPNGFile().
+ */
+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 imageSize = getAlignedBytesPerRow() * headerChunk.getHeight();
+ data = new byte[imageSize];
+ imageData = ImageData.internal_new(
+ headerChunk.getWidth(),
+ headerChunk.getHeight(),
+ 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) {
+ 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);
+ }
+ 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(ImageData p1) {
+ SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
+}
+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) {
+ decodingStream = new PngDecodingDataStream(chunk, chunkReader);
+ int interlaceMethod = headerChunk.getInterlaceMethod();
+ if (interlaceMethod == PngIhdrChunk.INTERLACE_METHOD_NONE) {
+ readNonInterlacedImage();
+ } else {
+ readInterlacedImage();
+ }
+ decodingStream.assertImageDataAtEnd();
+ decodingStream.checkAdler();
+}
+/**
+ * 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(
+ int rowInterval,
+ int columnInterval,
+ int startRow,
+ int startColumn,
+ int frameCount)
+{
+ 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 = decodingStream.getNextDecodedByte();
+ for (int col = 0; col < bytesPerRow; col++) {
+ currentRow[col] = decodingStream.getNextDecodedByte();
+ }
+ 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() {
+ readInterlaceFrame(8, 8, 0, 0, 0);
+ readInterlaceFrame(8, 8, 0, 4, 1);
+ readInterlaceFrame(8, 4, 4, 0, 2);
+ readInterlaceFrame(4, 4, 0, 2, 3);
+ readInterlaceFrame(4, 2, 2, 0, 4);
+ readInterlaceFrame(2, 2, 0, 1, 5);
+ readInterlaceFrame(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() {
+ 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;
+ for (int row = 0; row < headerChunk.getHeight(); row++) {
+ byte filterType = decodingStream.getNextDecodedByte();
+ for (int col = 0; col < bytesPerRow; col++) {
+ currentRow[col] = decodingStream.getNextDecodedByte();
+ }
+ 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;
+ }
+}
+
}
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
index 534e333671..a74f3d9d18 100755
--- 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
@@ -1,336 +1,336 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.Compatibility;
-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);
- }
- }
- }
- }
-
-/**
- * Construct a PngChunk using the reference bytes
- * given.
- */
-PngChunk(byte[] reference) {
- super();
- setReference(reference);
-}
-
-/**
- * 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 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 getInt32(LENGTH_OFFSET);
-}
-
-/**
- * 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);
-}
-
-/**
- * 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() {
- return Character.isUpperCase((char) getTypeBytes()[0]);
-}
-
-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.
- if (!Character.isUpperCase((char) type[2])) SWT.error(SWT.ERROR_INVALID_IMAGE);
-
- // All characters must be letters.
- for (int i = 0; i < TYPE_FIELD_LENGTH; i++) {
- if (!Compatibility.isLetter((char) type[i])) 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) {}
-
-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();
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.internal.Compatibility;
+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);
+ }
+ }
+ }
+ }
+
+/**
+ * Construct a PngChunk using the reference bytes
+ * given.
+ */
+PngChunk(byte[] reference) {
+ super();
+ setReference(reference);
+}
+
+/**
+ * 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 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 getInt32(LENGTH_OFFSET);
+}
+
+/**
+ * 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);
+}
+
+/**
+ * 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() {
+ return Character.isUpperCase((char) getTypeBytes()[0]);
+}
+
+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.
+ if (!Character.isUpperCase((char) type[2])) SWT.error(SWT.ERROR_INVALID_IMAGE);
+
+ // All characters must be letters.
+ for (int i = 0; i < TYPE_FIELD_LENGTH; i++) {
+ if (!Compatibility.isLetter((char) type[i])) 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) {}
+
+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
index 86bf69275c..febd9148e8 100755
--- 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
@@ -1,66 +1,66 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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);
- 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);
- 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;
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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);
+ 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);
+ 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
index 350b3f6f0e..b17e342e10 100755
--- 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
@@ -1,132 +1,132 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
-public class PngDecodingDataStream {
- PngIdatChunk currentChunk;
- PngChunkReader chunkReader;
- byte currentByte;
- int nextByteIndex;
- int nextBitIndex;
-
- PngLzBlockReader lzBlockReader;
- int adlerValue;
-
- static final int PRIME = 65521;
- static final int MAX_BIT = 7;
-
-PngDecodingDataStream(PngIdatChunk idatChunk, PngChunkReader chunkReader) {
- super();
- this.currentChunk = idatChunk;
- this.chunkReader = chunkReader;
- nextByteIndex = 0;
- 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() {
- lzBlockReader.assertCompressedDataAtEnd();
-}
-
-int getNextIdatBits(int length) {
- int value = 0;
- for (int i = 0; i < length; i++) {
- value |= (getNextIdatBit() << i);
- }
- return value;
-}
-
-byte getNextIdatBit() {
- if (nextBitIndex > MAX_BIT) {
- currentByte = getNextIdatByte();
- nextBitIndex = 0;
- }
- int mask = 1 << nextBitIndex;
- nextBitIndex++;
- return ((currentByte & mask) > 0) ? (byte) 1 : (byte) 0;
-}
-
-private PngIdatChunk getNextChunk() {
- PngChunk chunk = chunkReader.readNextChunk();
- if (chunk == null) error();
- if (chunk.getChunkType() != PngChunk.CHUNK_IDAT) error();
- return (PngIdatChunk) chunk;
-}
-
-byte getNextIdatByte() {
- if (nextByteIndex > currentChunk.getLength() - 1) {
- currentChunk = getNextChunk();
- nextByteIndex = 0;
- }
- byte nextByte = currentChunk.getDataByteAtOffset(nextByteIndex);
- nextByteIndex++;
- nextBitIndex = MAX_BIT + 1;
- return nextByte;
-}
-
-private 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;
-}
-
-byte getNextDecodedByte() {
- byte nextDecodedByte = lzBlockReader.getNextByte();
- updateAdler(nextDecodedByte);
- return nextDecodedByte;
-}
-
-void error() {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
-}
-
-private void readCompressedDataHeader() {
- 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() {
- int storedAdler = ((getNextIdatByte() & 0xFF) << 24)
- | ((getNextIdatByte() & 0xFF) << 16)
- | ((getNextIdatByte() & 0xFF) << 8)
- | (getNextIdatByte() & 0xFF);
- if (storedAdler != adlerValue) error();
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+
+public class PngDecodingDataStream {
+ PngIdatChunk currentChunk;
+ PngChunkReader chunkReader;
+ byte currentByte;
+ int nextByteIndex;
+ int nextBitIndex;
+
+ PngLzBlockReader lzBlockReader;
+ int adlerValue;
+
+ static final int PRIME = 65521;
+ static final int MAX_BIT = 7;
+
+PngDecodingDataStream(PngIdatChunk idatChunk, PngChunkReader chunkReader) {
+ super();
+ this.currentChunk = idatChunk;
+ this.chunkReader = chunkReader;
+ nextByteIndex = 0;
+ 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() {
+ lzBlockReader.assertCompressedDataAtEnd();
+}
+
+int getNextIdatBits(int length) {
+ int value = 0;
+ for (int i = 0; i < length; i++) {
+ value |= (getNextIdatBit() << i);
+ }
+ return value;
+}
+
+byte getNextIdatBit() {
+ if (nextBitIndex > MAX_BIT) {
+ currentByte = getNextIdatByte();
+ nextBitIndex = 0;
+ }
+ int mask = 1 << nextBitIndex;
+ nextBitIndex++;
+ return ((currentByte & mask) > 0) ? (byte) 1 : (byte) 0;
+}
+
+private PngIdatChunk getNextChunk() {
+ PngChunk chunk = chunkReader.readNextChunk();
+ if (chunk == null) error();
+ if (chunk.getChunkType() != PngChunk.CHUNK_IDAT) error();
+ return (PngIdatChunk) chunk;
+}
+
+byte getNextIdatByte() {
+ if (nextByteIndex > currentChunk.getLength() - 1) {
+ currentChunk = getNextChunk();
+ nextByteIndex = 0;
+ }
+ byte nextByte = currentChunk.getDataByteAtOffset(nextByteIndex);
+ nextByteIndex++;
+ nextBitIndex = MAX_BIT + 1;
+ return nextByte;
+}
+
+private 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;
+}
+
+byte getNextDecodedByte() {
+ byte nextDecodedByte = lzBlockReader.getNextByte();
+ updateAdler(nextDecodedByte);
+ return nextDecodedByte;
+}
+
+void error() {
+ SWT.error(SWT.ERROR_INVALID_IMAGE);
+}
+
+private void readCompressedDataHeader() {
+ 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() {
+ 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
index 0a7103f844..fc4c4e5a0e 100755
--- 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
@@ -1,22 +1,22 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-class PngFileReadState extends Object {
- boolean readIHDR;
- boolean readPLTE;
- boolean readIDAT;
- boolean readIEND;
-
- // Non - critical chunks
- boolean readBKGD;
- boolean readTRNS;
-
- // Set to true after IDATs have been read.
- boolean readPixelData;
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+class PngFileReadState extends Object {
+ boolean readIHDR;
+ boolean readPLTE;
+ boolean readIDAT;
+ boolean readIEND;
+
+ // Non - critical chunks
+ boolean readBKGD;
+ 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
index 483c1672ed..1d5602d236 100755
--- 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
@@ -1,124 +1,124 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-public class PngHuffmanTable {
- CodeLengthInfo[] codeLengthInfo;
- int[] codeValues;
-
- static final int MAX_CODE_LENGTH = 15;
- static final int BAD_CODE = 0xFFFFFFF;
-
-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. Primary key is code size. Secondary key is value.
- for (int i = 0; i < lengths.length - 1; i++) {
- for (int j = i + 1; j < lengths.length; j++) {
- if (lengths[j] < lengths[i]
- || (lengths[j] == lengths[i]
- && codeValues[j] < codeValues[i]))
- {
- int tmp;
- tmp = lengths[j];
- lengths[j] = lengths[i];
- lengths[i] = tmp;
- tmp = codeValues[j];
- codeValues[j] = codeValues[i];
- codeValues[i] = tmp;
- }
- }
- }
-
- // 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) {
- 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 (code > codeLengthInfo[codelength].max && codelength < MAX_CODE_LENGTH) {
- 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 CodeValuePair {
- int value;
- int code;
-}
-class CodeLengthInfo {
- int length;
- int max;
- int min;
- int baseIndex;
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+public class PngHuffmanTable {
+ CodeLengthInfo[] codeLengthInfo;
+ int[] codeValues;
+
+ static final int MAX_CODE_LENGTH = 15;
+ static final int BAD_CODE = 0xFFFFFFF;
+
+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. Primary key is code size. Secondary key is value.
+ for (int i = 0; i < lengths.length - 1; i++) {
+ for (int j = i + 1; j < lengths.length; j++) {
+ if (lengths[j] < lengths[i]
+ || (lengths[j] == lengths[i]
+ && codeValues[j] < codeValues[i]))
+ {
+ int tmp;
+ tmp = lengths[j];
+ lengths[j] = lengths[i];
+ lengths[i] = tmp;
+ tmp = codeValues[j];
+ codeValues[j] = codeValues[i];
+ codeValues[i] = tmp;
+ }
+ }
+ }
+
+ // 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) {
+ 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 (code > codeLengthInfo[codelength].max && codelength < MAX_CODE_LENGTH) {
+ 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 CodeValuePair {
+ int value;
+ int code;
+}
+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
index 5d0dcde249..c88a983a01 100755
--- 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
@@ -1,158 +1,158 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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){
- 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 () {
- super();
- literalTable = getFixedLiteralTable();
- distanceTable = getFixedDistanceTable();
-}
-
-private PngHuffmanTables (PngDecodingDataStream stream) {
- super();
-
- 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)
-{
- 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) {
- return literalTable.getNextValue(stream);
-}
-
-int getNextDistanceValue(PngDecodingDataStream stream) {
- return distanceTable.getNextValue(stream);
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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){
+ 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 () {
+ super();
+ literalTable = getFixedLiteralTable();
+ distanceTable = getFixedDistanceTable();
+}
+
+private PngHuffmanTables (PngDecodingDataStream stream) {
+ super();
+
+ 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)
+{
+ 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) {
+ return literalTable.getNextValue(stream);
+}
+
+int getNextDistanceValue(PngDecodingDataStream stream) {
+ 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
index 744c0d3765..8dbb505539 100755
--- 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
@@ -1,38 +1,38 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
-class PngIdatChunk extends PngChunk {
-
-PngIdatChunk(byte[] reference){
- super(reference);
-}
-
-/**
- * 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];
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+
+class PngIdatChunk extends PngChunk {
+
+PngIdatChunk(byte[] reference){
+ super(reference);
+}
+
+/**
+ * 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
index 914fad1e02..57fa44c7c2 100755
--- 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
@@ -1,41 +1,41 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
-class PngIendChunk extends PngChunk {
-
-PngIendChunk(byte[] reference){
- super(reference);
-}
-
-/**
- * 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);
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+
+class PngIendChunk extends PngChunk {
+
+PngIendChunk(byte[] reference){
+ super(reference);
+}
+
+/**
+ * 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
index 780e6051e5..4c2a60182e 100755
--- 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
@@ -1,375 +1,375 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.Compatibility;
-
-class PngIhdrChunk extends PngChunk {
- static final int EXPECTED_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 int COLOR_TYPE_GRAYSCALE = 0;
- static final int COLOR_TYPE_RGB = 2;
- static final int COLOR_TYPE_PALETTE = 3;
- static final int COLOR_TYPE_GRAYSCALE_WITH_ALPHA = 4;
- static final int 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};
-
-/**
- * Construct a PNGChunk using the reference bytes
- * given.
- */
-PngIhdrChunk(byte[] reference) {
- super(reference);
-}
-
-/**
- * Get the image's width in pixels.
- */
-int getWidth() {
- return getInt32(WIDTH_DATA_OFFSET);
-}
-
-/**
- * Set the image's width in pixels.
- */
-void setWidth(int value) {
- setInt32(WIDTH_DATA_OFFSET, value);
-}
-
-/**
- * Get the image's height in pixels.
- */
-int getHeight() {
- return getInt32(HEIGHT_DATA_OFFSET);
-}
-
-/**
- * Set the image's height in pixels.
- */
-void setHeight(int value) {
- setInt32(HEIGHT_DATA_OFFSET, value);
-}
-
-/**
- * Get the image's bit depth.
- * This is limited to the values 1, 2, 4, 8, or 16.
- */
-byte getBitDepth() {
- return reference[BIT_DEPTH_OFFSET];
-}
-
-/**
- * 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;
-}
-
-/**
- * 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 reference[COLOR_TYPE_OFFSET];
-}
-
-/**
- * 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;
-}
-
-/**
- * Get the image's compression method.
- * This value must be 0.
- */
-byte getCompressionMethod() {
- return reference[COMPRESSION_METHOD_OFFSET];
-}
-
-/**
- * Set the image's compression method.
- * This value must be 0.
- */
-void setCompressionMethod(byte value) {
- reference[COMPRESSION_METHOD_OFFSET] = value;
-}
-
-/**
- * Get the image's filter method.
- * This value must be 0.
- */
-byte getFilterMethod() {
- return reference[FILTER_METHOD_OFFSET];
-}
-
-/**
- * Set the image's filter method.
- * This value must be 0.
- */
-void setFilterMethod(byte value) {
- reference[FILTER_METHOD_OFFSET] = value;
-}
-
-/**
- * Get the image's interlace method.
- * This value is limited to:
- * 0 - No interlacing used.
- * 1 - Adam7 interlacing used.
- */
-byte getInterlaceMethod() {
- return reference[INTERLACE_METHOD_OFFSET];
-}
-
-/**
- * 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;
-}
-
-/**
- * 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 (getLength() != EXPECTED_DATA_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE);
- if (getCompressionMethod() != 0) SWT.error(SWT.ERROR_INVALID_IMAGE);
- if (getInterlaceMethod() != INTERLACE_METHOD_NONE &&
- getInterlaceMethod() != INTERLACE_METHOD_ADAM7) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
-
- boolean colorTypeIsValid = false;
- byte colorType = getColorType();
- 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;
- byte bitDepth = getBitDepth();
- 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 (getColorType()) {
- 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 - " + getColorType();
- }
-}
-
-String getFilterMethodString() {
- switch (getFilterMethod()) {
- 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 (getInterlaceMethod()) {
- 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(getWidth());
- buffer.append("\n\tHeight: ");
- buffer.append(getHeight());
- buffer.append("\n\tBit Depth: ");
- buffer.append(getBitDepth());
- buffer.append("\n\tColor Type: ");
- buffer.append(getColorTypeString());
- buffer.append("\n\tCompression Method: ");
- buffer.append(getCompressionMethod());
- buffer.append("\n\tFilter Method: ");
- buffer.append(getFilterMethodString());
- buffer.append("\n\tInterlace Method: ");
- buffer.append(getInterlaceMethodString());
-}
-
-boolean getMustHavePalette() {
- return getColorType() == COLOR_TYPE_PALETTE;
-}
-
-boolean getCanHavePalette() {
- int colorType = getColorType();
- 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() {
- int bitDepth = getBitDepth();
- switch (getColorType()) {
- 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() {
- int bitDepth = getBitDepth();
- switch (getColorType()) {
- 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 (getBitDepth() < 8) return 1;
- return getBitsPerPixel() / 8;
-}
-
-boolean usesDirectColor() {
- switch (getColorType()) {
- 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 bitDepth = Math.min(getBitDepth(), 8);
- int max = Compatibility.pow2(bitDepth) - 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 (getColorType()) {
- 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;
- }
-}
-
-
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.internal.Compatibility;
+
+class PngIhdrChunk extends PngChunk {
+ static final int EXPECTED_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 int COLOR_TYPE_GRAYSCALE = 0;
+ static final int COLOR_TYPE_RGB = 2;
+ static final int COLOR_TYPE_PALETTE = 3;
+ static final int COLOR_TYPE_GRAYSCALE_WITH_ALPHA = 4;
+ static final int 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};
+
+/**
+ * Construct a PNGChunk using the reference bytes
+ * given.
+ */
+PngIhdrChunk(byte[] reference) {
+ super(reference);
+}
+
+/**
+ * Get the image's width in pixels.
+ */
+int getWidth() {
+ return getInt32(WIDTH_DATA_OFFSET);
+}
+
+/**
+ * Set the image's width in pixels.
+ */
+void setWidth(int value) {
+ setInt32(WIDTH_DATA_OFFSET, value);
+}
+
+/**
+ * Get the image's height in pixels.
+ */
+int getHeight() {
+ return getInt32(HEIGHT_DATA_OFFSET);
+}
+
+/**
+ * Set the image's height in pixels.
+ */
+void setHeight(int value) {
+ setInt32(HEIGHT_DATA_OFFSET, value);
+}
+
+/**
+ * Get the image's bit depth.
+ * This is limited to the values 1, 2, 4, 8, or 16.
+ */
+byte getBitDepth() {
+ return reference[BIT_DEPTH_OFFSET];
+}
+
+/**
+ * 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;
+}
+
+/**
+ * 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 reference[COLOR_TYPE_OFFSET];
+}
+
+/**
+ * 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;
+}
+
+/**
+ * Get the image's compression method.
+ * This value must be 0.
+ */
+byte getCompressionMethod() {
+ return reference[COMPRESSION_METHOD_OFFSET];
+}
+
+/**
+ * Set the image's compression method.
+ * This value must be 0.
+ */
+void setCompressionMethod(byte value) {
+ reference[COMPRESSION_METHOD_OFFSET] = value;
+}
+
+/**
+ * Get the image's filter method.
+ * This value must be 0.
+ */
+byte getFilterMethod() {
+ return reference[FILTER_METHOD_OFFSET];
+}
+
+/**
+ * Set the image's filter method.
+ * This value must be 0.
+ */
+void setFilterMethod(byte value) {
+ reference[FILTER_METHOD_OFFSET] = value;
+}
+
+/**
+ * Get the image's interlace method.
+ * This value is limited to:
+ * 0 - No interlacing used.
+ * 1 - Adam7 interlacing used.
+ */
+byte getInterlaceMethod() {
+ return reference[INTERLACE_METHOD_OFFSET];
+}
+
+/**
+ * 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;
+}
+
+/**
+ * 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 (getLength() != EXPECTED_DATA_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE);
+ if (getCompressionMethod() != 0) SWT.error(SWT.ERROR_INVALID_IMAGE);
+ if (getInterlaceMethod() != INTERLACE_METHOD_NONE &&
+ getInterlaceMethod() != INTERLACE_METHOD_ADAM7) {
+ SWT.error(SWT.ERROR_INVALID_IMAGE);
+ }
+
+ boolean colorTypeIsValid = false;
+ byte colorType = getColorType();
+ 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;
+ byte bitDepth = getBitDepth();
+ 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 (getColorType()) {
+ 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 - " + getColorType();
+ }
+}
+
+String getFilterMethodString() {
+ switch (getFilterMethod()) {
+ 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 (getInterlaceMethod()) {
+ 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(getWidth());
+ buffer.append("\n\tHeight: ");
+ buffer.append(getHeight());
+ buffer.append("\n\tBit Depth: ");
+ buffer.append(getBitDepth());
+ buffer.append("\n\tColor Type: ");
+ buffer.append(getColorTypeString());
+ buffer.append("\n\tCompression Method: ");
+ buffer.append(getCompressionMethod());
+ buffer.append("\n\tFilter Method: ");
+ buffer.append(getFilterMethodString());
+ buffer.append("\n\tInterlace Method: ");
+ buffer.append(getInterlaceMethodString());
+}
+
+boolean getMustHavePalette() {
+ return getColorType() == COLOR_TYPE_PALETTE;
+}
+
+boolean getCanHavePalette() {
+ int colorType = getColorType();
+ 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() {
+ int bitDepth = getBitDepth();
+ switch (getColorType()) {
+ 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() {
+ int bitDepth = getBitDepth();
+ switch (getColorType()) {
+ 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 (getBitDepth() < 8) return 1;
+ return getBitsPerPixel() / 8;
+}
+
+boolean usesDirectColor() {
+ switch (getColorType()) {
+ 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 bitDepth = Math.min(getBitDepth(), 8);
+ int max = Compatibility.pow2(bitDepth) - 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 (getColorType()) {
+ 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/PngLzBlockReader.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngLzBlockReader.java
index 4f3fd815e4..95a3651fc6 100755
--- 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
@@ -1,169 +1,169 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-public class PngLzBlockReader {
- boolean readHeader;
- 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;
- readHeader = false;
- isLastBlock = false;
-}
-
-void setWindowSize(int windowSize) {
- window = new byte[windowSize];
-}
-
-void readNextBlockHeader() {
- 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() {
- 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() {
- if (compressionType == UNCOMPRESSED) {
- if (uncompressedBytesRemaining > 0) stream.error();
- } else if (copyBytesRemaining > 0 ||
- (huffmanTables.getNextLiteralValue(stream) != END_OF_COMPRESSED_BLOCK))
- {
- stream.error();
- }
-}
-void assertCompressedDataAtEnd() {
- assertBlockAtEnd();
- while (!isLastBlock) {
- readNextBlockHeader();
- assertBlockAtEnd();
- }
-}
-
-private byte getNextCompressedByte() {
- 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 getNextCompressedByte();
- } 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;
- }
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+public class PngLzBlockReader {
+ boolean readHeader;
+ 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;
+ readHeader = false;
+ isLastBlock = false;
+}
+
+void setWindowSize(int windowSize) {
+ window = new byte[windowSize];
+}
+
+void readNextBlockHeader() {
+ 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() {
+ 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() {
+ if (compressionType == UNCOMPRESSED) {
+ if (uncompressedBytesRemaining > 0) stream.error();
+ } else if (copyBytesRemaining > 0 ||
+ (huffmanTables.getNextLiteralValue(stream) != END_OF_COMPRESSED_BLOCK))
+ {
+ stream.error();
+ }
+}
+void assertCompressedDataAtEnd() {
+ assertBlockAtEnd();
+ while (!isLastBlock) {
+ readNextBlockHeader();
+ assertBlockAtEnd();
+ }
+}
+
+private byte getNextCompressedByte() {
+ 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 getNextCompressedByte();
+ } 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
index 752a39a076..c78f96c05c 100755
--- 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
@@ -1,90 +1,90 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.Compatibility;
-
-class PngPlteChunk extends PngChunk {
-
-PngPlteChunk(byte[] reference){
- super(reference);
-}
-
-/**
- * Get the number of colors in this palette.
- */
-int getPaletteSize() {
- return getLength() / 3;
-}
-
-/**
- * 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[getPaletteSize()];
-// int start = DATA_OFFSET;
-// int end = DATA_OFFSET + getLength();
- 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);
-}
-
-/**
- * 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.readBKGD
- || 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.
- 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 (Compatibility.pow2(headerChunk.getBitDepth()) < getPaletteSize()) {
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
-
- // Palettes cannot have more than 256 entries.
- if (256 < getPaletteSize()) SWT.error(SWT.ERROR_INVALID_IMAGE);
-}
-
-void contributeToString(StringBuffer buffer) {
- buffer.append("\n\tPalette size:");
- buffer.append(getPaletteSize());
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.internal.Compatibility;
+
+class PngPlteChunk extends PngChunk {
+
+PngPlteChunk(byte[] reference){
+ super(reference);
+}
+
+/**
+ * Get the number of colors in this palette.
+ */
+int getPaletteSize() {
+ return getLength() / 3;
+}
+
+/**
+ * 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[getPaletteSize()];
+// int start = DATA_OFFSET;
+// int end = DATA_OFFSET + getLength();
+ 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);
+}
+
+/**
+ * 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.readBKGD
+ || 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.
+ 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 (Compatibility.pow2(headerChunk.getBitDepth()) < getPaletteSize()) {
+ SWT.error(SWT.ERROR_INVALID_IMAGE);
+ }
+
+ // Palettes cannot have more than 256 entries.
+ if (256 < getPaletteSize()) SWT.error(SWT.ERROR_INVALID_IMAGE);
+}
+
+void contributeToString(StringBuffer buffer) {
+ buffer.append("\n\tPalette size:");
+ buffer.append(getPaletteSize());
+}
+
}
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
index aeb8ca330f..560368ebd1 100755
--- 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
@@ -1,135 +1,135 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
-public class PngTrnsChunk extends PngChunk {
- static final int TRANSPARENCY_TYPE_PIXEL = 0;
- static final int TRANSPARENCY_TYPE_ALPHAS = 1;
-
-PngTrnsChunk(byte[] reference){
- super(reference);
-}
-
-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;
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+
+public class PngTrnsChunk extends PngChunk {
+ static final int TRANSPARENCY_TYPE_PIXEL = 0;
+ static final int TRANSPARENCY_TYPE_ALPHAS = 1;
+
+PngTrnsChunk(byte[] reference){
+ super(reference);
+}
+
+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/WinBMPFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinBMPFileFormat.java
index e03ad73744..205cdd0fd3 100755
--- 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
@@ -1,665 +1,665 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.io.*;
-
-final class WinBMPFileFormat extends FileFormat {
- int importantColors;
- Point pelsPerMeter = new Point(0, 0);
- public static final int BMPHeaderFixedSize = 40;
-
-/**
- * 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[2];
- stream.read(header);
- stream.unread(header);
- return header[0] == 0x42 && header[1] == 0x4D;
- } 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);
- }
- 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 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 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 << ((infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8));
- } 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.
- */
-byte[] paletteToBytes(PaletteData pal) {
- int n = (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(ImageData image) {
- 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 = 54;
- 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[] compressedData = out.toByteArray();
-
- // Calculate file size
- fileHeader[1] = fileHeader[4] + compressedData.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(WinBMPFileFormat.BMPHeaderFixedSize);
- outputStream.writeInt(image.width);
- outputStream.writeInt(image.height);
- outputStream.writeShort(1);
- outputStream.writeShort((short)image.depth);
- outputStream.writeInt(comp);
- outputStream.writeInt(compressedData.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(compressedData);
- } 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;
- }
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import java.io.*;
+
+final class WinBMPFileFormat extends FileFormat {
+ int importantColors;
+ Point pelsPerMeter = new Point(0, 0);
+ public static final int BMPHeaderFixedSize = 40;
+
+/**
+ * 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[2];
+ stream.read(header);
+ stream.unread(header);
+ return header[0] == 0x42 && header[1] == 0x4D;
+ } 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);
+ }
+ 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 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 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 << ((infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8));
+ } 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.
+ */
+byte[] paletteToBytes(PaletteData pal) {
+ int n = (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(ImageData image) {
+ 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 = 54;
+ 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[] compressedData = out.toByteArray();
+
+ // Calculate file size
+ fileHeader[1] = fileHeader[4] + compressedData.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(WinBMPFileFormat.BMPHeaderFixedSize);
+ outputStream.writeInt(image.width);
+ outputStream.writeInt(image.height);
+ outputStream.writeShort(1);
+ outputStream.writeShort((short)image.depth);
+ outputStream.writeInt(comp);
+ outputStream.writeInt(compressedData.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(compressedData);
+ } 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
index ebac34ad41..1da16ed8d2 100755
--- 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
@@ -1,284 +1,284 @@
-package org.eclipse.swt.internal.image;
-
-/*
+package org.eclipse.swt.internal.image;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.io.*;
-
-final class WinICOFileFormat extends FileFormat {
-/**
- * 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;
- return WinBMPFileFormat.BMPHeaderFixedSize + (i.palette.colors.length * 4) + 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) {
- if (!((i.depth == 1) || (i.depth == 4) || (i.depth == 8)))
- return false;
- int size = i.palette.colors.length;
- return ((size == 2) || (size == 16) || (size == 32) || (size == 256));
-}
-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 depth = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
- infoHeader[14] = 1;
- infoHeader[15] = 0;
- byte[] maskData = bmpFormat.loadData(infoHeader);
- bitInvertData(maskData, 0, maskData.length);
- 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);
- return ImageData.internal_new(
- infoWidth,
- infoHeight,
- depth,
- palette,
- 4,
- shapeData,
-// 4,
- 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))))
- 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.length);
- outputStream.writeInt(0);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-
- byte[] rgbs = new 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.writeByte((byte)i.width);
- outputStream.writeByte((byte)i.height);
- outputStream.writeShort(i.palette.colors.length);
- outputStream.writeShort(0);
- outputStream.writeShort(0);
- outputStream.writeInt(iconSize);
- outputStream.writeInt(offset);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
-}
-void unloadIntoByteStream(ImageData image) {
- 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) {
- int bpl = (icon.width + 7) / 8;
- int pad = 4;
- 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.getTransparencyMask().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 = 4;
- 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);
- }
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import java.io.*;
+
+final class WinICOFileFormat extends FileFormat {
+/**
+ * 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;
+ return WinBMPFileFormat.BMPHeaderFixedSize + (i.palette.colors.length * 4) + 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) {
+ if (!((i.depth == 1) || (i.depth == 4) || (i.depth == 8)))
+ return false;
+ int size = i.palette.colors.length;
+ return ((size == 2) || (size == 16) || (size == 32) || (size == 256));
+}
+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 depth = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
+ infoHeader[14] = 1;
+ infoHeader[15] = 0;
+ byte[] maskData = bmpFormat.loadData(infoHeader);
+ bitInvertData(maskData, 0, maskData.length);
+ 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);
+ return ImageData.internal_new(
+ infoWidth,
+ infoHeight,
+ depth,
+ palette,
+ 4,
+ shapeData,
+// 4,
+ 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))))
+ 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.length);
+ outputStream.writeInt(0);
+ } catch (IOException e) {
+ SWT.error(SWT.ERROR_IO, e);
+ }
+
+ byte[] rgbs = new 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.writeByte((byte)i.width);
+ outputStream.writeByte((byte)i.height);
+ outputStream.writeShort(i.palette.colors.length);
+ outputStream.writeShort(0);
+ outputStream.writeShort(0);
+ outputStream.writeInt(iconSize);
+ outputStream.writeInt(offset);
+ } catch (IOException e) {
+ SWT.error(SWT.ERROR_IO, e);
+ }
+}
+void unloadIntoByteStream(ImageData image) {
+ 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) {
+ int bpl = (icon.width + 7) / 8;
+ int pad = 4;
+ 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.getTransparencyMask().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 = 4;
+ 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/layout/FillLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FillLayout.java
index fd82c6a586..1b27a2774d 100755
--- 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
@@ -1,111 +1,111 @@
-package org.eclipse.swt.layout;
-
-/*
+package org.eclipse.swt.layout;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-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,
- * and you cannot specify margins or 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>.
- * </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:
- *
- * HORIZONTAL: Position the controls horizontally from left to right
- * VERTICAL: Position the controls vertically from top to bottom
- */
- public int type = SWT.HORIZONTAL;
-
-/**
- * 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];
- Point pt = child.computeSize (SWT.DEFAULT, SWT.DEFAULT, flushCache);
- maxWidth = Math.max (maxWidth, pt.x);
- maxHeight = Math.max (maxHeight, pt.y);
- }
- if (type == SWT.HORIZONTAL) {
- return new Point (count * maxWidth, maxHeight);
- }
- return new Point (maxWidth, count * maxHeight);
-}
-
-protected void layout (Composite composite, boolean flushCache) {
- Rectangle rect = composite.getClientArea ();
- Control [] children = composite.getChildren ();
- int count = children.length;
- if (count == 0) return;
- if (type == SWT.HORIZONTAL) {
- int x = rect.x + ((rect.width % count) / 2);
- int width = rect.width / count;
- int y = rect.y, height = rect.height;
- for (int i=0; i<count; i++) {
- Control child = children [i];
- child.setBounds (x, y, width, height);
- x += width;
- }
- return;
- }
- int x = rect.x, width = rect.width;
- int y = rect.y + ((rect.height % count) / 2);
- int height = rect.height / count;
- for (int i=0; i<count; i++) {
- Control child = children [i];
- child.setBounds (x, y, width, height);
- y += height;
- }
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+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,
+ * and you cannot specify margins or 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>.
+ * </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:
+ *
+ * HORIZONTAL: Position the controls horizontally from left to right
+ * VERTICAL: Position the controls vertically from top to bottom
+ */
+ public int type = SWT.HORIZONTAL;
+
+/**
+ * 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];
+ Point pt = child.computeSize (SWT.DEFAULT, SWT.DEFAULT, flushCache);
+ maxWidth = Math.max (maxWidth, pt.x);
+ maxHeight = Math.max (maxHeight, pt.y);
+ }
+ if (type == SWT.HORIZONTAL) {
+ return new Point (count * maxWidth, maxHeight);
+ }
+ return new Point (maxWidth, count * maxHeight);
+}
+
+protected void layout (Composite composite, boolean flushCache) {
+ Rectangle rect = composite.getClientArea ();
+ Control [] children = composite.getChildren ();
+ int count = children.length;
+ if (count == 0) return;
+ if (type == SWT.HORIZONTAL) {
+ int x = rect.x + ((rect.width % count) / 2);
+ int width = rect.width / count;
+ int y = rect.y, height = rect.height;
+ for (int i=0; i<count; i++) {
+ Control child = children [i];
+ child.setBounds (x, y, width, height);
+ x += width;
+ }
+ return;
+ }
+ int x = rect.x, width = rect.width;
+ int y = rect.y + ((rect.height % count) / 2);
+ int height = rect.height / count;
+ for (int i=0; i<count; i++) {
+ Control child = children [i];
+ child.setBounds (x, y, width, height);
+ y += height;
+ }
+}
+}
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
index 109a78a30c..e9fafdb6ff 100644
--- 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
@@ -1,261 +1,261 @@
-package org.eclipse.swt.layout;
-
-/*
+package org.eclipse.swt.layout;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-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.
- * 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.
- *
- * Possible values are:
- *
- * TOP: Attach the side to the top side of the specified control.
- * BOTTOM : Attach the side to the bottom side of the specified control.
- * LEFT: Attach the side to the left side of the specified control.
- * RIGHT: Attach the side to the right side of the specified control.
- * CENTER: Attach the side at a position which will center the control on
- * the specified control.
- * DEFAULT: Attach the side to the adjacent side of the specified control.
- */
- public int alignment;
-
-FormAttachment () {
-}
-
-/**
- * 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 numerator
- * and an offset. Since no denominator is specified, the default
- * is to read 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 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;
-}
-
-/**
- * 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.
- * 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);
-}
-
-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;
-}
-
-public String toString () {
- String string = control != null ? control.toString () : numerator + "/" + denominator;
- return "y = (" + string + (offset >= 0 ? ")x + " + offset: ")x - " + (-offset));
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+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.
+ * 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.
+ *
+ * Possible values are:
+ *
+ * TOP: Attach the side to the top side of the specified control.
+ * BOTTOM : Attach the side to the bottom side of the specified control.
+ * LEFT: Attach the side to the left side of the specified control.
+ * RIGHT: Attach the side to the right side of the specified control.
+ * CENTER: Attach the side at a position which will center the control on
+ * the specified control.
+ * DEFAULT: Attach the side to the adjacent side of the specified control.
+ */
+ public int alignment;
+
+FormAttachment () {
+}
+
+/**
+ * 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 numerator
+ * and an offset. Since no denominator is specified, the default
+ * is to read 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 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;
+}
+
+/**
+ * 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.
+ * 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);
+}
+
+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;
+}
+
+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/FormLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/FormLayout.java
index 50b1e09c9b..393d0f0907 100644
--- 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
@@ -10,8 +10,8 @@ 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 edge of
@@ -80,7 +80,7 @@ import org.eclipse.swt.widgets.*;
*
* @since 2.0
*
- */
+ */
public final class FormLayout extends Layout {
/**
* marginWidth specifies the number of pixels of horizontal margin
@@ -253,5 +253,5 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he
}
return move ? null : new Point (width, height);
}
-
-}
+
+}
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
index 184320e044..646d50ff8d 100755
--- 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
@@ -1,195 +1,195 @@
-package org.eclipse.swt.layout;
-
-/*
+package org.eclipse.swt.layout;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-import org.eclipse.swt.*;
-
-/**
- * <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>setLayoutData ()</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
- */
-public final class GridData {
- /**
- * verticalAlignment specifies how controls will be positioned
- * vertically within a cell.
- *
- * The default value is CENTER.
- *
- * Possible values are:
- *
- * BEGINNING: Position the control at the top of the cell
- * CENTER: Position the control in the vertical center of the cell
- * END: Position the control at the bottom of the cell
- * FILL: Resize the control to fill the cell vertically
- */
- public int verticalAlignment = CENTER;
- /**
- * horizontalAlignment specifies how controls will be positioned
- * horizontally within a cell.
- *
- * The default value is BEGINNING.
- *
- * Possible values are:
- *
- * BEGINNING: Position the control at the left of the cell
- * CENTER: Position the control in the horizontal center of the cell
- * END: Position the control at the right of the cell
- * FILL: Resize the control to fill the cell horizontally
- */
- public int horizontalAlignment = BEGINNING;
- /**
- * widthHint specifies a minimum width for the column. A value of
- * SWT.DEFAULT indicates that no minimum width is specified.
- *
- * The default value is SWT.DEFAULT.
- */
- public int widthHint = SWT.DEFAULT;
- /**
- * heightHint specifies a minimum height for the row. A value of
- * SWT.DEFAULT indicates that no minimum height is specified.
- *
- * The default value is SWT.DEFAULT.
- */
- 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;
- /**
- * 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;
- /**
- * grabExcessHorizontalSpace specifies whether the cell will be made
- * wide enough to fit the remaining horizontal space.
- *
- * The default value is false.
- */
- public boolean grabExcessHorizontalSpace = false;
- /**
- * grabExcessVerticalSpace specifies whether the cell will be made
- * tall enough to fit the remaining vertical space.
- *
- * The default value is false.
- */
- public boolean grabExcessVerticalSpace = false;
-
- // Alignment constants.
- public static final int BEGINNING = 1;
- public static final int CENTER = 2;
- public static final int END = 3;
- public static final int FILL = 4;
-
- // Style constants
- public static final int VERTICAL_ALIGN_BEGINNING = 1 << 1;
- public static final int VERTICAL_ALIGN_CENTER = 1 << 2;
- public static final int VERTICAL_ALIGN_END = 1 << 3;
- public static final int VERTICAL_ALIGN_FILL = 1 << 4;
- public static final int HORIZONTAL_ALIGN_BEGINNING = 1 << 5;
- public static final int HORIZONTAL_ALIGN_CENTER = 1 << 6;
- public static final int HORIZONTAL_ALIGN_END = 1 << 7;
- public static final int HORIZONTAL_ALIGN_FILL = 1 << 8;
- public static final int GRAB_HORIZONTAL = 1 << 9;
- public static final int GRAB_VERTICAL = 1 << 10;
-
- // Style convenience constants
- /**
- * FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL
- */
- public static final int FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL;
- /**
- * FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL
- */
- public static final int FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL;
- /**
- * FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL
- */
- public static final int FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL;
-
- // Private
- int childIndex;
- boolean isItemData = true;
- int hSpan;
-public GridData() {
- super();
-}
-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;
-
- if ((style & GRAB_HORIZONTAL) != 0)
- grabExcessHorizontalSpace = true;
- else
- grabExcessHorizontalSpace = false;
- if ((style & GRAB_VERTICAL) != 0)
- grabExcessVerticalSpace = true;
- else
- grabExcessVerticalSpace = false;
-
-}
-boolean isItemData() {
- return isItemData;
-}
-boolean isSpacerData() {
- return !isItemData;
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+import org.eclipse.swt.*;
+
+/**
+ * <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>setLayoutData ()</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
+ */
+public final class GridData {
+ /**
+ * verticalAlignment specifies how controls will be positioned
+ * vertically within a cell.
+ *
+ * The default value is CENTER.
+ *
+ * Possible values are:
+ *
+ * BEGINNING: Position the control at the top of the cell
+ * CENTER: Position the control in the vertical center of the cell
+ * END: Position the control at the bottom of the cell
+ * FILL: Resize the control to fill the cell vertically
+ */
+ public int verticalAlignment = CENTER;
+ /**
+ * horizontalAlignment specifies how controls will be positioned
+ * horizontally within a cell.
+ *
+ * The default value is BEGINNING.
+ *
+ * Possible values are:
+ *
+ * BEGINNING: Position the control at the left of the cell
+ * CENTER: Position the control in the horizontal center of the cell
+ * END: Position the control at the right of the cell
+ * FILL: Resize the control to fill the cell horizontally
+ */
+ public int horizontalAlignment = BEGINNING;
+ /**
+ * widthHint specifies a minimum width for the column. A value of
+ * SWT.DEFAULT indicates that no minimum width is specified.
+ *
+ * The default value is SWT.DEFAULT.
+ */
+ public int widthHint = SWT.DEFAULT;
+ /**
+ * heightHint specifies a minimum height for the row. A value of
+ * SWT.DEFAULT indicates that no minimum height is specified.
+ *
+ * The default value is SWT.DEFAULT.
+ */
+ 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;
+ /**
+ * 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;
+ /**
+ * grabExcessHorizontalSpace specifies whether the cell will be made
+ * wide enough to fit the remaining horizontal space.
+ *
+ * The default value is false.
+ */
+ public boolean grabExcessHorizontalSpace = false;
+ /**
+ * grabExcessVerticalSpace specifies whether the cell will be made
+ * tall enough to fit the remaining vertical space.
+ *
+ * The default value is false.
+ */
+ public boolean grabExcessVerticalSpace = false;
+
+ // Alignment constants.
+ public static final int BEGINNING = 1;
+ public static final int CENTER = 2;
+ public static final int END = 3;
+ public static final int FILL = 4;
+
+ // Style constants
+ public static final int VERTICAL_ALIGN_BEGINNING = 1 << 1;
+ public static final int VERTICAL_ALIGN_CENTER = 1 << 2;
+ public static final int VERTICAL_ALIGN_END = 1 << 3;
+ public static final int VERTICAL_ALIGN_FILL = 1 << 4;
+ public static final int HORIZONTAL_ALIGN_BEGINNING = 1 << 5;
+ public static final int HORIZONTAL_ALIGN_CENTER = 1 << 6;
+ public static final int HORIZONTAL_ALIGN_END = 1 << 7;
+ public static final int HORIZONTAL_ALIGN_FILL = 1 << 8;
+ public static final int GRAB_HORIZONTAL = 1 << 9;
+ public static final int GRAB_VERTICAL = 1 << 10;
+
+ // Style convenience constants
+ /**
+ * FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL
+ */
+ public static final int FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL;
+ /**
+ * FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL
+ */
+ public static final int FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL;
+ /**
+ * FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL
+ */
+ public static final int FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL;
+
+ // Private
+ int childIndex;
+ boolean isItemData = true;
+ int hSpan;
+public GridData() {
+ super();
+}
+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;
+
+ if ((style & GRAB_HORIZONTAL) != 0)
+ grabExcessHorizontalSpace = true;
+ else
+ grabExcessHorizontalSpace = false;
+ if ((style & GRAB_VERTICAL) != 0)
+ grabExcessVerticalSpace = true;
+ else
+ grabExcessVerticalSpace = false;
+
+}
+boolean isItemData() {
+ return isItemData;
+}
+boolean isSpacerData() {
+ return !isItemData;
+}
+}
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
index a6c5e55583..fdc5914afe 100755
--- 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
@@ -1,691 +1,691 @@
-package org.eclipse.swt.layout;
-
-/*
+package org.eclipse.swt.layout;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.graphics.*;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Vector;
-
-/**
- * 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 {
- /**
- * 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;
- /**
- * numColumns specifies the number of cell columns in the layout.
- *
- * 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;
- /**
- * 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;
-
- // Private variables. Cached values used to cut down on grid calculations.
- Vector grid = new Vector();
- int [] pixelColumnWidths;
- int [] pixelRowHeights;
- int [] expandableColumns;
- int [] expandableRows;
-
-/**
- * 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.
- *
- * @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;
-}
-
-void adjustGridDimensions(Composite composite, boolean flushCache) {
- // Ensure that controls that span more than one row or column have enough space.
- for (int row = 0; row < grid.size(); row++) {
- for (int column = 0; column < numColumns; column++) {
- GridData spec = ((GridData[]) grid.elementAt(row))[column];
- if (spec.isItemData()) {
- // Widgets spanning columns.
- if (spec.hSpan > 1) {
- Control child = composite.getChildren()[spec.childIndex];
- Point extent = child.computeSize(spec.widthHint, spec.heightHint, flushCache);
-
- // Calculate the size of the control's spanned columns.
- int lastSpanIndex = column + spec.hSpan;
- int spannedSize = 0;
- for (int c = column; c < lastSpanIndex; c++) {
- spannedSize = spannedSize + pixelColumnWidths[c] + horizontalSpacing;
- }
- spannedSize = spannedSize - horizontalSpacing;
-
- // If the spanned columns are not large enough to display the control, adjust the column
- // sizes to account for the extra space that is needed.
- if (extent.x + spec.horizontalIndent > spannedSize) {
- int extraSpaceNeeded = extent.x + spec.horizontalIndent - spannedSize;
- int lastColumn = column + spec.hSpan - 1;
- int colWidth;
- if (makeColumnsEqualWidth) {
- // Evenly distribute the extra space amongst all of the columns.
- int columnExtra = extraSpaceNeeded / numColumns;
- int columnRemainder = extraSpaceNeeded % numColumns;
- for (int i = 0; i < pixelColumnWidths.length; i++) {
- colWidth = pixelColumnWidths[i] + columnExtra;
- pixelColumnWidths[i] = colWidth;
- }
- colWidth = pixelColumnWidths[lastColumn] + columnRemainder;
- pixelColumnWidths[lastColumn] = colWidth;
- } else {
- Vector localExpandableColumns = new Vector();
- for (int i = column; i <= lastColumn; i++) {
- for (int j = 0; j < expandableColumns.length; j++) {
- if (expandableColumns[j] == i) {
- localExpandableColumns.addElement(new Integer(i));
- }
- }
- }
- if (localExpandableColumns.size() > 0) {
- // If any of the control's columns grab excess space, allocate the space amongst those columns.
- int columnExtra = extraSpaceNeeded / localExpandableColumns.size();
- int columnRemainder = extraSpaceNeeded % localExpandableColumns.size();
- for (int i = 0; i < localExpandableColumns.size(); i++) {
- int expandableCol = ((Integer) localExpandableColumns.elementAt(i)).intValue();
- colWidth = pixelColumnWidths[expandableCol] + columnExtra;
- pixelColumnWidths[expandableCol] = colWidth;
- }
- colWidth = pixelColumnWidths[lastColumn] + columnRemainder;
- pixelColumnWidths[lastColumn] = colWidth;
- } else {
- // Add the extra space to the control's last column if none of its columns grab excess space.
- colWidth = pixelColumnWidths[lastColumn] + extraSpaceNeeded;
- pixelColumnWidths[lastColumn] = colWidth;
- }
- }
- }
- }
-
- // Widgets spanning rows.
- if (spec.verticalSpan > 1) {
- Control child = composite.getChildren()[spec.childIndex];
- Point extent = child.computeSize(spec.widthHint, spec.heightHint, flushCache);
-
- // Calculate the size of the control's spanned rows.
- int lastSpanIndex = row + spec.verticalSpan;
- int spannedSize = 0;
- for (int r = row; r < lastSpanIndex; r++) {
- spannedSize = spannedSize + pixelRowHeights[r] + verticalSpacing;
- }
- spannedSize = spannedSize - verticalSpacing;
- // If the spanned rows are not large enough to display the control, adjust the row
- // sizes to account for the extra space that is needed.
- if (extent.y > spannedSize) {
- int extraSpaceNeeded = extent.y - spannedSize;
- int lastRow = row + spec.verticalSpan - 1;
- int rowHeight;
- Vector localExpandableRows = new Vector();
- for (int i = row; i <= lastRow; i++) {
- for (int j = 0; j < expandableRows.length; j++) {
- if (expandableRows[j] == i) {
- localExpandableRows.addElement(new Integer(i));
- }
- }
- }
- if (localExpandableRows.size() > 0) {
- // If any of the control's rows grab excess space, allocate the space amongst those rows.
- int rowExtra = extraSpaceNeeded / localExpandableRows.size();
- int rowRemainder = extraSpaceNeeded % localExpandableRows.size();
- for (int i = 0; i < localExpandableRows.size(); i++) {
- int expandableRow = ((Integer) localExpandableRows.elementAt(i)).intValue();
- rowHeight = pixelRowHeights[expandableRow] + rowExtra;
- pixelRowHeights[expandableRow] = rowHeight;
- }
- rowHeight = pixelRowHeights[lastRow] + rowRemainder;
- pixelRowHeights[lastRow] = rowHeight;
- } else {
- // Add the extra space to the control's last row if no rows grab excess space.
- rowHeight = pixelRowHeights[lastRow] + extraSpaceNeeded;
- pixelRowHeights[lastRow] = rowHeight;
- }
- }
- }
- }
- }
- }
-}
-void calculateGridDimensions(Composite composite, boolean flushCache) {
- int maxWidth, childWidth, maxHeight, childHeight;
-
- //
- Control[] children = composite.getChildren();
- Point[] childSizes = new Point[children.length];
- pixelColumnWidths = new int[numColumns];
- pixelRowHeights = new int[grid.size()];
-
- // Loop through the grid by column to get the width that each column needs to be.
- // Each column will be as wide as its widest control.
- for (int column = 0; column < numColumns; column++) {
- maxWidth = 0;
- for (int row = 0; row < grid.size(); row++) {
- GridData spec = ((GridData[]) grid.elementAt(row))[column];
- if (spec.isItemData()) {
- Control child = children[spec.childIndex];
- childSizes[spec.childIndex] = child.computeSize(spec.widthHint, spec.heightHint, flushCache);
- childWidth = childSizes[spec.childIndex].x + spec.horizontalIndent;
- if (spec.hSpan == 1) {
- maxWidth = Math.max(maxWidth, childWidth);
- }
- }
- }
- // Cache the values for later use.
- pixelColumnWidths[column] = maxWidth;
- }
-
- //
- if (makeColumnsEqualWidth) {
- maxWidth = 0;
- // Find the largest column size that is necessary and make each column that size.
- for (int i = 0; i < numColumns; i++) {
- maxWidth = Math.max(maxWidth, pixelColumnWidths[i]);
- }
- for (int i = 0; i < numColumns; i++) {
- pixelColumnWidths[i] = maxWidth;
- }
- }
-
- // Loop through the grid by row to get the height that each row needs to be.
- // Each row will be as high as its tallest control.
- for (int row = 0; row < grid.size(); row++) {
- maxHeight = 0;
- for (int column = 0; column < numColumns; column++) {
- GridData spec = ((GridData[]) grid.elementAt(row))[column];
- if (spec.isItemData()) {
- childHeight = childSizes[spec.childIndex].y;
- if (spec.verticalSpan == 1) {
- maxHeight = Math.max(maxHeight, childHeight);
- }
- }
- }
- // Cache the values for later use.
- pixelRowHeights[row] = maxHeight;
- }
-}
-void computeExpandableCells() {
- // If a control grabs excess horizontal space, the last column that the control spans
- // will be expandable. Similarly, if a control grabs excess vertical space, the
- // last row that the control spans will be expandable.
- Hashtable growColumns = new Hashtable();
- Hashtable growRows = new Hashtable();
- for (int col = 0; col < numColumns; col++) {
- for (int row = 0; row < grid.size(); row++) {
- GridData spec = ((GridData[]) grid.elementAt(row))[col];
- if (spec.grabExcessHorizontalSpace) {
- growColumns.put(new Integer(col + spec.hSpan - 1), new Object());
- }
- if (spec.grabExcessVerticalSpace) {
- growRows.put(new Integer(row + spec.verticalSpan - 1), new Object());
- }
- }
- }
-
- // Cache the values. These values are used later during children layout.
- int i = 0;
- Enumeration enum = growColumns.keys();
- expandableColumns = new int[growColumns.size()];
- while (enum.hasMoreElements()) {
- expandableColumns[i] = ((Integer)enum.nextElement()).intValue();
- i = i + 1;
- }
- i = 0;
- enum = growRows.keys();
- expandableRows = new int[growRows.size()];
- while (enum.hasMoreElements()) {
- expandableRows[i] = ((Integer)enum.nextElement()).intValue();
- i = i + 1;
- }
-}
-Point computeLayoutSize(Composite composite, int wHint, int hHint, boolean flushCache) {
- int totalMarginHeight, totalMarginWidth;
- int totalWidth, totalHeight;
- int cols, rows;
-
- // Initialize the grid and other cached information that help with the grid layout.
- if (grid.size() == 0) {
- createGrid(composite);
- calculateGridDimensions(composite, flushCache);
- computeExpandableCells();
- adjustGridDimensions(composite, flushCache);
- }
-
- //
- cols = numColumns;
- rows = grid.size();
- totalMarginHeight = marginHeight;
- totalMarginWidth = marginWidth;
-
- // The total width is the margin plus border width plus space between each column,
- // plus the width of each column.
- totalWidth = (totalMarginWidth * 2) + ((cols - 1) * horizontalSpacing);
-
- //Add up the width of each column.
- for (int i = 0; i < pixelColumnWidths.length; i++) {
- totalWidth = totalWidth + pixelColumnWidths[i];
- }
-
- // The total height is the margin plus border height, plus space between each row,
- // plus the height of the tallest child in each row.
- totalHeight = (totalMarginHeight * 2) + ((rows - 1) * verticalSpacing);
-
- //Add up the height of each row.
- for (int i = 0; i < pixelRowHeights.length; i++) {
- totalHeight = totalHeight + pixelRowHeights[i];
- }
-
- if (wHint != SWT.DEFAULT) {
- totalWidth = wHint;};
- if (hHint != SWT.DEFAULT) {
- totalHeight = hHint;};
- // The preferred extent is the width and height that will accomodate the grid's controls.
- return new Point(totalWidth, totalHeight);
-}
-protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
- Control[] children = composite.getChildren();
- int numChildren = children.length;
-
- if (numChildren == 0) return new Point(0,0);
-
- if (flushCache) {
- // Cause the grid and its related information to be calculated
- // again.
- grid.removeAllElements();
- }
- return computeLayoutSize(composite, wHint, hHint, flushCache);
-}
-Point getFirstEmptyCell(int row, int column) {
- GridData[] rowData = (GridData[]) grid.elementAt(row);
- while (column < numColumns && rowData[column] != null) {
- column++;
- }
- if (column == numColumns) {
- row++;
- column = 0;
- if (row == grid.size()) {
- grid.addElement(emptyRow());
- }
- return getFirstEmptyCell(row, column);
- }
- return new Point(row, column);
-}
-Point getLastEmptyCell(int row, int column) {
- GridData[] rowData = (GridData[])grid.elementAt(row);
- while (column < numColumns && rowData[column] == null ) {
- column++;
- }
- return new Point(row, column - 1);
-}
-Point getCell(int row, int column, int width, int height) {
- Point start = getFirstEmptyCell(row, column);
- Point end = getLastEmptyCell(start.x, start.y);
- if (end.y + 1 - start.y >= width) return start;
- GridData[] rowData = (GridData[]) grid.elementAt(start.x);
- for (int j = start.y; j < end.y + 1; j++) {
- GridData spacerSpec = new GridData();
- spacerSpec.isItemData = false;
- rowData[j] = spacerSpec;
- }
- return getCell(end.x, end.y, width, height);
-}
-void createGrid(Composite composite) {
- int row, column, rowFill, columnFill;
- Control[] children;
- GridData spacerSpec;
-
- //
- children = composite.getChildren();
-
- //
- grid.addElement(emptyRow());
- row = 0;
- column = 0;
-
- // Loop through the children and place their associated layout specs in the
- // grid. Placement occurs left to right, top to bottom (i.e., by row).
- for (int i = 0; i < children.length; i++) {
- // Find the first available spot in the grid.
- Control child = children[i];
- GridData spec = (GridData) child.getLayoutData();
- if (spec == null) {
- spec = new GridData();
- child.setLayoutData(spec);
- }
- spec.hSpan = Math.min(spec.horizontalSpan, numColumns);
- Point p = getCell(row, column, spec.hSpan, spec.verticalSpan);
- row = p.x; column = p.y;
-
- // The vertical span for the item will be at least 1. If it is > 1,
- // add other rows to the grid.
- for (int j = 2; j <= spec.verticalSpan; j++) {
- if (row + j > grid.size()) {
- grid.addElement(emptyRow());
- }
- }
-
- // Store the layout spec. Also cache the childIndex. NOTE: That we assume the children of a
- // composite are maintained in the order in which they are created and added to the composite.
- ((GridData[]) grid.elementAt(row))[column] = spec;
- spec.childIndex = i;
-
- // Put spacers in the grid to account for the item's vertical and horizontal
- // span.
- rowFill = spec.verticalSpan - 1;
- columnFill = spec.hSpan - 1;
- for (int r = 1; r <= rowFill; r++) {
- for (int c = 0; c < spec.hSpan; c++) {
- spacerSpec = new GridData();
- spacerSpec.isItemData = false;
- ((GridData[]) grid.elementAt(row + r))[column + c] = spacerSpec;
- }
- }
- for (int c = 1; c <= columnFill; c++) {
- for (int r = 0; r < spec.verticalSpan; r++) {
- spacerSpec = new GridData();
- spacerSpec.isItemData = false;
- ((GridData[]) grid.elementAt(row + r))[column + c] = spacerSpec;
- }
- }
- column = column + spec.hSpan - 1;
- }
-
- // Fill out empty grid cells with spacers.
- for (int r = row; r < grid.size(); r++) {
- GridData[] rowData = (GridData[]) grid.elementAt(r);
- for (int c = 0; c < numColumns; c++) {
- if (rowData[c] == null) {
- spacerSpec = new GridData();
- spacerSpec.isItemData = false;
- rowData[c] = spacerSpec;
- }
- }
- }
-}
-GridData[] emptyRow() {
- GridData[] row = new GridData[numColumns];
- for (int i = 0; i < numColumns; i++) {
- row[i] = null;}
- return row;
-}
-protected void layout(Composite composite, boolean flushCache) {
- int[] columnWidths;
- int[] rowHeights;
- int rowSize, rowY, columnX;
- int compositeWidth, compositeHeight;
- int excessHorizontal, excessVertical;
- Control[] children;
- if (flushCache) {
- // Cause the grid and its related information to be calculated
- // again.
- grid.removeAllElements();
- }
- children = composite.getChildren();
- if (children.length == 0)
- return;
-
- //
- Point extent = computeSize(composite, SWT.DEFAULT, SWT.DEFAULT, flushCache);
- columnWidths = new int[numColumns];
- for (int i = 0; i < pixelColumnWidths.length; i++) {
- columnWidths[i] = pixelColumnWidths[i];
- }
- rowHeights = new int[grid.size()];
- for (int i = 0; i < pixelRowHeights.length; i++) {
- rowHeights[i] = pixelRowHeights[i];
- }
- int columnWidth = 0;
- rowSize = Math.max(1, grid.size());
-
- //
- compositeWidth = extent.x;
- compositeHeight = extent.y;
-
- // Calculate whether or not there is any extra space or not enough space due to a resize
- // operation. Then allocate/deallocate the space to columns and rows that are expandable.
- // If a control grabs excess space, its last column or row will be expandable.
- excessHorizontal = composite.getClientArea().width - compositeWidth;
- excessVertical = composite.getClientArea().height - compositeHeight;
-
- // Allocate/deallocate horizontal space.
- if (expandableColumns.length != 0) {
- int excess, remainder, last;
- int colWidth;
- excess = excessHorizontal / expandableColumns.length;
- remainder = excessHorizontal % expandableColumns.length;
- last = 0;
- for (int i = 0; i < expandableColumns.length; i++) {
- int expandableCol = expandableColumns[i];
- colWidth = columnWidths[expandableCol];
- colWidth = colWidth + excess;
- columnWidths[expandableCol] = colWidth;
- last = Math.max(last, expandableCol);
- }
- colWidth = columnWidths[last];
- colWidth = colWidth + remainder;
- columnWidths[last] = colWidth;
- }
-
- // Go through all specs in each expandable column and get the maximum specified
- // widthHint. Use this as the minimumWidth for the column.
- for (int i = 0; i < expandableColumns.length; i++) {
- int expandableCol = expandableColumns[i];
- int colWidth = columnWidths[expandableCol];
- int minWidth = 0;
- for (int j = 0; j < grid.size(); j++) {
- GridData[] row = (GridData[]) grid.elementAt(j);
- GridData spec = row[expandableCol];
- if (spec.hSpan == 1) {
- minWidth = Math.max(minWidth, spec.widthHint);
- }
- }
- columnWidths[expandableCol] = Math.max(colWidth, minWidth);
- }
- // Allocate/deallocate vertical space.
- if (expandableRows.length != 0) {
- int excess, remainder, last;
- int rowHeight;
- excess = excessVertical / expandableRows.length;
- remainder = excessVertical % expandableRows.length;
- last = 0;
- for (int i = 0; i < expandableRows.length; i++) {
- int expandableRow = expandableRows[i];
- rowHeight = rowHeights[expandableRow];
- rowHeight = rowHeight + excess;
- rowHeights[expandableRow] = rowHeight;
- last = Math.max(last, expandableRow);
- }
- rowHeight = rowHeights[last];
- rowHeight = rowHeight + remainder;
- rowHeights[last] = rowHeight;
- }
- // Go through all specs in each expandable row and get the maximum specified
- // heightHint. Use this as the minimumHeight for the row.
- for (int i = 0; i < expandableRows.length; i++) {
- int expandableRow = expandableRows[i];
- int rowHeight = rowHeights[expandableRow];
- int minHeight = 0;
- GridData[] row = (GridData[]) grid.elementAt(expandableRow);
- for (int j = 0; j < numColumns; j++) {
- GridData spec = row[j];
- if (spec.verticalSpan == 1) {
- minHeight = Math.max(minHeight, spec.heightHint);
- }
- }
- rowHeights[expandableRow] = Math.max(rowHeight, minHeight);
- }
-
- // Get the starting x and y.
- columnX = marginWidth + composite.getClientArea().x;
- rowY = marginHeight + composite.getClientArea().y;
-
- // Layout the control left to right, top to bottom.
- for (int r = 0; r < rowSize; r++) {
- int rowHeight = rowHeights[r];
- GridData[] row = (GridData[]) grid.elementAt(r);
-
- //
- for (int c = 0; c < row.length; c++) {
- int spannedWidth = 0, spannedHeight = 0;
- int hAlign = 0, vAlign = 0;
- int widgetX = 0, widgetY = 0;
- int widgetW = 0, widgetH = 0;
-
- //
- GridData spec = (GridData) row[c];
- if (makeColumnsEqualWidth) {
- columnWidth = composite.getClientArea().width - 2 * (marginWidth) - ((numColumns - 1) * horizontalSpacing);
- columnWidth = columnWidth / numColumns;
- for (int i = 0; i < columnWidths.length; i++) {
- columnWidths[i] = columnWidth;
- }
- } else {
- columnWidth = columnWidths[c];
- }
-
- //
- spannedWidth = columnWidth;
- for (int k = 1; k < spec.hSpan; k++) {
- if ((c + k) <= numColumns) {
- if (!makeColumnsEqualWidth) {
- columnWidth = columnWidths[c + k];
- }
- spannedWidth = spannedWidth + columnWidth + horizontalSpacing;
- }
- }
-
- //
- spannedHeight = rowHeight;
- for (int k = 1; k < spec.verticalSpan; k++) {
- if ((r + k) <= grid.size()) {
- spannedHeight = spannedHeight + rowHeights[r + k] + verticalSpacing;
- }
- }
-
- //
- if (spec.isItemData()) {
- Control child = children[spec.childIndex];
- Point childExtent = child.computeSize(spec.widthHint, spec.heightHint, flushCache);
- hAlign = spec.horizontalAlignment;
- widgetX = columnX;
-
- // Calculate the x and width values for the control.
- if (hAlign == GridData.CENTER) {
- widgetX = widgetX + (spannedWidth / 2) - (childExtent.x / 2);
- } else
- if (hAlign == GridData.END) {
- widgetX = widgetX + spannedWidth - childExtent.x - spec.horizontalIndent;
- } else {
- widgetX = widgetX + spec.horizontalIndent;
- }
- if (hAlign == GridData.FILL) {
- widgetW = spannedWidth - spec.horizontalIndent;
- widgetX = columnX + spec.horizontalIndent;
- } else {
- widgetW = childExtent.x;
- }
-
- // Calculate the y and height values for the control.
- vAlign = spec.verticalAlignment;
- widgetY = rowY;
- if (vAlign == GridData.CENTER) {
- widgetY = widgetY + (spannedHeight / 2) - (childExtent.y / 2);
- } else
- if (vAlign == GridData.END) {
- widgetY = widgetY + spannedHeight - childExtent.y;
- }
- if (vAlign == GridData.FILL) {
- widgetH = spannedHeight;
- widgetY = rowY;
- } else {
- widgetH = childExtent.y;
- }
- // Place the control.
- child.setBounds(widgetX, widgetY, widgetW, widgetH);
- }
- // Update the starting x value.
- columnX = columnX + columnWidths[c] + horizontalSpacing;
- }
- // Update the starting y value and since we're starting a new row, reset the starting x value.
- rowY = rowY + rowHeights[r] + verticalSpacing;
- columnX = marginWidth + composite.getClientArea().x;
- }
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+import org.eclipse.swt.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.graphics.*;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * 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 {
+ /**
+ * 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;
+ /**
+ * numColumns specifies the number of cell columns in the layout.
+ *
+ * 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;
+ /**
+ * 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;
+
+ // Private variables. Cached values used to cut down on grid calculations.
+ Vector grid = new Vector();
+ int [] pixelColumnWidths;
+ int [] pixelRowHeights;
+ int [] expandableColumns;
+ int [] expandableRows;
+
+/**
+ * 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.
+ *
+ * @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;
+}
+
+void adjustGridDimensions(Composite composite, boolean flushCache) {
+ // Ensure that controls that span more than one row or column have enough space.
+ for (int row = 0; row < grid.size(); row++) {
+ for (int column = 0; column < numColumns; column++) {
+ GridData spec = ((GridData[]) grid.elementAt(row))[column];
+ if (spec.isItemData()) {
+ // Widgets spanning columns.
+ if (spec.hSpan > 1) {
+ Control child = composite.getChildren()[spec.childIndex];
+ Point extent = child.computeSize(spec.widthHint, spec.heightHint, flushCache);
+
+ // Calculate the size of the control's spanned columns.
+ int lastSpanIndex = column + spec.hSpan;
+ int spannedSize = 0;
+ for (int c = column; c < lastSpanIndex; c++) {
+ spannedSize = spannedSize + pixelColumnWidths[c] + horizontalSpacing;
+ }
+ spannedSize = spannedSize - horizontalSpacing;
+
+ // If the spanned columns are not large enough to display the control, adjust the column
+ // sizes to account for the extra space that is needed.
+ if (extent.x + spec.horizontalIndent > spannedSize) {
+ int extraSpaceNeeded = extent.x + spec.horizontalIndent - spannedSize;
+ int lastColumn = column + spec.hSpan - 1;
+ int colWidth;
+ if (makeColumnsEqualWidth) {
+ // Evenly distribute the extra space amongst all of the columns.
+ int columnExtra = extraSpaceNeeded / numColumns;
+ int columnRemainder = extraSpaceNeeded % numColumns;
+ for (int i = 0; i < pixelColumnWidths.length; i++) {
+ colWidth = pixelColumnWidths[i] + columnExtra;
+ pixelColumnWidths[i] = colWidth;
+ }
+ colWidth = pixelColumnWidths[lastColumn] + columnRemainder;
+ pixelColumnWidths[lastColumn] = colWidth;
+ } else {
+ Vector localExpandableColumns = new Vector();
+ for (int i = column; i <= lastColumn; i++) {
+ for (int j = 0; j < expandableColumns.length; j++) {
+ if (expandableColumns[j] == i) {
+ localExpandableColumns.addElement(new Integer(i));
+ }
+ }
+ }
+ if (localExpandableColumns.size() > 0) {
+ // If any of the control's columns grab excess space, allocate the space amongst those columns.
+ int columnExtra = extraSpaceNeeded / localExpandableColumns.size();
+ int columnRemainder = extraSpaceNeeded % localExpandableColumns.size();
+ for (int i = 0; i < localExpandableColumns.size(); i++) {
+ int expandableCol = ((Integer) localExpandableColumns.elementAt(i)).intValue();
+ colWidth = pixelColumnWidths[expandableCol] + columnExtra;
+ pixelColumnWidths[expandableCol] = colWidth;
+ }
+ colWidth = pixelColumnWidths[lastColumn] + columnRemainder;
+ pixelColumnWidths[lastColumn] = colWidth;
+ } else {
+ // Add the extra space to the control's last column if none of its columns grab excess space.
+ colWidth = pixelColumnWidths[lastColumn] + extraSpaceNeeded;
+ pixelColumnWidths[lastColumn] = colWidth;
+ }
+ }
+ }
+ }
+
+ // Widgets spanning rows.
+ if (spec.verticalSpan > 1) {
+ Control child = composite.getChildren()[spec.childIndex];
+ Point extent = child.computeSize(spec.widthHint, spec.heightHint, flushCache);
+
+ // Calculate the size of the control's spanned rows.
+ int lastSpanIndex = row + spec.verticalSpan;
+ int spannedSize = 0;
+ for (int r = row; r < lastSpanIndex; r++) {
+ spannedSize = spannedSize + pixelRowHeights[r] + verticalSpacing;
+ }
+ spannedSize = spannedSize - verticalSpacing;
+ // If the spanned rows are not large enough to display the control, adjust the row
+ // sizes to account for the extra space that is needed.
+ if (extent.y > spannedSize) {
+ int extraSpaceNeeded = extent.y - spannedSize;
+ int lastRow = row + spec.verticalSpan - 1;
+ int rowHeight;
+ Vector localExpandableRows = new Vector();
+ for (int i = row; i <= lastRow; i++) {
+ for (int j = 0; j < expandableRows.length; j++) {
+ if (expandableRows[j] == i) {
+ localExpandableRows.addElement(new Integer(i));
+ }
+ }
+ }
+ if (localExpandableRows.size() > 0) {
+ // If any of the control's rows grab excess space, allocate the space amongst those rows.
+ int rowExtra = extraSpaceNeeded / localExpandableRows.size();
+ int rowRemainder = extraSpaceNeeded % localExpandableRows.size();
+ for (int i = 0; i < localExpandableRows.size(); i++) {
+ int expandableRow = ((Integer) localExpandableRows.elementAt(i)).intValue();
+ rowHeight = pixelRowHeights[expandableRow] + rowExtra;
+ pixelRowHeights[expandableRow] = rowHeight;
+ }
+ rowHeight = pixelRowHeights[lastRow] + rowRemainder;
+ pixelRowHeights[lastRow] = rowHeight;
+ } else {
+ // Add the extra space to the control's last row if no rows grab excess space.
+ rowHeight = pixelRowHeights[lastRow] + extraSpaceNeeded;
+ pixelRowHeights[lastRow] = rowHeight;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+void calculateGridDimensions(Composite composite, boolean flushCache) {
+ int maxWidth, childWidth, maxHeight, childHeight;
+
+ //
+ Control[] children = composite.getChildren();
+ Point[] childSizes = new Point[children.length];
+ pixelColumnWidths = new int[numColumns];
+ pixelRowHeights = new int[grid.size()];
+
+ // Loop through the grid by column to get the width that each column needs to be.
+ // Each column will be as wide as its widest control.
+ for (int column = 0; column < numColumns; column++) {
+ maxWidth = 0;
+ for (int row = 0; row < grid.size(); row++) {
+ GridData spec = ((GridData[]) grid.elementAt(row))[column];
+ if (spec.isItemData()) {
+ Control child = children[spec.childIndex];
+ childSizes[spec.childIndex] = child.computeSize(spec.widthHint, spec.heightHint, flushCache);
+ childWidth = childSizes[spec.childIndex].x + spec.horizontalIndent;
+ if (spec.hSpan == 1) {
+ maxWidth = Math.max(maxWidth, childWidth);
+ }
+ }
+ }
+ // Cache the values for later use.
+ pixelColumnWidths[column] = maxWidth;
+ }
+
+ //
+ if (makeColumnsEqualWidth) {
+ maxWidth = 0;
+ // Find the largest column size that is necessary and make each column that size.
+ for (int i = 0; i < numColumns; i++) {
+ maxWidth = Math.max(maxWidth, pixelColumnWidths[i]);
+ }
+ for (int i = 0; i < numColumns; i++) {
+ pixelColumnWidths[i] = maxWidth;
+ }
+ }
+
+ // Loop through the grid by row to get the height that each row needs to be.
+ // Each row will be as high as its tallest control.
+ for (int row = 0; row < grid.size(); row++) {
+ maxHeight = 0;
+ for (int column = 0; column < numColumns; column++) {
+ GridData spec = ((GridData[]) grid.elementAt(row))[column];
+ if (spec.isItemData()) {
+ childHeight = childSizes[spec.childIndex].y;
+ if (spec.verticalSpan == 1) {
+ maxHeight = Math.max(maxHeight, childHeight);
+ }
+ }
+ }
+ // Cache the values for later use.
+ pixelRowHeights[row] = maxHeight;
+ }
+}
+void computeExpandableCells() {
+ // If a control grabs excess horizontal space, the last column that the control spans
+ // will be expandable. Similarly, if a control grabs excess vertical space, the
+ // last row that the control spans will be expandable.
+ Hashtable growColumns = new Hashtable();
+ Hashtable growRows = new Hashtable();
+ for (int col = 0; col < numColumns; col++) {
+ for (int row = 0; row < grid.size(); row++) {
+ GridData spec = ((GridData[]) grid.elementAt(row))[col];
+ if (spec.grabExcessHorizontalSpace) {
+ growColumns.put(new Integer(col + spec.hSpan - 1), new Object());
+ }
+ if (spec.grabExcessVerticalSpace) {
+ growRows.put(new Integer(row + spec.verticalSpan - 1), new Object());
+ }
+ }
+ }
+
+ // Cache the values. These values are used later during children layout.
+ int i = 0;
+ Enumeration enum = growColumns.keys();
+ expandableColumns = new int[growColumns.size()];
+ while (enum.hasMoreElements()) {
+ expandableColumns[i] = ((Integer)enum.nextElement()).intValue();
+ i = i + 1;
+ }
+ i = 0;
+ enum = growRows.keys();
+ expandableRows = new int[growRows.size()];
+ while (enum.hasMoreElements()) {
+ expandableRows[i] = ((Integer)enum.nextElement()).intValue();
+ i = i + 1;
+ }
+}
+Point computeLayoutSize(Composite composite, int wHint, int hHint, boolean flushCache) {
+ int totalMarginHeight, totalMarginWidth;
+ int totalWidth, totalHeight;
+ int cols, rows;
+
+ // Initialize the grid and other cached information that help with the grid layout.
+ if (grid.size() == 0) {
+ createGrid(composite);
+ calculateGridDimensions(composite, flushCache);
+ computeExpandableCells();
+ adjustGridDimensions(composite, flushCache);
+ }
+
+ //
+ cols = numColumns;
+ rows = grid.size();
+ totalMarginHeight = marginHeight;
+ totalMarginWidth = marginWidth;
+
+ // The total width is the margin plus border width plus space between each column,
+ // plus the width of each column.
+ totalWidth = (totalMarginWidth * 2) + ((cols - 1) * horizontalSpacing);
+
+ //Add up the width of each column.
+ for (int i = 0; i < pixelColumnWidths.length; i++) {
+ totalWidth = totalWidth + pixelColumnWidths[i];
+ }
+
+ // The total height is the margin plus border height, plus space between each row,
+ // plus the height of the tallest child in each row.
+ totalHeight = (totalMarginHeight * 2) + ((rows - 1) * verticalSpacing);
+
+ //Add up the height of each row.
+ for (int i = 0; i < pixelRowHeights.length; i++) {
+ totalHeight = totalHeight + pixelRowHeights[i];
+ }
+
+ if (wHint != SWT.DEFAULT) {
+ totalWidth = wHint;};
+ if (hHint != SWT.DEFAULT) {
+ totalHeight = hHint;};
+ // The preferred extent is the width and height that will accomodate the grid's controls.
+ return new Point(totalWidth, totalHeight);
+}
+protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
+ Control[] children = composite.getChildren();
+ int numChildren = children.length;
+
+ if (numChildren == 0) return new Point(0,0);
+
+ if (flushCache) {
+ // Cause the grid and its related information to be calculated
+ // again.
+ grid.removeAllElements();
+ }
+ return computeLayoutSize(composite, wHint, hHint, flushCache);
+}
+Point getFirstEmptyCell(int row, int column) {
+ GridData[] rowData = (GridData[]) grid.elementAt(row);
+ while (column < numColumns && rowData[column] != null) {
+ column++;
+ }
+ if (column == numColumns) {
+ row++;
+ column = 0;
+ if (row == grid.size()) {
+ grid.addElement(emptyRow());
+ }
+ return getFirstEmptyCell(row, column);
+ }
+ return new Point(row, column);
+}
+Point getLastEmptyCell(int row, int column) {
+ GridData[] rowData = (GridData[])grid.elementAt(row);
+ while (column < numColumns && rowData[column] == null ) {
+ column++;
+ }
+ return new Point(row, column - 1);
+}
+Point getCell(int row, int column, int width, int height) {
+ Point start = getFirstEmptyCell(row, column);
+ Point end = getLastEmptyCell(start.x, start.y);
+ if (end.y + 1 - start.y >= width) return start;
+ GridData[] rowData = (GridData[]) grid.elementAt(start.x);
+ for (int j = start.y; j < end.y + 1; j++) {
+ GridData spacerSpec = new GridData();
+ spacerSpec.isItemData = false;
+ rowData[j] = spacerSpec;
+ }
+ return getCell(end.x, end.y, width, height);
+}
+void createGrid(Composite composite) {
+ int row, column, rowFill, columnFill;
+ Control[] children;
+ GridData spacerSpec;
+
+ //
+ children = composite.getChildren();
+
+ //
+ grid.addElement(emptyRow());
+ row = 0;
+ column = 0;
+
+ // Loop through the children and place their associated layout specs in the
+ // grid. Placement occurs left to right, top to bottom (i.e., by row).
+ for (int i = 0; i < children.length; i++) {
+ // Find the first available spot in the grid.
+ Control child = children[i];
+ GridData spec = (GridData) child.getLayoutData();
+ if (spec == null) {
+ spec = new GridData();
+ child.setLayoutData(spec);
+ }
+ spec.hSpan = Math.min(spec.horizontalSpan, numColumns);
+ Point p = getCell(row, column, spec.hSpan, spec.verticalSpan);
+ row = p.x; column = p.y;
+
+ // The vertical span for the item will be at least 1. If it is > 1,
+ // add other rows to the grid.
+ for (int j = 2; j <= spec.verticalSpan; j++) {
+ if (row + j > grid.size()) {
+ grid.addElement(emptyRow());
+ }
+ }
+
+ // Store the layout spec. Also cache the childIndex. NOTE: That we assume the children of a
+ // composite are maintained in the order in which they are created and added to the composite.
+ ((GridData[]) grid.elementAt(row))[column] = spec;
+ spec.childIndex = i;
+
+ // Put spacers in the grid to account for the item's vertical and horizontal
+ // span.
+ rowFill = spec.verticalSpan - 1;
+ columnFill = spec.hSpan - 1;
+ for (int r = 1; r <= rowFill; r++) {
+ for (int c = 0; c < spec.hSpan; c++) {
+ spacerSpec = new GridData();
+ spacerSpec.isItemData = false;
+ ((GridData[]) grid.elementAt(row + r))[column + c] = spacerSpec;
+ }
+ }
+ for (int c = 1; c <= columnFill; c++) {
+ for (int r = 0; r < spec.verticalSpan; r++) {
+ spacerSpec = new GridData();
+ spacerSpec.isItemData = false;
+ ((GridData[]) grid.elementAt(row + r))[column + c] = spacerSpec;
+ }
+ }
+ column = column + spec.hSpan - 1;
+ }
+
+ // Fill out empty grid cells with spacers.
+ for (int r = row; r < grid.size(); r++) {
+ GridData[] rowData = (GridData[]) grid.elementAt(r);
+ for (int c = 0; c < numColumns; c++) {
+ if (rowData[c] == null) {
+ spacerSpec = new GridData();
+ spacerSpec.isItemData = false;
+ rowData[c] = spacerSpec;
+ }
+ }
+ }
+}
+GridData[] emptyRow() {
+ GridData[] row = new GridData[numColumns];
+ for (int i = 0; i < numColumns; i++) {
+ row[i] = null;}
+ return row;
+}
+protected void layout(Composite composite, boolean flushCache) {
+ int[] columnWidths;
+ int[] rowHeights;
+ int rowSize, rowY, columnX;
+ int compositeWidth, compositeHeight;
+ int excessHorizontal, excessVertical;
+ Control[] children;
+ if (flushCache) {
+ // Cause the grid and its related information to be calculated
+ // again.
+ grid.removeAllElements();
+ }
+ children = composite.getChildren();
+ if (children.length == 0)
+ return;
+
+ //
+ Point extent = computeSize(composite, SWT.DEFAULT, SWT.DEFAULT, flushCache);
+ columnWidths = new int[numColumns];
+ for (int i = 0; i < pixelColumnWidths.length; i++) {
+ columnWidths[i] = pixelColumnWidths[i];
+ }
+ rowHeights = new int[grid.size()];
+ for (int i = 0; i < pixelRowHeights.length; i++) {
+ rowHeights[i] = pixelRowHeights[i];
+ }
+ int columnWidth = 0;
+ rowSize = Math.max(1, grid.size());
+
+ //
+ compositeWidth = extent.x;
+ compositeHeight = extent.y;
+
+ // Calculate whether or not there is any extra space or not enough space due to a resize
+ // operation. Then allocate/deallocate the space to columns and rows that are expandable.
+ // If a control grabs excess space, its last column or row will be expandable.
+ excessHorizontal = composite.getClientArea().width - compositeWidth;
+ excessVertical = composite.getClientArea().height - compositeHeight;
+
+ // Allocate/deallocate horizontal space.
+ if (expandableColumns.length != 0) {
+ int excess, remainder, last;
+ int colWidth;
+ excess = excessHorizontal / expandableColumns.length;
+ remainder = excessHorizontal % expandableColumns.length;
+ last = 0;
+ for (int i = 0; i < expandableColumns.length; i++) {
+ int expandableCol = expandableColumns[i];
+ colWidth = columnWidths[expandableCol];
+ colWidth = colWidth + excess;
+ columnWidths[expandableCol] = colWidth;
+ last = Math.max(last, expandableCol);
+ }
+ colWidth = columnWidths[last];
+ colWidth = colWidth + remainder;
+ columnWidths[last] = colWidth;
+ }
+
+ // Go through all specs in each expandable column and get the maximum specified
+ // widthHint. Use this as the minimumWidth for the column.
+ for (int i = 0; i < expandableColumns.length; i++) {
+ int expandableCol = expandableColumns[i];
+ int colWidth = columnWidths[expandableCol];
+ int minWidth = 0;
+ for (int j = 0; j < grid.size(); j++) {
+ GridData[] row = (GridData[]) grid.elementAt(j);
+ GridData spec = row[expandableCol];
+ if (spec.hSpan == 1) {
+ minWidth = Math.max(minWidth, spec.widthHint);
+ }
+ }
+ columnWidths[expandableCol] = Math.max(colWidth, minWidth);
+ }
+ // Allocate/deallocate vertical space.
+ if (expandableRows.length != 0) {
+ int excess, remainder, last;
+ int rowHeight;
+ excess = excessVertical / expandableRows.length;
+ remainder = excessVertical % expandableRows.length;
+ last = 0;
+ for (int i = 0; i < expandableRows.length; i++) {
+ int expandableRow = expandableRows[i];
+ rowHeight = rowHeights[expandableRow];
+ rowHeight = rowHeight + excess;
+ rowHeights[expandableRow] = rowHeight;
+ last = Math.max(last, expandableRow);
+ }
+ rowHeight = rowHeights[last];
+ rowHeight = rowHeight + remainder;
+ rowHeights[last] = rowHeight;
+ }
+ // Go through all specs in each expandable row and get the maximum specified
+ // heightHint. Use this as the minimumHeight for the row.
+ for (int i = 0; i < expandableRows.length; i++) {
+ int expandableRow = expandableRows[i];
+ int rowHeight = rowHeights[expandableRow];
+ int minHeight = 0;
+ GridData[] row = (GridData[]) grid.elementAt(expandableRow);
+ for (int j = 0; j < numColumns; j++) {
+ GridData spec = row[j];
+ if (spec.verticalSpan == 1) {
+ minHeight = Math.max(minHeight, spec.heightHint);
+ }
+ }
+ rowHeights[expandableRow] = Math.max(rowHeight, minHeight);
+ }
+
+ // Get the starting x and y.
+ columnX = marginWidth + composite.getClientArea().x;
+ rowY = marginHeight + composite.getClientArea().y;
+
+ // Layout the control left to right, top to bottom.
+ for (int r = 0; r < rowSize; r++) {
+ int rowHeight = rowHeights[r];
+ GridData[] row = (GridData[]) grid.elementAt(r);
+
+ //
+ for (int c = 0; c < row.length; c++) {
+ int spannedWidth = 0, spannedHeight = 0;
+ int hAlign = 0, vAlign = 0;
+ int widgetX = 0, widgetY = 0;
+ int widgetW = 0, widgetH = 0;
+
+ //
+ GridData spec = (GridData) row[c];
+ if (makeColumnsEqualWidth) {
+ columnWidth = composite.getClientArea().width - 2 * (marginWidth) - ((numColumns - 1) * horizontalSpacing);
+ columnWidth = columnWidth / numColumns;
+ for (int i = 0; i < columnWidths.length; i++) {
+ columnWidths[i] = columnWidth;
+ }
+ } else {
+ columnWidth = columnWidths[c];
+ }
+
+ //
+ spannedWidth = columnWidth;
+ for (int k = 1; k < spec.hSpan; k++) {
+ if ((c + k) <= numColumns) {
+ if (!makeColumnsEqualWidth) {
+ columnWidth = columnWidths[c + k];
+ }
+ spannedWidth = spannedWidth + columnWidth + horizontalSpacing;
+ }
+ }
+
+ //
+ spannedHeight = rowHeight;
+ for (int k = 1; k < spec.verticalSpan; k++) {
+ if ((r + k) <= grid.size()) {
+ spannedHeight = spannedHeight + rowHeights[r + k] + verticalSpacing;
+ }
+ }
+
+ //
+ if (spec.isItemData()) {
+ Control child = children[spec.childIndex];
+ Point childExtent = child.computeSize(spec.widthHint, spec.heightHint, flushCache);
+ hAlign = spec.horizontalAlignment;
+ widgetX = columnX;
+
+ // Calculate the x and width values for the control.
+ if (hAlign == GridData.CENTER) {
+ widgetX = widgetX + (spannedWidth / 2) - (childExtent.x / 2);
+ } else
+ if (hAlign == GridData.END) {
+ widgetX = widgetX + spannedWidth - childExtent.x - spec.horizontalIndent;
+ } else {
+ widgetX = widgetX + spec.horizontalIndent;
+ }
+ if (hAlign == GridData.FILL) {
+ widgetW = spannedWidth - spec.horizontalIndent;
+ widgetX = columnX + spec.horizontalIndent;
+ } else {
+ widgetW = childExtent.x;
+ }
+
+ // Calculate the y and height values for the control.
+ vAlign = spec.verticalAlignment;
+ widgetY = rowY;
+ if (vAlign == GridData.CENTER) {
+ widgetY = widgetY + (spannedHeight / 2) - (childExtent.y / 2);
+ } else
+ if (vAlign == GridData.END) {
+ widgetY = widgetY + spannedHeight - childExtent.y;
+ }
+ if (vAlign == GridData.FILL) {
+ widgetH = spannedHeight;
+ widgetY = rowY;
+ } else {
+ widgetH = childExtent.y;
+ }
+ // Place the control.
+ child.setBounds(widgetX, widgetY, widgetW, widgetH);
+ }
+ // Update the starting x value.
+ columnX = columnX + columnWidths[c] + horizontalSpacing;
+ }
+ // Update the starting y value and since we're starting a new row, reset the starting x value.
+ rowY = rowY + rowHeights[r] + verticalSpacing;
+ columnX = marginWidth + composite.getClientArea().x;
+ }
+}
+}
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
index 05d4019e35..9f44d42b2f 100755
--- 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
@@ -1,53 +1,53 @@
-package org.eclipse.swt.layout;
-
-/*
+package org.eclipse.swt.layout;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-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 width of the cell in pixels.
- */
- public int width;
- /**
- * height specifies the height of the cell in pixels.
- */
- public int height;
-
-public RowData () {
- this (SWT.DEFAULT, SWT.DEFAULT);
-}
-
-public RowData (int width, int height) {
- this.width = width;
- this.height = height;
-}
-
-public RowData (Point point) {
- this (point.x, point.y);
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+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 width of the cell in pixels.
+ */
+ public int width;
+ /**
+ * height specifies the height of the cell in pixels.
+ */
+ public int height;
+
+public RowData () {
+ this (SWT.DEFAULT, SWT.DEFAULT);
+}
+
+public RowData (int width, int height) {
+ this.width = width;
+ this.height = height;
+}
+
+public RowData (Point point) {
+ this (point.x, point.y);
+}
+}
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
index d99d0c1a57..f6463fa49b 100755
--- 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
@@ -1,297 +1,297 @@
-package org.eclipse.swt.layout;
-
-/*
+package org.eclipse.swt.layout;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-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:
- *
- * HORIZONTAL: Position the controls horizontally from left to right
- * VERTICAL: Position the controls vertically from top to bottom
- *
- * @since 2.0
- */
- public int type = SWT.HORIZONTAL;
- /**
- * 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;
- /**
- * 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;
- /**
- * 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;
- /**
- * 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 getSize (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 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 = children.length;
- int childWidth = 0, childHeight = 0, maxHeight = 0;
- if (!pack) {
- for (int i=0; i<count; i++) {
- Control child = children [i];
- Point pt = getSize (child, flushCache);
- childWidth = Math.max (childWidth, pt.x);
- childHeight = Math.max (childHeight, pt.y);
- }
- maxHeight = childHeight;
- }
- int clientX = 0, clientY = 0;
- if (move) {
- Rectangle rect = composite.getClientArea ();
- clientX = rect.x; clientY = rect.y;
- }
- boolean wrapped = false;
- Rectangle [] bounds = null;
- if (move && justify) bounds = new Rectangle [count];
- int maxX = 0, x = marginLeft, y = marginTop;
- for (int i=0; i<count; i++) {
- Control child = children [i];
- if (pack) {
- Point pt = getSize (child, flushCache);
- childWidth = pt.x; childHeight = pt.y;
- }
- if (wrap && (i != 0) && (x + childWidth > width)) {
- wrapped = true;
- x = marginLeft; y += spacing + maxHeight;
- }
- if (pack) {
- maxHeight = Math.max (maxHeight, childHeight);
- }
- if (move) {
- int childX = x + clientX, childY = y + clientY;
- if (justify) {
- bounds [i] = new Rectangle (childX, childY, childWidth, childHeight);
- } else {
- child.setBounds (childX, childY, childWidth, childHeight);
- }
- }
- x += spacing + childWidth;
- maxX = Math.max (maxX, x);
- }
- if (!wrap) maxX = x + marginRight;
- if (move && justify) {
- int space = 0, margin = 0;
- if (!wrapped) {
- space = Math.max (0, (width - maxX) / (count + 1));
- margin = Math.max (0, ((width - maxX) % (count + 1)) / 2);
- }
- for (int i=0; i<count; i++) {
- Control child = children [i];
- bounds [i].x += (space * (i + 1)) + margin;
- child.setBounds (bounds [i]);
- }
- }
- return new Point (maxX, y + maxHeight + marginBottom);
-}
-
-Point layoutVertical (Composite composite, boolean move, boolean wrap, int height, boolean flushCache) {
- Control [] children = composite.getChildren ();
- int count = children.length;
- int childWidth = 0, childHeight = 0, maxWidth = 0;
- if (!pack) {
- for (int i=0; i<count; i++) {
- Control child = children [i];
- Point pt = getSize (child, flushCache);
- childWidth = Math.max (childWidth, pt.x);
- childHeight = Math.max (childHeight, pt.y);
- }
- maxWidth = childWidth;
- }
- int clientX = 0, clientY = 0;
- if (move) {
- Rectangle rect = composite.getClientArea ();
- clientX = rect.x; clientY = rect.y;
- }
- boolean wrapped = false;
- Rectangle [] bounds = null;
- if (move && justify) bounds = new Rectangle [count];
- int maxY = 0, x = marginLeft, y = marginTop;
- for (int i=0; i<count; i++) {
- Control child = children [i];
- if (pack) {
- Point pt = getSize (child, flushCache);
- childWidth = pt.x; childHeight = pt.y;
- }
- if (wrap && (i != 0) && (y + childHeight > height)) {
- wrapped = true;
- x += spacing + maxWidth; y = marginTop;
- }
- if (pack) {
- maxWidth = Math.max (maxWidth, childWidth);
- }
- if (move) {
- int childX = x + clientX, childY = y + clientY;
- if (justify) {
- bounds [i] = new Rectangle (childX, childY, childWidth, childHeight);
- } else {
- child.setBounds (childX, childY, childWidth, childHeight);
- }
- }
- y += spacing + childHeight;
- maxY = Math.max (maxY, y);
- }
- if (!wrap) maxY = y + marginBottom;
- if (move && justify) {
- int space = 0, margin = 0;
- if (!wrapped) {
- space = Math.max (0, (height - maxY) / (count + 1));
- margin = Math.max (0, ((height - maxY) % (count + 1)) / 2);
- }
- for (int i=0; i<count; i++) {
- Control child = children [i];
- bounds [i].y += (space * (i + 1)) + margin;
- child.setBounds (bounds [i]);
- }
- }
- return new Point (x + maxWidth + marginRight, maxY);
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+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:
+ *
+ * HORIZONTAL: Position the controls horizontally from left to right
+ * VERTICAL: Position the controls vertically from top to bottom
+ *
+ * @since 2.0
+ */
+ public int type = SWT.HORIZONTAL;
+ /**
+ * 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;
+ /**
+ * 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;
+ /**
+ * 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;
+ /**
+ * 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 getSize (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 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 = children.length;
+ int childWidth = 0, childHeight = 0, maxHeight = 0;
+ if (!pack) {
+ for (int i=0; i<count; i++) {
+ Control child = children [i];
+ Point pt = getSize (child, flushCache);
+ childWidth = Math.max (childWidth, pt.x);
+ childHeight = Math.max (childHeight, pt.y);
+ }
+ maxHeight = childHeight;
+ }
+ int clientX = 0, clientY = 0;
+ if (move) {
+ Rectangle rect = composite.getClientArea ();
+ clientX = rect.x; clientY = rect.y;
+ }
+ boolean wrapped = false;
+ Rectangle [] bounds = null;
+ if (move && justify) bounds = new Rectangle [count];
+ int maxX = 0, x = marginLeft, y = marginTop;
+ for (int i=0; i<count; i++) {
+ Control child = children [i];
+ if (pack) {
+ Point pt = getSize (child, flushCache);
+ childWidth = pt.x; childHeight = pt.y;
+ }
+ if (wrap && (i != 0) && (x + childWidth > width)) {
+ wrapped = true;
+ x = marginLeft; y += spacing + maxHeight;
+ }
+ if (pack) {
+ maxHeight = Math.max (maxHeight, childHeight);
+ }
+ if (move) {
+ int childX = x + clientX, childY = y + clientY;
+ if (justify) {
+ bounds [i] = new Rectangle (childX, childY, childWidth, childHeight);
+ } else {
+ child.setBounds (childX, childY, childWidth, childHeight);
+ }
+ }
+ x += spacing + childWidth;
+ maxX = Math.max (maxX, x);
+ }
+ if (!wrap) maxX = x + marginRight;
+ if (move && justify) {
+ int space = 0, margin = 0;
+ if (!wrapped) {
+ space = Math.max (0, (width - maxX) / (count + 1));
+ margin = Math.max (0, ((width - maxX) % (count + 1)) / 2);
+ }
+ for (int i=0; i<count; i++) {
+ Control child = children [i];
+ bounds [i].x += (space * (i + 1)) + margin;
+ child.setBounds (bounds [i]);
+ }
+ }
+ return new Point (maxX, y + maxHeight + marginBottom);
+}
+
+Point layoutVertical (Composite composite, boolean move, boolean wrap, int height, boolean flushCache) {
+ Control [] children = composite.getChildren ();
+ int count = children.length;
+ int childWidth = 0, childHeight = 0, maxWidth = 0;
+ if (!pack) {
+ for (int i=0; i<count; i++) {
+ Control child = children [i];
+ Point pt = getSize (child, flushCache);
+ childWidth = Math.max (childWidth, pt.x);
+ childHeight = Math.max (childHeight, pt.y);
+ }
+ maxWidth = childWidth;
+ }
+ int clientX = 0, clientY = 0;
+ if (move) {
+ Rectangle rect = composite.getClientArea ();
+ clientX = rect.x; clientY = rect.y;
+ }
+ boolean wrapped = false;
+ Rectangle [] bounds = null;
+ if (move && justify) bounds = new Rectangle [count];
+ int maxY = 0, x = marginLeft, y = marginTop;
+ for (int i=0; i<count; i++) {
+ Control child = children [i];
+ if (pack) {
+ Point pt = getSize (child, flushCache);
+ childWidth = pt.x; childHeight = pt.y;
+ }
+ if (wrap && (i != 0) && (y + childHeight > height)) {
+ wrapped = true;
+ x += spacing + maxWidth; y = marginTop;
+ }
+ if (pack) {
+ maxWidth = Math.max (maxWidth, childWidth);
+ }
+ if (move) {
+ int childX = x + clientX, childY = y + clientY;
+ if (justify) {
+ bounds [i] = new Rectangle (childX, childY, childWidth, childHeight);
+ } else {
+ child.setBounds (childX, childY, childWidth, childHeight);
+ }
+ }
+ y += spacing + childHeight;
+ maxY = Math.max (maxY, y);
+ }
+ if (!wrap) maxY = y + marginBottom;
+ if (move && justify) {
+ int space = 0, margin = 0;
+ if (!wrapped) {
+ space = Math.max (0, (height - maxY) / (count + 1));
+ margin = Math.max (0, ((height - maxY) % (count + 1)) / 2);
+ }
+ for (int i=0; i<count; i++) {
+ Control child = children [i];
+ bounds [i].y += (space * (i + 1)) + margin;
+ child.setBounds (bounds [i]);
+ }
+ }
+ return new Point (x + maxWidth + marginRight, maxY);
+}
+}
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
index cfdfa57a1c..a45ffc96a5 100755
--- 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
@@ -1,253 +1,253 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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:
- * <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;
- * }
- * }
- * </code>
- * <p>
- * Note: The <em>modality</em> styles supported by this class
- * must be 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, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- *
- * @see Shell
- */
-
-public abstract class Dialog {
- int style;
- Shell parent;
- String title;
-
-/**
- * Constructs a new instance of this class given only its
- * parent.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the 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, 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>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the 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, 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);
- if (!parent.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (parent.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * 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 SWTError#error
- */
-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 text 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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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:
+ * <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;
+ * }
+ * }
+ * </code>
+ * <p>
+ * Note: The <em>modality</em> styles supported by this class
+ * must be 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, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>(none)</dd>
+ * </dl>
+ *
+ * @see Shell
+ */
+
+public abstract class Dialog {
+ int style;
+ Shell parent;
+ String title;
+
+/**
+ * Constructs a new instance of this class given only its
+ * parent.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the 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, 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>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the 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, 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);
+ if (!parent.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (parent.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+}
+
+/**
+ * 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 SWTError#error
+ */
+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 text 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
index 2bc9da03a9..6ae5cc2ef6 100755
--- 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
@@ -1,208 +1,208 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 SWT
- */
- public int type;
-
- /**
- * the event specific detail field, as defined by the detail constants
- * in class <code>SWT</code>
- *
- * @see SWT
- */
- public int detail;
-
- /**
- * the item that the event occurred in (can be null)
- */
- public Widget item;
-
- /**
- * 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;
-
- /**
- * the number of following paint events which
- * are pending which may always be zero on
- * some platforms
- */
- 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 (NUL). 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 unicode value of the original character. For example,
- * typing Ctrl+M or Return both result in the character '\r' but the
- * keyCode field will also contain '\r' when Return was typed.
- *
- * @see 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 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.
-* <p>
-* @return a rectangle that is the bounds.
-*/
-public Rectangle getBounds () {
- return new Rectangle (x, y, width, height);
-}
-
-/**
-* Sets the bounds.
-* <p>
-* @param x the new x position
-* @param y the new y position
-* @param width the new width
-* @param height the new height
-*/
-public void setBounds (Rectangle rect) {
- this.x = rect.x;
- this.y = rect.y;
- this.width = rect.width;
- this.height = rect.height;
-}
-
-/**
-* Returns a string representation of the object.
-*
-* @return a string representation of the object
-*/
-public String toString () {
- return "Event {type=" + type + ",widget=" + widget + ",x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "}";
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 SWT
+ */
+ public int type;
+
+ /**
+ * the event specific detail field, as defined by the detail constants
+ * in class <code>SWT</code>
+ *
+ * @see SWT
+ */
+ public int detail;
+
+ /**
+ * the item that the event occurred in (can be null)
+ */
+ public Widget item;
+
+ /**
+ * 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;
+
+ /**
+ * the number of following paint events which
+ * are pending which may always be zero on
+ * some platforms
+ */
+ 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 (NUL). 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 unicode value of the original character. For example,
+ * typing Ctrl+M or Return both result in the character '\r' but the
+ * keyCode field will also contain '\r' when Return was typed.
+ *
+ * @see 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 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.
+* <p>
+* @return a rectangle that is the bounds.
+*/
+public Rectangle getBounds () {
+ return new Rectangle (x, y, width, height);
+}
+
+/**
+* Sets the bounds.
+* <p>
+* @param x the new x position
+* @param y the new y position
+* @param width the new width
+* @param height the new height
+*/
+public void setBounds (Rectangle rect) {
+ this.x = rect.x;
+ this.y = rect.y;
+ this.width = rect.width;
+ this.height = rect.height;
+}
+
+/**
+* Returns a string representation of the object.
+*
+* @return a string representation of the object
+*/
+public String toString () {
+ return "Event {type=" + type + ",widget=" + widget + ",x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "}";
+}
+}
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
index 702ff474c5..712f718feb 100755
--- 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
@@ -1,130 +1,130 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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) {
- if (level == 0) {
- 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;
- }
- }
- 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++;
- try {
- for (int i=0; i<types.length; i++) {
- if (types [i] == event.type) {
- Listener listener = listeners [i];
- if (listener != null) listener.handleEvent (event);
- }
- }
- } finally {
- --level;
- }
-}
-
-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;
- }
- 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;
- }
- }
- }
- }
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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) {
+ if (level == 0) {
+ 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;
+ }
+ }
+ 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++;
+ try {
+ for (int i=0; i<types.length; i++) {
+ if (types [i] == event.type) {
+ Listener listener = listeners [i];
+ if (listener != null) listener.handleEvent (event);
+ }
+ }
+ } finally {
+ --level;
+ }
+}
+
+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;
+ }
+ 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
index 189440f0d9..8a561af97a 100755
--- 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
@@ -1,177 +1,177 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 #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 index at which to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the 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 #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 ();
- text = string;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 #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 index at which to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the 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 #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 ();
+ 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
index af6450636e..93e0fb0afa 100755
--- 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
@@ -1,83 +1,83 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.
- */
-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 minimum size that the
- * client area of the composite must be in order to
- * position all children at their minimum 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 minimum
- * 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 minimum)
- * @param hHint height (<code>SWT.DEFAULT</code> for minimum)
- * @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
- * @see "computeTrim, getClientArea for controls that implement them"
- */
-protected abstract Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache);
-
-/**
- * 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 layed 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);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
+ */
+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 minimum size that the
+ * client area of the composite must be in order to
+ * position all children at their minimum 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 minimum
+ * 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 minimum)
+ * @param hHint height (<code>SWT.DEFAULT</code> for minimum)
+ * @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
+ * @see "computeTrim, getClientArea for controls that implement them"
+ */
+protected abstract Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache);
+
+/**
+ * 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 layed 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
index df23674df5..624dc129cc 100755
--- 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
@@ -1,47 +1,47 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * <code>Listener</code>s implement 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
- * 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);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * <code>Listener</code>s implement 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
+ * 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/RunnableLock.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/RunnableLock.java
index ae9ea81a26..543c44dc00 100755
--- 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
@@ -1,35 +1,35 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * 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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * 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
index f3565259e6..11e30e40aa 100755
--- 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
@@ -1,155 +1,155 @@
-package org.eclipse.swt.widgets;
-
-/*
- * Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
- * This file is made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
-
-public Synchronizer (Display display) {
- this.display = display;
-}
-
-void addLast (RunnableLock lock) {
- 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;
- }
-}
-
-/**
- * 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) addLast (new RunnableLock (runnable));
- display.wake ();
-}
-
-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) messages = null;
- return lock;
- }
-}
-
-boolean runAsyncMessages () {
- if (messageCount == 0) return false;
- RunnableLock lock = removeFirst ();
- if (lock == null) return 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 ();
- }
- }
- 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.
- *
- * @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);
- display.wake ();
- 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);
- }
- }
-}
-
-}
+package org.eclipse.swt.widgets;
+
+/*
+ * Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
+ * This file is made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+
+public Synchronizer (Display display) {
+ this.display = display;
+}
+
+void addLast (RunnableLock lock) {
+ 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;
+ }
+}
+
+/**
+ * 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) addLast (new RunnableLock (runnable));
+ display.wake ();
+}
+
+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) messages = null;
+ return lock;
+ }
+}
+
+boolean runAsyncMessages () {
+ if (messageCount == 0) return false;
+ RunnableLock lock = removeFirst ();
+ if (lock == null) return 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 ();
+ }
+ }
+ 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.
+ *
+ * @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);
+ display.wake ();
+ 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/TypedListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/TypedListener.java
index bc053d803e..2484e3124c 100755
--- 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
@@ -1,224 +1,224 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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
- *
- * @private
- */
-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>
- */
-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: {
- ((KeyListener) eventListener).keyPressed(new KeyEvent(e));
- break;
- }
- case SWT.KeyUp: {
- ((KeyListener) eventListener).keyReleased(new KeyEvent(e));
- 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: {
- ((TreeListener) eventListener).treeExpanded(new TreeEvent(e));
- break;
- }
- case SWT.Collapse: {
- ((TreeListener) eventListener).treeCollapsed(new TreeEvent(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;
- }
-
- }
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
+ *
+ * @private
+ */
+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>
+ */
+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: {
+ ((KeyListener) eventListener).keyPressed(new KeyEvent(e));
+ break;
+ }
+ case SWT.KeyUp: {
+ ((KeyListener) eventListener).keyReleased(new KeyEvent(e));
+ 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: {
+ ((TreeListener) eventListener).treeExpanded(new TreeEvent(e));
+ break;
+ }
+ case SWT.Collapse: {
+ ((TreeListener) eventListener).treeCollapsed(new TreeEvent(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/version.txt b/bundles/org.eclipse.swt/Eclipse SWT/common/version.txt
index 9f8d3cf97e..ad7435eb54 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/version.txt
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/version.txt
@@ -1 +1 @@
-version 2.131
+version 2.131
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
index 1972538a89..7c1ad12b80 100644
--- 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
@@ -1,27 +1,27 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * 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 {
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * 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 {
} \ No newline at end of file
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
index 72b155ab0f..01cc49118f 100644
--- 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
@@ -1,392 +1,392 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 {
-
-/**
- * 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();
-}
-
-/**
- * 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";
- if (key.equals("SWT_No")) return "No";
- if (key.equals("SWT_OK")) return "OK";
- if (key.equals("SWT_Cancel")) return "Cancel";
- if (key.equals("SWT_Abort")) return "Abort";
- if (key.equals("SWT_Retry")) return "Retry";
- if (key.equals("SWT_Ignore")) return "Ignore";
- if (key.equals("SWT_Sample")) return "Sample";
- if (key.equals("SWT_A_Sample_Text")) return "A Sample Text";
- if (key.equals("SWT_Selection")) return "Selection";
- if (key.equals("SWT_Current_Selection")) return "Current Selection";
- if (key.equals("SWT_Character_set")) return "Character set";
- if (key.equals("SWT_Font")) return "Font";
- if (key.equals("SWT_Extended_style")) return "Extended style";
- if (key.equals("SWT_Size")) return "Size";
- if (key.equals("SWT_Style")) return "Style";
- if (key.equals("SWT_Save")) return "Save";
- if (key.equals("SWT_Character_set")) return "Character set";
- if (key.equals("SWT_ColorDialog_Title")) return "Colors";
- if (key.equals("SWT_FontDialog_Title")) return "Fonts";
- if (key.equals("SWT_Charset_Western")) return "western";
- if (key.equals("SWT_Charset_EastEuropean")) return "east european";
- if (key.equals("SWT_Charset_SouthEuropean")) return "south european";
- if (key.equals("SWT_Charset_NorthEuropean")) return "north european";
- if (key.equals("SWT_Charset_Cyrillic")) return "cyrillic";
- if (key.equals("SWT_Charset_Arabic")) return "arabic";
- if (key.equals("SWT_Charset_Greek")) return "greek";
- if (key.equals("SWT_Charset_Hebrew")) return "hebrew";
- if (key.equals("SWT_Charset_Turkish")) return "turkish";
- if (key.equals("SWT_Charset_Nordic")) return "nordic";
- if (key.equals("SWT_Charset_Thai")) return "thai";
- if (key.equals("SWT_Charset_BalticRim")) return "baltic rim";
- if (key.equals("SWT_Charset_Celtic")) return "celtic";
- if (key.equals("SWT_Charset_Euro")) return "euro";
- if (key.equals("SWT_Charset_Romanian")) return "romanian";
- if (key.equals("SWT_Charset_SimplifiedChinese")) return "simplified chinese";
- if (key.equals("SWT_Charset_TraditionalChinese")) return "traditional chinese";
- if (key.equals("SWT_Charset_Japanese")) return "japanese";
- if (key.equals("SWT_Charset_Korean")) return "korean";
- if (key.equals("SWT_Charset_Unicode")) return "unicode";
- if (key.equals("SWT_Charset_ASCII")) return "ASCII";
- if (key.equals("SWT_InputMethods")) return "Input Methods";
- 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;
-}
-
-/**
- * Copies a range of characters into a new String.
- *
- * @param buffer the StringBuffer we want to copy from
- * @param start the offset of the first character
- * @param end the offset one past the last character
- * @return a new String containing the characters from start to end - 1
- *
- * @exception IndexOutOfBoundsException
- * when <code>start < 0, start > end</code> or <code>end > length()</code>
- */
-public static String substring(StringBuffer buffer, int start, int end) {
- return buffer.toString().substring(start, end);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 {
+
+/**
+ * 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();
+}
+
+/**
+ * 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";
+ if (key.equals("SWT_No")) return "No";
+ if (key.equals("SWT_OK")) return "OK";
+ if (key.equals("SWT_Cancel")) return "Cancel";
+ if (key.equals("SWT_Abort")) return "Abort";
+ if (key.equals("SWT_Retry")) return "Retry";
+ if (key.equals("SWT_Ignore")) return "Ignore";
+ if (key.equals("SWT_Sample")) return "Sample";
+ if (key.equals("SWT_A_Sample_Text")) return "A Sample Text";
+ if (key.equals("SWT_Selection")) return "Selection";
+ if (key.equals("SWT_Current_Selection")) return "Current Selection";
+ if (key.equals("SWT_Character_set")) return "Character set";
+ if (key.equals("SWT_Font")) return "Font";
+ if (key.equals("SWT_Extended_style")) return "Extended style";
+ if (key.equals("SWT_Size")) return "Size";
+ if (key.equals("SWT_Style")) return "Style";
+ if (key.equals("SWT_Save")) return "Save";
+ if (key.equals("SWT_Character_set")) return "Character set";
+ if (key.equals("SWT_ColorDialog_Title")) return "Colors";
+ if (key.equals("SWT_FontDialog_Title")) return "Fonts";
+ if (key.equals("SWT_Charset_Western")) return "western";
+ if (key.equals("SWT_Charset_EastEuropean")) return "east european";
+ if (key.equals("SWT_Charset_SouthEuropean")) return "south european";
+ if (key.equals("SWT_Charset_NorthEuropean")) return "north european";
+ if (key.equals("SWT_Charset_Cyrillic")) return "cyrillic";
+ if (key.equals("SWT_Charset_Arabic")) return "arabic";
+ if (key.equals("SWT_Charset_Greek")) return "greek";
+ if (key.equals("SWT_Charset_Hebrew")) return "hebrew";
+ if (key.equals("SWT_Charset_Turkish")) return "turkish";
+ if (key.equals("SWT_Charset_Nordic")) return "nordic";
+ if (key.equals("SWT_Charset_Thai")) return "thai";
+ if (key.equals("SWT_Charset_BalticRim")) return "baltic rim";
+ if (key.equals("SWT_Charset_Celtic")) return "celtic";
+ if (key.equals("SWT_Charset_Euro")) return "euro";
+ if (key.equals("SWT_Charset_Romanian")) return "romanian";
+ if (key.equals("SWT_Charset_SimplifiedChinese")) return "simplified chinese";
+ if (key.equals("SWT_Charset_TraditionalChinese")) return "traditional chinese";
+ if (key.equals("SWT_Charset_Japanese")) return "japanese";
+ if (key.equals("SWT_Charset_Korean")) return "korean";
+ if (key.equals("SWT_Charset_Unicode")) return "unicode";
+ if (key.equals("SWT_Charset_ASCII")) return "ASCII";
+ if (key.equals("SWT_InputMethods")) return "Input Methods";
+ 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;
+}
+
+/**
+ * Copies a range of characters into a new String.
+ *
+ * @param buffer the StringBuffer we want to copy from
+ * @param start the offset of the first character
+ * @param end the offset one past the last character
+ * @return a new String containing the characters from start to end - 1
+ *
+ * @exception IndexOutOfBoundsException
+ * when <code>start < 0, start > end</code> or <code>end > length()</code>
+ */
+public static String substring(StringBuffer buffer, int start, int end) {
+ return buffer.toString().substring(start, end);
+}
+
+}
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
index a31d38ef82..4f8bb49e46 100644
--- 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
@@ -1,23 +1,23 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * 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 {
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * 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 {
} \ No newline at end of file
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
index fd5be03d13..c1fdf3c007 100644
--- 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
@@ -1,57 +1,57 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * 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) + ']';
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * 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) + ']';
+}
+
} \ No newline at end of file
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
index 1d9ea39120..acf71e235a 100644
--- 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
@@ -1,28 +1,28 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * 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 {
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * 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 {
} \ No newline at end of file
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
index 54b8d35d25..b5f679f934 100644
--- 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
@@ -1,23 +1,23 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * 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 {
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+/**
+ * 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 {
} \ No newline at end of file
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
index 068e57a933..2f10d38af5 100644
--- 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
@@ -1,303 +1,303 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import java.io.*;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-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 {
-
-static double pi = 3.1415926535;
-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 (int)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.
- */
-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.
- */
-public static OutputStream newFileOutputStream(String filename) throws IOException {
- return new FileOutputStream(filename);
-}
-
-/**
- * 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 ch 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 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 {
- 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
- */
-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");
- } catch (MissingResourceException ex) {
- answer = key + " (no resource bundle)";
- }
- }
- if (msgs != null) {
- try {
- answer = msgs.getString(key);
- } 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);
-}
-
-/**
- * Copies a range of characters into a new String.
- *
- * @param buffer the StringBuffer we want to copy from
- * @param start the offset of the first character
- * @param end the offset one past the last character
- * @return a new String containing the characters from start to end - 1
- *
- * @exception IndexOutOfBoundsException
- * when <code>start < 0, start > end</code> or <code>end > length()</code>
- */
-public static String substring(StringBuffer buffer, int start, int end) {
- return buffer.substring(start, end);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import java.io.*;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+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 {
+
+static double pi = 3.1415926535;
+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 (int)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.
+ */
+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.
+ */
+public static OutputStream newFileOutputStream(String filename) throws IOException {
+ return new FileOutputStream(filename);
+}
+
+/**
+ * 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 ch 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 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 {
+ 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
+ */
+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");
+ } catch (MissingResourceException ex) {
+ answer = key + " (no resource bundle)";
+ }
+ }
+ if (msgs != null) {
+ try {
+ answer = msgs.getString(key);
+ } 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);
+}
+
+/**
+ * Copies a range of characters into a new String.
+ *
+ * @param buffer the StringBuffer we want to copy from
+ * @param start the offset of the first character
+ * @param end the offset one past the last character
+ * @return a new String containing the characters from start to end - 1
+ *
+ * @exception IndexOutOfBoundsException
+ * when <code>start < 0, start > end</code> or <code>end > length()</code>
+ */
+public static String substring(StringBuffer buffer, int start, int end) {
+ return buffer.substring(start, end);
+}
+
+}
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
index a2f1cd6999..7099aad332 100644
--- 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
@@ -1,25 +1,25 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 {
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 {
} \ No newline at end of file
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
index af6499fc12..1232f736f6 100644
--- 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
@@ -1,34 +1,34 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 {
-
-/**
- * Constructs a new instance of this class.
- *
- * @param source the object which fired the event
- */
-public SWTEventObject(Object source) {
- super(source);
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 {
+
+/**
+ * Constructs a new instance of this class.
+ *
+ * @param source the object which fired the event
+ */
+public SWTEventObject(Object source) {
+ super(source);
+}
} \ No newline at end of file
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
index fd8b229a67..5c5e43ac4f 100644
--- 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
@@ -1,42 +1,42 @@
-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_Charset_Western=western
-SWT_Charset_EastEuropean=east european
-SWT_Charset_SouthEuropean=south european
-SWT_Charset_NorthEuropean=north european
-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=simplified chinese
-SWT_Charset_TraditionalChinese=traditional chinese
-SWT_Charset_Japanese=japanese
-SWT_Charset_Korean=korean
-SWT_Charset_Unicode=unicode
-SWT_Charset_ASCII=ASCII
+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_Charset_Western=western
+SWT_Charset_EastEuropean=east european
+SWT_Charset_SouthEuropean=south european
+SWT_Charset_NorthEuropean=north european
+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=simplified chinese
+SWT_Charset_TraditionalChinese=traditional chinese
+SWT_Charset_Japanese=japanese
+SWT_Charset_Korean=korean
+SWT_Charset_Unicode=unicode
+SWT_Charset_ASCII=ASCII
SWT_InputMethods=Input Methods \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SerializableCompatibility.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SerializableCompatibility.java
index 13399fd72b..67ab74a64b 100644
--- 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
@@ -1,26 +1,26 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 {
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 {
} \ No newline at end of file
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
index 999b1c4e1d..33119cb970 100644
--- 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
@@ -1,86 +1,86 @@
package org.eclipse.swt.internal; /* * Copyright (c) 2001, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html */
-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 REORDER = 0;
- public static final int LIGATE = 0;
- public static final int GLYPHSHAPE = 0;
-
-/*
- * Not implemented.
- */
-public static void addLanguageListener(int 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 hwnd) {
-}
-/*
- * Not implemented.
- */
-public static void setKeyboardLanguage(int language) {
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html */
+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 REORDER = 0;
+ public static final int LIGATE = 0;
+ public static final int GLYPHSHAPE = 0;
+
+/*
+ * Not implemented.
+ */
+public static void addLanguageListener(int 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 hwnd) {
+}
+/*
+ * Not implemented.
+ */
+public static void setKeyboardLanguage(int language) {
+}
+
} \ No newline at end of file
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
index 472937c2a6..fe4c0a3138 100644
--- 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
@@ -1,1071 +1,1071 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class CoolBar extends Composite {
- CoolItem[][] items = new CoolItem[0][0];
- CoolItem[] originalItems = new CoolItem[0];
- Cursor hoverCursor, dragCursor;
- CoolItem dragging = null;
- int mouseXOffset, itemXOffset;
- static final int ROW_SPACING = 2;
- static final int CLICK_DISTANCE = 3;
-
- boolean isLocked = false;
- boolean inDispose = false;
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
+
+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>(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 CoolBar (Composite parent, int style) {
- super (parent, checkStyle(style));
- Display display = getDisplay();
- 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(); 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;
- }
- }
- };
- int[] events = new int[] {
- SWT.Dispose,
- SWT.MouseDown,
- SWT.MouseExit,
- SWT.MouseMove,
- SWT.MouseUp,
- SWT.MouseDoubleClick,
- SWT.Paint
- };
- for (int i = 0; i < events.length; i++) {
- addListener(events[i], listener);
- }
-}
-private static int checkStyle (int style) {
- return (style | SWT.NO_REDRAW_RESIZE) & ~(SWT.V_SCROLL | SWT.H_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;
- for (int row = 0; row < items.length; row++) {
- int rowWidth = 0, rowHeight = 0;
- for (int i = 0; i < items[row].length; i++) {
- rowWidth += items[row][i].preferredWidth;
- rowHeight = Math.max(rowHeight, items[row][i].getSize().y);
- }
- height += rowHeight;
- if (row > 0) height += ROW_SPACING;
- width = Math.max(width, rowWidth);
- }
- 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);
-}
-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.getBounds();
- 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
- * </ul>
+public class CoolBar extends Composite {
+ CoolItem[][] items = new CoolItem[0][0];
+ CoolItem[] originalItems = new CoolItem[0];
+ Cursor hoverCursor, dragCursor;
+ CoolItem dragging = null;
+ int mouseXOffset, itemXOffset;
+ static final int ROW_SPACING = 2;
+ static final int CLICK_DISTANCE = 3;
+
+ boolean isLocked = false;
+ boolean inDispose = false;
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
+ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
+ * </ul>
+ *
+ * @see SWT
+ * @see Widget#checkSubclass
+ * @see Widget#getStyle
*/
-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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
- * </ul>
+public CoolBar (Composite parent, int style) {
+ super (parent, checkStyle(style));
+ Display display = getDisplay();
+ 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(); 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;
+ }
+ }
+ };
+ int[] events = new int[] {
+ SWT.Dispose,
+ SWT.MouseDown,
+ SWT.MouseExit,
+ SWT.MouseMove,
+ SWT.MouseUp,
+ SWT.MouseDoubleClick,
+ SWT.Paint
+ };
+ for (int i = 0; i < events.length; i++) {
+ addListener(events[i], listener);
+ }
+}
+private static int checkStyle (int style) {
+ return (style | SWT.NO_REDRAW_RESIZE) & ~(SWT.V_SCROLL | SWT.H_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;
+ for (int row = 0; row < items.length; row++) {
+ int rowWidth = 0, rowHeight = 0;
+ for (int i = 0; i < items[row].length; i++) {
+ rowWidth += items[row][i].preferredWidth;
+ rowHeight = Math.max(rowHeight, items[row][i].getSize().y);
+ }
+ height += rowHeight;
+ if (row > 0) height += ROW_SPACING;
+ width = Math.max(width, rowWidth);
+ }
+ 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);
+}
+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.getBounds();
+ 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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);
-}
-/**
- * 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 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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.
+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);
+}
+/**
+ * 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>
*/
-void insertItemIntoRow(CoolItem item, int rowIndex, int x_root) {
- int barWidth = getSize().x;
- int rowY = items[rowIndex][0].getBounds().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].getBounds().x) break;
- }
- 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.getBounds();
- 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.getSize().y;
- if (index < items[rowIndex].length - 1) {
- CoolItem right = items[rowIndex][index + 1];
- width = right.getBounds().x - x;
- if (width < right.internalGetMinimumWidth()) {
- moveRight(right, right.internalGetMinimumWidth() - width);
- width = right.getBounds().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.getBounds();
- item.requestedWidth = bounds.width;
- redraw(bounds.x, bounds.y, item.internalGetMinimumWidth(), bounds.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.getBounds();
- bounds.width = lastItem.preferredWidth;
- lastItem.requestedWidth = lastItem.preferredWidth;
- lastItem.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
- }
- 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;
- layoutItems();
-
- 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 destroyItem(CoolItem item) {
- if (inDispose) return;
- int row = findItem(item).y;
- if (row == -1) return;
- Rectangle bounds = item.getBounds();
- removeItemFromRow(item, row, true);
- redraw(bounds.x, bounds.y, CoolItem.MINIMUM_WIDTH, bounds.height, false);
- relayout();
-
- 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;
-}
-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.getBounds();
- redraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height, false);
- 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;
- }
- 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.getBounds();
- 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.getBounds();
- if (leftBounds.x + left.internalGetMinimumWidth() > x) {
- int shift = leftBounds.x + left.internalGetMinimumWidth() - x;
- moveLeft(left, shift);
- leftBounds = left.getBounds();
- }
- 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) {
- redraw(x, bounds.y, damagedWidth, bounds.height, false);
- }
-}
-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.getBounds();
- int minSpaceOnRight = 0;
- for (int i = index; i < items[row].length; i++) {
- minSpaceOnRight += items[row][i].internalGetMinimumWidth();
- }
- int max = getBounds().width - minSpaceOnRight;
- int x = Math.min(max, bounds.x + pixels);
- int width = 0;
- if (index + 1 == items[row].length) {
- width = getBounds().width - x;
- } else {
- CoolItem right = items[row][index + 1];
- Rectangle rightBounds = right.getBounds();
- if (x + item.internalGetMinimumWidth() > rightBounds.x) {
- int shift = x + item.internalGetMinimumWidth() - rightBounds.x;
- moveRight(right, shift);
- rightBounds = right.getBounds();
- }
- width = rightBounds.x - x;
- }
- item.setBounds(x, bounds.y, width, bounds.height);
- item.requestedWidth = width;
- CoolItem left = items[row][index - 1];
- Rectangle leftBounds = left.getBounds();
- 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) {
- redraw(bounds.x - CoolItem.MARGIN_WIDTH, bounds.y, damagedWidth, bounds.height, false);
- }
-}
-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.getBounds();
- redraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height, false);
- 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;
- }
- else {
- insertItemIntoRow(item, newRowIndex, x_root);
- }
- if (resize) relayout();
- else layoutItems();
-}
-void onDispose() {
- /*
- * 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.
- */
- inDispose = true;
- 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();
-}
-void onMouseDown(Event event) {
- if (isLocked || event.button != 1) return;
- dragging = getGrabbedItem(event.x, event.y);
- if (dragging != null) {
- mouseXOffset = event.x;
- itemXOffset = mouseXOffset - dragging.getBounds().x;
- setCursor(dragCursor);
- }
-}
-void onMouseExit() {
- if (dragging == null) setCursor(null);
-}
-void onMouseMove(Event event) {
- if (isLocked) return;
- 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.getBounds();
- 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;
- return;
- }
- if (grabbed != null) {
- setCursor(hoverCursor);
- }
- else {
- setCursor(null);
- }
-}
-void onMouseUp(Event event) {
- setCursor(null);
- dragging = null;
-}
-void onMouseDoubleClick(Event event) {
- if (isLocked) return;
- dragging = null;
- CoolItem target = getGrabbedItem(event.x, event.y);
- if (target == null) {
- setCursor(null);
- return;
- }
-
- Point location = findItem(target);
- int row = location.y;
- int index = location.x;
- if (items[row].length > 1) {
- Point size = target.getSize();
- int maxSize = getSize().x;
- for (int i = 0; i < items[row].length; i++) {
- if (i != index) {
- maxSize -= items[row][i].internalGetMinimumWidth();
- }
- }
- if (size.x == maxSize) {
- /* The item is at its maximum width. It should be resized to its minimum width. */
- int distance = size.x - 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 (size.x < target.preferredWidth) {
- /* The item is less than its preferredWidth. Resize to preferredWidth. */
- int distance = target.preferredWidth - size.x;
- if (index + 1 < items[row].length) {
- CoolItem right = items[row][index + 1];
- moveRight(right, distance);
- distance = target.preferredWidth - target.getSize().x;
- }
- 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);
- }
-}
-void onPaint(Event event) {
- GC gc = event.gc;
- if (items.length == 0) return;
- Display display = getDisplay();
- Color shadowColor = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- Color highlightColor = display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
-
- int stopX = getBounds().width;
- 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].getBounds();
- if (!gc.getClipping().intersects(bounds)) continue;
-
- /* Draw separator. */
- if (i != 0) {
- gc.setForeground(shadowColor);
- gc.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height - 1);
- gc.setForeground(highlightColor);
- gc.drawLine(bounds.x + 1, bounds.y, bounds.x + 1, bounds.y + bounds.height - 1);
- }
-
- /* Draw grabber. */
- if (!isLocked) {
- int grabberTrim = 2;
- int grabberHeight = bounds.height - (2 * CoolItem.MARGIN_HEIGHT) - (2 * grabberTrim) - 1;
- gc.setForeground(shadowColor);
- gc.drawRectangle(
- bounds.x + CoolItem.MARGIN_WIDTH,
- bounds.y + CoolItem.MARGIN_HEIGHT + grabberTrim,
- 2,
- grabberHeight);
- gc.setForeground(highlightColor);
- gc.drawLine(
- bounds.x + CoolItem.MARGIN_WIDTH,
- bounds.y + CoolItem.MARGIN_HEIGHT + grabberTrim + 1,
- bounds.x + CoolItem.MARGIN_WIDTH,
- bounds.y + CoolItem.MARGIN_HEIGHT + grabberTrim + grabberHeight - 1);
- gc.drawLine(
- bounds.x + CoolItem.MARGIN_WIDTH,
- bounds.y + CoolItem.MARGIN_HEIGHT + grabberTrim,
- bounds.x + CoolItem.MARGIN_WIDTH + 1,
- bounds.y + CoolItem.MARGIN_HEIGHT + grabberTrim);
- }
- }
- if (row + 1 < items.length) {
- /* Draw row separator. */
- int separatorY = bounds.y + bounds.height;
- gc.setForeground(shadowColor);
- gc.drawLine(0, separatorY, stopX, separatorY);
- gc.setForeground(highlightColor);
- gc.drawLine(0, separatorY + 1, stopX, separatorY + 1);
- }
- }
-}
-/**
- * Remove the item from the row. Adjust the x and width values
- * appropriately.
+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 removeItemFromRow(CoolItem item, int rowIndex, boolean disposed) {
- int index = findItem(item).x;
- int newLength = items[rowIndex].length - 1;
- Rectangle itemBounds = item.getBounds();
- 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;
- }
- 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.getBounds();
- int width = bounds.x + bounds.width;
- first.setBounds(0, bounds.y, width, bounds.height);
- first.requestedWidth = width;
- redraw(bounds.x, bounds.y, CoolItem.MINIMUM_WIDTH, bounds.height, false);
- } else {
- CoolItem previous = items[rowIndex][index - 1];
- Rectangle bounds = previous.getBounds();
- 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 layed out for the given width.
+void insertItemIntoRow(CoolItem item, int rowIndex, int x_root) {
+ int barWidth = getSize().x;
+ int rowY = items[rowIndex][0].getBounds().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].getBounds().x) break;
+ }
+ 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.getBounds();
+ 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.getSize().y;
+ if (index < items[rowIndex].length - 1) {
+ CoolItem right = items[rowIndex][index + 1];
+ width = right.getBounds().x - x;
+ if (width < right.internalGetMinimumWidth()) {
+ moveRight(right, right.internalGetMinimumWidth() - width);
+ width = right.getBounds().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.getBounds();
+ item.requestedWidth = bounds.width;
+ redraw(bounds.x, bounds.y, item.internalGetMinimumWidth(), bounds.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.getBounds();
+ bounds.width = lastItem.preferredWidth;
+ lastItem.requestedWidth = lastItem.preferredWidth;
+ lastItem.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
+ }
+ 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;
+ layoutItems();
+
+ 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 destroyItem(CoolItem item) {
+ if (inDispose) return;
+ int row = findItem(item).y;
+ if (row == -1) return;
+ Rectangle bounds = item.getBounds();
+ removeItemFromRow(item, row, true);
+ redraw(bounds.x, bounds.y, CoolItem.MINIMUM_WIDTH, bounds.height, false);
+ relayout();
+
+ 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;
+}
+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.getBounds();
+ redraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height, false);
+ 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;
+ }
+ 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.getBounds();
+ 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.getBounds();
+ if (leftBounds.x + left.internalGetMinimumWidth() > x) {
+ int shift = leftBounds.x + left.internalGetMinimumWidth() - x;
+ moveLeft(left, shift);
+ leftBounds = left.getBounds();
+ }
+ 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) {
+ redraw(x, bounds.y, damagedWidth, bounds.height, false);
+ }
+}
+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.getBounds();
+ int minSpaceOnRight = 0;
+ for (int i = index; i < items[row].length; i++) {
+ minSpaceOnRight += items[row][i].internalGetMinimumWidth();
+ }
+ int max = getBounds().width - minSpaceOnRight;
+ int x = Math.min(max, bounds.x + pixels);
+ int width = 0;
+ if (index + 1 == items[row].length) {
+ width = getBounds().width - x;
+ } else {
+ CoolItem right = items[row][index + 1];
+ Rectangle rightBounds = right.getBounds();
+ if (x + item.internalGetMinimumWidth() > rightBounds.x) {
+ int shift = x + item.internalGetMinimumWidth() - rightBounds.x;
+ moveRight(right, shift);
+ rightBounds = right.getBounds();
+ }
+ width = rightBounds.x - x;
+ }
+ item.setBounds(x, bounds.y, width, bounds.height);
+ item.requestedWidth = width;
+ CoolItem left = items[row][index - 1];
+ Rectangle leftBounds = left.getBounds();
+ 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) {
+ redraw(bounds.x - CoolItem.MARGIN_WIDTH, bounds.y, damagedWidth, bounds.height, false);
+ }
+}
+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.getBounds();
+ redraw(old.x, old.y, CoolItem.MINIMUM_WIDTH, old.height, false);
+ 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;
+ }
+ else {
+ insertItemIntoRow(item, newRowIndex, x_root);
+ }
+ if (resize) relayout();
+ else layoutItems();
+}
+void onDispose() {
+ /*
+ * 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.
+ */
+ inDispose = true;
+ 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();
+}
+void onMouseDown(Event event) {
+ if (isLocked || event.button != 1) return;
+ dragging = getGrabbedItem(event.x, event.y);
+ if (dragging != null) {
+ mouseXOffset = event.x;
+ itemXOffset = mouseXOffset - dragging.getBounds().x;
+ setCursor(dragCursor);
+ }
+}
+void onMouseExit() {
+ if (dragging == null) setCursor(null);
+}
+void onMouseMove(Event event) {
+ if (isLocked) return;
+ 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.getBounds();
+ 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;
+ return;
+ }
+ if (grabbed != null) {
+ setCursor(hoverCursor);
+ }
+ else {
+ setCursor(null);
+ }
+}
+void onMouseUp(Event event) {
+ setCursor(null);
+ dragging = null;
+}
+void onMouseDoubleClick(Event event) {
+ if (isLocked) return;
+ dragging = null;
+ CoolItem target = getGrabbedItem(event.x, event.y);
+ if (target == null) {
+ setCursor(null);
+ return;
+ }
+
+ Point location = findItem(target);
+ int row = location.y;
+ int index = location.x;
+ if (items[row].length > 1) {
+ Point size = target.getSize();
+ int maxSize = getSize().x;
+ for (int i = 0; i < items[row].length; i++) {
+ if (i != index) {
+ maxSize -= items[row][i].internalGetMinimumWidth();
+ }
+ }
+ if (size.x == maxSize) {
+ /* The item is at its maximum width. It should be resized to its minimum width. */
+ int distance = size.x - 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 (size.x < target.preferredWidth) {
+ /* The item is less than its preferredWidth. Resize to preferredWidth. */
+ int distance = target.preferredWidth - size.x;
+ if (index + 1 < items[row].length) {
+ CoolItem right = items[row][index + 1];
+ moveRight(right, distance);
+ distance = target.preferredWidth - target.getSize().x;
+ }
+ 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);
+ }
+}
+void onPaint(Event event) {
+ GC gc = event.gc;
+ if (items.length == 0) return;
+ Display display = getDisplay();
+ Color shadowColor = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ Color highlightColor = display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
+
+ int stopX = getBounds().width;
+ 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].getBounds();
+ if (!gc.getClipping().intersects(bounds)) continue;
+
+ /* Draw separator. */
+ if (i != 0) {
+ gc.setForeground(shadowColor);
+ gc.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height - 1);
+ gc.setForeground(highlightColor);
+ gc.drawLine(bounds.x + 1, bounds.y, bounds.x + 1, bounds.y + bounds.height - 1);
+ }
+
+ /* Draw grabber. */
+ if (!isLocked) {
+ int grabberTrim = 2;
+ int grabberHeight = bounds.height - (2 * CoolItem.MARGIN_HEIGHT) - (2 * grabberTrim) - 1;
+ gc.setForeground(shadowColor);
+ gc.drawRectangle(
+ bounds.x + CoolItem.MARGIN_WIDTH,
+ bounds.y + CoolItem.MARGIN_HEIGHT + grabberTrim,
+ 2,
+ grabberHeight);
+ gc.setForeground(highlightColor);
+ gc.drawLine(
+ bounds.x + CoolItem.MARGIN_WIDTH,
+ bounds.y + CoolItem.MARGIN_HEIGHT + grabberTrim + 1,
+ bounds.x + CoolItem.MARGIN_WIDTH,
+ bounds.y + CoolItem.MARGIN_HEIGHT + grabberTrim + grabberHeight - 1);
+ gc.drawLine(
+ bounds.x + CoolItem.MARGIN_WIDTH,
+ bounds.y + CoolItem.MARGIN_HEIGHT + grabberTrim,
+ bounds.x + CoolItem.MARGIN_WIDTH + 1,
+ bounds.y + CoolItem.MARGIN_HEIGHT + grabberTrim);
+ }
+ }
+ if (row + 1 < items.length) {
+ /* Draw row separator. */
+ int separatorY = bounds.y + bounds.height;
+ gc.setForeground(shadowColor);
+ gc.drawLine(0, separatorY, stopX, separatorY);
+ gc.setForeground(highlightColor);
+ gc.drawLine(0, separatorY + 1, stopX, separatorY + 1);
+ }
+ }
+}
+/**
+ * Remove the item from the row. Adjust the x and width values
+ * appropriately.
*/
-int layoutItems () {
- int y = 0, maxWidth = 0, width = getSize().x;
- 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 < items[row].length; i++) {
- CoolItem item = items[row][i];
- if (item.control != null) {
- rowHeight = Math.max(rowHeight, item.control.getSize().y);
- }
- available -= item.internalGetMinimumWidth();
- if (available < 0 && (width > item.internalGetMinimumWidth())) {
- /* push the next items into the next row */
- available += item.internalGetMinimumWidth();
- int amount = items[row].length - i;
- CoolItem[] nextRow;
- if (row + 1 == items.length) { /* Adding a new row */
- nextRow = new CoolItem [amount];
- CoolItem[][] newItems = new CoolItem [items.length + 1][];
- System.arraycopy(items, 0, newItems, 0, items.length);
- items = newItems;
- } else {
- nextRow = new CoolItem [amount + items [row + 1].length];
- System.arraycopy(items[row+1], 0, nextRow, amount, items [row + 1].length);
- }
- System.arraycopy(items[row], i, nextRow, 0, amount);
- items [row + 1] = nextRow;
- CoolItem[] thisRow = new CoolItem[i];
- System.arraycopy(items[row], 0, thisRow, 0, i);
- items[row] = thisRow;
- break;
- }
- }
- rowHeight += 2 * CoolItem.MARGIN_HEIGHT;
- if (row > 0) y += ROW_SPACING;
-
-
- /* lay the items out */
- for (int i = 0; i < items[row].length; 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.getBounds();
- 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 -= ROW_SPACING;
- damage.height += 2 * ROW_SPACING;
- }
- 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 + ROW_SPACING;
- 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;
- }
- redraw(damage.x, damage.y, damage.width, damage.height, false);
- }
- x += newWidth;
- }
- maxWidth = Math.max(maxWidth, x);
- y += rowHeight;
- }
- return y;
-}
-void relayout() {
- Point size = getSize();
- int height = layoutItems();
- Rectangle trim = computeTrim (0, 0, 0, height);
- if (height != size.y) super.setSize(size.x, trim.height);
-}
-public void setBounds (int x, int y, int width, int height) {
- super.setBounds (x, y, width, height);
- layoutItems();
-}
-public void setSize (int width, int height) {
- super.setSize (width, height);
- layoutItems();
-}
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
- * </ul>
+void removeItemFromRow(CoolItem item, int rowIndex, boolean disposed) {
+ int index = findItem(item).x;
+ int newLength = items[rowIndex].length - 1;
+ Rectangle itemBounds = item.getBounds();
+ 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;
+ }
+ 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.getBounds();
+ int width = bounds.x + bounds.width;
+ first.setBounds(0, bounds.y, width, bounds.height);
+ first.requestedWidth = width;
+ redraw(bounds.x, bounds.y, CoolItem.MINIMUM_WIDTH, bounds.height, false);
+ } else {
+ CoolItem previous = items[rowIndex][index - 1];
+ Rectangle bounds = previous.getBounds();
+ 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 layed out for the given width.
*/
-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>
+int layoutItems () {
+ int y = 0, maxWidth = 0, width = getSize().x;
+ 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 < items[row].length; i++) {
+ CoolItem item = items[row][i];
+ if (item.control != null) {
+ rowHeight = Math.max(rowHeight, item.control.getSize().y);
+ }
+ available -= item.internalGetMinimumWidth();
+ if (available < 0 && (width > item.internalGetMinimumWidth())) {
+ /* push the next items into the next row */
+ available += item.internalGetMinimumWidth();
+ int amount = items[row].length - i;
+ CoolItem[] nextRow;
+ if (row + 1 == items.length) { /* Adding a new row */
+ nextRow = new CoolItem [amount];
+ CoolItem[][] newItems = new CoolItem [items.length + 1][];
+ System.arraycopy(items, 0, newItems, 0, items.length);
+ items = newItems;
+ } else {
+ nextRow = new CoolItem [amount + items [row + 1].length];
+ System.arraycopy(items[row+1], 0, nextRow, amount, items [row + 1].length);
+ }
+ System.arraycopy(items[row], i, nextRow, 0, amount);
+ items [row + 1] = nextRow;
+ CoolItem[] thisRow = new CoolItem[i];
+ System.arraycopy(items[row], 0, thisRow, 0, i);
+ items[row] = thisRow;
+ break;
+ }
+ }
+ rowHeight += 2 * CoolItem.MARGIN_HEIGHT;
+ if (row > 0) y += ROW_SPACING;
+
+
+ /* lay the items out */
+ for (int i = 0; i < items[row].length; 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.getBounds();
+ 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 -= ROW_SPACING;
+ damage.height += 2 * ROW_SPACING;
+ }
+ 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 + ROW_SPACING;
+ 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;
+ }
+ redraw(damage.x, damage.y, damage.width, damage.height, false);
+ }
+ x += newWidth;
+ }
+ maxWidth = Math.max(maxWidth, x);
+ y += rowHeight;
+ }
+ return y;
+}
+void relayout() {
+ Point size = getSize();
+ int height = layoutItems();
+ Rectangle trim = computeTrim (0, 0, 0, height);
+ if (height != size.y) super.setSize(size.x, trim.height);
+}
+public void setBounds (int x, int y, int width, int height) {
+ super.setBounds (x, y, width, height);
+ layoutItems();
+}
+public void setSize (int width, int height) {
+ super.setSize (width, height);
+ layoutItems();
+}
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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 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 boolean getLocked () {
- checkWidget ();
- return isLocked;
-}
-/**
- * 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 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 int[] getWrapIndices () {
- checkWidget();
- if (items.length <= 1) return new int[]{};
- int[] data = new int[items.length - 1];
- int i = 0, nextWrap = items[0].length;
- for (int row = 1; row < items.length; row++) {
- data[i++] = nextWrap;
- nextWrap += items[row].length;
- }
- return data;
-}
-/**
- * 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 boolean getLocked () {
+ checkWidget ();
+ return isLocked;
+}
+/**
+ * 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 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 int[] getWrapIndices () {
+ checkWidget();
+ if (items.length <= 1) return new int[]{};
+ int[] data = new int[items.length - 1];
+ int i = 0, nextWrap = items[0].length;
+ for (int row = 1; row < items.length; row++) {
+ data[i++] = nextWrap;
+ nextWrap += items[row].length;
+ }
+ return data;
+}
+/**
+ * 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 setWrapIndices (int[] data) {
- checkWidget();
- if (data == null) data = new int[0];
- for (int i=0; i<data.length; i++) {
- if (data[i] < 0 || data[i] >= originalItems.length) error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (items.length == 0) return;
-
- CoolItem[] allItems = getItems();
- items = new CoolItem[0][];
- CoolItem[][] newItems;
- CoolItem[] row;
- int itemIndex = 0;
- for (int i = 0; i <= data.length; i++) {
- int nextWrap = (i < data.length) ? data[i] : allItems.length;
- if (nextWrap != 0) {
- row = new CoolItem[nextWrap - itemIndex];
- System.arraycopy(allItems, itemIndex, row, 0, row.length);
- itemIndex += row.length;
- newItems = new CoolItem[items.length + 1][];
- System.arraycopy(items, 0, newItems, 0, items.length);
- newItems[items.length] = row;
- items = newItems;
- }
- }
- relayout();
-}
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
- * </ul>
+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 setItemLayout (int[] itemOrder, int[] wrapIndices, Point[] sizes) {
- checkWidget();
- setItemOrder(itemOrder);
- setWrapIndices(wrapIndices);
- setItemSizes(sizes);
- relayout();
-}
-}
+public void setWrapIndices (int[] data) {
+ checkWidget();
+ if (data == null) data = new int[0];
+ for (int i=0; i<data.length; i++) {
+ if (data[i] < 0 || data[i] >= originalItems.length) error (SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (items.length == 0) return;
+
+ CoolItem[] allItems = getItems();
+ items = new CoolItem[0][];
+ CoolItem[][] newItems;
+ CoolItem[] row;
+ int itemIndex = 0;
+ for (int i = 0; i <= data.length; i++) {
+ int nextWrap = (i < data.length) ? data[i] : allItems.length;
+ if (nextWrap != 0) {
+ row = new CoolItem[nextWrap - itemIndex];
+ System.arraycopy(allItems, itemIndex, row, 0, row.length);
+ itemIndex += row.length;
+ newItems = new CoolItem[items.length + 1][];
+ System.arraycopy(items, 0, newItems, 0, items.length);
+ newItems[items.length] = row;
+ items = newItems;
+ }
+ }
+ relayout();
+}
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void setItemLayout (int[] itemOrder, int[] wrapIndices, Point[] sizes) {
+ checkWidget();
+ setItemOrder(itemOrder);
+ setWrapIndices(wrapIndices);
+ setItemSizes(sizes);
+ relayout();
+}
+}
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
index 043dcddd4b..325a1bc8a8 100644
--- 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
@@ -1,639 +1,639 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class CoolItem extends Item {
- Control control;
- CoolBar parent;
- int preferredWidth, requestedWidth;
- boolean ideal;
- Point minimumSize = new Point (MINIMUM_WIDTH, 2 * MARGIN_HEIGHT);
- Rectangle itemBounds = new Rectangle(0, 0, 0, 0);
-
- static final int MARGIN_WIDTH = 4;
- static final int MARGIN_HEIGHT = 0;
- static final int GRABBER_WIDTH = 2;
-
- 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
-
- static final int MINIMUM_WIDTH = (2 * MARGIN_WIDTH) + GRABBER_WIDTH;
-
- ToolBar chevron;
- 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
+
+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 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 index at which to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 class CoolItem extends Item {
+ Control control;
+ CoolBar parent;
+ int preferredWidth, requestedWidth;
+ boolean ideal;
+ Point minimumSize = new Point (MINIMUM_WIDTH, 2 * MARGIN_HEIGHT);
+ Rectangle itemBounds = new Rectangle(0, 0, 0, 0);
+
+ static final int MARGIN_WIDTH = 4;
+ static final int MARGIN_HEIGHT = 0;
+ static final int GRABBER_WIDTH = 2;
+
+ 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
+
+ static final int MINIMUM_WIDTH = (2 * MARGIN_WIDTH) + GRABBER_WIDTH;
+
+ ToolBar chevron;
+ 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, 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 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 index at which to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 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 (getDisplay(), 1, 1);
- ti.setImage (image);
- Point size = tb.computeSize (SWT.DEFAULT, SWT.DEFAULT);
- 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 CoolBar#getBorderWidth
- * @see CoolBar#computeTrim
- * @see CoolBar#getClientArea
+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 Point computeSize (int wHint, int hHint) {
- checkWidget();
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT) width = 32;
- if (hHint == SWT.DEFAULT) height = 32;
- width += MINIMUM_WIDTH + MARGIN_WIDTH;
- height += 2 * MARGIN_HEIGHT;
- 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) {
- Display display = getDisplay ();
- 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 ;
- 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 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.
*/
-public Rectangle getBounds () {
- checkWidget();
- 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>
+void calculateChevronTrim () {
+ ToolBar tb = new ToolBar (parent, SWT.FLAT);
+ ToolItem ti = new ToolItem (tb, SWT.PUSH);
+ Image image = new Image (getDisplay(), 1, 1);
+ ti.setImage (image);
+ Point size = tb.computeSize (SWT.DEFAULT, SWT.DEFAULT);
+ 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 CoolBar#getBorderWidth
+ * @see CoolBar#computeTrim
+ * @see CoolBar#getClientArea
*/
-public Control getControl () {
- checkWidget();
- return control;
-}
-public Display getDisplay () {
- Composite parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/**
- * 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 computeSize (int wHint, int hHint) {
+ checkWidget();
+ int width = wHint, height = hHint;
+ if (wHint == SWT.DEFAULT) width = 32;
+ if (hHint == SWT.DEFAULT) height = 32;
+ width += MINIMUM_WIDTH + MARGIN_WIDTH;
+ height += 2 * MARGIN_HEIGHT;
+ 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) {
+ Display display = getDisplay ();
+ 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 ;
+ 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 Point getMinimumSize () {
- checkWidget();
- return minimumSize;
-}
-/**
- * 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 Rectangle getBounds () {
+ checkWidget();
+ 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 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 Control getControl () {
+ checkWidget();
+ return control;
+}
+public Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+ * 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 getPreferredSize () {
- checkWidget();
- int height = getSize().y;
- return new Point(preferredWidth, height);
-}
-/**
- * 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 getMinimumSize () {
+ checkWidget();
+ return minimumSize;
+}
+/**
+ * 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 Point getSize () {
- checkWidget();
- return new Point (itemBounds.width, itemBounds.height);
-}
-int internalGetMinimumWidth () {
- int width = minimumSize.x;
- width += MINIMUM_WIDTH + MARGIN_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;
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 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 controlHeight = Math.min (height, control.getSize().y);
- int controlWidth = width - MINIMUM_WIDTH - MARGIN_WIDTH;
- if ((style & SWT.DROP_DOWN) != 0 && width < preferredWidth) {
- controlWidth -= CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
- }
- control.setBounds (
- x + MINIMUM_WIDTH,
- y + MARGIN_HEIGHT,
- controlWidth,
- controlHeight);
- }
- 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 Point getPreferredSize () {
+ checkWidget();
+ int height = getSize().y;
+ return new Point(preferredWidth, height);
+}
+/**
+ * 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 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;
- if (oldControl != null) oldControl.setVisible(false);
- this.control = control;
- if (control != null && !control.isDisposed ()) {
- Rectangle bounds = getBounds();
- control.setBounds (
- bounds.x + MINIMUM_WIDTH,
- bounds.y + MARGIN_HEIGHT,
- bounds.width - MINIMUM_WIDTH - MARGIN_WIDTH,
- bounds.height - (2 * MARGIN_HEIGHT));
- control.setVisible(true);
- }
-}
-/**
- * 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 Point getSize () {
+ checkWidget();
+ return new Point (itemBounds.width, itemBounds.height);
+}
+int internalGetMinimumWidth () {
+ int width = minimumSize.x;
+ width += MINIMUM_WIDTH + MARGIN_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.
*/
-public void setMinimumSize (int width, int height) {
- checkWidget ();
- setMinimumSize(new Point(width, height));
-}
-/**
- * Sets the minimum size that the cool item can be resized to
- * using the cool item's gripper, to the point specified by the argument.
- *
- * @param size a point representing the minimum width and height of the cool item, in pixels
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
+void onSelection (Event ev) {
+ Rectangle bounds = chevron.getBounds();
+ Event event = new Event();
+ event.detail = SWT.ARROW;
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 setMinimumSize (Point size) {
- checkWidget ();
- if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
- minimumSize = size;
-}
-/**
- * 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 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 controlHeight = Math.min (height, control.getSize().y);
+ int controlWidth = width - MINIMUM_WIDTH - MARGIN_WIDTH;
+ if ((style & SWT.DROP_DOWN) != 0 && width < preferredWidth) {
+ controlWidth -= CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
+ }
+ control.setBounds (
+ x + MINIMUM_WIDTH,
+ y + MARGIN_HEIGHT,
+ controlWidth,
+ controlHeight);
+ }
+ 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 setPreferredSize (int width, int height) {
- checkWidget();
- ideal = true;
- preferredWidth = Math.max (width, MINIMUM_WIDTH);
- Rectangle bounds = getBounds();
- setBounds(bounds.x, bounds.y, bounds.width, height);
- if (height != bounds.height) parent.relayout();
-}
-/**
- * Sets the receiver's ideal size to the point specified by the argument.
- *
- * @param size the new ideal size for the receiver
- * @param height the new ideal height 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 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;
+ if (oldControl != null) oldControl.setVisible(false);
+ this.control = control;
+ if (control != null && !control.isDisposed ()) {
+ Rectangle bounds = getBounds();
+ control.setBounds (
+ bounds.x + MINIMUM_WIDTH,
+ bounds.y + MARGIN_HEIGHT,
+ bounds.width - MINIMUM_WIDTH - MARGIN_WIDTH,
+ bounds.height - (2 * MARGIN_HEIGHT));
+ control.setVisible(true);
+ }
+}
+/**
+ * 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 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 setMinimumSize (int width, int height) {
+ checkWidget ();
+ setMinimumSize(new Point(width, height));
+}
+/**
+ * Sets the minimum size that the cool item can be resized to
+ * using the cool item's gripper, to the point specified by the argument.
+ *
+ * @param size a point representing the minimum width and height of the cool item, in pixels
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @since 2.0
*/
-public void setSize (int width, int height) {
- checkWidget();
- int newWidth = Math.max (width, MINIMUM_WIDTH);
- itemBounds.width = requestedWidth = newWidth;
- if (!ideal) preferredWidth = newWidth;
- itemBounds.height = height;
- if (control != null) {
- int controlWidth = newWidth - MINIMUM_WIDTH - MARGIN_WIDTH;
- if ((style & SWT.DROP_DOWN) != 0 && width < preferredWidth) {
- controlWidth -= CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
- }
- int controlHeight = height - (2 * MARGIN_HEIGHT);
- control.setSize(controlWidth, controlHeight);
- }
- 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
- * @param height the new height 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 setMinimumSize (Point size) {
+ checkWidget ();
+ if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
+ minimumSize = size;
+}
+/**
+ * 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 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) {
- int height = Math.min (control.getSize ().y, itemBounds.height);
- if (chevron == null) {
- chevron = new ToolBar (parent, SWT.FLAT | SWT.NO_FOCUS);
- ToolItem toolItem = new ToolItem (chevron, SWT.PUSH);
- chevron.setBackground (parent.getBackground());
- toolItem.addListener (SWT.Selection, new Listener() {
- public void handleEvent (Event event) {
- CoolItem.this.onSelection (event);
- }
- });
- }
- int imageHeight = Math.max(1, height - CHEVRON_VERTICAL_TRIM);
- if (arrowImage == null || (arrowImage != null && arrowImage.getBounds().height != imageHeight)) {
- Image image = createArrowImage (CHEVRON_IMAGE_WIDTH, imageHeight);
- chevron.getItem (0).setImage (image);
- if (arrowImage != null) arrowImage.dispose ();
- arrowImage = image;
- }
- chevron.setBounds (
- itemBounds.x + width - CHEVRON_LEFT_MARGIN - CHEVRON_IMAGE_WIDTH - CHEVRON_HORIZONTAL_TRIM,
- itemBounds.y + MARGIN_HEIGHT,
- CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM,
- height);
- chevron.setVisible(true);
- } else {
- if (chevron != null) {
- chevron.setVisible(false);
- }
- }
- }
-}
-}
+public void setPreferredSize (int width, int height) {
+ checkWidget();
+ ideal = true;
+ preferredWidth = Math.max (width, MINIMUM_WIDTH);
+ Rectangle bounds = getBounds();
+ setBounds(bounds.x, bounds.y, bounds.width, height);
+ if (height != bounds.height) parent.relayout();
+}
+/**
+ * Sets the receiver's ideal size to the point specified by the argument.
+ *
+ * @param size the new ideal size for the receiver
+ * @param height the new ideal height 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();
+ int newWidth = Math.max (width, MINIMUM_WIDTH);
+ itemBounds.width = requestedWidth = newWidth;
+ if (!ideal) preferredWidth = newWidth;
+ itemBounds.height = height;
+ if (control != null) {
+ int controlWidth = newWidth - MINIMUM_WIDTH - MARGIN_WIDTH;
+ if ((style & SWT.DROP_DOWN) != 0 && width < preferredWidth) {
+ controlWidth -= CHEVRON_IMAGE_WIDTH + CHEVRON_HORIZONTAL_TRIM + CHEVRON_LEFT_MARGIN;
+ }
+ int controlHeight = height - (2 * MARGIN_HEIGHT);
+ control.setSize(controlWidth, controlHeight);
+ }
+ 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
+ * @param height the new height 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) {
+ int height = Math.min (control.getSize ().y, itemBounds.height);
+ if (chevron == null) {
+ chevron = new ToolBar (parent, SWT.FLAT | SWT.NO_FOCUS);
+ ToolItem toolItem = new ToolItem (chevron, SWT.PUSH);
+ chevron.setBackground (parent.getBackground());
+ toolItem.addListener (SWT.Selection, new Listener() {
+ public void handleEvent (Event event) {
+ CoolItem.this.onSelection (event);
+ }
+ });
+ }
+ int imageHeight = Math.max(1, height - CHEVRON_VERTICAL_TRIM);
+ if (arrowImage == null || (arrowImage != null && arrowImage.getBounds().height != imageHeight)) {
+ Image image = createArrowImage (CHEVRON_IMAGE_WIDTH, imageHeight);
+ chevron.getItem (0).setImage (image);
+ if (arrowImage != null) arrowImage.dispose ();
+ arrowImage = image;
+ }
+ chevron.setBounds (
+ itemBounds.x + width - CHEVRON_LEFT_MARGIN - CHEVRON_IMAGE_WIDTH - CHEVRON_HORIZONTAL_TRIM,
+ itemBounds.y + MARGIN_HEIGHT,
+ 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/tabfolder/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/tabfolder/org/eclipse/swt/widgets/TabFolder.java
index 0ff216082e..448d9c7335 100644
--- 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
@@ -1,1152 +1,1152 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-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
+
+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>(none)</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>Selection</dd>
+ * </dl>
+ * <p>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ * </p>
*/
-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 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 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) {
- /*
- * 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 = CLIENT_MARGIN_WIDTH * 2 + TabItem.SHADOW_WIDTH * 2;
- int height = 0;
-
- if (items.length > 0) {
- TabItem lastItem = items[items.length-1];
- width = Math.max (width, lastItem.x + lastItem.width);
- }
- Point size;
- Layout layout = getLayout();
- if (layout != null) {
- size = layout.computeSize (this, wHint, hHint, 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);
- return new Point (trim.width, trim.height);
-}
-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'.
+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
*/
-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.
+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) {
+ /*
+ * 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 = CLIENT_MARGIN_WIDTH * 2 + TabItem.SHADOW_WIDTH * 2;
+ int height = 0;
+
+ if (items.length > 0) {
+ TabItem lastItem = items[items.length-1];
+ width = Math.max (width, lastItem.x + lastItem.width);
+ }
+ Point size;
+ Layout layout = getLayout();
+ if (layout != null) {
+ size = layout.computeSize (this, wHint, hHint, 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);
+ return new Point (trim.width, trim.height);
+}
+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 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 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 doDispose() {
- inDispose = true;
- // 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 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 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 doDispose() {
+ inDispose = true;
+ // 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 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 = getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
- final Color LightShadow = getDisplay().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(getDisplay().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(getDisplay().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 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 drawPlainButton(GC gc, int xPos, int yPos, int size) {
- Color rightBottomColor = getForeground();
- Color leftTopColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- Color rightBottomInnerColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
- Color leftTopInnerColor = getDisplay().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 = getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
- leftTopColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
- rightBottomInnerColor = getDisplay().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 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 = getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
+ final Color LightShadow = getDisplay().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(getDisplay().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(getDisplay().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 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 drawPlainButton(GC gc, int xPos, int yPos, int size) {
+ Color rightBottomColor = getForeground();
+ Color leftTopColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ Color rightBottomInnerColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
+ Color leftTopInnerColor = getDisplay().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 = getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
+ leftTopColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
+ rightBottomInnerColor = getDisplay().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 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.
+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.
*/
-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>
+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.
*/
-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>
+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.
*/
-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>
+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 [] getItems() {
- checkWidget();
- TabItem[] tabItems = new TabItem [items.length];
- System.arraycopy(items, 0, tabItems, 0, items.length);
- return tabItems;
-}
-/**
- * Returns the area where the two scroll buttons are drawn.
+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>
*/
-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 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 [] 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 TabItem [] getItems() {
+ checkWidget();
+ TabItem[] tabItems = new TabItem [items.length];
+ System.arraycopy(items, 0, tabItems, 0, items.length);
+ return tabItems;
+}
+/**
+ * Returns the area where the two scroll buttons are drawn.
*/
-public int getSelectionIndex() {
- checkWidget();
- return selectedIndex;
-}
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-/**
- * Handle the events that I have hooked on the canvas.
+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>
*/
-void handleEvents (Event event){
- switch (event.type) {
- case SWT.Dispose:
- doDispose();
- 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:
- //do nothing - this callback exists so that widget is included in tab order
- 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 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 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.
+public int getSelectionIndex() {
+ checkWidget();
+ return selectedIndex;
+}
+public String getToolTipText () {
+ checkWidget();
+ return toolTipText;
+}
+/**
+ * Handle the events that I have hooked on the canvas.
*/
-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.
+void handleEvents (Event event){
+ switch (event.type) {
+ case SWT.Dispose:
+ doDispose();
+ 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:
+ //do nothing - this callback exists so that widget is included in tab order
+ 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>
*/
-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.
+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.
*/
-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();
- }
-}
-
-/**
- * Layout the items and store the client area size.
+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.
*/
-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);
-}
-/**
- * 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.
+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.
*/
-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.
+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 mouseUp(Event event) {
- if (scrollButtonDown && event.button == 1) {
- scrollButtonDown = false;
- redrawHitButton(event);
- }
-}
-/**
- * Paint the receiver.
+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();
+ }
+}
+
+/**
+ * Layout the items and store the client area size.
*/
-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 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);
+}
+/**
+ * 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 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 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 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 mouseUp(Event event) {
+ if (scrollButtonDown && event.button == 1) {
+ scrollButtonDown = false;
+ redrawHitButton(event);
+ }
+}
+/**
+ * Paint the receiver.
*/
-void redrawScrollButtons() {
- Rectangle scrollButtonArea = getScrollButtonArea();
-
- redraw(
- scrollButtonArea.x, scrollButtonArea.y,
- scrollButtonArea.width, scrollButtonArea.height, false);
-}
-/**
- * Redraw the tabs at the specified indexes.
+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 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 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 redrawTabs() {
- redraw(0, 0, super.getClientArea().width, getClientArea().y);
-}
-/**
- * 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
+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
*/
-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 redrawScrollButtons() {
+ Rectangle scrollButtonArea = getScrollButtonArea();
+
+ redraw(
+ scrollButtonArea.x, scrollButtonArea.y,
+ scrollButtonArea.width, scrollButtonArea.height, false);
+}
+/**
+ * Redraw the tabs at the specified indexes.
*/
-void scrollLeft() {
- if (topTabIndex > 0) {
- --topTabIndex;
- layoutItems();
- redrawTabs();
- }
-}
-/**
- * Scroll the tab items to the right.
+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 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();
- }
- }
-}
-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 selected 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>
+void redrawTabs() {
+ redraw(0, 0, super.getClientArea().width, getClientArea().y);
+}
+/**
+ * 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 setSelection(int index) {
- checkWidget();
- setSelection(index, false);
-}
-/**
- * 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+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.
*/
-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 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 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:
- event.doit = true;
- break;
- case SWT.TRAVERSE_MNEMONIC:
- event.doit = mnemonicTraversal(event);
- if (event.doit) event.detail = SWT.TRAVERSE_NONE;
- break;
- case SWT.TRAVERSE_PAGE_NEXT:
- case SWT.TRAVERSE_PAGE_PREVIOUS:
- event.doit = pageTraversal(event);
- if (event.doit) event.detail = SWT.TRAVERSE_NONE;
- break;
- case SWT.TRAVERSE_ARROW_NEXT:
- if (selectedIndex < items.length - 1) {
- setSelection(selectedIndex + 1, true);
- }
- event.doit = true;
- event.detail = SWT.TRAVERSE_NONE;
- break;
- case SWT.TRAVERSE_ARROW_PREVIOUS:
- if (selectedIndex > 0) {
- setSelection(selectedIndex - 1, true);
- }
- event.doit = true;
- event.detail = SWT.TRAVERSE_NONE;
- break;
- }
-}
-
-boolean pageTraversal(Event event) {
- int count = getItemCount ();
- if (count == 0) return false;
- int index = getSelectionIndex ();
- if (index == -1) {
- index = 0;
- } else {
- int offset = (event.detail == SWT.TRAVERSE_PAGE_NEXT) ? 1 : -1;
- index = (index + offset + count) % count;
- }
- setSelection (index, true);
- return true;
-}
-
-boolean mnemonicTraversal (Event event) {
- char key = event.character;
- for (int i = 0; i < items.length; i++) {
- if (items[i] != null) {
- char mnemonic = getMnemonic (items[i].getText ());
- if (mnemonic != '\0') {
- if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) {
- setSelection(i, true);
- return true;
- }
- }
- }
- }
- return false;
-}
-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';
-}
-}
+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();
+ }
+ }
+}
+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 selected 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();
+ setSelection(index, false);
+}
+/**
+ * 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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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:
+ event.doit = true;
+ break;
+ case SWT.TRAVERSE_MNEMONIC:
+ event.doit = mnemonicTraversal(event);
+ if (event.doit) event.detail = SWT.TRAVERSE_NONE;
+ break;
+ case SWT.TRAVERSE_PAGE_NEXT:
+ case SWT.TRAVERSE_PAGE_PREVIOUS:
+ event.doit = pageTraversal(event);
+ if (event.doit) event.detail = SWT.TRAVERSE_NONE;
+ break;
+ case SWT.TRAVERSE_ARROW_NEXT:
+ if (selectedIndex < items.length - 1) {
+ setSelection(selectedIndex + 1, true);
+ }
+ event.doit = true;
+ event.detail = SWT.TRAVERSE_NONE;
+ break;
+ case SWT.TRAVERSE_ARROW_PREVIOUS:
+ if (selectedIndex > 0) {
+ setSelection(selectedIndex - 1, true);
+ }
+ event.doit = true;
+ event.detail = SWT.TRAVERSE_NONE;
+ break;
+ }
+}
+
+boolean pageTraversal(Event event) {
+ int count = getItemCount ();
+ if (count == 0) return false;
+ int index = getSelectionIndex ();
+ if (index == -1) {
+ index = 0;
+ } else {
+ int offset = (event.detail == SWT.TRAVERSE_PAGE_NEXT) ? 1 : -1;
+ index = (index + offset + count) % count;
+ }
+ setSelection (index, true);
+ return true;
+}
+
+boolean mnemonicTraversal (Event event) {
+ char key = event.character;
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] != null) {
+ char mnemonic = getMnemonic (items[i].getText ());
+ if (mnemonic != '\0') {
+ if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) {
+ setSelection(i, true);
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+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';
+}
+}
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
index cbd2ad0053..a4fd023f1d 100644
--- 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
@@ -1,408 +1,408 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-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.
- // Used for preferred item width calculation
-/**
- * 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
+
+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 TabItem (TabFolder parent, int style) {
- this(parent, style, 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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 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.
+ // Used for preferred item width calculation
+/**
+ * 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, 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.
+public TabItem (TabFolder parent, int style) {
+ this(parent, style, 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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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
*/
-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.
+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.
*/
-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>
+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.
*/
-public Control getControl () {
- checkWidget();
- return control;
-}
-public Display getDisplay() {
- if (parent == null) error(SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay();
-}
-/**
- * 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>
+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 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 Control getControl () {
+ checkWidget();
+ return control;
+}
+public Display getDisplay() {
+ if (parent == null) error(SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay();
+}
+/**
+ * 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 String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-/**
- * Answer true if the receiver has been layed out.
+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>
*/
-boolean hasLocation() {
- return !(width == 0 && height == 0 && x == 0 && y == 0);
-}
-/**
- * Answer the image height.
+public String getToolTipText () {
+ checkWidget();
+ return toolTipText;
+}
+/**
+ * Answer true if the receiver has been layed out.
*/
-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.
+boolean hasLocation() {
+ return !(width == 0 && height == 0 && x == 0 && y == 0);
+}
+/**
+ * Answer the image height.
*/
-private int imageWidth() {
- Image image = getImage();
-
- if (image != null && !image.isDisposed()) {
- return image.getBounds().width;
- } else {
- return 0;
- }
-}
-/**
- * Paint the receiver.
+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.
*/
-void paint(GC gc, boolean isSelected) {
- // high light colored line across left and top
- gc.setForeground(parent.getDisplay().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(parent.getDisplay().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(parent.getDisplay().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(parent.getDisplay().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;
- gc.drawText(getText(), xDraw, yCenter, flags);
-}
-/**
- * Answer the preferred height of the receiver for the GC.
+private int imageWidth() {
+ Image image = getImage();
+
+ if (image != null && !image.isDisposed()) {
+ return image.getBounds().width;
+ } else {
+ return 0;
+ }
+}
+/**
+ * Paint the receiver.
*/
-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.
+void paint(GC gc, boolean isSelected) {
+ // high light colored line across left and top
+ gc.setForeground(parent.getDisplay().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(parent.getDisplay().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(parent.getDisplay().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(parent.getDisplay().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;
+ gc.drawText(getText(), xDraw, yCenter, flags);
+}
+/**
+ * Answer the preferred height 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>
+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.
*/
-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.
- *
- * @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>
+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 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 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.
+ *
+ * @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 setToolTipText (String string) {
- checkWidget();
- toolTipText = string;
-}
-/**
- * Answer the text height.
+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>
*/
-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.
+public void setToolTipText (String string) {
+ checkWidget();
+ toolTipText = string;
+}
+/**
+ * Answer the text height.
*/
-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;
-}
-}
+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/treetable/org/eclipse/swt/widgets/AbstractTreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/AbstractTreeItem.java
index b48dde3da5..485a2afacd 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/AbstractTreeItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/AbstractTreeItem.java
@@ -1,313 +1,313 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * This class stores and manages child items of a tree item.
- * It provides protocol to query the index of an item relative
- * to the root and to retrieve items by index.
- * The TreeItem class implements this protocol for general
- * tree items.
- * TreeRoots provides a special implementation that allows the
- * Tree class to treat trees with one root and with multiple
- * roots equally.
- */
-abstract class AbstractTreeItem extends SelectableItem {
- private Vector children;
- private boolean isExpanded = false;
- // number of children.
- // includes all expanded items down to the leafs.
- private int visibleItemCount = 0;
-
-/**
- * Create a new instance of the receiver.
- * @param parent - widget the receiver belongs to
- * @param swtStyle - widget style. see Widget class for details
- */
-AbstractTreeItem(Tree parent, int swtStyle) {
- super(parent, swtStyle);
-}
-/**
- * Insert 'item' in the list of child items. Notify the
- * parent about the new item.
- * @param 'item' - the item that should be added to the
- * receiver's children.
- * @param index - position that 'item' will be inserted at
- * in the receiver.
- */
-void add(TreeItem item, int index) {
- Vector items = getChildren();
- int visibleIndex = getVisibleIndex();
-
- if (index < 0 || index > items.size()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- if (item.isRoot()) {
- visibleIndex = index;
- }
- else
- if (isExpanded == false) {
- visibleIndex = -1;
- }
- if (visibleIndex != -1) {
- if (index > 0) {
- TreeItem previousChild = (TreeItem) getChildren().elementAt(index - 1);
- visibleIndex = previousChild.getVisibleIndex() + previousChild.getVisibleItemCount() + 1;
- }
- else {
- visibleIndex = getVisibleIndex() + 1;
- }
- }
- getSelectableParent().addingItem(item, visibleIndex);
- item.setIndex(index);
- resetChildIndices(index, true);
- items.insertElementAt(item, index);
- if (isExpanded == true) {
- visibleItemCount++;
- calculateVisibleItemCountParent();
- }
- getSelectableParent().addedItem(item, visibleIndex);
-}
-/**
- * Set whether the receiver is expanded or not.
- * If the receiver is expanded its child items are visible.
- * @param expanded -
- * true=the receiver is expanded, making its child items visible.
- * false=the receiver is collapsed, making its child items invisible
- */
-void internalSetExpanded(boolean expanded) {
- isExpanded = expanded;
- calculateVisibleItemCount();
-}
-/**
- * Calculate the number of expanded children.
- * Recurse up in the tree to the root item.
- */
-abstract void calculateVisibleItemCount();
-/**
- * Calculate the number of expanded children for the parent item
- * of this item.
- */
-abstract void calculateVisibleItemCountParent();
-/**
- * Deselect the receiver and all children
- */
-void deselectAll() {
- Enumeration children = getChildren().elements();
- AbstractTreeItem treeItem;
-
- setSelected(false);
- while (children.hasMoreElements() == true) {
- treeItem = (AbstractTreeItem) children.nextElement();
- treeItem.deselectAll();
- }
-}
-public void dispose() {
- if (isDisposed()) return;
- Vector children = getChildren();
- AbstractTreeItem child;
- while (children.size() > 0) { // TreeItem objects are removed from vector during dispose
- child = (AbstractTreeItem) children.firstElement();
- child.dispose();
- }
- super.dispose();
-}
-void doDispose() {
- setChildren(null);
- visibleItemCount = 0;
- super.doDispose();
-}
-/**
- * Answer the Vector containing the child items of the receiver.
- */
-Vector getChildren() {
- if (children == null) {
- children = new Vector(4);
- }
- return children;
-}
-/**
- * Answer whether the receiver is expanded or not.
- * If the receiver is expanded its children are visible.
- * @return
- * true - the receiver is expanded, making its children visible
- * false - the receiver is collapsed, making its children invisible
- */
-public boolean getExpanded() {
- checkWidget();
-
- return isExpanded;
-}
-/**
- * Answer the number of children.
- */
-public int getItemCount() {
- checkWidget();
-
- return getChildren().size();
-}
-/**
- * Answer the index of the receiver relative to the first root
- * item.
- * If 'anIndex' is the global index of the expanded item 'anItem'
- * then the following expressions are true:
- * 'anItem == theRoot.getVisibleItem(anIndex)' and
- * 'anIndex == anItem.getVisibleIndex()'
- * @return
- * The index of the receiver relative to the first root item.
- * Answer -1 if the receiver is not visible (because the parent
- * is collapsed).
- */
-abstract int getVisibleIndex();
-/**
- * Answer the index of the child item identified by 'childIndex'
- * relative to the first root item.
- */
-abstract int getVisibleIndex(int childIndex);
-/**
- * Answer the item at 'searchIndex' relativ to the receiver.
- * When this method is called for the root item, 'searchIndex'
- * represents the global index into all items of the tree.
- * searchIndex=0 returns the receiver.
- * searchIndex=1 returns the first visible child.
- * Note: searchIndex must be >= 0
- *
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. Visible here means that all
- * the parents of the item are expanded. An item is only
- * visible on screen if it is within the receiver's parent's
- * client area.
- */
-abstract TreeItem getVisibleItem(int searchIndex);
-/**
- * Answer the number of expanded children, direct and indirect.
- */
-int getVisibleItemCount() {
- return visibleItemCount;
-}
-/**
- * Returns the expanded state. Circumvent widget/thread check
- * for performance. For non-API callers only.
- */
-boolean internalGetExpanded() {
- return isExpanded;
-}
-/**
- * Answer whether the receiver is a leaf item.
- * An item is a leaf when it has no child items.
- * @return
- * true - receiver is a leaf item
- * false - receiver is not a leaf item.
- */
-boolean isLeaf() {
- return (getChildren().size() == 0);
-}
-/**
- * Answer whether the receiver is a root item.
- * The receiver is a root item when it doesn't have a parent item.
- * @return
- * true - the receiver is a root item.
- * false - the receiver is not a root item.
- */
-boolean isRoot() {
- return false;
-}
-/**
- * Remove 'child' from the receiver.
- * Notify the parent widget only if it is not being disposed itself.
- */
-void removeItem(SelectableItem child) {
- Vector children = getChildren();
- SelectableItemWidget parent = getSelectableParent();
- int childIndex = children.indexOf(child);
-
- if (childIndex != -1) {
- if (((Tree) parent).isRemovingAll() == true) {
- children.removeElementAt(childIndex); // just remove the item from the list if the whole tree is being disposed
- if (isExpanded == true) {
- visibleItemCount--;
- calculateVisibleItemCountParent();
- }
- }
- else {
- parent.removingItem(child);
- children.removeElementAt(childIndex);
- if (isExpanded == true) {
- visibleItemCount--;
- calculateVisibleItemCountParent();
- }
- resetChildIndices(childIndex, false); // mark child index dirty
- parent.removedItem(child);
- }
- }
-}
-/**
- * Allow subclasses to reset any cached data.
- * Called for all children of the receiver.
- */
-void reset() {
- Enumeration children = getChildren().elements();
- AbstractTreeItem treeItem;
-
- while (children.hasMoreElements() == true) {
- treeItem = (AbstractTreeItem) children.nextElement();
- treeItem.reset();
- }
-}
-/**
- * Mark all child indices dirty starting with the child at
- * 'startIndex'. This causes getIndex to recalculate the index.
- * @param startIndex - index in the list of children at which
- * and after which the indices are reset.
- */
-void resetChildIndices(int startIndex, boolean addItem) {
- Vector children = getChildren();
- TreeItem child;
- int increment = addItem ? 1 : 0;
-
- for (int i = startIndex; i < children.size(); i++) {
- child = (TreeItem) children.elementAt(i);
- child.setIndex(i + increment); // mark child index dirty
- }
-}
-/**
- * Select the receiver and all children.
- * Return a Vector containing all the items that have been selected
- * (and that have not been selected before).
- */
-Vector selectAll(Vector selectedItems) {
- Enumeration children = getChildren().elements();
- AbstractTreeItem treeItem;
-
- if (isSelected() == false) {
- selectedItems.addElement(this);
- setSelected(true);
- getSelectableParent().redrawSelection(this);
- }
- while (children.hasMoreElements() == true) {
- treeItem = (AbstractTreeItem) children.nextElement();
- selectedItems = treeItem.selectAll(selectedItems);
- }
- return selectedItems;
-}
-/**
- * Set the Array containing the receiver's child items to 'children'.
- */
-void setChildren(Vector children) {
- this.children = children;
-}
-
-void setVisibleItemCount(int count) {
- visibleItemCount = count;
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * This class stores and manages child items of a tree item.
+ * It provides protocol to query the index of an item relative
+ * to the root and to retrieve items by index.
+ * The TreeItem class implements this protocol for general
+ * tree items.
+ * TreeRoots provides a special implementation that allows the
+ * Tree class to treat trees with one root and with multiple
+ * roots equally.
+ */
+abstract class AbstractTreeItem extends SelectableItem {
+ private Vector children;
+ private boolean isExpanded = false;
+ // number of children.
+ // includes all expanded items down to the leafs.
+ private int visibleItemCount = 0;
+
+/**
+ * Create a new instance of the receiver.
+ * @param parent - widget the receiver belongs to
+ * @param swtStyle - widget style. see Widget class for details
+ */
+AbstractTreeItem(Tree parent, int swtStyle) {
+ super(parent, swtStyle);
+}
+/**
+ * Insert 'item' in the list of child items. Notify the
+ * parent about the new item.
+ * @param 'item' - the item that should be added to the
+ * receiver's children.
+ * @param index - position that 'item' will be inserted at
+ * in the receiver.
+ */
+void add(TreeItem item, int index) {
+ Vector items = getChildren();
+ int visibleIndex = getVisibleIndex();
+
+ if (index < 0 || index > items.size()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ if (item.isRoot()) {
+ visibleIndex = index;
+ }
+ else
+ if (isExpanded == false) {
+ visibleIndex = -1;
+ }
+ if (visibleIndex != -1) {
+ if (index > 0) {
+ TreeItem previousChild = (TreeItem) getChildren().elementAt(index - 1);
+ visibleIndex = previousChild.getVisibleIndex() + previousChild.getVisibleItemCount() + 1;
+ }
+ else {
+ visibleIndex = getVisibleIndex() + 1;
+ }
+ }
+ getSelectableParent().addingItem(item, visibleIndex);
+ item.setIndex(index);
+ resetChildIndices(index, true);
+ items.insertElementAt(item, index);
+ if (isExpanded == true) {
+ visibleItemCount++;
+ calculateVisibleItemCountParent();
+ }
+ getSelectableParent().addedItem(item, visibleIndex);
+}
+/**
+ * Set whether the receiver is expanded or not.
+ * If the receiver is expanded its child items are visible.
+ * @param expanded -
+ * true=the receiver is expanded, making its child items visible.
+ * false=the receiver is collapsed, making its child items invisible
+ */
+void internalSetExpanded(boolean expanded) {
+ isExpanded = expanded;
+ calculateVisibleItemCount();
+}
+/**
+ * Calculate the number of expanded children.
+ * Recurse up in the tree to the root item.
+ */
+abstract void calculateVisibleItemCount();
+/**
+ * Calculate the number of expanded children for the parent item
+ * of this item.
+ */
+abstract void calculateVisibleItemCountParent();
+/**
+ * Deselect the receiver and all children
+ */
+void deselectAll() {
+ Enumeration children = getChildren().elements();
+ AbstractTreeItem treeItem;
+
+ setSelected(false);
+ while (children.hasMoreElements() == true) {
+ treeItem = (AbstractTreeItem) children.nextElement();
+ treeItem.deselectAll();
+ }
+}
+public void dispose() {
+ if (isDisposed()) return;
+ Vector children = getChildren();
+ AbstractTreeItem child;
+ while (children.size() > 0) { // TreeItem objects are removed from vector during dispose
+ child = (AbstractTreeItem) children.firstElement();
+ child.dispose();
+ }
+ super.dispose();
+}
+void doDispose() {
+ setChildren(null);
+ visibleItemCount = 0;
+ super.doDispose();
+}
+/**
+ * Answer the Vector containing the child items of the receiver.
+ */
+Vector getChildren() {
+ if (children == null) {
+ children = new Vector(4);
+ }
+ return children;
+}
+/**
+ * Answer whether the receiver is expanded or not.
+ * If the receiver is expanded its children are visible.
+ * @return
+ * true - the receiver is expanded, making its children visible
+ * false - the receiver is collapsed, making its children invisible
+ */
+public boolean getExpanded() {
+ checkWidget();
+
+ return isExpanded;
+}
+/**
+ * Answer the number of children.
+ */
+public int getItemCount() {
+ checkWidget();
+
+ return getChildren().size();
+}
+/**
+ * Answer the index of the receiver relative to the first root
+ * item.
+ * If 'anIndex' is the global index of the expanded item 'anItem'
+ * then the following expressions are true:
+ * 'anItem == theRoot.getVisibleItem(anIndex)' and
+ * 'anIndex == anItem.getVisibleIndex()'
+ * @return
+ * The index of the receiver relative to the first root item.
+ * Answer -1 if the receiver is not visible (because the parent
+ * is collapsed).
+ */
+abstract int getVisibleIndex();
+/**
+ * Answer the index of the child item identified by 'childIndex'
+ * relative to the first root item.
+ */
+abstract int getVisibleIndex(int childIndex);
+/**
+ * Answer the item at 'searchIndex' relativ to the receiver.
+ * When this method is called for the root item, 'searchIndex'
+ * represents the global index into all items of the tree.
+ * searchIndex=0 returns the receiver.
+ * searchIndex=1 returns the first visible child.
+ * Note: searchIndex must be >= 0
+ *
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. Visible here means that all
+ * the parents of the item are expanded. An item is only
+ * visible on screen if it is within the receiver's parent's
+ * client area.
+ */
+abstract TreeItem getVisibleItem(int searchIndex);
+/**
+ * Answer the number of expanded children, direct and indirect.
+ */
+int getVisibleItemCount() {
+ return visibleItemCount;
+}
+/**
+ * Returns the expanded state. Circumvent widget/thread check
+ * for performance. For non-API callers only.
+ */
+boolean internalGetExpanded() {
+ return isExpanded;
+}
+/**
+ * Answer whether the receiver is a leaf item.
+ * An item is a leaf when it has no child items.
+ * @return
+ * true - receiver is a leaf item
+ * false - receiver is not a leaf item.
+ */
+boolean isLeaf() {
+ return (getChildren().size() == 0);
+}
+/**
+ * Answer whether the receiver is a root item.
+ * The receiver is a root item when it doesn't have a parent item.
+ * @return
+ * true - the receiver is a root item.
+ * false - the receiver is not a root item.
+ */
+boolean isRoot() {
+ return false;
+}
+/**
+ * Remove 'child' from the receiver.
+ * Notify the parent widget only if it is not being disposed itself.
+ */
+void removeItem(SelectableItem child) {
+ Vector children = getChildren();
+ SelectableItemWidget parent = getSelectableParent();
+ int childIndex = children.indexOf(child);
+
+ if (childIndex != -1) {
+ if (((Tree) parent).isRemovingAll() == true) {
+ children.removeElementAt(childIndex); // just remove the item from the list if the whole tree is being disposed
+ if (isExpanded == true) {
+ visibleItemCount--;
+ calculateVisibleItemCountParent();
+ }
+ }
+ else {
+ parent.removingItem(child);
+ children.removeElementAt(childIndex);
+ if (isExpanded == true) {
+ visibleItemCount--;
+ calculateVisibleItemCountParent();
+ }
+ resetChildIndices(childIndex, false); // mark child index dirty
+ parent.removedItem(child);
+ }
+ }
+}
+/**
+ * Allow subclasses to reset any cached data.
+ * Called for all children of the receiver.
+ */
+void reset() {
+ Enumeration children = getChildren().elements();
+ AbstractTreeItem treeItem;
+
+ while (children.hasMoreElements() == true) {
+ treeItem = (AbstractTreeItem) children.nextElement();
+ treeItem.reset();
+ }
+}
+/**
+ * Mark all child indices dirty starting with the child at
+ * 'startIndex'. This causes getIndex to recalculate the index.
+ * @param startIndex - index in the list of children at which
+ * and after which the indices are reset.
+ */
+void resetChildIndices(int startIndex, boolean addItem) {
+ Vector children = getChildren();
+ TreeItem child;
+ int increment = addItem ? 1 : 0;
+
+ for (int i = startIndex; i < children.size(); i++) {
+ child = (TreeItem) children.elementAt(i);
+ child.setIndex(i + increment); // mark child index dirty
+ }
+}
+/**
+ * Select the receiver and all children.
+ * Return a Vector containing all the items that have been selected
+ * (and that have not been selected before).
+ */
+Vector selectAll(Vector selectedItems) {
+ Enumeration children = getChildren().elements();
+ AbstractTreeItem treeItem;
+
+ if (isSelected() == false) {
+ selectedItems.addElement(this);
+ setSelected(true);
+ getSelectableParent().redrawSelection(this);
+ }
+ while (children.hasMoreElements() == true) {
+ treeItem = (AbstractTreeItem) children.nextElement();
+ selectedItems = treeItem.selectAll(selectedItems);
+ }
+ return selectedItems;
+}
+/**
+ * Set the Array containing the receiver's child items to 'children'.
+ */
+void setChildren(Vector children) {
+ this.children = children;
+}
+
+void setVisibleItemCount(int count) {
+ visibleItemCount = count;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/SelectableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/SelectableItem.java
index 36c88ff9c4..b47e21db05 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/SelectableItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/SelectableItem.java
@@ -1,318 +1,318 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * This class implements common behavior of TreeItem and TableItem.
- */
-abstract class SelectableItem extends Item {
- protected static final int CHECKBOX_PADDING = 1; // Space behind check box, before item image or text
-
- private SelectableItemWidget parent; // parent widget of the receiver
- private boolean isSelected = false; // item selection state
- private boolean isChecked = false; // item checked state. Can be one of checked and unchecked
- private boolean isGrayed = false; // item grayed state. The gray state is combined with the
- // checked state to create gray checked and gray unchecked.
-/**
- * Create a new instance of the receiver.
- * @param parent - widget the receiver is created in
- * @param style - widget style. see Widget class for details
- */
-SelectableItem(SelectableItemWidget parent, int style) {
- super(parent, style);
- setParent(parent);
-}
-public void dispose() {
- if (isDisposed()) return;
- super.dispose();
- doDispose();
-}
-void doDispose() {
- setParent(null);
-}
-/**
- * Draw the check box of the receiver at 'position' using 'gc'.
- * @param gc - GC to draw on.
- * @param destinationPosition - position on the GC to draw at.
- * @return Answer the position where drawing stopped.
- */
-Point drawCheckbox(GC gc, Point position) {
- SelectableItemWidget parent = getSelectableParent();
- Image image;
- Point imageExtent;
- Rectangle imageBounds;
- int imageOffset;
- int xInset;
- int yInset;
-
- if (getGrayed() == true) {
- image = parent.getGrayUncheckedImage();
- }
- else {
- image = parent.getUncheckedImage();
- }
- if (image != null) {
- imageExtent = parent.getCheckBoxExtent();
- imageOffset = (parent.getItemHeight() - imageExtent.y) / 2;
- gc.drawImage(image, position.x, position.y + imageOffset);
- if (getChecked() == true) {
- image = parent.getCheckMarkImage();
- imageBounds = image.getBounds();
- xInset = (imageExtent.x - imageBounds.width) / 2;
- yInset = (imageExtent.y - imageBounds.height) / 2;
- gc.drawImage(image, position.x + xInset, position.y + imageOffset + yInset);
- }
- position.x += imageExtent.x;
- }
- position.x += CHECKBOX_PADDING; // leave extra space behind check box
- return position;
-}
-void drawInsertMark(GC gc, Point position) {
- SelectableItemWidget parent = getSelectableParent();
- Point selectionExtent = getSelectionExtent();
- final int markerWidth = getInsertMarkWidth();
- int insertMarkYOffset = 0;
-
- if (selectionExtent == null) {
- return;
- }
- if (parent.isInsertAfter()) {
- insertMarkYOffset = selectionExtent.y - markerWidth;
- }
- gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_BLACK));
- gc.fillRectangle(position.x, position.y + insertMarkYOffset, selectionExtent.x, markerWidth);
- gc.setBackground(parent.getBackground());
-}
-/**
- * Answer the bounding rectangle of the item check box.
- * All points within this rectangle hit the check box.
- */
-Rectangle getCheckboxBounds() {
- SelectableItemWidget parent = getSelectableParent();
- Point checkBoxExtent;
- int redrawPosition;
- Rectangle checkboxBounds = new Rectangle(0, 0, 0, 0);
-
- if (isCheckable() == true) {
- checkboxBounds.x = getCheckboxXPosition();
- redrawPosition = parent.getRedrawY(this);
- if (redrawPosition != -1) {
- checkboxBounds.y = redrawPosition;
- }
- checkBoxExtent = parent.getCheckBoxExtent();
- checkboxBounds.width = checkBoxExtent.x;
- checkboxBounds.height = checkBoxExtent.y;
- checkboxBounds.y += (parent.getItemHeight() - checkBoxExtent.y) / 2;
- }
- return checkboxBounds;
-}
-/**
- * Answer the x position of the item check box
- */
-abstract int getCheckboxXPosition();
-/**
- * Return whether or not the receiver is checked.
- * Always return false if the parent of the receiver does not
- * have the CHECK style.
- */
-public boolean getChecked() {
- checkWidget();
- boolean checked = false;
-
- if (isCheckable() == true) {
- checked = isChecked;
- }
- return checked;
-}
-/**
- * Answer the display of the receiver's parent widget.
- */
-public Display getDisplay() {
- SelectableItemWidget parent = getSelectableParent();
-
- if (parent == null) {
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- return parent.getDisplay();
-}
-
-/**
- * Gets the grayed state.
- * <p>
- * @return the item grayed state.
- *
- * @exception SWTError <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
- * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
- * </ul>
- */
-public boolean getGrayed () {
- checkWidget();
- boolean grayed = false;
-
- if (isCheckable() == true) {
- grayed = isGrayed;
- }
- return grayed;
-}
-/**
- * Return the width in pixels of the line drawn to indicate the
- * drop insert position during a drag and drop operation.
- */
-int getInsertMarkWidth() {
- return 2;
-}
-/**
- * Answer the parent widget of the receiver.
- */
-SelectableItemWidget getSelectableParent() {
- return parent;
-}
-/**
- * Answer the background color to use for drawing the
- * selection rectangle.
- */
-Color getSelectionBackgroundColor() {
- Display display = getSelectableParent().getDisplay();
-
- return display.getSystemColor(SWT.COLOR_LIST_SELECTION);
-}
-/**
- * Return the size of the rectangle drawn to indicate the
- * selected state of the receiver.
- */
-abstract Point getSelectionExtent();
-/**
- * Answer the foreground color to use for drawing the
- * selection rectangle.
- */
-Color getSelectionForegroundColor() {
- Display display = getSelectableParent().getDisplay();
-
- return display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
-}
-/**
- * Return the x position of the selection rectangle
- */
-abstract int getSelectionX();
-/**
- * Answer whether 'posiiton' is inside the item check box.
- * @return
- * true - item check box hit
- * false - item check box not hit
- */
-boolean isCheckHit(Point position) {
- boolean isCheckHit = false;
-
- if (isCheckable() == true) {
- isCheckHit = getCheckboxBounds().contains(position);
- }
- return isCheckHit;
-}
-/**
- * Return whether or not the receiver has a check box and can
- * be checked.
- */
-boolean isCheckable() {
- return (getSelectableParent().getStyle() & SWT.CHECK) != 0;
-}
-/**
- * Answer whether the receiver is selected.
- * @return
- * true - the receiver is selected
- * false - the receiver is not selected
- */
-boolean isSelected() {
- return isSelected;
-}
-/**
- * Redraw the insert mark
- * @param yPosition - y position in the receiver's client area
- * where the item should be drawn.
- */
-void redrawInsertMark(int yPosition) {
- SelectableItemWidget parent = getSelectableParent();
- Point selectionExtent = getSelectionExtent();
- int redrawHeight = getInsertMarkWidth();
-
- if (selectionExtent != null) {
- parent.redraw(getSelectionX(), yPosition, selectionExtent.x, redrawHeight, false);
- parent.redraw(getSelectionX(), yPosition + selectionExtent.y - redrawHeight, selectionExtent.x, redrawHeight, false);
- }
-}
-/**
- * Redraw the selection
- * @param yPosition - y position in the receiver's client area
- * where the item should be drawn.
- */
-void redrawSelection(int yPosition) {
- SelectableItemWidget parent = getSelectableParent();
- Point selectionExtent = getSelectionExtent();
-
- if (selectionExtent != null) {
- parent.redraw(getSelectionX(), yPosition, selectionExtent.x, selectionExtent.y, false);
- }
-}
-/**
- * Set the checked state to 'checked' if the parent of the
- * receiver has the CHECK style.
- */
-public void setChecked(boolean checked) {
- checkWidget();
- SelectableItemWidget parent = getSelectableParent();
- Rectangle redrawRectangle = getCheckboxBounds();
-
- if (isCheckable() == true && isChecked != checked) {
- isChecked = checked;
- parent.redraw(
- redrawRectangle.x, redrawRectangle.y,
- redrawRectangle.width, redrawRectangle.height, false);
- }
-}
-
-/**
- * Sets the grayed state.
- * <p>
- * @param grayed the new grayed state.
- *
- * @exception SWTError <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
- * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget();
- SelectableItemWidget parent = getSelectableParent();
- Rectangle redrawRectangle = getCheckboxBounds();
-
- if (isCheckable() == true && isGrayed != grayed) {
- isGrayed = grayed;
- parent.redraw(
- redrawRectangle.x, redrawRectangle.y,
- redrawRectangle.width, redrawRectangle.height, false);
- }
-}
-
-/**
- * Set the receiver's parent widget to 'parent'.
- */
-void setParent(SelectableItemWidget parent) {
- this.parent = parent;
-}
-/**
- * Set whether the receiver is selected.
- * @param selected - true=the receiver is selected
- * false=the receiver is not selected
- */
-void setSelected(boolean selected) {
- isSelected = selected;
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+/**
+ * This class implements common behavior of TreeItem and TableItem.
+ */
+abstract class SelectableItem extends Item {
+ protected static final int CHECKBOX_PADDING = 1; // Space behind check box, before item image or text
+
+ private SelectableItemWidget parent; // parent widget of the receiver
+ private boolean isSelected = false; // item selection state
+ private boolean isChecked = false; // item checked state. Can be one of checked and unchecked
+ private boolean isGrayed = false; // item grayed state. The gray state is combined with the
+ // checked state to create gray checked and gray unchecked.
+/**
+ * Create a new instance of the receiver.
+ * @param parent - widget the receiver is created in
+ * @param style - widget style. see Widget class for details
+ */
+SelectableItem(SelectableItemWidget parent, int style) {
+ super(parent, style);
+ setParent(parent);
+}
+public void dispose() {
+ if (isDisposed()) return;
+ super.dispose();
+ doDispose();
+}
+void doDispose() {
+ setParent(null);
+}
+/**
+ * Draw the check box of the receiver at 'position' using 'gc'.
+ * @param gc - GC to draw on.
+ * @param destinationPosition - position on the GC to draw at.
+ * @return Answer the position where drawing stopped.
+ */
+Point drawCheckbox(GC gc, Point position) {
+ SelectableItemWidget parent = getSelectableParent();
+ Image image;
+ Point imageExtent;
+ Rectangle imageBounds;
+ int imageOffset;
+ int xInset;
+ int yInset;
+
+ if (getGrayed() == true) {
+ image = parent.getGrayUncheckedImage();
+ }
+ else {
+ image = parent.getUncheckedImage();
+ }
+ if (image != null) {
+ imageExtent = parent.getCheckBoxExtent();
+ imageOffset = (parent.getItemHeight() - imageExtent.y) / 2;
+ gc.drawImage(image, position.x, position.y + imageOffset);
+ if (getChecked() == true) {
+ image = parent.getCheckMarkImage();
+ imageBounds = image.getBounds();
+ xInset = (imageExtent.x - imageBounds.width) / 2;
+ yInset = (imageExtent.y - imageBounds.height) / 2;
+ gc.drawImage(image, position.x + xInset, position.y + imageOffset + yInset);
+ }
+ position.x += imageExtent.x;
+ }
+ position.x += CHECKBOX_PADDING; // leave extra space behind check box
+ return position;
+}
+void drawInsertMark(GC gc, Point position) {
+ SelectableItemWidget parent = getSelectableParent();
+ Point selectionExtent = getSelectionExtent();
+ final int markerWidth = getInsertMarkWidth();
+ int insertMarkYOffset = 0;
+
+ if (selectionExtent == null) {
+ return;
+ }
+ if (parent.isInsertAfter()) {
+ insertMarkYOffset = selectionExtent.y - markerWidth;
+ }
+ gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_BLACK));
+ gc.fillRectangle(position.x, position.y + insertMarkYOffset, selectionExtent.x, markerWidth);
+ gc.setBackground(parent.getBackground());
+}
+/**
+ * Answer the bounding rectangle of the item check box.
+ * All points within this rectangle hit the check box.
+ */
+Rectangle getCheckboxBounds() {
+ SelectableItemWidget parent = getSelectableParent();
+ Point checkBoxExtent;
+ int redrawPosition;
+ Rectangle checkboxBounds = new Rectangle(0, 0, 0, 0);
+
+ if (isCheckable() == true) {
+ checkboxBounds.x = getCheckboxXPosition();
+ redrawPosition = parent.getRedrawY(this);
+ if (redrawPosition != -1) {
+ checkboxBounds.y = redrawPosition;
+ }
+ checkBoxExtent = parent.getCheckBoxExtent();
+ checkboxBounds.width = checkBoxExtent.x;
+ checkboxBounds.height = checkBoxExtent.y;
+ checkboxBounds.y += (parent.getItemHeight() - checkBoxExtent.y) / 2;
+ }
+ return checkboxBounds;
+}
+/**
+ * Answer the x position of the item check box
+ */
+abstract int getCheckboxXPosition();
+/**
+ * Return whether or not the receiver is checked.
+ * Always return false if the parent of the receiver does not
+ * have the CHECK style.
+ */
+public boolean getChecked() {
+ checkWidget();
+ boolean checked = false;
+
+ if (isCheckable() == true) {
+ checked = isChecked;
+ }
+ return checked;
+}
+/**
+ * Answer the display of the receiver's parent widget.
+ */
+public Display getDisplay() {
+ SelectableItemWidget parent = getSelectableParent();
+
+ if (parent == null) {
+ error(SWT.ERROR_WIDGET_DISPOSED);
+ }
+ return parent.getDisplay();
+}
+
+/**
+ * Gets the grayed state.
+ * <p>
+ * @return the item grayed state.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
+ */
+public boolean getGrayed () {
+ checkWidget();
+ boolean grayed = false;
+
+ if (isCheckable() == true) {
+ grayed = isGrayed;
+ }
+ return grayed;
+}
+/**
+ * Return the width in pixels of the line drawn to indicate the
+ * drop insert position during a drag and drop operation.
+ */
+int getInsertMarkWidth() {
+ return 2;
+}
+/**
+ * Answer the parent widget of the receiver.
+ */
+SelectableItemWidget getSelectableParent() {
+ return parent;
+}
+/**
+ * Answer the background color to use for drawing the
+ * selection rectangle.
+ */
+Color getSelectionBackgroundColor() {
+ Display display = getSelectableParent().getDisplay();
+
+ return display.getSystemColor(SWT.COLOR_LIST_SELECTION);
+}
+/**
+ * Return the size of the rectangle drawn to indicate the
+ * selected state of the receiver.
+ */
+abstract Point getSelectionExtent();
+/**
+ * Answer the foreground color to use for drawing the
+ * selection rectangle.
+ */
+Color getSelectionForegroundColor() {
+ Display display = getSelectableParent().getDisplay();
+
+ return display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
+}
+/**
+ * Return the x position of the selection rectangle
+ */
+abstract int getSelectionX();
+/**
+ * Answer whether 'posiiton' is inside the item check box.
+ * @return
+ * true - item check box hit
+ * false - item check box not hit
+ */
+boolean isCheckHit(Point position) {
+ boolean isCheckHit = false;
+
+ if (isCheckable() == true) {
+ isCheckHit = getCheckboxBounds().contains(position);
+ }
+ return isCheckHit;
+}
+/**
+ * Return whether or not the receiver has a check box and can
+ * be checked.
+ */
+boolean isCheckable() {
+ return (getSelectableParent().getStyle() & SWT.CHECK) != 0;
+}
+/**
+ * Answer whether the receiver is selected.
+ * @return
+ * true - the receiver is selected
+ * false - the receiver is not selected
+ */
+boolean isSelected() {
+ return isSelected;
+}
+/**
+ * Redraw the insert mark
+ * @param yPosition - y position in the receiver's client area
+ * where the item should be drawn.
+ */
+void redrawInsertMark(int yPosition) {
+ SelectableItemWidget parent = getSelectableParent();
+ Point selectionExtent = getSelectionExtent();
+ int redrawHeight = getInsertMarkWidth();
+
+ if (selectionExtent != null) {
+ parent.redraw(getSelectionX(), yPosition, selectionExtent.x, redrawHeight, false);
+ parent.redraw(getSelectionX(), yPosition + selectionExtent.y - redrawHeight, selectionExtent.x, redrawHeight, false);
+ }
+}
+/**
+ * Redraw the selection
+ * @param yPosition - y position in the receiver's client area
+ * where the item should be drawn.
+ */
+void redrawSelection(int yPosition) {
+ SelectableItemWidget parent = getSelectableParent();
+ Point selectionExtent = getSelectionExtent();
+
+ if (selectionExtent != null) {
+ parent.redraw(getSelectionX(), yPosition, selectionExtent.x, selectionExtent.y, false);
+ }
+}
+/**
+ * Set the checked state to 'checked' if the parent of the
+ * receiver has the CHECK style.
+ */
+public void setChecked(boolean checked) {
+ checkWidget();
+ SelectableItemWidget parent = getSelectableParent();
+ Rectangle redrawRectangle = getCheckboxBounds();
+
+ if (isCheckable() == true && isChecked != checked) {
+ isChecked = checked;
+ parent.redraw(
+ redrawRectangle.x, redrawRectangle.y,
+ redrawRectangle.width, redrawRectangle.height, false);
+ }
+}
+
+/**
+ * Sets the grayed state.
+ * <p>
+ * @param grayed the new grayed state.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
+ */
+public void setGrayed (boolean grayed) {
+ checkWidget();
+ SelectableItemWidget parent = getSelectableParent();
+ Rectangle redrawRectangle = getCheckboxBounds();
+
+ if (isCheckable() == true && isGrayed != grayed) {
+ isGrayed = grayed;
+ parent.redraw(
+ redrawRectangle.x, redrawRectangle.y,
+ redrawRectangle.width, redrawRectangle.height, false);
+ }
+}
+
+/**
+ * Set the receiver's parent widget to 'parent'.
+ */
+void setParent(SelectableItemWidget parent) {
+ this.parent = parent;
+}
+/**
+ * Set whether the receiver is selected.
+ * @param selected - true=the receiver is selected
+ * false=the receiver is not selected
+ */
+void setSelected(boolean selected) {
+ isSelected = selected;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/SelectableItemWidget.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/SelectableItemWidget.java
index d433e1e281..5e15179df7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/SelectableItemWidget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/SelectableItemWidget.java
@@ -1,2066 +1,2066 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.Compatibility;
-
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * This class is intended for widgets that display data of
- * type Item. It provides a framework for scrolling and
- * handles the screen refresh required when adding and
- * removing items.
- */
-abstract class SelectableItemWidget extends Composite {
- private static final int DEFAULT_WIDTH = 64; // used in computeSize if width could not be calculated
- private static final int DEFAULT_HEIGHT = 64; // used in computeSize if height could not be calculated
- private static final int HORIZONTAL_SCROLL_INCREMENT = 5; // number of pixel the tree is moved
- // during horizontal line scrolling
- private static ImageData UncheckedImageData; // deselected check box image data. used to create an image at run time
- private static ImageData GrayUncheckedImageData; // grayed deselected check box image data. used to create an image at run time
- private static ImageData CheckMarkImageData; // check mark image data for check box. used to create an image at run time
- static {
- initializeImageData();
- }
-
- private int topIndex = 0; // index of the first visible item
- private int itemHeight = 0; // height of a table item
- private Point itemImageExtent = null; // size of the item images. Null unless an image is set for any item
- private int textHeight = -1;
- private int contentWidth = 0; // width of the widget data (ie. table rows/tree items)
- private int horizontalOffset = 0;
- private Vector selectedItems; // indices of the selected items
- private SelectableItem lastSelectedItem; // item that was selected last
- private SelectableItem lastFocusItem; // item that had the focus last. Always equals lastSelectedItem
- // for mouse selection but may differ for keyboard selection
- private SelectableItem insertItem; // item that draws the insert marker to indicate the drop location in a drag and drop operation
- private boolean isInsertAfter; // indicates where the insert marker is rendered, at the top or bottom of 'insertItem'
- private boolean isCtrlSelection = false; // the most recently selected item was
- // selected using the Ctrl modifier key
- private boolean isRemovingAll = false; // true=all items are removed. Used to optimize screen updates and to control item selection on dispose.
- private boolean hasFocus; // workaround for 1FMITIE
- private Image uncheckedImage; // deselected check box
- private Image grayUncheckedImage; // grayed check box
- private Image checkMarkImage; // check mark for selected check box
- private Point checkBoxExtent = null; // width, height of the item check box
- private Listener listener; // event listener used for all events. Events are dispatched
- // to handler methods in handleEvents(Event)
- private int drawCount = 0; // used to reimplement setRedraw(boolean)
-/**
- * Create a new instance of ScrollableItemWidget.
- * @param parent - the parent window of the new instance
- * @param style - window style for the new instance
- */
-SelectableItemWidget(Composite parent, int style) {
- super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_REDRAW_RESIZE);
- initialize();
-}
-/**
- * The SelectableItem 'item' has been added to the tree.
- * Calculate the vertical scroll bar.
- * Update the screen to display the new item.
- * @param item - item that has been added to the receiver.
- */
-void addedItem(SelectableItem item, int index) {
- calculateVerticalScrollbar();
- if (getLastFocus() == null) { // if no item has the focus
- setLastFocus(item, true); // set focus to new (must be first) item
- }
-}
-/**
- * The SelectableItem 'item' is about to be added to the tree.
- * @param item - item that is about to be added to the receiver.
- */
-void addingItem(SelectableItem item, int index) {
- if (index >= 0 && index <= getBottomIndex()) {
- scrollVerticalAddingItem(index);
- }
-}
-/**
- * Set the scroll range of the horizontal scroll bar.
- * Resize the scroll bar if the scroll range maximum
- * has changed.
- */
-void calculateHorizontalScrollbar() {
- int newMaximum = getContentWidth();
- ScrollBar horizontalBar = getHorizontalBar();
-
- if (horizontalBar.getMaximum() != newMaximum) {
- // The call to setMaximum is ignored if newMaximum is 0.
- // Therefore we can not rely on getMaximum to subsequently return the number of
- // items in the receiver. We always have to use getVisibleItemCount().
- // Never rely on getMaximum to return what you set. It may not accept the
- // value you set. Even if you use a valid value now the implementation may change
- // later. That's what caused 1FRLOSG.
- horizontalBar.setMaximum(newMaximum);
- if (getVerticalBar().getVisible() == false) { // remove these lines
- horizontalBar.setMaximum(newMaximum); // when PR 1FIG5CG
- } // is fixed
- resizeHorizontalScrollbar();
- }
-}
-/**
- * Calculate the height of items in the receiver.
- * Only the image height is calculated if an item height
- * has already been calculated. Do nothing if both the item
- * height and the image height have already been calculated
- */
-void calculateItemHeight(SelectableItem item) {
- GC gc;
- String itemText;
- int itemHeight = -1;
-
- if (itemImageExtent != null && textHeight != -1) {
- return;
- }
- itemText = item.getText();
- if (itemText != null && textHeight == -1) {
- gc = new GC(this);
- itemHeight = gc.stringExtent(itemText).y;
- textHeight = itemHeight;
- gc.dispose();
- }
- if (itemImageExtent == null) {
- itemImageExtent = getImageExtent(item);
- if (itemImageExtent != null) {
- if (itemImageExtent.y > textHeight) {
- itemHeight = itemImageExtent.y;
- }
- else {
- itemHeight = textHeight;
- }
- }
- }
- itemHeight += getItemPadding(); // make sure that there is empty space below the image/text
- if (itemHeight > getItemHeight()) { // only set new item height if it's higher because new,
- setItemHeight(itemHeight); // smaller item height may not include an icon
- }
-}
-/**
- * Calculate the range of items that need to be selected given
- * the clicked item identified by 'hitItemIndex'
- * @param hitItemIndex - item that was clicked and that the new
- * selection range will be based on. This index is relative to
- * the top index.
- */
-int [] calculateShiftSelectionRange(int hitItemIndex) {
- int selectionRange[] = new int[] {-1, -1};
- SelectableItem closestItem = null;
- SelectableItem selectedItem;
- Enumeration selectedItems = getSelectionVector().elements();
-
- while (selectedItems.hasMoreElements() == true) {
- selectedItem = (SelectableItem) selectedItems.nextElement();
- if (closestItem == null) {
- closestItem = selectedItem;
- }
- else
- if (Math.abs(hitItemIndex - getVisibleIndex(selectedItem)) <
- Math.abs(hitItemIndex - getVisibleIndex(closestItem))) {
- closestItem = selectedItem;
- }
- }
- if (closestItem == null) { // no item selected
- closestItem = getLastSelection(); // item selected last may still have the focus
- }
- if (closestItem != null) {
- selectionRange[0] = getVisibleIndex(closestItem);
- selectionRange[1] = hitItemIndex;
- }
- return selectionRange;
-}
-/**
- * Set the scroll range of the vertical scroll bar.
- * Resize the scroll bar if the scroll range maximum
- * has changed.
- */
-void calculateVerticalScrollbar() {
- int newMaximum = getVisibleItemCount();
- ScrollBar verticalBar = getVerticalBar();
-
- // The call to setMaximum is ignored if newMaximum is 0.
- // Therefore we can not rely on getMaximum to subsequently return the number of
- // items in the receiver. We always have to use getVisibleItemCount().
- // Never rely on getMaximum to return what you set. It may not accept the
- // value you set. Even if you use a valid value now the implementation may change
- // later. That's what caused 1FRLOSG.
- verticalBar.setMaximum(newMaximum);
- if (getHorizontalBar().getVisible() == false) { // remove these lines
- verticalBar.setMaximum(newMaximum); // when PR 1FIG5CG
- } // is fixed
- resizeVerticalScrollbar();
-}
-
-/**
- * Answer the size of the receiver needed to display all items.
- * The length of the longest item in the receiver is used for the
- * width.
- */
-public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = getContentWidth();
- int height = getItemCount() * getItemHeight();
- int scrollBarWidth = computeTrim(0, 0, 0, 0).width;
-
- 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 ((getStyle() & SWT.V_SCROLL) != 0) {
- width += scrollBarWidth;
- }
- if ((getStyle() & SWT.H_SCROLL) != 0) {
- height += scrollBarWidth;
- }
- return new Point(width, height);
-}
-/**
- * Do a ctrl+shift selection meaning the ctrl and shift keys
- * were pressed when the mouse click on an item occurred.
- * If an already selected item was clicked the focus is moved to
- * that item.
- * If the previous selection was a ctrl or ctrl+shift selection
- * the range between the last selected item and the clicked item
- * is selected.
- * Otherwise a regular shift selection is performed.
- * @param hitItem - specifies the clicked item
- * @param hitItemIndex - specifies the index of the clicked item
- * relative to the first item.
- */
-void ctrlShiftSelect(SelectableItem hitItem, int hitItemIndex) {
- int fromIndex = -1;
- int toIndex = -1;
- int lastSelectionIndex = -1;
- int selectionRange[];
- SelectableItem lastSelection = getLastSelection();
-
- if (lastSelection != null) {
- lastSelectionIndex = getVisibleIndex(lastSelection);
- }
- if ((getSelectionVector().contains(hitItem) == true) && // clicked an already selected item?
- (hitItemIndex != lastSelectionIndex)) { // and click was not on last selected item?
- setLastSelection(hitItem, true); // set last selection which also sets the focus
- }
- else
- if (isCtrlSelection() == true) { // was last selection ctrl/ctrl+shift selection?
- fromIndex = lastSelectionIndex; // select from last selection
- toIndex = hitItemIndex;
- }
- else { // clicked outside existing selection range
- selectionRange = calculateShiftSelectionRange(hitItemIndex);
- fromIndex = selectionRange[0];
- toIndex = selectionRange[1];
- }
- if (fromIndex != -1 && toIndex != -1) {
- selectRange(fromIndex, toIndex);
- }
-}
-/**
- * Deselect 'item'.
- * @param item - item that should be deselected
- */
-void deselect(SelectableItem item) {
- Vector selectedItems = getSelectionVector();
-
- if ((item != null) && (item.isSelected() == true)) {
- item.setSelected(false);
- redrawSelection(item);
- selectedItems.removeElement(item);
- }
-}
-/**
- * Deselect all item except 'keepSelected'.
- * @param keepSelected - item that should remain selected
- */
-void deselectAllExcept(SelectableItem keepSelected) {
- Vector selectedItems = getSelectionVector();
- Vector deselectedItems = new Vector(selectedItems.size());
- Enumeration elements = selectedItems.elements();
- SelectableItem item;
-
- // deselect and repaint previously selected items
- while (elements.hasMoreElements() == true) {
- item = (SelectableItem) elements.nextElement();
- if (item.isSelected() == true && item != keepSelected) {
- item.setSelected(false);
- // always redraw the selection, even if item is redrawn again
- // in setLastSelection. Fixes 1G0GQ8W
- redrawSelection(item);
- deselectedItems.addElement(item);
- }
- }
- elements = deselectedItems.elements();
- while (elements.hasMoreElements() == true) {
- item = (SelectableItem) elements.nextElement();
- selectedItems.removeElement(item);
- }
- setLastSelection(keepSelected, false);
-}
-/**
- * Deselect all items except those in 'keepSelected'.
- * @param keepSelected - items that should remain selected
- */
-void deselectAllExcept(Vector keepSelected) {
- Vector selectedItems = getSelectionVector();
- Vector deselectedItems = new Vector(selectedItems.size());
- Enumeration elements = selectedItems.elements();
- SelectableItem item;
-
- // deselect and repaint previously selected items
- while (elements.hasMoreElements() == true) {
- item = (SelectableItem) elements.nextElement();
- if (item.isSelected() == true && keepSelected.contains(item) == false) {
- item.setSelected(false);
- // always redraw the selection, even if item is redrawn again
- // in setLastSelection. Fixes 1G0GQ8W
- redrawSelection(item);
- deselectedItems.addElement(item);
- }
- }
- elements = deselectedItems.elements();
- while (elements.hasMoreElements() == true) {
- item = (SelectableItem) elements.nextElement();
- selectedItems.removeElement(item);
- }
- if (keepSelected.size() > 0) {
- setLastSelection((SelectableItem) keepSelected.firstElement(), false);
- }
-}
-/**
- * Deselect 'item'. Notify listeners.
- * @param item - item that should be deselected
- */
-void deselectNotify(SelectableItem item) {
- Event event = new Event();
-
- if (item.isSelected() == true) {
- deselect(item);
- setLastSelection(item, true);
- update(); // looks better when event notification takes long to return
- }
- event.item = item;
- notifyListeners(SWT.Selection, event);
-}
-/**
- * Deselect all items starting at and including 'fromIndex'
- * stopping at and including 'toIndex'.
- * @param fromIndex - index relative to the first item where
- * deselection should start. Deselecion includes 'fromIndex'.
- * @param toIndex - index relative to the first item where
- * deselection should stop. Deselecion includes 'toIndex'.
- */
-void deselectRange(int fromIndex, int toIndex) {
- if (fromIndex > toIndex) {
- for (int i = toIndex; i <= fromIndex; i++) {
- deselect(getVisibleItem(i));
- }
- }
- else
- if (fromIndex < toIndex) {
- for (int i = toIndex; i >= fromIndex; i--) {
- deselect(getVisibleItem(i));
- }
- }
- setLastSelection(getVisibleItem(fromIndex), true);
-}
-/**
- * Modifier Key Action
- * None Remove old selection, move selection down one item
- * Ctrl Keep old selection, move input focus down one item
- * Shift Extend selection by one item.
- * Modifier Key is ignored when receiver has single selection style.
- * @param keyMask - the modifier key that was pressed
- */
-void doArrowDown(int keyMask) {
- SelectableItem lastFocus = getLastFocus();
- SelectableItem newFocus;
- int focusItemIndex = getVisibleIndex(lastFocus);
-
- if (focusItemIndex < (getVisibleItemCount() - 1)) { // - 1 because indices are 0 based
- focusItemIndex++;
- newFocus = getVisibleItem(focusItemIndex);
- if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
- setLastFocus(newFocus, true);
- }
- else
- if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
- shiftSelect(newFocus, focusItemIndex);
- }
- else {
- deselectAllExcept(newFocus);
- selectNotify(newFocus);
- }
- }
-}
-/**
- * Modifier Key Action
- * None Scroll receiver to the left
- * Ctrl See None above
- * Shift See None above
- * @param keyMask - the modifier key that was pressed
- */
-void doArrowLeft(int keyMask) {
- ScrollBar horizontalBar = getHorizontalBar();
- int scrollSelection = horizontalBar.getSelection();
- int scrollAmount;
-
- if (horizontalBar.getVisible() == false) {
- return;
- }
- scrollAmount = Math.min(HORIZONTAL_SCROLL_INCREMENT, scrollSelection);
- horizontalBar.setSelection(scrollSelection - scrollAmount);
- setHorizontalOffset(horizontalBar.getSelection() * -1);
-}
-/**
- * Modifier Key Action
- * None Scroll receiver to the right
- * Ctrl See None above
- * Shift See None above
- * @param keyMask - the modifier key that was pressed
- */
-void doArrowRight(int keyMask) {
- ScrollBar horizontalBar = getHorizontalBar();
- int scrollSelection = horizontalBar.getSelection();
- int scrollAmount;
-
- if (horizontalBar.getVisible() == false) {
- return;
- }
- scrollAmount = Math.min( // scroll by the smaller of
- HORIZONTAL_SCROLL_INCREMENT, // the scroll increment
- horizontalBar.getMaximum() // and the remaining scroll range
- - horizontalBar.getPageIncrement()
- - scrollSelection);
- horizontalBar.setSelection(scrollSelection + scrollAmount);
- setHorizontalOffset(horizontalBar.getSelection() * -1);
-}
-/**
- * Modifier Key Action
- * None Remove old selection, move selection up one item
- * Ctrl Keep old selection, move input focus up one item
- * Shift Extend selection by one item.
- * Modifier Key is ignored when receiver has single selection style.
- * @param keyMask - the modifier key that was pressed
- */
-void doArrowUp(int keyMask) {
- SelectableItem lastFocus = getLastFocus();
- SelectableItem newFocus;
- int focusItemIndex = getVisibleIndex(lastFocus);
-
- if (focusItemIndex > 0) {
- focusItemIndex--;
- newFocus = getVisibleItem(focusItemIndex);
- if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
- setLastFocus(newFocus, true);
- }
- else
- if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
- shiftSelect(newFocus, focusItemIndex);
- }
- else {
- deselectAllExcept(newFocus);
- selectNotify(newFocus);
- }
- }
-}
-/**
- * Perform a selection operation on the item check box.
- * @param item - the item that was clicked
- */
-void doCheckItem(SelectableItem item) {
- Event event = new Event();
-
- item.setChecked(!item.getChecked());
- event.item = item;
- event.detail = SWT.CHECK;
- notifyListeners(SWT.Selection, event);
-}
-/**
- * Free resources.
- */
-void doDispose() {
- setRemovingAll(true);
- getSelectionVector().removeAllElements();
- lastFocusItem = null;
- lastSelectedItem = null;
- if (uncheckedImage != null) {
- uncheckedImage.dispose();
- }
- if (grayUncheckedImage != null) {
- grayUncheckedImage.dispose();
- }
- if (checkMarkImage != null) {
- checkMarkImage.dispose();
- }
-}
-/**
- * Modifier Key Action
- * None Remove old selection, move selection to the
- * last item
- * Ctrl Keep old selection, move input focus to the
- * last item
- * Shift Extend selection to the last item.
- * Modifier Key is ignored when receiver has single selection style.
- * @param keyMask - the modifier key that was pressed
- */
-void doEnd(int keyMask) {
- SelectableItem lastFocus = getLastFocus();
- SelectableItem newFocus;
- int focusItemIndex = getVisibleIndex(lastFocus);
- int lastItemIndex = getVisibleItemCount() - 1; // - 1 because indices are 0 based
-
- if (focusItemIndex < lastItemIndex) {
- newFocus = getVisibleItem(lastItemIndex);
- if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
- setLastFocus(newFocus, true);
- }
- else
- if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
- shiftSelect(newFocus, lastItemIndex);
- }
- else {
- deselectAllExcept(newFocus);
- selectNotify(newFocus);
- }
- }
-}
-/**
- * Modifier Key Action
- * None Remove old selection, move selection to the
- * first item
- * Ctrl Keep old selection, move input focus to the
- * first item
- * Shift Extend selection to the first item.
- * Modifier Key is ignored when receiver has single selection style.
- * @param keyMask - the modifier key that was pressed
- */
-void doHome(int keyMask) {
- SelectableItem lastFocus = getLastFocus();
- SelectableItem newFocus;
- int firstItemIndex = 0;
-
- if (getVisibleIndex(lastFocus) > firstItemIndex) {
- newFocus = getVisibleItem(firstItemIndex);
- if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
- setLastFocus(newFocus, true);
- }
- else
- if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
- shiftSelect(newFocus, firstItemIndex);
- }
- else {
- deselectAllExcept(newFocus);
- selectNotify(newFocus);
- }
- }
-}
-/**
- * Perform a mouse select action according to the key state
- * mask in 'eventStateMask'.
- * Key state mask is ignored when receiver has the single selection
- * style.
- * @param item - the item that was clicked
- * @param itemIndex - the index of the clicked item relative
- * to the first item of the receiver
- * @param eventStateMask - the key state mask of the mouse event
- * @param button - the mouse button that was pressed
- */
-void doMouseSelect(SelectableItem item, int itemIndex, int eventStateMask, int button) {
- if (button != 1 && item.isSelected() == true) {
- // If the item is already selected, do not change the selection when using
- // button 2 or 3. These buttons may invoke drag and drop or open the
- // context menu for the current selection.
- return;
- }
- if (((eventStateMask & SWT.MOD1) != 0) &&
- ((eventStateMask & SWT.MOD2) != 0) &&
- (isMultiSelect() == true)) {
- if (getSelectionVector().size() == 0) { // no old selection?
- selectNotify(item); // do standard CTRL selection
- }
- else {
- ctrlShiftSelect(item, itemIndex);
- }
- setCtrlSelection(true);
- }
- else
- if (((eventStateMask & SWT.MOD2) != 0) && (isMultiSelect() == true)) {
- shiftSelect(item, itemIndex);
- setCtrlSelection(false);
- }
- else
- if (((eventStateMask & SWT.MOD1) != 0) && (isMultiSelect() == true)) {
- toggleSelectionNotify(item);
- setCtrlSelection(true);
- }
- else
- if ((eventStateMask & (SWT.MOD3 | SWT.MOD4)) == 0) {
- // On MacOSX, holding the control key down while pressing button 1 brings up the context menu.
- // Do not change the selection in this case.
- deselectAllExcept(item);
- selectNotify(item);
- setCtrlSelection(false);
- }
-}
-/**
- * Modifier Key Action
- * None Remove old selection, move selection one page down
- * Ctrl Keep old selection, move input focus one page down
- * Shift Extend selection one page down
- * One page is the number of items that can be displayed in the
- * receiver's canvas without truncating the last item.
- * The selection is set to the last item if there is no full page
- * of items left.
- * Modifier Key is ignored when receiver has single selection style.
- * @param keyMask - the modifier key that was pressed
- */
-void doPageDown(int keyMask) {
- SelectableItem newFocus;
- int focusItemIndex = getVisibleIndex(getLastFocus());
- int lastItemIndex = getVisibleItemCount() - 1; // - 1 because indices are 0 based
- int visibleItemCount;
-
- if (focusItemIndex < lastItemIndex) {
- visibleItemCount = getItemCountWhole();
- focusItemIndex = Math.min(
- lastItemIndex,
- focusItemIndex + (visibleItemCount - 1));
- newFocus = getVisibleItem(focusItemIndex);
- if (newFocus == null) {
- return;
- }
- if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
- setLastFocus(newFocus, true);
- }
- else
- if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
- shiftSelect(newFocus, focusItemIndex);
- }
- else {
- deselectAllExcept(newFocus);
- selectNotify(newFocus);
- }
- }
-}
-/**
- * Modifier Key Action
- * None Remove old selection, move selection one page up
- * Ctrl Keep old selection, move input focus one page up
- * Shift Extend selection one page up
- * One page is the number of items that can be displayed in the
- * receiver's canvas without truncating the last item.
- * The selection is set to the first item if there is no full page
- * of items left.
- * Modifier Key is ignored when receiver has single selection style.
- * @param keyMask - the modifier key that was pressed
- */
-void doPageUp(int keyMask) {
- SelectableItem newFocus;
- int focusItemIndex = getVisibleIndex(getLastFocus());
- int visibleItemCount;
-
- if (focusItemIndex > 0) {
- visibleItemCount = getItemCountWhole();
- focusItemIndex = Math.max(
- 0,
- focusItemIndex - (visibleItemCount - 1));
- newFocus = getVisibleItem(focusItemIndex);
- if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
- setLastFocus(newFocus, true);
- }
- else
- if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
- shiftSelect(newFocus, focusItemIndex);
- }
- else {
- deselectAllExcept(newFocus);
- selectNotify(newFocus);
- }
- }
-}
-/**
- * Modifier Key Action
- * Ctrl Keep old selection, toggle selection of the item
- * that has the input focus
- * Shift Extend selection to the item that has the input
- * focus
- * Ctrl & Shift Set selection to the item that has input focus
- * Do nothing if receiver has single selection style.
- * @param keyMask - the modifier key that was pressed
- */
-
-void doSpace(int keyMask) {
- SelectableItem item = getLastFocus();
- if (item == null) return;
- if (item.isCheckable() == true) doCheckItem(item);
- int itemIndex = getVisibleIndex(item);
-
- if (keyMask == SWT.NULL && item.isSelected() == false) { // do simple space select in SINGLE and MULTI mode
- deselectAllExcept(item);
- selectNotify(item);
- return;
- }
- if (isMultiSelect() == false) {
- return;
- }
- if (keyMask == SWT.MOD1) {
- toggleSelectionNotify(item);
- }
- else
- if (((keyMask & SWT.MOD1) != 0) && ((keyMask & SWT.MOD2) != 0)) {
- deselectAllExcept(item);
- selectNotify(item);
- }
- else
- if (keyMask == SWT.MOD2) {
- shiftSelect(item, itemIndex);
- }
-}
-/**
- * Make sure that free space at the bottom of the receiver is
- * occupied.
- * There will be new space available below the last item when the
- * receiver's height is increased. In this case the receiver
- * is scrolled down to occupy the new space.if the top item is
- * not the first item of the receiver.
- */
-void claimBottomFreeSpace() {
- int clientAreaItemCount = getItemCountWhole();
- int topIndex = getTopIndex();
- int newTopIndex;
- int lastItemIndex = getVisibleItemCount() - topIndex;
-
- if ((topIndex > 0) &&
- (lastItemIndex > 0) &&
- (lastItemIndex < clientAreaItemCount)) {
- newTopIndex = Math.max(0, topIndex-(clientAreaItemCount-lastItemIndex));
- setTopIndex(newTopIndex, true);
- }
-}
-/**
- * Make sure that free space at the right side of the receiver is
- * occupied.
- * There will be new space available at the right side of the receiver
- * when the receiver's width is increased. In this case the receiver
- * is scrolled to the right to occupy the new space.if possible.
- */
-void claimRightFreeSpace() {
- int clientAreaWidth = getClientArea().width;
- int newHorizontalOffset = clientAreaWidth - getContentWidth();
-
- if (newHorizontalOffset - getHorizontalOffset() > 0) { // item is no longer drawn past the right border of the client area
- newHorizontalOffset = Math.min(0, newHorizontalOffset); // align the right end of the item with the right border of the
- setHorizontalOffset(newHorizontalOffset); // client area (window is scrolled right)
- }
-}
-/** Not used right now. Replace focusIn/focusOut with this method once
- * Display.getFocusWindow returns the new focus window on FocusOut event
- * (see 1FMITIE)
- * The focus has moved in to or out of the receiver.
- * Redraw the item selection to reflect the focus change.
- * @param event - the focus change event
- */
-void focusChange(Event event) {
- Enumeration items = getSelectionVector().elements();
- SelectableItem lastFocusItem = getLastFocus();
- SelectableItem item;
-
- while (items.hasMoreElements() == true) {
- item = (SelectableItem) items.nextElement();
- redrawSelection(item);
- }
- if (lastFocusItem != null) {
- redrawSelection(lastFocusItem);
- }
-}
-/**
- * The focus has moved in to or out of the receiver.
- * Redraw the item selection to reflect the focus change.
- * @param event - the focus change event
- */
-void focusIn(Event event) {
- Enumeration items = getSelectionVector().elements();
- SelectableItem lastFocusItem = getLastFocus();
- SelectableItem item;
-
- // Workaround for 1FMITIE
- hasFocus = true;
- while (items.hasMoreElements() == true) {
- item = (SelectableItem) items.nextElement();
- redrawSelection(item);
- }
- if (lastFocusItem != null) {
- redrawSelection(lastFocusItem);
- }
- // Fix blank item on slow machines/VMs. Also fixes 1G0IFMZ.
- update();
-}
-/**
- * The focus has moved in to or out of the receiver.
- * Redraw the item selection to reflect the focus change.
- * @param event - the focus change event
- */
-void focusOut(Event event) {
- Enumeration items = getSelectionVector().elements();
- SelectableItem lastFocusItem = getLastFocus();
- SelectableItem item;
-
- // Workaround for 1FMITIE
- hasFocus = false;
- while (items.hasMoreElements() == true) {
- item = (SelectableItem) items.nextElement();
- redrawSelection(item);
- }
- if (lastFocusItem != null) {
- redrawSelection(lastFocusItem);
- }
- // Fix blank item on slow machines/VMs. Also fixes 1G0IFMZ.
- update();
-}
-/**
- * Answer the index of the last item position in the receiver's
- * client area.
- * @return 0-based index of the last item position in the tree's
- * client area.
- */
-int getBottomIndex() {
- return getTopIndex() + getItemCountTruncated(getClientArea());
-}
-/**
- * Answer the size of the check box image.
- * The calculation is cached and assumes that the images for
- * the checked and unchecked state are the same size.
- */
-Point getCheckBoxExtent() {
- Image checkedImage;
- Rectangle imageBounds;
-
- if (checkBoxExtent == null) {
- checkedImage = getUncheckedImage();
- if (checkedImage != null) {
- imageBounds = checkedImage.getBounds();
- checkBoxExtent = new Point(imageBounds.width, imageBounds.height);
- }
- else {
- checkBoxExtent = new Point(0, 0);
- }
- }
- return checkBoxExtent;
-}
-/**
- * Answer the image for the selected check box
- * Answer null if the image couldn't be loaded.
- */
-Image getCheckMarkImage() {
-
- if (checkMarkImage == null) {
- checkMarkImage = new Image(getDisplay(), CheckMarkImageData);
- }
- return checkMarkImage;
-}
-/**
- * Answer the width of the receiver's content.
- * Needs to be set by subclasses.
- */
-int getContentWidth() {
- return contentWidth;
-}
-/**
- * Answer the horizontal drawing offset used for scrolling.
- * This is < 0 if the receiver has been scrolled to the left,
- * > 0 if the receiver has been scrolled to the right and 0
- * if the receiver has not been scrolled.
- */
-int getHorizontalOffset() {
- return horizontalOffset;
-}
-
-/**
- * Answer the size of item images. Calculated during the item
- * height calculation.
- */
-Point getImageExtent() {
- return itemImageExtent;
-}
-/**
- * Answer the image extent of 'item'. Overridden by subclasses.
- */
-Point getImageExtent(SelectableItem item) {
- Image image = item.getImage();
- Rectangle imageBounds;
- Point imageExtent = null;
-
- if (image != null) {
- imageBounds = image.getBounds();
- imageExtent = new Point(imageBounds.width, imageBounds.height);
- }
- return imageExtent;
-}
-/**
- * Answer the index of 'item' in the receiver.
- */
-abstract int getIndex(SelectableItem item);
-/**
- * Answer the first and last index of items that can be displayed in
- * the area defined by 'clipRectangle'. This includes partial items.
- * @return
- * Array -
- * First element is the index of the first item in 'clipRectangle'.
- * Second element is the index of the last item in 'clipRectangle'.
- */
-int[] getIndexRange(Rectangle clipRectangle) {
- int visibleRange[] = new int[] {0, 0};
-
- visibleRange[0] = clipRectangle.y / getItemHeight();
- visibleRange[1] =
- visibleRange[0] +
- getItemCountTruncated(clipRectangle) - 1; // - 1 because item index is 0 based
- return visibleRange;
-}
-/**
- * Return the item that draws the marker indicating the insert location
- * in a drag and drop operation
- */
-SelectableItem getInsertItem() {
- return insertItem;
-}
-/**
- * Answer the number of items in the receiver.
- */
-public abstract int getItemCount();
-/**
- * Answer the number of items that can be displayed in 'rectangle'.
- * The result includes partially visible items.
- */
-int getItemCountTruncated(Rectangle rectangle) {
- int itemHeight = getItemHeight();
- int itemCount = 0;
- int startIndex;
-
- startIndex = rectangle.y / itemHeight;
- itemCount = Compatibility.ceil(rectangle.y + rectangle.height, itemHeight)-startIndex;
- return itemCount;
-}
-/**
- * Answer the number of items that can be displayed in the client
- * area of the receiver.
- * The result only includes items that completely fit into the
- * client area.
- */
-int getItemCountWhole() {
- return getClientArea().height / getItemHeight();
-}
-/**
- * Answer the height of an item in the receiver.
- * The item height is the greater of the item icon height and
- * text height of the first item that has text or an image
- * respectively.
- * Calculate a default item height based on the font height if
- * no item height has been calculated yet.
- */
-public int getItemHeight() {
- checkWidget();
- GC gc;
- if (itemHeight == 0) {
- gc = new GC(this);
- itemHeight = gc.stringExtent("String").y + getItemPadding(); // initial item height=font height + item spacing
- // use real font height here when available in SWT, instead of GC.textExtent
- gc.dispose();
- }
- return itemHeight;
-}
-/**
- * Answer the number of pixels that should be added to the item height.
- */
-int getItemPadding() {
- return 2 + getDisplay().textHighlightThickness;
-}
-/**
- * Answer the item that most recently received the input focus.
- */
-SelectableItem getLastFocus() {
- return lastFocusItem;
-}
-/**
- * Answer the item that was selected most recently.
- */
-SelectableItem getLastSelection() {
- return lastSelectedItem;
-}
-/**
- * Answer the event listener used for all events. Events are
- * dispatched to handler methods in handleEvents(Event).
- * This scheme saves a lot of inner classes.
- */
-Listener getListener() {
- return listener;
-}
-/**
- * Answer the y coordinate at which 'item' is drawn.
- * @param item - SelectableItem for which the paint position
- * should be returned
- * @return the y coordinate at which 'item' is drawn.
- * Return -1 if 'item' is not an item of the receiver
- */
-int getRedrawY(SelectableItem item) {
- int redrawIndex = getVisibleIndex(item);
- int redrawY = -1;
-
- if (redrawIndex != -1) {
- redrawY = (redrawIndex - getTopIndex()) * getItemHeight();
- }
- return redrawY;
-}
-/**
- * Answer the number of selected items in the receiver.
- */
-public int getSelectionCount() {
- checkWidget();
- return getSelectionVector().size();
-}
-/**
- * Answer the selected items of the receiver.
- * @return The selected items of the receiver stored in a Vector.
- * Returned Vector is empty if no items are selected.
- */
-Vector getSelectionVector() {
- return selectedItems;
-}
-/**
- * Answer the width of 'text' in pixel.
- * Answer 0 if 'text' is null.
- */
-int getTextWidth(String text) {
- int textWidth = 0;
- GC gc;
-
- if (text != null) {
- gc = new GC(this);
- textWidth = gc.stringExtent(text).x;
- gc.dispose();
- }
- return textWidth;
-}
-/**
- * Answer the index of the first visible item in the receiver's
- * client area.
- * @return 0-based index of the first visible item in the
- * receiver's client area.
- */
-int getTopIndex() {
- return topIndex;
-}
-/**
- * Answer the image for the deselected check box.
- */
-Image getUncheckedImage() {
-
- if (uncheckedImage == null) {
- uncheckedImage = new Image(getDisplay(), UncheckedImageData);
- }
- return uncheckedImage;
-}
-
-/**
- * Answer the image for the grayed eck box.
- */
-Image getGrayUncheckedImage() {
-
- if (grayUncheckedImage == null) {
- grayUncheckedImage = new Image(getDisplay(), GrayUncheckedImageData);
- }
- return grayUncheckedImage;
-}
-
-/**
- * Answer the index of 'item' in the receiver.
- * Answer -1 if the item is not visible.
- * The returned index must refer to a visible item.
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. It only means that the item
- * would be displayed if it is located inside the receiver's
- * client area.
- * Normally, every item of the receiver is visible.
- */
-abstract int getVisibleIndex(SelectableItem item);
-/**
- * Answer the SelectableItem located at 'itemIndex' in the
- * receiver.
- * @param itemIndex - location of the SelectableItem object
- * to return
- */
-abstract SelectableItem getVisibleItem(int itemIndex);
-/**
- * Answer the number of visible items of the receiver.
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. It only means that the item
- * would be displayed if it is located inside the receiver's
- * client area.
- * Normally every item of the receiver is visible.
- */
-int getVisibleItemCount() {
- return getItemCount();
-}
-/**
- * Answer the y coordinate at which 'item' is drawn.
- * @param item - SelectableItem for which the paint position
- * should be returned
- * @return the y coordinate at which 'item' is drawn.
- * Return -1 if 'item' is null or outside the client area
- */
-abstract int getVisibleRedrawY(SelectableItem item);
-/**
- * Handle the events the receiver is listening to.
- */
-void handleEvents(Event event) {
- switch (event.type) {
- case SWT.Dispose:
- doDispose();
- break;
- case SWT.KeyDown:
- keyDown(event);
- break;
- case SWT.Resize:
- resize(event);
- break;
- case SWT.Selection:
- if (event.widget == getVerticalBar()) {
- scrollVertical(event);
- }
- else
- if (event.widget == getHorizontalBar()) {
- scrollHorizontal(event);
- }
- break;
- case SWT.FocusOut:
- focusOut(event);
- break;
- case SWT.FocusIn:
- focusIn(event);
- 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:
- event.doit = true;
- break;
- }
- break;
- }
-}
-
-
-
-/**
- * Answer whether 'item' has the input focus.
- */
-boolean hasFocus(SelectableItem item) {
- return (isFocusControl() && item == getLastFocus());
-}
-/**
- * Initialize the receiver. Add event listeners and set widget
- * colors.
- */
-void initialize() {
- Display display = getDisplay();
- ScrollBar horizontalBar = getHorizontalBar();
- ScrollBar verticalBar = getVerticalBar();
-
- // listener may be needed by overridden installListeners()
- listener = new Listener() {
- public void handleEvent(Event event) {handleEvents(event);}
- };
- setSelectionVector(new Vector());
- installListeners();
- calculateVerticalScrollbar();
- calculateHorizontalScrollbar();
- horizontalBar.setMinimum(0);
- verticalBar.setMinimum(0);
- horizontalBar.setIncrement(HORIZONTAL_SCROLL_INCREMENT);
- setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
- setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
-}
-/**
- * Initialize the ImageData used for the checked/unchecked images.
- */
-static void initializeImageData() {
- PaletteData uncheckedPalette = new PaletteData(
- new RGB[] {new RGB(128, 128, 128), new RGB(255, 255, 255)});
- PaletteData grayUncheckedPalette = new PaletteData(
- new RGB[] {new RGB(128, 128, 128), new RGB(192, 192, 192)});
- 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};
-
- // Each pixel is represented by one bit in the byte data.
- // The bit references the palette position (0 or 1). Each pixel row of an image is padded to one byte.
- // Arguments: width, height, depth, palette, scanline padding, data
- UncheckedImageData = new ImageData(11, 11, 1, uncheckedPalette, 2, checkbox);
- GrayUncheckedImageData = new ImageData(11, 11, 1, grayUncheckedPalette, 2, checkbox);
- CheckMarkImageData = new ImageData(7, 7, 1, checkMarkPalette, 1, new byte[] {-4, -8, 112, 34, 6, -114, -34});
- CheckMarkImageData.transparentPixel = 1;
-}
-/**
- * Add event listeners to the tree widget and its scroll bars.
- */
-void installListeners() {
- Listener listener = getListener();
-
- addListener(SWT.Dispose, listener);
- addListener(SWT.Resize, listener);
- addListener(SWT.KeyDown, listener);
- addListener(SWT.FocusOut, listener);
- addListener(SWT.FocusIn, listener);
- addListener(SWT.Traverse, listener);
-
- getVerticalBar().addListener(SWT.Selection, listener);
- getHorizontalBar().addListener(SWT.Selection, listener);
-}
-/**
- * Answer whether the currently selected items were selected
- * using the ctrl key.
- */
-boolean isCtrlSelection() {
- return isCtrlSelection;
-}
-/**
- * Answer true if all items in the widget are disposed.
- * Used to optimize item disposal. Prevents unnecessary screen
- * updates.
- */
-boolean isRemovingAll() {
- return isRemovingAll;
-}
-/**
- * Answer whether the receiver has the input focus.
- * Workaround for 1FMITIE
- */
-public boolean isFocusControl() {
- return hasFocus;
-}
-/**
- * Return whether the drop insert position is before or after the
- * item set using motif_setInsertMark.
- * @return
- * true=insert position is after the insert item
- * false=insert position is before the insert item
- */
-boolean isInsertAfter() {
- return isInsertAfter;
-}
-/**
- * Answer whether the receiver has the MULTI selection style set.
- * @return
- * true = receiver is in multiple selection mode.
- * false = receiver is in single selection mode.
- */
-boolean isMultiSelect() {
- return ((getStyle() & SWT.MULTI) != 0);
-}
-/**
- * The item identified by 'changedItem' has changed.
- * Calculate the item height based on the new item data (it might
- * now have an image which could also be the first image in the
- * receiver)
- * Redraw the whole window if the item height has changed. Otherwise
- * redraw only the changed item or part of it depending on the
- * 'repaintStartX' and 'repaintWidth' parameters.
- * @param changedItem - the item that has changed
- * @param repaintStartX - x position of the item redraw.
- * @param repaintWidth - width of the item redraw.
- */
-void itemChanged(SelectableItem changedItem, int repaintStartX, int repaintWidth) {
- int yPosition;
- int itemHeight;
- int oldItemHeight = getItemHeight();
- Point oldImageExtent = getImageExtent();
-
- calculateItemHeight(changedItem); // make sure that the item height is recalculated
- // no redraw necessary if redraw width is 0 or item is not visible
- if (repaintWidth == 0 || (yPosition = getVisibleRedrawY(changedItem)) == -1) {
- return;
- } // if changedItem is the first item with image.
- itemHeight = getItemHeight();
- if ((oldItemHeight == itemHeight) && // only redraw changed item if the item height and
- (oldImageExtent == getImageExtent())) { // image size has not changed. The latter will only change once,
- // from null to a value-so it's safe to test using !=
- // redrawing outside the client area redraws the widget border on Motif.
- // adjust the redraw width if necessary. Workaround for 1G4TQRW
- repaintWidth = Math.min(repaintWidth, getClientArea().width - repaintStartX);
- if (repaintWidth > 0) {
- redraw(repaintStartX, yPosition, repaintWidth, itemHeight, true);
- }
- }
- else {
- redraw(); // redraw all items if the item height has changed
- }
-}
-/**
- * A key was pressed. Call the appropriate handler method.
- * @param event - the key event
- */
-void keyDown(Event event) {
- boolean isCtrlSelection = isCtrlSelection();
-
- if (event.stateMask != SWT.MOD1) {
- isCtrlSelection = false;
- }
- switch (event.keyCode) {
- case SWT.ARROW_UP:
- doArrowUp(event.stateMask);
- break;
- case SWT.ARROW_DOWN:
- doArrowDown(event.stateMask);
- break;
- case SWT.ARROW_LEFT:
- doArrowLeft(event.stateMask);
- break;
- case SWT.ARROW_RIGHT:
- doArrowRight(event.stateMask);
- break;
- case SWT.PAGE_UP:
- doPageUp(event.stateMask);
- break;
- case SWT.PAGE_DOWN:
- doPageDown(event.stateMask);
- break;
- case SWT.HOME:
- doHome(event.stateMask);
- break;
- case SWT.END:
- doEnd(event.stateMask);
- break;
- default: // no selection occurred, keep previous
- isCtrlSelection = isCtrlSelection(); // selection type information
- }
- if (event.character == ' ') {
- doSpace(event.stateMask);
- isCtrlSelection = (event.stateMask == SWT.MOD1);
- }
- //forward the enter key pressed to defaultSelection listenters
- if(event.character == SWT.CR){
- Event forwardEvent = new Event();
- forwardEvent.item = getLastFocus();
- notifyListeners(SWT.DefaultSelection, forwardEvent);
- }
- setCtrlSelection(isCtrlSelection);
-}
-/**
- * Sets the drop insert item.
- * The drop insert item has a visual hint to show where a dragged item
- * will be inserted when dropped on the tree.
- * <p>
- * @param item the insert item
- * @param after true places the insert mark below 'item'. false places
- * the insert mark above 'item'.
- */
-void motif_setInsertMark(SelectableItem item, boolean after) {
- SelectableItem currentItem = getInsertItem();
- int redrawY;
-
- setInsertItem(item);
- setInsertAfter(after);
- if (currentItem != null) {
- redrawY = getVisibleRedrawY(currentItem);
- if (redrawY != -1) {
- currentItem.redrawInsertMark(redrawY);
- }
- }
- if (item != null) {
- redrawY = getVisibleRedrawY(item);
- if (redrawY != -1) {
- item.redrawInsertMark(redrawY);
- }
- }
-}
-
-
-/**
- * Overridden to implement setRedraw(). Redraw is ignored if setRedraw was
- * set to false.
- */
-public void redraw () {
- checkWidget();
- if (drawCount == 0) {
- super.redraw();
- }
-}
-/**
- * Overridden to implement setRedraw(). Redraw is ignored if setRedraw was
- * set to false.
- */
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget();
- if (drawCount == 0) {
- super.redraw(x, y, width, height, all);
- }
-}
-
-/**
- * Redraw the selection of 'item'
- * @param item - SelectableItem that should have the selection redrawn.
- */
-void redrawSelection(SelectableItem item) {
- int redrawPosition = getVisibleRedrawY(item);
- if (redrawPosition != -1) {
- item.redrawSelection(redrawPosition);
- }
-}
-/**
- * 'item' has been removed from the receiver.
- * Update the display and the scroll bars.
- */
-void removedItem(SelectableItem item) {
- claimBottomFreeSpace();
- calculateVerticalScrollbar();
- if (getItemCount() == 0) {
- reset();
- }
-}
-/**
- * 'item' is about to be removed from the tree.
- * Move the selection/input focus if 'item' is selected or has the
- * input focus,
- * @param item - item that is about to be removed from the tree.
- */
-void removingItem(SelectableItem item) {
- SelectableItem nextFocusItem = null;
- int itemIndex = getVisibleIndex(item);
- int itemCount = getVisibleItemCount();
-
- // deselect item and remove from selection
- if (item.isSelected() == true) {
- getSelectionVector().removeElement(item);
- }
- if (item == getLastFocus() && itemCount > 1) {
- // select previous item if removed item is bottom item
- // otherwise select next item. Fixes 1GA6L85
- if (itemIndex == itemCount - 1) {
- nextFocusItem = getVisibleItem(itemIndex - 1);
- }
- else {
- nextFocusItem = getVisibleItem(itemIndex + 1);
- }
- setLastFocus(nextFocusItem, true);
- }
- // ignore items below widget client area
- if (itemIndex != -1 && itemIndex <= getBottomIndex()) {
- scrollVerticalRemovedItem(itemIndex);
- }
-}
-/**
- * Reset state that is dependent on or calculated from the state
- * of the receiver.
- */
-void reset() {
- setSelectionVector(new Vector());
- setTopIndexNoScroll(0, true);
- lastSelectedItem = null;
- lastFocusItem = null;
- resetItemData();
-}
-/**
- * Reset state that is dependent on or calculated from the items
- * of the receiver.
- */
-void resetItemData() {
- setHorizontalOffset(0);
- setItemHeight(0);
- itemImageExtent = null;
- textHeight = -1;
- claimRightFreeSpace();
-}
-/**
- * The receiver has been resized. Update the scroll bars and
- * make sure that new space is being occupied by items.
- */
-void resize(Event event) {
- int horizontalPageSize = getHorizontalBar().getPageIncrement();
-
- resizeHorizontalScrollbar();
- resizeVerticalScrollbar();
- if (getClientArea().width > horizontalPageSize) { // window resized wider? - Do this check here
- claimRightFreeSpace(); // because claimRightFreeSpace is called elsewhere.
- }
- claimBottomFreeSpace();
-}
-/**
- * Display the horizontal scroll bar if items are drawn off
- * screen. Update the page size.
- */
-void resizeHorizontalScrollbar() {
- ScrollBar horizontalBar = getHorizontalBar();
- int clientAreaWidth = getClientArea().width;
-
- if (clientAreaWidth < getContentWidth()) {
- if (horizontalBar.getVisible() == false) {
- horizontalBar.setVisible(true);
- horizontalBar.setSelection(0);
- }
- }
- else
- if (horizontalBar.getVisible() == true) {
- horizontalBar.setVisible(false);
- }
- horizontalBar.setThumb(clientAreaWidth);
- horizontalBar.setPageIncrement(clientAreaWidth);
-}
-/**
- * Display the vertical scroll bar if items are drawn off screen.
- * Update the page size.
- */
-void resizeVerticalScrollbar() {
- int clientAreaItemCount = getItemCountWhole();
- ScrollBar verticalBar = getVerticalBar();
-
- if (clientAreaItemCount == 0) {
- return;
- }
- if (clientAreaItemCount < getVisibleItemCount()) {
- if (verticalBar.getVisible() == false) {
- verticalBar.setVisible(true);
- }
- // Only set the page size to something smaller than the scroll
- // range maximum. Otherwise the scroll selection will be reset.
- verticalBar.setPageIncrement(clientAreaItemCount);
- verticalBar.setThumb(clientAreaItemCount);
- }
- else
- if (verticalBar.getVisible() == true) {
- verticalBar.setVisible(false);
- }
-}
-/**
- * Scroll the rectangle specified by x, y, width, height to the destination
- * position. Do nothing if redraw is set to false using setRedraw().
- *
- * @param destX - destination x position of the scrolled rectangle
- * @param destY - destination y position of the scrolled rectangle
- * @param x - x location of the upper left corner of the scroll rectangle
- * @param y - y location of the upper left corner of the scroll rectangle
- * @param width - width of the scroll rectangle
- * @param height - height of the scroll rectangle
- * @param all - not used. Used to be true=scroll children intersecting the
- * scroll rectangle.
- */
-void scroll(int destX, int destY, int x, int y, int width, int height, boolean all) {
- if (drawCount == 0) {
- update();
- GC gc = new GC(this);
- gc.copyArea(x, y, width, height, destX, destY);
- gc.dispose();
- }
-}
-/**
- * Scroll horizontally by 'numPixel' pixel.
- * @param numPixel - the number of pixel to scroll
- * numPixel > 0 = scroll to left. numPixel < 0 = scroll to right
- */
-abstract void scrollHorizontal(int numPixel);
-/**
- * The position of the horizontal scroll bar has been modified
- * by the user.
- * Adjust the horizontal offset to trigger a horizontal scroll.
- * @param event-the scroll event
- */
-void scrollHorizontal(Event event) {
- setHorizontalOffset(getHorizontalBar().getSelection() * -1);
-}
-void scrollShowItem(int index) {
- int itemIndexFromTop = index - getTopIndex();
- int clientAreaWholeItemCount = getItemCountWhole();
- int scrollAmount = 0;
-
- if (itemIndexFromTop >= clientAreaWholeItemCount) { // show item below visible items?
- scrollAmount = itemIndexFromTop;
- if (clientAreaWholeItemCount > 0) { // will be 0 if showItem is called and receiver hasn't been displayed yet
- scrollAmount -= clientAreaWholeItemCount - 1;
- }
- }
- else
- if (itemIndexFromTop < 0) { // show item above visible items?
- scrollAmount = itemIndexFromTop;
- }
- setTopIndex(getTopIndex() + scrollAmount, true);
-}
-/**
- * Scroll vertically by 'scrollIndexCount' items.
- * @param scrollIndexCount - the number of items to scroll.
- * scrollIndexCount > 0 = scroll up. scrollIndexCount < 0 = scroll down
- */
-abstract void scrollVertical(int scrollIndexCount);
-/**
- * The position of the horizontal scroll bar has been modified
- * by the user.
- * Adjust the index of the top item to trigger a vertical scroll.
- * @param event-the scroll event
- */
-void scrollVertical(Event event) {
- setTopIndex(getVerticalBar().getSelection(), false);
-}
-/**
- * Scroll items down to make space for a new item added to
- * the receiver at position 'index'.
- * @param index - position at which space for one new item
- * should be made. This index is relative to the first item
- * of the receiver.
- */
-void scrollVerticalAddingItem(int index) {
- Rectangle clientArea = getClientArea();
- int itemHeight = getItemHeight();
- int sourceY = Math.max(0, (index - getTopIndex()) * itemHeight); // need to scroll in visible area
-
- scroll(
- 0, sourceY + itemHeight, // destination x, y
- 0, sourceY, // source x, y
- clientArea.width, clientArea.height, true);
-}
-/**
- * Scroll the items below the item at position 'index' up
- * so that they cover the removed item.
- * @param index - index of the removed item
- */
-void scrollVerticalRemovedItem(int index) {
- Rectangle clientArea = getClientArea();
- int itemHeight = getItemHeight();
- int destinationY = Math.max(0, (index - getTopIndex()) * itemHeight);
-
- scroll(
- 0, destinationY, // destination x, y
- 0, destinationY + itemHeight, // source x, y
- clientArea.width, clientArea.height, true);
-}
-/**
- * Select 'item' if it is not selected.
- * @param item - item that should be selected
- */
-void select(SelectableItem item) {
- Vector selectedItems = getSelectionVector();
-
- if (item != null && item.isSelected() == false && isRemovingAll() == false) {
- item.setSelected(true);
- redrawSelection(item);
- selectedItems.addElement(item);
- }
-}
-/**
- * Select 'item' if it is not selected. Send a Selection event
- * if the selection was changed.
- * @param item - item that should be selected
- * @param asyncNotify
- * true=send the selection event asynchronously
- * false=send the selection event immediately
- */
-void selectNotify(final SelectableItem item, boolean asyncNotify) {
- if (isRemovingAll() == false) {
- if (item.isSelected() == false) {
- select(item);
- setLastSelection(item, true);
- update(); // looks better when event notification takes long to return
- }
- if (asyncNotify == false) {
- Event event = new Event();
- event.item = item;
- notifyListeners(SWT.Selection, event);
- }
- else {
- getDisplay().asyncExec(new Runnable() {
- public void run() {
- // Only send a selection event when the item has not been disposed.
- // Fixes 1GE6XQA
- if (item.isDisposed() == false) {
- Event event = new Event();
- event.item = item;
- notifyListeners(SWT.Selection, event);
- }
- }
- });
- }
- }
-}
-/**
- * Select 'item' if it is not selected. Send a Selection event
- * if the selection was changed.
- * @param item - item that should be selected
- */
-void selectNotify(SelectableItem item) {
- selectNotify(item, false);
-}
-/**
- * Select all items of the receiver starting at 'fromIndex'
- * and including 'toIndex'.
- */
-void selectRange(int fromIndex, int toIndex) {
- if (fromIndex > toIndex) {
- for (int i = fromIndex; i > toIndex; i--) {
- select(getVisibleItem(i));
- }
- }
- else {
- for (int i = fromIndex; i < toIndex; i++) {
- select(getVisibleItem(i));
- }
- }
- selectNotify(getVisibleItem(toIndex)); // select last item, notifying listeners
-}
-/**
- * Set the width of the receiver's contents to 'newWidth'.
- * Content width is used to calculate the horizontal scrollbar.
- */
-void setContentWidth(int newWidth) {
- ScrollBar horizontalBar;
- boolean scrollBarVisible;
-
- if (contentWidth != newWidth) {
- horizontalBar = getHorizontalBar();
- scrollBarVisible = horizontalBar.getVisible();
- contentWidth = newWidth;
- calculateHorizontalScrollbar();
- if (scrollBarVisible != horizontalBar.getVisible()) {
- resizeVerticalScrollbar(); // the vertical scroll bar needs to be resized if the horizontal
- } // scroll bar was hidden or made visible during recalculation
- }
-}
-/**
- * Set whether the currently selected items were selected using the
- * ctrl key.
- * @param isCtrlSelection -
- * true = currently selected items were selected using the ctrl key.
- * false = currently selected items were not selected using the
- * ctrl key.
- */
-void setCtrlSelection(boolean isCtrlSelection) {
- this.isCtrlSelection = isCtrlSelection;
-}
-/**
- * The font is changing. Reset the text height to force a
- * recalculation during itemChanged().
- */
-public void setFont(Font font) {
- checkWidget();
- super.setFont(font);
- textHeight = -1;
-}
-/**
- * Set the horizontal drawing offset to 'offset'.
- * Scroll the receiver's contents according to the offset change.
- * @param offset - value < 0 = widget contents is drawn left of the client area.
- */
-void setHorizontalOffset(int offset) {
- int offsetChange = offset - horizontalOffset;
- if (offsetChange != 0) {
- scrollHorizontal(offsetChange);
- horizontalOffset = offset;
- }
-}
-
-/**
- * Set whether the drop insert position is before or after the
- * item set using motif_setInsertMark.
- * @param after true=insert position is after the insert item
- * false=insert position is before the insert item
- */
-void setInsertAfter(boolean after) {
- isInsertAfter = after;
-}
-
-/**
- * Set the item that draws the marker indicating the insert location
- * in a drag and drop operation.
- * @param item the item that draws the insert marker
- */
-void setInsertItem(SelectableItem item) {
- insertItem = item;
-}
-/**
- * Set the height of the receiver's items to 'height'.
- */
-void setItemHeight(int height) {
- itemHeight = height;
-}
-/**
- * Set the item that most recently received the input focus
- * to 'focusItem'. Redraw both, the item that lost focus
- * and the one that received focus.
- * @param focusItem - the item that most recently received
- * the input focus
- * @param showItem true=new focus item, if any, should be scrolled
- * into view. false=don't scroll
- */
-void setLastFocus(SelectableItem focusItem, boolean showItem) {
- SelectableItem oldFocusItem = lastFocusItem;
-
- if (focusItem != lastFocusItem) {
- lastFocusItem = focusItem;
- if (oldFocusItem != null) {
- redrawSelection(oldFocusItem);
- }
- if (lastFocusItem != null && isFocusControl() == true) {
- redrawSelection(lastFocusItem);
- }
- }
- if (focusItem != null && showItem == true) {
- showSelectableItem(focusItem);
- }
-}
-/**
- * Set the item that was selected most recently to 'selectedItem'.
- * Set the input focus to that item.
- * @param selectedItem - the item that was selected most recently
- * @param showItem true=new focus item, if any, should be scrolled
- * into view. false=don't scroll
- */
-void setLastSelection(SelectableItem selectedItem, boolean showItem) {
- if (selectedItem == null) { // always store the item selected last
- return;
- }
- setLastFocus(selectedItem, showItem);
- lastSelectedItem = selectedItem;
-}
-/**
- * Sets the redraw flag.
- * @param redraw -
- * true = redraw and scroll operations are performed normally
- * false = redraw and scroll operations are ignored
- */
-public void setRedraw (boolean redraw) {
- checkWidget();
- if (redraw) {
- if (--drawCount == 0) redraw();
- } else {
- drawCount++;
- }
-}
-/**
- * Set whether all items in the widget are disposed.
- * Used to optimize item disposal. Prevents unnecessary screen
- * updates.
- * @param removingAll
- * true=all items are removed.
- * false=normal state, no items or not all items are removed.
- */
-void setRemovingAll(boolean removingAll) {
- isRemovingAll = removingAll;
-}
-/**
- * Select the items stored in 'selectionItems'.
- * A SWT.Selection event is not going to be sent.
- * @param selectionItems - Array containing the items that should
- * be selected
- */
-void setSelectableSelection(SelectableItem selectionItems[]) {
- SelectableItem item = null;
- int selectionCount = selectionItems.length;
- Vector keepSelected;
-
- if (isMultiSelect() == false && selectionCount > 1) {
- selectionCount = 1;
- }
- keepSelected = new Vector(selectionItems.length);
- for (int i = 0; i < selectionCount; i++) {
- if (selectionItems[i] != null) {
- if (selectionItems[i].isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- keepSelected.addElement(selectionItems[i]);
- }
- }
- deselectAllExcept(keepSelected);
- // select in the same order as all the other selection and deslection methods.
- // Otherwise setLastSelection repeatedly changes the lastSelectedItem for repeated
- // selections of the items, causing flash.
- for (int i = selectionCount - 1; i >= 0; i--) {
- item = selectionItems[i];
- if (item != null) {
- select(item);
- }
- }
- if (item != null) {
- setLastSelection(item, true);
- }
-}
-/**
- * Set the vector used to store the selected items of the receiver
- * to 'newVector'.
- * @param newVector - the vector used to store the selected items
- * of the receiver
- */
-void setSelectionVector(Vector newVector) {
- selectedItems = newVector;
-}
-/**
- * Scroll the item at 'index' to the top.
- * @param index - 0-based index of the first visible item in the
- * receiver's client area.
- * @param adjustScrollbar - true=set the position of the vertical
- * scroll bar to the new top index.
- * false=don't adjust the vertical scroll bar
- */
-void setTopIndex(int index, boolean adjustScrollbar) {
- int indexDiff = index-topIndex;
-
- if (indexDiff != 0) {
- scrollVertical(indexDiff);
- setTopIndexNoScroll(index, adjustScrollbar);
- }
-}
-/**
- * Set the index of the first visible item in the receiver's client
- * area to 'index'.
- * @param index - 0-based index of the first visible item in the
- * receiver's client area.
- * @param adjustScrollbar - true=set the position of the vertical
- * scroll bar to the new top index.
- * false=don't adjust the vertical scroll bar
- */
-void setTopIndexNoScroll(int index, boolean adjustScrollbar) {
- topIndex = index;
- if (adjustScrollbar == true) {
- getVerticalBar().setSelection(index);
- }
-}
-/**
- * The shift key was pressed when the mouse click on an item
- * occurred. Do a shift selection. If an already selected item was
- * clicked the selection is expanded/reduced to that item
- * @param hitItem - specifies the clicked item
- * @param hitItemIndex - specifies the index of the clicked item
- * relative to the first item.
- */
-void shiftSelect(SelectableItem hitItem, int hitItemIndex) {
- int fromIndex = -1;
- int toIndex = -1;
- int lastSelectionIndex = -1;
- int selectionRange[];
- SelectableItem lastSelection = getLastSelection();
-
- if (lastSelection != null) {
- lastSelectionIndex = getVisibleIndex(lastSelection);
- }
- if (isCtrlSelection() == true) { // was last selection ctrl selection?
- deselectAllExcept(lastSelection);
- fromIndex = lastSelectionIndex; // select from last selection
- toIndex = hitItemIndex;
- }
- else
- if (getSelectionVector().contains(hitItem) == true) { // clicked an item already selected?
- deselectRange(hitItemIndex, lastSelectionIndex); // reduce selection
- }
- else { // clicked outside existing selection range
- selectionRange = calculateShiftSelectionRange(hitItemIndex);
- fromIndex = selectionRange[0];
- toIndex = selectionRange[1];
- }
- if (hitItemIndex == lastSelectionIndex) { // was click on last selected item?
- return;
- }
- if (fromIndex == -1 || toIndex == -1) { // are there previously selected items?
- toggleSelectionNotify(hitItem); // do a single select.
- }
- else {
- if (((lastSelectionIndex < fromIndex) && (hitItemIndex > fromIndex)) || // does selection reverse direction?
- ((lastSelectionIndex > fromIndex) && (hitItemIndex < fromIndex))) {
- deselectAllExcept((SelectableItem) null); // remove old selection
- }
- selectRange(fromIndex, toIndex);
- }
-}
-/**
- * Make 'item' visible by scrolling it into the receiver's client
- * area if necessary.
- * @param item - the item that should be made visible to the user.
- */
-void showSelectableItem(SelectableItem item) {
- if (item.getSelectableParent() != this) {
- return;
- }
- int index = getIndex (item);
- showSelectableItem(index);
-}
-/**
- * Make 'index' visible by scrolling it into the receiver's client
- * area if necessary.
- * @param index - the item index that should be made visible to the user.
- */
-void showSelectableItem(int index) {
- scrollShowItem(index);
- scrollShowItem(index); // second call makes sure that the item is still visible
- // even if the first scroll caused the horizontal scroll
- // to be displayed and the item to be hidden again.
-}
-/**
- * Show the selection. If there is no selection or the
- * selection is already visible, this method does nothing.
- * If the selection is not visible, the top index of the
- * widget is changed such that the selection becomes visible.
- */
-public void showSelection() {
- checkWidget();
- Vector selection = getSelectionVector();
- SelectableItem selectionItem;
-
- if (selection.size() > 0) {
- selectionItem = (SelectableItem) selection.firstElement();
- showSelectableItem(selectionItem);
- }
-}
-/**
- * Sorts the specified range in the array.
- *
- * @param array the SelectableItem array to be sorted
- * @param start the start index to sort
- * @param end the last + 1 index to sort
- */
-void sort(SelectableItem[] array, int start, int end) {
- int middle = (start + end) / 2;
- if (start + 1 < middle) sort(array, start, middle);
- if (middle + 1 < end) sort(array, middle, end);
- if (start + 1 >= end) return; // this case can only happen when this method is called by the user
- if (getVisibleIndex(array[middle-1]) <= getVisibleIndex(array[middle])) return;
- if (start + 2 == end) {
- SelectableItem temp = array[start];
- array[start] = array[middle];
- array[middle] = temp;
- return;
- }
- int i1 = start, i2 = middle, i3 = 0;
- SelectableItem[] merge = new SelectableItem[end - start];
- while (i1 < middle && i2 < end) {
- merge[i3++] = getVisibleIndex(array[i1]) <= getVisibleIndex(array[i2]) ?
- array[i1++] : array[i2++];
- }
- if (i1 < middle) System.arraycopy(array, i1, merge, i3, middle - i1);
- System.arraycopy(merge, 0, array, start, i2 - start);
-}
-/**
- * Toggle the selection of 'item'.
- * @param item - item that should be selected/deselected
- */
-void toggleSelectionNotify(SelectableItem item) {
- if (item.isSelected() == true) {
- deselectNotify(item);
- }
- else {
- selectNotify(item);
- }
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.internal.Compatibility;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * This class is intended for widgets that display data of
+ * type Item. It provides a framework for scrolling and
+ * handles the screen refresh required when adding and
+ * removing items.
+ */
+abstract class SelectableItemWidget extends Composite {
+ private static final int DEFAULT_WIDTH = 64; // used in computeSize if width could not be calculated
+ private static final int DEFAULT_HEIGHT = 64; // used in computeSize if height could not be calculated
+ private static final int HORIZONTAL_SCROLL_INCREMENT = 5; // number of pixel the tree is moved
+ // during horizontal line scrolling
+ private static ImageData UncheckedImageData; // deselected check box image data. used to create an image at run time
+ private static ImageData GrayUncheckedImageData; // grayed deselected check box image data. used to create an image at run time
+ private static ImageData CheckMarkImageData; // check mark image data for check box. used to create an image at run time
+ static {
+ initializeImageData();
+ }
+
+ private int topIndex = 0; // index of the first visible item
+ private int itemHeight = 0; // height of a table item
+ private Point itemImageExtent = null; // size of the item images. Null unless an image is set for any item
+ private int textHeight = -1;
+ private int contentWidth = 0; // width of the widget data (ie. table rows/tree items)
+ private int horizontalOffset = 0;
+ private Vector selectedItems; // indices of the selected items
+ private SelectableItem lastSelectedItem; // item that was selected last
+ private SelectableItem lastFocusItem; // item that had the focus last. Always equals lastSelectedItem
+ // for mouse selection but may differ for keyboard selection
+ private SelectableItem insertItem; // item that draws the insert marker to indicate the drop location in a drag and drop operation
+ private boolean isInsertAfter; // indicates where the insert marker is rendered, at the top or bottom of 'insertItem'
+ private boolean isCtrlSelection = false; // the most recently selected item was
+ // selected using the Ctrl modifier key
+ private boolean isRemovingAll = false; // true=all items are removed. Used to optimize screen updates and to control item selection on dispose.
+ private boolean hasFocus; // workaround for 1FMITIE
+ private Image uncheckedImage; // deselected check box
+ private Image grayUncheckedImage; // grayed check box
+ private Image checkMarkImage; // check mark for selected check box
+ private Point checkBoxExtent = null; // width, height of the item check box
+ private Listener listener; // event listener used for all events. Events are dispatched
+ // to handler methods in handleEvents(Event)
+ private int drawCount = 0; // used to reimplement setRedraw(boolean)
+/**
+ * Create a new instance of ScrollableItemWidget.
+ * @param parent - the parent window of the new instance
+ * @param style - window style for the new instance
+ */
+SelectableItemWidget(Composite parent, int style) {
+ super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_REDRAW_RESIZE);
+ initialize();
+}
+/**
+ * The SelectableItem 'item' has been added to the tree.
+ * Calculate the vertical scroll bar.
+ * Update the screen to display the new item.
+ * @param item - item that has been added to the receiver.
+ */
+void addedItem(SelectableItem item, int index) {
+ calculateVerticalScrollbar();
+ if (getLastFocus() == null) { // if no item has the focus
+ setLastFocus(item, true); // set focus to new (must be first) item
+ }
+}
+/**
+ * The SelectableItem 'item' is about to be added to the tree.
+ * @param item - item that is about to be added to the receiver.
+ */
+void addingItem(SelectableItem item, int index) {
+ if (index >= 0 && index <= getBottomIndex()) {
+ scrollVerticalAddingItem(index);
+ }
+}
+/**
+ * Set the scroll range of the horizontal scroll bar.
+ * Resize the scroll bar if the scroll range maximum
+ * has changed.
+ */
+void calculateHorizontalScrollbar() {
+ int newMaximum = getContentWidth();
+ ScrollBar horizontalBar = getHorizontalBar();
+
+ if (horizontalBar.getMaximum() != newMaximum) {
+ // The call to setMaximum is ignored if newMaximum is 0.
+ // Therefore we can not rely on getMaximum to subsequently return the number of
+ // items in the receiver. We always have to use getVisibleItemCount().
+ // Never rely on getMaximum to return what you set. It may not accept the
+ // value you set. Even if you use a valid value now the implementation may change
+ // later. That's what caused 1FRLOSG.
+ horizontalBar.setMaximum(newMaximum);
+ if (getVerticalBar().getVisible() == false) { // remove these lines
+ horizontalBar.setMaximum(newMaximum); // when PR 1FIG5CG
+ } // is fixed
+ resizeHorizontalScrollbar();
+ }
+}
+/**
+ * Calculate the height of items in the receiver.
+ * Only the image height is calculated if an item height
+ * has already been calculated. Do nothing if both the item
+ * height and the image height have already been calculated
+ */
+void calculateItemHeight(SelectableItem item) {
+ GC gc;
+ String itemText;
+ int itemHeight = -1;
+
+ if (itemImageExtent != null && textHeight != -1) {
+ return;
+ }
+ itemText = item.getText();
+ if (itemText != null && textHeight == -1) {
+ gc = new GC(this);
+ itemHeight = gc.stringExtent(itemText).y;
+ textHeight = itemHeight;
+ gc.dispose();
+ }
+ if (itemImageExtent == null) {
+ itemImageExtent = getImageExtent(item);
+ if (itemImageExtent != null) {
+ if (itemImageExtent.y > textHeight) {
+ itemHeight = itemImageExtent.y;
+ }
+ else {
+ itemHeight = textHeight;
+ }
+ }
+ }
+ itemHeight += getItemPadding(); // make sure that there is empty space below the image/text
+ if (itemHeight > getItemHeight()) { // only set new item height if it's higher because new,
+ setItemHeight(itemHeight); // smaller item height may not include an icon
+ }
+}
+/**
+ * Calculate the range of items that need to be selected given
+ * the clicked item identified by 'hitItemIndex'
+ * @param hitItemIndex - item that was clicked and that the new
+ * selection range will be based on. This index is relative to
+ * the top index.
+ */
+int [] calculateShiftSelectionRange(int hitItemIndex) {
+ int selectionRange[] = new int[] {-1, -1};
+ SelectableItem closestItem = null;
+ SelectableItem selectedItem;
+ Enumeration selectedItems = getSelectionVector().elements();
+
+ while (selectedItems.hasMoreElements() == true) {
+ selectedItem = (SelectableItem) selectedItems.nextElement();
+ if (closestItem == null) {
+ closestItem = selectedItem;
+ }
+ else
+ if (Math.abs(hitItemIndex - getVisibleIndex(selectedItem)) <
+ Math.abs(hitItemIndex - getVisibleIndex(closestItem))) {
+ closestItem = selectedItem;
+ }
+ }
+ if (closestItem == null) { // no item selected
+ closestItem = getLastSelection(); // item selected last may still have the focus
+ }
+ if (closestItem != null) {
+ selectionRange[0] = getVisibleIndex(closestItem);
+ selectionRange[1] = hitItemIndex;
+ }
+ return selectionRange;
+}
+/**
+ * Set the scroll range of the vertical scroll bar.
+ * Resize the scroll bar if the scroll range maximum
+ * has changed.
+ */
+void calculateVerticalScrollbar() {
+ int newMaximum = getVisibleItemCount();
+ ScrollBar verticalBar = getVerticalBar();
+
+ // The call to setMaximum is ignored if newMaximum is 0.
+ // Therefore we can not rely on getMaximum to subsequently return the number of
+ // items in the receiver. We always have to use getVisibleItemCount().
+ // Never rely on getMaximum to return what you set. It may not accept the
+ // value you set. Even if you use a valid value now the implementation may change
+ // later. That's what caused 1FRLOSG.
+ verticalBar.setMaximum(newMaximum);
+ if (getHorizontalBar().getVisible() == false) { // remove these lines
+ verticalBar.setMaximum(newMaximum); // when PR 1FIG5CG
+ } // is fixed
+ resizeVerticalScrollbar();
+}
+
+/**
+ * Answer the size of the receiver needed to display all items.
+ * The length of the longest item in the receiver is used for the
+ * width.
+ */
+public Point computeSize(int wHint, int hHint, boolean changed) {
+ checkWidget();
+ int width = getContentWidth();
+ int height = getItemCount() * getItemHeight();
+ int scrollBarWidth = computeTrim(0, 0, 0, 0).width;
+
+ 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 ((getStyle() & SWT.V_SCROLL) != 0) {
+ width += scrollBarWidth;
+ }
+ if ((getStyle() & SWT.H_SCROLL) != 0) {
+ height += scrollBarWidth;
+ }
+ return new Point(width, height);
+}
+/**
+ * Do a ctrl+shift selection meaning the ctrl and shift keys
+ * were pressed when the mouse click on an item occurred.
+ * If an already selected item was clicked the focus is moved to
+ * that item.
+ * If the previous selection was a ctrl or ctrl+shift selection
+ * the range between the last selected item and the clicked item
+ * is selected.
+ * Otherwise a regular shift selection is performed.
+ * @param hitItem - specifies the clicked item
+ * @param hitItemIndex - specifies the index of the clicked item
+ * relative to the first item.
+ */
+void ctrlShiftSelect(SelectableItem hitItem, int hitItemIndex) {
+ int fromIndex = -1;
+ int toIndex = -1;
+ int lastSelectionIndex = -1;
+ int selectionRange[];
+ SelectableItem lastSelection = getLastSelection();
+
+ if (lastSelection != null) {
+ lastSelectionIndex = getVisibleIndex(lastSelection);
+ }
+ if ((getSelectionVector().contains(hitItem) == true) && // clicked an already selected item?
+ (hitItemIndex != lastSelectionIndex)) { // and click was not on last selected item?
+ setLastSelection(hitItem, true); // set last selection which also sets the focus
+ }
+ else
+ if (isCtrlSelection() == true) { // was last selection ctrl/ctrl+shift selection?
+ fromIndex = lastSelectionIndex; // select from last selection
+ toIndex = hitItemIndex;
+ }
+ else { // clicked outside existing selection range
+ selectionRange = calculateShiftSelectionRange(hitItemIndex);
+ fromIndex = selectionRange[0];
+ toIndex = selectionRange[1];
+ }
+ if (fromIndex != -1 && toIndex != -1) {
+ selectRange(fromIndex, toIndex);
+ }
+}
+/**
+ * Deselect 'item'.
+ * @param item - item that should be deselected
+ */
+void deselect(SelectableItem item) {
+ Vector selectedItems = getSelectionVector();
+
+ if ((item != null) && (item.isSelected() == true)) {
+ item.setSelected(false);
+ redrawSelection(item);
+ selectedItems.removeElement(item);
+ }
+}
+/**
+ * Deselect all item except 'keepSelected'.
+ * @param keepSelected - item that should remain selected
+ */
+void deselectAllExcept(SelectableItem keepSelected) {
+ Vector selectedItems = getSelectionVector();
+ Vector deselectedItems = new Vector(selectedItems.size());
+ Enumeration elements = selectedItems.elements();
+ SelectableItem item;
+
+ // deselect and repaint previously selected items
+ while (elements.hasMoreElements() == true) {
+ item = (SelectableItem) elements.nextElement();
+ if (item.isSelected() == true && item != keepSelected) {
+ item.setSelected(false);
+ // always redraw the selection, even if item is redrawn again
+ // in setLastSelection. Fixes 1G0GQ8W
+ redrawSelection(item);
+ deselectedItems.addElement(item);
+ }
+ }
+ elements = deselectedItems.elements();
+ while (elements.hasMoreElements() == true) {
+ item = (SelectableItem) elements.nextElement();
+ selectedItems.removeElement(item);
+ }
+ setLastSelection(keepSelected, false);
+}
+/**
+ * Deselect all items except those in 'keepSelected'.
+ * @param keepSelected - items that should remain selected
+ */
+void deselectAllExcept(Vector keepSelected) {
+ Vector selectedItems = getSelectionVector();
+ Vector deselectedItems = new Vector(selectedItems.size());
+ Enumeration elements = selectedItems.elements();
+ SelectableItem item;
+
+ // deselect and repaint previously selected items
+ while (elements.hasMoreElements() == true) {
+ item = (SelectableItem) elements.nextElement();
+ if (item.isSelected() == true && keepSelected.contains(item) == false) {
+ item.setSelected(false);
+ // always redraw the selection, even if item is redrawn again
+ // in setLastSelection. Fixes 1G0GQ8W
+ redrawSelection(item);
+ deselectedItems.addElement(item);
+ }
+ }
+ elements = deselectedItems.elements();
+ while (elements.hasMoreElements() == true) {
+ item = (SelectableItem) elements.nextElement();
+ selectedItems.removeElement(item);
+ }
+ if (keepSelected.size() > 0) {
+ setLastSelection((SelectableItem) keepSelected.firstElement(), false);
+ }
+}
+/**
+ * Deselect 'item'. Notify listeners.
+ * @param item - item that should be deselected
+ */
+void deselectNotify(SelectableItem item) {
+ Event event = new Event();
+
+ if (item.isSelected() == true) {
+ deselect(item);
+ setLastSelection(item, true);
+ update(); // looks better when event notification takes long to return
+ }
+ event.item = item;
+ notifyListeners(SWT.Selection, event);
+}
+/**
+ * Deselect all items starting at and including 'fromIndex'
+ * stopping at and including 'toIndex'.
+ * @param fromIndex - index relative to the first item where
+ * deselection should start. Deselecion includes 'fromIndex'.
+ * @param toIndex - index relative to the first item where
+ * deselection should stop. Deselecion includes 'toIndex'.
+ */
+void deselectRange(int fromIndex, int toIndex) {
+ if (fromIndex > toIndex) {
+ for (int i = toIndex; i <= fromIndex; i++) {
+ deselect(getVisibleItem(i));
+ }
+ }
+ else
+ if (fromIndex < toIndex) {
+ for (int i = toIndex; i >= fromIndex; i--) {
+ deselect(getVisibleItem(i));
+ }
+ }
+ setLastSelection(getVisibleItem(fromIndex), true);
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection down one item
+ * Ctrl Keep old selection, move input focus down one item
+ * Shift Extend selection by one item.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowDown(int keyMask) {
+ SelectableItem lastFocus = getLastFocus();
+ SelectableItem newFocus;
+ int focusItemIndex = getVisibleIndex(lastFocus);
+
+ if (focusItemIndex < (getVisibleItemCount() - 1)) { // - 1 because indices are 0 based
+ focusItemIndex++;
+ newFocus = getVisibleItem(focusItemIndex);
+ if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
+ shiftSelect(newFocus, focusItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Modifier Key Action
+ * None Scroll receiver to the left
+ * Ctrl See None above
+ * Shift See None above
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowLeft(int keyMask) {
+ ScrollBar horizontalBar = getHorizontalBar();
+ int scrollSelection = horizontalBar.getSelection();
+ int scrollAmount;
+
+ if (horizontalBar.getVisible() == false) {
+ return;
+ }
+ scrollAmount = Math.min(HORIZONTAL_SCROLL_INCREMENT, scrollSelection);
+ horizontalBar.setSelection(scrollSelection - scrollAmount);
+ setHorizontalOffset(horizontalBar.getSelection() * -1);
+}
+/**
+ * Modifier Key Action
+ * None Scroll receiver to the right
+ * Ctrl See None above
+ * Shift See None above
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowRight(int keyMask) {
+ ScrollBar horizontalBar = getHorizontalBar();
+ int scrollSelection = horizontalBar.getSelection();
+ int scrollAmount;
+
+ if (horizontalBar.getVisible() == false) {
+ return;
+ }
+ scrollAmount = Math.min( // scroll by the smaller of
+ HORIZONTAL_SCROLL_INCREMENT, // the scroll increment
+ horizontalBar.getMaximum() // and the remaining scroll range
+ - horizontalBar.getPageIncrement()
+ - scrollSelection);
+ horizontalBar.setSelection(scrollSelection + scrollAmount);
+ setHorizontalOffset(horizontalBar.getSelection() * -1);
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection up one item
+ * Ctrl Keep old selection, move input focus up one item
+ * Shift Extend selection by one item.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowUp(int keyMask) {
+ SelectableItem lastFocus = getLastFocus();
+ SelectableItem newFocus;
+ int focusItemIndex = getVisibleIndex(lastFocus);
+
+ if (focusItemIndex > 0) {
+ focusItemIndex--;
+ newFocus = getVisibleItem(focusItemIndex);
+ if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
+ shiftSelect(newFocus, focusItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Perform a selection operation on the item check box.
+ * @param item - the item that was clicked
+ */
+void doCheckItem(SelectableItem item) {
+ Event event = new Event();
+
+ item.setChecked(!item.getChecked());
+ event.item = item;
+ event.detail = SWT.CHECK;
+ notifyListeners(SWT.Selection, event);
+}
+/**
+ * Free resources.
+ */
+void doDispose() {
+ setRemovingAll(true);
+ getSelectionVector().removeAllElements();
+ lastFocusItem = null;
+ lastSelectedItem = null;
+ if (uncheckedImage != null) {
+ uncheckedImage.dispose();
+ }
+ if (grayUncheckedImage != null) {
+ grayUncheckedImage.dispose();
+ }
+ if (checkMarkImage != null) {
+ checkMarkImage.dispose();
+ }
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection to the
+ * last item
+ * Ctrl Keep old selection, move input focus to the
+ * last item
+ * Shift Extend selection to the last item.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doEnd(int keyMask) {
+ SelectableItem lastFocus = getLastFocus();
+ SelectableItem newFocus;
+ int focusItemIndex = getVisibleIndex(lastFocus);
+ int lastItemIndex = getVisibleItemCount() - 1; // - 1 because indices are 0 based
+
+ if (focusItemIndex < lastItemIndex) {
+ newFocus = getVisibleItem(lastItemIndex);
+ if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
+ shiftSelect(newFocus, lastItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection to the
+ * first item
+ * Ctrl Keep old selection, move input focus to the
+ * first item
+ * Shift Extend selection to the first item.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doHome(int keyMask) {
+ SelectableItem lastFocus = getLastFocus();
+ SelectableItem newFocus;
+ int firstItemIndex = 0;
+
+ if (getVisibleIndex(lastFocus) > firstItemIndex) {
+ newFocus = getVisibleItem(firstItemIndex);
+ if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
+ shiftSelect(newFocus, firstItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Perform a mouse select action according to the key state
+ * mask in 'eventStateMask'.
+ * Key state mask is ignored when receiver has the single selection
+ * style.
+ * @param item - the item that was clicked
+ * @param itemIndex - the index of the clicked item relative
+ * to the first item of the receiver
+ * @param eventStateMask - the key state mask of the mouse event
+ * @param button - the mouse button that was pressed
+ */
+void doMouseSelect(SelectableItem item, int itemIndex, int eventStateMask, int button) {
+ if (button != 1 && item.isSelected() == true) {
+ // If the item is already selected, do not change the selection when using
+ // button 2 or 3. These buttons may invoke drag and drop or open the
+ // context menu for the current selection.
+ return;
+ }
+ if (((eventStateMask & SWT.MOD1) != 0) &&
+ ((eventStateMask & SWT.MOD2) != 0) &&
+ (isMultiSelect() == true)) {
+ if (getSelectionVector().size() == 0) { // no old selection?
+ selectNotify(item); // do standard CTRL selection
+ }
+ else {
+ ctrlShiftSelect(item, itemIndex);
+ }
+ setCtrlSelection(true);
+ }
+ else
+ if (((eventStateMask & SWT.MOD2) != 0) && (isMultiSelect() == true)) {
+ shiftSelect(item, itemIndex);
+ setCtrlSelection(false);
+ }
+ else
+ if (((eventStateMask & SWT.MOD1) != 0) && (isMultiSelect() == true)) {
+ toggleSelectionNotify(item);
+ setCtrlSelection(true);
+ }
+ else
+ if ((eventStateMask & (SWT.MOD3 | SWT.MOD4)) == 0) {
+ // On MacOSX, holding the control key down while pressing button 1 brings up the context menu.
+ // Do not change the selection in this case.
+ deselectAllExcept(item);
+ selectNotify(item);
+ setCtrlSelection(false);
+ }
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection one page down
+ * Ctrl Keep old selection, move input focus one page down
+ * Shift Extend selection one page down
+ * One page is the number of items that can be displayed in the
+ * receiver's canvas without truncating the last item.
+ * The selection is set to the last item if there is no full page
+ * of items left.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doPageDown(int keyMask) {
+ SelectableItem newFocus;
+ int focusItemIndex = getVisibleIndex(getLastFocus());
+ int lastItemIndex = getVisibleItemCount() - 1; // - 1 because indices are 0 based
+ int visibleItemCount;
+
+ if (focusItemIndex < lastItemIndex) {
+ visibleItemCount = getItemCountWhole();
+ focusItemIndex = Math.min(
+ lastItemIndex,
+ focusItemIndex + (visibleItemCount - 1));
+ newFocus = getVisibleItem(focusItemIndex);
+ if (newFocus == null) {
+ return;
+ }
+ if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
+ shiftSelect(newFocus, focusItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Modifier Key Action
+ * None Remove old selection, move selection one page up
+ * Ctrl Keep old selection, move input focus one page up
+ * Shift Extend selection one page up
+ * One page is the number of items that can be displayed in the
+ * receiver's canvas without truncating the last item.
+ * The selection is set to the first item if there is no full page
+ * of items left.
+ * Modifier Key is ignored when receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+void doPageUp(int keyMask) {
+ SelectableItem newFocus;
+ int focusItemIndex = getVisibleIndex(getLastFocus());
+ int visibleItemCount;
+
+ if (focusItemIndex > 0) {
+ visibleItemCount = getItemCountWhole();
+ focusItemIndex = Math.max(
+ 0,
+ focusItemIndex - (visibleItemCount - 1));
+ newFocus = getVisibleItem(focusItemIndex);
+ if (keyMask == SWT.MOD1 && isMultiSelect() == true) {
+ setLastFocus(newFocus, true);
+ }
+ else
+ if (keyMask == SWT.MOD2 && isMultiSelect() == true) {
+ shiftSelect(newFocus, focusItemIndex);
+ }
+ else {
+ deselectAllExcept(newFocus);
+ selectNotify(newFocus);
+ }
+ }
+}
+/**
+ * Modifier Key Action
+ * Ctrl Keep old selection, toggle selection of the item
+ * that has the input focus
+ * Shift Extend selection to the item that has the input
+ * focus
+ * Ctrl & Shift Set selection to the item that has input focus
+ * Do nothing if receiver has single selection style.
+ * @param keyMask - the modifier key that was pressed
+ */
+
+void doSpace(int keyMask) {
+ SelectableItem item = getLastFocus();
+ if (item == null) return;
+ if (item.isCheckable() == true) doCheckItem(item);
+ int itemIndex = getVisibleIndex(item);
+
+ if (keyMask == SWT.NULL && item.isSelected() == false) { // do simple space select in SINGLE and MULTI mode
+ deselectAllExcept(item);
+ selectNotify(item);
+ return;
+ }
+ if (isMultiSelect() == false) {
+ return;
+ }
+ if (keyMask == SWT.MOD1) {
+ toggleSelectionNotify(item);
+ }
+ else
+ if (((keyMask & SWT.MOD1) != 0) && ((keyMask & SWT.MOD2) != 0)) {
+ deselectAllExcept(item);
+ selectNotify(item);
+ }
+ else
+ if (keyMask == SWT.MOD2) {
+ shiftSelect(item, itemIndex);
+ }
+}
+/**
+ * Make sure that free space at the bottom of the receiver is
+ * occupied.
+ * There will be new space available below the last item when the
+ * receiver's height is increased. In this case the receiver
+ * is scrolled down to occupy the new space.if the top item is
+ * not the first item of the receiver.
+ */
+void claimBottomFreeSpace() {
+ int clientAreaItemCount = getItemCountWhole();
+ int topIndex = getTopIndex();
+ int newTopIndex;
+ int lastItemIndex = getVisibleItemCount() - topIndex;
+
+ if ((topIndex > 0) &&
+ (lastItemIndex > 0) &&
+ (lastItemIndex < clientAreaItemCount)) {
+ newTopIndex = Math.max(0, topIndex-(clientAreaItemCount-lastItemIndex));
+ setTopIndex(newTopIndex, true);
+ }
+}
+/**
+ * Make sure that free space at the right side of the receiver is
+ * occupied.
+ * There will be new space available at the right side of the receiver
+ * when the receiver's width is increased. In this case the receiver
+ * is scrolled to the right to occupy the new space.if possible.
+ */
+void claimRightFreeSpace() {
+ int clientAreaWidth = getClientArea().width;
+ int newHorizontalOffset = clientAreaWidth - getContentWidth();
+
+ if (newHorizontalOffset - getHorizontalOffset() > 0) { // item is no longer drawn past the right border of the client area
+ newHorizontalOffset = Math.min(0, newHorizontalOffset); // align the right end of the item with the right border of the
+ setHorizontalOffset(newHorizontalOffset); // client area (window is scrolled right)
+ }
+}
+/** Not used right now. Replace focusIn/focusOut with this method once
+ * Display.getFocusWindow returns the new focus window on FocusOut event
+ * (see 1FMITIE)
+ * The focus has moved in to or out of the receiver.
+ * Redraw the item selection to reflect the focus change.
+ * @param event - the focus change event
+ */
+void focusChange(Event event) {
+ Enumeration items = getSelectionVector().elements();
+ SelectableItem lastFocusItem = getLastFocus();
+ SelectableItem item;
+
+ while (items.hasMoreElements() == true) {
+ item = (SelectableItem) items.nextElement();
+ redrawSelection(item);
+ }
+ if (lastFocusItem != null) {
+ redrawSelection(lastFocusItem);
+ }
+}
+/**
+ * The focus has moved in to or out of the receiver.
+ * Redraw the item selection to reflect the focus change.
+ * @param event - the focus change event
+ */
+void focusIn(Event event) {
+ Enumeration items = getSelectionVector().elements();
+ SelectableItem lastFocusItem = getLastFocus();
+ SelectableItem item;
+
+ // Workaround for 1FMITIE
+ hasFocus = true;
+ while (items.hasMoreElements() == true) {
+ item = (SelectableItem) items.nextElement();
+ redrawSelection(item);
+ }
+ if (lastFocusItem != null) {
+ redrawSelection(lastFocusItem);
+ }
+ // Fix blank item on slow machines/VMs. Also fixes 1G0IFMZ.
+ update();
+}
+/**
+ * The focus has moved in to or out of the receiver.
+ * Redraw the item selection to reflect the focus change.
+ * @param event - the focus change event
+ */
+void focusOut(Event event) {
+ Enumeration items = getSelectionVector().elements();
+ SelectableItem lastFocusItem = getLastFocus();
+ SelectableItem item;
+
+ // Workaround for 1FMITIE
+ hasFocus = false;
+ while (items.hasMoreElements() == true) {
+ item = (SelectableItem) items.nextElement();
+ redrawSelection(item);
+ }
+ if (lastFocusItem != null) {
+ redrawSelection(lastFocusItem);
+ }
+ // Fix blank item on slow machines/VMs. Also fixes 1G0IFMZ.
+ update();
+}
+/**
+ * Answer the index of the last item position in the receiver's
+ * client area.
+ * @return 0-based index of the last item position in the tree's
+ * client area.
+ */
+int getBottomIndex() {
+ return getTopIndex() + getItemCountTruncated(getClientArea());
+}
+/**
+ * Answer the size of the check box image.
+ * The calculation is cached and assumes that the images for
+ * the checked and unchecked state are the same size.
+ */
+Point getCheckBoxExtent() {
+ Image checkedImage;
+ Rectangle imageBounds;
+
+ if (checkBoxExtent == null) {
+ checkedImage = getUncheckedImage();
+ if (checkedImage != null) {
+ imageBounds = checkedImage.getBounds();
+ checkBoxExtent = new Point(imageBounds.width, imageBounds.height);
+ }
+ else {
+ checkBoxExtent = new Point(0, 0);
+ }
+ }
+ return checkBoxExtent;
+}
+/**
+ * Answer the image for the selected check box
+ * Answer null if the image couldn't be loaded.
+ */
+Image getCheckMarkImage() {
+
+ if (checkMarkImage == null) {
+ checkMarkImage = new Image(getDisplay(), CheckMarkImageData);
+ }
+ return checkMarkImage;
+}
+/**
+ * Answer the width of the receiver's content.
+ * Needs to be set by subclasses.
+ */
+int getContentWidth() {
+ return contentWidth;
+}
+/**
+ * Answer the horizontal drawing offset used for scrolling.
+ * This is < 0 if the receiver has been scrolled to the left,
+ * > 0 if the receiver has been scrolled to the right and 0
+ * if the receiver has not been scrolled.
+ */
+int getHorizontalOffset() {
+ return horizontalOffset;
+}
+
+/**
+ * Answer the size of item images. Calculated during the item
+ * height calculation.
+ */
+Point getImageExtent() {
+ return itemImageExtent;
+}
+/**
+ * Answer the image extent of 'item'. Overridden by subclasses.
+ */
+Point getImageExtent(SelectableItem item) {
+ Image image = item.getImage();
+ Rectangle imageBounds;
+ Point imageExtent = null;
+
+ if (image != null) {
+ imageBounds = image.getBounds();
+ imageExtent = new Point(imageBounds.width, imageBounds.height);
+ }
+ return imageExtent;
+}
+/**
+ * Answer the index of 'item' in the receiver.
+ */
+abstract int getIndex(SelectableItem item);
+/**
+ * Answer the first and last index of items that can be displayed in
+ * the area defined by 'clipRectangle'. This includes partial items.
+ * @return
+ * Array -
+ * First element is the index of the first item in 'clipRectangle'.
+ * Second element is the index of the last item in 'clipRectangle'.
+ */
+int[] getIndexRange(Rectangle clipRectangle) {
+ int visibleRange[] = new int[] {0, 0};
+
+ visibleRange[0] = clipRectangle.y / getItemHeight();
+ visibleRange[1] =
+ visibleRange[0] +
+ getItemCountTruncated(clipRectangle) - 1; // - 1 because item index is 0 based
+ return visibleRange;
+}
+/**
+ * Return the item that draws the marker indicating the insert location
+ * in a drag and drop operation
+ */
+SelectableItem getInsertItem() {
+ return insertItem;
+}
+/**
+ * Answer the number of items in the receiver.
+ */
+public abstract int getItemCount();
+/**
+ * Answer the number of items that can be displayed in 'rectangle'.
+ * The result includes partially visible items.
+ */
+int getItemCountTruncated(Rectangle rectangle) {
+ int itemHeight = getItemHeight();
+ int itemCount = 0;
+ int startIndex;
+
+ startIndex = rectangle.y / itemHeight;
+ itemCount = Compatibility.ceil(rectangle.y + rectangle.height, itemHeight)-startIndex;
+ return itemCount;
+}
+/**
+ * Answer the number of items that can be displayed in the client
+ * area of the receiver.
+ * The result only includes items that completely fit into the
+ * client area.
+ */
+int getItemCountWhole() {
+ return getClientArea().height / getItemHeight();
+}
+/**
+ * Answer the height of an item in the receiver.
+ * The item height is the greater of the item icon height and
+ * text height of the first item that has text or an image
+ * respectively.
+ * Calculate a default item height based on the font height if
+ * no item height has been calculated yet.
+ */
+public int getItemHeight() {
+ checkWidget();
+ GC gc;
+ if (itemHeight == 0) {
+ gc = new GC(this);
+ itemHeight = gc.stringExtent("String").y + getItemPadding(); // initial item height=font height + item spacing
+ // use real font height here when available in SWT, instead of GC.textExtent
+ gc.dispose();
+ }
+ return itemHeight;
+}
+/**
+ * Answer the number of pixels that should be added to the item height.
+ */
+int getItemPadding() {
+ return 2 + getDisplay().textHighlightThickness;
+}
+/**
+ * Answer the item that most recently received the input focus.
+ */
+SelectableItem getLastFocus() {
+ return lastFocusItem;
+}
+/**
+ * Answer the item that was selected most recently.
+ */
+SelectableItem getLastSelection() {
+ return lastSelectedItem;
+}
+/**
+ * Answer the event listener used for all events. Events are
+ * dispatched to handler methods in handleEvents(Event).
+ * This scheme saves a lot of inner classes.
+ */
+Listener getListener() {
+ return listener;
+}
+/**
+ * Answer the y coordinate at which 'item' is drawn.
+ * @param item - SelectableItem for which the paint position
+ * should be returned
+ * @return the y coordinate at which 'item' is drawn.
+ * Return -1 if 'item' is not an item of the receiver
+ */
+int getRedrawY(SelectableItem item) {
+ int redrawIndex = getVisibleIndex(item);
+ int redrawY = -1;
+
+ if (redrawIndex != -1) {
+ redrawY = (redrawIndex - getTopIndex()) * getItemHeight();
+ }
+ return redrawY;
+}
+/**
+ * Answer the number of selected items in the receiver.
+ */
+public int getSelectionCount() {
+ checkWidget();
+ return getSelectionVector().size();
+}
+/**
+ * Answer the selected items of the receiver.
+ * @return The selected items of the receiver stored in a Vector.
+ * Returned Vector is empty if no items are selected.
+ */
+Vector getSelectionVector() {
+ return selectedItems;
+}
+/**
+ * Answer the width of 'text' in pixel.
+ * Answer 0 if 'text' is null.
+ */
+int getTextWidth(String text) {
+ int textWidth = 0;
+ GC gc;
+
+ if (text != null) {
+ gc = new GC(this);
+ textWidth = gc.stringExtent(text).x;
+ gc.dispose();
+ }
+ return textWidth;
+}
+/**
+ * Answer the index of the first visible item in the receiver's
+ * client area.
+ * @return 0-based index of the first visible item in the
+ * receiver's client area.
+ */
+int getTopIndex() {
+ return topIndex;
+}
+/**
+ * Answer the image for the deselected check box.
+ */
+Image getUncheckedImage() {
+
+ if (uncheckedImage == null) {
+ uncheckedImage = new Image(getDisplay(), UncheckedImageData);
+ }
+ return uncheckedImage;
+}
+
+/**
+ * Answer the image for the grayed eck box.
+ */
+Image getGrayUncheckedImage() {
+
+ if (grayUncheckedImage == null) {
+ grayUncheckedImage = new Image(getDisplay(), GrayUncheckedImageData);
+ }
+ return grayUncheckedImage;
+}
+
+/**
+ * Answer the index of 'item' in the receiver.
+ * Answer -1 if the item is not visible.
+ * The returned index must refer to a visible item.
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. It only means that the item
+ * would be displayed if it is located inside the receiver's
+ * client area.
+ * Normally, every item of the receiver is visible.
+ */
+abstract int getVisibleIndex(SelectableItem item);
+/**
+ * Answer the SelectableItem located at 'itemIndex' in the
+ * receiver.
+ * @param itemIndex - location of the SelectableItem object
+ * to return
+ */
+abstract SelectableItem getVisibleItem(int itemIndex);
+/**
+ * Answer the number of visible items of the receiver.
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. It only means that the item
+ * would be displayed if it is located inside the receiver's
+ * client area.
+ * Normally every item of the receiver is visible.
+ */
+int getVisibleItemCount() {
+ return getItemCount();
+}
+/**
+ * Answer the y coordinate at which 'item' is drawn.
+ * @param item - SelectableItem for which the paint position
+ * should be returned
+ * @return the y coordinate at which 'item' is drawn.
+ * Return -1 if 'item' is null or outside the client area
+ */
+abstract int getVisibleRedrawY(SelectableItem item);
+/**
+ * Handle the events the receiver is listening to.
+ */
+void handleEvents(Event event) {
+ switch (event.type) {
+ case SWT.Dispose:
+ doDispose();
+ break;
+ case SWT.KeyDown:
+ keyDown(event);
+ break;
+ case SWT.Resize:
+ resize(event);
+ break;
+ case SWT.Selection:
+ if (event.widget == getVerticalBar()) {
+ scrollVertical(event);
+ }
+ else
+ if (event.widget == getHorizontalBar()) {
+ scrollHorizontal(event);
+ }
+ break;
+ case SWT.FocusOut:
+ focusOut(event);
+ break;
+ case SWT.FocusIn:
+ focusIn(event);
+ 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:
+ event.doit = true;
+ break;
+ }
+ break;
+ }
+}
+
+
+
+/**
+ * Answer whether 'item' has the input focus.
+ */
+boolean hasFocus(SelectableItem item) {
+ return (isFocusControl() && item == getLastFocus());
+}
+/**
+ * Initialize the receiver. Add event listeners and set widget
+ * colors.
+ */
+void initialize() {
+ Display display = getDisplay();
+ ScrollBar horizontalBar = getHorizontalBar();
+ ScrollBar verticalBar = getVerticalBar();
+
+ // listener may be needed by overridden installListeners()
+ listener = new Listener() {
+ public void handleEvent(Event event) {handleEvents(event);}
+ };
+ setSelectionVector(new Vector());
+ installListeners();
+ calculateVerticalScrollbar();
+ calculateHorizontalScrollbar();
+ horizontalBar.setMinimum(0);
+ verticalBar.setMinimum(0);
+ horizontalBar.setIncrement(HORIZONTAL_SCROLL_INCREMENT);
+ setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
+ setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+}
+/**
+ * Initialize the ImageData used for the checked/unchecked images.
+ */
+static void initializeImageData() {
+ PaletteData uncheckedPalette = new PaletteData(
+ new RGB[] {new RGB(128, 128, 128), new RGB(255, 255, 255)});
+ PaletteData grayUncheckedPalette = new PaletteData(
+ new RGB[] {new RGB(128, 128, 128), new RGB(192, 192, 192)});
+ 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};
+
+ // Each pixel is represented by one bit in the byte data.
+ // The bit references the palette position (0 or 1). Each pixel row of an image is padded to one byte.
+ // Arguments: width, height, depth, palette, scanline padding, data
+ UncheckedImageData = new ImageData(11, 11, 1, uncheckedPalette, 2, checkbox);
+ GrayUncheckedImageData = new ImageData(11, 11, 1, grayUncheckedPalette, 2, checkbox);
+ CheckMarkImageData = new ImageData(7, 7, 1, checkMarkPalette, 1, new byte[] {-4, -8, 112, 34, 6, -114, -34});
+ CheckMarkImageData.transparentPixel = 1;
+}
+/**
+ * Add event listeners to the tree widget and its scroll bars.
+ */
+void installListeners() {
+ Listener listener = getListener();
+
+ addListener(SWT.Dispose, listener);
+ addListener(SWT.Resize, listener);
+ addListener(SWT.KeyDown, listener);
+ addListener(SWT.FocusOut, listener);
+ addListener(SWT.FocusIn, listener);
+ addListener(SWT.Traverse, listener);
+
+ getVerticalBar().addListener(SWT.Selection, listener);
+ getHorizontalBar().addListener(SWT.Selection, listener);
+}
+/**
+ * Answer whether the currently selected items were selected
+ * using the ctrl key.
+ */
+boolean isCtrlSelection() {
+ return isCtrlSelection;
+}
+/**
+ * Answer true if all items in the widget are disposed.
+ * Used to optimize item disposal. Prevents unnecessary screen
+ * updates.
+ */
+boolean isRemovingAll() {
+ return isRemovingAll;
+}
+/**
+ * Answer whether the receiver has the input focus.
+ * Workaround for 1FMITIE
+ */
+public boolean isFocusControl() {
+ return hasFocus;
+}
+/**
+ * Return whether the drop insert position is before or after the
+ * item set using motif_setInsertMark.
+ * @return
+ * true=insert position is after the insert item
+ * false=insert position is before the insert item
+ */
+boolean isInsertAfter() {
+ return isInsertAfter;
+}
+/**
+ * Answer whether the receiver has the MULTI selection style set.
+ * @return
+ * true = receiver is in multiple selection mode.
+ * false = receiver is in single selection mode.
+ */
+boolean isMultiSelect() {
+ return ((getStyle() & SWT.MULTI) != 0);
+}
+/**
+ * The item identified by 'changedItem' has changed.
+ * Calculate the item height based on the new item data (it might
+ * now have an image which could also be the first image in the
+ * receiver)
+ * Redraw the whole window if the item height has changed. Otherwise
+ * redraw only the changed item or part of it depending on the
+ * 'repaintStartX' and 'repaintWidth' parameters.
+ * @param changedItem - the item that has changed
+ * @param repaintStartX - x position of the item redraw.
+ * @param repaintWidth - width of the item redraw.
+ */
+void itemChanged(SelectableItem changedItem, int repaintStartX, int repaintWidth) {
+ int yPosition;
+ int itemHeight;
+ int oldItemHeight = getItemHeight();
+ Point oldImageExtent = getImageExtent();
+
+ calculateItemHeight(changedItem); // make sure that the item height is recalculated
+ // no redraw necessary if redraw width is 0 or item is not visible
+ if (repaintWidth == 0 || (yPosition = getVisibleRedrawY(changedItem)) == -1) {
+ return;
+ } // if changedItem is the first item with image.
+ itemHeight = getItemHeight();
+ if ((oldItemHeight == itemHeight) && // only redraw changed item if the item height and
+ (oldImageExtent == getImageExtent())) { // image size has not changed. The latter will only change once,
+ // from null to a value-so it's safe to test using !=
+ // redrawing outside the client area redraws the widget border on Motif.
+ // adjust the redraw width if necessary. Workaround for 1G4TQRW
+ repaintWidth = Math.min(repaintWidth, getClientArea().width - repaintStartX);
+ if (repaintWidth > 0) {
+ redraw(repaintStartX, yPosition, repaintWidth, itemHeight, true);
+ }
+ }
+ else {
+ redraw(); // redraw all items if the item height has changed
+ }
+}
+/**
+ * A key was pressed. Call the appropriate handler method.
+ * @param event - the key event
+ */
+void keyDown(Event event) {
+ boolean isCtrlSelection = isCtrlSelection();
+
+ if (event.stateMask != SWT.MOD1) {
+ isCtrlSelection = false;
+ }
+ switch (event.keyCode) {
+ case SWT.ARROW_UP:
+ doArrowUp(event.stateMask);
+ break;
+ case SWT.ARROW_DOWN:
+ doArrowDown(event.stateMask);
+ break;
+ case SWT.ARROW_LEFT:
+ doArrowLeft(event.stateMask);
+ break;
+ case SWT.ARROW_RIGHT:
+ doArrowRight(event.stateMask);
+ break;
+ case SWT.PAGE_UP:
+ doPageUp(event.stateMask);
+ break;
+ case SWT.PAGE_DOWN:
+ doPageDown(event.stateMask);
+ break;
+ case SWT.HOME:
+ doHome(event.stateMask);
+ break;
+ case SWT.END:
+ doEnd(event.stateMask);
+ break;
+ default: // no selection occurred, keep previous
+ isCtrlSelection = isCtrlSelection(); // selection type information
+ }
+ if (event.character == ' ') {
+ doSpace(event.stateMask);
+ isCtrlSelection = (event.stateMask == SWT.MOD1);
+ }
+ //forward the enter key pressed to defaultSelection listenters
+ if(event.character == SWT.CR){
+ Event forwardEvent = new Event();
+ forwardEvent.item = getLastFocus();
+ notifyListeners(SWT.DefaultSelection, forwardEvent);
+ }
+ setCtrlSelection(isCtrlSelection);
+}
+/**
+ * Sets the drop insert item.
+ * The drop insert item has a visual hint to show where a dragged item
+ * will be inserted when dropped on the tree.
+ * <p>
+ * @param item the insert item
+ * @param after true places the insert mark below 'item'. false places
+ * the insert mark above 'item'.
+ */
+void motif_setInsertMark(SelectableItem item, boolean after) {
+ SelectableItem currentItem = getInsertItem();
+ int redrawY;
+
+ setInsertItem(item);
+ setInsertAfter(after);
+ if (currentItem != null) {
+ redrawY = getVisibleRedrawY(currentItem);
+ if (redrawY != -1) {
+ currentItem.redrawInsertMark(redrawY);
+ }
+ }
+ if (item != null) {
+ redrawY = getVisibleRedrawY(item);
+ if (redrawY != -1) {
+ item.redrawInsertMark(redrawY);
+ }
+ }
+}
+
+
+/**
+ * Overridden to implement setRedraw(). Redraw is ignored if setRedraw was
+ * set to false.
+ */
+public void redraw () {
+ checkWidget();
+ if (drawCount == 0) {
+ super.redraw();
+ }
+}
+/**
+ * Overridden to implement setRedraw(). Redraw is ignored if setRedraw was
+ * set to false.
+ */
+public void redraw (int x, int y, int width, int height, boolean all) {
+ checkWidget();
+ if (drawCount == 0) {
+ super.redraw(x, y, width, height, all);
+ }
+}
+
+/**
+ * Redraw the selection of 'item'
+ * @param item - SelectableItem that should have the selection redrawn.
+ */
+void redrawSelection(SelectableItem item) {
+ int redrawPosition = getVisibleRedrawY(item);
+ if (redrawPosition != -1) {
+ item.redrawSelection(redrawPosition);
+ }
+}
+/**
+ * 'item' has been removed from the receiver.
+ * Update the display and the scroll bars.
+ */
+void removedItem(SelectableItem item) {
+ claimBottomFreeSpace();
+ calculateVerticalScrollbar();
+ if (getItemCount() == 0) {
+ reset();
+ }
+}
+/**
+ * 'item' is about to be removed from the tree.
+ * Move the selection/input focus if 'item' is selected or has the
+ * input focus,
+ * @param item - item that is about to be removed from the tree.
+ */
+void removingItem(SelectableItem item) {
+ SelectableItem nextFocusItem = null;
+ int itemIndex = getVisibleIndex(item);
+ int itemCount = getVisibleItemCount();
+
+ // deselect item and remove from selection
+ if (item.isSelected() == true) {
+ getSelectionVector().removeElement(item);
+ }
+ if (item == getLastFocus() && itemCount > 1) {
+ // select previous item if removed item is bottom item
+ // otherwise select next item. Fixes 1GA6L85
+ if (itemIndex == itemCount - 1) {
+ nextFocusItem = getVisibleItem(itemIndex - 1);
+ }
+ else {
+ nextFocusItem = getVisibleItem(itemIndex + 1);
+ }
+ setLastFocus(nextFocusItem, true);
+ }
+ // ignore items below widget client area
+ if (itemIndex != -1 && itemIndex <= getBottomIndex()) {
+ scrollVerticalRemovedItem(itemIndex);
+ }
+}
+/**
+ * Reset state that is dependent on or calculated from the state
+ * of the receiver.
+ */
+void reset() {
+ setSelectionVector(new Vector());
+ setTopIndexNoScroll(0, true);
+ lastSelectedItem = null;
+ lastFocusItem = null;
+ resetItemData();
+}
+/**
+ * Reset state that is dependent on or calculated from the items
+ * of the receiver.
+ */
+void resetItemData() {
+ setHorizontalOffset(0);
+ setItemHeight(0);
+ itemImageExtent = null;
+ textHeight = -1;
+ claimRightFreeSpace();
+}
+/**
+ * The receiver has been resized. Update the scroll bars and
+ * make sure that new space is being occupied by items.
+ */
+void resize(Event event) {
+ int horizontalPageSize = getHorizontalBar().getPageIncrement();
+
+ resizeHorizontalScrollbar();
+ resizeVerticalScrollbar();
+ if (getClientArea().width > horizontalPageSize) { // window resized wider? - Do this check here
+ claimRightFreeSpace(); // because claimRightFreeSpace is called elsewhere.
+ }
+ claimBottomFreeSpace();
+}
+/**
+ * Display the horizontal scroll bar if items are drawn off
+ * screen. Update the page size.
+ */
+void resizeHorizontalScrollbar() {
+ ScrollBar horizontalBar = getHorizontalBar();
+ int clientAreaWidth = getClientArea().width;
+
+ if (clientAreaWidth < getContentWidth()) {
+ if (horizontalBar.getVisible() == false) {
+ horizontalBar.setVisible(true);
+ horizontalBar.setSelection(0);
+ }
+ }
+ else
+ if (horizontalBar.getVisible() == true) {
+ horizontalBar.setVisible(false);
+ }
+ horizontalBar.setThumb(clientAreaWidth);
+ horizontalBar.setPageIncrement(clientAreaWidth);
+}
+/**
+ * Display the vertical scroll bar if items are drawn off screen.
+ * Update the page size.
+ */
+void resizeVerticalScrollbar() {
+ int clientAreaItemCount = getItemCountWhole();
+ ScrollBar verticalBar = getVerticalBar();
+
+ if (clientAreaItemCount == 0) {
+ return;
+ }
+ if (clientAreaItemCount < getVisibleItemCount()) {
+ if (verticalBar.getVisible() == false) {
+ verticalBar.setVisible(true);
+ }
+ // Only set the page size to something smaller than the scroll
+ // range maximum. Otherwise the scroll selection will be reset.
+ verticalBar.setPageIncrement(clientAreaItemCount);
+ verticalBar.setThumb(clientAreaItemCount);
+ }
+ else
+ if (verticalBar.getVisible() == true) {
+ verticalBar.setVisible(false);
+ }
+}
+/**
+ * Scroll the rectangle specified by x, y, width, height to the destination
+ * position. Do nothing if redraw is set to false using setRedraw().
+ *
+ * @param destX - destination x position of the scrolled rectangle
+ * @param destY - destination y position of the scrolled rectangle
+ * @param x - x location of the upper left corner of the scroll rectangle
+ * @param y - y location of the upper left corner of the scroll rectangle
+ * @param width - width of the scroll rectangle
+ * @param height - height of the scroll rectangle
+ * @param all - not used. Used to be true=scroll children intersecting the
+ * scroll rectangle.
+ */
+void scroll(int destX, int destY, int x, int y, int width, int height, boolean all) {
+ if (drawCount == 0) {
+ update();
+ GC gc = new GC(this);
+ gc.copyArea(x, y, width, height, destX, destY);
+ gc.dispose();
+ }
+}
+/**
+ * Scroll horizontally by 'numPixel' pixel.
+ * @param numPixel - the number of pixel to scroll
+ * numPixel > 0 = scroll to left. numPixel < 0 = scroll to right
+ */
+abstract void scrollHorizontal(int numPixel);
+/**
+ * The position of the horizontal scroll bar has been modified
+ * by the user.
+ * Adjust the horizontal offset to trigger a horizontal scroll.
+ * @param event-the scroll event
+ */
+void scrollHorizontal(Event event) {
+ setHorizontalOffset(getHorizontalBar().getSelection() * -1);
+}
+void scrollShowItem(int index) {
+ int itemIndexFromTop = index - getTopIndex();
+ int clientAreaWholeItemCount = getItemCountWhole();
+ int scrollAmount = 0;
+
+ if (itemIndexFromTop >= clientAreaWholeItemCount) { // show item below visible items?
+ scrollAmount = itemIndexFromTop;
+ if (clientAreaWholeItemCount > 0) { // will be 0 if showItem is called and receiver hasn't been displayed yet
+ scrollAmount -= clientAreaWholeItemCount - 1;
+ }
+ }
+ else
+ if (itemIndexFromTop < 0) { // show item above visible items?
+ scrollAmount = itemIndexFromTop;
+ }
+ setTopIndex(getTopIndex() + scrollAmount, true);
+}
+/**
+ * Scroll vertically by 'scrollIndexCount' items.
+ * @param scrollIndexCount - the number of items to scroll.
+ * scrollIndexCount > 0 = scroll up. scrollIndexCount < 0 = scroll down
+ */
+abstract void scrollVertical(int scrollIndexCount);
+/**
+ * The position of the horizontal scroll bar has been modified
+ * by the user.
+ * Adjust the index of the top item to trigger a vertical scroll.
+ * @param event-the scroll event
+ */
+void scrollVertical(Event event) {
+ setTopIndex(getVerticalBar().getSelection(), false);
+}
+/**
+ * Scroll items down to make space for a new item added to
+ * the receiver at position 'index'.
+ * @param index - position at which space for one new item
+ * should be made. This index is relative to the first item
+ * of the receiver.
+ */
+void scrollVerticalAddingItem(int index) {
+ Rectangle clientArea = getClientArea();
+ int itemHeight = getItemHeight();
+ int sourceY = Math.max(0, (index - getTopIndex()) * itemHeight); // need to scroll in visible area
+
+ scroll(
+ 0, sourceY + itemHeight, // destination x, y
+ 0, sourceY, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Scroll the items below the item at position 'index' up
+ * so that they cover the removed item.
+ * @param index - index of the removed item
+ */
+void scrollVerticalRemovedItem(int index) {
+ Rectangle clientArea = getClientArea();
+ int itemHeight = getItemHeight();
+ int destinationY = Math.max(0, (index - getTopIndex()) * itemHeight);
+
+ scroll(
+ 0, destinationY, // destination x, y
+ 0, destinationY + itemHeight, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Select 'item' if it is not selected.
+ * @param item - item that should be selected
+ */
+void select(SelectableItem item) {
+ Vector selectedItems = getSelectionVector();
+
+ if (item != null && item.isSelected() == false && isRemovingAll() == false) {
+ item.setSelected(true);
+ redrawSelection(item);
+ selectedItems.addElement(item);
+ }
+}
+/**
+ * Select 'item' if it is not selected. Send a Selection event
+ * if the selection was changed.
+ * @param item - item that should be selected
+ * @param asyncNotify
+ * true=send the selection event asynchronously
+ * false=send the selection event immediately
+ */
+void selectNotify(final SelectableItem item, boolean asyncNotify) {
+ if (isRemovingAll() == false) {
+ if (item.isSelected() == false) {
+ select(item);
+ setLastSelection(item, true);
+ update(); // looks better when event notification takes long to return
+ }
+ if (asyncNotify == false) {
+ Event event = new Event();
+ event.item = item;
+ notifyListeners(SWT.Selection, event);
+ }
+ else {
+ getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ // Only send a selection event when the item has not been disposed.
+ // Fixes 1GE6XQA
+ if (item.isDisposed() == false) {
+ Event event = new Event();
+ event.item = item;
+ notifyListeners(SWT.Selection, event);
+ }
+ }
+ });
+ }
+ }
+}
+/**
+ * Select 'item' if it is not selected. Send a Selection event
+ * if the selection was changed.
+ * @param item - item that should be selected
+ */
+void selectNotify(SelectableItem item) {
+ selectNotify(item, false);
+}
+/**
+ * Select all items of the receiver starting at 'fromIndex'
+ * and including 'toIndex'.
+ */
+void selectRange(int fromIndex, int toIndex) {
+ if (fromIndex > toIndex) {
+ for (int i = fromIndex; i > toIndex; i--) {
+ select(getVisibleItem(i));
+ }
+ }
+ else {
+ for (int i = fromIndex; i < toIndex; i++) {
+ select(getVisibleItem(i));
+ }
+ }
+ selectNotify(getVisibleItem(toIndex)); // select last item, notifying listeners
+}
+/**
+ * Set the width of the receiver's contents to 'newWidth'.
+ * Content width is used to calculate the horizontal scrollbar.
+ */
+void setContentWidth(int newWidth) {
+ ScrollBar horizontalBar;
+ boolean scrollBarVisible;
+
+ if (contentWidth != newWidth) {
+ horizontalBar = getHorizontalBar();
+ scrollBarVisible = horizontalBar.getVisible();
+ contentWidth = newWidth;
+ calculateHorizontalScrollbar();
+ if (scrollBarVisible != horizontalBar.getVisible()) {
+ resizeVerticalScrollbar(); // the vertical scroll bar needs to be resized if the horizontal
+ } // scroll bar was hidden or made visible during recalculation
+ }
+}
+/**
+ * Set whether the currently selected items were selected using the
+ * ctrl key.
+ * @param isCtrlSelection -
+ * true = currently selected items were selected using the ctrl key.
+ * false = currently selected items were not selected using the
+ * ctrl key.
+ */
+void setCtrlSelection(boolean isCtrlSelection) {
+ this.isCtrlSelection = isCtrlSelection;
+}
+/**
+ * The font is changing. Reset the text height to force a
+ * recalculation during itemChanged().
+ */
+public void setFont(Font font) {
+ checkWidget();
+ super.setFont(font);
+ textHeight = -1;
+}
+/**
+ * Set the horizontal drawing offset to 'offset'.
+ * Scroll the receiver's contents according to the offset change.
+ * @param offset - value < 0 = widget contents is drawn left of the client area.
+ */
+void setHorizontalOffset(int offset) {
+ int offsetChange = offset - horizontalOffset;
+ if (offsetChange != 0) {
+ scrollHorizontal(offsetChange);
+ horizontalOffset = offset;
+ }
+}
+
+/**
+ * Set whether the drop insert position is before or after the
+ * item set using motif_setInsertMark.
+ * @param after true=insert position is after the insert item
+ * false=insert position is before the insert item
+ */
+void setInsertAfter(boolean after) {
+ isInsertAfter = after;
+}
+
+/**
+ * Set the item that draws the marker indicating the insert location
+ * in a drag and drop operation.
+ * @param item the item that draws the insert marker
+ */
+void setInsertItem(SelectableItem item) {
+ insertItem = item;
+}
+/**
+ * Set the height of the receiver's items to 'height'.
+ */
+void setItemHeight(int height) {
+ itemHeight = height;
+}
+/**
+ * Set the item that most recently received the input focus
+ * to 'focusItem'. Redraw both, the item that lost focus
+ * and the one that received focus.
+ * @param focusItem - the item that most recently received
+ * the input focus
+ * @param showItem true=new focus item, if any, should be scrolled
+ * into view. false=don't scroll
+ */
+void setLastFocus(SelectableItem focusItem, boolean showItem) {
+ SelectableItem oldFocusItem = lastFocusItem;
+
+ if (focusItem != lastFocusItem) {
+ lastFocusItem = focusItem;
+ if (oldFocusItem != null) {
+ redrawSelection(oldFocusItem);
+ }
+ if (lastFocusItem != null && isFocusControl() == true) {
+ redrawSelection(lastFocusItem);
+ }
+ }
+ if (focusItem != null && showItem == true) {
+ showSelectableItem(focusItem);
+ }
+}
+/**
+ * Set the item that was selected most recently to 'selectedItem'.
+ * Set the input focus to that item.
+ * @param selectedItem - the item that was selected most recently
+ * @param showItem true=new focus item, if any, should be scrolled
+ * into view. false=don't scroll
+ */
+void setLastSelection(SelectableItem selectedItem, boolean showItem) {
+ if (selectedItem == null) { // always store the item selected last
+ return;
+ }
+ setLastFocus(selectedItem, showItem);
+ lastSelectedItem = selectedItem;
+}
+/**
+ * Sets the redraw flag.
+ * @param redraw -
+ * true = redraw and scroll operations are performed normally
+ * false = redraw and scroll operations are ignored
+ */
+public void setRedraw (boolean redraw) {
+ checkWidget();
+ if (redraw) {
+ if (--drawCount == 0) redraw();
+ } else {
+ drawCount++;
+ }
+}
+/**
+ * Set whether all items in the widget are disposed.
+ * Used to optimize item disposal. Prevents unnecessary screen
+ * updates.
+ * @param removingAll
+ * true=all items are removed.
+ * false=normal state, no items or not all items are removed.
+ */
+void setRemovingAll(boolean removingAll) {
+ isRemovingAll = removingAll;
+}
+/**
+ * Select the items stored in 'selectionItems'.
+ * A SWT.Selection event is not going to be sent.
+ * @param selectionItems - Array containing the items that should
+ * be selected
+ */
+void setSelectableSelection(SelectableItem selectionItems[]) {
+ SelectableItem item = null;
+ int selectionCount = selectionItems.length;
+ Vector keepSelected;
+
+ if (isMultiSelect() == false && selectionCount > 1) {
+ selectionCount = 1;
+ }
+ keepSelected = new Vector(selectionItems.length);
+ for (int i = 0; i < selectionCount; i++) {
+ if (selectionItems[i] != null) {
+ if (selectionItems[i].isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ keepSelected.addElement(selectionItems[i]);
+ }
+ }
+ deselectAllExcept(keepSelected);
+ // select in the same order as all the other selection and deslection methods.
+ // Otherwise setLastSelection repeatedly changes the lastSelectedItem for repeated
+ // selections of the items, causing flash.
+ for (int i = selectionCount - 1; i >= 0; i--) {
+ item = selectionItems[i];
+ if (item != null) {
+ select(item);
+ }
+ }
+ if (item != null) {
+ setLastSelection(item, true);
+ }
+}
+/**
+ * Set the vector used to store the selected items of the receiver
+ * to 'newVector'.
+ * @param newVector - the vector used to store the selected items
+ * of the receiver
+ */
+void setSelectionVector(Vector newVector) {
+ selectedItems = newVector;
+}
+/**
+ * Scroll the item at 'index' to the top.
+ * @param index - 0-based index of the first visible item in the
+ * receiver's client area.
+ * @param adjustScrollbar - true=set the position of the vertical
+ * scroll bar to the new top index.
+ * false=don't adjust the vertical scroll bar
+ */
+void setTopIndex(int index, boolean adjustScrollbar) {
+ int indexDiff = index-topIndex;
+
+ if (indexDiff != 0) {
+ scrollVertical(indexDiff);
+ setTopIndexNoScroll(index, adjustScrollbar);
+ }
+}
+/**
+ * Set the index of the first visible item in the receiver's client
+ * area to 'index'.
+ * @param index - 0-based index of the first visible item in the
+ * receiver's client area.
+ * @param adjustScrollbar - true=set the position of the vertical
+ * scroll bar to the new top index.
+ * false=don't adjust the vertical scroll bar
+ */
+void setTopIndexNoScroll(int index, boolean adjustScrollbar) {
+ topIndex = index;
+ if (adjustScrollbar == true) {
+ getVerticalBar().setSelection(index);
+ }
+}
+/**
+ * The shift key was pressed when the mouse click on an item
+ * occurred. Do a shift selection. If an already selected item was
+ * clicked the selection is expanded/reduced to that item
+ * @param hitItem - specifies the clicked item
+ * @param hitItemIndex - specifies the index of the clicked item
+ * relative to the first item.
+ */
+void shiftSelect(SelectableItem hitItem, int hitItemIndex) {
+ int fromIndex = -1;
+ int toIndex = -1;
+ int lastSelectionIndex = -1;
+ int selectionRange[];
+ SelectableItem lastSelection = getLastSelection();
+
+ if (lastSelection != null) {
+ lastSelectionIndex = getVisibleIndex(lastSelection);
+ }
+ if (isCtrlSelection() == true) { // was last selection ctrl selection?
+ deselectAllExcept(lastSelection);
+ fromIndex = lastSelectionIndex; // select from last selection
+ toIndex = hitItemIndex;
+ }
+ else
+ if (getSelectionVector().contains(hitItem) == true) { // clicked an item already selected?
+ deselectRange(hitItemIndex, lastSelectionIndex); // reduce selection
+ }
+ else { // clicked outside existing selection range
+ selectionRange = calculateShiftSelectionRange(hitItemIndex);
+ fromIndex = selectionRange[0];
+ toIndex = selectionRange[1];
+ }
+ if (hitItemIndex == lastSelectionIndex) { // was click on last selected item?
+ return;
+ }
+ if (fromIndex == -1 || toIndex == -1) { // are there previously selected items?
+ toggleSelectionNotify(hitItem); // do a single select.
+ }
+ else {
+ if (((lastSelectionIndex < fromIndex) && (hitItemIndex > fromIndex)) || // does selection reverse direction?
+ ((lastSelectionIndex > fromIndex) && (hitItemIndex < fromIndex))) {
+ deselectAllExcept((SelectableItem) null); // remove old selection
+ }
+ selectRange(fromIndex, toIndex);
+ }
+}
+/**
+ * Make 'item' visible by scrolling it into the receiver's client
+ * area if necessary.
+ * @param item - the item that should be made visible to the user.
+ */
+void showSelectableItem(SelectableItem item) {
+ if (item.getSelectableParent() != this) {
+ return;
+ }
+ int index = getIndex (item);
+ showSelectableItem(index);
+}
+/**
+ * Make 'index' visible by scrolling it into the receiver's client
+ * area if necessary.
+ * @param index - the item index that should be made visible to the user.
+ */
+void showSelectableItem(int index) {
+ scrollShowItem(index);
+ scrollShowItem(index); // second call makes sure that the item is still visible
+ // even if the first scroll caused the horizontal scroll
+ // to be displayed and the item to be hidden again.
+}
+/**
+ * Show the selection. If there is no selection or the
+ * selection is already visible, this method does nothing.
+ * If the selection is not visible, the top index of the
+ * widget is changed such that the selection becomes visible.
+ */
+public void showSelection() {
+ checkWidget();
+ Vector selection = getSelectionVector();
+ SelectableItem selectionItem;
+
+ if (selection.size() > 0) {
+ selectionItem = (SelectableItem) selection.firstElement();
+ showSelectableItem(selectionItem);
+ }
+}
+/**
+ * Sorts the specified range in the array.
+ *
+ * @param array the SelectableItem array to be sorted
+ * @param start the start index to sort
+ * @param end the last + 1 index to sort
+ */
+void sort(SelectableItem[] array, int start, int end) {
+ int middle = (start + end) / 2;
+ if (start + 1 < middle) sort(array, start, middle);
+ if (middle + 1 < end) sort(array, middle, end);
+ if (start + 1 >= end) return; // this case can only happen when this method is called by the user
+ if (getVisibleIndex(array[middle-1]) <= getVisibleIndex(array[middle])) return;
+ if (start + 2 == end) {
+ SelectableItem temp = array[start];
+ array[start] = array[middle];
+ array[middle] = temp;
+ return;
+ }
+ int i1 = start, i2 = middle, i3 = 0;
+ SelectableItem[] merge = new SelectableItem[end - start];
+ while (i1 < middle && i2 < end) {
+ merge[i3++] = getVisibleIndex(array[i1]) <= getVisibleIndex(array[i2]) ?
+ array[i1++] : array[i2++];
+ }
+ if (i1 < middle) System.arraycopy(array, i1, merge, i3, middle - i1);
+ System.arraycopy(merge, 0, array, start, i2 - start);
+}
+/**
+ * Toggle the selection of 'item'.
+ * @param item - item that should be selected/deselected
+ */
+void toggleSelectionNotify(SelectableItem item) {
+ if (item.isSelected() == true) {
+ deselectNotify(item);
+ }
+ else {
+ selectNotify(item);
+ }
+}
+}
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
index df5871f9fe..b51dc1faaa 100644
--- 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
@@ -1,2701 +1,2701 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * Instances of this class implement a selectable user interface
- * object that displays a list of images and strings and issue
- * notificiation when selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TableItem</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</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection</dd>
- * </dl>
- * <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 SelectableItemWidget {
- private static final int COLUMN_RESIZE_OFFSET = 7; // offset from the start and end of each
- // column at which the resize cursor is displayed
- // if the mouse is in the column header
- static final String DOT_STRING = "..."; // used to indicate truncated item labels
-
- private Header tableHeader;
- private Vector items;
- private Vector columns;
- private boolean drawGridLines = false;
- private boolean firstColumnImage = false; // true if any item in the first column has an image
- private int columnResizeX; // last position of the cursor in a column resize operation
- private Cursor columnResizeCursor; // cursor displayed when a column resize is in progress.
- // Need to keep reference to the cursor in order to dispose it.
- private boolean isColumnResizeCursor = false; // set to true if the column resize cursor is active
- private TableColumn resizeColumn; // column that is currently being resized
- private TableColumn fillColumn; // column used to fill up space that is not used
- // by user defined columns
- private TableColumn defaultColumn; // Default column that is created as soon as the table is created.
- // Fix for 1FUSJY5
- private int dotsWidth; // width of the static String dots (see above)
- private int fontHeight; // font height, avoid use GC.stringExtend for each pain
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Table(Composite parent, int style) {
- // use NO_REDRAW_RESIZE to avoid flashing during widget resize redraw
- super(parent, checkStyle(style| SWT.NO_REDRAW_RESIZE));
-}
-
-/**
- * Add 'column' to the receiver.
- * @param column - new table column that should be added to
- * the receiver
- */
-void addColumn(TableColumn column) {
- int index = column.getIndex();
-
- getColumnVector().insertElementAt(column, index);
- // has the column been inserted (vs. appended)?
- if (index < getColumnCount() - 1) {
- reindexColumns(index + 1);
- }
- // is there more than one user created column?
- // There always is the data and visual of the default column
- // so we don't need to create those for the first user column
- if (getColumnCount() > 1) {
- insertColumnData(column);
- }
- else { // first user created column
- setContentWidth(0); // pretend it's ground zero for column resizings
- redraw(); // redraw the table and header. The default column
- getHeader().redraw(); // won't be drawn anymore, because there now is a user created table.
- }
- insertColumnVisual(column);
-}
-/**
- * Add 'item' to the receiver.
- * @param item - new table item that should be added to
- * the receiver
- * @param index - position the new item should be inserted at
- */
-void addItem(TableItem item, int index) {
- Vector items = getItemVector();
-
- if (index < 0 || index > getItemCount()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- addingItem(item, index);
- item.setIndex(index);
- if (index < items.size()) {
- for (int i = index; i < items.size(); i++) {
- TableItem anItem = (TableItem) items.elementAt(i);
- anItem.setIndex(anItem.getIndex() + 1);
- }
- items.insertElementAt(item, index);
- }
- else {
- items.addElement(item);
- }
- addedItem(item, index);
-}
-/**
- * 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 reciever 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);
-}
-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);
-}
-/**
- * The width of 'column' is about to change.
- * Adjust the position of all columns behind it.
- */
-void columnChange(TableColumn column, Rectangle newBounds) {
- Rectangle columnBounds = column.getBounds();
- Rectangle clientArea = getClientArea();
- int oldXPosition = columnBounds.x + columnBounds.width;
- int newXPosition = newBounds.x + newBounds.width;
- int widthChange = newBounds.width - columnBounds.width;
- int headerHeight = getHeaderHeight();
- int columnIndex = column.getIndex();
-
- if (widthChange != 0) {
- getHeader().widthChange(columnIndex, widthChange);
- if (columnIndex != TableColumn.FILL) {
- if (getLinesVisible() == true) {
- oldXPosition -= getGridLineWidth(); // include vertical grid line when scrolling resized column.
- newXPosition -= getGridLineWidth();
- }
- scroll( // physically move all following columns
- newXPosition, headerHeight, // destination x, y
- oldXPosition, headerHeight, // source x, y
- clientArea.width, clientArea.height, true);
- }
- column.internalSetBounds(newBounds);
- if (columnIndex != TableColumn.FILL) {
- resetTableItems(columnIndex);
- moveColumns(columnIndex + 1, widthChange); // logically move all following columns (set their bounds)
- setContentWidth(getContentWidth() + widthChange); // set the width of the receiver's content
- claimRightFreeSpace();
- resizeRedraw(column, columnBounds.width, newBounds.width);
- }
- }
-}
-/**
- * The mouse pointer was double clicked on the receiver.
- * Handle the event according to the position of the mouse click
- * and the modifier key that was pressed, if any.
- * @param event - the mouse event
- */
-void columnMouseDoubleClick(Event event) {
- int itemHeight = getItemHeight();
- int itemIndex;
- TableItem hitItem;
- TableColumn hitColumn = getColumnAtX (event.x);
- Event columnDblClickEvent;
- boolean isFullSelection = (getStyle () & SWT.FULL_SELECTION) != 0;
-
- if (isFocusControl () == false) {
- forceFocus ();
- }
- if (hitColumn != null) {
- itemIndex = (event.y - getHeaderHeight()) / itemHeight + getTopIndex();
- hitItem = (TableItem) getVisibleItem(itemIndex);
- if (hitItem != null &&
- (hitColumn.getIndex() == TableColumn.FIRST || isFullSelection)) {
- if (hitItem.isSelectionHit(event.x) == true) {
- columnDblClickEvent = new Event();
- columnDblClickEvent.item = hitItem;
- notifyListeners(SWT.DefaultSelection, columnDblClickEvent);
- }
- }
- }
-}
-/**
- * The mouse pointer was pressed down on the receiver.
- * Handle the event according to the position of the mouse click
- * and the modifier key that was pressed, if any.
- * @param event - the mouse event
- */
-void columnMouseDown(Event event) {
- int itemHeight = getItemHeight();
- int itemIndex;
- TableItem hitItem;
- TableColumn hitColumn = getColumnAtX (event.x);
-
- if (isFocusControl () == false) {
- forceFocus ();
- }
- if (hitColumn != null) {
- itemIndex = (event.y - getHeaderHeight()) / itemHeight + getTopIndex();
- hitItem = (TableItem) getVisibleItem(itemIndex);
- if (hitItem != null) {
- if (hitItem.isSelectionHit(event.x) == true) {
- doMouseSelect(hitItem, itemIndex, event.stateMask, event.button);
- }
- else
- if (hitItem.isCheckHit(new Point(event.x, event.y)) == true) {
- // only react to button one clicks. fixes bug 6770
- if (event.button != 1) {
- return;
- }
- doCheckItem(hitItem);
- }
- }
- }
-}
-/**
- * The mouse pointer was moved over the receiver.
- * Reset the column resize cursor if it was active.
- * @param event - the mouse event
- */
-void columnMouseMove(Event event) {
- if (isColumnResizeStarted() == false) {
- setColumnResizeCursor(false);
- }
-}
-public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- Point size = super.computeSize(wHint, hHint, changed);
- Point headerSize;
- GC gc;
- final int WidthCalculationCount = Math.min(getItemCount(), 50); // calculate item width for the first couple of items only
- TableItem item;
- Image itemImage;
- String itemText;
- int width;
- int newItemWidth = 0;
-
- if (getHeaderVisible() == true) {
- headerSize = getHeader().computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
- size.y += headerSize.y;
- }
- if (getContentWidth() == 0 && WidthCalculationCount > 0) {
- gc = new GC(this);
- for (int i = 0; i < WidthCalculationCount; i++) {
- item = getItem(i);
- if (item == null) {
- break; // no more items
- }
- itemImage = item.getImage();
- itemText = item.getText();
- width = 0;
- if (itemImage != null) {
- width += itemImage.getBounds().width;
- }
- if (itemText != null) {
- width += gc.stringExtent(itemText).x;
- }
- newItemWidth = Math.max(newItemWidth, width);
- }
- if (newItemWidth > 0) {
- size.x = newItemWidth;
- }
- gc.dispose();
- }
- return size;
-}
-/**
- * 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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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();
- SelectableItem item = null;
-
- if (indices == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- for (int i = 0; i < indices.length; i++) {
- item = getVisibleItem(indices[i]);
- if (item != null) {
- deselect(item);
- }
- }
- if (item != null) {
- setLastSelection(item, 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();
- SelectableItem item = getVisibleItem(index);
-
- if (item != null) {
- deselect(item);
- setLastSelection(item, 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();
- SelectableItem item = null;
-
- for (int i=start; i<=end; i++) {
- item = getVisibleItem(i);
- if (item != null) {
- deselect(item);
- }
- }
- if (item != null) {
- setLastSelection(item, 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();
-
- deselectAllExcept((SelectableItem) null);
-}
-/**
- * Free resources.
- */
-void doDispose() {
- Vector items = getItemVector();
-
- super.doDispose();
- for (int i = items.size() - 1; i >= 0; i--) {
- ((TableItem) items.elementAt(i)).dispose();
- }
- setItemVector(null);
- items = getColumnVector();
- while (items.size() > 0) { // TableColumn objects are removed from vector during dispose()
- ((TableColumn) items.lastElement()).dispose();
- }
- resizeColumn = null;
- fillColumn = null;
- defaultColumn = null;
- if (columnResizeCursor != null) {
- columnResizeCursor.dispose();
- }
-}
-/**
- * Draw a line tracking the current position of a column
- * resize operation.
- * @param xPosition - x coordinate to draw the line at
- */
-void drawColumnResizeLine(int xPosition) {
- GC gc = new GC(this);
- int lineHeight = getClientArea().height;
- int lineWidth = getGridLineWidth();
-
- redraw(getColumnResizeX() - lineWidth, 0, 1, lineHeight, false);
- setColumnResizeX(xPosition);
- gc.drawLine(xPosition - lineWidth, 0, xPosition - lineWidth, lineHeight);
- gc.dispose();
-}
-/**
- * Draw the grid lines for the receiver.
- * @param event - Paint event triggering the drawing operation.
- * @param drawColumns - The table columns for which the grid
- * lines should be drawn.
- */
-void drawGridLines(Event event, Enumeration drawColumns) {
- GC gc = event.gc;
- Color oldForeground = getForeground();
- Rectangle columnBounds;
- TableColumn column;
- int lineWidth = getGridLineWidth();
- int itemHeight = getItemHeight();
- int headerHeight = getHeaderHeight();
- int lineXPosition;
- int lineYPosition = headerHeight + ((event.y-headerHeight) / itemHeight) * itemHeight;
- int lineYStopPosition = event.y + event.height;
-
- gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
- // Draw the horizontal lines
- if (itemHeight > 0) {
- while (lineYPosition < lineYStopPosition) {
- gc.drawLine(
- event.x, lineYPosition + itemHeight - lineWidth,
- event.x + event.width, lineYPosition + itemHeight - lineWidth);
- lineYPosition += itemHeight;
- }
- }
- // Draw the vertical lines at the right border of each column except the fill column
- while (drawColumns.hasMoreElements() == true) {
- column = (TableColumn) drawColumns.nextElement();
- if (column.getIndex() != TableColumn.FILL) {
- columnBounds = column.getBounds();
- lineXPosition = columnBounds.x + columnBounds.width - lineWidth;
- gc.drawLine(
- lineXPosition, event.y,
- lineXPosition, event.y + event.height);
- }
- }
- gc.setForeground(oldForeground);
-}
-
-/**
- * If the receiver has input focus draw a rectangle enclosing
- * the label of 'item' to indicate the input focus.
- * The rectangle is drawn in either the first column or in all columns
- * for full row select.
- * @param item - item for which the selection state should be drawn
- * @param gc - GC to draw on.
- */
-void drawSelectionFocus(TableItem item, GC gc) {
- Point extent = item.getSelectionExtent();
- Point position = new Point(
- item.getImageStopX(TableColumn.FIRST) + getHorizontalOffset(),
- getRedrawY(item));
-
- gc.drawFocus(position.x, position.y, extent.x, extent.y);
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * 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>
- */
-public TableColumn getColumn(int index) {
- checkWidget();
- Vector columns = getColumnVector();
-
- if (columns == null) error(SWT.ERROR_CANNOT_GET_ITEM);
- if (index < 0 || index >= columns.size()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
-
- return (TableColumn) columns.elementAt(index);
-}
-/**
- * Return the column located at 'xPosition' in the widget.
- * Return null if xPosition is outside the widget.
- * @param xPosition - position of the desired column
- */
-TableColumn getColumnAtX(int xPosition) {
- Enumeration columns = internalGetColumnVector().elements();
- TableColumn column;
- TableColumn hitColumn = null;
- Rectangle bounds;
-
- while (columns.hasMoreElements() == true && hitColumn == null) {
- column = (TableColumn) columns.nextElement();
- bounds = column.getBounds();
- if ((xPosition >= bounds.x) &&
- (xPosition <= bounds.x + bounds.width)) {
- hitColumn = column;
- }
- }
- if (hitColumn == null) {
- column = getFillColumn();
- bounds = column.getBounds();
- if ((xPosition >= bounds.x) &&
- (xPosition <= bounds.x + bounds.width)) {
- hitColumn = column;
- }
- }
- return hitColumn;
-}
-/**
- * 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 is 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public int getColumnCount() {
- checkWidget();
- Vector columns = getColumnVector();
- int count = 0;
-
- if (columns != null) {
- count = columns.size();
- }
- return count;
-}
-/** Replace CURSOR_SIZEWE with real column resize cursor
- * (no standard cursor-have to load from file)
- * Answer the cursor displayed during a column resize
- * operation.
- * Lazy initialize the cursor since it may never be needed.
- */
-Cursor getColumnResizeCursor() {
- if (columnResizeCursor == null) {
- columnResizeCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZEWE);
- }
- return columnResizeCursor;
-}
-/**
- * Answer the current position of the mouse cursor during
- * a column resize operation.
- */
-int getColumnResizeX() {
- return columnResizeX;
-}
-/**
- * Returns an array of <code>TableColumn</code>s which are the
- * columns in the receiver. 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>
- */
-public TableColumn [] getColumns() {
- checkWidget();
- Vector columns = getColumnVector();
- TableColumn columnArray[] = new TableColumn[columns.size()];
-
- columns.copyInto(columnArray);
- return columnArray;
-}
-/**
- * Answer a Vector containing all columns of receiver except
- * the fill column to the right of all content columns.
- */
-Vector getColumnVector() {
- return columns;
-}
-/**
- * Return the default column that is created as soon as the table
- * is created.
- * Fix for 1FUSJY5
- */
-TableColumn getDefaultColumn() {
- return defaultColumn;
-}
-/**
- * Answer the width of the replacement String used to indicate
- * truncated items.
- * Cached to speed up calculation of truncated items.
- * @param gc - GC used to measure the width of the replacement
- * String
- */
-int getDotsWidth(GC gc) {
- return dotsWidth;
-}
-/**
- * Answer the column used to occupy any space left to the
- * right of all the user created columns.
- */
-TableColumn getFillColumn() {
- return fillColumn;
-}
-/**
- * Returns the width in pixels of a grid 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 getGridLineWidth () {
- checkWidget();
-
- return 1;
-}
-/**
- * Answer the table header widget.
- */
-Header getHeader() {
- return tableHeader;
-}
-/**
- * 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();
- Header header = getHeader();
- int height = 0;
-
- if (header.getVisible() == true) {
- height = header.getBounds().height;
- }
- return height;
-}
-/**
- * Returns <code>true</code> if the receiver's header is visible,
- * and <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's header's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean getHeaderVisible() {
- checkWidget();
-
- return getHeader().getVisible();
-}
-/**
- * Answer the image extent of 'item'. Use the image of any column.
- */
-Point getImageExtent(SelectableItem item) {
- Image image = null;
- Rectangle imageBounds;
- Point imageExtent = null;
- int columnCount = internalGetColumnCount();
-
- for (int i = 0; i < columnCount && image == null; i++) {
- image = ((TableItem) item).getImage(i);
- }
- if (image != null) {
- imageBounds = image.getBounds();
- imageExtent = new Point(imageBounds.width, imageBounds.height);
- }
- return imageExtent;
-}
-/**
- * Answer the index of 'item' in the receiver.
- */
-int getIndex(SelectableItem item) {
- int index = -1;
-
- if (item != null && item.getSelectableParent() == this) {
- index = ((TableItem) item).getIndex();
- }
- return index;
-}
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public TableItem getItem(int index) {
- checkWidget();
-
- if (!(0 <= index && index < getItemCount())) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- return (TableItem) getVisibleItem(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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 headerHeight = getHeaderHeight();
- TableColumn column = getColumnAtX(point.x);
- TableItem item = null;
-
- if (column != null && column.getIndex() != TableColumn.FILL && point.y - headerHeight > 0) {
- int itemIndex = (point.y - headerHeight) / getItemHeight() + getTopIndex();
- item = (TableItem) getVisibleItem(itemIndex);
- if (item != null) {
- Point itemSize = item.getItemExtent(column);
- if (point.x - column.getBounds().x > itemSize.x) {
- item = null;
- }
- }
- }
- 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 getItemVector().size();
-}
-/**
- * Answer the number of items that can be displayed in the
- * client area of the receiver without truncating any items.
- */
-int getItemCountWhole() {
- int clientAreaHeight = Math.max(0, getClientArea().height - getHeaderHeight());
-
- return clientAreaHeight / getItemHeight();
-}
-/**
- * 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 super.getItemHeight();
-}
-/**
- * Answer the number of pixels that should be added to the item height.
- */
-int getItemPadding() {
- return getGridLineWidth() + getDisplay().textHighlightThickness + 1;
-}
-/**
- * Returns an 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();
- Vector items = getItemVector();
- TableItem itemArray[] = new TableItem[items.size()];
-
- items.copyInto(itemArray);
- return itemArray;
-}
-/**
- * Answer all items of the receiver.
- */
-Vector getItemVector() {
- return items;
-}
-/**
- * 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 drawGridLines;
-}
-/**
- * Answer a Vector containing the columns that need repainting
- * based on the 'paintArea'.
- * @param paintArea - invalidated rectangle that needs repainting
- */
-Vector getPaintColumns(Rectangle paintArea) {
- Enumeration columns = internalGetColumnVector().elements();
- Vector paintColumns = new Vector();
- TableColumn column;
- Rectangle columnBounds;
- int paintAreaRightBorder = paintArea.x + paintArea.width;
-
- while (columns.hasMoreElements() == true) {
- column = (TableColumn) columns.nextElement();
- columnBounds = column.getBounds();
- if ((columnBounds.x + columnBounds.width >= paintArea.x) && // does the paintArea overlap the current column?
- (columnBounds.x <= paintAreaRightBorder)) {
- paintColumns.addElement(column);
- }
- }
- return paintColumns;
-}
-/**
- * Return the width of the widest item in the column identified by 'columnIndex'
- * @param columnIndex - index of the column whose preferred width should be
- * calculated
- */
-int getPreferredColumnWidth(int columnIndex) {
- Enumeration tableItems = getItemVector().elements();
- TableItem tableItem;
- int width = 0;
- int headerWidth;
-
- if (columnIndex != TableColumn.FILL) {
- while (tableItems.hasMoreElements() == true) {
- tableItem = (TableItem) tableItems.nextElement();
- width = Math.max(width, tableItem.getPreferredWidth(columnIndex));
- }
- headerWidth = getHeader().getPreferredWidth(columnIndex);
- if (width < headerWidth) {
- width = headerWidth;
- }
- }
- return width;
-}
-/**
- * Answer the position in the receiver where 'item' is drawn
- * @return the y coordinate at which 'item' is drawn.
- * Return -1 if 'item' is not an item of the receiver
- */
-int getRedrawY(SelectableItem item) {
- int redrawY = super.getRedrawY(item);
-
- if (redrawY != -1) {
- redrawY += getHeaderHeight();
- }
- return redrawY;
-}
-/**
- * Answer the column that is being resized or null if no
- * resize operation is in progress.
- */
-TableColumn getResizeColumn() {
- return resizeColumn;
-}
-/**
- * Return the positions at which the column identified by 'columnIndex'
- * must be redrawn.
- * These positions may be different for each item since each item may
- * have a different label
- * @param columnIndex - the column index
- * @param columnWidth - width of the column
- * @return the positions at which the column must be redrawn.
- * Each item in the widget client area is represented by a slot in
- * the array. The item at position 'topIndex' is the first item in
- * the array.
- */
-int [] getResizeRedrawX(int columnIndex, int columnWidth) {
- int topIndex = getTopIndex();
- int bottomIndex = getBottomIndex();
- int resizeRedrawX[];
- TableItem item;
-
- bottomIndex = Math.min(bottomIndex, getItemCount());
- resizeRedrawX = new int[bottomIndex-topIndex+1];
- for (int i = topIndex; i < bottomIndex; i++) {
- item = (TableItem) getVisibleItem(i);
- resizeRedrawX[i-topIndex] = item.getDotStartX(columnIndex, columnWidth);
- }
- return resizeRedrawX;
-}
-/**
- * Returns an array of <code>TableItem</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 TableItem [] getSelection() {
- checkWidget();
- Vector selectionVector = getSelectionVector();
- TableItem[] selectionArray = new TableItem[selectionVector.size()];
-
- selectionVector.copyInto(selectionArray);
- sort(selectionArray, 0, selectionArray.length);
- return selectionArray;
-}
-
-/**
- * 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 super.getSelectionCount();
-}
-
-int getFontHeight(){
- return fontHeight;
-}
-/**
- * Answer the size of the full row selection rectangle for 'item'.
- */
-Point getFullSelectionExtent(TableItem item) {
- TableColumn lastColumn = (TableColumn) internalGetColumnVector().lastElement();
- Point selectionExtent = null;
- Rectangle columnBounds;
- int xPosition = item.getImageStopX(TableColumn.FIRST);
- int gridLineWidth = getGridLineWidth();
-
- if (lastColumn != null) {
- columnBounds = lastColumn.getBounds();
- selectionExtent = new Point(
- columnBounds.x - getHorizontalOffset() + columnBounds.width - xPosition - gridLineWidth,
- getItemHeight());
- if (getLinesVisible() == true) {
- selectionExtent.y -= gridLineWidth;
- }
- }
- return selectionExtent;
-}
-/**
- * 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 = -1;
-
- if (getSelectionCount() > 0) {
- index = getIndex(getSelection()[0]);
- }
- return index;
-}
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. 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();
- TableItem[] items = getSelection();
- int indices[] = new int[items.length];
-
- for (int i = 0; i < items.length; i++) {
- indices[i] = getIndex(items[i]);
- }
- 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 super.getTopIndex();
-}
-/**
- * Answer the index of 'item' in the receiver.
- * Answer -1 if the item is not visible.
- * The returned index must refer to a visible item.
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. It only means that the item
- * would be displayed if it is located inside the receiver's
- * client area.
- * Every item in a table widget should be visible.
- */
-int getVisibleIndex(SelectableItem item) {
- return getIndex(item);
-}
-/**
- * Answer the SelectableItem located at 'itemIndex' in the receiver.
- * @param itemIndex - location of the SelectableItem object to return
- */
-SelectableItem getVisibleItem(int itemIndex) {
- Vector items = getItemVector();
- TableItem item = null;
-
- if ((items != null) && (itemIndex >= 0) && (itemIndex < items.size())) {
- item = (TableItem) items.elementAt(itemIndex);
- }
- return item;
-}
-/**
- * Answer the y coordinate at which 'item' is drawn.
- * @param item - SelectableItem for which the paint position
- * should be returned
- * @return the y coordinate at which 'item' is drawn.
- * Return -1 if 'item' is null or outside the client area
- */
-int getVisibleRedrawY(SelectableItem item) {
- int redrawY = -1;
- int index = getTopIndex();
- int bottomIndex = getBottomIndex();
-
- if (item == null) {
- return redrawY;
- }
- while (index < bottomIndex && item.equals(getVisibleItem(index)) == false) {
- index++;
- }
- if (index < bottomIndex) {
- redrawY = getRedrawY(item);
- }
- return redrawY;
-}
-/**
- * Handle the events the receiver is listening to.
- */
-void handleEvents(Event event) {
- switch (event.type) {
- case SWT.MouseMove:
- if (event.widget == tableHeader) {
- headerMouseMove(event);
- }
- else {
- columnMouseMove(event);
- }
- break;
- case SWT.MouseDown:
- if (event.widget == tableHeader) {
- headerMouseDown(event);
- }
- else {
- columnMouseDown(event);
- }
- break;
- case SWT.MouseDoubleClick:
- columnMouseDoubleClick(event);
- break;
- case SWT.MouseUp:
- mouseUp(event);
- break;
- case SWT.Paint:
- paint(event);
- break;
- default:
- super.handleEvents(event);
- }
-}
-/**
- * Answer true if any item in the first column has an image.
- * Answer false otherwise.
- */
-boolean hasFirstColumnImage() {
- return firstColumnImage;
-}
-/**
- * The mouse pointer was pressed down on the receiver's header
- * widget. Start a column resize operation if apropriate.
- * @param event - the mouse event that occured over the header
- * widget
- */
-void headerMouseDown(Event event) {
- TableColumn column = getColumnAtX(event.x);
-
- // only react to button one clicks. fixes bug 6770
- if (event.button != 1) {
- return;
- }
- if (isColumnResize(event) == true) {
- startColumnResize(event);
- }
- else
- if (column != null) {
- column.notifyListeners(SWT.Selection, new Event());
- }
-}
-/**
- * The mouse pointer was moved over the receiver's header widget.
- * If a column is currently being resized a vertical line indicating
- * the new position of the resized column is drawn.
- * Otherwise, if no column resize operation is in progress, the
- * column resize cursor is displayed when the mouse is near the border
- * of a column.
- */
-void headerMouseMove(Event event) {
- if (isColumnResizeStarted() == false) { // only check whether cursor is in resize
- setColumnResizeCursor(isColumnResize(event)); // area if no resize operation is in progress
- }
- else
- if (event.x >= getResizeColumn().getBounds().x) {
- drawColumnResizeLine(event.x);
- update(); // looks better if resize line is drawn immediately
- }
-}
-/**
- * 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);
- }
- return internalGetColumnVector().indexOf(column);
-}
-/**
- * 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);
- }
- return getIndex(item);
-}
-/**
- * Initialize the receiver. Create a header widget and an empty column.
- */
-void initialize() {
- columns = new Vector();
- setItemVector(new Vector());
- GC gc = new GC(this);
- Point extent = gc.stringExtent(DOT_STRING);
- dotsWidth = extent.x;
- fontHeight = extent.y;
- gc.dispose();
- tableHeader = new Header(this);
- tableHeader.setVisible(false); // SWT table header is invisible by default, too
- fillColumn = TableColumn.createFillColumn(this);
- setColumnPosition(fillColumn);
- defaultColumn = TableColumn.createDefaultColumn(this); // Create the default column. Fix for 1FUSJY5
- super.initialize();
-}
-/**
- * Insert the new column 'column' into the table data at position
- * 'index'.
- */
-void insertColumnData(TableColumn column) {
- Enumeration tableItems = getItemVector().elements();
- TableItem tableItem;
-
- while (tableItems.hasMoreElements() == true ) {
- tableItem = (TableItem) tableItems.nextElement();
- tableItem.insertColumn(column);
- }
-}
-/**
- * Insert the new column 'column'.
- * Set the position and move the following columns to the right.
- */
-void insertColumnVisual(TableColumn column) {
- Rectangle columnBounds = column.getBounds();
- Rectangle previousColumnBounds;
- int index = column.getIndex();
-
- if (index > 0) {
- previousColumnBounds = getColumn(index - 1).getBounds();
- columnBounds.x = previousColumnBounds.x + previousColumnBounds.width;
- }
- else {
- columnBounds.x = 0;
- }
- column.setBounds(columnBounds);
- setColumnPosition(column);
-}
-/**
- * Set event listeners for the receiver.
- */
-void installListeners() {
- Header tableHeader = getHeader();
- Listener listener = getListener();
-
- super.installListeners();
- tableHeader.addListener(SWT.MouseMove, listener);
- tableHeader.addListener(SWT.MouseDown, listener);
- tableHeader.addListener(SWT.MouseUp, listener);
-
- addListener(SWT.MouseMove, listener);
- addListener(SWT.MouseDown, listener);
- addListener(SWT.MouseDoubleClick, listener);
- addListener(SWT.MouseUp, listener);
- addListener(SWT.Paint, listener);
-}
-/**
- * Answer the TableColumn at 'index'.
- * If the user has not created any columns the default column is
- * returned if index is 0.
- * Fix for 1FUSJY5
- */
-TableColumn internalGetColumn(int index) {
- Vector columns = internalGetColumnVector();
-
- if (columns == null) error(SWT.ERROR_CANNOT_GET_ITEM);
- if (index < 0 || index >= columns.size()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
-
- return (TableColumn) columns.elementAt(index);
-
-}
-/**
- * Answer the number of columns in the receiver.
- * If the user has not created any columns, 1 is returned since there
- * always is a default column.
- * Fix for 1FUSJY5
- */
-int internalGetColumnCount() {
- Vector columns = internalGetColumnVector();
- int count = 0;
-
- if (columns != null) {
- count = columns.size();
- }
- return count;
-}
-/**
- * Return a Vector containing all columns of the receiver except
- * the fill column to the right of all content columns.
- * Return a Vector containing the default column if the user has
- * not created any columns.
- * Fix for 1FUSJY5
- */
-Vector internalGetColumnVector() {
- Vector internalColumnVector;
- TableColumn defaultColumn;
-
- if (columns.isEmpty() == false) {
- internalColumnVector = columns;
- }
- else {
- internalColumnVector = new Vector(1);
- defaultColumn = getDefaultColumn();
- if (defaultColumn != null) {
- internalColumnVector.addElement(defaultColumn);
- }
- }
- return internalColumnVector;
-}
-/**
- * Answer whether the mouse pointer is at a position that can
- * start a column resize operation. A column resize can be
- * started if the mouse pointer is at either the left or right
- * border of a column.
- * @param event - mouse event specifying the location of the
- * mouse pointer.
- */
-boolean isColumnResize(Event event) {
- TableColumn hotColumn = getColumnAtX(event.x);
- if (hotColumn == null) return false;
- Rectangle bounds = hotColumn.getBounds();
- int hotColumnIndex = hotColumn.getIndex();
- int columnX = event.x - bounds.x;
- boolean isColumnResize = false;
-
- if (columnX <= COLUMN_RESIZE_OFFSET && // mouse over left side of column? and
- hotColumnIndex != TableColumn.FIRST) { // it's not the first column)
- if (hotColumnIndex == TableColumn.FILL) {
- hotColumn = (TableColumn) internalGetColumnVector().lastElement();
- }
- else {
- hotColumn = internalGetColumn(hotColumnIndex - 1);
- }
- isColumnResize = hotColumn.getResizable(); // check whether left column can be resized
- }
- else
- if (columnX >= bounds.width - COLUMN_RESIZE_OFFSET && // mouse over right side of column and
- hotColumn != getFillColumn()) { // column is a real one (not the right hand fill column)?
- isColumnResize = hotColumn.getResizable(); // check whether column under cursor can be resized
- }
- return isColumnResize;
-}
-/**
- * Answer whether a column of the receiver is being resized.
- */
-boolean isColumnResizeStarted() {
- return (getResizeColumn() != 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();
- TableItem item = getItem(index);
-
- return (item != null && item.isSelected() == true);
-}
-/**
- * 'changedItem' has changed. Update the default column width.
- * @param changedItem - the item that has changed
- */
-void itemChanged(SelectableItem changedItem, int repaintStartX, int repaintWidth) {
- // call super.itemChanged first to make sure that table image size is
- // calculated if necessary. Fixes 1FYPBBG.
- super.itemChanged(changedItem, repaintStartX, repaintWidth);
- // remember if any item ever had an image in the first column.
- if (firstColumnImage == false && changedItem.getImage() != null) {
- firstColumnImage = true;
- redraw ();
- }
- setFirstColumnWidth((TableItem) changedItem);
-}
-/**
- * A mouse button was released.
- * Update the display if a column has been resized.
- * @param event - the mouse event for the button up action
- */
-void mouseUp(Event event) {
- TableColumn resizeColumn = getResizeColumn();
- Rectangle oldColumnBounds;
- int resizeXPosition;
- int widthChange;
- if (isColumnResizeStarted() == true) {
- oldColumnBounds = resizeColumn.getBounds();
- resizeXPosition = getColumnResizeX();
- widthChange = resizeXPosition - (oldColumnBounds.x + oldColumnBounds.width);
- if (widthChange >= 0) {
- redraw(resizeXPosition - getGridLineWidth(), 0, 1, getClientArea().height, false); // remove resize line
- update(); // to avoid cheese caused by scrolling the resize line
- }
- if (widthChange != 0) {
- resizeColumn.setWidth(oldColumnBounds.width + widthChange);
- }
- setResizeColumn(null);
- }
-}
-/**
- * Adjust the position of all columns starting at 'startIndex'.
- * @param startIndex - index at which the column move should begin
- * If this is the index of the fill column all columns are moved,
- * including the fill column
- * @param moveDistance - distance that the columns should be moved.
- * < 0 = columns are going to be moved left.
- * > 0 = columns are going to be moved right.
- */
-void moveColumns(int startIndex, int moveDistance) {
- Vector columns = internalGetColumnVector();
- TableColumn moveColumn;
- Rectangle columnBounds;
-
- if (startIndex == TableColumn.FILL) {
- moveColumn = getFillColumn();
- columnBounds = moveColumn.getBounds();
- columnBounds.x += moveDistance;
- moveColumn.setBounds(columnBounds);
- startIndex = 0; // continue with first data column
- }
- for (int i = startIndex; i < columns.size(); i++) {
- moveColumn = (TableColumn) columns.elementAt(i);
- columnBounds = moveColumn.getBounds();
- columnBounds.x += moveDistance;
- moveColumn.setBounds(columnBounds);
- }
-}
-/**
- * Adjust the y position of all columns including the fill column.
- */
-void moveColumnsVertical() {
- Enumeration columns = internalGetColumnVector().elements();
- TableColumn column;
-
- setColumnPosition(getFillColumn());
- while (columns.hasMoreElements() == true) {
- column = (TableColumn) columns.nextElement();
- setColumnPosition(column);
- }
-}
-/**
- * A paint event has occurred. Paint the invalidated items.
- * @param event - paint event specifying the invalidated area.
- */
-void paint(Event event) {
- int visibleRange[];
- int headerHeight = getHeaderHeight();
- Vector paintColumns = getPaintColumns(event.getBounds());
- TableItem focusItem = null;
-
- if (paintColumns.size() > 0) {
- event.y -= headerHeight;
- visibleRange = getIndexRange(event.getBounds());
- event.y += headerHeight;
- // When the top index is > 0 and the receiver is resized
- // higher so that the top index becomes 0 the invalidated
- // rectangle doesn't start below the header widget but at
- // y position 0. Subtraction of the header height (it is
- // not above the receiver but on top) causes event.y and
- // subsequently visibleRange[0] to be negative.
- // Hack to prevent visibleRange[0] from becoming negative.
- // Need to find out why the invalidated area starts at 0
- // in the first place.
- if (visibleRange[0] < 0) {
- visibleRange[0] = 0;
- }
- //
- visibleRange[1] = Math.min(visibleRange[1], getItemCount()-1-getTopIndex());
- focusItem = paintItems(event, visibleRange[0], visibleRange[1], paintColumns);
- }
- if (getLinesVisible() == true) {
- drawGridLines(event, paintColumns.elements());
- }
- if (focusItem != null) {
- // draw focus on top of drawing grid lines so that focus rectangle
- // is not obscured by grid. Fixes 1G5X20B
- drawSelectionFocus(focusItem, event.gc);
- }
-}
-
-/**
- * Paint items of the receiver starting at index 'topPaintIndex' and
- * ending at 'bottomPaintIndex'.
- * @param event - holds the GC to draw on and the clipping rectangle
- * @param topPaintIndex - index of the first item to draw
- * @param bottomPaintIndex - index of the last item to draw
- * @param paintColumns - the table columns that should be painted
- * @return the item that has focus if it was among the rendered items.
- * null if the focus item was not rendered or if no item has focus (ie.
- * because the widget does not have focus)
- */
-TableItem paintItems(Event event, int topPaintIndex, int bottomPaintIndex, Vector paintColumns) {
- Enumeration columns;
- TableColumn column;
- TableItem paintItem;
- TableItem focusItem = null;
- Point selectionExtent;
- GC gc = event.gc;
- Color selectionColor = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
- Point fullSelectionExtent;
- int paintXPosition;
- int paintYPosition;
-
- topPaintIndex += getTopIndex();
- bottomPaintIndex += getTopIndex();
- for (int i = topPaintIndex; i <= bottomPaintIndex; i++) {
- paintItem = (TableItem) getVisibleItem(i);
- paintXPosition = paintItem.getSelectionX();
- paintYPosition = getRedrawY(paintItem);
- fullSelectionExtent = getFullSelectionExtent(paintItem);
- gc.setBackground(paintItem.getBackground());
- gc.fillRectangle(paintXPosition, paintYPosition, fullSelectionExtent.x, fullSelectionExtent.y);
-
- if (paintItem.isSelected() == true) {
- selectionExtent = paintItem.getSelectionExtent();
- gc.setBackground(selectionColor);
- gc.fillRectangle(paintXPosition, paintYPosition, selectionExtent.x, selectionExtent.y);
- }
- columns = paintColumns.elements();
- while (columns.hasMoreElements() == true) {
- column = (TableColumn) columns.nextElement();
- paintSubItem(event, paintItem, column, paintYPosition);
- }
- if (hasFocus(paintItem)) {
- focusItem = paintItem;
- }
- }
- return focusItem;
-}
-
-/**
- * Paint the table item 'paintItem' in 'column' at y position
- * 'paintYPosition' of the receiver.
- * @param event - holds the GC to draw on and the clipping
- * rectangle.
- * @param paintItem - the item to draw
- * @param column - column to draw 'paintItem' in
- * @param paintYPosition - y position in the receiver to draw
- * 'paintItem' at.
- */
-void paintSubItem(Event event, TableItem paintItem, TableColumn column, int paintYPosition) {
- Rectangle columnBounds = column.getBounds();
- Point paintPosition;
- int gridLineWidth = getGridLineWidth();
- int itemDrawStopX = columnBounds.x + columnBounds.width - gridLineWidth;
- int clipX;
-
- if (event.x + event.width > itemDrawStopX) { // does the invalidated area stretch past the current column's right border?
- clipX = Math.max(columnBounds.x, event.x);
- event.gc.setClipping( // clip the drawing area
- clipX, event.y,
- Math.max(0, itemDrawStopX - clipX), event.height);
- }
- paintPosition = new Point(columnBounds.x, paintYPosition);
- paintItem.paint(event.gc, paintPosition, column);
- if (event.x + event.width > itemDrawStopX) {
- event.gc.setClipping(event.x, event.y, event.width, event.height); // restore original clip rectangle
- }
-}
-/**
- * Reindex all columns starting at 'startIndex'.
- * Reindexing is necessary when a new column has been inserted.
- */
-void reindexColumns(int startIndex) {
- Vector columns = getColumnVector();
- TableColumn column;
-
- for (int i = startIndex; i < getColumnCount(); i++) {
- column = (TableColumn) columns.elementAt(i);
- column.setIndex(i);
- }
-}
-/**
- * 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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove(int indices[]) {
- checkWidget();
- SelectableItem item;
- int [] sortedIndices;
- int last = -1;
- int sortedIndex;
-
- if (indices == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- sortedIndices = new int[indices.length];
- System.arraycopy (indices, 0, sortedIndices, 0, indices.length);
- sort(sortedIndices); // sort indices in descending order
- for (int i = 0; i < sortedIndices.length; i++) {
- sortedIndex = sortedIndices[i];
- if (sortedIndex != last) {
- item = getVisibleItem(sortedIndex);
- if (item != null) {
- item.dispose();
- }
- else {
- if (0 <= sortedIndex && sortedIndex < getItemVector().size()) {
- error(SWT.ERROR_ITEM_NOT_REMOVED);
- }
- else {
- error(SWT.ERROR_INVALID_RANGE);
- }
- }
- last = sortedIndex;
- }
- }
-}
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove(int index) {
- checkWidget();
- SelectableItem item = getVisibleItem(index);
-
- if (item != null) {
- item.dispose();
- }
- else {
- if (0 <= index && index < getItemVector().size()) {
- error(SWT.ERROR_ITEM_NOT_REMOVED);
- }
- else {
- error(SWT.ERROR_INVALID_RANGE);
- }
- }
-}
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove(int start, int end) {
- checkWidget();
- SelectableItem item;
-
- for (int i = end; i >= start; i--) {
- item = getVisibleItem(i);
- if (item != null) {
- item.dispose();
- }
- else {
- 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();
- Vector items = getItemVector();
-
- setRedraw(false);
- setRemovingAll(true);
- for (int i = items.size() - 1; i >= 0; i--) {
- ((TableItem) items.elementAt(i)).dispose();
- }
- setItemVector(new Vector());
- reset();
- calculateVerticalScrollbar();
- setRemovingAll(false);
- setRedraw(true);
-}
-/**
- * Remove 'column' from the receiver.
- */
-void removeColumn(TableColumn column) {
- int index = column.getIndex();
- int columnWidth = column.getWidth();
- int columnCount;
-
- if (isRemovingAll() == true) {
- getColumnVector().removeElementAt(index);
- }
- else {
- getColumnVector().removeElementAt(index);
- columnCount = getColumnCount();
- // Never remove the data of the last user created column.
- // SWT for Windows does the same.
- if (columnCount > 0) {
- removeColumnData(column);
- removeColumnVisual(column);
- }
- else {
- redraw();
- getHeader().redraw();
- }
- if (index < columnCount) { // is there a column after the removed one?
- reindexColumns(index);
- }
- // last user created column is about to be removed.
- if (columnCount == 0) {
- TableColumn defaultColumn = getDefaultColumn();
- defaultColumn.pack(); // make sure the default column has the right size...
- setColumnPosition(defaultColumn); // ...and is at the right position
- }
- // Fixes for 1G1L0UT
- // Reduce the content width by the width of the removed column
- setContentWidth(getContentWidth() - columnWidth);
- // claim free space
- claimRightFreeSpace();
- //
- }
-}
-/**
- * Remove the column 'column' from the table data.
- */
-void removeColumnData(TableColumn column) {
- Enumeration tableItems = getItemVector().elements();
- TableItem tableItem;
-
- while (tableItems.hasMoreElements() == true ) {
- tableItem = (TableItem) tableItems.nextElement();
- tableItem.removeColumn(column);
- }
-}
-/**
- * Remove the column 'column'.
- * Set the position of the following columns.
- */
-void removeColumnVisual(TableColumn column) {
- int columnWidth = column.getWidth();
-
- // move following columns to the left
- moveColumns(column.getIndex(), columnWidth * -1);
- redraw();
- getHeader().redraw();
-}
-/**
- * 'item' has been removed from the receiver.
- * Update the display and the scroll bars.
- */
-void removedItem(SelectableItem item) {
- int oldHeight = getItemHeight();
- super.removedItem (item);
- if (getItemCount() == 0 && drawGridLines && oldHeight != getItemHeight()) {
- redraw();
- }
-}
-/**
- * Remove 'item' from the receiver.
- * @param item - item that should be removed from the receiver
- */
-void removeItem(TableItem item) {
- if (isRemovingAll() == true) return;
-
- Vector items = getItemVector();
- int index = items.indexOf(item);
- if (index != -1) {
- removingItem(item);
- items.removeElementAt(index);
- for (int i = index; i < items.size(); i++) {
- TableItem anItem = (TableItem) items.elementAt(i);
- anItem.setIndex(anItem.getIndex() - 1);
- }
- removedItem(item);
- }
-}
-/**
- * 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);
-}
-/**
- * Reset cached data of column at 'columnIndex' for the items of the receiver.
- * @param columnIndex - index of the column for which the item data should be
- * reset.
- */
-void resetTableItems(int columnIndex) {
- Enumeration tableItems = getItemVector().elements();
- TableItem tableItem;
-
- while (tableItems.hasMoreElements() == true ) {
- tableItem = (TableItem) tableItems.nextElement();
- tableItem.reset(columnIndex);
- }
-}
-/**
- * The receiver has been resized. Resize the fill column
- * and the header widget.
- */
-void resize(Event event) {
- TableColumn fillColumn = getFillColumn();
- Rectangle fillColumnBounds;
-
- super.resize(event);
- // the x position may change in super.resize.
- // get the column bounds after calling super.resize. Fixes 1G7ALGG
- fillColumnBounds = fillColumn.getBounds();
- fillColumnBounds.width = Math.max(0, getClientArea().width - getContentWidth());
- fillColumn.setBounds(fillColumnBounds);
- resizeHeader();
-}
-/**
- * Resize the header widget to occupy the whole width of the
- * receiver.
- */
-void resizeHeader() {
- Header tableHeader = getHeader();
- Point size = tableHeader.getSize();
-
- size.x = Math.max(getContentWidth(), getClientArea().width);
- tableHeader.setSize(size);
-}
-/**
- * Redraw 'column' after its width has been changed.
- * @param column - column whose width has changed.
- * @param oldColumnWidth - column width before resize
- * @param oldColumnWidth - column width after resize
- */
-void resizeRedraw(TableColumn column, int oldColumnWidth, int newColumnWidth) {
- Rectangle columnBounds = column.getBounds();
- int columnIndex = column.getIndex();
- int oldRedrawStartX[] = getResizeRedrawX(columnIndex, oldColumnWidth);
- int newRedrawStartX[] = getResizeRedrawX(columnIndex, newColumnWidth);
- int itemHeight = getItemHeight();
- int widthChange = newColumnWidth - oldColumnWidth;
- int topIndex = getTopIndex();
-
- for (int i = 0; i < newRedrawStartX.length; i++) {
- if (newRedrawStartX[i] != oldRedrawStartX[i]) {
- if (widthChange > 0) {
- newRedrawStartX[i] = oldRedrawStartX[i];
- }
- redraw(
- columnBounds.x + newRedrawStartX[i], columnBounds.y + itemHeight * (i + topIndex),
- columnBounds.width - newRedrawStartX[i], itemHeight, false);
- }
- }
-}
-/**
- * Scroll horizontally by 'numPixel' pixel.
- * @param numPixel - the number of pixel to scroll
- * < 0 = columns are going to be moved left.
- * > 0 = columns are going to be moved right.
- */
-void scrollHorizontal(int numPixel) {
- Rectangle clientArea = getClientArea();
-
- scroll(
- numPixel, 0, // destination x, y
- 0, 0, // source x, y
- clientArea.width, clientArea.height, true);
- getHeader().scroll(
- numPixel, 0, // destination x, y
- 0, 0, // source x, y
- clientArea.width, clientArea.height, true);
- moveColumns(TableColumn.FILL, numPixel);
-}
-/**
- * Scroll vertically by 'scrollIndexCount' items.
- * @param scrollIndexCount - the number of items to scroll.
- * scrollIndexCount > 0 = scroll up. scrollIndexCount < 0 = scroll down
- */
-void scrollVertical(int scrollIndexCount) {
- int scrollAmount = scrollIndexCount * getItemHeight();
- int headerHeight = getHeaderHeight();
- int destY;
- int sourceY;
- boolean scrollUp = scrollIndexCount < 0;
- Rectangle clientArea = getClientArea();
-
- if (scrollIndexCount == 0) {
- return;
- }
- if (scrollUp == true) {
- destY = headerHeight - scrollAmount;
- sourceY = headerHeight;
- }
- else {
- destY = headerHeight;
- sourceY = destY + scrollAmount;
- }
- scroll(
- 0, destY, // destination x, y
- 0, sourceY, // source x, y
- clientArea.width, clientArea.height, true);
-}
-/**
- * Scroll items down to make space for a new item added to
- * the receiver at position 'index'.
- * @param index - position at which space for one new item
- * should be made. This index is relative to the first item
- * of the receiver.
- */
-void scrollVerticalAddingItem(int index) {
- int itemHeight = getItemHeight();
- int sourceY = getHeaderHeight();
- Rectangle clientArea = getClientArea();
-
- if (index >= getTopIndex()) {
- sourceY += (index-getTopIndex()) * itemHeight;
- }
- scroll(
- 0, sourceY + itemHeight, // destination x, y
- 0, sourceY, // source x, y
- clientArea.width, clientArea.height, true);
-}
-/**
- * Scroll the items below the item at position 'index' up
- * so that they cover the removed item.
- * @param index - index of the removed item
- */
-void scrollVerticalRemovedItem(int index) {
- int itemHeight = getItemHeight();
- int headerHeight = getHeaderHeight();
- int destY;
- Rectangle clientArea = getClientArea();
-
- destY = Math.max(headerHeight, headerHeight + (index - getTopIndex()) * itemHeight);
- scroll(
- 0, destY, // destination x, y
- 0, destY + itemHeight, // source x, y
- clientArea.width, clientArea.height, true);
-}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is not selected, it is selected. If the item at the index
- * was selected, it remains selected. Indices that are out
- * of range and duplicate 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>
- */
-public void select(int indices[]) {
- checkWidget();
- SelectableItem item = null;
- int selectionCount;
-
- if (indices == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- selectionCount = indices.length;
- if (isMultiSelect() == false && selectionCount > 1) {
- selectionCount = 1;
- deselectAllExcept(getVisibleItem(indices[0]));
- }
- for (int i = selectionCount - 1; i >= 0; --i) {
- item = getVisibleItem(indices[i]);
- if (item != null) {
- select(item);
- }
- }
- if (item != null) {
- setLastSelection(item, 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();
- SelectableItem item = getVisibleItem(index);
-
- if (isMultiSelect() == false) {
- deselectAllExcept(getVisibleItem(index));
- }
- if (item != null) {
- select(item);
- setLastSelection(item, false);
- }
-}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * If the item at the index was already selected, it remains
- * selected. The range of the indices is inclusive. Indices that are
- * out of range 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>
- */
-public void select(int start, int end) {
- checkWidget();
- SelectableItem item = null;
-
- if (isMultiSelect() == false) {
- if (start < 0 && end >= 0) {
- start = 0;
- }
- end = start;
- deselectAllExcept(getVisibleItem(end));
- }
- // select in the same order as all the other selection and deslection methods.
- // Otherwise setLastSelection repeatedly changes the lastSelectedItem for repeated
- // selections of the items, causing flash.
- for (int i = end; i >= start; i--) {
- item = getVisibleItem(i);
- if (item != null) {
- select(item);
- }
- }
- if (item != null) {
- setLastSelection(item, false);
- }
-}
-/**
- * Selects all 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 void selectAll() {
- checkWidget();
- Enumeration items = getItemVector().elements();
- TableItem item = null;
-
- if (isMultiSelect() == false) {
- return;
- }
- while (items.hasMoreElements() == true) {
- item = (TableItem) items.nextElement();
- select(item);
- }
- if (item != null) {
- setLastSelection(item, false);
- }
-}
-/**
- * Set the y position of 'column'.
- * @param column - the TableColumn that should be set to
- * a new y position.
- */
-void setColumnPosition(TableColumn column) {
- Rectangle bounds = column.getBounds();
-
- bounds.y = getHeaderHeight() - getTopIndex() * getItemHeight();
- column.setBounds(bounds);
-}
-/**
- * Change the cursor of the receiver.
- * @param isColumnResizeCursor - indicates whether the column
- * resize cursor or the regular cursor should be set.
- */
-void setColumnResizeCursor(boolean isColumnResizeCursor) {
- if (isColumnResizeCursor != this.isColumnResizeCursor) {
- this.isColumnResizeCursor = isColumnResizeCursor;
- if (isColumnResizeCursor == true) {
- setCursor(getColumnResizeCursor());
- }
- else {
- setCursor(null);
- }
- }
-}
-/**
- * Set the current position of the resized column to 'xPosition'.
- * @param xPosition - the current position of the resized column
- */
-void setColumnResizeX(int xPosition) {
- columnResizeX = xPosition;
-}
-/**
- * Set the width of the receiver's contents to 'newWidth'.
- * Content width is used to calculate the horizontal scrollbar.
- */
-void setContentWidth(int newWidth) {
- TableColumn fillColumn = getFillColumn();
- Rectangle fillColumnBounds;
- int widthDiff = newWidth - getContentWidth();
-
- super.setContentWidth(newWidth);
- if (fillColumn != null) {
- fillColumnBounds = fillColumn.getBounds();
- fillColumnBounds.x += widthDiff;
- fillColumnBounds.width = Math.max(0, getClientArea().width - newWidth);
- fillColumn.setBounds(fillColumnBounds);
- }
-}
-/**
- * Set the width of the first column to fit 'item' if it is longer than
- * the current column width.
- * Do nothing if the user has already set a width.
- */
-void setFirstColumnWidth(TableItem item) {
- int newWidth;
- TableColumn column;
-
- if (internalGetColumnCount() > 0) {
- column = internalGetColumn(TableColumn.FIRST);
- if (column.isDefaultWidth() == true) {
- newWidth = Math.max(column.getWidth(), item.getPreferredWidth(TableColumn.FIRST));
- column.setWidth(newWidth);
- column.setDefaultWidth(true); // reset to true so that we know when the user has set
- // the width instead of us setting a default width.
- }
- }
-}
-public void setFont(Font font) {
- checkWidget();
- int itemCount = getItemCount();
-
- if (font == null || font.equals(getFont()) == true) {
- return;
- }
- setRedraw(false); // disable redraw because itemChanged() triggers undesired redraw
- resetItemData();
- super.setFont(font);
-
- GC gc = new GC(this);
- Point extent = gc.stringExtent(DOT_STRING);
- dotsWidth = extent.x;
- fontHeight = extent.y;
- gc.dispose();
-
- for (int i = 0; i < itemCount; i++) {
- itemChanged(getItem(i), 0, getClientArea().width);
- }
- setRedraw(true); // re-enable redraw
- getHeader().setFont(font);
-}
-/**
- * Marks the receiver's header as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param 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 setHeaderVisible(boolean headerVisible) {
- checkWidget();
- if (headerVisible != getHeaderVisible()) {
- getHeader().setLocation(0, 0);
- getHeader().setVisible(headerVisible);
- // Windows resets scrolling so do we
- setTopIndex(0, true);
- moveColumnsVertical();
- resizeVerticalScrollbar();
- redraw();
- }
-}
-/**
- * Set the vector that stores the items of the receiver
- * to 'newVector'.
- * @param newVector - Vector to use for storing the items of
- * the receiver.
- */
-void setItemVector(Vector newVector) {
- items = newVector;
-}
-/**
- * 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 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 setLinesVisible(boolean drawGridLines) {
- checkWidget();
- if (this.drawGridLines != drawGridLines) {
- this.drawGridLines = drawGridLines;
- redraw();
- }
-}
-public void setRedraw(boolean redraw) {
- checkWidget();
- super.setRedraw(redraw);
- getHeader().setRedraw(redraw);
-}
-/**
- * Set the column that is being resized to 'column'.
- * @param column - the TableColumn that is being resized.
- * A null value indicates that no column resize operation is
- * in progress.
- */
-void setResizeColumn(TableColumn column) {
- resizeColumn = column;
-}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selected is first cleared, then the new items are selected.
- *
- * @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();
- Vector keepSelected;
-
- if (indices == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- keepSelected = new Vector(indices.length);
- for (int i = 0; i < indices.length; i++) {
- SelectableItem item = getVisibleItem(indices[i]);
- if (item != null) {
- keepSelected.addElement(item);
- }
- }
- deselectAllExcept(keepSelected);
- select(indices);
- showSelection ();
-}
-/**
- * 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 array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of 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#deselectAll()
- * @see Table#select(int)
- */
-public void setSelection(TableItem selectionItems[]) {
- checkWidget();
- if (selectionItems == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- setSelectableSelection(selectionItems);
-}
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * The current selected 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();
- deselectAllExcept(getVisibleItem(index));
- select(index);
- showSelection ();
-}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selected if first cleared, then the new items are selected.
- *
- * @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();
- Vector keepSelected = new Vector();
-
- for (int i = start; i <= end; i++) {
- SelectableItem item = getVisibleItem(i);
- if (item != null) {
- keepSelected.addElement(item);
- }
- }
- deselectAllExcept(keepSelected);
- select(start, end);
- 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 itemCount = getItemCount();
- int itemCountWhole = getItemCountWhole();
- if (index < 0 || itemCount == 0) return;
- if (index >= itemCount) index = itemCount - 1;
- if (itemCount > itemCountWhole) {
- if (index + itemCountWhole <= itemCount) {
- setTopIndex(index, true);
- } else if (index > itemCount - itemCountWhole) {
- setTopIndex(itemCount - itemCountWhole, true);
- } else {
- showSelectableItem(index);
- }
- }
-}
-/**
- * Set the index of the first visible item in the receiver's client
- * area to 'index'.
- * @param index - 0-based index of the first visible item in the
- * receiver's client area.
- * @param adjustScrollbar - true=set the position of the vertical
- * scroll bar to the new top index.
- * false=don't adjust the vertical scroll bar
- */
-void setTopIndexNoScroll(int index, boolean adjustScrollbar) {
- super.setTopIndexNoScroll(index, adjustScrollbar);
- moveColumnsVertical();
-}
-/**
- * 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);
- showSelectableItem(item);
-}
-/**
- * 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 IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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();
- super.showSelection();
-}
-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;
- }
- }
- }
- }
-}
-/**
- * Start a column resize operation.
- * @param event - the mouse event that occured over the header
- * widget
- */
-void startColumnResize(Event event) {
- Vector columns = internalGetColumnVector();
- TableColumn hitColumn = getColumnAtX(event.x);
- Rectangle hitColumnBounds;
- int hitIndex = hitColumn.getIndex();
-
- if (hitColumn == getFillColumn()) { // clicked on the fill column?
- hitColumn = (TableColumn) columns.lastElement(); // resize the last real column
- }
- else
- if ((event.x - hitColumn.getBounds().x <= COLUMN_RESIZE_OFFSET) && // check if left side of a column was clicked
- (hitIndex > 0)) {
- hitColumn = (TableColumn) columns.elementAt(hitIndex - 1); // resize the preceding column
- }
- hitColumnBounds = hitColumn.getBounds();
- setColumnResizeX(hitColumnBounds.x + hitColumnBounds.width);
- setResizeColumn(hitColumn);
-}
-/**
- * Return 'text' after it has been checked to be no longer than 'maxWidth'
- * when drawn on 'gc'.
- * If it is too long it will be truncated up to the last character.
- * @param text - the String that should be checked for length
- * @param maxWidth - maximum width of 'text'
- * @param gc - GC to use for String measurement
- */
-String trimItemText(String text, int maxWidth, GC gc) {
- int textWidth;
- int dotsWidth;
-
- if (text != null && text.length() > 1) {
- textWidth = gc.stringExtent(text).x;
- if (textWidth > maxWidth) {
- dotsWidth = getDotsWidth(gc);
- while (textWidth + dotsWidth > maxWidth && text.length() > 1) {
- text = text.substring(0, text.length() - 1); // chop off one character at the end
- textWidth = gc.stringExtent(text).x;
- }
- text = text.concat(Table.DOT_STRING);
- }
- }
- return text;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.*;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * Instances of this class implement a selectable user interface
+ * object that displays a list of images and strings and issue
+ * notificiation when selected.
+ * <p>
+ * The item children that may be added to instances of this class
+ * must be of type <code>TableItem</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</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>Selection, DefaultSelection</dd>
+ * </dl>
+ * <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 SelectableItemWidget {
+ private static final int COLUMN_RESIZE_OFFSET = 7; // offset from the start and end of each
+ // column at which the resize cursor is displayed
+ // if the mouse is in the column header
+ static final String DOT_STRING = "..."; // used to indicate truncated item labels
+
+ private Header tableHeader;
+ private Vector items;
+ private Vector columns;
+ private boolean drawGridLines = false;
+ private boolean firstColumnImage = false; // true if any item in the first column has an image
+ private int columnResizeX; // last position of the cursor in a column resize operation
+ private Cursor columnResizeCursor; // cursor displayed when a column resize is in progress.
+ // Need to keep reference to the cursor in order to dispose it.
+ private boolean isColumnResizeCursor = false; // set to true if the column resize cursor is active
+ private TableColumn resizeColumn; // column that is currently being resized
+ private TableColumn fillColumn; // column used to fill up space that is not used
+ // by user defined columns
+ private TableColumn defaultColumn; // Default column that is created as soon as the table is created.
+ // Fix for 1FUSJY5
+ private int dotsWidth; // width of the static String dots (see above)
+ private int fontHeight; // font height, avoid use GC.stringExtend for each pain
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 Widget#checkSubclass
+ * @see Widget#getStyle
+ */
+public Table(Composite parent, int style) {
+ // use NO_REDRAW_RESIZE to avoid flashing during widget resize redraw
+ super(parent, checkStyle(style| SWT.NO_REDRAW_RESIZE));
+}
+
+/**
+ * Add 'column' to the receiver.
+ * @param column - new table column that should be added to
+ * the receiver
+ */
+void addColumn(TableColumn column) {
+ int index = column.getIndex();
+
+ getColumnVector().insertElementAt(column, index);
+ // has the column been inserted (vs. appended)?
+ if (index < getColumnCount() - 1) {
+ reindexColumns(index + 1);
+ }
+ // is there more than one user created column?
+ // There always is the data and visual of the default column
+ // so we don't need to create those for the first user column
+ if (getColumnCount() > 1) {
+ insertColumnData(column);
+ }
+ else { // first user created column
+ setContentWidth(0); // pretend it's ground zero for column resizings
+ redraw(); // redraw the table and header. The default column
+ getHeader().redraw(); // won't be drawn anymore, because there now is a user created table.
+ }
+ insertColumnVisual(column);
+}
+/**
+ * Add 'item' to the receiver.
+ * @param item - new table item that should be added to
+ * the receiver
+ * @param index - position the new item should be inserted at
+ */
+void addItem(TableItem item, int index) {
+ Vector items = getItemVector();
+
+ if (index < 0 || index > getItemCount()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ addingItem(item, index);
+ item.setIndex(index);
+ if (index < items.size()) {
+ for (int i = index; i < items.size(); i++) {
+ TableItem anItem = (TableItem) items.elementAt(i);
+ anItem.setIndex(anItem.getIndex() + 1);
+ }
+ items.insertElementAt(item, index);
+ }
+ else {
+ items.addElement(item);
+ }
+ addedItem(item, index);
+}
+/**
+ * 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 reciever 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);
+}
+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);
+}
+/**
+ * The width of 'column' is about to change.
+ * Adjust the position of all columns behind it.
+ */
+void columnChange(TableColumn column, Rectangle newBounds) {
+ Rectangle columnBounds = column.getBounds();
+ Rectangle clientArea = getClientArea();
+ int oldXPosition = columnBounds.x + columnBounds.width;
+ int newXPosition = newBounds.x + newBounds.width;
+ int widthChange = newBounds.width - columnBounds.width;
+ int headerHeight = getHeaderHeight();
+ int columnIndex = column.getIndex();
+
+ if (widthChange != 0) {
+ getHeader().widthChange(columnIndex, widthChange);
+ if (columnIndex != TableColumn.FILL) {
+ if (getLinesVisible() == true) {
+ oldXPosition -= getGridLineWidth(); // include vertical grid line when scrolling resized column.
+ newXPosition -= getGridLineWidth();
+ }
+ scroll( // physically move all following columns
+ newXPosition, headerHeight, // destination x, y
+ oldXPosition, headerHeight, // source x, y
+ clientArea.width, clientArea.height, true);
+ }
+ column.internalSetBounds(newBounds);
+ if (columnIndex != TableColumn.FILL) {
+ resetTableItems(columnIndex);
+ moveColumns(columnIndex + 1, widthChange); // logically move all following columns (set their bounds)
+ setContentWidth(getContentWidth() + widthChange); // set the width of the receiver's content
+ claimRightFreeSpace();
+ resizeRedraw(column, columnBounds.width, newBounds.width);
+ }
+ }
+}
+/**
+ * The mouse pointer was double clicked on the receiver.
+ * Handle the event according to the position of the mouse click
+ * and the modifier key that was pressed, if any.
+ * @param event - the mouse event
+ */
+void columnMouseDoubleClick(Event event) {
+ int itemHeight = getItemHeight();
+ int itemIndex;
+ TableItem hitItem;
+ TableColumn hitColumn = getColumnAtX (event.x);
+ Event columnDblClickEvent;
+ boolean isFullSelection = (getStyle () & SWT.FULL_SELECTION) != 0;
+
+ if (isFocusControl () == false) {
+ forceFocus ();
+ }
+ if (hitColumn != null) {
+ itemIndex = (event.y - getHeaderHeight()) / itemHeight + getTopIndex();
+ hitItem = (TableItem) getVisibleItem(itemIndex);
+ if (hitItem != null &&
+ (hitColumn.getIndex() == TableColumn.FIRST || isFullSelection)) {
+ if (hitItem.isSelectionHit(event.x) == true) {
+ columnDblClickEvent = new Event();
+ columnDblClickEvent.item = hitItem;
+ notifyListeners(SWT.DefaultSelection, columnDblClickEvent);
+ }
+ }
+ }
+}
+/**
+ * The mouse pointer was pressed down on the receiver.
+ * Handle the event according to the position of the mouse click
+ * and the modifier key that was pressed, if any.
+ * @param event - the mouse event
+ */
+void columnMouseDown(Event event) {
+ int itemHeight = getItemHeight();
+ int itemIndex;
+ TableItem hitItem;
+ TableColumn hitColumn = getColumnAtX (event.x);
+
+ if (isFocusControl () == false) {
+ forceFocus ();
+ }
+ if (hitColumn != null) {
+ itemIndex = (event.y - getHeaderHeight()) / itemHeight + getTopIndex();
+ hitItem = (TableItem) getVisibleItem(itemIndex);
+ if (hitItem != null) {
+ if (hitItem.isSelectionHit(event.x) == true) {
+ doMouseSelect(hitItem, itemIndex, event.stateMask, event.button);
+ }
+ else
+ if (hitItem.isCheckHit(new Point(event.x, event.y)) == true) {
+ // only react to button one clicks. fixes bug 6770
+ if (event.button != 1) {
+ return;
+ }
+ doCheckItem(hitItem);
+ }
+ }
+ }
+}
+/**
+ * The mouse pointer was moved over the receiver.
+ * Reset the column resize cursor if it was active.
+ * @param event - the mouse event
+ */
+void columnMouseMove(Event event) {
+ if (isColumnResizeStarted() == false) {
+ setColumnResizeCursor(false);
+ }
+}
+public Point computeSize(int wHint, int hHint, boolean changed) {
+ checkWidget();
+ Point size = super.computeSize(wHint, hHint, changed);
+ Point headerSize;
+ GC gc;
+ final int WidthCalculationCount = Math.min(getItemCount(), 50); // calculate item width for the first couple of items only
+ TableItem item;
+ Image itemImage;
+ String itemText;
+ int width;
+ int newItemWidth = 0;
+
+ if (getHeaderVisible() == true) {
+ headerSize = getHeader().computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
+ size.y += headerSize.y;
+ }
+ if (getContentWidth() == 0 && WidthCalculationCount > 0) {
+ gc = new GC(this);
+ for (int i = 0; i < WidthCalculationCount; i++) {
+ item = getItem(i);
+ if (item == null) {
+ break; // no more items
+ }
+ itemImage = item.getImage();
+ itemText = item.getText();
+ width = 0;
+ if (itemImage != null) {
+ width += itemImage.getBounds().width;
+ }
+ if (itemText != null) {
+ width += gc.stringExtent(itemText).x;
+ }
+ newItemWidth = Math.max(newItemWidth, width);
+ }
+ if (newItemWidth > 0) {
+ size.x = newItemWidth;
+ }
+ gc.dispose();
+ }
+ return size;
+}
+/**
+ * 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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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();
+ SelectableItem item = null;
+
+ if (indices == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ for (int i = 0; i < indices.length; i++) {
+ item = getVisibleItem(indices[i]);
+ if (item != null) {
+ deselect(item);
+ }
+ }
+ if (item != null) {
+ setLastSelection(item, 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();
+ SelectableItem item = getVisibleItem(index);
+
+ if (item != null) {
+ deselect(item);
+ setLastSelection(item, 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();
+ SelectableItem item = null;
+
+ for (int i=start; i<=end; i++) {
+ item = getVisibleItem(i);
+ if (item != null) {
+ deselect(item);
+ }
+ }
+ if (item != null) {
+ setLastSelection(item, 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();
+
+ deselectAllExcept((SelectableItem) null);
+}
+/**
+ * Free resources.
+ */
+void doDispose() {
+ Vector items = getItemVector();
+
+ super.doDispose();
+ for (int i = items.size() - 1; i >= 0; i--) {
+ ((TableItem) items.elementAt(i)).dispose();
+ }
+ setItemVector(null);
+ items = getColumnVector();
+ while (items.size() > 0) { // TableColumn objects are removed from vector during dispose()
+ ((TableColumn) items.lastElement()).dispose();
+ }
+ resizeColumn = null;
+ fillColumn = null;
+ defaultColumn = null;
+ if (columnResizeCursor != null) {
+ columnResizeCursor.dispose();
+ }
+}
+/**
+ * Draw a line tracking the current position of a column
+ * resize operation.
+ * @param xPosition - x coordinate to draw the line at
+ */
+void drawColumnResizeLine(int xPosition) {
+ GC gc = new GC(this);
+ int lineHeight = getClientArea().height;
+ int lineWidth = getGridLineWidth();
+
+ redraw(getColumnResizeX() - lineWidth, 0, 1, lineHeight, false);
+ setColumnResizeX(xPosition);
+ gc.drawLine(xPosition - lineWidth, 0, xPosition - lineWidth, lineHeight);
+ gc.dispose();
+}
+/**
+ * Draw the grid lines for the receiver.
+ * @param event - Paint event triggering the drawing operation.
+ * @param drawColumns - The table columns for which the grid
+ * lines should be drawn.
+ */
+void drawGridLines(Event event, Enumeration drawColumns) {
+ GC gc = event.gc;
+ Color oldForeground = getForeground();
+ Rectangle columnBounds;
+ TableColumn column;
+ int lineWidth = getGridLineWidth();
+ int itemHeight = getItemHeight();
+ int headerHeight = getHeaderHeight();
+ int lineXPosition;
+ int lineYPosition = headerHeight + ((event.y-headerHeight) / itemHeight) * itemHeight;
+ int lineYStopPosition = event.y + event.height;
+
+ gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
+ // Draw the horizontal lines
+ if (itemHeight > 0) {
+ while (lineYPosition < lineYStopPosition) {
+ gc.drawLine(
+ event.x, lineYPosition + itemHeight - lineWidth,
+ event.x + event.width, lineYPosition + itemHeight - lineWidth);
+ lineYPosition += itemHeight;
+ }
+ }
+ // Draw the vertical lines at the right border of each column except the fill column
+ while (drawColumns.hasMoreElements() == true) {
+ column = (TableColumn) drawColumns.nextElement();
+ if (column.getIndex() != TableColumn.FILL) {
+ columnBounds = column.getBounds();
+ lineXPosition = columnBounds.x + columnBounds.width - lineWidth;
+ gc.drawLine(
+ lineXPosition, event.y,
+ lineXPosition, event.y + event.height);
+ }
+ }
+ gc.setForeground(oldForeground);
+}
+
+/**
+ * If the receiver has input focus draw a rectangle enclosing
+ * the label of 'item' to indicate the input focus.
+ * The rectangle is drawn in either the first column or in all columns
+ * for full row select.
+ * @param item - item for which the selection state should be drawn
+ * @param gc - GC to draw on.
+ */
+void drawSelectionFocus(TableItem item, GC gc) {
+ Point extent = item.getSelectionExtent();
+ Point position = new Point(
+ item.getImageStopX(TableColumn.FIRST) + getHorizontalOffset(),
+ getRedrawY(item));
+
+ gc.drawFocus(position.x, position.y, extent.x, extent.y);
+}
+
+/**
+ * Returns the column at the given, zero-relative index in the
+ * receiver. Throws an exception if the index is out of range.
+ * 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>
+ */
+public TableColumn getColumn(int index) {
+ checkWidget();
+ Vector columns = getColumnVector();
+
+ if (columns == null) error(SWT.ERROR_CANNOT_GET_ITEM);
+ if (index < 0 || index >= columns.size()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+
+ return (TableColumn) columns.elementAt(index);
+}
+/**
+ * Return the column located at 'xPosition' in the widget.
+ * Return null if xPosition is outside the widget.
+ * @param xPosition - position of the desired column
+ */
+TableColumn getColumnAtX(int xPosition) {
+ Enumeration columns = internalGetColumnVector().elements();
+ TableColumn column;
+ TableColumn hitColumn = null;
+ Rectangle bounds;
+
+ while (columns.hasMoreElements() == true && hitColumn == null) {
+ column = (TableColumn) columns.nextElement();
+ bounds = column.getBounds();
+ if ((xPosition >= bounds.x) &&
+ (xPosition <= bounds.x + bounds.width)) {
+ hitColumn = column;
+ }
+ }
+ if (hitColumn == null) {
+ column = getFillColumn();
+ bounds = column.getBounds();
+ if ((xPosition >= bounds.x) &&
+ (xPosition <= bounds.x + bounds.width)) {
+ hitColumn = column;
+ }
+ }
+ return hitColumn;
+}
+/**
+ * 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 is 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public int getColumnCount() {
+ checkWidget();
+ Vector columns = getColumnVector();
+ int count = 0;
+
+ if (columns != null) {
+ count = columns.size();
+ }
+ return count;
+}
+/** Replace CURSOR_SIZEWE with real column resize cursor
+ * (no standard cursor-have to load from file)
+ * Answer the cursor displayed during a column resize
+ * operation.
+ * Lazy initialize the cursor since it may never be needed.
+ */
+Cursor getColumnResizeCursor() {
+ if (columnResizeCursor == null) {
+ columnResizeCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZEWE);
+ }
+ return columnResizeCursor;
+}
+/**
+ * Answer the current position of the mouse cursor during
+ * a column resize operation.
+ */
+int getColumnResizeX() {
+ return columnResizeX;
+}
+/**
+ * Returns an array of <code>TableColumn</code>s which are the
+ * columns in the receiver. 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>
+ */
+public TableColumn [] getColumns() {
+ checkWidget();
+ Vector columns = getColumnVector();
+ TableColumn columnArray[] = new TableColumn[columns.size()];
+
+ columns.copyInto(columnArray);
+ return columnArray;
+}
+/**
+ * Answer a Vector containing all columns of receiver except
+ * the fill column to the right of all content columns.
+ */
+Vector getColumnVector() {
+ return columns;
+}
+/**
+ * Return the default column that is created as soon as the table
+ * is created.
+ * Fix for 1FUSJY5
+ */
+TableColumn getDefaultColumn() {
+ return defaultColumn;
+}
+/**
+ * Answer the width of the replacement String used to indicate
+ * truncated items.
+ * Cached to speed up calculation of truncated items.
+ * @param gc - GC used to measure the width of the replacement
+ * String
+ */
+int getDotsWidth(GC gc) {
+ return dotsWidth;
+}
+/**
+ * Answer the column used to occupy any space left to the
+ * right of all the user created columns.
+ */
+TableColumn getFillColumn() {
+ return fillColumn;
+}
+/**
+ * Returns the width in pixels of a grid 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 getGridLineWidth () {
+ checkWidget();
+
+ return 1;
+}
+/**
+ * Answer the table header widget.
+ */
+Header getHeader() {
+ return tableHeader;
+}
+/**
+ * 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();
+ Header header = getHeader();
+ int height = 0;
+
+ if (header.getVisible() == true) {
+ height = header.getBounds().height;
+ }
+ return height;
+}
+/**
+ * Returns <code>true</code> if the receiver's header is visible,
+ * and <code>false</code> otherwise.
+ * <p>
+ * If one of the receiver's ancestors is not visible or some
+ * other condition makes the receiver not visible, this method
+ * may still indicate that it is considered visible even though
+ * it may not actually be showing.
+ * </p>
+ *
+ * @return the receiver's header's visibility state
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public boolean getHeaderVisible() {
+ checkWidget();
+
+ return getHeader().getVisible();
+}
+/**
+ * Answer the image extent of 'item'. Use the image of any column.
+ */
+Point getImageExtent(SelectableItem item) {
+ Image image = null;
+ Rectangle imageBounds;
+ Point imageExtent = null;
+ int columnCount = internalGetColumnCount();
+
+ for (int i = 0; i < columnCount && image == null; i++) {
+ image = ((TableItem) item).getImage(i);
+ }
+ if (image != null) {
+ imageBounds = image.getBounds();
+ imageExtent = new Point(imageBounds.width, imageBounds.height);
+ }
+ return imageExtent;
+}
+/**
+ * Answer the index of 'item' in the receiver.
+ */
+int getIndex(SelectableItem item) {
+ int index = -1;
+
+ if (item != null && item.getSelectableParent() == this) {
+ index = ((TableItem) item).getIndex();
+ }
+ return index;
+}
+/**
+ * Returns the item at the given, zero-relative index in the
+ * receiver. Throws an exception if the index is out of range.
+ *
+ * @param index the index of the item to return
+ * @return the item at the given index
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public TableItem getItem(int index) {
+ checkWidget();
+
+ if (!(0 <= index && index < getItemCount())) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ return (TableItem) getVisibleItem(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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 headerHeight = getHeaderHeight();
+ TableColumn column = getColumnAtX(point.x);
+ TableItem item = null;
+
+ if (column != null && column.getIndex() != TableColumn.FILL && point.y - headerHeight > 0) {
+ int itemIndex = (point.y - headerHeight) / getItemHeight() + getTopIndex();
+ item = (TableItem) getVisibleItem(itemIndex);
+ if (item != null) {
+ Point itemSize = item.getItemExtent(column);
+ if (point.x - column.getBounds().x > itemSize.x) {
+ item = null;
+ }
+ }
+ }
+ 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 getItemVector().size();
+}
+/**
+ * Answer the number of items that can be displayed in the
+ * client area of the receiver without truncating any items.
+ */
+int getItemCountWhole() {
+ int clientAreaHeight = Math.max(0, getClientArea().height - getHeaderHeight());
+
+ return clientAreaHeight / getItemHeight();
+}
+/**
+ * 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 super.getItemHeight();
+}
+/**
+ * Answer the number of pixels that should be added to the item height.
+ */
+int getItemPadding() {
+ return getGridLineWidth() + getDisplay().textHighlightThickness + 1;
+}
+/**
+ * Returns an 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();
+ Vector items = getItemVector();
+ TableItem itemArray[] = new TableItem[items.size()];
+
+ items.copyInto(itemArray);
+ return itemArray;
+}
+/**
+ * Answer all items of the receiver.
+ */
+Vector getItemVector() {
+ return items;
+}
+/**
+ * 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 drawGridLines;
+}
+/**
+ * Answer a Vector containing the columns that need repainting
+ * based on the 'paintArea'.
+ * @param paintArea - invalidated rectangle that needs repainting
+ */
+Vector getPaintColumns(Rectangle paintArea) {
+ Enumeration columns = internalGetColumnVector().elements();
+ Vector paintColumns = new Vector();
+ TableColumn column;
+ Rectangle columnBounds;
+ int paintAreaRightBorder = paintArea.x + paintArea.width;
+
+ while (columns.hasMoreElements() == true) {
+ column = (TableColumn) columns.nextElement();
+ columnBounds = column.getBounds();
+ if ((columnBounds.x + columnBounds.width >= paintArea.x) && // does the paintArea overlap the current column?
+ (columnBounds.x <= paintAreaRightBorder)) {
+ paintColumns.addElement(column);
+ }
+ }
+ return paintColumns;
+}
+/**
+ * Return the width of the widest item in the column identified by 'columnIndex'
+ * @param columnIndex - index of the column whose preferred width should be
+ * calculated
+ */
+int getPreferredColumnWidth(int columnIndex) {
+ Enumeration tableItems = getItemVector().elements();
+ TableItem tableItem;
+ int width = 0;
+ int headerWidth;
+
+ if (columnIndex != TableColumn.FILL) {
+ while (tableItems.hasMoreElements() == true) {
+ tableItem = (TableItem) tableItems.nextElement();
+ width = Math.max(width, tableItem.getPreferredWidth(columnIndex));
+ }
+ headerWidth = getHeader().getPreferredWidth(columnIndex);
+ if (width < headerWidth) {
+ width = headerWidth;
+ }
+ }
+ return width;
+}
+/**
+ * Answer the position in the receiver where 'item' is drawn
+ * @return the y coordinate at which 'item' is drawn.
+ * Return -1 if 'item' is not an item of the receiver
+ */
+int getRedrawY(SelectableItem item) {
+ int redrawY = super.getRedrawY(item);
+
+ if (redrawY != -1) {
+ redrawY += getHeaderHeight();
+ }
+ return redrawY;
+}
+/**
+ * Answer the column that is being resized or null if no
+ * resize operation is in progress.
+ */
+TableColumn getResizeColumn() {
+ return resizeColumn;
+}
+/**
+ * Return the positions at which the column identified by 'columnIndex'
+ * must be redrawn.
+ * These positions may be different for each item since each item may
+ * have a different label
+ * @param columnIndex - the column index
+ * @param columnWidth - width of the column
+ * @return the positions at which the column must be redrawn.
+ * Each item in the widget client area is represented by a slot in
+ * the array. The item at position 'topIndex' is the first item in
+ * the array.
+ */
+int [] getResizeRedrawX(int columnIndex, int columnWidth) {
+ int topIndex = getTopIndex();
+ int bottomIndex = getBottomIndex();
+ int resizeRedrawX[];
+ TableItem item;
+
+ bottomIndex = Math.min(bottomIndex, getItemCount());
+ resizeRedrawX = new int[bottomIndex-topIndex+1];
+ for (int i = topIndex; i < bottomIndex; i++) {
+ item = (TableItem) getVisibleItem(i);
+ resizeRedrawX[i-topIndex] = item.getDotStartX(columnIndex, columnWidth);
+ }
+ return resizeRedrawX;
+}
+/**
+ * Returns an array of <code>TableItem</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 TableItem [] getSelection() {
+ checkWidget();
+ Vector selectionVector = getSelectionVector();
+ TableItem[] selectionArray = new TableItem[selectionVector.size()];
+
+ selectionVector.copyInto(selectionArray);
+ sort(selectionArray, 0, selectionArray.length);
+ return selectionArray;
+}
+
+/**
+ * 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 super.getSelectionCount();
+}
+
+int getFontHeight(){
+ return fontHeight;
+}
+/**
+ * Answer the size of the full row selection rectangle for 'item'.
+ */
+Point getFullSelectionExtent(TableItem item) {
+ TableColumn lastColumn = (TableColumn) internalGetColumnVector().lastElement();
+ Point selectionExtent = null;
+ Rectangle columnBounds;
+ int xPosition = item.getImageStopX(TableColumn.FIRST);
+ int gridLineWidth = getGridLineWidth();
+
+ if (lastColumn != null) {
+ columnBounds = lastColumn.getBounds();
+ selectionExtent = new Point(
+ columnBounds.x - getHorizontalOffset() + columnBounds.width - xPosition - gridLineWidth,
+ getItemHeight());
+ if (getLinesVisible() == true) {
+ selectionExtent.y -= gridLineWidth;
+ }
+ }
+ return selectionExtent;
+}
+/**
+ * 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 = -1;
+
+ if (getSelectionCount() > 0) {
+ index = getIndex(getSelection()[0]);
+ }
+ return index;
+}
+/**
+ * Returns the zero-relative indices of the items which are currently
+ * selected in the receiver. 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();
+ TableItem[] items = getSelection();
+ int indices[] = new int[items.length];
+
+ for (int i = 0; i < items.length; i++) {
+ indices[i] = getIndex(items[i]);
+ }
+ 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 super.getTopIndex();
+}
+/**
+ * Answer the index of 'item' in the receiver.
+ * Answer -1 if the item is not visible.
+ * The returned index must refer to a visible item.
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. It only means that the item
+ * would be displayed if it is located inside the receiver's
+ * client area.
+ * Every item in a table widget should be visible.
+ */
+int getVisibleIndex(SelectableItem item) {
+ return getIndex(item);
+}
+/**
+ * Answer the SelectableItem located at 'itemIndex' in the receiver.
+ * @param itemIndex - location of the SelectableItem object to return
+ */
+SelectableItem getVisibleItem(int itemIndex) {
+ Vector items = getItemVector();
+ TableItem item = null;
+
+ if ((items != null) && (itemIndex >= 0) && (itemIndex < items.size())) {
+ item = (TableItem) items.elementAt(itemIndex);
+ }
+ return item;
+}
+/**
+ * Answer the y coordinate at which 'item' is drawn.
+ * @param item - SelectableItem for which the paint position
+ * should be returned
+ * @return the y coordinate at which 'item' is drawn.
+ * Return -1 if 'item' is null or outside the client area
+ */
+int getVisibleRedrawY(SelectableItem item) {
+ int redrawY = -1;
+ int index = getTopIndex();
+ int bottomIndex = getBottomIndex();
+
+ if (item == null) {
+ return redrawY;
+ }
+ while (index < bottomIndex && item.equals(getVisibleItem(index)) == false) {
+ index++;
+ }
+ if (index < bottomIndex) {
+ redrawY = getRedrawY(item);
+ }
+ return redrawY;
+}
+/**
+ * Handle the events the receiver is listening to.
+ */
+void handleEvents(Event event) {
+ switch (event.type) {
+ case SWT.MouseMove:
+ if (event.widget == tableHeader) {
+ headerMouseMove(event);
+ }
+ else {
+ columnMouseMove(event);
+ }
+ break;
+ case SWT.MouseDown:
+ if (event.widget == tableHeader) {
+ headerMouseDown(event);
+ }
+ else {
+ columnMouseDown(event);
+ }
+ break;
+ case SWT.MouseDoubleClick:
+ columnMouseDoubleClick(event);
+ break;
+ case SWT.MouseUp:
+ mouseUp(event);
+ break;
+ case SWT.Paint:
+ paint(event);
+ break;
+ default:
+ super.handleEvents(event);
+ }
+}
+/**
+ * Answer true if any item in the first column has an image.
+ * Answer false otherwise.
+ */
+boolean hasFirstColumnImage() {
+ return firstColumnImage;
+}
+/**
+ * The mouse pointer was pressed down on the receiver's header
+ * widget. Start a column resize operation if apropriate.
+ * @param event - the mouse event that occured over the header
+ * widget
+ */
+void headerMouseDown(Event event) {
+ TableColumn column = getColumnAtX(event.x);
+
+ // only react to button one clicks. fixes bug 6770
+ if (event.button != 1) {
+ return;
+ }
+ if (isColumnResize(event) == true) {
+ startColumnResize(event);
+ }
+ else
+ if (column != null) {
+ column.notifyListeners(SWT.Selection, new Event());
+ }
+}
+/**
+ * The mouse pointer was moved over the receiver's header widget.
+ * If a column is currently being resized a vertical line indicating
+ * the new position of the resized column is drawn.
+ * Otherwise, if no column resize operation is in progress, the
+ * column resize cursor is displayed when the mouse is near the border
+ * of a column.
+ */
+void headerMouseMove(Event event) {
+ if (isColumnResizeStarted() == false) { // only check whether cursor is in resize
+ setColumnResizeCursor(isColumnResize(event)); // area if no resize operation is in progress
+ }
+ else
+ if (event.x >= getResizeColumn().getBounds().x) {
+ drawColumnResizeLine(event.x);
+ update(); // looks better if resize line is drawn immediately
+ }
+}
+/**
+ * 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);
+ }
+ return internalGetColumnVector().indexOf(column);
+}
+/**
+ * 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);
+ }
+ return getIndex(item);
+}
+/**
+ * Initialize the receiver. Create a header widget and an empty column.
+ */
+void initialize() {
+ columns = new Vector();
+ setItemVector(new Vector());
+ GC gc = new GC(this);
+ Point extent = gc.stringExtent(DOT_STRING);
+ dotsWidth = extent.x;
+ fontHeight = extent.y;
+ gc.dispose();
+ tableHeader = new Header(this);
+ tableHeader.setVisible(false); // SWT table header is invisible by default, too
+ fillColumn = TableColumn.createFillColumn(this);
+ setColumnPosition(fillColumn);
+ defaultColumn = TableColumn.createDefaultColumn(this); // Create the default column. Fix for 1FUSJY5
+ super.initialize();
+}
+/**
+ * Insert the new column 'column' into the table data at position
+ * 'index'.
+ */
+void insertColumnData(TableColumn column) {
+ Enumeration tableItems = getItemVector().elements();
+ TableItem tableItem;
+
+ while (tableItems.hasMoreElements() == true ) {
+ tableItem = (TableItem) tableItems.nextElement();
+ tableItem.insertColumn(column);
+ }
+}
+/**
+ * Insert the new column 'column'.
+ * Set the position and move the following columns to the right.
+ */
+void insertColumnVisual(TableColumn column) {
+ Rectangle columnBounds = column.getBounds();
+ Rectangle previousColumnBounds;
+ int index = column.getIndex();
+
+ if (index > 0) {
+ previousColumnBounds = getColumn(index - 1).getBounds();
+ columnBounds.x = previousColumnBounds.x + previousColumnBounds.width;
+ }
+ else {
+ columnBounds.x = 0;
+ }
+ column.setBounds(columnBounds);
+ setColumnPosition(column);
+}
+/**
+ * Set event listeners for the receiver.
+ */
+void installListeners() {
+ Header tableHeader = getHeader();
+ Listener listener = getListener();
+
+ super.installListeners();
+ tableHeader.addListener(SWT.MouseMove, listener);
+ tableHeader.addListener(SWT.MouseDown, listener);
+ tableHeader.addListener(SWT.MouseUp, listener);
+
+ addListener(SWT.MouseMove, listener);
+ addListener(SWT.MouseDown, listener);
+ addListener(SWT.MouseDoubleClick, listener);
+ addListener(SWT.MouseUp, listener);
+ addListener(SWT.Paint, listener);
+}
+/**
+ * Answer the TableColumn at 'index'.
+ * If the user has not created any columns the default column is
+ * returned if index is 0.
+ * Fix for 1FUSJY5
+ */
+TableColumn internalGetColumn(int index) {
+ Vector columns = internalGetColumnVector();
+
+ if (columns == null) error(SWT.ERROR_CANNOT_GET_ITEM);
+ if (index < 0 || index >= columns.size()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+
+ return (TableColumn) columns.elementAt(index);
+
+}
+/**
+ * Answer the number of columns in the receiver.
+ * If the user has not created any columns, 1 is returned since there
+ * always is a default column.
+ * Fix for 1FUSJY5
+ */
+int internalGetColumnCount() {
+ Vector columns = internalGetColumnVector();
+ int count = 0;
+
+ if (columns != null) {
+ count = columns.size();
+ }
+ return count;
+}
+/**
+ * Return a Vector containing all columns of the receiver except
+ * the fill column to the right of all content columns.
+ * Return a Vector containing the default column if the user has
+ * not created any columns.
+ * Fix for 1FUSJY5
+ */
+Vector internalGetColumnVector() {
+ Vector internalColumnVector;
+ TableColumn defaultColumn;
+
+ if (columns.isEmpty() == false) {
+ internalColumnVector = columns;
+ }
+ else {
+ internalColumnVector = new Vector(1);
+ defaultColumn = getDefaultColumn();
+ if (defaultColumn != null) {
+ internalColumnVector.addElement(defaultColumn);
+ }
+ }
+ return internalColumnVector;
+}
+/**
+ * Answer whether the mouse pointer is at a position that can
+ * start a column resize operation. A column resize can be
+ * started if the mouse pointer is at either the left or right
+ * border of a column.
+ * @param event - mouse event specifying the location of the
+ * mouse pointer.
+ */
+boolean isColumnResize(Event event) {
+ TableColumn hotColumn = getColumnAtX(event.x);
+ if (hotColumn == null) return false;
+ Rectangle bounds = hotColumn.getBounds();
+ int hotColumnIndex = hotColumn.getIndex();
+ int columnX = event.x - bounds.x;
+ boolean isColumnResize = false;
+
+ if (columnX <= COLUMN_RESIZE_OFFSET && // mouse over left side of column? and
+ hotColumnIndex != TableColumn.FIRST) { // it's not the first column)
+ if (hotColumnIndex == TableColumn.FILL) {
+ hotColumn = (TableColumn) internalGetColumnVector().lastElement();
+ }
+ else {
+ hotColumn = internalGetColumn(hotColumnIndex - 1);
+ }
+ isColumnResize = hotColumn.getResizable(); // check whether left column can be resized
+ }
+ else
+ if (columnX >= bounds.width - COLUMN_RESIZE_OFFSET && // mouse over right side of column and
+ hotColumn != getFillColumn()) { // column is a real one (not the right hand fill column)?
+ isColumnResize = hotColumn.getResizable(); // check whether column under cursor can be resized
+ }
+ return isColumnResize;
+}
+/**
+ * Answer whether a column of the receiver is being resized.
+ */
+boolean isColumnResizeStarted() {
+ return (getResizeColumn() != 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();
+ TableItem item = getItem(index);
+
+ return (item != null && item.isSelected() == true);
+}
+/**
+ * 'changedItem' has changed. Update the default column width.
+ * @param changedItem - the item that has changed
+ */
+void itemChanged(SelectableItem changedItem, int repaintStartX, int repaintWidth) {
+ // call super.itemChanged first to make sure that table image size is
+ // calculated if necessary. Fixes 1FYPBBG.
+ super.itemChanged(changedItem, repaintStartX, repaintWidth);
+ // remember if any item ever had an image in the first column.
+ if (firstColumnImage == false && changedItem.getImage() != null) {
+ firstColumnImage = true;
+ redraw ();
+ }
+ setFirstColumnWidth((TableItem) changedItem);
+}
+/**
+ * A mouse button was released.
+ * Update the display if a column has been resized.
+ * @param event - the mouse event for the button up action
+ */
+void mouseUp(Event event) {
+ TableColumn resizeColumn = getResizeColumn();
+ Rectangle oldColumnBounds;
+ int resizeXPosition;
+ int widthChange;
+ if (isColumnResizeStarted() == true) {
+ oldColumnBounds = resizeColumn.getBounds();
+ resizeXPosition = getColumnResizeX();
+ widthChange = resizeXPosition - (oldColumnBounds.x + oldColumnBounds.width);
+ if (widthChange >= 0) {
+ redraw(resizeXPosition - getGridLineWidth(), 0, 1, getClientArea().height, false); // remove resize line
+ update(); // to avoid cheese caused by scrolling the resize line
+ }
+ if (widthChange != 0) {
+ resizeColumn.setWidth(oldColumnBounds.width + widthChange);
+ }
+ setResizeColumn(null);
+ }
+}
+/**
+ * Adjust the position of all columns starting at 'startIndex'.
+ * @param startIndex - index at which the column move should begin
+ * If this is the index of the fill column all columns are moved,
+ * including the fill column
+ * @param moveDistance - distance that the columns should be moved.
+ * < 0 = columns are going to be moved left.
+ * > 0 = columns are going to be moved right.
+ */
+void moveColumns(int startIndex, int moveDistance) {
+ Vector columns = internalGetColumnVector();
+ TableColumn moveColumn;
+ Rectangle columnBounds;
+
+ if (startIndex == TableColumn.FILL) {
+ moveColumn = getFillColumn();
+ columnBounds = moveColumn.getBounds();
+ columnBounds.x += moveDistance;
+ moveColumn.setBounds(columnBounds);
+ startIndex = 0; // continue with first data column
+ }
+ for (int i = startIndex; i < columns.size(); i++) {
+ moveColumn = (TableColumn) columns.elementAt(i);
+ columnBounds = moveColumn.getBounds();
+ columnBounds.x += moveDistance;
+ moveColumn.setBounds(columnBounds);
+ }
+}
+/**
+ * Adjust the y position of all columns including the fill column.
+ */
+void moveColumnsVertical() {
+ Enumeration columns = internalGetColumnVector().elements();
+ TableColumn column;
+
+ setColumnPosition(getFillColumn());
+ while (columns.hasMoreElements() == true) {
+ column = (TableColumn) columns.nextElement();
+ setColumnPosition(column);
+ }
+}
+/**
+ * A paint event has occurred. Paint the invalidated items.
+ * @param event - paint event specifying the invalidated area.
+ */
+void paint(Event event) {
+ int visibleRange[];
+ int headerHeight = getHeaderHeight();
+ Vector paintColumns = getPaintColumns(event.getBounds());
+ TableItem focusItem = null;
+
+ if (paintColumns.size() > 0) {
+ event.y -= headerHeight;
+ visibleRange = getIndexRange(event.getBounds());
+ event.y += headerHeight;
+ // When the top index is > 0 and the receiver is resized
+ // higher so that the top index becomes 0 the invalidated
+ // rectangle doesn't start below the header widget but at
+ // y position 0. Subtraction of the header height (it is
+ // not above the receiver but on top) causes event.y and
+ // subsequently visibleRange[0] to be negative.
+ // Hack to prevent visibleRange[0] from becoming negative.
+ // Need to find out why the invalidated area starts at 0
+ // in the first place.
+ if (visibleRange[0] < 0) {
+ visibleRange[0] = 0;
+ }
+ //
+ visibleRange[1] = Math.min(visibleRange[1], getItemCount()-1-getTopIndex());
+ focusItem = paintItems(event, visibleRange[0], visibleRange[1], paintColumns);
+ }
+ if (getLinesVisible() == true) {
+ drawGridLines(event, paintColumns.elements());
+ }
+ if (focusItem != null) {
+ // draw focus on top of drawing grid lines so that focus rectangle
+ // is not obscured by grid. Fixes 1G5X20B
+ drawSelectionFocus(focusItem, event.gc);
+ }
+}
+
+/**
+ * Paint items of the receiver starting at index 'topPaintIndex' and
+ * ending at 'bottomPaintIndex'.
+ * @param event - holds the GC to draw on and the clipping rectangle
+ * @param topPaintIndex - index of the first item to draw
+ * @param bottomPaintIndex - index of the last item to draw
+ * @param paintColumns - the table columns that should be painted
+ * @return the item that has focus if it was among the rendered items.
+ * null if the focus item was not rendered or if no item has focus (ie.
+ * because the widget does not have focus)
+ */
+TableItem paintItems(Event event, int topPaintIndex, int bottomPaintIndex, Vector paintColumns) {
+ Enumeration columns;
+ TableColumn column;
+ TableItem paintItem;
+ TableItem focusItem = null;
+ Point selectionExtent;
+ GC gc = event.gc;
+ Color selectionColor = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
+ Point fullSelectionExtent;
+ int paintXPosition;
+ int paintYPosition;
+
+ topPaintIndex += getTopIndex();
+ bottomPaintIndex += getTopIndex();
+ for (int i = topPaintIndex; i <= bottomPaintIndex; i++) {
+ paintItem = (TableItem) getVisibleItem(i);
+ paintXPosition = paintItem.getSelectionX();
+ paintYPosition = getRedrawY(paintItem);
+ fullSelectionExtent = getFullSelectionExtent(paintItem);
+ gc.setBackground(paintItem.getBackground());
+ gc.fillRectangle(paintXPosition, paintYPosition, fullSelectionExtent.x, fullSelectionExtent.y);
+
+ if (paintItem.isSelected() == true) {
+ selectionExtent = paintItem.getSelectionExtent();
+ gc.setBackground(selectionColor);
+ gc.fillRectangle(paintXPosition, paintYPosition, selectionExtent.x, selectionExtent.y);
+ }
+ columns = paintColumns.elements();
+ while (columns.hasMoreElements() == true) {
+ column = (TableColumn) columns.nextElement();
+ paintSubItem(event, paintItem, column, paintYPosition);
+ }
+ if (hasFocus(paintItem)) {
+ focusItem = paintItem;
+ }
+ }
+ return focusItem;
+}
+
+/**
+ * Paint the table item 'paintItem' in 'column' at y position
+ * 'paintYPosition' of the receiver.
+ * @param event - holds the GC to draw on and the clipping
+ * rectangle.
+ * @param paintItem - the item to draw
+ * @param column - column to draw 'paintItem' in
+ * @param paintYPosition - y position in the receiver to draw
+ * 'paintItem' at.
+ */
+void paintSubItem(Event event, TableItem paintItem, TableColumn column, int paintYPosition) {
+ Rectangle columnBounds = column.getBounds();
+ Point paintPosition;
+ int gridLineWidth = getGridLineWidth();
+ int itemDrawStopX = columnBounds.x + columnBounds.width - gridLineWidth;
+ int clipX;
+
+ if (event.x + event.width > itemDrawStopX) { // does the invalidated area stretch past the current column's right border?
+ clipX = Math.max(columnBounds.x, event.x);
+ event.gc.setClipping( // clip the drawing area
+ clipX, event.y,
+ Math.max(0, itemDrawStopX - clipX), event.height);
+ }
+ paintPosition = new Point(columnBounds.x, paintYPosition);
+ paintItem.paint(event.gc, paintPosition, column);
+ if (event.x + event.width > itemDrawStopX) {
+ event.gc.setClipping(event.x, event.y, event.width, event.height); // restore original clip rectangle
+ }
+}
+/**
+ * Reindex all columns starting at 'startIndex'.
+ * Reindexing is necessary when a new column has been inserted.
+ */
+void reindexColumns(int startIndex) {
+ Vector columns = getColumnVector();
+ TableColumn column;
+
+ for (int i = startIndex; i < getColumnCount(); i++) {
+ column = (TableColumn) columns.elementAt(i);
+ column.setIndex(i);
+ }
+}
+/**
+ * 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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove(int indices[]) {
+ checkWidget();
+ SelectableItem item;
+ int [] sortedIndices;
+ int last = -1;
+ int sortedIndex;
+
+ if (indices == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ sortedIndices = new int[indices.length];
+ System.arraycopy (indices, 0, sortedIndices, 0, indices.length);
+ sort(sortedIndices); // sort indices in descending order
+ for (int i = 0; i < sortedIndices.length; i++) {
+ sortedIndex = sortedIndices[i];
+ if (sortedIndex != last) {
+ item = getVisibleItem(sortedIndex);
+ if (item != null) {
+ item.dispose();
+ }
+ else {
+ if (0 <= sortedIndex && sortedIndex < getItemVector().size()) {
+ error(SWT.ERROR_ITEM_NOT_REMOVED);
+ }
+ else {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ }
+ last = sortedIndex;
+ }
+ }
+}
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove(int index) {
+ checkWidget();
+ SelectableItem item = getVisibleItem(index);
+
+ if (item != null) {
+ item.dispose();
+ }
+ else {
+ if (0 <= index && index < getItemVector().size()) {
+ error(SWT.ERROR_ITEM_NOT_REMOVED);
+ }
+ else {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ }
+}
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove(int start, int end) {
+ checkWidget();
+ SelectableItem item;
+
+ for (int i = end; i >= start; i--) {
+ item = getVisibleItem(i);
+ if (item != null) {
+ item.dispose();
+ }
+ else {
+ 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();
+ Vector items = getItemVector();
+
+ setRedraw(false);
+ setRemovingAll(true);
+ for (int i = items.size() - 1; i >= 0; i--) {
+ ((TableItem) items.elementAt(i)).dispose();
+ }
+ setItemVector(new Vector());
+ reset();
+ calculateVerticalScrollbar();
+ setRemovingAll(false);
+ setRedraw(true);
+}
+/**
+ * Remove 'column' from the receiver.
+ */
+void removeColumn(TableColumn column) {
+ int index = column.getIndex();
+ int columnWidth = column.getWidth();
+ int columnCount;
+
+ if (isRemovingAll() == true) {
+ getColumnVector().removeElementAt(index);
+ }
+ else {
+ getColumnVector().removeElementAt(index);
+ columnCount = getColumnCount();
+ // Never remove the data of the last user created column.
+ // SWT for Windows does the same.
+ if (columnCount > 0) {
+ removeColumnData(column);
+ removeColumnVisual(column);
+ }
+ else {
+ redraw();
+ getHeader().redraw();
+ }
+ if (index < columnCount) { // is there a column after the removed one?
+ reindexColumns(index);
+ }
+ // last user created column is about to be removed.
+ if (columnCount == 0) {
+ TableColumn defaultColumn = getDefaultColumn();
+ defaultColumn.pack(); // make sure the default column has the right size...
+ setColumnPosition(defaultColumn); // ...and is at the right position
+ }
+ // Fixes for 1G1L0UT
+ // Reduce the content width by the width of the removed column
+ setContentWidth(getContentWidth() - columnWidth);
+ // claim free space
+ claimRightFreeSpace();
+ //
+ }
+}
+/**
+ * Remove the column 'column' from the table data.
+ */
+void removeColumnData(TableColumn column) {
+ Enumeration tableItems = getItemVector().elements();
+ TableItem tableItem;
+
+ while (tableItems.hasMoreElements() == true ) {
+ tableItem = (TableItem) tableItems.nextElement();
+ tableItem.removeColumn(column);
+ }
+}
+/**
+ * Remove the column 'column'.
+ * Set the position of the following columns.
+ */
+void removeColumnVisual(TableColumn column) {
+ int columnWidth = column.getWidth();
+
+ // move following columns to the left
+ moveColumns(column.getIndex(), columnWidth * -1);
+ redraw();
+ getHeader().redraw();
+}
+/**
+ * 'item' has been removed from the receiver.
+ * Update the display and the scroll bars.
+ */
+void removedItem(SelectableItem item) {
+ int oldHeight = getItemHeight();
+ super.removedItem (item);
+ if (getItemCount() == 0 && drawGridLines && oldHeight != getItemHeight()) {
+ redraw();
+ }
+}
+/**
+ * Remove 'item' from the receiver.
+ * @param item - item that should be removed from the receiver
+ */
+void removeItem(TableItem item) {
+ if (isRemovingAll() == true) return;
+
+ Vector items = getItemVector();
+ int index = items.indexOf(item);
+ if (index != -1) {
+ removingItem(item);
+ items.removeElementAt(index);
+ for (int i = index; i < items.size(); i++) {
+ TableItem anItem = (TableItem) items.elementAt(i);
+ anItem.setIndex(anItem.getIndex() - 1);
+ }
+ removedItem(item);
+ }
+}
+/**
+ * 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);
+}
+/**
+ * Reset cached data of column at 'columnIndex' for the items of the receiver.
+ * @param columnIndex - index of the column for which the item data should be
+ * reset.
+ */
+void resetTableItems(int columnIndex) {
+ Enumeration tableItems = getItemVector().elements();
+ TableItem tableItem;
+
+ while (tableItems.hasMoreElements() == true ) {
+ tableItem = (TableItem) tableItems.nextElement();
+ tableItem.reset(columnIndex);
+ }
+}
+/**
+ * The receiver has been resized. Resize the fill column
+ * and the header widget.
+ */
+void resize(Event event) {
+ TableColumn fillColumn = getFillColumn();
+ Rectangle fillColumnBounds;
+
+ super.resize(event);
+ // the x position may change in super.resize.
+ // get the column bounds after calling super.resize. Fixes 1G7ALGG
+ fillColumnBounds = fillColumn.getBounds();
+ fillColumnBounds.width = Math.max(0, getClientArea().width - getContentWidth());
+ fillColumn.setBounds(fillColumnBounds);
+ resizeHeader();
+}
+/**
+ * Resize the header widget to occupy the whole width of the
+ * receiver.
+ */
+void resizeHeader() {
+ Header tableHeader = getHeader();
+ Point size = tableHeader.getSize();
+
+ size.x = Math.max(getContentWidth(), getClientArea().width);
+ tableHeader.setSize(size);
+}
+/**
+ * Redraw 'column' after its width has been changed.
+ * @param column - column whose width has changed.
+ * @param oldColumnWidth - column width before resize
+ * @param oldColumnWidth - column width after resize
+ */
+void resizeRedraw(TableColumn column, int oldColumnWidth, int newColumnWidth) {
+ Rectangle columnBounds = column.getBounds();
+ int columnIndex = column.getIndex();
+ int oldRedrawStartX[] = getResizeRedrawX(columnIndex, oldColumnWidth);
+ int newRedrawStartX[] = getResizeRedrawX(columnIndex, newColumnWidth);
+ int itemHeight = getItemHeight();
+ int widthChange = newColumnWidth - oldColumnWidth;
+ int topIndex = getTopIndex();
+
+ for (int i = 0; i < newRedrawStartX.length; i++) {
+ if (newRedrawStartX[i] != oldRedrawStartX[i]) {
+ if (widthChange > 0) {
+ newRedrawStartX[i] = oldRedrawStartX[i];
+ }
+ redraw(
+ columnBounds.x + newRedrawStartX[i], columnBounds.y + itemHeight * (i + topIndex),
+ columnBounds.width - newRedrawStartX[i], itemHeight, false);
+ }
+ }
+}
+/**
+ * Scroll horizontally by 'numPixel' pixel.
+ * @param numPixel - the number of pixel to scroll
+ * < 0 = columns are going to be moved left.
+ * > 0 = columns are going to be moved right.
+ */
+void scrollHorizontal(int numPixel) {
+ Rectangle clientArea = getClientArea();
+
+ scroll(
+ numPixel, 0, // destination x, y
+ 0, 0, // source x, y
+ clientArea.width, clientArea.height, true);
+ getHeader().scroll(
+ numPixel, 0, // destination x, y
+ 0, 0, // source x, y
+ clientArea.width, clientArea.height, true);
+ moveColumns(TableColumn.FILL, numPixel);
+}
+/**
+ * Scroll vertically by 'scrollIndexCount' items.
+ * @param scrollIndexCount - the number of items to scroll.
+ * scrollIndexCount > 0 = scroll up. scrollIndexCount < 0 = scroll down
+ */
+void scrollVertical(int scrollIndexCount) {
+ int scrollAmount = scrollIndexCount * getItemHeight();
+ int headerHeight = getHeaderHeight();
+ int destY;
+ int sourceY;
+ boolean scrollUp = scrollIndexCount < 0;
+ Rectangle clientArea = getClientArea();
+
+ if (scrollIndexCount == 0) {
+ return;
+ }
+ if (scrollUp == true) {
+ destY = headerHeight - scrollAmount;
+ sourceY = headerHeight;
+ }
+ else {
+ destY = headerHeight;
+ sourceY = destY + scrollAmount;
+ }
+ scroll(
+ 0, destY, // destination x, y
+ 0, sourceY, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Scroll items down to make space for a new item added to
+ * the receiver at position 'index'.
+ * @param index - position at which space for one new item
+ * should be made. This index is relative to the first item
+ * of the receiver.
+ */
+void scrollVerticalAddingItem(int index) {
+ int itemHeight = getItemHeight();
+ int sourceY = getHeaderHeight();
+ Rectangle clientArea = getClientArea();
+
+ if (index >= getTopIndex()) {
+ sourceY += (index-getTopIndex()) * itemHeight;
+ }
+ scroll(
+ 0, sourceY + itemHeight, // destination x, y
+ 0, sourceY, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Scroll the items below the item at position 'index' up
+ * so that they cover the removed item.
+ * @param index - index of the removed item
+ */
+void scrollVerticalRemovedItem(int index) {
+ int itemHeight = getItemHeight();
+ int headerHeight = getHeaderHeight();
+ int destY;
+ Rectangle clientArea = getClientArea();
+
+ destY = Math.max(headerHeight, headerHeight + (index - getTopIndex()) * itemHeight);
+ scroll(
+ 0, destY, // destination x, y
+ 0, destY + itemHeight, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * If the item at the given zero-relative index in the receiver
+ * is not selected, it is selected. If the item at the index
+ * was selected, it remains selected. Indices that are out
+ * of range and duplicate 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>
+ */
+public void select(int indices[]) {
+ checkWidget();
+ SelectableItem item = null;
+ int selectionCount;
+
+ if (indices == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ selectionCount = indices.length;
+ if (isMultiSelect() == false && selectionCount > 1) {
+ selectionCount = 1;
+ deselectAllExcept(getVisibleItem(indices[0]));
+ }
+ for (int i = selectionCount - 1; i >= 0; --i) {
+ item = getVisibleItem(indices[i]);
+ if (item != null) {
+ select(item);
+ }
+ }
+ if (item != null) {
+ setLastSelection(item, 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();
+ SelectableItem item = getVisibleItem(index);
+
+ if (isMultiSelect() == false) {
+ deselectAllExcept(getVisibleItem(index));
+ }
+ if (item != null) {
+ select(item);
+ setLastSelection(item, false);
+ }
+}
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * If the item at the index was already selected, it remains
+ * selected. The range of the indices is inclusive. Indices that are
+ * out of range 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>
+ */
+public void select(int start, int end) {
+ checkWidget();
+ SelectableItem item = null;
+
+ if (isMultiSelect() == false) {
+ if (start < 0 && end >= 0) {
+ start = 0;
+ }
+ end = start;
+ deselectAllExcept(getVisibleItem(end));
+ }
+ // select in the same order as all the other selection and deslection methods.
+ // Otherwise setLastSelection repeatedly changes the lastSelectedItem for repeated
+ // selections of the items, causing flash.
+ for (int i = end; i >= start; i--) {
+ item = getVisibleItem(i);
+ if (item != null) {
+ select(item);
+ }
+ }
+ if (item != null) {
+ setLastSelection(item, false);
+ }
+}
+/**
+ * Selects all 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 void selectAll() {
+ checkWidget();
+ Enumeration items = getItemVector().elements();
+ TableItem item = null;
+
+ if (isMultiSelect() == false) {
+ return;
+ }
+ while (items.hasMoreElements() == true) {
+ item = (TableItem) items.nextElement();
+ select(item);
+ }
+ if (item != null) {
+ setLastSelection(item, false);
+ }
+}
+/**
+ * Set the y position of 'column'.
+ * @param column - the TableColumn that should be set to
+ * a new y position.
+ */
+void setColumnPosition(TableColumn column) {
+ Rectangle bounds = column.getBounds();
+
+ bounds.y = getHeaderHeight() - getTopIndex() * getItemHeight();
+ column.setBounds(bounds);
+}
+/**
+ * Change the cursor of the receiver.
+ * @param isColumnResizeCursor - indicates whether the column
+ * resize cursor or the regular cursor should be set.
+ */
+void setColumnResizeCursor(boolean isColumnResizeCursor) {
+ if (isColumnResizeCursor != this.isColumnResizeCursor) {
+ this.isColumnResizeCursor = isColumnResizeCursor;
+ if (isColumnResizeCursor == true) {
+ setCursor(getColumnResizeCursor());
+ }
+ else {
+ setCursor(null);
+ }
+ }
+}
+/**
+ * Set the current position of the resized column to 'xPosition'.
+ * @param xPosition - the current position of the resized column
+ */
+void setColumnResizeX(int xPosition) {
+ columnResizeX = xPosition;
+}
+/**
+ * Set the width of the receiver's contents to 'newWidth'.
+ * Content width is used to calculate the horizontal scrollbar.
+ */
+void setContentWidth(int newWidth) {
+ TableColumn fillColumn = getFillColumn();
+ Rectangle fillColumnBounds;
+ int widthDiff = newWidth - getContentWidth();
+
+ super.setContentWidth(newWidth);
+ if (fillColumn != null) {
+ fillColumnBounds = fillColumn.getBounds();
+ fillColumnBounds.x += widthDiff;
+ fillColumnBounds.width = Math.max(0, getClientArea().width - newWidth);
+ fillColumn.setBounds(fillColumnBounds);
+ }
+}
+/**
+ * Set the width of the first column to fit 'item' if it is longer than
+ * the current column width.
+ * Do nothing if the user has already set a width.
+ */
+void setFirstColumnWidth(TableItem item) {
+ int newWidth;
+ TableColumn column;
+
+ if (internalGetColumnCount() > 0) {
+ column = internalGetColumn(TableColumn.FIRST);
+ if (column.isDefaultWidth() == true) {
+ newWidth = Math.max(column.getWidth(), item.getPreferredWidth(TableColumn.FIRST));
+ column.setWidth(newWidth);
+ column.setDefaultWidth(true); // reset to true so that we know when the user has set
+ // the width instead of us setting a default width.
+ }
+ }
+}
+public void setFont(Font font) {
+ checkWidget();
+ int itemCount = getItemCount();
+
+ if (font == null || font.equals(getFont()) == true) {
+ return;
+ }
+ setRedraw(false); // disable redraw because itemChanged() triggers undesired redraw
+ resetItemData();
+ super.setFont(font);
+
+ GC gc = new GC(this);
+ Point extent = gc.stringExtent(DOT_STRING);
+ dotsWidth = extent.x;
+ fontHeight = extent.y;
+ gc.dispose();
+
+ for (int i = 0; i < itemCount; i++) {
+ itemChanged(getItem(i), 0, getClientArea().width);
+ }
+ setRedraw(true); // re-enable redraw
+ getHeader().setFont(font);
+}
+/**
+ * Marks the receiver's header as visible if the argument is <code>true</code>,
+ * and marks it invisible otherwise.
+ * <p>
+ * If one of the receiver's ancestors is not visible or some
+ * other condition makes the receiver not visible, marking
+ * it visible may not actually cause it to be displayed.
+ * </p>
+ *
+ * @param 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 setHeaderVisible(boolean headerVisible) {
+ checkWidget();
+ if (headerVisible != getHeaderVisible()) {
+ getHeader().setLocation(0, 0);
+ getHeader().setVisible(headerVisible);
+ // Windows resets scrolling so do we
+ setTopIndex(0, true);
+ moveColumnsVertical();
+ resizeVerticalScrollbar();
+ redraw();
+ }
+}
+/**
+ * Set the vector that stores the items of the receiver
+ * to 'newVector'.
+ * @param newVector - Vector to use for storing the items of
+ * the receiver.
+ */
+void setItemVector(Vector newVector) {
+ items = newVector;
+}
+/**
+ * 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 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 setLinesVisible(boolean drawGridLines) {
+ checkWidget();
+ if (this.drawGridLines != drawGridLines) {
+ this.drawGridLines = drawGridLines;
+ redraw();
+ }
+}
+public void setRedraw(boolean redraw) {
+ checkWidget();
+ super.setRedraw(redraw);
+ getHeader().setRedraw(redraw);
+}
+/**
+ * Set the column that is being resized to 'column'.
+ * @param column - the TableColumn that is being resized.
+ * A null value indicates that no column resize operation is
+ * in progress.
+ */
+void setResizeColumn(TableColumn column) {
+ resizeColumn = column;
+}
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * The current selected is first cleared, then the new items are selected.
+ *
+ * @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();
+ Vector keepSelected;
+
+ if (indices == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ keepSelected = new Vector(indices.length);
+ for (int i = 0; i < indices.length; i++) {
+ SelectableItem item = getVisibleItem(indices[i]);
+ if (item != null) {
+ keepSelected.addElement(item);
+ }
+ }
+ deselectAllExcept(keepSelected);
+ select(indices);
+ showSelection ();
+}
+/**
+ * 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 array of items is null</li>
+ * <li>ERROR_INVALID_ARGUMENT - if one of 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#deselectAll()
+ * @see Table#select(int)
+ */
+public void setSelection(TableItem selectionItems[]) {
+ checkWidget();
+ if (selectionItems == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ setSelectableSelection(selectionItems);
+}
+/**
+ * Selects the item at the given zero-relative index in the receiver.
+ * The current selected 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();
+ deselectAllExcept(getVisibleItem(index));
+ select(index);
+ showSelection ();
+}
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * The current selected if first cleared, then the new items are selected.
+ *
+ * @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();
+ Vector keepSelected = new Vector();
+
+ for (int i = start; i <= end; i++) {
+ SelectableItem item = getVisibleItem(i);
+ if (item != null) {
+ keepSelected.addElement(item);
+ }
+ }
+ deselectAllExcept(keepSelected);
+ select(start, end);
+ 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 itemCount = getItemCount();
+ int itemCountWhole = getItemCountWhole();
+ if (index < 0 || itemCount == 0) return;
+ if (index >= itemCount) index = itemCount - 1;
+ if (itemCount > itemCountWhole) {
+ if (index + itemCountWhole <= itemCount) {
+ setTopIndex(index, true);
+ } else if (index > itemCount - itemCountWhole) {
+ setTopIndex(itemCount - itemCountWhole, true);
+ } else {
+ showSelectableItem(index);
+ }
+ }
+}
+/**
+ * Set the index of the first visible item in the receiver's client
+ * area to 'index'.
+ * @param index - 0-based index of the first visible item in the
+ * receiver's client area.
+ * @param adjustScrollbar - true=set the position of the vertical
+ * scroll bar to the new top index.
+ * false=don't adjust the vertical scroll bar
+ */
+void setTopIndexNoScroll(int index, boolean adjustScrollbar) {
+ super.setTopIndexNoScroll(index, adjustScrollbar);
+ moveColumnsVertical();
+}
+/**
+ * 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);
+ showSelectableItem(item);
+}
+/**
+ * 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 IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
+ super.showSelection();
+}
+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;
+ }
+ }
+ }
+ }
+}
+/**
+ * Start a column resize operation.
+ * @param event - the mouse event that occured over the header
+ * widget
+ */
+void startColumnResize(Event event) {
+ Vector columns = internalGetColumnVector();
+ TableColumn hitColumn = getColumnAtX(event.x);
+ Rectangle hitColumnBounds;
+ int hitIndex = hitColumn.getIndex();
+
+ if (hitColumn == getFillColumn()) { // clicked on the fill column?
+ hitColumn = (TableColumn) columns.lastElement(); // resize the last real column
+ }
+ else
+ if ((event.x - hitColumn.getBounds().x <= COLUMN_RESIZE_OFFSET) && // check if left side of a column was clicked
+ (hitIndex > 0)) {
+ hitColumn = (TableColumn) columns.elementAt(hitIndex - 1); // resize the preceding column
+ }
+ hitColumnBounds = hitColumn.getBounds();
+ setColumnResizeX(hitColumnBounds.x + hitColumnBounds.width);
+ setResizeColumn(hitColumn);
+}
+/**
+ * Return 'text' after it has been checked to be no longer than 'maxWidth'
+ * when drawn on 'gc'.
+ * If it is too long it will be truncated up to the last character.
+ * @param text - the String that should be checked for length
+ * @param maxWidth - maximum width of 'text'
+ * @param gc - GC to use for String measurement
+ */
+String trimItemText(String text, int maxWidth, GC gc) {
+ int textWidth;
+ int dotsWidth;
+
+ if (text != null && text.length() > 1) {
+ textWidth = gc.stringExtent(text).x;
+ if (textWidth > maxWidth) {
+ dotsWidth = getDotsWidth(gc);
+ while (textWidth + dotsWidth > maxWidth && text.length() > 1) {
+ text = text.substring(0, text.length() - 1); // chop off one character at the end
+ textWidth = gc.stringExtent(text).x;
+ }
+ text = text.concat(Table.DOT_STRING);
+ }
+ }
+ return text;
+}
+
+}
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
index 4dfefadc65..ffd2bfddbd 100644
--- 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
@@ -1,536 +1,536 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * <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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class TableColumn extends Item {
- static final int FIRST = 0; // index of the first column
- static final int FILL = -1; // index that identifies the column used to
- // fill space not used by other columns.
- private static final int DEFAULT_WIDTH = 10;
-
- private Table parent;
- private int index; // 0-based column index
- private Rectangle bounds = new Rectangle(0, 0, 0, 0);
- private boolean isDefaultWidth = true;
- private boolean resize = true;
-
-/**
- * Create a new TableColumn without adding it to the parent.
- * Currently used to create fill columns and default columns.
- * @see createFillColumn
- * @see createDefaultColumn
- * @param parent - Table widget the new instance will be a child of.
+
+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.
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>LEFT, RIGHT, CENTER</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd> Move, Resize, Selection</dd>
+ * </dl>
+ * <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>
*/
-TableColumn(Table parent) {
- super(parent, SWT.NULL);
- this.parent = parent;
-}
-
-/**
- * Constructs a new instance of this class given its parent
- * (which must be a <code>Table</code>) and a style value
- * describing its behavior and appearance. The item is added
- * to the end of the items maintained by its parent.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT#LEFT
- * @see SWT#RIGHT
- * @see SWT#CENTER
- * @see Widget#checkSubclass
- * @see Widget#getStyle
+public class TableColumn extends Item {
+ static final int FIRST = 0; // index of the first column
+ static final int FILL = -1; // index that identifies the column used to
+ // fill space not used by other columns.
+ private static final int DEFAULT_WIDTH = 10;
+
+ private Table parent;
+ private int index; // 0-based column index
+ private Rectangle bounds = new Rectangle(0, 0, 0, 0);
+ private boolean isDefaultWidth = true;
+ private boolean resize = true;
+
+/**
+ * Create a new TableColumn without adding it to the parent.
+ * Currently used to create fill columns and default columns.
+ * @see createFillColumn
+ * @see createDefaultColumn
+ * @param parent - Table widget the new instance will be a child of.
*/
-public TableColumn(Table parent, int style) {
- this(parent, style, checkNull(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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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
+TableColumn(Table parent) {
+ super(parent, SWT.NULL);
+ this.parent = parent;
+}
+
+/**
+ * Constructs a new instance of this class given its parent
+ * (which must be a <code>Table</code>) and a style value
+ * describing its behavior and appearance. The item is added
+ * to the end of the items maintained by its parent.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
+ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
+ * </ul>
+ *
+ * @see SWT#LEFT
+ * @see SWT#RIGHT
+ * @see SWT#CENTER
+ * @see Widget#checkSubclass
+ * @see Widget#getStyle
*/
-public TableColumn(Table parent, int style, int index) {
- super(parent, checkStyle (style), index);
-
- this.parent = parent;
- if (index < 0 || index > parent.getColumnCount()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- setIndex(index);
- parent.addColumn(this);
- setWidth(DEFAULT_WIDTH);
- setDefaultWidth(true);
- addListener(SWT.Dispose, new Listener() {
- public void handleEvent(Event event) {disposeColumn();}
- });
-}
-/**
- * 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 TableColumn(Table parent, int style) {
+ this(parent, style, checkNull(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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 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 TableColumn(Table parent, int style, int index) {
+ super(parent, checkStyle (style), index);
+
+ this.parent = parent;
+ if (index < 0 || index > parent.getColumnCount()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ setIndex(index);
+ parent.addColumn(this);
+ setWidth(DEFAULT_WIDTH);
+ setDefaultWidth(true);
+ addListener(SWT.Dispose, new Listener() {
+ public void handleEvent(Event event) {disposeColumn();}
+ });
+}
+/**
+ * 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 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);
-}
-/**
- * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'table' is null.
- * Otherwise return 'table'
+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
*/
-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);
-}
-/**
- * Create a new instance of TableColumn that acts as a default column
- * if the user does not create a TableColumn.
- * @param parent - Table widget the new instance will be a child of.
+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);
+}
+/**
+ * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'table' is null.
+ * Otherwise return 'table'
*/
-static TableColumn createDefaultColumn(Table parent) {
- TableColumn defaultColumn = new TableColumn(parent);
-
- defaultColumn.setIndex(FIRST);
- defaultColumn.setWidth(DEFAULT_WIDTH);
- defaultColumn.setDefaultWidth(true);
- return defaultColumn;
-}
-/**
- * Create a new instance of TableColumn that acts as the rightmost
- * fill column in a Table. The new object is not added to the parent
- * like a regular column is.
- * @param parent - Table widget the new instance will be a child of.
+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);
+}
+/**
+ * Create a new instance of TableColumn that acts as a default column
+ * if the user does not create a TableColumn.
+ * @param parent - Table widget the new instance will be a child of.
*/
-static TableColumn createFillColumn(Table parent) {
- TableColumn fillColumn = new TableColumn(parent);
-
- fillColumn.setIndex(FILL);
- return fillColumn;
-}
-/**
- * Remove the receiver from its parent
+static TableColumn createDefaultColumn(Table parent) {
+ TableColumn defaultColumn = new TableColumn(parent);
+
+ defaultColumn.setIndex(FIRST);
+ defaultColumn.setWidth(DEFAULT_WIDTH);
+ defaultColumn.setDefaultWidth(true);
+ return defaultColumn;
+}
+/**
+ * Create a new instance of TableColumn that acts as the rightmost
+ * fill column in a Table. The new object is not added to the parent
+ * like a regular column is.
+ * @param parent - Table widget the new instance will be a child of.
*/
-void disposeColumn() {
- getParent().removeColumn(this);
-}
-/**
- * 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>
+static TableColumn createFillColumn(Table parent) {
+ TableColumn fillColumn = new TableColumn(parent);
+
+ fillColumn.setIndex(FILL);
+ return fillColumn;
+}
+/**
+ * Remove the receiver from its parent
*/
-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;
-}
-
-/**
- * Answer the bounding rectangle of the receiver.
+void disposeColumn() {
+ getParent().removeColumn(this);
+}
+/**
+ * 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>
*/
-Rectangle getBounds() {
- return new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height); // copy the object to prevent changes
-}
-public Display getDisplay() {
- if (parent == null) { // access parent field directly to prevent endless recursion
- error(SWT.ERROR_WIDGET_DISPOSED);
- }
- return parent.getDisplay();
-}
-/**
- * Answer the index of the receiver. Specifies the position of the
- * receiver relative to other columns in the parent.
+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;
+}
+
+/**
+ * Answer the bounding rectangle of the receiver.
*/
-int getIndex() {
- return index;
-}
-/**
- * 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>
+Rectangle getBounds() {
+ return new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height); // copy the object to prevent changes
+}
+public Display getDisplay() {
+ if (parent == null) { // access parent field directly to prevent endless recursion
+ error(SWT.ERROR_WIDGET_DISPOSED);
+ }
+ return parent.getDisplay();
+}
+/**
+ * Answer the index of the receiver. Specifies the position of the
+ * receiver relative to other columns in the parent.
*/
-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>
+int getIndex() {
+ return index;
+}
+/**
+ * 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 boolean getResizable() {
- checkWidget();
- return resize;
-}
-/**
- * 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 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 int getWidth () {
- checkWidget();
- return getBounds().width;
-}
-/**
- * Set the colun bounds.
+public boolean getResizable() {
+ checkWidget();
+ return resize;
+}
+/**
+ * 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>
*/
-void internalSetBounds(Rectangle newBounds) {
- bounds = newBounds;
-}
-/**
- * Answer whether the column has a default width or if a width has been
- * set by the user.
- * @return
- * true=column width is a default width set internally
- * false=column width has been set by the user.
+public int getWidth () {
+ checkWidget();
+ return getBounds().width;
+}
+/**
+ * Set the colun bounds.
*/
-boolean isDefaultWidth() {
- return isDefaultWidth;
-}
-/**
- * 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>
- *
+void internalSetBounds(Rectangle newBounds) {
+ bounds = newBounds;
+}
+/**
+ * Answer whether the column has a default width or if a width has been
+ * set by the user.
+ * @return
+ * true=column width is a default width set internally
+ * false=column width has been set by the user.
*/
-public void pack() {
- checkWidget();
- Table parent = getParent();
- int index = parent.indexOf(this);
-
- if (getIndex() != TableColumn.FILL && index != -1) {
- setWidth(parent.getPreferredColumnWidth(index));
- }
-}
-
-/**
- * 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+boolean isDefaultWidth() {
+ return isDefaultWidth;
+}
+/**
+ * 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 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 pack() {
+ checkWidget();
+ Table parent = getParent();
+ int index = parent.indexOf(this);
+
+ if (getIndex() != TableColumn.FILL && index != -1) {
+ setWidth(parent.getPreferredColumnWidth(index));
+ }
+}
+
+/**
+ * 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 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 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 setAlignment(int alignment) {
- checkWidget();
- int index = getIndex();
-
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) != 0 && index != 0) { // ignore calls for the first column to match Windows behavior
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- getParent().getHeader().redraw(index);
- }
-}
-/**
- * Set the bounding rectangle of the receiver to 'newBounds'.
- * Notify the table widget if the column width changes.
- * @param newBounds - the new bounding rectangle of the receiver,
- * consisting of x, y, width, height
+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>
*/
-void setBounds(Rectangle newBounds) {
- if (newBounds.width != bounds.width) {
- if (isDefaultWidth() == true) {
- setDefaultWidth(false);
- }
- getParent().columnChange(this, newBounds);
- }
- else {
- // columnChange causes update (via scroll) which may flush redraw
- // based on old bounds. Setting bounds after notifying table fixes 1GABZR5
- // Table sets column bounds at appropriate time when called above with
- // width change. Only set bounds when table was not called. Fixes 1GCGDPB
- bounds = newBounds;
- }
-}
-/**
- * Set whether the column has a default width or if a width has been
- * set by the user.
- * @param isDefaultWidth
- * true=column width is a default width set internally
- * false=column width has been set by the user
+public void setAlignment(int alignment) {
+ checkWidget();
+ int index = getIndex();
+
+ if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) != 0 && index != 0) { // ignore calls for the first column to match Windows behavior
+ style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
+ style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
+ getParent().getHeader().redraw(index);
+ }
+}
+/**
+ * Set the bounding rectangle of the receiver to 'newBounds'.
+ * Notify the table widget if the column width changes.
+ * @param newBounds - the new bounding rectangle of the receiver,
+ * consisting of x, y, width, height
*/
-void setDefaultWidth(boolean isDefaultWidth) {
- this.isDefaultWidth = isDefaultWidth;
-}
-public void setImage(Image image) {
- super.setImage(image);
- Header header = parent.getHeader();
- header.setHeaderHeight();
- header.redraw();
- parent.redraw();
-}
-/**
- * Set the index of the receiver to 'newIndex'. The index specifies the
- * position of the receiver relative to other columns in the parent.
+void setBounds(Rectangle newBounds) {
+ if (newBounds.width != bounds.width) {
+ if (isDefaultWidth() == true) {
+ setDefaultWidth(false);
+ }
+ getParent().columnChange(this, newBounds);
+ }
+ else {
+ // columnChange causes update (via scroll) which may flush redraw
+ // based on old bounds. Setting bounds after notifying table fixes 1GABZR5
+ // Table sets column bounds at appropriate time when called above with
+ // width change. Only set bounds when table was not called. Fixes 1GCGDPB
+ bounds = newBounds;
+ }
+}
+/**
+ * Set whether the column has a default width or if a width has been
+ * set by the user.
+ * @param isDefaultWidth
+ * true=column width is a default width set internally
+ * false=column width has been set by the user
*/
-void setIndex(int newIndex) {
- this.index = newIndex;
-}
-/**
- * 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>
+void setDefaultWidth(boolean isDefaultWidth) {
+ this.isDefaultWidth = isDefaultWidth;
+}
+public void setImage(Image image) {
+ super.setImage(image);
+ Header header = parent.getHeader();
+ header.setHeaderHeight();
+ header.redraw();
+ parent.redraw();
+}
+/**
+ * Set the index of the receiver to 'newIndex'. The index specifies the
+ * position of the receiver relative to other columns in the parent.
*/
-public void setResizable(boolean resize) {
- checkWidget();
- this.resize = resize;
-}
-public void setText(String newText) {
- checkWidget();
- int index = getIndex();
-
- if (newText == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (index != FILL && (text == null || text.equals(newText) == false)) {
- super.setText(newText);
- getParent().getHeader().redraw(index);
- }
-}
-/**
- * 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>
+void setIndex(int newIndex) {
+ this.index = newIndex;
+}
+/**
+ * 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 setWidth(int width) {
- checkWidget();
- Rectangle bounds = getBounds();
- int oldWidth = bounds.width;
- int redrawX;
-
- if (width != oldWidth) {
- redrawX = bounds.x;
- bounds.width = width;
- setBounds(bounds);
- // redraw at old column position if column was resized wider.
- // fixes focus rectangle.
- redrawX += Math.min(width, oldWidth);
- parent.redraw(
- redrawX - 2, 0,
- 2, parent.getClientArea().height, false); // redraw 2 pixels wide to redraw item focus rectangle and grid line
- }
-
- sendEvent(SWT.Resize, new Event ());
- int count = parent.getColumnCount();
- for (int i = index + 1; i < count; i++) {
- parent.getColumn(i).sendEvent(SWT.Move, new Event ());
- }
-}
-}
+public void setResizable(boolean resize) {
+ checkWidget();
+ this.resize = resize;
+}
+public void setText(String newText) {
+ checkWidget();
+ int index = getIndex();
+
+ if (newText == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (index != FILL && (text == null || text.equals(newText) == false)) {
+ super.setText(newText);
+ getParent().getHeader().redraw(index);
+ }
+}
+/**
+ * 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();
+ Rectangle bounds = getBounds();
+ int oldWidth = bounds.width;
+ int redrawX;
+
+ if (width != oldWidth) {
+ redrawX = bounds.x;
+ bounds.width = width;
+ setBounds(bounds);
+ // redraw at old column position if column was resized wider.
+ // fixes focus rectangle.
+ redrawX += Math.min(width, oldWidth);
+ parent.redraw(
+ redrawX - 2, 0,
+ 2, parent.getClientArea().height, false); // redraw 2 pixels wide to redraw item focus rectangle and grid line
+ }
+
+ sendEvent(SWT.Resize, new Event ());
+ int count = parent.getColumnCount();
+ for (int i = index + 1; i < count; i++) {
+ parent.getColumn(i).sendEvent(SWT.Move, new Event ());
+ }
+}
+}
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
index f4f0b02fb8..cafaf2b892 100644
--- 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
@@ -1,1257 +1,1257 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.util.Vector;
-
-/**
- * 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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class TableItem extends SelectableItem {
- private static final int FIRST_COLUMN_IMAGE_INDENT = 2; // Space in front of image - first column only
- private static final int FIRST_COLUMN_TEXT_INDENT = 4; // Space in front of text - first column only
- private static final int TEXT_INDENT_NO_IMAGE = 2; // Space in front of item text when no item in the column has an image - first column only
- private static final int TEXT_INDENT = 6; // Space in front of item text - all other columns
- private static final int SELECTION_PADDING = 6; // Space behind text in a selected item
-
- private Vector dataLabels = new Vector(); // Original text set by the user. Items that don't
- // have a label are represented by a null slot
- private String[] trimmedLabels; // Text that is actually displayed, may be trimmed
- // to fit the column
- private Vector images = new Vector(); // Item images. Items that don't have an image
- // are represented by a null slot
- private Point selectionExtent; // Size of the rectangle drawn to indicate a
- // selected item.
- private int imageIndent = 0; // the factor by which the item image and check box, if any,
- // are indented. The multiplier is the image width.
- private int index; // index of the item in the parent widget
-
- Color background = null;
- Color foreground = null;
-
-/**
- * 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
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import java.util.Vector;
+
+/**
+ * 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 TableItem(Table parent, int style) {
- this(parent, style, checkNull(parent).getItemCount());
-}
-
-/**
- * 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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 class TableItem extends SelectableItem {
+ private static final int FIRST_COLUMN_IMAGE_INDENT = 2; // Space in front of image - first column only
+ private static final int FIRST_COLUMN_TEXT_INDENT = 4; // Space in front of text - first column only
+ private static final int TEXT_INDENT_NO_IMAGE = 2; // Space in front of item text when no item in the column has an image - first column only
+ private static final int TEXT_INDENT = 6; // Space in front of item text - all other columns
+ private static final int SELECTION_PADDING = 6; // Space behind text in a selected item
+
+ private Vector dataLabels = new Vector(); // Original text set by the user. Items that don't
+ // have a label are represented by a null slot
+ private String[] trimmedLabels; // Text that is actually displayed, may be trimmed
+ // to fit the column
+ private Vector images = new Vector(); // Item images. Items that don't have an image
+ // are represented by a null slot
+ private Point selectionExtent; // Size of the rectangle drawn to indicate a
+ // selected item.
+ private int imageIndent = 0; // the factor by which the item image and check box, if any,
+ // are indented. The multiplier is the image width.
+ private int index; // index of the item in the parent widget
+
+ Color background = null;
+ Color foreground = null;
+
+/**
+ * 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, int index) {
- super(parent, style);
- trimmedLabels = new String[parent.internalGetColumnCount()];
- parent.addItem(this, index);
-}
-
-/**
- * Calculate the size of the rectangle drawn to indicate a selected
- * item. This is also used to draw the selection focus rectangle.
- * The selection extent is calculated for the first column only (the
- * only column the selection is drawn in).
+public TableItem(Table parent, int style) {
+ this(parent, style, checkNull(parent).getItemCount());
+}
+
+/**
+ * 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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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
*/
-void calculateSelectionExtent() {
- Table parent = getParent();
- TableColumn column = parent.internalGetColumn(TableColumn.FIRST);
- GC gc = new GC(parent);
- String trimmedText = getText(gc, column);
- int gridLineWidth = parent.getGridLineWidth();
-
- if (trimmedText != null) {
- selectionExtent = new Point(gc.stringExtent(trimmedText).x, parent.getItemHeight());
- selectionExtent.x += getTextIndent(TableColumn.FIRST) + SELECTION_PADDING;
- selectionExtent.x = Math.min(
- selectionExtent.x, column.getWidth() - getImageStopX(column.getIndex()) - gridLineWidth);
- if (parent.getLinesVisible() == true) {
- selectionExtent.y -= gridLineWidth;
- }
- }
- gc.dispose();
-}
-/**
- * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'table' is null.
- * Otherwise return 'table'
+public TableItem(Table parent, int style, int index) {
+ super(parent, style);
+ trimmedLabels = new String[parent.internalGetColumnCount()];
+ parent.addItem(this, index);
+}
+
+/**
+ * Calculate the size of the rectangle drawn to indicate a selected
+ * item. This is also used to draw the selection focus rectangle.
+ * The selection extent is calculated for the first column only (the
+ * only column the selection is drawn in).
*/
-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);
-}
-public void dispose() {
- if (isDisposed()) return;
- Table parent = getParent();
- parent.removeItem(this);
- super.dispose();
-}
-void doDispose() {
- dataLabels = null;
- trimmedLabels = null;
- images = null;
- selectionExtent = null;
- super.doDispose();
-}
-
-/**
- * Draw the image of the receiver for column 'index' at
- * 'destinationPosition' using 'gc'.
- * Stretch/shrink the image to the fixed image size of the receiver's
- * parent.
- * @param gc - GC to draw on.
- * @param destinationPosition - position on the GC to draw at.
- * @param index - index of the image to draw
- * @return Answer the position where drawing stopped.
+void calculateSelectionExtent() {
+ Table parent = getParent();
+ TableColumn column = parent.internalGetColumn(TableColumn.FIRST);
+ GC gc = new GC(parent);
+ String trimmedText = getText(gc, column);
+ int gridLineWidth = parent.getGridLineWidth();
+
+ if (trimmedText != null) {
+ selectionExtent = new Point(gc.stringExtent(trimmedText).x, parent.getItemHeight());
+ selectionExtent.x += getTextIndent(TableColumn.FIRST) + SELECTION_PADDING;
+ selectionExtent.x = Math.min(
+ selectionExtent.x, column.getWidth() - getImageStopX(column.getIndex()) - gridLineWidth);
+ if (parent.getLinesVisible() == true) {
+ selectionExtent.y -= gridLineWidth;
+ }
+ }
+ gc.dispose();
+}
+/**
+ * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'table' is null.
+ * Otherwise return 'table'
*/
-Point drawImage(GC gc, Point destinationPosition, int index) {
- Table parent = getParent();
- Image image = getImage(index);
- Rectangle sourceImageBounds;
- Point destinationImageExtent = parent.getImageExtent();
- int imageOffset;
-
- if (image != null) {
- sourceImageBounds = image.getBounds();
- // full row select would obscure transparent images in all but the first column
- // so always clear the image area in this case. Fixes 1FYNITC
- if ((parent.getStyle() & SWT.FULL_SELECTION) != 0 && index != TableColumn.FIRST) {
- gc.fillRectangle(
- destinationPosition.x, destinationPosition.y,
- destinationImageExtent.x, destinationImageExtent.y);
- }
- imageOffset = (parent.getItemHeight() - destinationImageExtent.y) / 2;
- gc.drawImage(
- image, 0, 0, // source x, y
- sourceImageBounds.width, sourceImageBounds.height, // source width, height
- destinationPosition.x, destinationPosition.y + imageOffset, // destination x, y
- destinationImageExtent.x, destinationImageExtent.y); // destination width, height
- }
- if (((index == TableColumn.FIRST && // always add the image width for the first column
- parent.hasFirstColumnImage() == true) || // if any item in the first column has an image
- (index != TableColumn.FIRST && // add the image width if it's not the first column
- image != null)) && // only when the item actually has an image
- destinationImageExtent != null) {
- destinationPosition.x += destinationImageExtent.x;
- }
- return destinationPosition;
-}
-/**
- * Draw the label of the receiver for column 'index' at 'position'
- * using 'gc'.
- * The background color is set to the selection background color if
- * the item is selected and the text is drawn for the first column.
- * @param gc - GC to draw on.
- * @param position - position on the GC to draw at.
- * @param index - specifies which subitem text to draw
+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);
+}
+public void dispose() {
+ if (isDisposed()) return;
+ Table parent = getParent();
+ parent.removeItem(this);
+ super.dispose();
+}
+void doDispose() {
+ dataLabels = null;
+ trimmedLabels = null;
+ images = null;
+ selectionExtent = null;
+ super.doDispose();
+}
+
+/**
+ * Draw the image of the receiver for column 'index' at
+ * 'destinationPosition' using 'gc'.
+ * Stretch/shrink the image to the fixed image size of the receiver's
+ * parent.
+ * @param gc - GC to draw on.
+ * @param destinationPosition - position on the GC to draw at.
+ * @param index - index of the image to draw
+ * @return Answer the position where drawing stopped.
*/
-void drawText(String label, GC gc, Point position, int index) {
- Table parent = getParent();
- boolean drawSelection;
- int textOffset, alignmentOffset;
-
- if (label != null) {
- drawSelection = (index == TableColumn.FIRST || (parent.getStyle() & SWT.FULL_SELECTION) != 0);
- if (isSelected() == true && drawSelection == true) {
- gc.setForeground(getSelectionForegroundColor());
- } else {
- gc.setForeground(getForeground());
- }
- alignmentOffset = getAlignmentOffset (index, getBounds(index).width, gc);
- textOffset = (parent.getItemHeight() - parent.getFontHeight()) / 2; // vertically center the text
- gc.drawString(label, position.x + alignmentOffset, position.y + textOffset, true);
- }
-}
-int getAlignmentOffset(int columnIndex, int columnWidth, GC gc) {
- Table parent = getParent();
- TableColumn column = parent.internalGetColumn (columnIndex);
- Image image = getImage(columnIndex);
- int alignmentOffset = 0;
- int alignment = column.getAlignment();
- String label = getText(gc, column);
- int imageWidth = 0;
- int textWidth = gc.stringExtent (label).x;
- Point imageExtent = parent.getImageExtent();
- if (((columnIndex == TableColumn.FIRST && // always add the image width for the first column
- parent.hasFirstColumnImage() == true) || // if any item in the first column has an image
- (columnIndex != TableColumn.FIRST && // add the image width if it's not the first column
- image != null)) && // only when the item actually has an image
- imageExtent != null) {
- textWidth += imageExtent.x;
- }
- if ((alignment & SWT.RIGHT) != 0) {
- alignmentOffset = columnWidth - textWidth - imageWidth - TEXT_INDENT - TEXT_INDENT;
- }
- if ((alignment & SWT.CENTER) != 0) {
- alignmentOffset = ((columnWidth - textWidth) / 2) - imageWidth - TEXT_INDENT;
- }
- if (alignmentOffset < 0) alignmentOffset = 0;
- return alignmentOffset;
-}
-/**
- * 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
- *
+Point drawImage(GC gc, Point destinationPosition, int index) {
+ Table parent = getParent();
+ Image image = getImage(index);
+ Rectangle sourceImageBounds;
+ Point destinationImageExtent = parent.getImageExtent();
+ int imageOffset;
+
+ if (image != null) {
+ sourceImageBounds = image.getBounds();
+ // full row select would obscure transparent images in all but the first column
+ // so always clear the image area in this case. Fixes 1FYNITC
+ if ((parent.getStyle() & SWT.FULL_SELECTION) != 0 && index != TableColumn.FIRST) {
+ gc.fillRectangle(
+ destinationPosition.x, destinationPosition.y,
+ destinationImageExtent.x, destinationImageExtent.y);
+ }
+ imageOffset = (parent.getItemHeight() - destinationImageExtent.y) / 2;
+ gc.drawImage(
+ image, 0, 0, // source x, y
+ sourceImageBounds.width, sourceImageBounds.height, // source width, height
+ destinationPosition.x, destinationPosition.y + imageOffset, // destination x, y
+ destinationImageExtent.x, destinationImageExtent.y); // destination width, height
+ }
+ if (((index == TableColumn.FIRST && // always add the image width for the first column
+ parent.hasFirstColumnImage() == true) || // if any item in the first column has an image
+ (index != TableColumn.FIRST && // add the image width if it's not the first column
+ image != null)) && // only when the item actually has an image
+ destinationImageExtent != null) {
+ destinationPosition.x += destinationImageExtent.x;
+ }
+ return destinationPosition;
+}
+/**
+ * Draw the label of the receiver for column 'index' at 'position'
+ * using 'gc'.
+ * The background color is set to the selection background color if
+ * the item is selected and the text is drawn for the first column.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ * @param index - specifies which subitem text to draw
*/
-public Color getBackground(){
- checkWidget ();
- if (background != null) return background;
- Table parent = getParent();
- return parent.getBackground();
-}
-/**
- * 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>
+void drawText(String label, GC gc, Point position, int index) {
+ Table parent = getParent();
+ boolean drawSelection;
+ int textOffset, alignmentOffset;
+
+ if (label != null) {
+ drawSelection = (index == TableColumn.FIRST || (parent.getStyle() & SWT.FULL_SELECTION) != 0);
+ if (isSelected() == true && drawSelection == true) {
+ gc.setForeground(getSelectionForegroundColor());
+ } else {
+ gc.setForeground(getForeground());
+ }
+ alignmentOffset = getAlignmentOffset (index, getBounds(index).width, gc);
+ textOffset = (parent.getItemHeight() - parent.getFontHeight()) / 2; // vertically center the text
+ gc.drawString(label, position.x + alignmentOffset, position.y + textOffset, true);
+ }
+}
+int getAlignmentOffset(int columnIndex, int columnWidth, GC gc) {
+ Table parent = getParent();
+ TableColumn column = parent.internalGetColumn (columnIndex);
+ Image image = getImage(columnIndex);
+ int alignmentOffset = 0;
+ int alignment = column.getAlignment();
+ String label = getText(gc, column);
+ int imageWidth = 0;
+ int textWidth = gc.stringExtent (label).x;
+ Point imageExtent = parent.getImageExtent();
+ if (((columnIndex == TableColumn.FIRST && // always add the image width for the first column
+ parent.hasFirstColumnImage() == true) || // if any item in the first column has an image
+ (columnIndex != TableColumn.FIRST && // add the image width if it's not the first column
+ image != null)) && // only when the item actually has an image
+ imageExtent != null) {
+ textWidth += imageExtent.x;
+ }
+ if ((alignment & SWT.RIGHT) != 0) {
+ alignmentOffset = columnWidth - textWidth - imageWidth - TEXT_INDENT - TEXT_INDENT;
+ }
+ if ((alignment & SWT.CENTER) != 0) {
+ alignmentOffset = ((columnWidth - textWidth) / 2) - imageWidth - TEXT_INDENT;
+ }
+ if (alignmentOffset < 0) alignmentOffset = 0;
+ return alignmentOffset;
+}
+/**
+ * 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 Rectangle getBounds(int index) {
- checkWidget();
- Rectangle itemBounds;
- Rectangle columnBounds;
- Rectangle checkboxBounds;
- Table parent = getParent();
- TableColumn column;
- int itemIndex = parent.indexOf(this);
- int itemHeight = parent.getItemHeight();
- int gridLineWidth = parent.getLinesVisible() ? parent.getGridLineWidth() : 0;
- int itemYPos;
-
- if (itemIndex == -1 || index < 0 || index >= parent.internalGetColumnCount()) {
- itemBounds = new Rectangle(0, 0, 0, 0);
- }
- else {
- column = parent.internalGetColumn(index);
- columnBounds = column.getBounds();
- itemYPos = columnBounds.y + itemHeight * itemIndex;
- itemBounds = new Rectangle(
- columnBounds.x, itemYPos,
- columnBounds.width - gridLineWidth, itemHeight - gridLineWidth);
- if (index == TableColumn.FIRST) {
- if (isCheckable() == true) {
- checkboxBounds = getCheckboxBounds();
- itemBounds.x += checkboxBounds.x + checkboxBounds.width + CHECKBOX_PADDING; // add checkbox start, width and space behind checkbox
- itemBounds.width -= itemBounds.x;
- }
- else {
- itemBounds.x += getImageIndentPixel();
- }
- }
- }
- return itemBounds;
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK 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 Color getBackground(){
+ checkWidget ();
+ if (background != null) return background;
+ Table parent = getParent();
+ return parent.getBackground();
+}
+/**
+ * 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 boolean getChecked() {
- checkWidget();
- return super.getChecked();
-}
-/**
- * Answer the x position of the item check box
+public Rectangle getBounds(int index) {
+ checkWidget();
+ Rectangle itemBounds;
+ Rectangle columnBounds;
+ Rectangle checkboxBounds;
+ Table parent = getParent();
+ TableColumn column;
+ int itemIndex = parent.indexOf(this);
+ int itemHeight = parent.getItemHeight();
+ int gridLineWidth = parent.getLinesVisible() ? parent.getGridLineWidth() : 0;
+ int itemYPos;
+
+ if (itemIndex == -1 || index < 0 || index >= parent.internalGetColumnCount()) {
+ itemBounds = new Rectangle(0, 0, 0, 0);
+ }
+ else {
+ column = parent.internalGetColumn(index);
+ columnBounds = column.getBounds();
+ itemYPos = columnBounds.y + itemHeight * itemIndex;
+ itemBounds = new Rectangle(
+ columnBounds.x, itemYPos,
+ columnBounds.width - gridLineWidth, itemHeight - gridLineWidth);
+ if (index == TableColumn.FIRST) {
+ if (isCheckable() == true) {
+ checkboxBounds = getCheckboxBounds();
+ itemBounds.x += checkboxBounds.x + checkboxBounds.width + CHECKBOX_PADDING; // add checkbox start, width and space behind checkbox
+ itemBounds.width -= itemBounds.x;
+ }
+ else {
+ itemBounds.x += getImageIndentPixel();
+ }
+ }
+ }
+ return itemBounds;
+}
+
+/**
+ * Returns <code>true</code> if the receiver is checked,
+ * and false otherwise. When the parent does not have
+ * the <code>CHECK 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>
*/
-int getCheckboxXPosition() {
- return getImageIndentPixel();
-}
-/**
- * Answer the item labels set by the user.
- * These may not be the same as those drawn on the screen. The latter
- * may be trimmed to fit the column. Items that don't have a label are
- * represented by a null slot in the vector.
- * @return Vector - the item labels set by the user.
+public boolean getChecked() {
+ checkWidget();
+ return super.getChecked();
+}
+/**
+ * Answer the x position of the item check box
*/
-Vector getDataLabels() {
- return dataLabels;
-}
-public Display getDisplay() {
- return super.getDisplay();
-}
-/**
- * Return the position at which the string starts that is used
- * to indicate a truncated item text.
- * @param columnIndex - index of the column for which the position of
- * the truncation replacement should be calculated
- * @param columnWidth - width of the column for which the position of
- * the truncation replacement should be calculated
- * @return -1 when the item text is not truncated
+int getCheckboxXPosition() {
+ return getImageIndentPixel();
+}
+/**
+ * Answer the item labels set by the user.
+ * These may not be the same as those drawn on the screen. The latter
+ * may be trimmed to fit the column. Items that don't have a label are
+ * represented by a null slot in the vector.
+ * @return Vector - the item labels set by the user.
*/
-int getDotStartX(int columnIndex, int columnWidth) {
- GC gc;
- Table parent = getParent();
- String label = getText(columnIndex);
- int alignment = parent.internalGetColumn (columnIndex).getAlignment();
- int dotStartX = -1;
- int maxWidth;
-
- if (label != null) {
- gc = new GC(parent);
- dotStartX = getAlignmentOffset(columnIndex, columnWidth, gc);
- if ((alignment & SWT.LEFT) != 0) {
- maxWidth = getMaxTextWidth(columnIndex, columnWidth);
- label = parent.trimItemText(label, maxWidth, gc);
- if (label.endsWith(Table.DOT_STRING)) {
- dotStartX = gc.stringExtent(label).x - parent.getDotsWidth(gc);
- // add indents, margins and image width
- dotStartX += getImageStopX(columnIndex);
- dotStartX += getTextIndent(columnIndex);
- }
- }
- gc.dispose();
- }
- return dotStartX;
-}
-/**
- * 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
- *
+Vector getDataLabels() {
+ return dataLabels;
+}
+public Display getDisplay() {
+ return super.getDisplay();
+}
+/**
+ * Return the position at which the string starts that is used
+ * to indicate a truncated item text.
+ * @param columnIndex - index of the column for which the position of
+ * the truncation replacement should be calculated
+ * @param columnWidth - width of the column for which the position of
+ * the truncation replacement should be calculated
+ * @return -1 when the item text is not truncated
*/
-public Color getForeground(){
- checkWidget ();
- if (foreground != null) return foreground;
- Table parent = getParent();
- return parent.getForeground();
-}
-/**
- * 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>
+int getDotStartX(int columnIndex, int columnWidth) {
+ GC gc;
+ Table parent = getParent();
+ String label = getText(columnIndex);
+ int alignment = parent.internalGetColumn (columnIndex).getAlignment();
+ int dotStartX = -1;
+ int maxWidth;
+
+ if (label != null) {
+ gc = new GC(parent);
+ dotStartX = getAlignmentOffset(columnIndex, columnWidth, gc);
+ if ((alignment & SWT.LEFT) != 0) {
+ maxWidth = getMaxTextWidth(columnIndex, columnWidth);
+ label = parent.trimItemText(label, maxWidth, gc);
+ if (label.endsWith(Table.DOT_STRING)) {
+ dotStartX = gc.stringExtent(label).x - parent.getDotsWidth(gc);
+ // add indents, margins and image width
+ dotStartX += getImageStopX(columnIndex);
+ dotStartX += getTextIndent(columnIndex);
+ }
+ }
+ gc.dispose();
+ }
+ return dotStartX;
+}
+/**
+ * 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 boolean getGrayed() {
- checkWidget();
- return super.getGrayed();
-}
-public Image getImage() {
- checkWidget();
- return getImage(0);
-}
-/**
- * Returns the image stored at the given column index in the receiver,
- * or null if the image has not been set or if the column does not exist.
- *
- * @param index the column index
- * @return the image stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Color getForeground(){
+ checkWidget ();
+ if (foreground != null) return foreground;
+ Table parent = getParent();
+ return parent.getForeground();
+}
+/**
+ * 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 Image getImage(int columnIndex) {
- checkWidget();
- Image image = null;
- Vector images = getImages();
- int itemIndex = getParent().indexOf(this);
-
- if (itemIndex != -1 && columnIndex >= 0 && columnIndex < images.size()) {
- image = (Image) images.elementAt(columnIndex);
- }
- return image;
-}
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * table.
- *
- * @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 boolean getGrayed() {
+ checkWidget();
+ return super.getGrayed();
+}
+public Image getImage() {
+ checkWidget();
+ return getImage(0);
+}
+/**
+ * Returns the image stored at the given column index in the receiver,
+ * or null if the image has not been set or if the column does not exist.
+ *
+ * @param index the column index
+ * @return the image stored at the given column index in the receiver
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
*/
-public Rectangle getImageBounds(int index) {
- checkWidget();
- Table parent = getParent();
- int itemIndex = parent.indexOf (this);
- int imageWidth = 0;
- Point imageExtent = parent.getImageExtent();
- Rectangle imageBounds = getBounds(index);
-
- if (itemIndex == -1) {
- imageBounds = new Rectangle(0, 0, 0, 0);
- }
- else
- if (imageExtent != null) {
- if (index == TableColumn.FIRST || getImage(index) != null) {
- imageWidth = imageExtent.x;
- }
- }
- imageBounds.width = imageWidth;
- if (imageBounds.height > 0 && !parent.getLinesVisible()) {
- imageBounds.height -= parent.getGridLineWidth();
- }
- return imageBounds;
-}
-/**
- * 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 Image getImage(int columnIndex) {
+ checkWidget();
+ Image image = null;
+ Vector images = getImages();
+ int itemIndex = getParent().indexOf(this);
+
+ if (itemIndex != -1 && columnIndex >= 0 && columnIndex < images.size()) {
+ image = (Image) images.elementAt(columnIndex);
+ }
+ return image;
+}
+/**
+ * Returns a rectangle describing the size and location
+ * relative to its parent of an image at a column in the
+ * table.
+ *
+ * @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 int getImageIndent() {
- checkWidget();
- int index = getParent().indexOf(this);
-
- if (index == -1) {
- return 0;
- }
- return imageIndent;
-}
-/**
- * Answer the number of pixels the image in the first column is
- * indented. Calculation starts at the column start and counts
- * all pixels except the check box.
+public Rectangle getImageBounds(int index) {
+ checkWidget();
+ Table parent = getParent();
+ int itemIndex = parent.indexOf (this);
+ int imageWidth = 0;
+ Point imageExtent = parent.getImageExtent();
+ Rectangle imageBounds = getBounds(index);
+
+ if (itemIndex == -1) {
+ imageBounds = new Rectangle(0, 0, 0, 0);
+ }
+ else
+ if (imageExtent != null) {
+ if (index == TableColumn.FIRST || getImage(index) != null) {
+ imageWidth = imageExtent.x;
+ }
+ }
+ imageBounds.width = imageWidth;
+ if (imageBounds.height > 0 && !parent.getLinesVisible()) {
+ imageBounds.height -= parent.getGridLineWidth();
+ }
+ return imageBounds;
+}
+/**
+ * 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>
*/
-int getImageIndentPixel() {
- int indentPixel = FIRST_COLUMN_IMAGE_INDENT;
- Point imageExtent = getParent().getImageExtent();
-
- if (imageExtent != null) {
- indentPixel += imageExtent.x * getImageIndent();
- }
- return indentPixel;
-}
-/**
- * Answer the item images set by the user. Items that don't have an
- * image are represented by a null slot in the vector.
+public int getImageIndent() {
+ checkWidget();
+ int index = getParent().indexOf(this);
+
+ if (index == -1) {
+ return 0;
+ }
+ return imageIndent;
+}
+/**
+ * Answer the number of pixels the image in the first column is
+ * indented. Calculation starts at the column start and counts
+ * all pixels except the check box.
*/
-Vector getImages() {
- return images;
-}
-/**
- * Calculate the x coordinate where the item image of column
- * 'columnIndex' stops.
- * @param columnIndex - the column for which the stop position of the
- * image should be calculated.
+int getImageIndentPixel() {
+ int indentPixel = FIRST_COLUMN_IMAGE_INDENT;
+ Point imageExtent = getParent().getImageExtent();
+
+ if (imageExtent != null) {
+ indentPixel += imageExtent.x * getImageIndent();
+ }
+ return indentPixel;
+}
+/**
+ * Answer the item images set by the user. Items that don't have an
+ * image are represented by a null slot in the vector.
*/
-int getImageStopX(int columnIndex) {
- int imageStopX = 0;
- Table parent = getParent();
- Rectangle checkboxBounds;
-
- if (columnIndex == TableColumn.FIRST) {
- if (isCheckable() == true) {
- checkboxBounds = getCheckboxBounds();
- imageStopX += checkboxBounds.x + checkboxBounds.width + CHECKBOX_PADDING;
- }
- else {
- imageStopX = getImageIndentPixel();
- }
- }
- if (((columnIndex == TableColumn.FIRST && // always add the image width for the first column
- parent.hasFirstColumnImage() == true) || // if any item in the first column has an image
- (columnIndex != TableColumn.FIRST && // add the image width if it's not the first column
- getImage(columnIndex) != null)) && // only when the item actually has an image
- parent.getImageExtent() != null) {
- imageStopX += parent.getImageExtent().x;
- }
- return imageStopX;
-}
-/**
- * Return the index of the item in its parent widget.
+Vector getImages() {
+ return images;
+}
+/**
+ * Calculate the x coordinate where the item image of column
+ * 'columnIndex' stops.
+ * @param columnIndex - the column for which the stop position of the
+ * image should be calculated.
*/
-int getIndex() {
- return index;
-}
-/**
- * Return the item extent in the specified column
- * The extent includes the actual width of the item including checkbox,
- * image and text.
+int getImageStopX(int columnIndex) {
+ int imageStopX = 0;
+ Table parent = getParent();
+ Rectangle checkboxBounds;
+
+ if (columnIndex == TableColumn.FIRST) {
+ if (isCheckable() == true) {
+ checkboxBounds = getCheckboxBounds();
+ imageStopX += checkboxBounds.x + checkboxBounds.width + CHECKBOX_PADDING;
+ }
+ else {
+ imageStopX = getImageIndentPixel();
+ }
+ }
+ if (((columnIndex == TableColumn.FIRST && // always add the image width for the first column
+ parent.hasFirstColumnImage() == true) || // if any item in the first column has an image
+ (columnIndex != TableColumn.FIRST && // add the image width if it's not the first column
+ getImage(columnIndex) != null)) && // only when the item actually has an image
+ parent.getImageExtent() != null) {
+ imageStopX += parent.getImageExtent().x;
+ }
+ return imageStopX;
+}
+/**
+ * Return the index of the item in its parent widget.
*/
-Point getItemExtent(TableColumn column) {
- Table parent = getParent();
- int columnIndex = column.getIndex();
- Point extent = new Point(getImageStopX(columnIndex), parent.getItemHeight() - parent.getGridLineWidth());
- GC gc = new GC(parent);
- String trimmedText = getText(gc, column);
-
- if (trimmedText != null && trimmedText.length() > 0) {
- extent.x += gc.stringExtent(trimmedText).x + getTextIndent(columnIndex);
- }
- if (columnIndex == TableColumn.FIRST) {
- extent.x += SELECTION_PADDING;
- }
- gc.dispose();
- return extent;
-}
-/**
- * Answer the maximum width in pixel of the text that fits in the
- * column identified by 'columnIndex' without trimming the text.
- * @param columnIndex - the column for which the maximum text width
- * should be calculated.
- * @param columnWidth - width of the column 'columnIndex'
+int getIndex() {
+ return index;
+}
+/**
+ * Return the item extent in the specified column
+ * The extent includes the actual width of the item including checkbox,
+ * image and text.
*/
-int getMaxTextWidth(int columnIndex, int columnWidth) {
- int itemWidth = getImageStopX(columnIndex) + getTextIndent(columnIndex) * 2;
- return columnWidth - itemWidth;
-}
-/**
- * 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>
+Point getItemExtent(TableColumn column) {
+ Table parent = getParent();
+ int columnIndex = column.getIndex();
+ Point extent = new Point(getImageStopX(columnIndex), parent.getItemHeight() - parent.getGridLineWidth());
+ GC gc = new GC(parent);
+ String trimmedText = getText(gc, column);
+
+ if (trimmedText != null && trimmedText.length() > 0) {
+ extent.x += gc.stringExtent(trimmedText).x + getTextIndent(columnIndex);
+ }
+ if (columnIndex == TableColumn.FIRST) {
+ extent.x += SELECTION_PADDING;
+ }
+ gc.dispose();
+ return extent;
+}
+/**
+ * Answer the maximum width in pixel of the text that fits in the
+ * column identified by 'columnIndex' without trimming the text.
+ * @param columnIndex - the column for which the maximum text width
+ * should be calculated.
+ * @param columnWidth - width of the column 'columnIndex'
*/
-public Table getParent() {
- checkWidget();
- return (Table) super.getSelectableParent();
-}
-/**
- * Answer the width of the item required to display the complete contents.
+int getMaxTextWidth(int columnIndex, int columnWidth) {
+ int itemWidth = getImageStopX(columnIndex) + getTextIndent(columnIndex) * 2;
+ return columnWidth - itemWidth;
+}
+/**
+ * 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>
*/
-int getPreferredWidth(int index) {
- int size = getImageStopX(index);
- String text = getText(index);
- if (text != null) {
- size += getParent().getTextWidth(text) + getTextIndent(index) * 2 + 1;
- }
- return size;
-}
-/**
- * Return the size of the rectangle drawn to indicate a selected item.
- * This is also used to draw the selection focus rectangle and drop
- * insert marker.
- * Implements SelectableItem#getSelectionExtent
+public Table getParent() {
+ checkWidget();
+ return (Table) super.getSelectableParent();
+}
+/**
+ * Answer the width of the item required to display the complete contents.
*/
-Point getSelectionExtent() {
- Table parent = getParent();
- Point extent;
-
- if ((parent.getStyle() & SWT.FULL_SELECTION) == 0) { // regular, first column, selection?
- if (selectionExtent == null) {
- calculateSelectionExtent();
- }
- extent = selectionExtent;
- }
- else {
- extent = parent.getFullSelectionExtent(this);
- }
- return extent;
-}
-/**
- * Return the x position of the selection rectangle
- * Implements SelectableItem#getSelectionX
+int getPreferredWidth(int index) {
+ int size = getImageStopX(index);
+ String text = getText(index);
+ if (text != null) {
+ size += getParent().getTextWidth(text) + getTextIndent(index) * 2 + 1;
+ }
+ return size;
+}
+/**
+ * Return the size of the rectangle drawn to indicate a selected item.
+ * This is also used to draw the selection focus rectangle and drop
+ * insert marker.
+ * Implements SelectableItem#getSelectionExtent
*/
-int getSelectionX() {
- return getImageStopX(TableColumn.FIRST) + getParent().getHorizontalOffset();
-}
-public String getText() {
- checkWidget();
- return getText(0);
-}
-/**
- * Returns the text stored at the given column index in the receiver,
- * or empty string if the text has not been set.
- *
- * @param index the column index
- * @return the text stored at the given column index in the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_TEXT - if the column at index does not exist</li>
- * </ul>
+Point getSelectionExtent() {
+ Table parent = getParent();
+ Point extent;
+
+ if ((parent.getStyle() & SWT.FULL_SELECTION) == 0) { // regular, first column, selection?
+ if (selectionExtent == null) {
+ calculateSelectionExtent();
+ }
+ extent = selectionExtent;
+ }
+ else {
+ extent = parent.getFullSelectionExtent(this);
+ }
+ return extent;
+}
+/**
+ * Return the x position of the selection rectangle
+ * Implements SelectableItem#getSelectionX
*/
-public String getText(int columnIndex) {
- checkWidget();
- int itemIndex = getParent().indexOf(this);
- Vector labels = getDataLabels();
- String label = null;
-
- if (itemIndex == -1) {
- error(SWT.ERROR_CANNOT_GET_TEXT);
- }
- if (columnIndex >= 0 && columnIndex < labels.size()) {
- label = (String) labels.elementAt(columnIndex);
- }
- if (label == null) {
- label = ""; // label vector is initialized with null instead of empty Strings
- }
- return label;
-}
-/**
- * Answer the text that is going to be drawn in 'column'. This
- * text may be a trimmed copy of the original text set by the
- * user if it doesn't fit into the column. In that case the last
- * characters are replaced with Table.DOT_STRING.
- * A cached copy of the trimmed text is returned if available.
- * @param gc - GC to use for measuring the text extent
- * @param column - TableColumn for which the text should be returned
+int getSelectionX() {
+ return getImageStopX(TableColumn.FIRST) + getParent().getHorizontalOffset();
+}
+public String getText() {
+ checkWidget();
+ return getText(0);
+}
+/**
+ * Returns the text stored at the given column index in the receiver,
+ * or empty string if the text has not been set.
+ *
+ * @param index the column index
+ * @return the text stored at the given column index in the receiver
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_TEXT - if the column at index does not exist</li>
+ * </ul>
*/
-String getText(GC gc, TableColumn column) {
- int columnIndex = column.getIndex();
- String label = getTrimmedText(columnIndex);
- int maxWidth;
-
- if (label == null) {
- maxWidth = getMaxTextWidth(columnIndex, column.getWidth());
- label = getParent().trimItemText(getText(columnIndex), maxWidth, gc);
- }
- return label;
-}
-/**
- * Answer the indent of the text in column 'columnIndex' in pixel.
- * This indent is used in front of and behind the item text.
- * @param columnIndex - specifies the column for which the indent
- * should be calculated.
+public String getText(int columnIndex) {
+ checkWidget();
+ int itemIndex = getParent().indexOf(this);
+ Vector labels = getDataLabels();
+ String label = null;
+
+ if (itemIndex == -1) {
+ error(SWT.ERROR_CANNOT_GET_TEXT);
+ }
+ if (columnIndex >= 0 && columnIndex < labels.size()) {
+ label = (String) labels.elementAt(columnIndex);
+ }
+ if (label == null) {
+ label = ""; // label vector is initialized with null instead of empty Strings
+ }
+ return label;
+}
+/**
+ * Answer the text that is going to be drawn in 'column'. This
+ * text may be a trimmed copy of the original text set by the
+ * user if it doesn't fit into the column. In that case the last
+ * characters are replaced with Table.DOT_STRING.
+ * A cached copy of the trimmed text is returned if available.
+ * @param gc - GC to use for measuring the text extent
+ * @param column - TableColumn for which the text should be returned
*/
-int getTextIndent(int columnIndex) {
- int textIndent;
-
- if (columnIndex == TableColumn.FIRST) {
- if (getParent().hasFirstColumnImage() == false) {
- textIndent = TEXT_INDENT_NO_IMAGE;
- }
- else {
- textIndent = FIRST_COLUMN_TEXT_INDENT;
- }
- }
- else {
- textIndent = TEXT_INDENT;
- }
- return textIndent;
-}
-/**
- * Answer the cached trimmed text for column 'columnIndex'.
- * Answer null if it hasn't been calculated yet.
- * @param columnIndex - specifies the column for which the
- * trimmed text should be answered.
+String getText(GC gc, TableColumn column) {
+ int columnIndex = column.getIndex();
+ String label = getTrimmedText(columnIndex);
+ int maxWidth;
+
+ if (label == null) {
+ maxWidth = getMaxTextWidth(columnIndex, column.getWidth());
+ label = getParent().trimItemText(getText(columnIndex), maxWidth, gc);
+ }
+ return label;
+}
+/**
+ * Answer the indent of the text in column 'columnIndex' in pixel.
+ * This indent is used in front of and behind the item text.
+ * @param columnIndex - specifies the column for which the indent
+ * should be calculated.
*/
-String getTrimmedText(int columnIndex) {
- String label = null;
- String labels[] = getTrimmedTexts();
-
- if (columnIndex < labels.length) {
- label = labels[columnIndex];
- }
- return label;
-}
-/**
- * Answer an array of cached trimmed labels.
+int getTextIndent(int columnIndex) {
+ int textIndent;
+
+ if (columnIndex == TableColumn.FIRST) {
+ if (getParent().hasFirstColumnImage() == false) {
+ textIndent = TEXT_INDENT_NO_IMAGE;
+ }
+ else {
+ textIndent = FIRST_COLUMN_TEXT_INDENT;
+ }
+ }
+ else {
+ textIndent = TEXT_INDENT;
+ }
+ return textIndent;
+}
+/**
+ * Answer the cached trimmed text for column 'columnIndex'.
+ * Answer null if it hasn't been calculated yet.
+ * @param columnIndex - specifies the column for which the
+ * trimmed text should be answered.
*/
-String [] getTrimmedTexts() {
- return trimmedLabels;
-}
-/**
- * Ensure that the image and label vectors have at least
- * 'newSize' number of elements.
+String getTrimmedText(int columnIndex) {
+ String label = null;
+ String labels[] = getTrimmedTexts();
+
+ if (columnIndex < labels.length) {
+ label = labels[columnIndex];
+ }
+ return label;
+}
+/**
+ * Answer an array of cached trimmed labels.
*/
-void growVectors(int newSize) {
- Vector images = getImages();
- Vector labels = getDataLabels();
-
- if (newSize > images.size()){
- images.setSize(newSize);
- }
- if (newSize > labels.size()){
- labels.setSize(newSize);
- }
-}
-/**
- * Insert 'column' into the receiver.
+String [] getTrimmedTexts() {
+ return trimmedLabels;
+}
+/**
+ * Ensure that the image and label vectors have at least
+ * 'newSize' number of elements.
*/
-void insertColumn(TableColumn column) {
- Vector data = getDataLabels();
- Vector images = getImages();
- String stringData[];
- Image imageData[];
- int index = column.getIndex();
-
- if (index < data.size()) {
- data.insertElementAt(null, index);
- }
- else {
- data.addElement(null);
- }
- stringData = new String[data.size()];
- data.copyInto(stringData);
- setText(stringData);
-
- if (index < images.size()) {
- images.insertElementAt(null, index);
- }
- else {
- images.addElement(null);
- }
- imageData = new Image[images.size()];
- images.copyInto(imageData);
- setImage(imageData);
-
- String[] tempTrimmed = new String[trimmedLabels.length + 1];
- System.arraycopy(trimmedLabels, 0, tempTrimmed, 0, index);
- System.arraycopy(trimmedLabels, index, tempTrimmed, index + 1, trimmedLabels.length - index);
- trimmedLabels = tempTrimmed;
-
-}
-/**
- * Sets the image at an index.
- *
- * @param image the new image (or null)
- *
- * @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
- * when called from the wrong thread
- * @exception SWTError(ERROR_WIDGET_DISPOSED)
- * when the widget has been disposed
+void growVectors(int newSize) {
+ Vector images = getImages();
+ Vector labels = getDataLabels();
+
+ if (newSize > images.size()){
+ images.setSize(newSize);
+ }
+ if (newSize > labels.size()){
+ labels.setSize(newSize);
+ }
+}
+/**
+ * Insert 'column' into the receiver.
*/
-void internalSetImage(int columnIndex, Image image) {
- Vector images = getImages();
- boolean imageWasNull = false;
- Table parent = getParent();
-
- if (columnIndex >= 0 &&
- columnIndex < parent.internalGetColumnCount()) {
- if (columnIndex >= images.size()) {
- growVectors(columnIndex + 1);
- }
- if (((Image) images.elementAt(columnIndex)) == null && image != null) {
- imageWasNull = true;
- }
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- images.setElementAt(image, columnIndex);
- reset(columnIndex); // new image may cause text to no longer fit in the column
- notifyImageChanged(columnIndex, imageWasNull);
- }
-}
-/**
- * Sets the widget text.
- *
- * The widget text for an item is the label of the
- * item or the label of the text specified by a column
- * number.
- *
- * @param index the column number
- * @param text the new text
- *
+void insertColumn(TableColumn column) {
+ Vector data = getDataLabels();
+ Vector images = getImages();
+ String stringData[];
+ Image imageData[];
+ int index = column.getIndex();
+
+ if (index < data.size()) {
+ data.insertElementAt(null, index);
+ }
+ else {
+ data.addElement(null);
+ }
+ stringData = new String[data.size()];
+ data.copyInto(stringData);
+ setText(stringData);
+
+ if (index < images.size()) {
+ images.insertElementAt(null, index);
+ }
+ else {
+ images.addElement(null);
+ }
+ imageData = new Image[images.size()];
+ images.copyInto(imageData);
+ setImage(imageData);
+
+ String[] tempTrimmed = new String[trimmedLabels.length + 1];
+ System.arraycopy(trimmedLabels, 0, tempTrimmed, 0, index);
+ System.arraycopy(trimmedLabels, index, tempTrimmed, index + 1, trimmedLabels.length - index);
+ trimmedLabels = tempTrimmed;
+
+}
+/**
+ * Sets the image at an index.
+ *
+ * @param image the new image (or null)
+ *
+ * @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+ * when called from the wrong thread
+ * @exception SWTError(ERROR_WIDGET_DISPOSED)
+ * when the widget has been disposed
*/
-void internalSetText(int columnIndex, String string) {
- Vector labels = getDataLabels();
- Table parent = getParent();
- String oldText;
-
- if (columnIndex >= 0 &&
- columnIndex < parent.internalGetColumnCount()) {
- if (columnIndex >= labels.size()) {
- growVectors(columnIndex + 1);
- }
- oldText = (String) labels.elementAt(columnIndex);
- if (string.equals(oldText) == false) {
- labels.setElementAt(string, columnIndex);
- reset(columnIndex);
- notifyTextChanged(columnIndex, oldText == null);
- }
- }
-}
-/**
- * Answer whether the click at 'xPosition' on the receiver is a
- * selection click.
- * A selection click occurred when the click was behind the image
- * and before the end of the item text.
- * @return
- * true - 'xPosition' is a selection click.
- * false - otherwise
+void internalSetImage(int columnIndex, Image image) {
+ Vector images = getImages();
+ boolean imageWasNull = false;
+ Table parent = getParent();
+
+ if (columnIndex >= 0 &&
+ columnIndex < parent.internalGetColumnCount()) {
+ if (columnIndex >= images.size()) {
+ growVectors(columnIndex + 1);
+ }
+ if (((Image) images.elementAt(columnIndex)) == null && image != null) {
+ imageWasNull = true;
+ }
+ if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ images.setElementAt(image, columnIndex);
+ reset(columnIndex); // new image may cause text to no longer fit in the column
+ notifyImageChanged(columnIndex, imageWasNull);
+ }
+}
+/**
+ * Sets the widget text.
+ *
+ * The widget text for an item is the label of the
+ * item or the label of the text specified by a column
+ * number.
+ *
+ * @param index the column number
+ * @param text the new text
+ *
*/
-boolean isSelectionHit(int xPosition) {
- int itemStopX = getImageStopX(TableColumn.FIRST);
- Point selectionExtent = getSelectionExtent();
-
- if (selectionExtent != null) {
- itemStopX += selectionExtent.x;
- }
- return (xPosition > getCheckboxBounds().x + getCheckboxBounds().width) && (xPosition <= itemStopX);
-}
-/**
- * The image for the column identified by 'columnIndex' has changed.
- * Notify the parent widget and supply redraw coordinates, if possible.
- * @param columnIndex - index of the column that has a new image.
+void internalSetText(int columnIndex, String string) {
+ Vector labels = getDataLabels();
+ Table parent = getParent();
+ String oldText;
+
+ if (columnIndex >= 0 &&
+ columnIndex < parent.internalGetColumnCount()) {
+ if (columnIndex >= labels.size()) {
+ growVectors(columnIndex + 1);
+ }
+ oldText = (String) labels.elementAt(columnIndex);
+ if (string.equals(oldText) == false) {
+ labels.setElementAt(string, columnIndex);
+ reset(columnIndex);
+ notifyTextChanged(columnIndex, oldText == null);
+ }
+ }
+}
+/**
+ * Answer whether the click at 'xPosition' on the receiver is a
+ * selection click.
+ * A selection click occurred when the click was behind the image
+ * and before the end of the item text.
+ * @return
+ * true - 'xPosition' is a selection click.
+ * false - otherwise
*/
-void notifyImageChanged(int columnIndex, boolean imageWasNull) {
- Table parent = getParent();
- Rectangle changedColumnBounds;
- Image currentImage;
- int redrawStartX = 0;
- int redrawWidth = 0;
- int columnCount = parent.internalGetColumnCount();
-
- if (columnIndex >= 0 && columnIndex < columnCount && parent.getVisibleRedrawY(this) != -1) {
- changedColumnBounds = parent.internalGetColumn(columnIndex).getBounds();
- currentImage = getImage(columnIndex);
- redrawStartX = Math.max(0, getImageBounds(columnIndex).x);
- if (parent.getImageExtent() != null && imageWasNull == false && currentImage != null) {
- redrawWidth = getImageStopX(columnIndex);
- }
- else {
- redrawWidth = changedColumnBounds.width;
- }
- redrawWidth += changedColumnBounds.x - redrawStartX;
- }
- parent.itemChanged(this, redrawStartX, redrawWidth);
-}
-
-/**
- * The label for the column identified by 'columnIndex' has changed.
- * Notify the parent widget and supply redraw coordinates, if possible.
- * @param columnIndex - index of the column that has a new label.
+boolean isSelectionHit(int xPosition) {
+ int itemStopX = getImageStopX(TableColumn.FIRST);
+ Point selectionExtent = getSelectionExtent();
+
+ if (selectionExtent != null) {
+ itemStopX += selectionExtent.x;
+ }
+ return (xPosition > getCheckboxBounds().x + getCheckboxBounds().width) && (xPosition <= itemStopX);
+}
+/**
+ * The image for the column identified by 'columnIndex' has changed.
+ * Notify the parent widget and supply redraw coordinates, if possible.
+ * @param columnIndex - index of the column that has a new image.
*/
-void notifyTextChanged(int columnIndex, boolean textWasNull) {
- Table parent = getParent();
- String text;
- Rectangle columnBounds;
- int redrawStartX = 0;
- int redrawWidth = 0;
- int columnCount = parent.internalGetColumnCount();
-
- if (columnIndex >= 0 && columnIndex < columnCount && parent.getVisibleRedrawY(this) != -1) {
- text = (String) getDataLabels().elementAt(columnIndex);
- columnBounds = parent.internalGetColumn(columnIndex).getBounds();
- redrawStartX = columnBounds.x;
- if (getImage(columnIndex) != null) {
- redrawStartX += getImageStopX(columnIndex);
- }
- redrawStartX = Math.max(0, redrawStartX);
- // don't redraw if text changed from null to empty string
- if (textWasNull == false || text.length() > 0) {
- redrawWidth = columnBounds.x + columnBounds.width - redrawStartX;
- }
- }
- parent.itemChanged(this, redrawStartX, redrawWidth);
-}
-/**
- * Draw the receiver at 'paintPosition' in the column identified by
- * 'columnIndex' using 'gc'.
- * @param gc - GC to use for drawing
- * @param paintPosition - position where the receiver should be drawing.
- * @param column - the column to draw in
+void notifyImageChanged(int columnIndex, boolean imageWasNull) {
+ Table parent = getParent();
+ Rectangle changedColumnBounds;
+ Image currentImage;
+ int redrawStartX = 0;
+ int redrawWidth = 0;
+ int columnCount = parent.internalGetColumnCount();
+
+ if (columnIndex >= 0 && columnIndex < columnCount && parent.getVisibleRedrawY(this) != -1) {
+ changedColumnBounds = parent.internalGetColumn(columnIndex).getBounds();
+ currentImage = getImage(columnIndex);
+ redrawStartX = Math.max(0, getImageBounds(columnIndex).x);
+ if (parent.getImageExtent() != null && imageWasNull == false && currentImage != null) {
+ redrawWidth = getImageStopX(columnIndex);
+ }
+ else {
+ redrawWidth = changedColumnBounds.width;
+ }
+ redrawWidth += changedColumnBounds.x - redrawStartX;
+ }
+ parent.itemChanged(this, redrawStartX, redrawWidth);
+}
+
+/**
+ * The label for the column identified by 'columnIndex' has changed.
+ * Notify the parent widget and supply redraw coordinates, if possible.
+ * @param columnIndex - index of the column that has a new label.
*/
-void paint(GC gc, Point paintPosition, TableColumn column) {
- int columnIndex = column.getIndex();
- String label = getText(gc, column);
- String oldLabel = getTrimmedText(columnIndex);
-
- if (label != null && label.equals(oldLabel) == false) {
- setTrimmedText(label, columnIndex);
- selectionExtent = null; // force a recalculation next time the selection extent is needed
- }
- if (columnIndex == TableColumn.FIRST) {
- paintPosition.x += getImageIndentPixel();
- if (isCheckable() == true) {
- paintPosition = drawCheckbox(gc, paintPosition);
- }
- }
- paintPosition = drawImage(gc, paintPosition, columnIndex);
- paintPosition.x += getTextIndent(columnIndex);
- drawText(label, gc, paintPosition, columnIndex);
-}
-/**
- * Remove 'column' from the receiver.
+void notifyTextChanged(int columnIndex, boolean textWasNull) {
+ Table parent = getParent();
+ String text;
+ Rectangle columnBounds;
+ int redrawStartX = 0;
+ int redrawWidth = 0;
+ int columnCount = parent.internalGetColumnCount();
+
+ if (columnIndex >= 0 && columnIndex < columnCount && parent.getVisibleRedrawY(this) != -1) {
+ text = (String) getDataLabels().elementAt(columnIndex);
+ columnBounds = parent.internalGetColumn(columnIndex).getBounds();
+ redrawStartX = columnBounds.x;
+ if (getImage(columnIndex) != null) {
+ redrawStartX += getImageStopX(columnIndex);
+ }
+ redrawStartX = Math.max(0, redrawStartX);
+ // don't redraw if text changed from null to empty string
+ if (textWasNull == false || text.length() > 0) {
+ redrawWidth = columnBounds.x + columnBounds.width - redrawStartX;
+ }
+ }
+ parent.itemChanged(this, redrawStartX, redrawWidth);
+}
+/**
+ * Draw the receiver at 'paintPosition' in the column identified by
+ * 'columnIndex' using 'gc'.
+ * @param gc - GC to use for drawing
+ * @param paintPosition - position where the receiver should be drawing.
+ * @param column - the column to draw in
*/
-void removeColumn(TableColumn column) {
- Vector data = getDataLabels();
- Vector images = getImages();
- String stringData[];
- Image imageData[];
- int index = column.getIndex();
-
- if (index < data.size()) {
- data.removeElementAt(index);
- stringData = new String[data.size()];
- data.copyInto(stringData);
- setText(stringData);
- }
- if (index < images.size()) {
- images.removeElementAt(index);
- imageData = new Image[images.size()];
- images.copyInto(imageData);
- setImage(imageData);
- }
-
- if (trimmedLabels.length == 1) {
- trimmedLabels = new String[0];
- } else {
- String[] tempTrimmed = new String[trimmedLabels.length - 1];
- System.arraycopy(trimmedLabels, 0, tempTrimmed, 0, index);
- System.arraycopy(trimmedLabels, index +1, tempTrimmed, index, trimmedLabels.length - index -1);
- trimmedLabels = tempTrimmed;
- }
-
-}
-/**
- * Reset the cached trimmed label for the sub item identified by
- * 'index'.
- * @param index - index of the label that should be reset.
+void paint(GC gc, Point paintPosition, TableColumn column) {
+ int columnIndex = column.getIndex();
+ String label = getText(gc, column);
+ String oldLabel = getTrimmedText(columnIndex);
+
+ if (label != null && label.equals(oldLabel) == false) {
+ setTrimmedText(label, columnIndex);
+ selectionExtent = null; // force a recalculation next time the selection extent is needed
+ }
+ if (columnIndex == TableColumn.FIRST) {
+ paintPosition.x += getImageIndentPixel();
+ if (isCheckable() == true) {
+ paintPosition = drawCheckbox(gc, paintPosition);
+ }
+ }
+ paintPosition = drawImage(gc, paintPosition, columnIndex);
+ paintPosition.x += getTextIndent(columnIndex);
+ drawText(label, gc, paintPosition, columnIndex);
+}
+/**
+ * Remove 'column' from the receiver.
*/
-void reset(int index) {
- String trimmedLabels[] = getTrimmedTexts();
-
- if (index >= 0 && index < trimmedLabels.length) {
- trimmedLabels[index] = null;
- }
- if (index == TableColumn.FIRST) {
- selectionExtent = null;
- }
-}
-
-void redraw(){
- Table parent = getParent();
- int y = parent.getRedrawY(this);
- parent.redraw(0, y, parent.getClientArea().width, parent.getItemHeight(), false);
-}
-/**
- * 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
- *
+void removeColumn(TableColumn column) {
+ Vector data = getDataLabels();
+ Vector images = getImages();
+ String stringData[];
+ Image imageData[];
+ int index = column.getIndex();
+
+ if (index < data.size()) {
+ data.removeElementAt(index);
+ stringData = new String[data.size()];
+ data.copyInto(stringData);
+ setText(stringData);
+ }
+ if (index < images.size()) {
+ images.removeElementAt(index);
+ imageData = new Image[images.size()];
+ images.copyInto(imageData);
+ setImage(imageData);
+ }
+
+ if (trimmedLabels.length == 1) {
+ trimmedLabels = new String[0];
+ } else {
+ String[] tempTrimmed = new String[trimmedLabels.length - 1];
+ System.arraycopy(trimmedLabels, 0, tempTrimmed, 0, index);
+ System.arraycopy(trimmedLabels, index +1, tempTrimmed, index, trimmedLabels.length - index -1);
+ trimmedLabels = tempTrimmed;
+ }
+
+}
+/**
+ * Reset the cached trimmed label for the sub item identified by
+ * 'index'.
+ * @param index - index of the label that should be reset.
*/
-public void setBackground (Color color) {
- checkWidget ();
- if (color != null && color.isDisposed ())
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- background = color;
- redraw();
-}
-/**
- * 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
- *
+void reset(int index) {
+ String trimmedLabels[] = getTrimmedTexts();
+
+ if (index >= 0 && index < trimmedLabels.length) {
+ trimmedLabels[index] = null;
+ }
+ if (index == TableColumn.FIRST) {
+ selectionExtent = null;
+ }
+}
+
+void redraw(){
+ Table parent = getParent();
+ int y = parent.getRedrawY(this);
+ parent.redraw(0, y, parent.getClientArea().width, parent.getItemHeight(), false);
+}
+/**
+ * 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 setForeground (Color color){
- checkWidget ();
- if (color != null && color.isDisposed ())
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- foreground = color;
- 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 setBackground (Color color) {
+ checkWidget ();
+ if (color != null && color.isDisposed ())
+ SWT.error (SWT.ERROR_INVALID_ARGUMENT);
+ background = color;
+ redraw();
+}
+/**
+ * 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 setImage(Image [] images) {
- checkWidget();
- if (images == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (getParent().indexOf(this) == -1) {
- return;
- }
- for (int i = 0; i < images.length; i++) {
- internalSetImage(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 setForeground (Color color){
+ checkWidget ();
+ if (color != null && color.isDisposed ())
+ SWT.error (SWT.ERROR_INVALID_ARGUMENT);
+ foreground = color;
+ 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(int index, Image image) {
- checkWidget();
- if (getParent().indexOf(this) != -1) {
- internalSetImage(index, image);
- }
-}
-public void setImage(Image image) {
- checkWidget();
- setImage(0, image);
-}
-/**
- * Sets the image indent.
- *
- * @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>
+public void setImage(Image [] images) {
+ checkWidget();
+ if (images == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (getParent().indexOf(this) == -1) {
+ return;
+ }
+ for (int i = 0; i < images.length; i++) {
+ internalSetImage(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 setImageIndent(int indent) {
- checkWidget();
- Table parent = getParent();
- TableColumn column;
- int index = parent.indexOf(this);
-
- if (index != -1 && indent >= 0 && indent != imageIndent) {
- imageIndent = indent;
- column = parent.internalGetColumn(TableColumn.FIRST);
- parent.redraw(
- 0, parent.getRedrawY(this),
- column.getWidth(), parent.getItemHeight(), false);
- }
-}
-/**
- * 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 setImage(int index, Image image) {
+ checkWidget();
+ if (getParent().indexOf(this) != -1) {
+ internalSetImage(index, image);
+ }
+}
+public void setImage(Image image) {
+ checkWidget();
+ setImage(0, image);
+}
+/**
+ * Sets the image indent.
+ *
+ * @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>
*/
-public void setText(String [] strings) {
- checkWidget();
- if (strings == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (getParent().indexOf(this) == -1) {
- return;
- }
- for (int i = 0; i < strings.length; i++) {
- String string = strings[i];
- if (string != null) {
- internalSetText(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 setImageIndent(int indent) {
+ checkWidget();
+ Table parent = getParent();
+ TableColumn column;
+ int index = parent.indexOf(this);
+
+ if (index != -1 && indent >= 0 && indent != imageIndent) {
+ imageIndent = indent;
+ column = parent.internalGetColumn(TableColumn.FIRST);
+ parent.redraw(
+ 0, parent.getRedrawY(this),
+ column.getWidth(), parent.getItemHeight(), false);
+ }
+}
+/**
+ * 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 (int index, String string) {
- checkWidget();
- if (string == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (getParent().indexOf(this) != -1) {
- internalSetText(index, string);
- }
-}
-public void setText(String text) {
- checkWidget();
- if (text == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- setText(0, text);
-}
-/**
- * Set the trimmed text of column 'columnIndex' to label. The trimmed
- * text is the one that is displayed in a column. It may be shorter than
- * the text originally set by the user via setText(...) to fit the
- * column.
- * @param label - the text label of column 'columnIndex'. May be trimmed
- * to fit the column.
- * @param columnIndex - specifies the column whose text label should be
- * set.
+public void setText(String [] strings) {
+ checkWidget();
+ if (strings == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (getParent().indexOf(this) == -1) {
+ return;
+ }
+ for (int i = 0; i < strings.length; i++) {
+ String string = strings[i];
+ if (string != null) {
+ internalSetText(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>
*/
-void setTrimmedText(String label, int columnIndex) {
- String labels[] = getTrimmedTexts();
-
- if (columnIndex < labels.length) {
- labels[columnIndex] = label;
- }
-}
-/**
- * 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 setText (int index, String string) {
+ checkWidget();
+ if (string == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (getParent().indexOf(this) != -1) {
+ internalSetText(index, string);
+ }
+}
+public void setText(String text) {
+ checkWidget();
+ if (text == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ setText(0, text);
+}
+/**
+ * Set the trimmed text of column 'columnIndex' to label. The trimmed
+ * text is the one that is displayed in a column. It may be shorter than
+ * the text originally set by the user via setText(...) to fit the
+ * column.
+ * @param label - the text label of column 'columnIndex'. May be trimmed
+ * to fit the column.
+ * @param columnIndex - specifies the column whose text label should be
+ * set.
*/
-public void setChecked(boolean checked) {
- checkWidget();
- super.setChecked(checked);
-}
-/**
- * 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>
+void setTrimmedText(String label, int columnIndex) {
+ String labels[] = getTrimmedTexts();
+
+ if (columnIndex < labels.length) {
+ labels[columnIndex] = label;
+ }
+}
+/**
+ * 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 setGrayed (boolean grayed) {
- checkWidget();
- super.setGrayed(grayed);
-}
-/**
- * Set the index of this item in its parent widget to 'newIndex'.
+public void setChecked(boolean checked) {
+ checkWidget();
+ super.setChecked(checked);
+}
+/**
+ * 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>
*/
-void setIndex(int newIndex) {
- index = newIndex;
-}
-
-}
-
+public void setGrayed (boolean grayed) {
+ checkWidget();
+ super.setGrayed(grayed);
+}
+/**
+ * Set the index of this item in its parent widget to 'newIndex'.
+ */
+void setIndex(int newIndex) {
+ index = newIndex;
+}
+
+}
+
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
index 5ba359ac39..8c6e90d894 100644
--- 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
@@ -1,1657 +1,1657 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import java.util.Enumeration;
-import java.util.Stack;
-import java.util.Vector;
-
-/**
- * Instances of this class provide a selectable user interface object
- * that displays a hierarchy of items and issue notificiation 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>
- * 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</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, Collapse, Expand</dd>
- * </dl>
- * <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 SelectableItemWidget {
- // These constants are used internally for item hit test on mouse click
- private static final int ActionNone = 0; // The mouse event was not handled
- private static final int ActionExpandCollapse = 1; // Do an expand/collapse
- private static final int ActionSelect = 2; // Select the item
- private static final int ActionCheck = 3; // Toggle checked state of the item
- private static ImageData CollapsedImageData; // collapsed sub tree image data. used to create an image at run time
- private static ImageData ExpandedImageData; // expanded sub tree image data. used to create an image at run time
- static {
- initializeImageData();
- }
-
- private TreeRoots root;
- private TreeItem expandingItem;
-
- private Image collapsedImage;
- private Image expandedImage;
-
- // The following fields are needed for painting tree items
- final Color CONNECTOR_LINE_COLOR; // Color constant used during painting. Can't keep this in TreeItem
- // because we only need one instance per tree widget/display and can't
- // have it static. Initialized in c'tor and freed in dispose();
- Rectangle hierarchyIndicatorRect = null; // bounding rectangle of the hierarchy indication image (plus/minus)
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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));
- CONNECTOR_LINE_COLOR = new Color(getDisplay(), 170, 170, 170); // Light gray;
-}
-/**
- * Add 'item' to the list of root items.
- * @param 'item' - the tree item that should be added as a root.
- * @param index - position that 'item' will be inserted at
- * in the receiver.
- */
-void addItem(TreeItem item, int index) {
- if (index < 0 || index > getItemCount()) {
- error(SWT.ERROR_INVALID_RANGE);
- }
- getRoot().add(item, index);
-}
-/**
- * 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 reciever 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();
- TypedListener typedListener;
-
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- 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();
- TypedListener typedListener;
-
- if (listener == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- typedListener = new TypedListener(listener);
- addListener(SWT.Expand, typedListener);
- addListener(SWT.Collapse, typedListener);
-}
-/**
- * The SelectableItem 'item' has been added to the tree.
- * Prevent screen updates when 'item' is inserted due to an
- * expand operation.
- * @param item - item that has been added to the receiver.
- */
-void addedItem(SelectableItem item, int index) {
- super.addedItem(item, index);
- redrawAfterModify(item, index); // redraw plus/minus image, hierarchy lines
-}
-/**
- * Answer the y position of both the first child of 'item' and
- * the item following the last child of 'item'.
- * Used to scroll items on expand/collapse.
- * @param item - TreeItem to use for calculating the y boundary
- * of child items.
- * @return Array - first element is the position of the first
- * child of 'item'. Second element is the position of the item
- * following the last child of 'item'.
- * Both elements are -1 if 'item' is not a child of the receiver.
- */
-int[] calculateChildrenYPos(TreeItem item) {
- int itemIndex = item.getVisibleIndex();
- int itemCount = item.getVisibleItemCount();
- int itemHeight = getItemHeight();
- int yPos;
- int[] yPosition = new int[] {-1, -1};
-
- if (itemIndex != -1) {
- itemIndex -= getTopIndex();
- yPos = (itemIndex + itemCount + 1) * itemHeight; // y position of the item following
- // the last child of 'item'
- yPosition = new int[] {yPos - (itemCount * itemHeight), yPos};
- }
- return yPosition;
-}
-/**
- * Calculate the widest of the children of 'item'.
- * Items that are off screen and that may be scrolled into view are
- * included in the calculation.
- * @param item - the tree item that was expanded
- */
-void calculateWidestExpandingItem(TreeItem item) {
- int itemIndex = item.getVisibleIndex();
- int newMaximumItemWidth = getContentWidth();
- int stopIndex = itemIndex + item.getVisibleItemCount();
-
- for (int i = itemIndex + 1; i <= stopIndex; i++) {
- newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
- }
- setContentWidth(newMaximumItemWidth);
-}
-/**
- * Calculate the width of new items as they are scrolled into view.
- * Precondition:
- * topIndex has already been set to the new index.
- * @param topIndexDifference - difference between old and new top
- * index.
- */
-void calculateWidestScrolledItem(int topIndexDifference) {
- int visibleItemCount = getItemCountTruncated(getClientArea());
- int newMaximumItemWidth = getContentWidth();
- int topIndex = getTopIndex();
- int stopIndex = topIndex;
-
- if (topIndexDifference < 0) { // scrolled up?
- if (Math.abs(topIndexDifference) > visibleItemCount) { // scrolled down more than one page (via quick thumb dragging)?
- topIndexDifference = visibleItemCount * -1;
- }
- for (int i = stopIndex - topIndexDifference; i >= stopIndex; i--) { // check item width from old top index up to new one
- newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
- }
- }
- else
- if (topIndexDifference > 0) { // scrolled down?
- if (topIndexDifference > visibleItemCount) { // scrolled down more than one page (via quick thumb dragging)?
- topIndexDifference = visibleItemCount;
- }
- stopIndex += visibleItemCount;
- for (int i = stopIndex - topIndexDifference; i < stopIndex; i++) {
- newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
- }
- }
- setContentWidth(newMaximumItemWidth);
-}
-/**
- * Calculate the maximum item width of all displayed items.
- */
-void calculateWidestShowingItem() {
- TreeItem visibleItem;
- int newMaximumItemWidth = 0;
- int bottomIndex = getBottomIndex();
- int paintStopX;
-
- // add one to the loop end index because otherwise an item covered
- // by the horizontal scroll bar would not be taken into acount and
- // may become visible after this calculation. We're in trouble if
- // that item is wider than the client area.
- if (getHorizontalBar().getVisible() == true) {
- bottomIndex++;
- }
- for (int i = getTopIndex(); i < bottomIndex; i++) {
- visibleItem = getRoot().getVisibleItem(i);
- if (visibleItem != null) {
- paintStopX = visibleItem.getPaintStopX();
- newMaximumItemWidth = Math.max(newMaximumItemWidth, paintStopX);
- }
- }
- setContentWidth(newMaximumItemWidth);
-}
-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);
-}
-/**
- * Collapse the tree item identified by 'item' if it is not
- * already collapsed. Move the selection to the parent item
- * if one of the collapsed items is currently selected.
- * @param item - item that should be collapsed.
- * @param notifyListeners -
- * true=a Collapse event is sent
- * false=no event is sent
- */
-void collapse(TreeItem item, boolean notifyListeners) {
- Event event;
- int itemIndex;
-
- if (item.getExpanded() == false) {
- return;
- }
- collapseNoRedraw(item);
- itemIndex = item.getVisibleIndex();
- if (itemIndex != -1) { // if the item's parent is not collapsed (and the item is thus visible) do the screen updates
- item.redrawExpanded(itemIndex - getTopIndex());
- showSelectableItem(item);
- calculateVerticalScrollbar();
- calculateWidestShowingItem();
- claimRightFreeSpace();
- claimBottomFreeSpace();
- }
- if (notifyListeners == true) {
- event = new Event();
- event.item = item;
- notifyListeners(SWT.Collapse, event);
- }
-}
-
-/**
- * Collapse the tree item identified by 'item' if it is not
- * already collapsed. Move the selection to the parent item
- * if one of the collapsed items is currently selected.
- * This method is used to hide the children if an item is deleted.
- * certain redraw and scroll operations are not needed for this
- * case.
- * @param item - item that should be collapsed.
- */
-void collapseNoRedraw(TreeItem item) {
-
- if (item.getExpanded() == false) {
- return;
- }
- if (isSelectedItemCollapsing(item) == true) {
- deselectAllExcept(item);
- selectNotify(item);
- update(); // call update to make sure that new selection is
- // drawn before items are collapsed (looks better)
- }
- scrollForCollapse(item);
- item.internalSetExpanded(false);
-}
-
-public Point computeSize(int wHint, int hHint, boolean changed) {
- checkWidget();
- Point size = super.computeSize(wHint, hHint, changed);
- GC gc;
- final int WidthCalculationCount = 50; // calculate item width for the first couple of items only
- TreeRoots root = getRoot();
- TreeItem item;
- Image itemImage;
- String itemText;
- int width;
- int newItemWidth = 0;
-
- if (wHint == SWT.DEFAULT && getContentWidth() == 0 && getItemCount() > 0) {
- gc = new GC(this);
- for (int i = 0; i < WidthCalculationCount; i++) {
- item = root.getVisibleItem(i);
- if (item == null) {
- break; // no more items
- }
- itemImage = item.getImage();
- itemText = item.getText();
- width = 0;
- if (itemImage != null) {
- width += itemImage.getBounds().width;
- }
- if (itemText != null) {
- width += gc.stringExtent(itemText).x;
- }
- newItemWidth = Math.max(newItemWidth, width);
- }
- if (newItemWidth > 0) {
- size.x = newItemWidth;
- }
- gc.dispose();
- }
- return size;
-}
-/**
- * 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();
- getRoot().deselectAll();
- getSelectionVector().removeAllElements();
- redraw();
-}
-/**
- * Modifier Key Action
- * None Collapse the selected item if expanded. Select
- * parent item if selected item is already
- * collapsed and if it's not the root item.
- * Ctrl super.doArrowLeft(int);
- * Shift see None above
- * @param keyMask - the modifier key that was pressed
- */
-void doArrowLeft(int keyMask) {
- TreeItem focusItem = (TreeItem) getLastFocus();
- TreeItem parentItem;
-
- if (focusItem == null) {
- return;
- }
- if (keyMask == SWT.MOD1) {
- super.doArrowLeft(keyMask);
- }
- else
- if (focusItem.getExpanded() == true) { // collapse if expanded
- collapse(focusItem, true);
- }
- else
- if (focusItem.isRoot() == false) { // go to the parent if there is one
- parentItem = focusItem.getParentItem();
- deselectAllExcept(parentItem);
- selectNotify(parentItem);
- }
-}
-/**
- * Modifier Key Action
- * None Expand selected item if collapsed. Select
- * first child item if selected item is
- * already expanded and there is a child item.
- * Ctrl super.doArrowRight(keyMask);
- * Shift see None above
- * @param keyMask - the modifier key that was pressed
- */
-void doArrowRight(int keyMask) {
- TreeItem focusItem = (TreeItem) getLastFocus();
- TreeItem childItem;
-
- if (focusItem == null) {
- return;
- }
- if (keyMask == SWT.MOD1) {
- super.doArrowRight(keyMask);
- }
- else
- if (focusItem.isLeaf() == false) {
- if (focusItem.getExpanded() == false) { // expand if collapsed
- expand(focusItem, true);
- }
- else { // go to the first child if there is one
- childItem = focusItem.getItems()[0];
- deselectAllExcept(childItem);
- selectNotify(childItem);
- }
- }
-}
-/**
- * Expand the selected item and all of its children.
- */
-void doAsterix() {
- expandAll((TreeItem) getLastFocus());
-}
-/**
- * Free resources.
- */
-void doDispose() {
- super.doDispose();
- if (collapsedImage != null) {
- collapsedImage.dispose();
- }
- if (expandedImage != null) {
- expandedImage.dispose();
- }
- getRoot().dispose();
- CONNECTOR_LINE_COLOR.dispose();
- resetHierarchyIndicatorRect();
-}
-/**
- * Collapse the selected item if it is expanded.
- */
-void doMinus() {
- TreeItem selectedItem = (TreeItem) getLastFocus();
-
- if (selectedItem != null) {
- collapse(selectedItem, true);
- }
-}
-/**
- * Expand the selected item if it is collapsed and if it
- * has children.
- */
-void doPlus() {
- TreeItem selectedItem = (TreeItem) getLastFocus();
-
- if (selectedItem != null && selectedItem.isLeaf() == false) {
- expand(selectedItem, true);
- }
-}
-/**
- * Expand the tree item identified by 'item' if it is not already
- * expanded. Scroll the expanded items into view.
- * @param item - item that should be expanded
- * @param notifyListeners -
- * true=an Expand event is sent
- * false=no event is sent
- */
-void expand(TreeItem item, boolean notifyListeners) {
- Event event = new Event();
- boolean nestedExpand = expandingItem != null;
-
- if (item.getExpanded() == true || item.getExpanding() == true) {
- return;
- }
- item.setExpanding(true);
- if (nestedExpand == false) {
- setExpandingItem(item);
- }
- if (notifyListeners == true) {
- event.item = item;
- notifyListeners(SWT.Expand, event);
- }
- scrollForExpand(item);
- item.internalSetExpanded(true);
- // redraw hierarchy image
- item.redrawExpanded(item.getVisibleIndex() - getTopIndex());
- calculateVerticalScrollbar();
- if (nestedExpand == false && isVisible() == true) {
- showSelectableItem(item); // make expanded item visible. Could be invisible if the expand was caused by a key press.
- calculateWidestExpandingItem(item);
- scrollExpandedItemsIntoView(item);
- }
- if (nestedExpand == false) {
- setExpandingItem(null);
- }
- item.setExpanding(false);
-}
-/**
- * Expand 'item' and all its children.
- */
-void expandAll(TreeItem item) {
- TreeItem items[];
-
- if (item != null && item.isLeaf() == false) {
- expand(item, true);
- update();
- items = item.getItems();
- for (int i = 0; i < items.length; i++) {
- expandAll(items[i]);
- }
- }
-}
-/**
- * Answer the image that is used as a hierarchy indicator
- * for a collapsed hierarchy.
- */
-Image getCollapsedImage() {
- if (collapsedImage == null) {
- collapsedImage = new Image(getDisplay(), CollapsedImageData);
- }
- return collapsedImage;
-}
-/**
- * Answer the width of the item identified by 'itemIndex'.
- */
-int getContentWidth(int itemIndex) {
- TreeItem item = getRoot().getVisibleItem(itemIndex);
- int paintStopX = 0;
-
- if (item != null) {
- paintStopX = item.getPaintStopX();
- }
- return paintStopX;
-}
-/**
- * Answer the image that is used as a hierarchy indicator
- * for an expanded hierarchy.
- */
-Image getExpandedImage() {
- if (expandedImage == null) {
- expandedImage = new Image(getDisplay(), ExpandedImageData);
- }
- return expandedImage;
-}
-/**
- * Answer the rectangle enclosing the hierarchy indicator of a tree item.
- *
- * Note:
- * Assumes that the hierarchy indicators for expanded and
- * collapsed state are the same size.
- * @return
- * The rectangle enclosing the hierarchy indicator.
- */
-Rectangle getHierarchyIndicatorRect() {
- int itemHeight = getItemHeight();
- Image hierarchyImage;
- Rectangle imageBounds;
-
- if (hierarchyIndicatorRect == null && itemHeight != -1) {
- hierarchyImage = getCollapsedImage();
- if (hierarchyImage != null) {
- imageBounds = hierarchyImage.getBounds();
- }
- else {
- imageBounds = new Rectangle(0, 0, 0, 0);
- }
- hierarchyIndicatorRect = new Rectangle(
- 0,
- (itemHeight - imageBounds.height) / 2 + (itemHeight - imageBounds.height) % 2,
- imageBounds.width,
- imageBounds.height);
- }
- return hierarchyIndicatorRect;
-}
-/**
- * Answer the index of 'item' in the receiver.
- */
-int getIndex(SelectableItem item) {
- int index = -1;
-
- if (item != null) {
- index = ((TreeItem) item).getGlobalIndex();
- }
- return 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 getRoot().getItemCount();
-}
-/**
- * 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 super.getItemHeight();
-}
-/**
- * Returns the number 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 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 TreeItem [] getItems() {
- checkWidget();
- TreeItem childrenArray[] = new TreeItem[getItemCount()];
-
- getRoot().getChildren().copyInto(childrenArray);
- return childrenArray;
-}
-/**
- * Answer the number of sub items of 'item' that do not fit in the
- * tree client area.
- */
-int getOffScreenItemCount(TreeItem item) {
- int itemIndexFromTop = item.getVisibleIndex() - getTopIndex();
- int spaceRemaining = getItemCountWhole()-(itemIndexFromTop+1);
- int expandedItemCount = item.getVisibleItemCount();
-
- return expandedItemCount - spaceRemaining;
-}
-/**
- * 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;
-}
-/**
- * Answer the object that holds the root items of the receiver.
- */
-TreeRoots getRoot() {
- return root;
-}
-/**
- * Returns an array of <code>TreeItem</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 TreeItem [] getSelection() {
- checkWidget();
- Vector selectionVector = getSelectionVector();
- TreeItem[] selectionArray = new TreeItem[selectionVector.size()];
-
- selectionVector.copyInto(selectionArray);
- sort(selectionArray, 0, selectionArray.length);
- return selectionArray;
-}
-/**
- * Answer the index of 'item' in the receiver.
- * Answer -1 if the item is not visible.
- * The returned index must refer to a visible item.
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. It only means that the item
- * would be displayed if it is located inside the receiver's
- * client area.
- * Collapsed items are not visible.
- */
-int getVisibleIndex(SelectableItem item) {
- int index = -1;
-
- if (item != null) {
- index = ((AbstractTreeItem) item).getVisibleIndex();
- }
- return index;
-}
-/**
- * Answer the SelectableItem located at 'itemIndex'
- * in the receiver.
- * @param itemIndex - location of the SelectableItem
- * object to return
- */
-SelectableItem getVisibleItem(int itemIndex) {
- return getRoot().getVisibleItem(itemIndex);
-}
-/**
- * Answer the number of visible items of the receiver.
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. It only means that the item
- * would be displayed if it is located inside the receiver's
- * client area.
- * Collapsed items are not visible.
- */
-int getVisibleItemCount() {
- return getRoot().getVisibleItemCount();
-}
-/**
- * Answer the y coordinate at which 'item' is drawn.
- * @param item - SelectableItem for which the paint position
- * should be returned
- * @return the y coordinate at which 'item' is drawn.
- * Return -1 if 'item' is null or outside the client area
- */
-int getVisibleRedrawY(SelectableItem item) {
- int redrawY = getRedrawY(item);
-
- if (redrawY < 0 || redrawY > getClientArea().height) {
- redrawY = -1;
- }
- return redrawY;
-}
-/**
- * Handle the events the receiver is listening to.
- */
-void handleEvents(Event event) {
- switch (event.type) {
- case SWT.Paint:
- paint(event);
- break;
- case SWT.MouseDown:
- mouseDown(event);
- break;
- case SWT.MouseDoubleClick:
- mouseDoubleClick(event);
- break;
- default:
- super.handleEvents(event);
- }
-}
-/**
- * Initialize the receiver.
- */
-void initialize() {
- resetRoot(); // has to be at very top because super class uses
- // functionality that relies on the TreeRoots object
- super.initialize();
-}
-/**
- * Initialize the ImageData used for the expanded/collapsed images.
- */
-static void initializeImageData() {
- 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)});
-
- CollapsedImageData = 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});
- CollapsedImageData.transparentPixel = 15; // use white for transparency
- ExpandedImageData = 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});
- ExpandedImageData.transparentPixel = 15; // use white for transparency
-}
-/**
- * Set event listeners for the receiver.
- */
-void installListeners() {
- Listener listener = getListener();
-
- super.installListeners();
- addListener(SWT.Paint, listener);
- addListener(SWT.MouseDown, listener);
- addListener(SWT.MouseDoubleClick, listener);
-}
-/**
- * Answer whether the receiver is currently expanding a sub tree
- * with 'item' in it.
- * Used for performance optimizations.
- */
-boolean isExpandingItem(SelectableItem item) {
- TreeItem parentItem;
-
- if (expandingItem == null || item == null || (item instanceof TreeItem) == false) {
- return false;
- }
- parentItem = ((TreeItem) item).getParentItem();
- return (parentItem == expandingItem || isExpandingItem(parentItem));
-}
-/**
- * Answer whether the children of 'collapsingItem' contain
- * at least one selected item.
- */
-boolean isSelectedItemCollapsing(TreeItem collapsingItem) {
- Enumeration selection = getSelectionVector().elements();
- TreeItem item;
- int selectedItemIndex;
- int collapsingItemIndex = collapsingItem.getVisibleIndex();
- int lastCollapsedItemIndex = collapsingItemIndex + collapsingItem.getVisibleItemCount();
-
- if (collapsingItemIndex == -1) { // is the collapsing item in a collapsed subtree?
- return false; // then neither it nor its children are selected
- }
- while (selection.hasMoreElements() == true) {
- item = (TreeItem) selection.nextElement();
- selectedItemIndex = item.getVisibleIndex();
- if ((selectedItemIndex > collapsingItemIndex) &&
- (selectedItemIndex <= lastCollapsedItemIndex)) {
- return true;
- }
- }
- return false;
-}
-/**
- * Test whether the mouse click specified by 'event' was a
- * valid selection or expand/collapse click.
- * @return
- * One of ActionExpandCollapse, ActionSelect, ActionNone, ActionCheck
- * specifying the action to be taken on the click.
- */
-int itemAction(TreeItem item, int x, int y) {
- int action = ActionNone;
- int itemHeight = getItemHeight();
- int offsetX;
- int offsetY;
- Point offsetPoint;
-
- if (item != null) {
- offsetX = x - item.getPaintStartX();
- offsetY = y - itemHeight * (y / itemHeight);
- offsetPoint = new Point(offsetX, offsetY);
- if ((item.isLeaf() == false) &&
- (getHierarchyIndicatorRect().contains(offsetPoint) == true)) {
- action |= ActionExpandCollapse;
- }
- else
- if (item.isSelectionHit(offsetPoint) == true) {
- action |= ActionSelect;
- }
- else
- if (item.isCheckHit(new Point(x, y)) == true) {
- action |= ActionCheck;
- }
- }
- return action;
-}
-/**
- * The table item 'changedItem' has changed. Redraw the whole
- * item in that column. Include the text in the redraw because
- * an image set to null requires a redraw of the whole item anyway.
- */
-void itemChanged(SelectableItem changedItem, int repaintStartX, int repaintWidth) {
- int oldItemHeight = getItemHeight();
- Point oldImageExtent = getImageExtent();
-
- if (isExpandingItem(changedItem) == false) {
- super.itemChanged(changedItem, repaintStartX, repaintWidth);
- }
- else {
- calculateItemHeight(changedItem);
- }
- if ((oldItemHeight != getItemHeight()) || // only reset items if the item height or
- (oldImageExtent != getImageExtent())) { // image size has changed. The latter will only change once,
- // from null to a value-so it's safe to test using !=
- getRoot().reset(); // reset cached data of all items in the receiver
- resetHierarchyIndicatorRect();
- redraw(); // redraw all items if the image extent has changed. Fixes 1FRIHPZ
- }
- else {
- ((AbstractTreeItem) changedItem).reset(); // reset the item that has changed when the tree item
- // height has not changed (otherwise the item caches old data)
- // Fixes 1FF6B42
- }
- if (repaintWidth != 0) {
- calculateWidestShowingItem();
- claimRightFreeSpace(); // otherwise scroll bar may be reset, but not horizontal offset
- // Fixes 1G4SBJ3
- }
-}
-/**
- * A key was pressed.
- * Call the appropriate key handler method.
- * @param event - the key event
- */
-void keyDown(Event event) {
- super.keyDown(event);
- switch (event.character) {
- case '+':
- doPlus();
- break;
- case '-':
- doMinus();
- break;
- case '*':
- doAsterix();
- break;
- }
-}
-
-/**
- * A mouse double clicked occurred over the receiver.
- * Expand/collapse the clicked item. Do nothing if no item was clicked.
- */
-void mouseDoubleClick(Event event) {
- int hitItemIndex = event.y / getItemHeight();
- TreeItem hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
- Event newEvent;
-
- if (hitItem == null || itemAction(hitItem, event.x, event.y) != ActionSelect) {
- return;
- }
- if (isListening(SWT.DefaultSelection) == true) {
- newEvent = new Event();
- newEvent.item = hitItem;
- notifyListeners(SWT.DefaultSelection, newEvent);
- }
- else
- if (hitItem.isLeaf() == false) { // item with children was hit. Default behavior is expand/collapse item
- if (hitItem.getExpanded() == true) {
- collapse(hitItem, true);
- }
- else {
- expand(hitItem, true);
- }
- }
-}
-/**
- * The mouse pointer was pressed down on the receiver.
- * Handle the event according to the position of the mouse click.
- */
-void mouseDown(Event event) {
- int hitItemIndex;
- TreeItem hitItem;
- SelectableItem selectionItem = getLastSelection();
- int itemAction;
-
- hitItemIndex = event.y / getItemHeight();
- hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
- if (hitItem == null) {
- return;
- }
- if (!isFocusControl()) forceFocus();
- switch (itemAction = itemAction(hitItem, event.x, event.y)) {
- case ActionExpandCollapse:
- if (event.button != 1) return;
- if (hitItem.getExpanded() == true) {
- collapse(hitItem, true);
- }
- else {
- expand(hitItem, true);
- }
- break;
- case ActionSelect:
- doMouseSelect(hitItem, hitItemIndex + getTopIndex(), event.stateMask, event.button);
- break;
- case ActionCheck:
- if (event.button != 1) return;
- doCheckItem(hitItem);
- break;
- }
- if (itemAction != ActionSelect && selectionItem == null) {
- selectionItem = getRoot().getVisibleItem(getTopIndex()); // select the top item if no item was selected before
- selectNotify(selectionItem);
- }
-}
-/**
- * A paint event has occurred. Display the invalidated items.
- * @param event - expose event specifying the invalidated area.
- */
-void paint(Event event) {
- int visibleRange[] = getIndexRange(event.getBounds());
-
- paintItems(event.gc, visibleRange[0], visibleRange[1] + 1); // + 1 to paint the vertical line
- // connection the last item we really
- // want to paint with the item after that.
-}
-/**
- * Paint tree items on 'gc' starting at index 'topPaintIndex' and
- * stopping at 'bottomPaintIndex'.
- * @param gc - GC to draw tree items on.
- * @param topPaintIndex - index of the first item to draw
- * @param bottomPaintIndex - index of the last item to draw
- */
-void paintItems(GC gc, int topPaintIndex, int bottomPaintIndex) {
- TreeItem visibleItem;
- int itemHeight = getItemHeight();
-
- for (int i = topPaintIndex; i <= bottomPaintIndex; i++) {
- visibleItem = getRoot().getVisibleItem(i + getTopIndex());
- if (visibleItem != null) {
- visibleItem.paint(gc, i * itemHeight);
- }
- }
-}
-/**
- * 'item' has been added to or removed from the receiver.
- * Repaint part of the tree to update the vertical hierarchy
- * connectors and hierarchy image.
- * @param modifiedItem - the added/removed item
- * @param modifiedIndex - index of the added/removed item
- */
-void redrawAfterModify(SelectableItem modifiedItem, int modifiedIndex) {
- int redrawStartY;
- int redrawStopY;
- int itemChildIndex = ((TreeItem) modifiedItem).getIndex();
- int topIndex = getTopIndex();
- int itemHeight = getItemHeight();
- int redrawItemIndex;
- int itemCount;
- AbstractTreeItem parentItem = ((TreeItem) modifiedItem).getParentItem();
- AbstractTreeItem redrawItem = null;
-
- if (redrawParentItem(modifiedItem) == false) {
- return;
- }
- if (parentItem == null) { // a root item is added/removed
- parentItem = getRoot();
- }
- itemCount = parentItem.getItemCount();
- // redraw hierarchy decorations of preceeding item if the last item at a tree
- // level was added/removed
- // otherwise, if the first item was removed, redraw the parent to update hierarchy icon
- if (itemChildIndex > 0) { // more than one item left at this tree level
- // added/removed last item at this tree level? have to test >=.
- // when removing last item, item index is outside itemCount
- if (itemChildIndex >= itemCount - 1) {
- redrawItem = (AbstractTreeItem) parentItem.getChildren().elementAt(itemChildIndex - 1);
- }
- }
- else
- if (getVisibleItemCount() > 0 && itemCount < 2) { // last item at this level removed/first item added?
- redrawItem = parentItem; // redraw parent item to update hierarchy icon
- }
- if (redrawItem != null) {
- redrawItemIndex = redrawItem.getVisibleIndex();
- if (modifiedIndex == -1) {
- modifiedIndex = redrawItemIndex + 1;
- }
- redrawStartY = (redrawItemIndex - topIndex) * itemHeight;
- redrawStopY = (modifiedIndex - topIndex) * itemHeight;
- redraw(
- 0,
- redrawStartY,
- redrawItem.getCheckboxXPosition(), // only redraw up to and including hierarchy icon to avoid flashing
- redrawStopY - redrawStartY, false);
- }
- if (modifiedIndex == 0) { // added/removed first item ?
- redraw(0, 0, getClientArea().width, getItemHeight() * 2, false);// redraw new first two items to
- // fix vertical hierarchy line
- }
-}
-
-/**
- * Determine if part of the tree hierarchy needs to be redrawn.
- * The hierarchy icon of the parent item of 'item' needs to be redrawn if
- * 'item' is added as the first child or removed as the last child.
- * Hierarchy lines need to be redrawn if 'item' is the last in a series of
- * children.
- * @param item - tree item that is added or removed.
- * @return true=tree hierarchy needs to be redrawn. false=no redraw necessary
- */
-boolean redrawParentItem(SelectableItem item) {
- TreeItem parentItem = ((TreeItem) item).getParentItem();
- TreeItem parentItem2;
- boolean redraw = false;
-
- // determine if only the hierarchy icon needs to be redrawn
- if (parentItem != null) {
- parentItem2 = parentItem.getParentItem();
- if ((parentItem2 == null || parentItem2.getExpanded() == true) && parentItem.getChildren().size() < 2) {
- redraw = true;
- }
- }
- // redraw is only neccessary when the receiver is not currently
- // expanding 'item' or a parent item or if the parent item is expanded
- // or if the hierarchy icon of the parent item needs to be redrawn
- if (isExpandingItem(item) == false && parentItem == null || parentItem.getExpanded() == true || redraw == true) {
- redraw = true;
- }
- else {
- redraw = false;
- }
- return redraw;
-}
-
-/**
- * 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();
- setRedraw(false);
- getRoot().dispose();
- resetRoot();
- reset();
- calculateWidestShowingItem();
- calculateVerticalScrollbar();
- setRedraw(true);
-}
-/**
- * Remove 'item' from the receiver.
- * @param item - tree item that should be removed from the
- * receiver-must be a root item.
- */
-void removeItem(TreeItem item) {
- getRoot().removeItem(item);
-}
-/**
- * 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);
-}
-/**
- * 'item' has been removed from the receiver.
- * Recalculate the content width.
- */
-void removedItem(SelectableItem item) {
- if (isExpandingItem(item) == false) {
- super.removedItem(item);
- }
- calculateWidestShowingItem();
- claimRightFreeSpace();
-}
-/**
- * Notification that 'item' is about to be removed from the tree.
- * Update the item selection if neccessary.
- * @param item - item that is about to be removed from the tree.
- */
-void removingItem(SelectableItem item) {
- Vector selection = getSelectionVector();
- TreeItem parentItem = ((TreeItem) item).getParentItem();
- TreeItem newSelectionItem = null;
- boolean isLastSelected = (selection.size() == 1) && (selection.elementAt(0) == item);
- int itemIndex = getVisibleIndex(item);
-
- if (isLastSelected == true) {
- // try selecting the following item
- newSelectionItem = (TreeItem) getVisibleItem(itemIndex + 1);
- if (newSelectionItem == null || newSelectionItem.getParentItem() != parentItem) {
- // select parent item if there is no item following the removed
- // one on the same tree level
- newSelectionItem = parentItem;
- }
- if (newSelectionItem != null) {
- selectNotify(newSelectionItem, true);
- }
- }
- super.removingItem(item);
- if (isExpandingItem(item) == false) {
- // redraw plus/minus image, hierarchy lines,
- // redrawing here assumes that no update happens between now and
- // after the item has actually been removed. Otherwise this call
- // would need to be in removedItem and we would need to store the
- // "itemIndex" here to redraw correctly.
- redrawAfterModify(item, itemIndex);
- }
-}
-/**
- * Reset the rectangle enclosing the hierarchy indicator to null.
- * Forces a recalculation next time getHierarchyIndicatorRect is called.
- */
-void resetHierarchyIndicatorRect() {
- hierarchyIndicatorRect = null;
-}
-/**
- * Reset state that is dependent on or calculated from the items
- * of the receiver.
- */
-void resetItemData() {
- setContentWidth(0);
- resetHierarchyIndicatorRect();
- super.resetItemData();
-}
-/**
- * Reset the object holding the root items of the receiver.
- */
-void resetRoot() {
- root = new TreeRoots(this);
-}
-/**
- * The receiver has been resized. Recalculate the content width.
- */
-void resize(Event event) {
- int oldItemCount = getVerticalBar().getPageIncrement();
-
- super.resize(event);
- if (getItemCountWhole() > oldItemCount) { // window resized higher?
- calculateWidestShowingItem(); // recalculate widest item since a longer item may be visible now
- }
-}
-/**
- * Display as many expanded tree items as possible.
- * Scroll the last expanded child to the bottom if all expanded
- * children can be displayed.
- * Otherwise scroll the expanded item to the top.
- * @param item - the tree item that was expanded
- */
-void scrollExpandedItemsIntoView(TreeItem item) {
- int itemCountOffScreen = getOffScreenItemCount(item);
- int newTopIndex = getTopIndex() + itemCountOffScreen;
-
- if (itemCountOffScreen > 0) {
- newTopIndex = Math.min(item.getVisibleIndex(), newTopIndex); // make sure the expanded item is never scrolled out of view
- setTopIndex(newTopIndex, true);
- }
-}
-/**
- * Scroll the items following the children of 'collapsedItem'
- * below 'collapsedItem' to cover the collapsed children.
- * @param collapsedItem - item that has been collapsed
- */
-void scrollForCollapse(TreeItem collapsedItem) {
- Rectangle clientArea = getClientArea();
- int topIndex = getTopIndex();
- int itemCount = collapsedItem.getVisibleItemCount();
- int scrollYPositions[] = calculateChildrenYPos(collapsedItem);
-
- if (scrollYPositions[0] == -1 && scrollYPositions[1] == -1) {
- return;
- }
- if (topIndex + getItemCountWhole() == getVisibleItemCount() && itemCount < topIndex) {
- // scroll from top if last item is at bottom and will stay at
- // bottom after collapse. Avoids flash caused by too much bit
- // blitting (which force update and thus premature redraw)
- int height = scrollYPositions[1] - scrollYPositions[0];
- scroll(
- 0, 0, // destination x, y
- 0, -height, // source x, y
- clientArea.width, scrollYPositions[0]+height, true);
- setTopIndexNoScroll(topIndex - itemCount, true);
- }
- else {
- scroll(
- 0, scrollYPositions[0], // destination x, y
- 0, scrollYPositions[1], // source x, y
- clientArea.width, clientArea.height - scrollYPositions[0], true);
- }
-}
-/**
- * Scroll the items following 'expandedItem' down to make
- * space for the children of 'expandedItem'.
- * @param expandedItem - item that has been expanded.
- */
-void scrollForExpand(TreeItem expandedItem) {
- int scrollYPositions[];
- Rectangle clientArea = getClientArea();
-
- expandedItem.internalSetExpanded(true);
- scrollYPositions = calculateChildrenYPos(expandedItem);
- expandedItem.internalSetExpanded(false);
- if (scrollYPositions[0] == -1 && scrollYPositions[1] == -1) {
- return;
- }
- scroll(
- 0, scrollYPositions[1], // destination x, y
- 0, scrollYPositions[0], // source x, y
- clientArea.width, clientArea.height, true);
-}
-/**
- * Scroll horizontally by 'numPixel' pixel.
- * @param numPixel - the number of pixel to scroll
- * < 0 = columns are going to be moved left.
- * > 0 = columns are going to be moved right.
- */
-void scrollHorizontal(int numPixel) {
- Rectangle clientArea = getClientArea();
-
- scroll(
- numPixel, 0, // destination x, y
- 0, 0, // source x, y
- clientArea.width, clientArea.height, true);
-}
-/**
- * Scroll vertically by 'scrollIndexCount' items.
- * @param scrollIndexCount - the number of items to scroll.
- * scrollIndexCount > 0 = scroll up. scrollIndexCount < 0 = scroll down
- */
-void scrollVertical(int scrollIndexCount) {
- Rectangle clientArea = getClientArea();
-
- scroll(
- 0, 0, // destination x, y
- 0, scrollIndexCount * getItemHeight(), // source x, y
- clientArea.width, clientArea.height, true);
-}
-/**
- * Selects all 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 void selectAll() {
- checkWidget();
- Vector selection = getSelectionVector();
-
- if (isMultiSelect() == true) {
- selection = getRoot().selectAll(selection);
- setSelectionVector(selection);
- }
-}
-/**
- * Set the item that is currently being expanded to 'item'.
- * Used for performance optimizations.
- */
-void setExpandingItem(TreeItem item) {
- expandingItem = item;
-}
-public void setFont(Font font) {
- checkWidget();
- Stack children = new Stack(); // traverse the tree depth first
- Enumeration elements;
- AbstractTreeItem item;
-
- if (font != null && font.equals(getFont()) == true) {
- return;
- }
- setRedraw(false); // disable redraw because itemChanged() triggers undesired redraw
- resetItemData();
- super.setFont(font);
-
- // Call itemChanged for all tree items
- elements = getRoot().getChildren().elements();
- while (elements.hasMoreElements() == true) {
- children.push(elements.nextElement());
- }
- while (children.empty() == false) {
- item = (AbstractTreeItem) children.pop();
- itemChanged(item, 0, getClientArea().width);
- elements = item.getChildren().elements();
- while (elements.hasMoreElements() == true) {
- children.push(elements.nextElement());
- }
- }
- setRedraw(true); // re-enable redraw
-}
-/**
- * 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 after 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);
- motif_setInsertMark(item, !before);
-}
-/**
- * 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 array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of 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#deselectAll()
- */
-public void setSelection(TreeItem selectionItems[]) {
- checkWidget();
- if (selectionItems == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- setSelectableSelection(selectionItems);
-}
-/**
- * Set the index of the first visible item in the tree client area
- * to 'index'.
- * Scroll the new top item to the top of the tree.
- * @param index - 0-based index of the first visible item in the
- * tree's client area.
- * @param adjustScrollbar -
- * true = the vertical scroll bar is set to reflect the new top index.
- * false = the vertical scroll bar position is not modified.
- */
-void setTopIndex(int index, boolean adjustScrollbar) {
- int indexDiff = index-getTopIndex();
-
- super.setTopIndex(index, adjustScrollbar);
- calculateWidestScrolledItem(indexDiff);
-}
-public void setTopItem(TreeItem item) {
- checkWidget();
- if (item == null) error(SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (item.isVisible() == false) {
- item.makeVisible();
- }
- scrollExpandedItemsIntoView(item);
-}
-/**
- * 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);
- showSelectableItem(item);
-}
-/**
- * Make 'item' visible by expanding its parent items and scrolling
- * it into the receiver's client area if necessary.
- * An SWT.Expand event is going to be sent for every parent item
- * that is expanded to make 'item' visible.
- * @param item - the item that should be made visible to the
- * user.
- */
-void showSelectableItem(SelectableItem item) {
- if (item.getSelectableParent() != this) {
- return;
- }
- if (((TreeItem) item).isVisible() == false) {
- ((TreeItem) item).makeVisible();
- }
- super.showSelectableItem(item);
-}
-/**
- * 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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 itemHeight;
- int hitItemIndex;
- TreeItem hitItem;
-
- if (getClientArea().contains(point) == false) {
- return null;
- }
- itemHeight = getItemHeight();
- hitItemIndex = point.y / itemHeight;
- hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
- if (hitItem != null) {
- Point pt = new Point(point.x, point.y);
- pt.x -= hitItem.getPaintStartX();
- pt.y -= itemHeight * hitItemIndex;
- if (hitItem.isSelectionHit(pt) == false) {
- hitItem = null;
- }
- }
- return hitItem;
-}
-/**
- * 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 super.getSelectionCount();
-}
-public TreeItem getTopItem() {
- checkWidget();
- return (TreeItem)getVisibleItem(getTopIndex());
-}
-/**
- * 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 IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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();
- super.showSelection();
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import java.util.Enumeration;
+import java.util.Stack;
+import java.util.Vector;
+
+/**
+ * Instances of this class provide a selectable user interface object
+ * that displays a hierarchy of items and issue notificiation 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>
+ * 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</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>Selection, DefaultSelection, Collapse, Expand</dd>
+ * </dl>
+ * <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 SelectableItemWidget {
+ // These constants are used internally for item hit test on mouse click
+ private static final int ActionNone = 0; // The mouse event was not handled
+ private static final int ActionExpandCollapse = 1; // Do an expand/collapse
+ private static final int ActionSelect = 2; // Select the item
+ private static final int ActionCheck = 3; // Toggle checked state of the item
+ private static ImageData CollapsedImageData; // collapsed sub tree image data. used to create an image at run time
+ private static ImageData ExpandedImageData; // expanded sub tree image data. used to create an image at run time
+ static {
+ initializeImageData();
+ }
+
+ private TreeRoots root;
+ private TreeItem expandingItem;
+
+ private Image collapsedImage;
+ private Image expandedImage;
+
+ // The following fields are needed for painting tree items
+ final Color CONNECTOR_LINE_COLOR; // Color constant used during painting. Can't keep this in TreeItem
+ // because we only need one instance per tree widget/display and can't
+ // have it static. Initialized in c'tor and freed in dispose();
+ Rectangle hierarchyIndicatorRect = null; // bounding rectangle of the hierarchy indication image (plus/minus)
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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));
+ CONNECTOR_LINE_COLOR = new Color(getDisplay(), 170, 170, 170); // Light gray;
+}
+/**
+ * Add 'item' to the list of root items.
+ * @param 'item' - the tree item that should be added as a root.
+ * @param index - position that 'item' will be inserted at
+ * in the receiver.
+ */
+void addItem(TreeItem item, int index) {
+ if (index < 0 || index > getItemCount()) {
+ error(SWT.ERROR_INVALID_RANGE);
+ }
+ getRoot().add(item, index);
+}
+/**
+ * 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 reciever 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();
+ TypedListener typedListener;
+
+ if (listener == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ 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();
+ TypedListener typedListener;
+
+ if (listener == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ typedListener = new TypedListener(listener);
+ addListener(SWT.Expand, typedListener);
+ addListener(SWT.Collapse, typedListener);
+}
+/**
+ * The SelectableItem 'item' has been added to the tree.
+ * Prevent screen updates when 'item' is inserted due to an
+ * expand operation.
+ * @param item - item that has been added to the receiver.
+ */
+void addedItem(SelectableItem item, int index) {
+ super.addedItem(item, index);
+ redrawAfterModify(item, index); // redraw plus/minus image, hierarchy lines
+}
+/**
+ * Answer the y position of both the first child of 'item' and
+ * the item following the last child of 'item'.
+ * Used to scroll items on expand/collapse.
+ * @param item - TreeItem to use for calculating the y boundary
+ * of child items.
+ * @return Array - first element is the position of the first
+ * child of 'item'. Second element is the position of the item
+ * following the last child of 'item'.
+ * Both elements are -1 if 'item' is not a child of the receiver.
+ */
+int[] calculateChildrenYPos(TreeItem item) {
+ int itemIndex = item.getVisibleIndex();
+ int itemCount = item.getVisibleItemCount();
+ int itemHeight = getItemHeight();
+ int yPos;
+ int[] yPosition = new int[] {-1, -1};
+
+ if (itemIndex != -1) {
+ itemIndex -= getTopIndex();
+ yPos = (itemIndex + itemCount + 1) * itemHeight; // y position of the item following
+ // the last child of 'item'
+ yPosition = new int[] {yPos - (itemCount * itemHeight), yPos};
+ }
+ return yPosition;
+}
+/**
+ * Calculate the widest of the children of 'item'.
+ * Items that are off screen and that may be scrolled into view are
+ * included in the calculation.
+ * @param item - the tree item that was expanded
+ */
+void calculateWidestExpandingItem(TreeItem item) {
+ int itemIndex = item.getVisibleIndex();
+ int newMaximumItemWidth = getContentWidth();
+ int stopIndex = itemIndex + item.getVisibleItemCount();
+
+ for (int i = itemIndex + 1; i <= stopIndex; i++) {
+ newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
+ }
+ setContentWidth(newMaximumItemWidth);
+}
+/**
+ * Calculate the width of new items as they are scrolled into view.
+ * Precondition:
+ * topIndex has already been set to the new index.
+ * @param topIndexDifference - difference between old and new top
+ * index.
+ */
+void calculateWidestScrolledItem(int topIndexDifference) {
+ int visibleItemCount = getItemCountTruncated(getClientArea());
+ int newMaximumItemWidth = getContentWidth();
+ int topIndex = getTopIndex();
+ int stopIndex = topIndex;
+
+ if (topIndexDifference < 0) { // scrolled up?
+ if (Math.abs(topIndexDifference) > visibleItemCount) { // scrolled down more than one page (via quick thumb dragging)?
+ topIndexDifference = visibleItemCount * -1;
+ }
+ for (int i = stopIndex - topIndexDifference; i >= stopIndex; i--) { // check item width from old top index up to new one
+ newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
+ }
+ }
+ else
+ if (topIndexDifference > 0) { // scrolled down?
+ if (topIndexDifference > visibleItemCount) { // scrolled down more than one page (via quick thumb dragging)?
+ topIndexDifference = visibleItemCount;
+ }
+ stopIndex += visibleItemCount;
+ for (int i = stopIndex - topIndexDifference; i < stopIndex; i++) {
+ newMaximumItemWidth = Math.max(newMaximumItemWidth, getContentWidth(i));
+ }
+ }
+ setContentWidth(newMaximumItemWidth);
+}
+/**
+ * Calculate the maximum item width of all displayed items.
+ */
+void calculateWidestShowingItem() {
+ TreeItem visibleItem;
+ int newMaximumItemWidth = 0;
+ int bottomIndex = getBottomIndex();
+ int paintStopX;
+
+ // add one to the loop end index because otherwise an item covered
+ // by the horizontal scroll bar would not be taken into acount and
+ // may become visible after this calculation. We're in trouble if
+ // that item is wider than the client area.
+ if (getHorizontalBar().getVisible() == true) {
+ bottomIndex++;
+ }
+ for (int i = getTopIndex(); i < bottomIndex; i++) {
+ visibleItem = getRoot().getVisibleItem(i);
+ if (visibleItem != null) {
+ paintStopX = visibleItem.getPaintStopX();
+ newMaximumItemWidth = Math.max(newMaximumItemWidth, paintStopX);
+ }
+ }
+ setContentWidth(newMaximumItemWidth);
+}
+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);
+}
+/**
+ * Collapse the tree item identified by 'item' if it is not
+ * already collapsed. Move the selection to the parent item
+ * if one of the collapsed items is currently selected.
+ * @param item - item that should be collapsed.
+ * @param notifyListeners -
+ * true=a Collapse event is sent
+ * false=no event is sent
+ */
+void collapse(TreeItem item, boolean notifyListeners) {
+ Event event;
+ int itemIndex;
+
+ if (item.getExpanded() == false) {
+ return;
+ }
+ collapseNoRedraw(item);
+ itemIndex = item.getVisibleIndex();
+ if (itemIndex != -1) { // if the item's parent is not collapsed (and the item is thus visible) do the screen updates
+ item.redrawExpanded(itemIndex - getTopIndex());
+ showSelectableItem(item);
+ calculateVerticalScrollbar();
+ calculateWidestShowingItem();
+ claimRightFreeSpace();
+ claimBottomFreeSpace();
+ }
+ if (notifyListeners == true) {
+ event = new Event();
+ event.item = item;
+ notifyListeners(SWT.Collapse, event);
+ }
+}
+
+/**
+ * Collapse the tree item identified by 'item' if it is not
+ * already collapsed. Move the selection to the parent item
+ * if one of the collapsed items is currently selected.
+ * This method is used to hide the children if an item is deleted.
+ * certain redraw and scroll operations are not needed for this
+ * case.
+ * @param item - item that should be collapsed.
+ */
+void collapseNoRedraw(TreeItem item) {
+
+ if (item.getExpanded() == false) {
+ return;
+ }
+ if (isSelectedItemCollapsing(item) == true) {
+ deselectAllExcept(item);
+ selectNotify(item);
+ update(); // call update to make sure that new selection is
+ // drawn before items are collapsed (looks better)
+ }
+ scrollForCollapse(item);
+ item.internalSetExpanded(false);
+}
+
+public Point computeSize(int wHint, int hHint, boolean changed) {
+ checkWidget();
+ Point size = super.computeSize(wHint, hHint, changed);
+ GC gc;
+ final int WidthCalculationCount = 50; // calculate item width for the first couple of items only
+ TreeRoots root = getRoot();
+ TreeItem item;
+ Image itemImage;
+ String itemText;
+ int width;
+ int newItemWidth = 0;
+
+ if (wHint == SWT.DEFAULT && getContentWidth() == 0 && getItemCount() > 0) {
+ gc = new GC(this);
+ for (int i = 0; i < WidthCalculationCount; i++) {
+ item = root.getVisibleItem(i);
+ if (item == null) {
+ break; // no more items
+ }
+ itemImage = item.getImage();
+ itemText = item.getText();
+ width = 0;
+ if (itemImage != null) {
+ width += itemImage.getBounds().width;
+ }
+ if (itemText != null) {
+ width += gc.stringExtent(itemText).x;
+ }
+ newItemWidth = Math.max(newItemWidth, width);
+ }
+ if (newItemWidth > 0) {
+ size.x = newItemWidth;
+ }
+ gc.dispose();
+ }
+ return size;
+}
+/**
+ * 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();
+ getRoot().deselectAll();
+ getSelectionVector().removeAllElements();
+ redraw();
+}
+/**
+ * Modifier Key Action
+ * None Collapse the selected item if expanded. Select
+ * parent item if selected item is already
+ * collapsed and if it's not the root item.
+ * Ctrl super.doArrowLeft(int);
+ * Shift see None above
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowLeft(int keyMask) {
+ TreeItem focusItem = (TreeItem) getLastFocus();
+ TreeItem parentItem;
+
+ if (focusItem == null) {
+ return;
+ }
+ if (keyMask == SWT.MOD1) {
+ super.doArrowLeft(keyMask);
+ }
+ else
+ if (focusItem.getExpanded() == true) { // collapse if expanded
+ collapse(focusItem, true);
+ }
+ else
+ if (focusItem.isRoot() == false) { // go to the parent if there is one
+ parentItem = focusItem.getParentItem();
+ deselectAllExcept(parentItem);
+ selectNotify(parentItem);
+ }
+}
+/**
+ * Modifier Key Action
+ * None Expand selected item if collapsed. Select
+ * first child item if selected item is
+ * already expanded and there is a child item.
+ * Ctrl super.doArrowRight(keyMask);
+ * Shift see None above
+ * @param keyMask - the modifier key that was pressed
+ */
+void doArrowRight(int keyMask) {
+ TreeItem focusItem = (TreeItem) getLastFocus();
+ TreeItem childItem;
+
+ if (focusItem == null) {
+ return;
+ }
+ if (keyMask == SWT.MOD1) {
+ super.doArrowRight(keyMask);
+ }
+ else
+ if (focusItem.isLeaf() == false) {
+ if (focusItem.getExpanded() == false) { // expand if collapsed
+ expand(focusItem, true);
+ }
+ else { // go to the first child if there is one
+ childItem = focusItem.getItems()[0];
+ deselectAllExcept(childItem);
+ selectNotify(childItem);
+ }
+ }
+}
+/**
+ * Expand the selected item and all of its children.
+ */
+void doAsterix() {
+ expandAll((TreeItem) getLastFocus());
+}
+/**
+ * Free resources.
+ */
+void doDispose() {
+ super.doDispose();
+ if (collapsedImage != null) {
+ collapsedImage.dispose();
+ }
+ if (expandedImage != null) {
+ expandedImage.dispose();
+ }
+ getRoot().dispose();
+ CONNECTOR_LINE_COLOR.dispose();
+ resetHierarchyIndicatorRect();
+}
+/**
+ * Collapse the selected item if it is expanded.
+ */
+void doMinus() {
+ TreeItem selectedItem = (TreeItem) getLastFocus();
+
+ if (selectedItem != null) {
+ collapse(selectedItem, true);
+ }
+}
+/**
+ * Expand the selected item if it is collapsed and if it
+ * has children.
+ */
+void doPlus() {
+ TreeItem selectedItem = (TreeItem) getLastFocus();
+
+ if (selectedItem != null && selectedItem.isLeaf() == false) {
+ expand(selectedItem, true);
+ }
+}
+/**
+ * Expand the tree item identified by 'item' if it is not already
+ * expanded. Scroll the expanded items into view.
+ * @param item - item that should be expanded
+ * @param notifyListeners -
+ * true=an Expand event is sent
+ * false=no event is sent
+ */
+void expand(TreeItem item, boolean notifyListeners) {
+ Event event = new Event();
+ boolean nestedExpand = expandingItem != null;
+
+ if (item.getExpanded() == true || item.getExpanding() == true) {
+ return;
+ }
+ item.setExpanding(true);
+ if (nestedExpand == false) {
+ setExpandingItem(item);
+ }
+ if (notifyListeners == true) {
+ event.item = item;
+ notifyListeners(SWT.Expand, event);
+ }
+ scrollForExpand(item);
+ item.internalSetExpanded(true);
+ // redraw hierarchy image
+ item.redrawExpanded(item.getVisibleIndex() - getTopIndex());
+ calculateVerticalScrollbar();
+ if (nestedExpand == false && isVisible() == true) {
+ showSelectableItem(item); // make expanded item visible. Could be invisible if the expand was caused by a key press.
+ calculateWidestExpandingItem(item);
+ scrollExpandedItemsIntoView(item);
+ }
+ if (nestedExpand == false) {
+ setExpandingItem(null);
+ }
+ item.setExpanding(false);
+}
+/**
+ * Expand 'item' and all its children.
+ */
+void expandAll(TreeItem item) {
+ TreeItem items[];
+
+ if (item != null && item.isLeaf() == false) {
+ expand(item, true);
+ update();
+ items = item.getItems();
+ for (int i = 0; i < items.length; i++) {
+ expandAll(items[i]);
+ }
+ }
+}
+/**
+ * Answer the image that is used as a hierarchy indicator
+ * for a collapsed hierarchy.
+ */
+Image getCollapsedImage() {
+ if (collapsedImage == null) {
+ collapsedImage = new Image(getDisplay(), CollapsedImageData);
+ }
+ return collapsedImage;
+}
+/**
+ * Answer the width of the item identified by 'itemIndex'.
+ */
+int getContentWidth(int itemIndex) {
+ TreeItem item = getRoot().getVisibleItem(itemIndex);
+ int paintStopX = 0;
+
+ if (item != null) {
+ paintStopX = item.getPaintStopX();
+ }
+ return paintStopX;
+}
+/**
+ * Answer the image that is used as a hierarchy indicator
+ * for an expanded hierarchy.
+ */
+Image getExpandedImage() {
+ if (expandedImage == null) {
+ expandedImage = new Image(getDisplay(), ExpandedImageData);
+ }
+ return expandedImage;
+}
+/**
+ * Answer the rectangle enclosing the hierarchy indicator of a tree item.
+ *
+ * Note:
+ * Assumes that the hierarchy indicators for expanded and
+ * collapsed state are the same size.
+ * @return
+ * The rectangle enclosing the hierarchy indicator.
+ */
+Rectangle getHierarchyIndicatorRect() {
+ int itemHeight = getItemHeight();
+ Image hierarchyImage;
+ Rectangle imageBounds;
+
+ if (hierarchyIndicatorRect == null && itemHeight != -1) {
+ hierarchyImage = getCollapsedImage();
+ if (hierarchyImage != null) {
+ imageBounds = hierarchyImage.getBounds();
+ }
+ else {
+ imageBounds = new Rectangle(0, 0, 0, 0);
+ }
+ hierarchyIndicatorRect = new Rectangle(
+ 0,
+ (itemHeight - imageBounds.height) / 2 + (itemHeight - imageBounds.height) % 2,
+ imageBounds.width,
+ imageBounds.height);
+ }
+ return hierarchyIndicatorRect;
+}
+/**
+ * Answer the index of 'item' in the receiver.
+ */
+int getIndex(SelectableItem item) {
+ int index = -1;
+
+ if (item != null) {
+ index = ((TreeItem) item).getGlobalIndex();
+ }
+ return 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 getRoot().getItemCount();
+}
+/**
+ * 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 super.getItemHeight();
+}
+/**
+ * Returns the number 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 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 TreeItem [] getItems() {
+ checkWidget();
+ TreeItem childrenArray[] = new TreeItem[getItemCount()];
+
+ getRoot().getChildren().copyInto(childrenArray);
+ return childrenArray;
+}
+/**
+ * Answer the number of sub items of 'item' that do not fit in the
+ * tree client area.
+ */
+int getOffScreenItemCount(TreeItem item) {
+ int itemIndexFromTop = item.getVisibleIndex() - getTopIndex();
+ int spaceRemaining = getItemCountWhole()-(itemIndexFromTop+1);
+ int expandedItemCount = item.getVisibleItemCount();
+
+ return expandedItemCount - spaceRemaining;
+}
+/**
+ * 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;
+}
+/**
+ * Answer the object that holds the root items of the receiver.
+ */
+TreeRoots getRoot() {
+ return root;
+}
+/**
+ * Returns an array of <code>TreeItem</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 TreeItem [] getSelection() {
+ checkWidget();
+ Vector selectionVector = getSelectionVector();
+ TreeItem[] selectionArray = new TreeItem[selectionVector.size()];
+
+ selectionVector.copyInto(selectionArray);
+ sort(selectionArray, 0, selectionArray.length);
+ return selectionArray;
+}
+/**
+ * Answer the index of 'item' in the receiver.
+ * Answer -1 if the item is not visible.
+ * The returned index must refer to a visible item.
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. It only means that the item
+ * would be displayed if it is located inside the receiver's
+ * client area.
+ * Collapsed items are not visible.
+ */
+int getVisibleIndex(SelectableItem item) {
+ int index = -1;
+
+ if (item != null) {
+ index = ((AbstractTreeItem) item).getVisibleIndex();
+ }
+ return index;
+}
+/**
+ * Answer the SelectableItem located at 'itemIndex'
+ * in the receiver.
+ * @param itemIndex - location of the SelectableItem
+ * object to return
+ */
+SelectableItem getVisibleItem(int itemIndex) {
+ return getRoot().getVisibleItem(itemIndex);
+}
+/**
+ * Answer the number of visible items of the receiver.
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. It only means that the item
+ * would be displayed if it is located inside the receiver's
+ * client area.
+ * Collapsed items are not visible.
+ */
+int getVisibleItemCount() {
+ return getRoot().getVisibleItemCount();
+}
+/**
+ * Answer the y coordinate at which 'item' is drawn.
+ * @param item - SelectableItem for which the paint position
+ * should be returned
+ * @return the y coordinate at which 'item' is drawn.
+ * Return -1 if 'item' is null or outside the client area
+ */
+int getVisibleRedrawY(SelectableItem item) {
+ int redrawY = getRedrawY(item);
+
+ if (redrawY < 0 || redrawY > getClientArea().height) {
+ redrawY = -1;
+ }
+ return redrawY;
+}
+/**
+ * Handle the events the receiver is listening to.
+ */
+void handleEvents(Event event) {
+ switch (event.type) {
+ case SWT.Paint:
+ paint(event);
+ break;
+ case SWT.MouseDown:
+ mouseDown(event);
+ break;
+ case SWT.MouseDoubleClick:
+ mouseDoubleClick(event);
+ break;
+ default:
+ super.handleEvents(event);
+ }
+}
+/**
+ * Initialize the receiver.
+ */
+void initialize() {
+ resetRoot(); // has to be at very top because super class uses
+ // functionality that relies on the TreeRoots object
+ super.initialize();
+}
+/**
+ * Initialize the ImageData used for the expanded/collapsed images.
+ */
+static void initializeImageData() {
+ 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)});
+
+ CollapsedImageData = 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});
+ CollapsedImageData.transparentPixel = 15; // use white for transparency
+ ExpandedImageData = 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});
+ ExpandedImageData.transparentPixel = 15; // use white for transparency
+}
+/**
+ * Set event listeners for the receiver.
+ */
+void installListeners() {
+ Listener listener = getListener();
+
+ super.installListeners();
+ addListener(SWT.Paint, listener);
+ addListener(SWT.MouseDown, listener);
+ addListener(SWT.MouseDoubleClick, listener);
+}
+/**
+ * Answer whether the receiver is currently expanding a sub tree
+ * with 'item' in it.
+ * Used for performance optimizations.
+ */
+boolean isExpandingItem(SelectableItem item) {
+ TreeItem parentItem;
+
+ if (expandingItem == null || item == null || (item instanceof TreeItem) == false) {
+ return false;
+ }
+ parentItem = ((TreeItem) item).getParentItem();
+ return (parentItem == expandingItem || isExpandingItem(parentItem));
+}
+/**
+ * Answer whether the children of 'collapsingItem' contain
+ * at least one selected item.
+ */
+boolean isSelectedItemCollapsing(TreeItem collapsingItem) {
+ Enumeration selection = getSelectionVector().elements();
+ TreeItem item;
+ int selectedItemIndex;
+ int collapsingItemIndex = collapsingItem.getVisibleIndex();
+ int lastCollapsedItemIndex = collapsingItemIndex + collapsingItem.getVisibleItemCount();
+
+ if (collapsingItemIndex == -1) { // is the collapsing item in a collapsed subtree?
+ return false; // then neither it nor its children are selected
+ }
+ while (selection.hasMoreElements() == true) {
+ item = (TreeItem) selection.nextElement();
+ selectedItemIndex = item.getVisibleIndex();
+ if ((selectedItemIndex > collapsingItemIndex) &&
+ (selectedItemIndex <= lastCollapsedItemIndex)) {
+ return true;
+ }
+ }
+ return false;
+}
+/**
+ * Test whether the mouse click specified by 'event' was a
+ * valid selection or expand/collapse click.
+ * @return
+ * One of ActionExpandCollapse, ActionSelect, ActionNone, ActionCheck
+ * specifying the action to be taken on the click.
+ */
+int itemAction(TreeItem item, int x, int y) {
+ int action = ActionNone;
+ int itemHeight = getItemHeight();
+ int offsetX;
+ int offsetY;
+ Point offsetPoint;
+
+ if (item != null) {
+ offsetX = x - item.getPaintStartX();
+ offsetY = y - itemHeight * (y / itemHeight);
+ offsetPoint = new Point(offsetX, offsetY);
+ if ((item.isLeaf() == false) &&
+ (getHierarchyIndicatorRect().contains(offsetPoint) == true)) {
+ action |= ActionExpandCollapse;
+ }
+ else
+ if (item.isSelectionHit(offsetPoint) == true) {
+ action |= ActionSelect;
+ }
+ else
+ if (item.isCheckHit(new Point(x, y)) == true) {
+ action |= ActionCheck;
+ }
+ }
+ return action;
+}
+/**
+ * The table item 'changedItem' has changed. Redraw the whole
+ * item in that column. Include the text in the redraw because
+ * an image set to null requires a redraw of the whole item anyway.
+ */
+void itemChanged(SelectableItem changedItem, int repaintStartX, int repaintWidth) {
+ int oldItemHeight = getItemHeight();
+ Point oldImageExtent = getImageExtent();
+
+ if (isExpandingItem(changedItem) == false) {
+ super.itemChanged(changedItem, repaintStartX, repaintWidth);
+ }
+ else {
+ calculateItemHeight(changedItem);
+ }
+ if ((oldItemHeight != getItemHeight()) || // only reset items if the item height or
+ (oldImageExtent != getImageExtent())) { // image size has changed. The latter will only change once,
+ // from null to a value-so it's safe to test using !=
+ getRoot().reset(); // reset cached data of all items in the receiver
+ resetHierarchyIndicatorRect();
+ redraw(); // redraw all items if the image extent has changed. Fixes 1FRIHPZ
+ }
+ else {
+ ((AbstractTreeItem) changedItem).reset(); // reset the item that has changed when the tree item
+ // height has not changed (otherwise the item caches old data)
+ // Fixes 1FF6B42
+ }
+ if (repaintWidth != 0) {
+ calculateWidestShowingItem();
+ claimRightFreeSpace(); // otherwise scroll bar may be reset, but not horizontal offset
+ // Fixes 1G4SBJ3
+ }
+}
+/**
+ * A key was pressed.
+ * Call the appropriate key handler method.
+ * @param event - the key event
+ */
+void keyDown(Event event) {
+ super.keyDown(event);
+ switch (event.character) {
+ case '+':
+ doPlus();
+ break;
+ case '-':
+ doMinus();
+ break;
+ case '*':
+ doAsterix();
+ break;
+ }
+}
+
+/**
+ * A mouse double clicked occurred over the receiver.
+ * Expand/collapse the clicked item. Do nothing if no item was clicked.
+ */
+void mouseDoubleClick(Event event) {
+ int hitItemIndex = event.y / getItemHeight();
+ TreeItem hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
+ Event newEvent;
+
+ if (hitItem == null || itemAction(hitItem, event.x, event.y) != ActionSelect) {
+ return;
+ }
+ if (isListening(SWT.DefaultSelection) == true) {
+ newEvent = new Event();
+ newEvent.item = hitItem;
+ notifyListeners(SWT.DefaultSelection, newEvent);
+ }
+ else
+ if (hitItem.isLeaf() == false) { // item with children was hit. Default behavior is expand/collapse item
+ if (hitItem.getExpanded() == true) {
+ collapse(hitItem, true);
+ }
+ else {
+ expand(hitItem, true);
+ }
+ }
+}
+/**
+ * The mouse pointer was pressed down on the receiver.
+ * Handle the event according to the position of the mouse click.
+ */
+void mouseDown(Event event) {
+ int hitItemIndex;
+ TreeItem hitItem;
+ SelectableItem selectionItem = getLastSelection();
+ int itemAction;
+
+ hitItemIndex = event.y / getItemHeight();
+ hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
+ if (hitItem == null) {
+ return;
+ }
+ if (!isFocusControl()) forceFocus();
+ switch (itemAction = itemAction(hitItem, event.x, event.y)) {
+ case ActionExpandCollapse:
+ if (event.button != 1) return;
+ if (hitItem.getExpanded() == true) {
+ collapse(hitItem, true);
+ }
+ else {
+ expand(hitItem, true);
+ }
+ break;
+ case ActionSelect:
+ doMouseSelect(hitItem, hitItemIndex + getTopIndex(), event.stateMask, event.button);
+ break;
+ case ActionCheck:
+ if (event.button != 1) return;
+ doCheckItem(hitItem);
+ break;
+ }
+ if (itemAction != ActionSelect && selectionItem == null) {
+ selectionItem = getRoot().getVisibleItem(getTopIndex()); // select the top item if no item was selected before
+ selectNotify(selectionItem);
+ }
+}
+/**
+ * A paint event has occurred. Display the invalidated items.
+ * @param event - expose event specifying the invalidated area.
+ */
+void paint(Event event) {
+ int visibleRange[] = getIndexRange(event.getBounds());
+
+ paintItems(event.gc, visibleRange[0], visibleRange[1] + 1); // + 1 to paint the vertical line
+ // connection the last item we really
+ // want to paint with the item after that.
+}
+/**
+ * Paint tree items on 'gc' starting at index 'topPaintIndex' and
+ * stopping at 'bottomPaintIndex'.
+ * @param gc - GC to draw tree items on.
+ * @param topPaintIndex - index of the first item to draw
+ * @param bottomPaintIndex - index of the last item to draw
+ */
+void paintItems(GC gc, int topPaintIndex, int bottomPaintIndex) {
+ TreeItem visibleItem;
+ int itemHeight = getItemHeight();
+
+ for (int i = topPaintIndex; i <= bottomPaintIndex; i++) {
+ visibleItem = getRoot().getVisibleItem(i + getTopIndex());
+ if (visibleItem != null) {
+ visibleItem.paint(gc, i * itemHeight);
+ }
+ }
+}
+/**
+ * 'item' has been added to or removed from the receiver.
+ * Repaint part of the tree to update the vertical hierarchy
+ * connectors and hierarchy image.
+ * @param modifiedItem - the added/removed item
+ * @param modifiedIndex - index of the added/removed item
+ */
+void redrawAfterModify(SelectableItem modifiedItem, int modifiedIndex) {
+ int redrawStartY;
+ int redrawStopY;
+ int itemChildIndex = ((TreeItem) modifiedItem).getIndex();
+ int topIndex = getTopIndex();
+ int itemHeight = getItemHeight();
+ int redrawItemIndex;
+ int itemCount;
+ AbstractTreeItem parentItem = ((TreeItem) modifiedItem).getParentItem();
+ AbstractTreeItem redrawItem = null;
+
+ if (redrawParentItem(modifiedItem) == false) {
+ return;
+ }
+ if (parentItem == null) { // a root item is added/removed
+ parentItem = getRoot();
+ }
+ itemCount = parentItem.getItemCount();
+ // redraw hierarchy decorations of preceeding item if the last item at a tree
+ // level was added/removed
+ // otherwise, if the first item was removed, redraw the parent to update hierarchy icon
+ if (itemChildIndex > 0) { // more than one item left at this tree level
+ // added/removed last item at this tree level? have to test >=.
+ // when removing last item, item index is outside itemCount
+ if (itemChildIndex >= itemCount - 1) {
+ redrawItem = (AbstractTreeItem) parentItem.getChildren().elementAt(itemChildIndex - 1);
+ }
+ }
+ else
+ if (getVisibleItemCount() > 0 && itemCount < 2) { // last item at this level removed/first item added?
+ redrawItem = parentItem; // redraw parent item to update hierarchy icon
+ }
+ if (redrawItem != null) {
+ redrawItemIndex = redrawItem.getVisibleIndex();
+ if (modifiedIndex == -1) {
+ modifiedIndex = redrawItemIndex + 1;
+ }
+ redrawStartY = (redrawItemIndex - topIndex) * itemHeight;
+ redrawStopY = (modifiedIndex - topIndex) * itemHeight;
+ redraw(
+ 0,
+ redrawStartY,
+ redrawItem.getCheckboxXPosition(), // only redraw up to and including hierarchy icon to avoid flashing
+ redrawStopY - redrawStartY, false);
+ }
+ if (modifiedIndex == 0) { // added/removed first item ?
+ redraw(0, 0, getClientArea().width, getItemHeight() * 2, false);// redraw new first two items to
+ // fix vertical hierarchy line
+ }
+}
+
+/**
+ * Determine if part of the tree hierarchy needs to be redrawn.
+ * The hierarchy icon of the parent item of 'item' needs to be redrawn if
+ * 'item' is added as the first child or removed as the last child.
+ * Hierarchy lines need to be redrawn if 'item' is the last in a series of
+ * children.
+ * @param item - tree item that is added or removed.
+ * @return true=tree hierarchy needs to be redrawn. false=no redraw necessary
+ */
+boolean redrawParentItem(SelectableItem item) {
+ TreeItem parentItem = ((TreeItem) item).getParentItem();
+ TreeItem parentItem2;
+ boolean redraw = false;
+
+ // determine if only the hierarchy icon needs to be redrawn
+ if (parentItem != null) {
+ parentItem2 = parentItem.getParentItem();
+ if ((parentItem2 == null || parentItem2.getExpanded() == true) && parentItem.getChildren().size() < 2) {
+ redraw = true;
+ }
+ }
+ // redraw is only neccessary when the receiver is not currently
+ // expanding 'item' or a parent item or if the parent item is expanded
+ // or if the hierarchy icon of the parent item needs to be redrawn
+ if (isExpandingItem(item) == false && parentItem == null || parentItem.getExpanded() == true || redraw == true) {
+ redraw = true;
+ }
+ else {
+ redraw = false;
+ }
+ return redraw;
+}
+
+/**
+ * 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();
+ setRedraw(false);
+ getRoot().dispose();
+ resetRoot();
+ reset();
+ calculateWidestShowingItem();
+ calculateVerticalScrollbar();
+ setRedraw(true);
+}
+/**
+ * Remove 'item' from the receiver.
+ * @param item - tree item that should be removed from the
+ * receiver-must be a root item.
+ */
+void removeItem(TreeItem item) {
+ getRoot().removeItem(item);
+}
+/**
+ * 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);
+}
+/**
+ * 'item' has been removed from the receiver.
+ * Recalculate the content width.
+ */
+void removedItem(SelectableItem item) {
+ if (isExpandingItem(item) == false) {
+ super.removedItem(item);
+ }
+ calculateWidestShowingItem();
+ claimRightFreeSpace();
+}
+/**
+ * Notification that 'item' is about to be removed from the tree.
+ * Update the item selection if neccessary.
+ * @param item - item that is about to be removed from the tree.
+ */
+void removingItem(SelectableItem item) {
+ Vector selection = getSelectionVector();
+ TreeItem parentItem = ((TreeItem) item).getParentItem();
+ TreeItem newSelectionItem = null;
+ boolean isLastSelected = (selection.size() == 1) && (selection.elementAt(0) == item);
+ int itemIndex = getVisibleIndex(item);
+
+ if (isLastSelected == true) {
+ // try selecting the following item
+ newSelectionItem = (TreeItem) getVisibleItem(itemIndex + 1);
+ if (newSelectionItem == null || newSelectionItem.getParentItem() != parentItem) {
+ // select parent item if there is no item following the removed
+ // one on the same tree level
+ newSelectionItem = parentItem;
+ }
+ if (newSelectionItem != null) {
+ selectNotify(newSelectionItem, true);
+ }
+ }
+ super.removingItem(item);
+ if (isExpandingItem(item) == false) {
+ // redraw plus/minus image, hierarchy lines,
+ // redrawing here assumes that no update happens between now and
+ // after the item has actually been removed. Otherwise this call
+ // would need to be in removedItem and we would need to store the
+ // "itemIndex" here to redraw correctly.
+ redrawAfterModify(item, itemIndex);
+ }
+}
+/**
+ * Reset the rectangle enclosing the hierarchy indicator to null.
+ * Forces a recalculation next time getHierarchyIndicatorRect is called.
+ */
+void resetHierarchyIndicatorRect() {
+ hierarchyIndicatorRect = null;
+}
+/**
+ * Reset state that is dependent on or calculated from the items
+ * of the receiver.
+ */
+void resetItemData() {
+ setContentWidth(0);
+ resetHierarchyIndicatorRect();
+ super.resetItemData();
+}
+/**
+ * Reset the object holding the root items of the receiver.
+ */
+void resetRoot() {
+ root = new TreeRoots(this);
+}
+/**
+ * The receiver has been resized. Recalculate the content width.
+ */
+void resize(Event event) {
+ int oldItemCount = getVerticalBar().getPageIncrement();
+
+ super.resize(event);
+ if (getItemCountWhole() > oldItemCount) { // window resized higher?
+ calculateWidestShowingItem(); // recalculate widest item since a longer item may be visible now
+ }
+}
+/**
+ * Display as many expanded tree items as possible.
+ * Scroll the last expanded child to the bottom if all expanded
+ * children can be displayed.
+ * Otherwise scroll the expanded item to the top.
+ * @param item - the tree item that was expanded
+ */
+void scrollExpandedItemsIntoView(TreeItem item) {
+ int itemCountOffScreen = getOffScreenItemCount(item);
+ int newTopIndex = getTopIndex() + itemCountOffScreen;
+
+ if (itemCountOffScreen > 0) {
+ newTopIndex = Math.min(item.getVisibleIndex(), newTopIndex); // make sure the expanded item is never scrolled out of view
+ setTopIndex(newTopIndex, true);
+ }
+}
+/**
+ * Scroll the items following the children of 'collapsedItem'
+ * below 'collapsedItem' to cover the collapsed children.
+ * @param collapsedItem - item that has been collapsed
+ */
+void scrollForCollapse(TreeItem collapsedItem) {
+ Rectangle clientArea = getClientArea();
+ int topIndex = getTopIndex();
+ int itemCount = collapsedItem.getVisibleItemCount();
+ int scrollYPositions[] = calculateChildrenYPos(collapsedItem);
+
+ if (scrollYPositions[0] == -1 && scrollYPositions[1] == -1) {
+ return;
+ }
+ if (topIndex + getItemCountWhole() == getVisibleItemCount() && itemCount < topIndex) {
+ // scroll from top if last item is at bottom and will stay at
+ // bottom after collapse. Avoids flash caused by too much bit
+ // blitting (which force update and thus premature redraw)
+ int height = scrollYPositions[1] - scrollYPositions[0];
+ scroll(
+ 0, 0, // destination x, y
+ 0, -height, // source x, y
+ clientArea.width, scrollYPositions[0]+height, true);
+ setTopIndexNoScroll(topIndex - itemCount, true);
+ }
+ else {
+ scroll(
+ 0, scrollYPositions[0], // destination x, y
+ 0, scrollYPositions[1], // source x, y
+ clientArea.width, clientArea.height - scrollYPositions[0], true);
+ }
+}
+/**
+ * Scroll the items following 'expandedItem' down to make
+ * space for the children of 'expandedItem'.
+ * @param expandedItem - item that has been expanded.
+ */
+void scrollForExpand(TreeItem expandedItem) {
+ int scrollYPositions[];
+ Rectangle clientArea = getClientArea();
+
+ expandedItem.internalSetExpanded(true);
+ scrollYPositions = calculateChildrenYPos(expandedItem);
+ expandedItem.internalSetExpanded(false);
+ if (scrollYPositions[0] == -1 && scrollYPositions[1] == -1) {
+ return;
+ }
+ scroll(
+ 0, scrollYPositions[1], // destination x, y
+ 0, scrollYPositions[0], // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Scroll horizontally by 'numPixel' pixel.
+ * @param numPixel - the number of pixel to scroll
+ * < 0 = columns are going to be moved left.
+ * > 0 = columns are going to be moved right.
+ */
+void scrollHorizontal(int numPixel) {
+ Rectangle clientArea = getClientArea();
+
+ scroll(
+ numPixel, 0, // destination x, y
+ 0, 0, // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Scroll vertically by 'scrollIndexCount' items.
+ * @param scrollIndexCount - the number of items to scroll.
+ * scrollIndexCount > 0 = scroll up. scrollIndexCount < 0 = scroll down
+ */
+void scrollVertical(int scrollIndexCount) {
+ Rectangle clientArea = getClientArea();
+
+ scroll(
+ 0, 0, // destination x, y
+ 0, scrollIndexCount * getItemHeight(), // source x, y
+ clientArea.width, clientArea.height, true);
+}
+/**
+ * Selects all 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 void selectAll() {
+ checkWidget();
+ Vector selection = getSelectionVector();
+
+ if (isMultiSelect() == true) {
+ selection = getRoot().selectAll(selection);
+ setSelectionVector(selection);
+ }
+}
+/**
+ * Set the item that is currently being expanded to 'item'.
+ * Used for performance optimizations.
+ */
+void setExpandingItem(TreeItem item) {
+ expandingItem = item;
+}
+public void setFont(Font font) {
+ checkWidget();
+ Stack children = new Stack(); // traverse the tree depth first
+ Enumeration elements;
+ AbstractTreeItem item;
+
+ if (font != null && font.equals(getFont()) == true) {
+ return;
+ }
+ setRedraw(false); // disable redraw because itemChanged() triggers undesired redraw
+ resetItemData();
+ super.setFont(font);
+
+ // Call itemChanged for all tree items
+ elements = getRoot().getChildren().elements();
+ while (elements.hasMoreElements() == true) {
+ children.push(elements.nextElement());
+ }
+ while (children.empty() == false) {
+ item = (AbstractTreeItem) children.pop();
+ itemChanged(item, 0, getClientArea().width);
+ elements = item.getChildren().elements();
+ while (elements.hasMoreElements() == true) {
+ children.push(elements.nextElement());
+ }
+ }
+ setRedraw(true); // re-enable redraw
+}
+/**
+ * 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 after 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);
+ motif_setInsertMark(item, !before);
+}
+/**
+ * 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 array of items is null</li>
+ * <li>ERROR_INVALID_ARGUMENT - if one of 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#deselectAll()
+ */
+public void setSelection(TreeItem selectionItems[]) {
+ checkWidget();
+ if (selectionItems == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ setSelectableSelection(selectionItems);
+}
+/**
+ * Set the index of the first visible item in the tree client area
+ * to 'index'.
+ * Scroll the new top item to the top of the tree.
+ * @param index - 0-based index of the first visible item in the
+ * tree's client area.
+ * @param adjustScrollbar -
+ * true = the vertical scroll bar is set to reflect the new top index.
+ * false = the vertical scroll bar position is not modified.
+ */
+void setTopIndex(int index, boolean adjustScrollbar) {
+ int indexDiff = index-getTopIndex();
+
+ super.setTopIndex(index, adjustScrollbar);
+ calculateWidestScrolledItem(indexDiff);
+}
+public void setTopItem(TreeItem item) {
+ checkWidget();
+ if (item == null) error(SWT.ERROR_NULL_ARGUMENT);
+ if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ if (item.isVisible() == false) {
+ item.makeVisible();
+ }
+ scrollExpandedItemsIntoView(item);
+}
+/**
+ * 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);
+ showSelectableItem(item);
+}
+/**
+ * Make 'item' visible by expanding its parent items and scrolling
+ * it into the receiver's client area if necessary.
+ * An SWT.Expand event is going to be sent for every parent item
+ * that is expanded to make 'item' visible.
+ * @param item - the item that should be made visible to the
+ * user.
+ */
+void showSelectableItem(SelectableItem item) {
+ if (item.getSelectableParent() != this) {
+ return;
+ }
+ if (((TreeItem) item).isVisible() == false) {
+ ((TreeItem) item).makeVisible();
+ }
+ super.showSelectableItem(item);
+}
+/**
+ * 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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 itemHeight;
+ int hitItemIndex;
+ TreeItem hitItem;
+
+ if (getClientArea().contains(point) == false) {
+ return null;
+ }
+ itemHeight = getItemHeight();
+ hitItemIndex = point.y / itemHeight;
+ hitItem = getRoot().getVisibleItem(hitItemIndex + getTopIndex());
+ if (hitItem != null) {
+ Point pt = new Point(point.x, point.y);
+ pt.x -= hitItem.getPaintStartX();
+ pt.y -= itemHeight * hitItemIndex;
+ if (hitItem.isSelectionHit(pt) == false) {
+ hitItem = null;
+ }
+ }
+ return hitItem;
+}
+/**
+ * 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 super.getSelectionCount();
+}
+public TreeItem getTopItem() {
+ checkWidget();
+ return (TreeItem)getVisibleItem(getTopIndex());
+}
+/**
+ * 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 IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
+ super.showSelection();
+}
+
+}
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
index 2894f062b8..e12d74dc14 100644
--- 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
@@ -1,1358 +1,1358 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * 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 AbstractTreeItem {
-/*
- * This class caches geometric data for drawing.
- * A description of the cached data follows:
- *
- * | 1 || 5 |
- * | 2 | | 6 |
- * |3 7|
- * _____ | 4 |f| |8
- * | | ____
- * | - | ===== {image} root 9
- * |_____| |
- * |b|c| |d|
- * | e |
- *
- * Widths are measured between vertical lines.
- *
- * Cached item rendering data:
- * 1 = getDecorationsWidth
- * 2 = getHierarchyIndicatorRect
- * 3 = getPaintStartX
- * 4 = getItemConnectorWidth
- * 5 = getItemWidth
- * 6 = getSelectionWidth
- * 7 = getPaintStopX
- * 8 - getTextXPos
- * 9 = getTextYPosition
- *
- * Rendering constants:
- * 4 = DEFAULT_ITEM_CONNECTOR_WIDTH, used when no image is set in the tree.
- * Otherwise it is the image width.
- * b = IMAGE_PADDING
- * c = TEXT_INDENT
- * d = SELECTION_PADDING
- * e = ITEM_NOIMAGE_OFFSET
- * f = ITEM_CONNECTOR_PADDING;
- */
- private static final int DEFAULT_ITEM_CONNECTOR_WIDTH = 8; // Default width of the horizontal line connecting
- // items with the vertical lines. Only used when
- // no image is set in the tree. Normally connector
- // line width is half the image width.
- private static final int ITEM_CONNECTOR_PADDING = 2; // Added to the calculated item connector width
- private static final int IMAGE_PADDING = 3; // Space behind bitmap
- private static final int ITEM_NOIMAGE_OFFSET = 8; // Offset added to the calculated paint position where
- // an item starts drawing. To be used when no item
- // image has been set. Otherwise children would start
- // drawing at the end of the horizontal item connector
- // of their parent.
- private static final int ROOT_INDENT = 5; // Indent of root items
- private static final int SELECTION_PADDING = 2; // Space behind text
- private static final int TEXT_INDENT = 2; // Identation of the item label
-
- // basic item info
- private TreeItem parentItem;
- private int index; // index in the parent item
-
- // geometrical item info
- private int paintStartX = -1; // X coordinate of the upper-left corner of the
- // receivers bounding rectangle
- private Point itemExtent; // Size of the item (image + label)
- private Point imageExtent; // original size of the item image
- private int textYPosition = -1; // Centered y position of the item text
-
-
- //Determine whether the item is being expanded
- private boolean isExpanding = false;
- Color background = null;
- Color foreground = null;
-
-/**
- * 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 composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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).getItemCount());
-}
-
-/**
- * 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 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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
- super(parent, style);
- parent.addItem(this, index);
-}
-
-/**
- * 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 composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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).getItemCount());
-}
-
-/**
- * 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 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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
- super(checkNull(parentItem).getParent(), style);
- setParentItem(parentItem);
- parentItem.add(this, index);
-}
-
-/**
- * Calculate the number of expanded children.
- * Recurse up in the tree to the root item.
- */
-void calculateVisibleItemCount() {
- Vector children;
- TreeItem child;
- int visibleItemCount = 0;
-
- // check isExpanded field directly for performance
- if (internalGetExpanded() == true) {
- children = getChildren();
- visibleItemCount = children.size();
- for (int i = 0; i < children.size(); i++) {
- child = (TreeItem) children.elementAt(i);
- visibleItemCount += child.getVisibleItemCount();
- }
- }
- setVisibleItemCount(visibleItemCount);
- calculateVisibleItemCountParent();
-}
-/**
- * Calculate the number of expanded children for the parent item
- * of this item.
- */
-void calculateVisibleItemCountParent() {
- TreeItem parentItem = getParentItem();
-
- if (parentItem != null) {
- parentItem.calculateVisibleItemCount();
- }
- else {
- getParent().getRoot().calculateVisibleItemCount();
- }
-}
-/**
- * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'tree' is null.
- * Otherwise return 'tree'
- */
-static Tree checkNull(Tree tree) {
- if (tree == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return tree;
-}
-/**
- * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'item' is null.
- * Otherwise return 'item'
- */
-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);
-}
-
-/**
- * Draw the hierarchy indicator at 'position'.
- *
- * Note:
- * Assumes that the hierarchy indicators for the expanded and
- * collapsed state are the same size.
- * @param gc - GC to draw on.
- * @param position - position on the GC to draw at.
- * @return position to continue drawing
- */
-Point drawHierarchyIndicator(GC gc, Point position) {
- Tree parent = getParent();
- Image hierarchyImage;
- Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
- int x = position.x;
- int y = position.y;
- int yCenter = y + parent.getItemHeight() / 2;
- Point connectorLinePosition;
-
- if (isLeaf() == false) {
- if (getExpanded() == true) {
- hierarchyImage = parent.getExpandedImage();
- }
- else {
- hierarchyImage = parent.getCollapsedImage();
- }
- if (hierarchyImage != null) {
- gc.drawImage(hierarchyImage, x + indicatorRectangle.x, y + indicatorRectangle.y);
- }
- connectorLinePosition = new Point(x + indicatorRectangle.width, yCenter);
- }
- else {
- connectorLinePosition = new Point(
- x + indicatorRectangle.width / 2
- + indicatorRectangle.width % 2, yCenter); // % 2 in order to not start the next hierarchy
- // component at the middle of the icon but after.
- }
- return connectorLinePosition;
-}
-/**
- * Draw a horizontal line connecting the item image (or label
- * if there is no image) to the vertical line connecting to
- * the parent.
- * @param gc - GC to draw on.
- * @param position - position on the GC to draw at.
- * @return position to continue drawing
- */
-Point drawHorizontalItemConnector(GC gc, Point position) {
- int itemConnectorEndPos = position.x + getItemConnectorWidth() - 1; // -1 because the position of the last pixel needs to be calculated
-
- gc.drawLine(position.x, position.y, itemConnectorEndPos, position.y);
- return new Point(itemConnectorEndPos + 1, position.y); // + 1 in order to resume drawing after line not on end of line
-}
-/**
- * Display the item image at 'position' using 'gc'.
- * @param gc - GC to draw on
- * @param position - position on the GC to draw at
- * @return position to continue drawing
- */
-Point drawImage(GC gc, Point destinationPosition) {
- Tree parent = getParent();
- Image image = getImage();
- Point sourceImageExtent;
- Point destinationImageExtent = parent.getImageExtent();
- int yCenter;
-
- if (image != null) {
- sourceImageExtent = getImageExtent();
- yCenter = (parent.getItemHeight() - destinationImageExtent.y) / 2;
- gc.drawImage(
- image,
- 0, 0, // source x, y
- sourceImageExtent.x, sourceImageExtent.y, // source width, height
- destinationPosition.x, destinationPosition.y + yCenter, // destination x, y
- destinationImageExtent.x, destinationImageExtent.y); // destination width, height
- }
- if (destinationImageExtent != null) {
- destinationPosition.x += destinationImageExtent.x + IMAGE_PADDING;
- }
- return destinationPosition;
-}
-/**
- * Draw a rectangle enclosing the item label. The rectangle
- * indicates that the receiver was selected last and that it has
- * the input focus.
- * The rectangle will only be drawn if the receiver is selected.
- * @param gc - GC to draw on.
- * @param position - position on the GC to draw at.
- */
-void drawSelectionFocus(GC gc, Point position) {
- Point selectionExtent = getSelectionExtent();
-
- if (selectionExtent == null) {
- return;
- }
- if (getParent().hasFocus(this) == true) {
- gc.drawFocus(
- position.x, position.y,
- selectionExtent.x, selectionExtent.y);
- }
-}
-/**
- * Draw a vertical line connecting the horizontal connector line
- * with that of the previous item.
- * Called recursively to draw the lines on all tree levels.
- * @param gc - GC to draw on.
- * @param yPosition - y position of the upper side of the
- * receiver's bounding box.
- * @param isFirstChild - method is called to draw a vertical
- * line for the first child. Leave room for the hierarchy icon.
- */
-void drawVerticalItemConnector(GC gc, int yPosition, boolean isFirstChild) {
- Tree parent = getParent();
- TreeItem nextDrawItem = getParentItem();
- AbstractTreeItem parentItem = nextDrawItem;
- Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
- int itemHeight = parent.getItemHeight();
- int itemHeightDiv2 = itemHeight / 2 + itemHeight % 2;
- int indicatorHeightDiv2 = indicatorRectangle.height / 2 + indicatorRectangle.height % 2;
- int lineX = getPaintStartX() + indicatorRectangle.width / 2;
- int lineStartY = yPosition - itemHeightDiv2;
- int lineEndY = yPosition + itemHeightDiv2;
-
- if (parentItem == null) {
- parentItem = parent.getRoot();
- }
- if (getIndex() != parentItem.getItemCount()-1) { // if item is not the last child
- if (isFirstChild == true) {
- lineStartY += indicatorHeightDiv2; // leave space for the hierarchy image
- }
- gc.drawLine(lineX, lineStartY, lineX, lineEndY);
- }
-
- if (nextDrawItem != null) {
- nextDrawItem.drawVerticalItemConnector(gc, yPosition, false);
- }
-}
-/**
- * Draw a vertical line connecting the horizontal connector line
- * with that of the previous item.
- * Do this on all tree levels up to the root level.
- * @param gc - GC to draw on.
- * @param position - position on the GC to draw at.
- * @return position to continue drawing
- */
-Point drawVerticalItemConnector(GC gc, Point position) {
- Tree parent = getParent();
- TreeItem parentItem = getParentItem();
- Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
- int itemHeight = parent.getItemHeight();
- int itemHeightDiv2 = itemHeight / 2 + itemHeight % 2;
- int indicatorHeightDiv2 = indicatorRectangle.height / 2 + indicatorRectangle.height % 2;
- int lineX = position.x + indicatorRectangle.width / 2;
- int lineStartY = position.y - itemHeightDiv2;
- int lineEndY = position.y + itemHeightDiv2 - itemHeight % 2;
- TreeItem predecessor;
- boolean isFirstChild = false;
-
- if (isRoot() == true) {
- if (getIndex() == 0) {
- return position; // first root, don't draw vertical line
- }
- }
- else
- if (getIndex() == 0) { // if item is first child
- lineStartY += itemHeightDiv2;
- isFirstChild = true;
- }
- predecessor = getPredecessor();
- if (predecessor != null && predecessor.isLeaf() == false) {
- lineStartY += indicatorHeightDiv2; // leave space for the hierarchy image
- }
- if (isLeaf() == false) {
- lineEndY -= indicatorHeightDiv2;
- }
- gc.drawLine(lineX, lineStartY, lineX, lineEndY);
- if (parentItem != null) {
- parentItem.drawVerticalItemConnector(gc, position.y, isFirstChild);
- }
- return position;
-}
-/**
- * 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 (background != null) return background;
- Tree parent = getParent();
- return parent.getBackground();
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds() {
- checkWidget();
- Tree parent = getParent();
- Point extent = getItemExtent();
- int x = getTextXPos() - TEXT_INDENT;
-
- return new Rectangle(x, parent.getRedrawY(this), extent.x - (x - getItemStartX()), extent.y);
-}
-
-/**
- * Answer the x position of the item check box
- */
-int getCheckboxXPosition() {
- return getPaintStartX() + getDecorationsWidth();
-}
-/**
- * Answer the combined width of the hierarchy indicator and
- * the horizontal item connector line.
- */
-int getDecorationsWidth() {
- int indicatorWidth = getParent().getHierarchyIndicatorRect().width;
- int width = indicatorWidth + getItemConnectorWidth();
-
- if (isLeaf() == true) {
- width -= indicatorWidth / 2;
- }
- return width;
-}
-/**
- * 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 (foreground != null) return foreground;
- Tree parent = getParent();
- return parent.getForeground();
-}
-/**
- * Answer the index of the receiver relative to the first root
- * item.
- * @return
- * The index of the receiver relative to the first root item.
- */
-int getGlobalIndex() {
- int globalItemIndex = getIndex();
- AbstractTreeItem item = null;
-
- if (isRoot() == false) {
- item = getParentItem();
- globalItemIndex++; // adjust for 0-based non-root items
- }
- else {
- item = getParent().getRoot();
- }
-
- globalItemIndex += item.getVisibleIndex(getIndex());
- return globalItemIndex;
-}
-/**
- * Answer the original size of the image of the receiver.
- */
-Point getImageExtent() {
- Image image = getImage();
- Rectangle imageBounds;
-
- if (imageExtent == null && image != null) {
- imageBounds = image.getBounds();
- imageExtent = new Point(imageBounds.width, imageBounds.height);
- }
- return imageExtent;
-}
-/**
- * Answer the receiver's index into its parent's list of children
- */
-int getIndex() {
- return index;
-}
-/**
- * Answer the width of the horizontal item connector line.
- */
-int getItemConnectorWidth() {
- Tree parent = getParent();
- Point imageExtent = parent.getImageExtent();
- int itemConnectorWidth;
- int indicatorWidth = parent.getHierarchyIndicatorRect().width;
-
- if (imageExtent != null) {
- itemConnectorWidth = imageExtent.x / 2 + ITEM_CONNECTOR_PADDING;
- }
- else {
- itemConnectorWidth = DEFAULT_ITEM_CONNECTOR_WIDTH;
- }
- if (isLeaf() == false) { // has children = has hierarchy indicator = shorter connector
- itemConnectorWidth -= indicatorWidth / 2;
- }
- return itemConnectorWidth;
-}
-/**
- * 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();
- return super.getItemCount();
-}
-/**
- * Answer the size of the receiver as displayed on the screen.
- */
-Point getItemExtent() {
- Tree parent;
- Point imageExtent;
- String text;
- int itemWidth;
-
- if (itemExtent == null) {
- parent = getParent();
- imageExtent = parent.getImageExtent();
- text = getText();
- itemWidth = SELECTION_PADDING;
- if (text != null) {
- itemWidth += parent.getTextWidth(text) + TEXT_INDENT;
- }
- if (imageExtent != null) {
- itemWidth += imageExtent.x + IMAGE_PADDING;
- }
- itemExtent = new Point(itemWidth, parent.getItemHeight());
- }
- return itemExtent;
-}
-/**
- * Answer the x position at which painting of the receiver's
- * contents (ie. image, text) can begin.
- */
-int getItemStartX() {
- int itemStartX = getPaintStartX() + getDecorationsWidth();
-
- if (isCheckable() == true) {
- itemStartX += getCheckboxBounds().width + CHECKBOX_PADDING;
- }
- return itemStartX;
-}
-/**
- * Returns an 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();
- TreeItem childrenArray[] = new TreeItem[getItemCount()];
-
- getChildren().copyInto(childrenArray);
- return childrenArray;
-}
-/**
- * Answer the x position where the receiver is drawn.
- */
-int getPaintStartX() {
- Tree parent = getParent();
- Point imageExtent;
- TreeItem parentItem;
-
- if (paintStartX == -1) {
- if (isRoot() == true) {
- paintStartX = ROOT_INDENT;
- }
- else {
- parentItem = getParentItem();
- // subtract parent.getHorizontalOffset() to calculate the cached start
- // position independent of the horizontal scroll offset. Fixes 1G1L7EU.
- paintStartX = parentItem.getPaintStartX()
- - parent.getHorizontalOffset()
- + parentItem.getDecorationsWidth()
- - parent.getHierarchyIndicatorRect().width / 2;
- imageExtent = parent.getImageExtent();
- if (imageExtent != null) {
- paintStartX += imageExtent.x / 2;
- }
- else {
- paintStartX += ITEM_NOIMAGE_OFFSET;
- }
- }
- }
- return paintStartX + parent.getHorizontalOffset();
-}
-/**
- * Answer the pixel at which the receiver stops drawing.
- */
-int getPaintStopX() {
- return (getItemStartX() + getItemExtent().x - getParent().getHorizontalOffset());
-}
-/**
- * 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 (Tree) super.getSelectableParent();
-}
-/**
- * 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;
-}
-/**
- * Answer the item that directly precedes the receiver.
- * Answer null if this is the first item in a hierarchy level
- * or if there are expanded children in the previous item.
- */
-TreeItem getPredecessor() {
- AbstractTreeItem parentItem = getParentItem();
- Vector children;
- int previousIndex = getIndex() - 1;
- TreeItem previousItem = null;
-
- if (parentItem == null) {
- parentItem = getParent().getRoot();
- }
- if (previousIndex >= 0) {
- children = parentItem.getChildren();
- previousItem = (TreeItem) children.elementAt(previousIndex);
- if (previousItem.isLeaf() == false && previousItem.getExpanded() == true) {
- previousItem = null; // no immediate predecessor because there are expanded children
- }
- }
- return previousItem;
-}
-/**
- * Answer the size of the rectangle drawn to indicate the
- * selected state of the receiver.
- * This is also used to draw the selection focus rectangle.
- */
-Point getSelectionExtent() {
- Point selectionExtent = getItemExtent();
- Point imageExtent = getParent().getImageExtent();
- int x = selectionExtent.x;
-
- if (imageExtent != null) {
- x -= imageExtent.x + IMAGE_PADDING;
- }
- return new Point(x, selectionExtent.y);
-}
-/**
- * Return the x position of the selection rectangle
- */
-int getSelectionX() {
- return getTextXPos() - TEXT_INDENT;
-}
-/**
- * Answer the x position where the receiver draws the item text.
- * This position is relative to the item start position.
- */
-int getTextXPos() {
- Point imageExtent = getParent().getImageExtent();
- int textXPos = getItemStartX() + TEXT_INDENT;
-
- if (imageExtent != null) {
- textXPos += imageExtent.x + IMAGE_PADDING;
- }
- return textXPos;
-}
-/**
- * Answer the y position of the receiver's text.
- * @param
- * gc - GC to use for calculating the text y position
- */
-int getTextYPosition(GC gc) {
- String text;
-
- if (textYPosition == -1) {
- text = getText();
- if (text != null) {
- textYPosition = (getParent().getItemHeight() - gc.stringExtent(text).y) / 2;
- }
- else {
- textYPosition = 0;
- }
- }
- return textYPosition;
-}
-/**
- * Answer the index of the receiver relative to the first root
- * item.
- * If 'anIndex' is the index of the expanded item 'anItem'
- * then the following expressions are true:
- * 'anItem == theRoot.getVisibleItem(anIndex)' and
- * 'anIndex == anItem.getVisibleIndex()'
- * @return
- * The index of the receiver relative to the first root item.
- * Answer -1 if the receiver is not visible (because the parent
- * is collapsed).
- */
-int getVisibleIndex() {
- int visibleItemIndex = getIndex();
- AbstractTreeItem item = null;
-
- if (isRoot() == false) {
- if (isVisible() == false) {
- return -1;
- }
- item = getParentItem();
- visibleItemIndex++; // adjust for 0-based non-root items
- }
- else {
- item = getParent().getRoot();
- }
-
- visibleItemIndex += item.getVisibleIndex(getIndex());
- return visibleItemIndex;
-}
-/**
- * Answer the index of the child item identified by 'childIndex'
- * relative to the first root item.
- */
-int getVisibleIndex(int childIndex) {
- Enumeration children = getChildren().elements();
- TreeItem child;
- int visibleItemIndex = getIndex();
-
- if (isRoot() == false) {
- visibleItemIndex++; // adjust for 0-based non-root items
- }
-
- while (children.hasMoreElements() == true) {
- child = (TreeItem) children.nextElement();
- if (child.getIndex() == childIndex) {
- if (isRoot() == false) {
- visibleItemIndex += getParentItem().getVisibleIndex(getIndex());
- }
- else {
- visibleItemIndex += getParent().getRoot().getVisibleIndex(getIndex());
- }
- break;
- }
- visibleItemIndex += child.getVisibleItemCount();
- }
- return visibleItemIndex;
-}
-/**
- * Answer the item at 'searchIndex' relativ to the receiver.
- * When this method is called for the root item, 'searchIndex'
- * represents the global index into all items of the tree.
- * searchIndex=0 returns the receiver.
- * searchIndex=1 returns the first visible child.
- * Note: searchIndex must be >= 0
- *
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. Visible here means that all
- * the parents of the item are expanded. An item is only
- * visible on screen if it is within the widget client area.
- */
-TreeItem getVisibleItem(int searchIndex) {
- TreeItem child;
- TreeItem foundItem = null;
- Enumeration children = getChildren().elements();
-
- if (searchIndex == 0) {
- return this;
- }
- else
- if (getExpanded() == false) { // trying to find a child when this item isn't expanded ?
- return null;
- }
-
- // Search for expanded items first. Count all subitems in the process.
- while (children.hasMoreElements() == true && foundItem == null) {
- child = (TreeItem) children.nextElement();
- searchIndex--;
- if (child.getExpanded() == true) {
- searchIndex -= child.getVisibleItemCount(); // count children of all expanded items
- }
- if (searchIndex <= 0) { // is searched item past child ?
- // add back children of current item (that's what we want to search)
- foundItem = child.getVisibleItem(searchIndex + child.getVisibleItemCount());
- }
- }
-
- return foundItem;
-}
-/**
- * Answer whether 'item' is a child, direct or indirect, of the receiver.
- * It is an indirect child if it is a child of one of the receiver's children.
- */
-boolean isChild(TreeItem item) {
- Vector children = getChildren();
- TreeItem child;
-
- if (children.contains(item) == true) {
- return true;
- }
- for (int i = 0; i < children.size(); i++) {
- child = (TreeItem) children.elementAt(i);
- if (child.isChild(item) == true) {
- return true;
- }
- }
- return false;
-}
-/**
- * Answer whether the receiver is a root item.
- * The receiver is a root item when it does not have a parent item.
- * @return
- * true - the receiver is a root item.
- * false - the receiver is not a root item.
- */
-boolean isRoot() {
- return (getParentItem() == null);
-}
-/**
- * Answer whether the click at 'position' on the receiver is a selection
- * click.
- * @param position - location of the mouse click relative to the
- * upper left corner of the receiver.
- * @return true - receiver was clicked.
- * false - receiver was not clicked.
- */
-boolean isSelectionHit(Point position) {
- Point itemExtent = getItemExtent();
-
- if (itemExtent == null) { // neither image nor text have been set
- return false;
- }
- return (new Rectangle(
- getItemStartX() - getPaintStartX(), 0,
- itemExtent.x, itemExtent.y)).contains(position);
-}
-/**
- * Answer whether the receiver is visible
- * An item is visible when its parent item is visible and
- * expanded. Root items are always visible.
- *
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. Visible here means that all
- * the parents of the item are expanded. An item is only
- * visible on screen if it is within the receiver's parent's
- * client area.
- * @return
- * true - the receiver is visible
- * false - the receiver is not visible
- */
-boolean isVisible() {
- boolean isVisible = true;
- TreeItem parentItem = getParentItem();
-
- if (isRoot() == false) {
- isVisible = parentItem.getExpanded();
- if (isVisible == true) {
- isVisible = parentItem.isVisible();
- }
- }
- return isVisible;
-}
-/**
- * Make this item visible by expanding its parent item.
- */
-void makeVisible() {
- TreeItem parentItem = getParentItem();
-
- if (isVisible() == false && parentItem != null) {
- getParent().expand(parentItem, true); // have to call Tree.expand directly in order to trigger Expand event
- parentItem.makeVisible();
- }
-}
-/**
- * Draw the receiver at 'yPosition' in the client area of the parent.
- * @param gc - GC to draw on.
- * @param yPosition - y coordinate where the receiver should draw at.
- */
-void paint(GC gc, int yPosition) {
- if (isVisible() == false) {
- return;
- }
-
- Tree parent = getParent();
- Point paintPosition = new Point(getPaintStartX(), yPosition);
- Point extent = getSelectionExtent();
- gc.setForeground(parent.CONNECTOR_LINE_COLOR);
- paintPosition = drawVerticalItemConnector(gc, paintPosition);
- paintPosition = drawHierarchyIndicator(gc, paintPosition);
- paintPosition = drawHorizontalItemConnector(gc, paintPosition);
- gc.setForeground(parent.getForeground());
- // paint the rest
- if (isCheckable() == true) {
- paintPosition = drawCheckbox(gc, new Point(paintPosition.x, yPosition));
- }
- paintPosition = drawImage(gc, new Point(paintPosition.x, yPosition));
- if (isSelected() == true) {
- gc.setBackground(getSelectionBackgroundColor());
- gc.setForeground(getSelectionForegroundColor());
- gc.fillRectangle(paintPosition.x, paintPosition.y, extent.x, extent.y);
- } else {
- gc.setBackground(getBackground());
- gc.setForeground(getForeground());
- if(getBackground() != parent.getBackground()){
- gc.fillRectangle(paintPosition.x, paintPosition.y, extent.x, extent.y);
- }
- }
- if (text != null) {
- gc.drawString(text, getTextXPos(), paintPosition.y + getTextYPosition(gc), true);
- }
- if (this == parent.getInsertItem()) {
- drawInsertMark(gc, paintPosition);
- }
- drawSelectionFocus(gc, paintPosition);
-}
-
-void redraw(){
- Rectangle bounds = getBounds();
- getParent().redraw(bounds.x, bounds.y, bounds.width, bounds.height, false);
-}
-
-/**
- * Update the display to reflect the expanded state of the
- * receiver.
- * @param itemIndex - index position in the receiver's client
- * area where should be drawn.
- */
-void redrawExpanded(int itemIndex) {
- Tree parent = getParent();
- int indicatorWidth = parent.getHierarchyIndicatorRect().width;
- int itemHeight = parent.getItemHeight();
-
- parent.redraw(
- getPaintStartX(), itemIndex * itemHeight,
- indicatorWidth, itemHeight, false);
-}
-/**
- * Reset cached size and position data.
- */
-void reset() {
- super.reset();
- setImageExtent(null);
- setItemExtent(null);
- setPaintStartX(-1);
- setTextYPosition(-1);
-}
-/**
- * Sets the expanded state of the receiver.
- * <p>
- *
- * @param expanded the new expanded state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setExpanded(boolean expand) {
- checkWidget();
- if (isLeaf() == false && expand == true) {
- getParent().expand(this, false);
- }
- else {
- getParent().collapse(this, false);
- }
-}
-public void setImage(Image newImage) {
- checkWidget();
- Tree parent = getParent();
- Image oldImage = getImage();
- boolean isSameImage;
- int imageWidth = 0;
- int redrawX = 0;
-
- super.setImage(newImage);
- if (newImage != null && oldImage != null) {
- isSameImage = newImage.equals(oldImage);
- }
- else {
- isSameImage = newImage == oldImage;
- }
- if (isSameImage == false) {
- if (parent.getVisibleRedrawY(this) != -1) {
- if (parent.getImageExtent() != null) {
- imageWidth = parent.getImageExtent().x;
- }
- else
- if (newImage != null) {
- imageWidth = newImage.getBounds().x;
- }
- redrawX = getItemStartX();
- }
- parent.itemChanged(this, redrawX, imageWidth);
- }
-}
-/**
- * Set the size of the original image of the receiver to 'imageExtent'.
- */
-void setImageExtent(Point imageExtent) {
- this.imageExtent = imageExtent;
-}
-/**
- * Set the index of the receiver to 'index'.
- * This index is used to reference children in their parent.
- */
-void setIndex(int index) {
- this.index = index;
-}
-/**
- * Set the size of the receiver to 'extent'.
- */
-void setItemExtent(Point extent) {
- itemExtent = extent;
-}
-/**
- * Set the x position where the receiver is drawn to 'startX'.
- * @param startX - the x position where the receiver is drawn
- */
-void setPaintStartX(int startX) {
- paintStartX = startX;
-}
-/**
- * Set the parent item of the receiver to 'parentItem'.
- * @param parentItem - the receiver's parent item.
- * Receiver is a root if this is null.
- */
-void setParentItem(TreeItem parentItem) {
- this.parentItem = parentItem;
-}
-/**
- * This label will be displayed to the right of the bitmap,
- * or, if the receiver doesn't have a bitmap to the right of
- * the horizontal hierarchy connector line.
- */
-public void setText(String newText) {
- checkWidget();
- Tree parent = getParent();
- String oldText = getText();
- int redrawX = 0;
- int redrawWidth = 0;
-
- if (newText == null) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
- super.setText(newText);
- if (newText.equals(oldText) == false) {
- if (parent.getVisibleRedrawY(this) != -1) {
- redrawX = getTextXPos();
- redrawWidth = parent.getClientArea().width - redrawX;
- }
- parent.itemChanged(this, redrawX, redrawWidth);
- }
-}
-/**
- * Set the y position of the receiver's text to 'yPosition'.
- */
-void setTextYPosition(int yPosition) {
- textYPosition = yPosition;
-}
-
-public void dispose() {
- if (isDisposed()) return;
- // if the tree is being disposed don't bother collapsing the item since all
- // items in the tree will be deleted and redraws will not be processed anyway
- Tree parent = getParent();
- if (parent.isRemovingAll() == false) {
- parent.collapseNoRedraw(this);
- }
-
- if (parentItem != null) {
- parentItem.removeItem(this);
- }
- else {
- parent.removeItem(this);
- }
-
- super.dispose();
-}
-
-void doDispose() {
- // Notify the parent that the receiver is being removed.
- // Reset cached data.
- setParentItem(null);
- setImageExtent(null);
- setItemExtent(null);
- setIndex(-1);
- setPaintStartX(-1);
- setTextYPosition(-1);
-
- super.doDispose();
-}
-/**
- * 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();
- return super.getChecked();
-}
-public Display getDisplay() {
- return super.getDisplay();
-}
-boolean getExpanding(){
- return isExpanding;
-}
-/**
- * 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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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();
- return super.getGrayed();
-}
-/**
- * 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);
- background = color;
- redraw();
-}
-/**
- * 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();
- super.setChecked(checked);
-}
-void setExpanding(boolean expanding){
- isExpanding = expanding;
-}
-/**
- * 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);
- foreground = color;
- redraw();
-}
-/**
- * Sets the grayed state of the receiver.
- * <p>
- *
- * @param checked the new grayed state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setGrayed (boolean grayed) {
- checkWidget();
- super.setGrayed(grayed);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * 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 AbstractTreeItem {
+/*
+ * This class caches geometric data for drawing.
+ * A description of the cached data follows:
+ *
+ * | 1 || 5 |
+ * | 2 | | 6 |
+ * |3 7|
+ * _____ | 4 |f| |8
+ * | | ____
+ * | - | ===== {image} root 9
+ * |_____| |
+ * |b|c| |d|
+ * | e |
+ *
+ * Widths are measured between vertical lines.
+ *
+ * Cached item rendering data:
+ * 1 = getDecorationsWidth
+ * 2 = getHierarchyIndicatorRect
+ * 3 = getPaintStartX
+ * 4 = getItemConnectorWidth
+ * 5 = getItemWidth
+ * 6 = getSelectionWidth
+ * 7 = getPaintStopX
+ * 8 - getTextXPos
+ * 9 = getTextYPosition
+ *
+ * Rendering constants:
+ * 4 = DEFAULT_ITEM_CONNECTOR_WIDTH, used when no image is set in the tree.
+ * Otherwise it is the image width.
+ * b = IMAGE_PADDING
+ * c = TEXT_INDENT
+ * d = SELECTION_PADDING
+ * e = ITEM_NOIMAGE_OFFSET
+ * f = ITEM_CONNECTOR_PADDING;
+ */
+ private static final int DEFAULT_ITEM_CONNECTOR_WIDTH = 8; // Default width of the horizontal line connecting
+ // items with the vertical lines. Only used when
+ // no image is set in the tree. Normally connector
+ // line width is half the image width.
+ private static final int ITEM_CONNECTOR_PADDING = 2; // Added to the calculated item connector width
+ private static final int IMAGE_PADDING = 3; // Space behind bitmap
+ private static final int ITEM_NOIMAGE_OFFSET = 8; // Offset added to the calculated paint position where
+ // an item starts drawing. To be used when no item
+ // image has been set. Otherwise children would start
+ // drawing at the end of the horizontal item connector
+ // of their parent.
+ private static final int ROOT_INDENT = 5; // Indent of root items
+ private static final int SELECTION_PADDING = 2; // Space behind text
+ private static final int TEXT_INDENT = 2; // Identation of the item label
+
+ // basic item info
+ private TreeItem parentItem;
+ private int index; // index in the parent item
+
+ // geometrical item info
+ private int paintStartX = -1; // X coordinate of the upper-left corner of the
+ // receivers bounding rectangle
+ private Point itemExtent; // Size of the item (image + label)
+ private Point imageExtent; // original size of the item image
+ private int textYPosition = -1; // Centered y position of the item text
+
+
+ //Determine whether the item is being expanded
+ private boolean isExpanding = false;
+ Color background = null;
+ Color foreground = null;
+
+/**
+ * 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 composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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).getItemCount());
+}
+
+/**
+ * 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 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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
+ super(parent, style);
+ parent.addItem(this, index);
+}
+
+/**
+ * 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 composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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).getItemCount());
+}
+
+/**
+ * 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 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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
+ super(checkNull(parentItem).getParent(), style);
+ setParentItem(parentItem);
+ parentItem.add(this, index);
+}
+
+/**
+ * Calculate the number of expanded children.
+ * Recurse up in the tree to the root item.
+ */
+void calculateVisibleItemCount() {
+ Vector children;
+ TreeItem child;
+ int visibleItemCount = 0;
+
+ // check isExpanded field directly for performance
+ if (internalGetExpanded() == true) {
+ children = getChildren();
+ visibleItemCount = children.size();
+ for (int i = 0; i < children.size(); i++) {
+ child = (TreeItem) children.elementAt(i);
+ visibleItemCount += child.getVisibleItemCount();
+ }
+ }
+ setVisibleItemCount(visibleItemCount);
+ calculateVisibleItemCountParent();
+}
+/**
+ * Calculate the number of expanded children for the parent item
+ * of this item.
+ */
+void calculateVisibleItemCountParent() {
+ TreeItem parentItem = getParentItem();
+
+ if (parentItem != null) {
+ parentItem.calculateVisibleItemCount();
+ }
+ else {
+ getParent().getRoot().calculateVisibleItemCount();
+ }
+}
+/**
+ * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'tree' is null.
+ * Otherwise return 'tree'
+ */
+static Tree checkNull(Tree tree) {
+ if (tree == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ return tree;
+}
+/**
+ * Throw an SWT.ERROR_NULL_ARGUMENT exception if 'item' is null.
+ * Otherwise return 'item'
+ */
+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);
+}
+
+/**
+ * Draw the hierarchy indicator at 'position'.
+ *
+ * Note:
+ * Assumes that the hierarchy indicators for the expanded and
+ * collapsed state are the same size.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ * @return position to continue drawing
+ */
+Point drawHierarchyIndicator(GC gc, Point position) {
+ Tree parent = getParent();
+ Image hierarchyImage;
+ Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
+ int x = position.x;
+ int y = position.y;
+ int yCenter = y + parent.getItemHeight() / 2;
+ Point connectorLinePosition;
+
+ if (isLeaf() == false) {
+ if (getExpanded() == true) {
+ hierarchyImage = parent.getExpandedImage();
+ }
+ else {
+ hierarchyImage = parent.getCollapsedImage();
+ }
+ if (hierarchyImage != null) {
+ gc.drawImage(hierarchyImage, x + indicatorRectangle.x, y + indicatorRectangle.y);
+ }
+ connectorLinePosition = new Point(x + indicatorRectangle.width, yCenter);
+ }
+ else {
+ connectorLinePosition = new Point(
+ x + indicatorRectangle.width / 2
+ + indicatorRectangle.width % 2, yCenter); // % 2 in order to not start the next hierarchy
+ // component at the middle of the icon but after.
+ }
+ return connectorLinePosition;
+}
+/**
+ * Draw a horizontal line connecting the item image (or label
+ * if there is no image) to the vertical line connecting to
+ * the parent.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ * @return position to continue drawing
+ */
+Point drawHorizontalItemConnector(GC gc, Point position) {
+ int itemConnectorEndPos = position.x + getItemConnectorWidth() - 1; // -1 because the position of the last pixel needs to be calculated
+
+ gc.drawLine(position.x, position.y, itemConnectorEndPos, position.y);
+ return new Point(itemConnectorEndPos + 1, position.y); // + 1 in order to resume drawing after line not on end of line
+}
+/**
+ * Display the item image at 'position' using 'gc'.
+ * @param gc - GC to draw on
+ * @param position - position on the GC to draw at
+ * @return position to continue drawing
+ */
+Point drawImage(GC gc, Point destinationPosition) {
+ Tree parent = getParent();
+ Image image = getImage();
+ Point sourceImageExtent;
+ Point destinationImageExtent = parent.getImageExtent();
+ int yCenter;
+
+ if (image != null) {
+ sourceImageExtent = getImageExtent();
+ yCenter = (parent.getItemHeight() - destinationImageExtent.y) / 2;
+ gc.drawImage(
+ image,
+ 0, 0, // source x, y
+ sourceImageExtent.x, sourceImageExtent.y, // source width, height
+ destinationPosition.x, destinationPosition.y + yCenter, // destination x, y
+ destinationImageExtent.x, destinationImageExtent.y); // destination width, height
+ }
+ if (destinationImageExtent != null) {
+ destinationPosition.x += destinationImageExtent.x + IMAGE_PADDING;
+ }
+ return destinationPosition;
+}
+/**
+ * Draw a rectangle enclosing the item label. The rectangle
+ * indicates that the receiver was selected last and that it has
+ * the input focus.
+ * The rectangle will only be drawn if the receiver is selected.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ */
+void drawSelectionFocus(GC gc, Point position) {
+ Point selectionExtent = getSelectionExtent();
+
+ if (selectionExtent == null) {
+ return;
+ }
+ if (getParent().hasFocus(this) == true) {
+ gc.drawFocus(
+ position.x, position.y,
+ selectionExtent.x, selectionExtent.y);
+ }
+}
+/**
+ * Draw a vertical line connecting the horizontal connector line
+ * with that of the previous item.
+ * Called recursively to draw the lines on all tree levels.
+ * @param gc - GC to draw on.
+ * @param yPosition - y position of the upper side of the
+ * receiver's bounding box.
+ * @param isFirstChild - method is called to draw a vertical
+ * line for the first child. Leave room for the hierarchy icon.
+ */
+void drawVerticalItemConnector(GC gc, int yPosition, boolean isFirstChild) {
+ Tree parent = getParent();
+ TreeItem nextDrawItem = getParentItem();
+ AbstractTreeItem parentItem = nextDrawItem;
+ Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
+ int itemHeight = parent.getItemHeight();
+ int itemHeightDiv2 = itemHeight / 2 + itemHeight % 2;
+ int indicatorHeightDiv2 = indicatorRectangle.height / 2 + indicatorRectangle.height % 2;
+ int lineX = getPaintStartX() + indicatorRectangle.width / 2;
+ int lineStartY = yPosition - itemHeightDiv2;
+ int lineEndY = yPosition + itemHeightDiv2;
+
+ if (parentItem == null) {
+ parentItem = parent.getRoot();
+ }
+ if (getIndex() != parentItem.getItemCount()-1) { // if item is not the last child
+ if (isFirstChild == true) {
+ lineStartY += indicatorHeightDiv2; // leave space for the hierarchy image
+ }
+ gc.drawLine(lineX, lineStartY, lineX, lineEndY);
+ }
+
+ if (nextDrawItem != null) {
+ nextDrawItem.drawVerticalItemConnector(gc, yPosition, false);
+ }
+}
+/**
+ * Draw a vertical line connecting the horizontal connector line
+ * with that of the previous item.
+ * Do this on all tree levels up to the root level.
+ * @param gc - GC to draw on.
+ * @param position - position on the GC to draw at.
+ * @return position to continue drawing
+ */
+Point drawVerticalItemConnector(GC gc, Point position) {
+ Tree parent = getParent();
+ TreeItem parentItem = getParentItem();
+ Rectangle indicatorRectangle = parent.getHierarchyIndicatorRect();
+ int itemHeight = parent.getItemHeight();
+ int itemHeightDiv2 = itemHeight / 2 + itemHeight % 2;
+ int indicatorHeightDiv2 = indicatorRectangle.height / 2 + indicatorRectangle.height % 2;
+ int lineX = position.x + indicatorRectangle.width / 2;
+ int lineStartY = position.y - itemHeightDiv2;
+ int lineEndY = position.y + itemHeightDiv2 - itemHeight % 2;
+ TreeItem predecessor;
+ boolean isFirstChild = false;
+
+ if (isRoot() == true) {
+ if (getIndex() == 0) {
+ return position; // first root, don't draw vertical line
+ }
+ }
+ else
+ if (getIndex() == 0) { // if item is first child
+ lineStartY += itemHeightDiv2;
+ isFirstChild = true;
+ }
+ predecessor = getPredecessor();
+ if (predecessor != null && predecessor.isLeaf() == false) {
+ lineStartY += indicatorHeightDiv2; // leave space for the hierarchy image
+ }
+ if (isLeaf() == false) {
+ lineEndY -= indicatorHeightDiv2;
+ }
+ gc.drawLine(lineX, lineStartY, lineX, lineEndY);
+ if (parentItem != null) {
+ parentItem.drawVerticalItemConnector(gc, position.y, isFirstChild);
+ }
+ return position;
+}
+/**
+ * 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 (background != null) return background;
+ Tree parent = getParent();
+ return parent.getBackground();
+}
+/**
+ * Returns a rectangle describing the receiver's size and location
+ * relative to its parent.
+ *
+ * @return the receiver's bounding rectangle
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public Rectangle getBounds() {
+ checkWidget();
+ Tree parent = getParent();
+ Point extent = getItemExtent();
+ int x = getTextXPos() - TEXT_INDENT;
+
+ return new Rectangle(x, parent.getRedrawY(this), extent.x - (x - getItemStartX()), extent.y);
+}
+
+/**
+ * Answer the x position of the item check box
+ */
+int getCheckboxXPosition() {
+ return getPaintStartX() + getDecorationsWidth();
+}
+/**
+ * Answer the combined width of the hierarchy indicator and
+ * the horizontal item connector line.
+ */
+int getDecorationsWidth() {
+ int indicatorWidth = getParent().getHierarchyIndicatorRect().width;
+ int width = indicatorWidth + getItemConnectorWidth();
+
+ if (isLeaf() == true) {
+ width -= indicatorWidth / 2;
+ }
+ return width;
+}
+/**
+ * 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 (foreground != null) return foreground;
+ Tree parent = getParent();
+ return parent.getForeground();
+}
+/**
+ * Answer the index of the receiver relative to the first root
+ * item.
+ * @return
+ * The index of the receiver relative to the first root item.
+ */
+int getGlobalIndex() {
+ int globalItemIndex = getIndex();
+ AbstractTreeItem item = null;
+
+ if (isRoot() == false) {
+ item = getParentItem();
+ globalItemIndex++; // adjust for 0-based non-root items
+ }
+ else {
+ item = getParent().getRoot();
+ }
+
+ globalItemIndex += item.getVisibleIndex(getIndex());
+ return globalItemIndex;
+}
+/**
+ * Answer the original size of the image of the receiver.
+ */
+Point getImageExtent() {
+ Image image = getImage();
+ Rectangle imageBounds;
+
+ if (imageExtent == null && image != null) {
+ imageBounds = image.getBounds();
+ imageExtent = new Point(imageBounds.width, imageBounds.height);
+ }
+ return imageExtent;
+}
+/**
+ * Answer the receiver's index into its parent's list of children
+ */
+int getIndex() {
+ return index;
+}
+/**
+ * Answer the width of the horizontal item connector line.
+ */
+int getItemConnectorWidth() {
+ Tree parent = getParent();
+ Point imageExtent = parent.getImageExtent();
+ int itemConnectorWidth;
+ int indicatorWidth = parent.getHierarchyIndicatorRect().width;
+
+ if (imageExtent != null) {
+ itemConnectorWidth = imageExtent.x / 2 + ITEM_CONNECTOR_PADDING;
+ }
+ else {
+ itemConnectorWidth = DEFAULT_ITEM_CONNECTOR_WIDTH;
+ }
+ if (isLeaf() == false) { // has children = has hierarchy indicator = shorter connector
+ itemConnectorWidth -= indicatorWidth / 2;
+ }
+ return itemConnectorWidth;
+}
+/**
+ * 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();
+ return super.getItemCount();
+}
+/**
+ * Answer the size of the receiver as displayed on the screen.
+ */
+Point getItemExtent() {
+ Tree parent;
+ Point imageExtent;
+ String text;
+ int itemWidth;
+
+ if (itemExtent == null) {
+ parent = getParent();
+ imageExtent = parent.getImageExtent();
+ text = getText();
+ itemWidth = SELECTION_PADDING;
+ if (text != null) {
+ itemWidth += parent.getTextWidth(text) + TEXT_INDENT;
+ }
+ if (imageExtent != null) {
+ itemWidth += imageExtent.x + IMAGE_PADDING;
+ }
+ itemExtent = new Point(itemWidth, parent.getItemHeight());
+ }
+ return itemExtent;
+}
+/**
+ * Answer the x position at which painting of the receiver's
+ * contents (ie. image, text) can begin.
+ */
+int getItemStartX() {
+ int itemStartX = getPaintStartX() + getDecorationsWidth();
+
+ if (isCheckable() == true) {
+ itemStartX += getCheckboxBounds().width + CHECKBOX_PADDING;
+ }
+ return itemStartX;
+}
+/**
+ * Returns an 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();
+ TreeItem childrenArray[] = new TreeItem[getItemCount()];
+
+ getChildren().copyInto(childrenArray);
+ return childrenArray;
+}
+/**
+ * Answer the x position where the receiver is drawn.
+ */
+int getPaintStartX() {
+ Tree parent = getParent();
+ Point imageExtent;
+ TreeItem parentItem;
+
+ if (paintStartX == -1) {
+ if (isRoot() == true) {
+ paintStartX = ROOT_INDENT;
+ }
+ else {
+ parentItem = getParentItem();
+ // subtract parent.getHorizontalOffset() to calculate the cached start
+ // position independent of the horizontal scroll offset. Fixes 1G1L7EU.
+ paintStartX = parentItem.getPaintStartX()
+ - parent.getHorizontalOffset()
+ + parentItem.getDecorationsWidth()
+ - parent.getHierarchyIndicatorRect().width / 2;
+ imageExtent = parent.getImageExtent();
+ if (imageExtent != null) {
+ paintStartX += imageExtent.x / 2;
+ }
+ else {
+ paintStartX += ITEM_NOIMAGE_OFFSET;
+ }
+ }
+ }
+ return paintStartX + parent.getHorizontalOffset();
+}
+/**
+ * Answer the pixel at which the receiver stops drawing.
+ */
+int getPaintStopX() {
+ return (getItemStartX() + getItemExtent().x - getParent().getHorizontalOffset());
+}
+/**
+ * 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 (Tree) super.getSelectableParent();
+}
+/**
+ * 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;
+}
+/**
+ * Answer the item that directly precedes the receiver.
+ * Answer null if this is the first item in a hierarchy level
+ * or if there are expanded children in the previous item.
+ */
+TreeItem getPredecessor() {
+ AbstractTreeItem parentItem = getParentItem();
+ Vector children;
+ int previousIndex = getIndex() - 1;
+ TreeItem previousItem = null;
+
+ if (parentItem == null) {
+ parentItem = getParent().getRoot();
+ }
+ if (previousIndex >= 0) {
+ children = parentItem.getChildren();
+ previousItem = (TreeItem) children.elementAt(previousIndex);
+ if (previousItem.isLeaf() == false && previousItem.getExpanded() == true) {
+ previousItem = null; // no immediate predecessor because there are expanded children
+ }
+ }
+ return previousItem;
+}
+/**
+ * Answer the size of the rectangle drawn to indicate the
+ * selected state of the receiver.
+ * This is also used to draw the selection focus rectangle.
+ */
+Point getSelectionExtent() {
+ Point selectionExtent = getItemExtent();
+ Point imageExtent = getParent().getImageExtent();
+ int x = selectionExtent.x;
+
+ if (imageExtent != null) {
+ x -= imageExtent.x + IMAGE_PADDING;
+ }
+ return new Point(x, selectionExtent.y);
+}
+/**
+ * Return the x position of the selection rectangle
+ */
+int getSelectionX() {
+ return getTextXPos() - TEXT_INDENT;
+}
+/**
+ * Answer the x position where the receiver draws the item text.
+ * This position is relative to the item start position.
+ */
+int getTextXPos() {
+ Point imageExtent = getParent().getImageExtent();
+ int textXPos = getItemStartX() + TEXT_INDENT;
+
+ if (imageExtent != null) {
+ textXPos += imageExtent.x + IMAGE_PADDING;
+ }
+ return textXPos;
+}
+/**
+ * Answer the y position of the receiver's text.
+ * @param
+ * gc - GC to use for calculating the text y position
+ */
+int getTextYPosition(GC gc) {
+ String text;
+
+ if (textYPosition == -1) {
+ text = getText();
+ if (text != null) {
+ textYPosition = (getParent().getItemHeight() - gc.stringExtent(text).y) / 2;
+ }
+ else {
+ textYPosition = 0;
+ }
+ }
+ return textYPosition;
+}
+/**
+ * Answer the index of the receiver relative to the first root
+ * item.
+ * If 'anIndex' is the index of the expanded item 'anItem'
+ * then the following expressions are true:
+ * 'anItem == theRoot.getVisibleItem(anIndex)' and
+ * 'anIndex == anItem.getVisibleIndex()'
+ * @return
+ * The index of the receiver relative to the first root item.
+ * Answer -1 if the receiver is not visible (because the parent
+ * is collapsed).
+ */
+int getVisibleIndex() {
+ int visibleItemIndex = getIndex();
+ AbstractTreeItem item = null;
+
+ if (isRoot() == false) {
+ if (isVisible() == false) {
+ return -1;
+ }
+ item = getParentItem();
+ visibleItemIndex++; // adjust for 0-based non-root items
+ }
+ else {
+ item = getParent().getRoot();
+ }
+
+ visibleItemIndex += item.getVisibleIndex(getIndex());
+ return visibleItemIndex;
+}
+/**
+ * Answer the index of the child item identified by 'childIndex'
+ * relative to the first root item.
+ */
+int getVisibleIndex(int childIndex) {
+ Enumeration children = getChildren().elements();
+ TreeItem child;
+ int visibleItemIndex = getIndex();
+
+ if (isRoot() == false) {
+ visibleItemIndex++; // adjust for 0-based non-root items
+ }
+
+ while (children.hasMoreElements() == true) {
+ child = (TreeItem) children.nextElement();
+ if (child.getIndex() == childIndex) {
+ if (isRoot() == false) {
+ visibleItemIndex += getParentItem().getVisibleIndex(getIndex());
+ }
+ else {
+ visibleItemIndex += getParent().getRoot().getVisibleIndex(getIndex());
+ }
+ break;
+ }
+ visibleItemIndex += child.getVisibleItemCount();
+ }
+ return visibleItemIndex;
+}
+/**
+ * Answer the item at 'searchIndex' relativ to the receiver.
+ * When this method is called for the root item, 'searchIndex'
+ * represents the global index into all items of the tree.
+ * searchIndex=0 returns the receiver.
+ * searchIndex=1 returns the first visible child.
+ * Note: searchIndex must be >= 0
+ *
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. Visible here means that all
+ * the parents of the item are expanded. An item is only
+ * visible on screen if it is within the widget client area.
+ */
+TreeItem getVisibleItem(int searchIndex) {
+ TreeItem child;
+ TreeItem foundItem = null;
+ Enumeration children = getChildren().elements();
+
+ if (searchIndex == 0) {
+ return this;
+ }
+ else
+ if (getExpanded() == false) { // trying to find a child when this item isn't expanded ?
+ return null;
+ }
+
+ // Search for expanded items first. Count all subitems in the process.
+ while (children.hasMoreElements() == true && foundItem == null) {
+ child = (TreeItem) children.nextElement();
+ searchIndex--;
+ if (child.getExpanded() == true) {
+ searchIndex -= child.getVisibleItemCount(); // count children of all expanded items
+ }
+ if (searchIndex <= 0) { // is searched item past child ?
+ // add back children of current item (that's what we want to search)
+ foundItem = child.getVisibleItem(searchIndex + child.getVisibleItemCount());
+ }
+ }
+
+ return foundItem;
+}
+/**
+ * Answer whether 'item' is a child, direct or indirect, of the receiver.
+ * It is an indirect child if it is a child of one of the receiver's children.
+ */
+boolean isChild(TreeItem item) {
+ Vector children = getChildren();
+ TreeItem child;
+
+ if (children.contains(item) == true) {
+ return true;
+ }
+ for (int i = 0; i < children.size(); i++) {
+ child = (TreeItem) children.elementAt(i);
+ if (child.isChild(item) == true) {
+ return true;
+ }
+ }
+ return false;
+}
+/**
+ * Answer whether the receiver is a root item.
+ * The receiver is a root item when it does not have a parent item.
+ * @return
+ * true - the receiver is a root item.
+ * false - the receiver is not a root item.
+ */
+boolean isRoot() {
+ return (getParentItem() == null);
+}
+/**
+ * Answer whether the click at 'position' on the receiver is a selection
+ * click.
+ * @param position - location of the mouse click relative to the
+ * upper left corner of the receiver.
+ * @return true - receiver was clicked.
+ * false - receiver was not clicked.
+ */
+boolean isSelectionHit(Point position) {
+ Point itemExtent = getItemExtent();
+
+ if (itemExtent == null) { // neither image nor text have been set
+ return false;
+ }
+ return (new Rectangle(
+ getItemStartX() - getPaintStartX(), 0,
+ itemExtent.x, itemExtent.y)).contains(position);
+}
+/**
+ * Answer whether the receiver is visible
+ * An item is visible when its parent item is visible and
+ * expanded. Root items are always visible.
+ *
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. Visible here means that all
+ * the parents of the item are expanded. An item is only
+ * visible on screen if it is within the receiver's parent's
+ * client area.
+ * @return
+ * true - the receiver is visible
+ * false - the receiver is not visible
+ */
+boolean isVisible() {
+ boolean isVisible = true;
+ TreeItem parentItem = getParentItem();
+
+ if (isRoot() == false) {
+ isVisible = parentItem.getExpanded();
+ if (isVisible == true) {
+ isVisible = parentItem.isVisible();
+ }
+ }
+ return isVisible;
+}
+/**
+ * Make this item visible by expanding its parent item.
+ */
+void makeVisible() {
+ TreeItem parentItem = getParentItem();
+
+ if (isVisible() == false && parentItem != null) {
+ getParent().expand(parentItem, true); // have to call Tree.expand directly in order to trigger Expand event
+ parentItem.makeVisible();
+ }
+}
+/**
+ * Draw the receiver at 'yPosition' in the client area of the parent.
+ * @param gc - GC to draw on.
+ * @param yPosition - y coordinate where the receiver should draw at.
+ */
+void paint(GC gc, int yPosition) {
+ if (isVisible() == false) {
+ return;
+ }
+
+ Tree parent = getParent();
+ Point paintPosition = new Point(getPaintStartX(), yPosition);
+ Point extent = getSelectionExtent();
+ gc.setForeground(parent.CONNECTOR_LINE_COLOR);
+ paintPosition = drawVerticalItemConnector(gc, paintPosition);
+ paintPosition = drawHierarchyIndicator(gc, paintPosition);
+ paintPosition = drawHorizontalItemConnector(gc, paintPosition);
+ gc.setForeground(parent.getForeground());
+ // paint the rest
+ if (isCheckable() == true) {
+ paintPosition = drawCheckbox(gc, new Point(paintPosition.x, yPosition));
+ }
+ paintPosition = drawImage(gc, new Point(paintPosition.x, yPosition));
+ if (isSelected() == true) {
+ gc.setBackground(getSelectionBackgroundColor());
+ gc.setForeground(getSelectionForegroundColor());
+ gc.fillRectangle(paintPosition.x, paintPosition.y, extent.x, extent.y);
+ } else {
+ gc.setBackground(getBackground());
+ gc.setForeground(getForeground());
+ if(getBackground() != parent.getBackground()){
+ gc.fillRectangle(paintPosition.x, paintPosition.y, extent.x, extent.y);
+ }
+ }
+ if (text != null) {
+ gc.drawString(text, getTextXPos(), paintPosition.y + getTextYPosition(gc), true);
+ }
+ if (this == parent.getInsertItem()) {
+ drawInsertMark(gc, paintPosition);
+ }
+ drawSelectionFocus(gc, paintPosition);
+}
+
+void redraw(){
+ Rectangle bounds = getBounds();
+ getParent().redraw(bounds.x, bounds.y, bounds.width, bounds.height, false);
+}
+
+/**
+ * Update the display to reflect the expanded state of the
+ * receiver.
+ * @param itemIndex - index position in the receiver's client
+ * area where should be drawn.
+ */
+void redrawExpanded(int itemIndex) {
+ Tree parent = getParent();
+ int indicatorWidth = parent.getHierarchyIndicatorRect().width;
+ int itemHeight = parent.getItemHeight();
+
+ parent.redraw(
+ getPaintStartX(), itemIndex * itemHeight,
+ indicatorWidth, itemHeight, false);
+}
+/**
+ * Reset cached size and position data.
+ */
+void reset() {
+ super.reset();
+ setImageExtent(null);
+ setItemExtent(null);
+ setPaintStartX(-1);
+ setTextYPosition(-1);
+}
+/**
+ * Sets the expanded state of the receiver.
+ * <p>
+ *
+ * @param expanded the new expanded state
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setExpanded(boolean expand) {
+ checkWidget();
+ if (isLeaf() == false && expand == true) {
+ getParent().expand(this, false);
+ }
+ else {
+ getParent().collapse(this, false);
+ }
+}
+public void setImage(Image newImage) {
+ checkWidget();
+ Tree parent = getParent();
+ Image oldImage = getImage();
+ boolean isSameImage;
+ int imageWidth = 0;
+ int redrawX = 0;
+
+ super.setImage(newImage);
+ if (newImage != null && oldImage != null) {
+ isSameImage = newImage.equals(oldImage);
+ }
+ else {
+ isSameImage = newImage == oldImage;
+ }
+ if (isSameImage == false) {
+ if (parent.getVisibleRedrawY(this) != -1) {
+ if (parent.getImageExtent() != null) {
+ imageWidth = parent.getImageExtent().x;
+ }
+ else
+ if (newImage != null) {
+ imageWidth = newImage.getBounds().x;
+ }
+ redrawX = getItemStartX();
+ }
+ parent.itemChanged(this, redrawX, imageWidth);
+ }
+}
+/**
+ * Set the size of the original image of the receiver to 'imageExtent'.
+ */
+void setImageExtent(Point imageExtent) {
+ this.imageExtent = imageExtent;
+}
+/**
+ * Set the index of the receiver to 'index'.
+ * This index is used to reference children in their parent.
+ */
+void setIndex(int index) {
+ this.index = index;
+}
+/**
+ * Set the size of the receiver to 'extent'.
+ */
+void setItemExtent(Point extent) {
+ itemExtent = extent;
+}
+/**
+ * Set the x position where the receiver is drawn to 'startX'.
+ * @param startX - the x position where the receiver is drawn
+ */
+void setPaintStartX(int startX) {
+ paintStartX = startX;
+}
+/**
+ * Set the parent item of the receiver to 'parentItem'.
+ * @param parentItem - the receiver's parent item.
+ * Receiver is a root if this is null.
+ */
+void setParentItem(TreeItem parentItem) {
+ this.parentItem = parentItem;
+}
+/**
+ * This label will be displayed to the right of the bitmap,
+ * or, if the receiver doesn't have a bitmap to the right of
+ * the horizontal hierarchy connector line.
+ */
+public void setText(String newText) {
+ checkWidget();
+ Tree parent = getParent();
+ String oldText = getText();
+ int redrawX = 0;
+ int redrawWidth = 0;
+
+ if (newText == null) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ super.setText(newText);
+ if (newText.equals(oldText) == false) {
+ if (parent.getVisibleRedrawY(this) != -1) {
+ redrawX = getTextXPos();
+ redrawWidth = parent.getClientArea().width - redrawX;
+ }
+ parent.itemChanged(this, redrawX, redrawWidth);
+ }
+}
+/**
+ * Set the y position of the receiver's text to 'yPosition'.
+ */
+void setTextYPosition(int yPosition) {
+ textYPosition = yPosition;
+}
+
+public void dispose() {
+ if (isDisposed()) return;
+ // if the tree is being disposed don't bother collapsing the item since all
+ // items in the tree will be deleted and redraws will not be processed anyway
+ Tree parent = getParent();
+ if (parent.isRemovingAll() == false) {
+ parent.collapseNoRedraw(this);
+ }
+
+ if (parentItem != null) {
+ parentItem.removeItem(this);
+ }
+ else {
+ parent.removeItem(this);
+ }
+
+ super.dispose();
+}
+
+void doDispose() {
+ // Notify the parent that the receiver is being removed.
+ // Reset cached data.
+ setParentItem(null);
+ setImageExtent(null);
+ setItemExtent(null);
+ setIndex(-1);
+ setPaintStartX(-1);
+ setTextYPosition(-1);
+
+ super.doDispose();
+}
+/**
+ * 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();
+ return super.getChecked();
+}
+public Display getDisplay() {
+ return super.getDisplay();
+}
+boolean getExpanding(){
+ return isExpanding;
+}
+/**
+ * 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
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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();
+ return super.getGrayed();
+}
+/**
+ * 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);
+ background = color;
+ redraw();
+}
+/**
+ * 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();
+ super.setChecked(checked);
+}
+void setExpanding(boolean expanding){
+ isExpanding = expanding;
+}
+/**
+ * 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);
+ foreground = color;
+ redraw();
+}
+/**
+ * Sets the grayed state of the receiver.
+ * <p>
+ *
+ * @param checked the new grayed state
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setGrayed (boolean grayed) {
+ checkWidget();
+ super.setGrayed(grayed);
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeRoots.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeRoots.java
index b50fab0422..a60f4e6082 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeRoots.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeRoots.java
@@ -1,159 +1,159 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.graphics.*;
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * This class is used to store tree root items.
- * Instances of this class are never displayed.
- */
-class TreeRoots extends AbstractTreeItem {
-/**
- * Create a tree item that holds one or more root items
- * @param parent - Tree widget the receiver belongs to
- */
-TreeRoots(Tree parent) {
- super(parent, 0);
- initialize();
-}
-/**
- * Calculate the number of expanded children.
- * Recurse up in the tree to the root item.
- */
-void calculateVisibleItemCount() {
- Vector children = getChildren();
- TreeItem child;
- int visibleItemCount = children.size();
-
- for (int i = 0; i < children.size(); i++) {
- child = (TreeItem) children.elementAt(i);
- visibleItemCount += child.getVisibleItemCount();
- }
- setVisibleItemCount(visibleItemCount);
-}
-/**
- * Calculate the number of expanded children for the parent item
- * of this item.
- */
-void calculateVisibleItemCountParent() {}
-
-public void dispose() {
- if (isDisposed()) return;
- Tree parent = (Tree) getSelectableParent();
-
- // all tree items are removed so we don't need to do
- // time consuming screen updates for each removed item
- parent.setRemovingAll(true);
- super.dispose();
- parent.setRemovingAll(false);
-}
-/**
- * Answer the x position of the item check box
- */
-int getCheckboxXPosition() {
- return 0;
-}
-/**
- * Implements SelectableItem#getSelectionExtent
- * Should never be called since objects of this type are never
- * rendered
- */
-Point getSelectionExtent() {
- return new Point(0, 0);
-}
-/**
- * Implements SelectableItem#getSelectionX
- * Should never be called since objects of this type are never
- * rendered
- */
-int getSelectionX() {
- return 0;
-}
-/**
- * Always answer -1 to indicate that the receiver is not visible.
- */
-int getVisibleIndex() {
- return -1;
-}
-/**
- * Answer the index of the child item identified by 'childIndex'
- * relative to the first root item.
- */
-int getVisibleIndex(int childIndex) {
- Enumeration children = getChildren().elements();
- TreeItem child;
- int globalItemIndex = 0;
-
- while (children.hasMoreElements() == true) {
- child = (TreeItem) children.nextElement();
- if (child.getIndex() == childIndex) {
- break;
- }
- globalItemIndex += child.getVisibleItemCount();
- }
- return globalItemIndex;
-}
-/**
- * Answer the item at 'searchIndex' relativ to the receiver.
- * When this method is called for the root item, 'searchIndex'
- * represents the global index into all items of the tree.
- * searchIndex=0 returns the receiver.
- * searchIndex=1 returns the first visible child.
- * Note: searchIndex must be >= 0
- *
- * Note:
- * Visible in this context does not neccessarily mean that the
- * item is displayed on the screen. Visible here means that all
- * the parents of the item are expanded. An item is only
- * visible on screen if it is within the widget client area.
- */
-TreeItem getVisibleItem(int searchIndex) {
- TreeItem child;
- TreeItem foundItem = null;
- Enumeration children = getChildren().elements();
-
- searchIndex++; // skip this fake root item
-
- // Search for expanded items first. Count all subitems in the process.
- while (children.hasMoreElements() == true && foundItem == null) {
- child = (TreeItem) children.nextElement();
- searchIndex--;
- if (child.internalGetExpanded() == true) {
- searchIndex -= child.getVisibleItemCount(); // count children of all expanded items
- }
- if (searchIndex <= 0) { // is searched item past child ?
- // add back children of current item (that's what we want to search)
- foundItem = child.getVisibleItem(searchIndex + child.getVisibleItemCount());
- }
- }
- return foundItem;
-}
-/**
- * Initialize the receiver
- */
-void initialize() {
- internalSetExpanded(true);
-}
-
-/**
- * Select the receiver and all children
- */
-Vector selectAll(Vector selectedItems) {
- Enumeration children = getChildren().elements();
- AbstractTreeItem treeItem;
-
- while (children.hasMoreElements() == true) {
- treeItem = (AbstractTreeItem) children.nextElement();
- selectedItems = treeItem.selectAll(selectedItems);
- }
- return selectedItems;
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.graphics.*;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * This class is used to store tree root items.
+ * Instances of this class are never displayed.
+ */
+class TreeRoots extends AbstractTreeItem {
+/**
+ * Create a tree item that holds one or more root items
+ * @param parent - Tree widget the receiver belongs to
+ */
+TreeRoots(Tree parent) {
+ super(parent, 0);
+ initialize();
+}
+/**
+ * Calculate the number of expanded children.
+ * Recurse up in the tree to the root item.
+ */
+void calculateVisibleItemCount() {
+ Vector children = getChildren();
+ TreeItem child;
+ int visibleItemCount = children.size();
+
+ for (int i = 0; i < children.size(); i++) {
+ child = (TreeItem) children.elementAt(i);
+ visibleItemCount += child.getVisibleItemCount();
+ }
+ setVisibleItemCount(visibleItemCount);
+}
+/**
+ * Calculate the number of expanded children for the parent item
+ * of this item.
+ */
+void calculateVisibleItemCountParent() {}
+
+public void dispose() {
+ if (isDisposed()) return;
+ Tree parent = (Tree) getSelectableParent();
+
+ // all tree items are removed so we don't need to do
+ // time consuming screen updates for each removed item
+ parent.setRemovingAll(true);
+ super.dispose();
+ parent.setRemovingAll(false);
+}
+/**
+ * Answer the x position of the item check box
+ */
+int getCheckboxXPosition() {
+ return 0;
+}
+/**
+ * Implements SelectableItem#getSelectionExtent
+ * Should never be called since objects of this type are never
+ * rendered
+ */
+Point getSelectionExtent() {
+ return new Point(0, 0);
+}
+/**
+ * Implements SelectableItem#getSelectionX
+ * Should never be called since objects of this type are never
+ * rendered
+ */
+int getSelectionX() {
+ return 0;
+}
+/**
+ * Always answer -1 to indicate that the receiver is not visible.
+ */
+int getVisibleIndex() {
+ return -1;
+}
+/**
+ * Answer the index of the child item identified by 'childIndex'
+ * relative to the first root item.
+ */
+int getVisibleIndex(int childIndex) {
+ Enumeration children = getChildren().elements();
+ TreeItem child;
+ int globalItemIndex = 0;
+
+ while (children.hasMoreElements() == true) {
+ child = (TreeItem) children.nextElement();
+ if (child.getIndex() == childIndex) {
+ break;
+ }
+ globalItemIndex += child.getVisibleItemCount();
+ }
+ return globalItemIndex;
+}
+/**
+ * Answer the item at 'searchIndex' relativ to the receiver.
+ * When this method is called for the root item, 'searchIndex'
+ * represents the global index into all items of the tree.
+ * searchIndex=0 returns the receiver.
+ * searchIndex=1 returns the first visible child.
+ * Note: searchIndex must be >= 0
+ *
+ * Note:
+ * Visible in this context does not neccessarily mean that the
+ * item is displayed on the screen. Visible here means that all
+ * the parents of the item are expanded. An item is only
+ * visible on screen if it is within the widget client area.
+ */
+TreeItem getVisibleItem(int searchIndex) {
+ TreeItem child;
+ TreeItem foundItem = null;
+ Enumeration children = getChildren().elements();
+
+ searchIndex++; // skip this fake root item
+
+ // Search for expanded items first. Count all subitems in the process.
+ while (children.hasMoreElements() == true && foundItem == null) {
+ child = (TreeItem) children.nextElement();
+ searchIndex--;
+ if (child.internalGetExpanded() == true) {
+ searchIndex -= child.getVisibleItemCount(); // count children of all expanded items
+ }
+ if (searchIndex <= 0) { // is searched item past child ?
+ // add back children of current item (that's what we want to search)
+ foundItem = child.getVisibleItem(searchIndex + child.getVisibleItemCount());
+ }
+ }
+ return foundItem;
+}
+/**
+ * Initialize the receiver
+ */
+void initialize() {
+ internalSetExpanded(true);
+}
+
+/**
+ * Select the receiver and all children
+ */
+Vector selectAll(Vector selectedItems) {
+ Enumeration children = getChildren().elements();
+ AbstractTreeItem treeItem;
+
+ while (children.hasMoreElements() == true) {
+ treeItem = (AbstractTreeItem) children.nextElement();
+ selectedItems = treeItem.selectAll(selectedItems);
+ }
+ return selectedItems;
+}
+}
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
index d10b1322ba..b01043f7d1 100644
--- 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
@@ -10,23 +10,23 @@ 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
+/**
+ * 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
*/
public final class Color {
- /**
- * the handle to the OS color resource
- * (Warning: This field is platform dependent)
+ /**
+ * the handle to the OS color resource
+ * (Warning: This field is platform dependent)
*/
public GdkColor handle;
@@ -38,29 +38,29 @@ public final class Color {
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
+/**
+ * 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();
@@ -69,27 +69,27 @@ public Color(Device device, int red, int green, int 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
+/**
+ * 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();
@@ -99,10 +99,10 @@ public Color(Device device, RGB rgb) {
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.
+/**
+ * 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;
@@ -121,15 +121,15 @@ public void dispose() {
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
+/**
+ * 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;
@@ -141,69 +141,69 @@ public boolean equals(Object object) {
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>
+/**
+ * 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>
+/**
+ * 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>
+/**
+ * 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 which 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
+/**
+ * Returns an integer hash code for the receiver. Any two
+ * objects which 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.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * Returns an <code>RGB</code> representing the receiver.
+ *
+ * @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);
@@ -263,25 +263,25 @@ void init(Device device, int red, int green, int blue) {
}
}
-/**
- * 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
+/**
+ * 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
+/**
+ * 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*}";
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
index 4fe50d063a..9f269831e1 100644
--- 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
@@ -10,34 +10,34 @@ 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>
+/**
+ * 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 {
- /**
- * the handle to the OS cursor resource
- * (Warning: This field is platform dependent)
+ /**
+ * the handle to the OS cursor resource
+ * (Warning: This field is platform dependent)
*/
public int handle;
@@ -49,46 +49,46 @@ public final class Cursor {
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
+/**
+ * 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();
@@ -170,37 +170,37 @@ public Cursor(Device device, int style) {
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 co-ordinates 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 either is not of depth one, 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>
+/**
+ * Constructs a new cursor given a device, image and mask
+ * data describing the desired cursor appearance, and the x
+ * and y co-ordinates 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 either is not of depth one, 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();
@@ -280,10 +280,10 @@ public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int
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.
+/**
+ * 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) OS.gdk_cursor_destroy(handle);
@@ -292,15 +292,15 @@ public void dispose() {
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
+/**
+ * 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;
@@ -332,39 +332,39 @@ public static Cursor gtk_new(Device device, int handle) {
return cursor;
}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects which 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
+/**
+ * Returns an integer hash code for the receiver. Any two
+ * objects which 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
+/**
+ * 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
+/**
+ * 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*}";
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
index 622db39b11..9144cb18fe 100644
--- 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
@@ -11,11 +11,11 @@ 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.
+/**
+ * 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 {
@@ -83,17 +83,17 @@ static Device getDevice () {
return device;
}
-/**
- * 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
+/**
+ * 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) {
if (data != null) {
@@ -118,15 +118,15 @@ protected void checkDevice () {
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
+/**
+ * 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;
@@ -153,32 +153,32 @@ void dispose_Object (Object object) {
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>
+/**
+ * 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
+/**
+ * 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();
@@ -203,68 +203,68 @@ public DeviceData getDeviceData () {
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
+/**
+ * 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>
+/**
+ * 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>
+/**
+ * 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 true if scalable fonts should be returned.
- * @return the matching font data
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * 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 true if scalable fonts should be 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 ();
@@ -309,23 +309,23 @@ public FontData[] getFontList (String faceName, boolean scalable) {
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_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see SWT
+/**
+ * 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_DEVICE_DISPOSED - if the receiver has been disposed</li>
+ * </ul>
+ *
+ * @see SWT
*/
public Color getSystemColor (int id) {
checkDevice ();
@@ -350,41 +350,41 @@ public Color getSystemColor (int id) {
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 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_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * 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_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>
+/**
+ * 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 ();
@@ -426,49 +426,49 @@ protected void init () {
COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF);
}
-/**
- * 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
- *
- * @private
+/**
+ * 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
+ *
+ * @private
*/
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 handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
+/**
+ * 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 handle the platform specific GC handle
+ * @param data the platform specific GC data
+ *
+ * @private
*/
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
+/**
+ * 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;
@@ -532,17 +532,17 @@ protected void release () {
logProc = 0;
}
-/**
- * If the underlying window system supports printing warning messages
- * to the console, setting warnings to <code>true</code> prevents these
- * messages from being printed. If the argument is <code>false</code>
- * message printing is not blocked.
- *
- * @param warnings <code>true</code>if warnings should be handled, and <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * If the underlying window system supports printing warning messages
+ * to the console, setting warnings to <code>true</code> prevents these
+ * messages from being printed. If the argument is <code>false</code>
+ * message printing is not blocked.
+ *
+ * @param warnings <code>true</code>if warnings should be handled, 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/gtk/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java
index dca0c2d364..edbaea1494 100644
--- 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
@@ -11,23 +11,23 @@ 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
+/**
+ * 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 {
- /**
- * the handle to the OS font resource
- * (Warning: This field is platform dependent)
+ /**
+ * the handle to the OS font resource
+ * (Warning: This field is platform dependent)
*/
public int handle;
@@ -39,23 +39,23 @@ public final class Font {
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>
+/**
+ * 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();
@@ -96,27 +96,27 @@ public Font(Device device, FontData[] 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>
+/**
+ * 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();
@@ -125,10 +125,10 @@ public Font(Device device, String name, int height, int 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.
+/**
+ * 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) OS.pango_font_description_free(handle);
@@ -137,15 +137,15 @@ public void dispose() {
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
+/**
+ * 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;
@@ -153,17 +153,17 @@ public boolean equals(Object object) {
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>
+/**
+ * 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);
@@ -213,15 +213,15 @@ public static Font gtk_new(Device device, int handle) {
return font;
}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects which 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
+/**
+ * Returns an integer hash code for the receiver. Any two
+ * objects which 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;
@@ -251,25 +251,25 @@ void init(Device device, String name, int height, int style, byte[] fontString)
}
}
-/**
- * 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
+/**
+ * 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
+/**
+ * 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*}";
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
index e725a5e473..28788204a2 100644
--- 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
@@ -1,77 +1,77 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe operating system fonts.
- * Only the public API of this type is platform independent.
- * <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
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public final class FontData {
- /**
- * the font name
- * (Warning: This field is platform dependent)
+
+import org.eclipse.swt.*;
+
+/**
+ * Instances of this class describe operating system fonts.
+ * Only the public API of this type is platform independent.
+ * <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)
*/
- public String name;
-
- /**
- * The height of the font data in points
- * (Warning: This field is platform dependent)
+ public String name;
+
+ /**
+ * The height of the font data in points
+ * (Warning: This field is platform dependent)
*/
- public int height;
-
- /**
- * the font style
- * (Warning: This field is platform dependent)
+ public int height;
+
+ /**
+ * the font style
+ * (Warning: This field is platform dependent)
*/
- public int style;
-
- /**
- * the Pango string
- * (Warning: This field is platform dependent)
+ public int style;
+
+ /**
+ * the Pango string
+ * (Warning: This field is platform dependent)
*/
- public byte[] string;
-
- /**
- * The locales of the font
- * (Warning: These fields are platform dependent)
+ public byte[] string;
+
+ /**
+ * The locales of the font
+ * (Warning: These fields are platform dependent)
*/
- String lang, country, variant;
-
+ String lang, country, variant;
+
/**
* Constructs a new un-initialized font data.
*/
-public FontData () {
- this("", 12, SWT.NORMAL);
-}
-
+public FontData () {
+ this("", 12, SWT.NORMAL);
+}
+
/**
* Constructs a new FontData given a string representation
* in the form generated by the <code>FontData.toString</code>
@@ -91,61 +91,61 @@ public FontData () {
*
* @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;
- }
-}
-
+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,
@@ -160,66 +160,66 @@ public FontData(String string) {
* <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 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 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 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 int getHeight() {
+ return height;
+}
+
+/**
+ * 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 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;
-}
-
+public int getStyle() {
+ return style;
+}
+
/**
* Returns an integer hash code for the receiver. Any two
* objects which return <code>true</code> when passed to
@@ -230,10 +230,10 @@ public int getStyle() {
*
* @see #equals
*/
-public int hashCode () {
- return name.hashCode() ^ height ^ style;
-}
-
+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
@@ -247,49 +247,49 @@ public int hashCode () {
*
* @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 which 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 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 which 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);
- }
-}
-
+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>
@@ -315,12 +315,12 @@ public void setLocale(String locale) {
*
* @see #getName
*/
-public void setName(String name) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.name = name;
- this.string = null;
-}
-
+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>
@@ -330,11 +330,11 @@ public void setName(String name) {
*
* @see #getStyle
*/
-public void setStyle(int style) {
- this.style = style;
- this.string = null;
-}
-
+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
@@ -344,17 +344,17 @@ public void setStyle(int style) {
*
* @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();
-}
-
-}
+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
index ca8787fbe6..5a65657044 100644
--- 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
@@ -1,12 +1,12 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
/**
* Instances of this class provide measurement information
* about fonts including ascent, descent, height, leading
@@ -16,12 +16,12 @@ package org.eclipse.swt.graphics;
*
* @see GC#getFontMetrics
*/
-public final class FontMetrics {
- int ascent, descent, averageCharWidth, leading, height;
-
-FontMetrics() {
-}
-
+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
@@ -32,15 +32,15 @@ FontMetrics() {
*
* @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;
-}
-
+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
@@ -49,20 +49,20 @@ public boolean equals (Object object) {
*
* @return the ascent of the font
*/
-public int getAscent() {
- return ascent;
-}
-
+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;
-}
-
+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
@@ -71,10 +71,10 @@ public int getAverageCharWidth() {
*
* @return the descent of the font
*/
-public int getDescent() {
- return descent;
-}
-
+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
@@ -86,10 +86,10 @@ public int getDescent() {
* @see #getDescent
* @see #getLeading
*/
-public int getHeight() {
- return height;
-}
-
+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
@@ -97,10 +97,10 @@ public int getHeight() {
*
* @return the leading space of the font
*/
-public int getLeading() {
- return leading;
-}
-
+public int getLeading() {
+ return leading;
+}
+
/**
* Returns an integer hash code for the receiver. Any two
* objects which return <code>true</code> when passed to
@@ -111,8 +111,8 @@ public int getLeading() {
*
* @see #equals
*/
-public int hashCode() {
- return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
-}
-
-}
+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
index 5df563ea03..e043ae233a 100644
--- 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
@@ -11,24 +11,24 @@ 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>.
- * <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>
- *
- * @see org.eclipse.swt.events.PaintEvent
+/**
+ * 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>.
+ * <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>
+ *
+ * @see org.eclipse.swt.events.PaintEvent
*/
public final class GC {
- /**
- * the handle to the OS device context
- * (Warning: This field is platform dependent)
+ /**
+ * the handle to the OS device context
+ * (Warning: This field is platform dependent)
*/
public int handle;
@@ -38,26 +38,26 @@ public final class GC {
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>
+/**
+ * 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) {
if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
@@ -71,20 +71,20 @@ public GC(Drawable drawable) {
if (device.tracking) device.new_Object(this);
}
-/**
- * Copies a rectangular area of the receiver at the specified
- * position into the image, which must be of type <code>SWT.BITMAP</code>.
- *
- * @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>
+/**
+ * Copies a rectangular area of the receiver at the specified
+ * position into the image, which must be of type <code>SWT.BITMAP</code>.
+ *
+ * @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);
@@ -98,20 +98,20 @@ public void copyArea(Image image, int x, int y) {
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>
+/**
+ * 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) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
@@ -156,10 +156,10 @@ public void copyArea(int srcX, int srcY, int width, int height, int destX, int d
}
}
-/**
- * Disposes of the operating system resources associated with
- * the graphics context. Applications must dispose of all GCs
- * which they allocate.
+/**
+ * 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;
@@ -192,37 +192,37 @@ public void dispose() {
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 IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * 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 IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.</li>
+ * </ul>
+ * @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 endAngle) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
@@ -240,22 +240,22 @@ public void drawArc(int x, int y, int width, int height, int startAngle, int end
OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, startAngle * 64, endAngle * 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
+/**
+ * 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
*/
public void drawFocus(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
@@ -278,24 +278,24 @@ public void drawFocus(int x, int y, int width, int height) {
OS.gdk_gc_set_foreground(handle, color);
}
-/**
- * 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 SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * 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 SWTError <ul>
+ * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
+ * </ul>
*/
public void drawImage(Image image, int x, int y) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
@@ -304,37 +304,37 @@ public void drawImage(Image image, int x, int y) {
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 SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * 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 SWTError <ul>
+ * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</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);
@@ -482,44 +482,44 @@ int scale(int src, int srcX, int srcY, int srcWidth, int srcHeight, int destWidt
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>
+/**
+ * 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);
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>
+/**
+ * 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);
@@ -534,44 +534,44 @@ public void drawOval(int x, int y, int width, int height) {
OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, 0, 23040);
}
-/**
- * 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>
+/**
+ * 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);
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>
+/**
+ * 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);
@@ -579,20 +579,20 @@ public void drawPolyline(int[] pointArray) {
OS.gdk_draw_lines(data.drawable, handle, pointArray, pointArray.length / 2);
}
-/**
- * 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>
+/**
+ * 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);
@@ -607,44 +607,44 @@ public void drawRectangle(int x, int y, int width, int height) {
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>
+/**
+ * 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.
- *
- * @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 horizontal diameter of the arc at the four corners
- * @param arcHeight the vertical diameter of the arc at the four corners
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * 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.
+ *
+ * @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 horizontal diameter of the arc at the four corners
+ * @param arcHeight the vertical diameter of the arc at the four corners
+ *
+ * @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);
@@ -700,46 +700,46 @@ public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth
}
}
-/**
- * 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>
+/**
+ * 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>
+/**
+ * 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);
@@ -751,47 +751,47 @@ public void drawString(String string, int x, int y, boolean isTransparent) {
OS.gdk_draw_layout(data.drawable, handle, x, y, layout);
}
-/**
- * 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>
+/**
+ * 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>
+/**
+ * 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;
@@ -799,39 +799,39 @@ public void drawText(String string, int x, int y, boolean isTransparent) {
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>
+/**
+ * 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);
@@ -843,15 +843,15 @@ public void drawText (String string, int x, int y, int flags) {
OS.gdk_draw_layout(data.drawable, handle, x, y, layout);
}
-/**
- * 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
+/**
+ * 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;
@@ -859,40 +859,40 @@ public boolean equals(Object object) {
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 IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawArc
+/**
+ * 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 IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.</li>
+ * </ul>
+ * @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 endAngle) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
@@ -917,25 +917,25 @@ public void fillArc(int x, int y, int width, int height, int startAngle, int end
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
+/**
+ * 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
*/
public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
@@ -975,21 +975,21 @@ public void fillGradientRectangle(int x, int y, int width, int height, boolean v
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
+/**
+ * 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);
@@ -1011,24 +1011,24 @@ public void fillOval(int x, int y, int width, int height) {
OS.gdk_gc_set_foreground(handle, color);
}
-/**
- * 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
+/**
+ * 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);
@@ -1043,20 +1043,20 @@ public void fillPolygon(int[] pointArray) {
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
+/**
+ * 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
*/
public void fillRectangle(int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
@@ -1078,20 +1078,20 @@ public void fillRectangle(int x, int y, int width, int height) {
OS.gdk_gc_set_foreground(handle, color);
}
-/**
- * Fills the interior of the specified rectangle, using the receiver's
- * background color.
- *
- * @param rectangle 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
+/**
+ * Fills the interior of the specified rectangle, using the receiver's
+ * background color.
+ *
+ * @param rectangle 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
*/
public void fillRectangle(Rectangle rect) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
@@ -1099,22 +1099,22 @@ public void fillRectangle(Rectangle rect) {
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 horizontal diameter of the arc at the four corners
- * @param arcHeight the vertical diameter of the arc at the four corners
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @see #drawRoundRectangle
+/**
+ * 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 horizontal diameter of the arc at the four corners
+ * @param arcHeight the vertical diameter of the arc at the four corners
+ *
+ * @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);
@@ -1176,20 +1176,20 @@ public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth
OS.gdk_gc_set_foreground(handle, color);
}
-/**
- * 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>
+/**
+ * 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);
@@ -1197,14 +1197,14 @@ public int getAdvanceWidth(char ch) {
return stringExtent(new String(new char[]{ch})).x;
}
-/**
- * Returns the background color.
- *
- * @return the receiver's background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * 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);
@@ -1217,21 +1217,21 @@ public Color getBackground() {
return Color.gtk_new(data.device, color);
}
-/**
- * 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>
+/**
+ * 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);
@@ -1239,17 +1239,17 @@ public int getCharWidth(char ch) {
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>
+/**
+ * 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);
@@ -1264,18 +1264,18 @@ public Rectangle getClipping() {
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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * 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>
+ * </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);
@@ -1294,31 +1294,31 @@ public void getClipping(Region region) {
}
OS.gdk_region_union(hRegion, clipRgn);
}
-/**
- * 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>
+/**
+ * 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>
+/**
+ * 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);
@@ -1334,14 +1334,14 @@ public FontMetrics getFontMetrics() {
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>
+/**
+ * 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);
@@ -1354,34 +1354,34 @@ public Color getForeground() {
return Color.gtk_new(data.device, color);
}
-/**
- * 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>
+/**
+ * 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>
+/**
+ * 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);
@@ -1390,19 +1390,19 @@ public int getLineWidth() {
return values.line_width;
}
-/**
- * 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>
+/**
+ * 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);
@@ -1411,19 +1411,19 @@ public boolean getXORMode() {
return values.function == OS.GDK_XOR;
}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects which 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
+/**
+ * Returns an integer hash code for the receiver. Any two
+ * objects which 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;
@@ -1460,53 +1460,53 @@ void init(Drawable drawable, GCData data, int gdkGC) {
handle = gdkGC;
}
-/**
- * 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>
+/**
+ * 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
+/**
+ * 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 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>
+/**
+ * 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);
@@ -1515,19 +1515,19 @@ public void setBackground(Color color) {
OS.gdk_gc_set_background(handle, color.handle);
}
-/**
- * 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>
+/**
+ * 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);
@@ -1543,16 +1543,16 @@ public void setClipping(int x, int y, int width, int height) {
OS.gdk_gc_set_clip_rectangle(handle, rect);
OS.gdk_region_union_with_rect(clipRgn, rect);
}
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the argument.
- *
- * @param rect the clipping rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * Sets the area of the receiver which can be changed
+ * by drawing operations to the rectangular area specified
+ * by the argument.
+ *
+ * @param rect the clipping rectangle
+ *
+ * @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);
@@ -1567,16 +1567,16 @@ public void setClipping(Rectangle rect) {
}
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.
- *
- * @param rect the clipping region.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * Sets the area of the receiver which can be changed
+ * by drawing operations to the region specified
+ * by the argument.
+ *
+ * @param rect the clipping region.
+ *
+ * @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);
@@ -1598,20 +1598,20 @@ public void setClipping(Region region) {
}
}
-/**
- * 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>
+/**
+ * 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);
@@ -1621,19 +1621,19 @@ public void setFont(Font font) {
OS.pango_layout_set_font_description(data.layout, fontHandle);
}
-/**
- * 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>
+/**
+ * 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);
@@ -1642,17 +1642,17 @@ public void setForeground(Color color) {
OS.gdk_gc_set_foreground(handle, color.handle);
}
-/**
- * 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 SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * 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 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);
@@ -1680,17 +1680,17 @@ public void setLineStyle(int lineStyle) {
OS.gdk_gc_set_line_attributes(handle, 0, OS.GDK_LINE_ON_OFF_DASH, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER);
}
-/**
- * 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.
- *
- * @param lineWidth the width of a line
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+/**
+ * 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.
+ *
+ * @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 width) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
@@ -1701,43 +1701,43 @@ public void setLineWidth(int width) {
}
}
-/**
- * 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.
- *
- * @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>
+/**
+ * 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.
+ *
+ * @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>
*/
public void setXORMode(boolean val) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
OS.gdk_gc_set_function(handle, val ? OS.GDK_XOR : OS.GDK_COPY);
}
-/**
- * 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>
+/**
+ * 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);
@@ -1752,59 +1752,59 @@ public Point stringExtent(String string) {
return new Point(OS.PANGO_PIXELS(width[0]), OS.PANGO_PIXELS(height[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>
+/**
+ * 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>
+/**
+ * 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);
@@ -1819,11 +1819,11 @@ public Point textExtent(String string, int flags) {
return new Point(OS.PANGO_PIXELS(width[0]), OS.PANGO_PIXELS(height[0]));
}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
+/**
+ * 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*}";
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
index e3fd3d689c..620d611c0f 100644
--- 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
@@ -1,36 +1,36 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- *
- * @private
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public final class GCData {
- public Device device;
- public Image image;
- public int drawable;
- public GdkColor foreground;
- public GdkColor background;
- public int font;
- public int context;
- public int layout;
- public int clipRgn;
- public int lineStyle = SWT.LINE_SOLID;
+
+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>
+ *
+ * @private
+ */
+public final class GCData {
+ public Device device;
+ public Image image;
+ public int drawable;
+ public GdkColor foreground;
+ public GdkColor background;
+ public int font;
+ public int context;
+ public int layout;
+ public int clipRgn;
+ public int lineStyle = SWT.LINE_SOLID;
}
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
index ae7658aae8..871e2b6e57 100644
--- 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
@@ -11,58 +11,58 @@ 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 explicitely 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
+/**
+ * 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 explicitely 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 implements Drawable{
- /**
- * specifies whether the receiver is a bitmap or an icon
- * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
+ /**
+ * specifies whether the receiver is a bitmap or an icon
+ * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
*/
public int type;
@@ -116,35 +116,35 @@ public final class Image implements Drawable{
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>
+/**
+ * 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();
@@ -153,36 +153,36 @@ public Image(Device device, int width, int 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>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
+/**
+ * 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>
+ * </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();
@@ -322,35 +322,35 @@ public Image(Device device, Image srcImage, int flag) {
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>
+/**
+ * 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();
@@ -360,20 +360,20 @@ public Image(Device device, Rectangle bounds) {
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 SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
+/**
+ * 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 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();
@@ -382,34 +382,34 @@ public Image(Device device, ImageData 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, and the mask image
- * must have a color depth of 1. Pixel transparency in either image
- * will be ignored. If either image is an icon to begin with, an
- * exception is thrown.
- * <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 or
- * if the mask is not monochrome, or if either the source or mask
- * is already an icon</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
+/**
+ * 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, and the mask image
+ * must have a color depth of 1. Pixel transparency in either image
+ * will be ignored. If either image is an icon to begin with, an
+ * exception is thrown.
+ * <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 or
+ * if the mask is not monochrome, or if either the source or mask
+ * is already an icon</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();
@@ -427,37 +427,37 @@ public Image(Device device, ImageData source, ImageData 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.
- * <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>
- * new Image(device, clazz.getResourceAsStream("file.gif"));
- * </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_INVALID_IMAGE - if the image file contains invalid data </li>
- * <li>ERROR_IO - if an IO error occurs while reading data</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
+/**
+ * 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.
+ * <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>
+ * new Image(device, clazz.getResourceAsStream("file.gif"));
+ * </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_INVALID_IMAGE - if the image file contains invalid data </li>
+ * <li>ERROR_IO - if an IO error occurs while reading data</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();
@@ -466,30 +466,30 @@ public Image(Device device, InputStream 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_INVALID_IMAGE - if the image file contains invalid data </li>
- * <li>ERROR_IO - if an IO error occurs while reading data</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
- * </ul>
+/**
+ * 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_INVALID_IMAGE - if the image file contains invalid data </li>
+ * <li>ERROR_IO - if an IO error occurs while reading data</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();
@@ -525,10 +525,10 @@ void destroyMask() {
mask = 0;
}
-/**
- * Disposes of the operating system resources associated with
- * the image. Applications must dispose of all images which
- * they allocate.
+/**
+ * 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;
@@ -541,15 +541,15 @@ public void dispose () {
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
+/**
+ * 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;
@@ -558,23 +558,23 @@ public boolean equals (Object 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>
+/**
+ * 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);
@@ -583,17 +583,17 @@ public Color getBackground() {
return null;
}
-/**
- * Returns the bounds of the receiver. The rectangle will always
- * have x and y values of 0, and the width and height of the
- * image.
- *
- * @return a rectangle specifying the image's bounds
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li>
- * </ul>
+/**
+ * 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);
@@ -602,19 +602,19 @@ public Rectangle getBounds() {
return new Rectangle(0, 0, width[0], height[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
+/**
+ * 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);
@@ -693,15 +693,15 @@ public static Image gtk_new(Device device, int type, int pixmap, int mask) {
return image;
}
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects which 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
+/**
+ * Returns an integer hash code for the receiver. Any two
+ * objects which 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;
@@ -838,20 +838,20 @@ void init(Device device, ImageData image) {
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
- *
- * @private
+/**
+ * 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
+ *
+ * @private
*/
public int internal_new_GC (GCData data) {
if (pixmap == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
@@ -868,72 +868,72 @@ public int internal_new_GC (GCData data) {
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 handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
+/**
+ * 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 handle the platform specific GC handle
+ * @param data the platform specific GC data
+ *
+ * @private
*/
public void internal_dispose_GC (int 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
+/**
+ * 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>
+/**
+ * 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);
@@ -943,11 +943,11 @@ public void setBackground(Color color) {
//NOT DONE
}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
+/**
+ * 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*}";
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
index bed035b3c6..7cd5011b3c 100644
--- 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
@@ -1,283 +1,283 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 rectangles.
- * <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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public final class Region {
- /**
- * the OS resource for the region
- * (Warning: This field is platform dependent)
+
+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 rectangles.
+ * <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 {
+ /**
+ * the OS resource for the region
+ * (Warning: This field is platform dependent)
*/
- 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 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() {
- handle = OS.gdk_region_new();
-}
-
-Region(int handle) {
- this.handle = handle;
-}
-
-/**
- * Adds the given rectangle to the collection of rectangles
- * 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 Region() {
+ handle = OS.gdk_region_new();
+}
+
+Region(int handle) {
+ this.handle = handle;
+}
+
+/**
+ * Adds the given rectangle to the collection of rectangles
+ * the receiver maintains to describe its area.
+ *
+ * @param rect the rectangle to merge with the receiver
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
+ * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
+ * </ul>
*/
-public void add(Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- GdkRectangle gdkRect = new GdkRectangle();
- gdkRect.x = rect.x;
- gdkRect.y = rect.y;
- gdkRect.width = rect.width;
- gdkRect.height = rect.height;
- OS.gdk_region_union_with_rect(handle, gdkRect);
-}
-
-/**
- * Adds all of the rectangles which make up the area covered
- * by the argument to the collection of rectangles 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(Rectangle rect) {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ GdkRectangle gdkRect = new GdkRectangle();
+ gdkRect.x = rect.x;
+ gdkRect.y = rect.y;
+ gdkRect.width = rect.width;
+ gdkRect.height = rect.height;
+ OS.gdk_region_union_with_rect(handle, gdkRect);
+}
+
+/**
+ * Adds all of the rectangles which make up the area covered
+ * by the argument to the collection of rectangles 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 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(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 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) OS.gdk_region_destroy(handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
+public void dispose() {
+ if (handle != 0) OS.gdk_region_destroy(handle);
+ handle = 0;
+}
+
+/**
+ * Compares the argument to the receiver, and returns true
+ * if they represent the <em>same</em> object using a class
+ * specific comparison.
+ *
+ * @param object the object to compare with this object
+ * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
+ *
+ * @see #hashCode
*/
-public boolean equals(Object object) {
- if (this == object) return true;
- if (!(object instanceof Region)) return false;
- Region region = (Region)object;
- return handle == region.handle;
-}
-
-/**
- * Returns a rectangle which represents the rectangular
- * union of the collection of rectangles 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 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 rectangles 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(int handle) {
- return new Region(handle);
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects which 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 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(int handle) {
+ return new Region(handle);
+}
+
+/**
+ * Returns an integer hash code for the receiver. Any two
+ * objects which 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 rectangle described by the
- * arguments intersects with any of the rectangles the receiver
- * mainains 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
+public int hashCode() {
+ return handle;
+}
+
+/**
+ * Returns <code>true</code> if the rectangle described by the
+ * arguments intersects with any of the rectangles the receiver
+ * mainains 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
*/
-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 rectangles the receiver mainains 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
+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 rectangles the receiver mainains 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
*/
-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 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 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);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
+public boolean isEmpty() {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ return OS.gdk_region_empty(handle);
+}
+
+/**
+ * Returns a string containing a concise, human-readable
+ * description of the receiver.
+ *
+ * @return a string representation of the receiver
*/
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
-}
+public String toString () {
+ if (isDisposed()) return "Region {*DISPOSED*}";
+ return "Region {" + handle + "}";
+}
+}
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
index 2e267e5b84..855722553b 100644
--- 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
@@ -1,14 +1,14 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.gtk.OS;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.gtk.OS;
+
/**
* This class implements the conversions between unicode characters
* and the <em>platform supported</em> representation for characters.
@@ -16,51 +16,51 @@ import org.eclipse.swt.internal.gtk.OS;
* 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];
-
+ */
+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 [] items_written = new int [1];
- int ptr = OS.g_utf8_to_utf16 (buffer, buffer.length, null, items_written, null);
- if (ptr == 0) return EmptyCharArray;
- int length = 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 [] items_read = new int [1], items_written = new int [1];
- int ptr = OS.g_utf16_to_utf8 (buffer, buffer.length, items_read, items_written, null);
- if (ptr == 0) return terminate ? NullByteArray : EmptyByteArray;
- int written = items_written [0];
- //TEMPORARY CODE - convertion stops at the first NULL
- if (items_read [0] != buffer.length && !terminate) written++;
- byte [] bytes = new byte [written + (terminate ? 1 : 0)];
- OS.memmove (bytes, ptr, written);
- OS.g_free (ptr);
- return bytes;
-}
-
-}
+public static String defaultCodePage () {
+ return "UTF8";
+}
+
+public static char [] mbcsToWcs (String codePage, byte [] buffer) {
+ int [] items_written = new int [1];
+ int ptr = OS.g_utf8_to_utf16 (buffer, buffer.length, null, items_written, null);
+ if (ptr == 0) return EmptyCharArray;
+ int length = 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 [] items_read = new int [1], items_written = new int [1];
+ int ptr = OS.g_utf16_to_utf8 (buffer, buffer.length, items_read, items_written, null);
+ if (ptr == 0) return terminate ? NullByteArray : EmptyByteArray;
+ int written = items_written [0];
+ //TEMPORARY CODE - convertion stops at the first NULL
+ if (items_read [0] != buffer.length && !terminate) written++;
+ 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
index b2daae9a6c..103f152da4 100644
--- 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
@@ -13,69 +13,69 @@ 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>
+/**
+ * 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 boxHandle, labelHandle, imageHandle, arrowHandle;
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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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));
@@ -95,29 +95,29 @@ static int checkStyle (int style) {
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
+/**
+ * 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 ();
@@ -237,21 +237,21 @@ int fontHandle () {
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>
+/**
+ * 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 ();
@@ -268,16 +268,16 @@ public int getAlignment () {
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>
+/**
+ * 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 ();
@@ -288,21 +288,21 @@ 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>
+/**
+ * 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 ();
@@ -310,16 +310,16 @@ public boolean getSelection () {
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.
- *
- * @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>
+/**
+ * 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();
@@ -388,22 +388,22 @@ void releaseWidget () {
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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notified when the control is selected.
+ *
+ * @param listener the listener which should be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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();
@@ -413,21 +413,21 @@ public void removeSelectionListener (SelectionListener listener) {
eventTable.unhook (SWT.DefaultSelection,listener);
}
-/**
- * Controls how text, images and arrows will be displayed
- * in the receiver. The argument should be one of
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>
- * unless the receiver is an <code>ARROW</code> button, in
- * which case, the argument indicates the direction of
- * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>,
- * <code>UP</code> or <code>DOWN</code>).
- *
- * @param alignment the new alignment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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 ();
@@ -488,19 +488,19 @@ void setForegroundColor (GdkColor color) {
if (imageHandle != 0) OS.gtk_widget_modify_fg (imageHandle, 0, color);
}
-/**
- * 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>
+/**
+ * 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 ();
@@ -525,21 +525,21 @@ public void setImage (Image image) {
OS.gtk_widget_size_request (handle, requisition);
}
-/**
- * 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>
+/**
+ * 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();
@@ -549,22 +549,22 @@ public void setSelection (boolean 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>
- *
- * @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>
+/**
+ * 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>
+ *
+ * @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 ();
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
index 5a9bc9b21b..c8e88faf06 100644
--- 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
@@ -11,79 +11,79 @@ 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
+/**
+ * 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>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 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>
+/**
+ * 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();
@@ -128,27 +128,27 @@ void releaseWidget () {
super.releaseWidget();
}
-/**
- * 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>
+/**
+ * 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();
@@ -233,25 +233,25 @@ boolean setBounds (int x, int y, int width, int height, boolean move, boolean re
return changed;
}
-/**
- * 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>
+/**
+ * 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();
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
index 496e49749d..f7a7abf241 100644
--- 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
@@ -11,19 +11,19 @@ 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>
+/**
+ * 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;
@@ -33,33 +33,33 @@ public class Caret extends Widget {
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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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);
@@ -108,16 +108,16 @@ boolean drawCaret () {
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>
+/**
+ * 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();
@@ -134,15 +134,15 @@ public Display getDisplay () {
return parent.getDisplay ();
}
-/**
- * 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>
+/**
+ * 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();
@@ -150,61 +150,61 @@ public Font getFont () {
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>
+/**
+ * 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>
+/**
+ * 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>
+/**
+ * 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>
+/**
+ * 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();
@@ -215,22 +215,22 @@ public Point getSize () {
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>
+/**
+ * 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();
@@ -290,21 +290,21 @@ void releaseWidget () {
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>
+/**
+ * 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();
@@ -317,18 +317,18 @@ public void setBounds (int x, int y, int width, int height) {
if (isFocus) 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>
+/**
+ * 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();
@@ -343,20 +343,20 @@ void setFocus () {
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>
+/**
+ * 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();
@@ -366,20 +366,20 @@ public void setFont (Font font) {
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 font the new font (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>
+/**
+ * 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 font the new font (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();
@@ -392,35 +392,35 @@ public void setImage (Image image) {
if (isFocus) 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>
+/**
+ * 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>
+/**
+ * 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();
@@ -428,35 +428,35 @@ public void setLocation (Point location) {
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>
+/**
+ * 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
- * @param height the new height 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>
+/**
+ * Sets the receiver's size to the point specified by the argument.
+ *
+ * @param size the new extent for the receiver
+ * @param height the new height 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();
@@ -464,21 +464,21 @@ public void setSize (Point size) {
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>
+/**
+ * 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();
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
index 9c2b3c5733..1349f4aaac 100644
--- 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
@@ -1,147 +1,147 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-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 (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
- * @see Widget#checkSubclass
- * @see Widget#getStyle
+
+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 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 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 (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
+ * @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 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 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 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 open () {
- byte [] buffer = Converter.wcsToMbcs (null, title, true);
- int handle = OS.gtk_color_selection_dialog_new (buffer);
- if (parent!=null) {
- OS.gtk_window_set_transient_for(handle, parent.topHandle());
- }
- 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);
- }
- 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;
-}
-/**
- * Returns 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 to select a default when
- * open() is called
- *
- * @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 void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-}
+public RGB open () {
+ byte [] buffer = Converter.wcsToMbcs (null, title, true);
+ int handle = OS.gtk_color_selection_dialog_new (buffer);
+ if (parent!=null) {
+ OS.gtk_window_set_transient_for(handle, parent.topHandle());
+ }
+ 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);
+ }
+ 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;
+}
+/**
+ * Returns 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 to 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
index f95acf6d97..f9b32b7f84 100644
--- 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
@@ -13,48 +13,48 @@ 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
+/**
+ * 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 arrowHandle, entryHandle, listHandle;
String [] items = new String [0];
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
+ /**
+ * 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;
@@ -67,57 +67,57 @@ public class Combo extends Composite {
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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- *
- * @see #add(String,int)
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ *
+ * @see #add(String,int)
*/
public void add (String string) {
checkWidget();
@@ -128,31 +128,31 @@ public void add (String string) {
setItems (newItems, true, 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- *
- * @see #add(String)
+/**
+ * Adds the argument to the receiver's list at the given
+ * zero-relative index.
+ * <p>
+ * Note: To add an item at the end of the list, use the
+ * result of calling <code>getItemCount()</code> as the
+ * index or use <code>add(String)</code>.
+ * </p>
+ *
+ * @param string the new item
+ * @param index the index for the item
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
+ * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ *
+ * @see #add(String)
*/
public void add (String string, int index) {
checkWidget();
@@ -167,24 +167,24 @@ public void add (String string, int index) {
setItems (newItems, true, 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
+/**
+ * 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();
@@ -193,29 +193,29 @@ public void addModifyListener (ModifyListener 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
+/**
+ * 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();
@@ -253,22 +253,22 @@ static int checkStyle (int style) {
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
+/**
+ * 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();
@@ -452,36 +452,36 @@ void hookEvents () {
}
}
-/**
- * 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>
+/**
+ * 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();
setItems (items, true, getSelectionIndex () != index);
}
-/**
- * Deselects all selected items in the receiver's list.
- * <p>
- * Note: To clear the selection in the receiver's text field,
- * use <code>clearSelection()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #clearSelection
+/**
+ * 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();
@@ -500,24 +500,24 @@ 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public String getItem (int index) {
checkWidget();
@@ -527,61 +527,61 @@ public String getItem (int index) {
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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public int getItemHeight () {
checkWidget();
return fontHeight (getFontDescription (), listHandle != 0 ? listHandle : handle);
}
-/**
- * Returns an 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * Returns an 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public String [] getItems () {
checkWidget();
@@ -590,19 +590,19 @@ public String [] getItems () {
return result;
}
-/**
- * Returns a <code>Point</code> whose x coordinate is the start
- * of the selection in the receiver's text field, and whose y
- * coordinate is the end of the selection. The returned values
- * are zero-relative. An "empty" selection as indicated by
- * the the x and y coordinates having the same value.
- *
- * @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>
+/**
+ * Returns a <code>Point</code> whose x coordinate is the start
+ * of the selection in the receiver's text field, and whose y
+ * coordinate is the end of the selection. The returned values
+ * are zero-relative. An "empty" selection as indicated by
+ * the the x and y coordinates having the same value.
+ *
+ * @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 ();
@@ -612,16 +612,16 @@ public Point getSelection () {
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>
+/**
+ * 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();
@@ -629,16 +629,16 @@ public int getSelectionIndex () {
return indexOf (getText ());
}
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field.
- *
- * @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>
+/**
+ * Returns a string containing a copy of the contents of the
+ * receiver's text field.
+ *
+ * @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();
@@ -658,36 +658,36 @@ String getText (int start, int stop) {
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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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>
+/**
+ * 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>
*/
public int getTextLimit () {
checkWidget();
@@ -710,45 +710,45 @@ int gtk_select_child (int list, int widget) {
return 0;
}
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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
- * @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>
+/**
+ * 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
+ * @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();
@@ -794,22 +794,22 @@ void releaseHandle () {
entryHandle = listHandle = 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public void remove (int index) {
checkWidget();
@@ -823,24 +823,24 @@ public void remove (int index) {
setItems (newItems, true, 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public void remove (int start, int end) {
checkWidget();
@@ -854,24 +854,24 @@ public void remove (int start, int end) {
setItems (newItems, true, 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public void remove (String string) {
checkWidget();
@@ -880,35 +880,35 @@ public void remove (String string) {
remove (index);
}
-/**
- * Removes all of the items from the receiver's list.
- * <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>
+/**
+ * Removes all of the items from the receiver's list.
+ * <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();
setItems (new String [0], false, 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
+/**
+ * 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();
@@ -917,22 +917,22 @@ public void removeModifyListener (ModifyListener listener) {
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
+/**
+ * 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();
@@ -942,17 +942,17 @@ public void removeSelectionListener (SelectionListener 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>
+/**
+ * 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();
@@ -983,26 +983,26 @@ void setForegroundColor (GdkColor color) {
if (listHandle != 0) OS.gtk_widget_modify_text (listHandle, 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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
- * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
+ * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</li>
+ * </ul>
*/
public void setItem (int index, String string) {
checkWidget();
@@ -1014,18 +1014,18 @@ public void setItem (int index, String string) {
setItems (items, true, true);
}
-/**
- * Sets the receiver's list to be the given array of items.
- *
- * @param items the array 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * Sets the receiver's list to be the given array of items.
+ *
+ * @param items the array 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public void setItems (String [] items) {
checkWidget();
@@ -1090,21 +1090,21 @@ void setItems (String [] items, boolean keepText, boolean keepSelection) {
if (!keepText) OS.gtk_editable_delete_text (entryHandle, 0, -1);
}
-/**
- * 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 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>
+/**
+ * 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 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();
@@ -1113,26 +1113,26 @@ public void setSelection (Point selection) {
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 text 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>
+/**
+ * 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 text 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();
@@ -1143,19 +1143,19 @@ public void setText (String string) {
OS.g_signal_handlers_unblock_matched (listHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SELECT_CHILD);
}
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- *
- * @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>
+/**
+ * Sets the maximum number of characters that the receiver's
+ * text field is capable of holding to be the argument.
+ *
+ * @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>
*/
public void setTextLimit (int limit) {
checkWidget();
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
index e37a86aced..fca3ed2854 100644
--- 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
@@ -11,28 +11,28 @@ 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</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>
- * This class may be subclassed by custom control implementors
- * who are building controls that are constructed from aggregates
- * of other controls.
- * </p>
- *
- * @see Canvas
+/**
+ * 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</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>
+ * 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 {
int radioHandle, imHandle;
@@ -43,35 +43,35 @@ 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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. 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);
@@ -104,23 +104,23 @@ Control [] _getChildren () {
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;
-}
+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;
+}
protected void checkSubclass () {
/* Do nothing - Subclassing is allowed */
@@ -244,36 +244,36 @@ public int getBorderWidth () {
return OS.gtk_container_get_border_width (topHandle);
}
-/**
- * Returns an array containing the receiver's children.
- * <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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * Returns an array containing the receiver's children.
+ * <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
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
*/
public Control [] getChildren () {
checkWidget();
return _getChildren ();
}
-/**
- * Returns layout which is associated with the receiver, or
- * null if one has not been set.
- *
- * @return the receiver's layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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();
@@ -398,39 +398,39 @@ int imHandle () {
return imHandle;
}
-/**
- * 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>
+/**
+ * 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 () {
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 the argument is <code>true</code> the layout must not rely
- * on any cached information it is keeping about the children. If it
- * is <code>false</code> the layout may (potentially) simplify the
- * work it is doing by assuming that the state of the none of the
- * receiver's children has changed since the last layout.
- * If the receiver does not have a layout, do nothing.
- *
- * @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>
+/**
+ * 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 the argument is <code>true</code> the layout must not rely
+ * on any cached information it is keeping about the children. If it
+ * is <code>false</code> the layout may (potentially) simplify the
+ * work it is doing by assuming that the state of the none of the
+ * receiver's children has changed since the last layout.
+ * If the receiver does not have a layout, do nothing.
+ *
+ * @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();
@@ -574,16 +574,16 @@ public boolean setFocus () {
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>
+/**
+ * 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();
@@ -617,20 +617,20 @@ boolean setTabItemFocus () {
return super.setTabItemFocus ();
}
-/**
- * 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>
+/**
+ * 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 ();
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
index 842909ebc0..48a06d439e 100644
--- 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
@@ -14,20 +14,20 @@ 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>
- * <dt><b>Events:</b>
- * <dd>FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+/**
+ * Control is the abstract superclass of all windowed user interface classes.
+ * <p>
+ * <dl>
+ * <dt><b>Styles:</b>
+ * <dd>BORDER</dd>
+ * <dt><b>Events:</b>
+ * <dd>FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter,
+ * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize</dd>
+ * </dl>
+ * <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 fixedHandle;
@@ -41,33 +41,33 @@ public abstract class Control extends Widget implements Drawable {
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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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);
@@ -199,32 +199,32 @@ int paintWindow () {
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
- * @see "computeTrim, getClientArea for controls that implement them"
+/**
+ * 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
+ * @see "computeTrim, getClientArea for controls that implement them"
*/
public Point computeSize (int wHint, int hHint) {
return computeSize (wHint, hHint, true);
@@ -266,39 +266,39 @@ void createWidget (int index) {
setZOrder (null, false);
}
-/**
- * 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
- * @see "computeTrim, getClientArea for controls that implement them"
+/**
+ * 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
+ * @see "computeTrim, getClientArea for controls that implement them"
*/
public Point computeSize (int wHint, int hHint, boolean changed) {
checkWidget();
@@ -317,22 +317,22 @@ Point computeNativeSize (int h, int wHint, int hHint, boolean changed) {
return new Point (width, height);
}
-/**
- * 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
+/**
+ * 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 ();
@@ -342,16 +342,16 @@ public Accessible getAccessible () {
return accessible;
}
-/**
- * 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>
+/**
+ * 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();
@@ -363,23 +363,23 @@ public Rectangle getBounds () {
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>
+/**
+ * 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 ();
@@ -387,26 +387,26 @@ public void setBounds (Rectangle rect) {
setBounds (rect.x, rect.y, rect.width, rect.height);
}
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null).
- * <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>
+/**
+ * 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).
+ * <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();
@@ -478,16 +478,16 @@ boolean setBounds (int x, int y, int width, int height, boolean move, boolean re
return !sameOrigin || !sameExtent;
}
-/**
- * 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>
+/**
+ * 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();
@@ -497,17 +497,17 @@ public Point getLocation () {
return new Point (x, y);
}
-/**
- * Sets the receiver's location to the point specified by
- * the argument which is relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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 ();
@@ -515,36 +515,36 @@ public void setLocation (Point location) {
setLocation (location.x, location.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).
- *
- * @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>
+/**
+ * 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, 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>
+/**
+ * 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();
@@ -554,24 +554,24 @@ public Point getSize () {
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
- * @param height the new height 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>
+/**
+ * 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
+ * @param height the new height 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 ();
@@ -579,43 +579,43 @@ public void setSize (Point size) {
setSize (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>
+/**
+ * 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);
}
-/**
- * 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 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>
+/**
+ * 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 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>
*/
public void moveAbove (Control control) {
checkWidget();
@@ -626,22 +626,22 @@ public void moveAbove (Control control) {
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 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>
+/**
+ * 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 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>
*/
public void moveBelow (Control control) {
checkWidget();
@@ -652,54 +652,54 @@ public void moveBelow (Control control) {
setZOrder (control, 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>
- *
- * @see #computeSize
+/**
+ * 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
*/
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>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+/**
+ * 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>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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
*/
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>
+/**
+ * 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();
@@ -715,20 +715,20 @@ public Point toControl (int x, int 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)
- *
- * @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>
+/**
+ * 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)
+ *
+ * @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 ();
@@ -745,20 +745,20 @@ public Point toDisplay (int x, int 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)
- *
- * @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>
+/**
+ * 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)
+ *
+ * @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();
@@ -766,24 +766,24 @@ public Point toDisplay (Point point) {
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
+/**
+ * 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();
@@ -793,24 +793,24 @@ public void addControlListener(ControlListener listener) {
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
+/**
+ * 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();
@@ -820,24 +820,24 @@ public void addFocusListener(FocusListener listener) {
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
+/**
+ * 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();
@@ -846,24 +846,24 @@ public void addHelpListener (HelpListener 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
+/**
+ * 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();
@@ -873,24 +873,24 @@ public void addKeyListener(KeyListener listener) {
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
+/**
+ * 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();
@@ -901,24 +901,24 @@ public void addMouseListener(MouseListener listener) {
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
+/**
+ * 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();
@@ -927,24 +927,24 @@ public void addMouseMoveListener(MouseMoveListener 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
+/**
+ * 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();
@@ -955,24 +955,24 @@ public void addMouseTrackListener (MouseTrackListener listener) {
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
+/**
+ * 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();
@@ -981,24 +981,24 @@ public void addPaintListener(PaintListener 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
+/**
+ * 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();
@@ -1007,22 +1007,22 @@ public void addTraverseListener (TraverseListener 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+/**
+ * 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
@@ -1031,22 +1031,22 @@ public void removeControlListener (ControlListener listener) {
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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+/**
+ * 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
@@ -1055,22 +1055,22 @@ public void removeFocusListener(FocusListener listener) {
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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+/**
+ * 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
@@ -1078,22 +1078,22 @@ public void removeHelpListener (HelpListener listener) {
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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+/**
+ * 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
@@ -1102,22 +1102,22 @@ public void removeKeyListener(KeyListener listener) {
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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+/**
+ * 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
@@ -1127,22 +1127,22 @@ public void removeMouseListener (MouseListener 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notified when the mouse moves.
+ *
+ * @param listener the listener which should be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
@@ -1151,22 +1151,22 @@ public void removeMouseMoveListener(MouseMoveListener listener) {
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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+/**
+ * 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
@@ -1177,22 +1177,22 @@ public void removeMouseTrackListener(MouseTrackListener 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+/**
+ * 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
@@ -1201,22 +1201,22 @@ public void removePaintListener(PaintListener listener) {
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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notified when traversal events occur.
+ *
+ * @param listener the listener which should be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 ();
@@ -1226,18 +1226,18 @@ public void removeTraverseListener(TraverseListener listener) {
}
-/**
- * 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
+/**
+ * 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();
@@ -1249,15 +1249,15 @@ public boolean forceFocus () {
return OS.gtk_widget_is_focus (handle);
}
-/**
- * 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>
+/**
+ * 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();
@@ -1292,30 +1292,30 @@ GdkColor getBaseColor () {
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>
+/**
+ * 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 the display that the receiver was created on.
- *
- * @return the receiver's 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>
+/**
+ * Returns the display that the receiver was created on.
+ *
+ * @return the receiver's 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 Display getDisplay () {
if (parent == null) {
@@ -1323,33 +1323,33 @@ public Display getDisplay () {
}
return parent.getDisplay ();
}
-/**
- * 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>
+/**
+ * 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>
*/
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>
+/**
+ * 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();
@@ -1364,15 +1364,15 @@ int getFontDescription () {
return style.font_desc;
}
-/**
- * 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>
+/**
+ * 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();
@@ -1411,51 +1411,51 @@ GdkColor getTextColor () {
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>
+/**
+ * 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>
+/**
+ * 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 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>
+/**
+ * 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();
@@ -1479,20 +1479,20 @@ Control [] getPath () {
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
+/**
+ * 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();
@@ -1502,37 +1502,37 @@ 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>
+/**
+ * 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>
+/**
+ * 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();
@@ -1778,20 +1778,20 @@ int gtk_show_help (int widget, int helpType) {
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
- *
- * @private
+/**
+ * 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
+ *
+ * @private
*/
public int internal_new_GC (GCData data) {
checkWidget ();
@@ -1826,36 +1826,36 @@ int 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 handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
+/**
+ * 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 handle the platform specific GC handle
+ * @param data the platform specific GC data
+ *
+ * @private
*/
public void internal_dispose_GC (int 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>
+/**
+ * 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();
@@ -1928,16 +1928,16 @@ boolean isFocusAncestor () {
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>
+/**
+ * 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();
@@ -1975,17 +1975,17 @@ void register () {
}
-/**
- * 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.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+/**
+ * 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.
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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
*/
public void redraw () {
checkWidget();
@@ -1994,28 +1994,28 @@ public void redraw () {
int height = OS.GTK_WIDGET_HEIGHT (paintHandle);
redrawWidget (0, 0, width, height, true);
}
-/**
- * Causes the rectangular area of the receiver specified by
- * the arguments to be marked as needing to be redrawn.
- * The next time a paint request is processed, that area of
- * the receiver will be painted. 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
+/**
+ * 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. 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
*/
public void redraw (int x, int y, int width, int height, boolean all) {
checkWidget();
@@ -2100,20 +2100,20 @@ void sendMouseEvent (int type, int button, int gdkEvent) {
postEvent (type, event);
}
-/**
- * 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>
+/**
+ * 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();
@@ -2131,17 +2131,17 @@ void setBackgroundColor (GdkColor color) {
OS.gtk_widget_modify_bg (handle, 0, color);
}
-/**
- * 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>
+/**
+ * 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();
@@ -2154,24 +2154,24 @@ public void setCapture (boolean capture) {
}
*/
}
-/**
- * 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>
+/**
+ * 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();
@@ -2186,18 +2186,18 @@ public void setCursor (Cursor cursor) {
}
}
-/**
- * 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>
+/**
+ * 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();
@@ -2213,38 +2213,38 @@ public void setEnabled (boolean enabled) {
if (fixFocus) fixFocus ();
}
-/**
- * Causes the receiver to have the <em>keyboard focus</em>,
- * such that all keyboard events will 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 #forceFocus
+/**
+ * Causes the receiver to have the <em>keyboard focus</em>,
+ * such that all keyboard events will 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 #forceFocus
*/
public boolean setFocus () {
checkWidget();
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>
+/**
+ * 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();
@@ -2263,20 +2263,20 @@ void setFontDescription (int 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>
+/**
+ * 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();
@@ -2303,25 +2303,25 @@ void setInitialSize () {
OS.gtk_container_resize_children (parentHandle);
}
-/**
- * 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.
- *
- * @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>
+/**
+ * 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.
+ *
+ * @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();
@@ -2336,21 +2336,21 @@ public void setMenu (Menu menu) {
this.menu = menu;
}
-/**
- * Changes the parent of the widget to be the one provided if
- * the underlying operating system supports this feature.
- * Answers <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>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
- * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
- * </ul>
+/**
+ * Changes the parent of the widget to be the one provided if
+ * the underlying operating system supports this feature.
+ * Answers <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>
+ * </ul>
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
*/
public boolean setParent (Composite parent) {
checkWidget();
@@ -2358,27 +2358,27 @@ public boolean setParent (Composite parent) {
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.
- * <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
- * @see #update
+/**
+ * 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.
+ * <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
+ * @see #update
*/
public void setRedraw (boolean redraw) {
checkWidget();
@@ -2392,16 +2392,16 @@ boolean setTabItemFocus () {
return setFocus ();
}
-/**
- * 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>
+/**
+ * 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();
@@ -2415,21 +2415,21 @@ public void setToolTipText (String string) {
OS.gtk_tooltips_set_tip (tooltipsHandle, handle, buffer, null);
}
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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();
@@ -2496,20 +2496,20 @@ void sort (int [] items) {
}
}
-/**
- * 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>
+/**
+ * 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 ();
@@ -2705,16 +2705,16 @@ boolean traverseMnemonic (Event event) {
return true;
}
-/**
- * Forces all outstanding paint requests for the widget tree
- * 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
+/**
+ * Forces all outstanding paint requests for the widget tree
+ * 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
*/
public void update () {
checkWidget ();
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
index 57b650e9a6..a6bb057931 100644
--- 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
@@ -1,554 +1,554 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- * 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
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class Decorations extends Canvas {
- String text;
- Image image;
- boolean minimized, maximized;
- Menu menuBar;
- Menu [] menus;
- Control savedFocus;
- Button defaultButton, saveDefault;
- int accelGroup;
-
-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
+
+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>
+ * 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 Decorations (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- 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;
-}
-
-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 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 shellHandle = topHandle ();
- OS.gtk_window_remove_accel_group (shellHandle, accelGroup);
- //TEMPORARY CODE
-// OS.g_object_unref (accelGroup);
- accelGroup = 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 class Decorations extends Canvas {
+ String text;
+ Image image;
+ boolean minimized, maximized;
+ Menu menuBar;
+ Menu [] menus;
+ Control savedFocus;
+ Button defaultButton, saveDefault;
+ int accelGroup;
+
+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 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 Decorations (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+
+static int checkStyle (int style) {
+ 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;
+}
+
+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 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 shellHandle = topHandle ();
+ OS.gtk_window_remove_accel_group (shellHandle, accelGroup);
+ //TEMPORARY CODE
+// OS.g_object_unref (accelGroup);
+ accelGroup = 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 Image getImage () {
- checkWidget();
- return image;
-}
-
-/**
- * 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 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 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 Image getImage () {
+ checkWidget();
+ return image;
+}
+
+/**
+ * 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 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 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 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 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 String getText () {
- checkWidget();
- return text;
-}
-
-boolean isTabGroup () {
- return true;
-}
-
-boolean isTabItem () {
- return false;
-}
-
-Decorations menuShell () {
- return this;
-}
-
-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 releaseWidget () {
- if (menuBar != null) menuBar.releaseResources ();
- menuBar = null;
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- }
- }
- menus = null;
- super.releaseWidget ();
- image = 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.
- *
- * @param the new default button
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+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 void setDefaultButton (Button button) {
- checkWidget();
- int buttonHandle = 0;
- if (button != null) {
- if (button.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- 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 String getText () {
+ checkWidget();
+ return text;
+}
+
+boolean isTabGroup () {
+ return true;
+}
+
+boolean isTabItem () {
+ return false;
+}
+
+Decorations menuShell () {
+ return this;
+}
+
+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 releaseWidget () {
+ if (menuBar != null) menuBar.releaseResources ();
+ menuBar = null;
+ if (menus != null) {
+ for (int i=0; i<menus.length; i++) {
+ Menu menu = menus [i];
+ if (menu != null && !menu.isDisposed ()) {
+ menu.dispose ();
+ }
+ }
+ }
+ menus = null;
+ super.releaseWidget ();
+ image = 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.
+ *
+ * @param the new default button
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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;
- int pixmap = 0, mask = 0;
- if (image != null) {
- pixmap = image.pixmap;
- mask = image.mask;
- }
- int window = OS.GTK_WIDGET_WINDOW(topHandle());
- OS.gdk_window_set_icon (window, 0, pixmap, mask);
-}
-
-/**
- * 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 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 setDefaultButton (Button button) {
+ checkWidget();
+ int buttonHandle = 0;
+ if (button != null) {
+ if (button.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
+ 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 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 setImage (Image image) {
+ checkWidget();
+ this.image = image;
+ int pixmap = 0, mask = 0;
+ if (image != null) {
+ pixmap = image.pixmap;
+ mask = image.mask;
+ }
+ int window = OS.GTK_WIDGET_WINDOW(topHandle());
+ OS.gdk_window_set_icon (window, 0, pixmap, mask);
+}
+
+/**
+ * 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 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 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 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 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 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 may not be null.
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 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 setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
-}
-
-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 shellHandle = _getShell ().topHandle ();
- return OS.gtk_window_activate_default (shellHandle);
-}
-
-}
+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 may not be null.
+ *
+ * @param text the new text
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 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 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
index 23ae7714ec..d9dd4ac4d3 100644
--- 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
@@ -1,186 +1,186 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class DirectoryDialog extends Dialog {
- String message = "", filterPath = "";
-
-/**
- * Constructs a new instance of this class given only its
- * parent.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
+
+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.
+ * <p>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation.
+ * </p>
*/
-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>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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 class DirectoryDialog extends Dialog {
+ String message = "", filterPath = "";
+
+/**
+ * Constructs a new instance of this class given only its
+ * parent.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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
+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>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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 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 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
*/
-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 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 open () {
- byte [] titleBytes = Converter.wcsToMbcs (null, title, true);
- int handle = OS.gtk_file_selection_new (titleBytes);
- if (parent != null) {
- OS.gtk_window_set_transient_for (handle, parent.topHandle ());
- }
- String answer = null;
- if (filterPath != null) {
- int length = filterPath.length ();
- char [] buffer = new char [length + 1];
- filterPath.getChars (0, length, buffer, 0);
- int utf8Ptr = OS.g_utf16_to_utf8 (buffer, -1, null, null, null);
- int 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 fileListParent = OS.gtk_widget_get_parent (selection.file_list);
- OS.gtk_widget_hide (selection.file_list);
- OS.gtk_widget_hide (fileListParent);
- int response = OS.gtk_dialog_run (handle);
- if (response == OS.GTK_RESPONSE_OK) {
- int fileNamePtr = OS.gtk_file_selection_get_filename (handle);
- int utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, null, null);
- int [] items_written = new int [1];
- int utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
- int length = items_written [0];
- char [] buffer = new char [length];
- OS.memmove (buffer, utf16Ptr, length * 2);
- String osAnswer = new String (buffer);
- OS.g_free (utf16Ptr);
- OS.g_free (utf8Ptr);
- if (osAnswer != null) {
- answer = osAnswer;
- // add trailing separator if not already present
- char separator = System.getProperty ("file.separator").charAt (0);
- int separatorIndex = answer.lastIndexOf (separator);
- if (separatorIndex != answer.length () - 1) answer += separator;
- }
- }
- OS.gtk_widget_destroy (handle);
- return answer;
-}
-/**
- * Sets the path which the dialog will use to filter
- * the directories it shows to the argument, which may be
- * null.
- *
- * @param string the filter path
+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 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
+public String open () {
+ byte [] titleBytes = Converter.wcsToMbcs (null, title, true);
+ int handle = OS.gtk_file_selection_new (titleBytes);
+ if (parent != null) {
+ OS.gtk_window_set_transient_for (handle, parent.topHandle ());
+ }
+ String answer = null;
+ if (filterPath != null) {
+ int length = filterPath.length ();
+ char [] buffer = new char [length + 1];
+ filterPath.getChars (0, length, buffer, 0);
+ int utf8Ptr = OS.g_utf16_to_utf8 (buffer, -1, null, null, null);
+ int 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 fileListParent = OS.gtk_widget_get_parent (selection.file_list);
+ OS.gtk_widget_hide (selection.file_list);
+ OS.gtk_widget_hide (fileListParent);
+ int response = OS.gtk_dialog_run (handle);
+ if (response == OS.GTK_RESPONSE_OK) {
+ int fileNamePtr = OS.gtk_file_selection_get_filename (handle);
+ int utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, null, null);
+ int [] items_written = new int [1];
+ int utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
+ int length = items_written [0];
+ char [] buffer = new char [length];
+ OS.memmove (buffer, utf16Ptr, length * 2);
+ String osAnswer = new String (buffer);
+ OS.g_free (utf16Ptr);
+ OS.g_free (utf8Ptr);
+ if (osAnswer != null) {
+ answer = osAnswer;
+ // add trailing separator if not already present
+ char separator = System.getProperty ("file.separator").charAt (0);
+ int separatorIndex = answer.lastIndexOf (separator);
+ if (separatorIndex != answer.length () - 1) answer += separator;
+ }
+ }
+ OS.gtk_widget_destroy (handle);
+ return answer;
+}
+/**
+ * Sets the path which the dialog will use to filter
+ * the directories it shows to the argument, which may be
+ * null.
+ *
+ * @param string the filter path
*/
-public void setMessage (String string) {
- /*
- * The native Gtk file selection dialog does not support message
- * strings other than the dialog title. However, we maintain the set
- * message so at least the application programs get back the same string.
- */
- message = string;
-}
-}
+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
+ */
+public void setMessage (String string) {
+ /*
+ * The native Gtk file selection dialog does not support message
+ * strings other than the dialog title. However, we maintain the set
+ * message so at least the application programs get back the same string.
+ */
+ 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
index 51b3d8b44c..7f883f95f8 100644
--- 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
@@ -12,80 +12,80 @@ 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 #dispose
+/**
+ * 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 #dispose
*/
public class Display extends Device {
@@ -272,24 +272,24 @@ 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 not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see #getCurrent
- * @see #getDefault
- * @see Widget#checkSubclass
- * @see Shell
+/**
+ * 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 not called from the thread that created the parent</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);
@@ -328,26 +328,26 @@ void addFilter (int eventType, Listener listener) {
filterTable.hook (eventType, listener);
}
-/**
- * Adds the listener to the collection of listeners who will
- * be notifed when an event of the given type occurs. 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>
- * </ul>
- *
- * @see Listener
- * @see #removeListener
- *
- * @since 2.0
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notifed when an event of the given type occurs. 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>
+ * </ul>
+ *
+ * @see Listener
+ * @see #removeListener
+ *
+ * @since 2.0
*/
public void addListener (int eventType, Listener listener) {
checkDevice ();
@@ -362,25 +362,25 @@ void addMouseHoverTimeout (int handle) {
mouseHoverHandle = handle;
}
-/**
- * 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
+/**
+ * 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
*/
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).
+/**
+ * Causes the system hardware to emit a short sound
+ * (if it supports this capability).
*/
public void beep () {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
@@ -405,17 +405,17 @@ 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>
- * </ul>
- *
- * @see #dispose
- *
- * @since 2.0
+/**
+ * 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>
+ * </ul>
+ *
+ * @see #dispose
+ *
+ * @since 2.0
*/
public void close () {
checkDevice ();
@@ -480,13 +480,13 @@ protected void destroy () {
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.
- *
- * @param thread the user-interface thread
- * @return the display for the given thread
+/**
+ * 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.
+ *
+ * @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++) {
@@ -498,12 +498,12 @@ public static synchronized Display findDisplay (Thread thread) {
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.
- *
- * @param runnable code to run at dispose time.
+/**
+ * Causes the <code>run()</code> method of the runnable to
+ * be invoked by the user-interface thread just before the
+ * receiver is disposed.
+ *
+ * @param runnable code to run at dispose time.
*/
public void disposeExec (Runnable runnable) {
checkDevice ();
@@ -577,34 +577,34 @@ int eventProc (int event, int data) {
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.
- *
- * @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>
- * </ul>
+/**
+ * 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.
+ *
+ * @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>
+ * </ul>
*/
public Widget findWidget (int handle) {
checkDevice ();
return WidgetTable.get (handle);
}
-/**
- * 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>
- * </ul>
+/**
+ * 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>
+ * </ul>
*/
public Shell getActiveShell () {
checkDevice ();
@@ -615,26 +615,26 @@ public Shell getActiveShell () {
return 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>
- * </ul>
+/**
+ * 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>
+ * </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
+/**
+ * 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 ();
@@ -645,16 +645,16 @@ public static synchronized Display getCurrent () {
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>
- * </ul>
+/**
+ * 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>
+ * </ul>
*/
public Control getCursorControl () {
checkDevice();
@@ -685,15 +685,15 @@ boolean filters (int eventType) {
return filterTable.hooks (eventType);
}
-/**
- * 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>
- * </ul>
+/**
+ * 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>
+ * </ul>
*/
public Point getCursorLocation () {
checkDevice ();
@@ -702,29 +702,29 @@ public Point getCursorLocation () {
return new Point (x [0], y [0]);
}
-/**
- * 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 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>
- * </ul>
- *
- * @see #setData
- * @see #disposeExec
+/**
+ * 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 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>
+ * </ul>
+ *
+ * @see #setData
+ * @see #disposeExec
*/
public Object getData (String key) {
checkDevice ();
@@ -736,27 +736,27 @@ public Object getData (String key) {
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 provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @return the display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #setData
- * @see #disposeExec
+/**
+ * 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 provide a
+ * <code>disposeExec()</code> handler which does so.
+ * </p>
+ *
+ * @return the display specific data
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
+ * </ul>
+ *
+ * @see #setData
+ * @see #disposeExec
*/
public Object getData () {
checkDevice ();
@@ -782,12 +782,12 @@ public Point getDPI () {
return new Point (dpi, dpi);
}
-/**
- * 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
+/**
+ * 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 ();
@@ -805,33 +805,33 @@ public int getDismissalAlignment () {
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>
- * </ul>
+/**
+ * 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>
+ * </ul>
*/
public int getDoubleClickTime () {
checkDevice ();
return DOUBLE_CLICK_TIME;
}
-/**
- * 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>
- * </ul>
+/**
+ * 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>
+ * </ul>
*/
public Control getFocusControl () {
checkDevice ();
@@ -857,16 +857,16 @@ public int getDepth () {
return visual.depth;
}
-/**
- * Returns the maximum allowed depth of icons on this display.
- * 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>
- * </ul>
+/**
+ * Returns the maximum allowed depth of icons on this display.
+ * 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>
+ * </ul>
*/
public int getIconDepth () {
checkDevice ();
@@ -877,15 +877,15 @@ int getLastEventTime () {
return OS.gtk_get_current_event_time ();
}
-/**
- * Returns an 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>
- * </ul>
+/**
+ * Returns an 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>
+ * </ul>
*/
public Shell [] getShells () {
checkDevice ();
@@ -908,39 +908,39 @@ public Shell [] getShells () {
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
+/**
+ * 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
*/
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>
- * </ul>
- *
- * @see SWT
+/**
+ * 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>
+ * </ul>
+ *
+ * @see SWT
*/
public Color getSystemColor (int id) {
checkDevice ();
@@ -1135,35 +1135,35 @@ void initializeSystemResources () {
OS.gtk_widget_destroy (shellHandle);
}
-/**
- * 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>
- * </ul>
+/**
+ * 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>
+ * </ul>
*/
public Font getSystemFont () {
checkDevice ();
return Font.gtk_new (this, defaultFont);
}
-/**
- * Returns the user-interface thread for the receiver.
- *
- * @return the receiver's user-interface thread
+/**
+ * Returns the user-interface thread for the receiver.
+ *
+ * @return the receiver's user-interface thread
*/
public Thread getThread () {
if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
@@ -1214,39 +1214,39 @@ void initializeCallbacks () {
if (treeSelectionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
}
-/**
- * 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 handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
+/**
+ * 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 handle the platform specific GC handle
+ * @param data the platform specific GC data
+ *
+ * @private
*/
public void internal_dispose_GC (int 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
- *
- * @private
+/**
+ * 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
+ *
+ * @private
*/
public int internal_new_GC (GCData data) {
if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
@@ -1293,27 +1293,27 @@ void postEvent (Event event) {
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>
- * </ul>
- *
- * @see #sleep
- * @see #wake
+/**
+ * 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>
+ * </ul>
+ *
+ * @see #sleep
+ * @see #wake
*/
public boolean readAndDispatch () {
checkDevice ();
@@ -1447,24 +1447,24 @@ void removeFilter (int eventType, Listener listener) {
if (filterTable.size () == 0) filterTable = null;
}
-/**
- * Removes the listener from the collection of listeners who will
- * be notifed when an event of the given type occurs.
- *
- * @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 #addListener
- *
- * @since 2.0
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notifed when an event of the given type occurs.
+ *
+ * @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 #addListener
+ *
+ * @since 2.0
*/
public void removeListener (int eventType, Listener listener) {
checkDevice ();
@@ -1524,12 +1524,12 @@ boolean runDeferredEvents () {
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.
- *
- * @param name the new app name
+/**
+ * On platforms which support it, sets the application name
+ * to be the argument. On Motif, for example, this can be used
+ * to set the name used for resource lookup.
+ *
+ * @param name the new app name
*/
public static void setAppName (String name) {
APP_NAME = name;
@@ -1540,17 +1540,17 @@ public void setCursorLocation (int x, int y) {
/* This is not supported on GTK */
}
-/**
- * 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
- * @since 2.0
- * @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
- * </ul>
+/**
+ * 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
+ * @since 2.0
+ * @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
+ * </ul>
*/
public void setCursorLocation (Point point) {
checkDevice ();
@@ -1558,29 +1558,29 @@ public void setCursorLocation (Point point) {
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>
- * </ul>
- *
- * @see #setData
- * @see #disposeExec
+/**
+ * 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>
+ * </ul>
+ *
+ * @see #setData
+ * @see #disposeExec
*/
public void setData (String key, Object value) {
checkDevice ();
@@ -1630,45 +1630,45 @@ public void setData (String key, Object value) {
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 - when called from the wrong thread</li>
- * </ul>
- *
- * @see #getData
- * @see #disposeExec
+/**
+ * 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 - when called from the wrong thread</li>
+ * </ul>
+ *
+ * @see #getData
+ * @see #disposeExec
*/
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>
- * </ul>
+/**
+ * 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>
+ * </ul>
*/
public void setSynchronizer (Synchronizer synchronizer) {
checkDevice ();
@@ -1712,18 +1712,18 @@ void showIMWindow (Control control) {
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>
- * </ul>
- *
- * @see #wake
+/**
+ * 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>
+ * </ul>
+ *
+ * @see #wake
*/
public boolean sleep () {
checkDevice ();
@@ -1734,23 +1734,23 @@ public boolean sleep () {
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.
- *
- * @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>
- * </ul>
- *
- * @see #asyncExec
+/**
+ * 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.
+ *
+ * @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>
+ * </ul>
+ *
+ * @see #asyncExec
*/
public void timerExec (int milliseconds, Runnable runnable) {
checkDevice ();
@@ -1843,19 +1843,19 @@ void setCurrentCaret (Caret caret) {
caretId = OS.gtk_timeout_add (blinkRate, caretProc, 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.
- *
- * @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
+/**
+ * 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
*/
public void syncExec (Runnable runnable) {
if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
@@ -1876,11 +1876,11 @@ static int untranslateKey (int key) {
return 0;
}
-/**
- * Forces all outstanding paint requests for the display
- * to be processed before this method returns.
- *
- * @see Control#update
+/**
+ * Forces all outstanding paint requests for the display
+ * to be processed before this method returns.
+ *
+ * @see Control#update
*/
public void update () {
checkDevice ();
@@ -1891,12 +1891,12 @@ public void 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.
- *
- * @see #sleep
+/**
+ * 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.
+ *
+ * @see #sleep
*/
public void wake () {
// NOT IMPLEMENTED - need to wake up the event loop
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
index 1ec06e658a..ac02ff869f 100644
--- 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
@@ -1,307 +1,307 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class FileDialog extends Dialog {
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String filterPath = "";
- String fileName = "";
- String[] fileNames;
- String fullPath = "";
- int handle;
- static final char SEPARATOR = System.getProperty ("file.separator").charAt (0);
-
-/**
- * Constructs a new instance of this class given only its
- * parent.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
+
+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>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation.
+ * </p>
*/
-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>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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 class FileDialog extends Dialog {
+ String [] filterNames = new String [0];
+ String [] filterExtensions = new String [0];
+ String filterPath = "";
+ String fileName = "";
+ String[] fileNames;
+ String fullPath = "";
+ int handle;
+ static final char SEPARATOR = System.getProperty ("file.separator").charAt (0);
+
+/**
+ * Constructs a new instance of this class given only its
+ * parent.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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
- *
- * @return the relative path of the file
+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>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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 String getFileName () {
- return fileName;
-}
-/**
- * Returns the paths of all files that were selected
- * in the dialog relative to the filter path, or null
- * if none are available.
- *
- * @return the relative paths of the files
+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
+ *
+ * @return the relative path of the file
*/
-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 getFileName () {
+ return fileName;
+}
+/**
+ * Returns the paths of all files that were selected
+ * in the dialog relative to the filter path, or null
+ * if none are available.
+ *
+ * @return the relative paths of the files
*/
-public String [] getFilterExtensions () {
- return filterExtensions;
-}
-/**
- * Returns the file names which the dialog will
- * use to filter the files it shows.
- *
- * @return the file name filter
+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 [] getFilterNames () {
- return filterNames;
-}
-/**
- * Returns the directory path that the dialog will use.
- * 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 [] getFilterExtensions () {
+ return filterExtensions;
+}
+/**
+ * Returns the file names which the dialog will
+ * use to filter the files it shows.
+ *
+ * @return the file name filter
*/
-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 [] getFilterNames () {
+ return filterNames;
+}
+/**
+ * Returns the directory path that the dialog will use.
+ * 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 open () {
- byte [] titleBytes = Converter.wcsToMbcs (null, title, true);
- handle = OS.gtk_file_selection_new (titleBytes);
- if (parent != null) {
- OS.gtk_window_set_transient_for (handle, parent.topHandle());
- }
- String answer = null;
- preset ();
- int response = OS.gtk_dialog_run (handle);
- if (response == OS.GTK_RESPONSE_OK) {
- int fileNamePtr = OS.gtk_file_selection_get_filename (handle);
- int utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, null, null);
- int [] items_written = new int [1];
- int utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
- int length = items_written [0];
- char [] buffer = new char [length];
- OS.memmove (buffer, utf16Ptr, length * 2);
- String osAnswer = new String (buffer);
- OS.g_free (utf16Ptr);
- OS.g_free (utf8Ptr);
- answer = interpretOsAnswer (osAnswer);
- }
- OS.gtk_widget_destroy (handle);
- return answer;
-}
-/**
- * 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 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 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.
- *
- * @param extensions the file extension filter
+public String open () {
+ byte [] titleBytes = Converter.wcsToMbcs (null, title, true);
+ handle = OS.gtk_file_selection_new (titleBytes);
+ if (parent != null) {
+ OS.gtk_window_set_transient_for (handle, parent.topHandle());
+ }
+ String answer = null;
+ preset ();
+ int response = OS.gtk_dialog_run (handle);
+ if (response == OS.GTK_RESPONSE_OK) {
+ int fileNamePtr = OS.gtk_file_selection_get_filename (handle);
+ int utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, null, null);
+ int [] items_written = new int [1];
+ int utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
+ int length = items_written [0];
+ char [] buffer = new char [length];
+ OS.memmove (buffer, utf16Ptr, length * 2);
+ String osAnswer = new String (buffer);
+ OS.g_free (utf16Ptr);
+ OS.g_free (utf8Ptr);
+ answer = interpretOsAnswer (osAnswer);
+ }
+ OS.gtk_widget_destroy (handle);
+ return answer;
+}
+/**
+ * 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 setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-/**
- * Sets the file names which the dialog will
- * use to filter the files it shows to the argument,
- * which may be null.
- *
- * @param names the file name filter
+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.
+ *
+ * @param extensions the file extension filter
*/
-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.
- *
- * @param string the directory path
- *
- * @see #setFilterExtensions
+public void setFilterExtensions (String [] extensions) {
+ filterExtensions = extensions;
+}
+/**
+ * Sets the file names which the dialog will
+ * use to filter the files it shows to the argument,
+ * which may be null.
+ *
+ * @param names the file name filter
*/
-public void setFilterPath (String string) {
- filterPath = string;
-}
-void preset() {
- 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 utf8Ptr = OS.g_utf16_to_utf8 (buffer, -1, null, null, null);
- int 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);
-
- /* Set the extension */
- if (filterNames == null) filterNames = new String [0];
- if (filterExtensions == null) filterExtensions = new String [0];
- if (filterExtensions.length == 1) {
- String ext = filterExtensions [0];
- byte [] extBytes = Converter.wcsToMbcs (null, ext, true);
- OS.gtk_file_selection_complete (handle, extBytes);
- }
- fullPath = null;
-}
-String interpretOsAnswer(String osAnswer) {
- 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 namesPtr = OS.gtk_file_selection_get_selections (handle);
- int namesPtr1 = namesPtr;
- int [] namePtr = new int [1];
- OS.memmove (namePtr, namesPtr1, 4);
- int length = 0;
- while (namePtr[0] != 0) {
- length++;
- namesPtr1+=4;
- OS.memmove(namePtr, namesPtr1, 4);
- }
- fileNames = new String [length];
- namePtr = new int [length];
- OS.memmove (namePtr, namesPtr, length * 4);
- for (int i = 0; i < length; i++) {
- int utf8Ptr = OS.g_filename_to_utf8 (namePtr [i], -1, null, null, null);
- int [] items_written = new int [1];
- int utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
- char[] buffer = new char [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;
-}
-
-}
+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.
+ *
+ * @param string the directory path
+ *
+ * @see #setFilterExtensions
+ */
+public void setFilterPath (String string) {
+ filterPath = string;
+}
+void preset() {
+ 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 utf8Ptr = OS.g_utf16_to_utf8 (buffer, -1, null, null, null);
+ int 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);
+
+ /* Set the extension */
+ if (filterNames == null) filterNames = new String [0];
+ if (filterExtensions == null) filterExtensions = new String [0];
+ if (filterExtensions.length == 1) {
+ String ext = filterExtensions [0];
+ byte [] extBytes = Converter.wcsToMbcs (null, ext, true);
+ OS.gtk_file_selection_complete (handle, extBytes);
+ }
+ fullPath = null;
+}
+String interpretOsAnswer(String osAnswer) {
+ 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 namesPtr = OS.gtk_file_selection_get_selections (handle);
+ int namesPtr1 = namesPtr;
+ int [] namePtr = new int [1];
+ OS.memmove (namePtr, namesPtr1, 4);
+ int length = 0;
+ while (namePtr[0] != 0) {
+ length++;
+ namesPtr1+=4;
+ OS.memmove(namePtr, namesPtr1, 4);
+ }
+ fileNames = new String [length];
+ namePtr = new int [length];
+ OS.memmove (namePtr, namesPtr, length * 4);
+ for (int i = 0; i < length; i++) {
+ int utf8Ptr = OS.g_filename_to_utf8 (namePtr [i], -1, null, null, null);
+ int [] items_written = new int [1];
+ int utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null);
+ char[] buffer = new char [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;
+}
+
+}
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
index ff6c96be46..3ab4e64e66 100644
--- 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
@@ -1,177 +1,177 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class FontDialog extends Dialog {
- FontData fontData;
- RGB rgb;
-/**
- * Constructs a new instance of this class given only its
- * parent.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
+
+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.
+ * <p>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation.
+ * </p>
*/
-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>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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 class FontDialog extends Dialog {
+ FontData fontData;
+ RGB rgb;
+/**
+ * Constructs a new instance of this class given only its
+ * parent.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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
+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>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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 FontData getFontData() {
- return fontData;
-}
-
-/**
- * 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 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 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
*/
-public FontData open () {
- int handle;
- byte [] titleBytes;
- titleBytes = Converter.wcsToMbcs (null, title, true);
- handle = OS.gtk_font_selection_dialog_new (titleBytes);
- if (parent!=null) {
- OS.gtk_window_set_transient_for(handle, parent.topHandle());
- }
- if (fontData != null) {
- Display display = parent != null ? parent.getDisplay () : Display.getCurrent ();
- Font font = new Font (display, fontData);
- int 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 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);
- int fontDesc = OS.pango_font_description_from_string (buffer);
- Display display = parent != null ? parent.getDisplay () : 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
+public FontData getFontData() {
+ return fontData;
+}
+
+/**
+ * Returns the currently selected color in the receiver.
+ *
+ * @return the RGB value for the selected color, may be null
+ *
+ * @see PaletteData#getRGBs
*/
-public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-/**
- * Returns 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 to select a default when
- * open() is called
- *
- * @see PaletteData#getRGBs
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-}
+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 handle;
+ byte [] titleBytes;
+ titleBytes = Converter.wcsToMbcs (null, title, true);
+ handle = OS.gtk_font_selection_dialog_new (titleBytes);
+ if (parent!=null) {
+ OS.gtk_window_set_transient_for(handle, parent.topHandle());
+ }
+ if (fontData != null) {
+ Display display = parent != null ? parent.getDisplay () : Display.getCurrent ();
+ Font font = new Font (display, fontData);
+ int 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 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);
+ int fontDesc = OS.pango_font_description_from_string (buffer);
+ Display display = parent != null ? parent.getDisplay () : 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
+ */
+public void setFontData (FontData fontData) {
+ this.fontData = fontData;
+}
+/**
+ * Returns 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 to 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/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java
index cabe9e2c07..84da604f97 100644
--- 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
@@ -12,61 +12,61 @@ 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>
+/**
+ * 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 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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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));
@@ -212,17 +212,17 @@ 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>
+/**
+ * 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();
@@ -264,20 +264,20 @@ void setForegroundColor (GdkColor color) {
OS.gtk_widget_modify_fg (labelHandle, 0, color);
}
-/**
- * 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.
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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.
+ *
+ * @param text the new text
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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();
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
index e530851422..6feb04783e 100644
--- 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
@@ -12,69 +12,69 @@ 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>
+/**
+ * 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 frameHandle, labelHandle, imageHandle;
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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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));
@@ -198,19 +198,19 @@ int 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>
+/**
+ * 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 ();
@@ -221,16 +221,16 @@ public int getAlignment () {
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>
+/**
+ * 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 ();
@@ -241,17 +241,17 @@ 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>
+/**
+ * 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 ();
@@ -326,18 +326,18 @@ void resizeHandle (int width, int height) {
OS.gtk_widget_size_request (widgetHandle, requisition);
}
-/**
- * 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>
+/**
+ * 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 ();
@@ -420,19 +420,19 @@ void setForegroundColor (GdkColor color) {
if (imageHandle != 0) OS.gtk_widget_modify_fg (imageHandle, 0, color);
}
-/**
- * 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>
+/**
+ * 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 ();
@@ -449,22 +449,22 @@ public void setImage (Image image) {
}
}
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the widget label. The label may include
- * the mnemonic characters 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>
+/**
+ * Sets the receiver's text.
+ * <p>
+ * This method sets the widget label. The label may include
+ * the mnemonic characters 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();
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
index 2ce6f11dfb..a307fa4beb 100644
--- 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
@@ -13,76 +13,76 @@ 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 notificiation
- * when a string 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>
+/**
+ * Instances of this class represent a selectable user interface
+ * object that displays a list of strings and issues notificiation
+ * when a string 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 modelHandle;
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- *
- * @see #add(String,int)
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ *
+ * @see #add(String,int)
*/
public void add (String string) {
checkWidget();
@@ -95,31 +95,31 @@ public void add (String string) {
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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- *
- * @see #add(String)
+/**
+ * Adds the argument to the receiver's list at the given
+ * zero-relative index.
+ * <p>
+ * Note: To add an item at the end of the list, use the
+ * result of calling <code>getItemCount()</code> as the
+ * index or use <code>add(String)</code>.
+ * </p>
+ *
+ * @param string the new item
+ * @param index the index for the item
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
+ * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ *
+ * @see #add(String)
*/
public void add (String string, int index) {
checkWidget();
@@ -135,29 +135,29 @@ public void add (String string, int index) {
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
+/**
+ * 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();
@@ -236,17 +236,17 @@ void deregister() {
WidgetTable.remove (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>
+/**
+ * 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();
@@ -260,20 +260,20 @@ public void deselect (int index) {
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>
+/**
+ * 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();
@@ -293,22 +293,22 @@ public void deselect (int start, int end) {
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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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();
@@ -327,13 +327,13 @@ public void deselect (int [] indices) {
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>
+/**
+ * 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();
@@ -347,16 +347,16 @@ GdkColor getBackgroundColor () {
return getBaseColor ();
}
-/**
- * Returns the zero-relative index of the item which is currently
- * has the focus in the receiver, or -1 if no item is 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>
+/**
+ * Returns the zero-relative index of the item which is currently
+ * has the focus in the receiver, or -1 if no item is 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();
@@ -374,23 +374,23 @@ 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public String getItem (int index) {
checkWidget();
@@ -410,37 +410,37 @@ public String getItem (int index) {
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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public int getItemHeight () {
checkWidget();
@@ -453,25 +453,25 @@ public int getItemHeight () {
return h [0];
}
-/**
- * Returns an 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li>
- * </ul>
+/**
+ * Returns an 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li>
+ * </ul>
*/
public String [] getItems () {
checkWidget();
@@ -494,25 +494,25 @@ public String [] getItems () {
return result;
}
-/**
- * Returns an array of <code>String</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure while getting the selection</li>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li>
- * </ul>
+/**
+ * Returns an array of <code>String</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure while getting the selection</li>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li>
+ * </ul>
*/
public String [] getSelection () {
checkWidget();
@@ -524,18 +524,18 @@ public String [] getSelection () {
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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public int getSelectionCount () {
checkWidget();
@@ -547,19 +547,19 @@ public int getSelectionCount () {
return display.treeSelectionLength;
}
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public int getSelectionIndex () {
checkWidget();
@@ -573,23 +573,23 @@ public int getSelectionIndex () {
return display.treeSelection [0];
}
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * Returns the zero-relative indices of the items which are currently
+ * selected in the receiver. 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public int [] getSelectionIndices () {
checkWidget();
@@ -605,17 +605,17 @@ public int [] getSelectionIndices () {
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>
+/**
+ * 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();
@@ -699,51 +699,51 @@ void hookEvents () {
OS.g_signal_connect (handle, OS.row_activated, display.windowProc4, ROW_ACTIVATED);
}
-/**
- * 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>
+/**
+ * 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
- * @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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li>
- * </ul>
+/**
+ * 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
+ * @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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li>
+ * </ul>
*/
public int indexOf (String string, int start) {
checkWidget();
@@ -755,18 +755,18 @@ public int indexOf (String string, int start) {
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>
+/**
+ * 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();
@@ -794,22 +794,22 @@ void releaseWidget () {
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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public void remove (int index) {
checkWidget();
@@ -825,24 +825,24 @@ public void remove (int index) {
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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public void remove (int start, int end) {
checkWidget();
@@ -851,7 +851,7 @@ public void remove (int start, int end) {
int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0);
int iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
int 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.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED);
for (int index=Math.min(end,count-1); index>=start; index--) {
OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index);
OS.gtk_list_store_remove (modelHandle, iter);
@@ -863,24 +863,24 @@ public void remove (int start, int end) {
}
}
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public void remove (String string) {
checkWidget();
@@ -889,22 +889,22 @@ public void remove (String string) {
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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public void remove (int [] indices) {
checkWidget();
@@ -935,13 +935,13 @@ public void remove (int [] indices) {
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>
+/**
+ * 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();
@@ -951,22 +951,22 @@ public void removeAll () {
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
+/**
+ * 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();
@@ -976,17 +976,17 @@ public void removeSelectionListener(SelectionListener 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>
+/**
+ * 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();
@@ -1006,19 +1006,19 @@ public void select (int index) {
OS.g_free (iter);
}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * If the item at the index was already selected, it remains
- * selected. The range of the indices is inclusive. Indices that are
- * out of range 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>
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * If the item at the index was already selected, it remains
+ * selected. The range of the indices is inclusive. Indices that are
+ * out of range 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>
*/
public void select (int start, int end) {
checkWidget();
@@ -1044,22 +1044,22 @@ public void select (int start, int end) {
OS.g_free (iter);
}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is not selected, it is selected. If the item at the index
- * was selected, it remains selected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * If the item at the given zero-relative index in the receiver
+ * is not selected, it is selected. If the item at the index
+ * was selected, it remains selected. Indices that are out
+ * of range and duplicate indices are ignored.
+ *
+ * @param indices the array of indices for the items to select
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 [] indices) {
checkWidget();
@@ -1085,13 +1085,13 @@ public void select (int [] indices) {
OS.g_free (iter);
}
-/**
- * Selects all 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>
+/**
+ * Selects all 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 void selectAll () {
checkWidget();
@@ -1126,26 +1126,26 @@ void setForegroundColor (GdkColor 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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
- * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * 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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
+ * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</li>
+ * </ul>
*/
public void setItem (int index, String string) {
checkWidget();
@@ -1160,18 +1160,18 @@ public void setItem (int index, String string) {
OS.g_free (iter);
}
-/**
- * Sets the receiver's items to be the given array of items.
- *
- * @param items the array 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
+/**
+ * Sets the receiver's items to be the given array of items.
+ *
+ * @param items the array 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
public void setItems (String [] items) {
checkWidget();
@@ -1195,20 +1195,20 @@ public void setItems (String [] items) {
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 selected 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>
- * @see List#deselectAll()
- * @see List#select(int)
+/**
+ * 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 selected 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>
+ * @see List#deselectAll()
+ * @see List#select(int)
*/
public void setSelection (int index) {
checkWidget();
@@ -1217,20 +1217,20 @@ public void setSelection (int index) {
showSelection ();
}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selected if first cleared, then the new items are selected.
- *
- * @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)
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * The current selected if first cleared, then the new items are selected.
+ *
+ * @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();
@@ -1239,22 +1239,22 @@ public void setSelection (int start, int end) {
showSelection ();
}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is first cleared, then the new items are selected.
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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[])
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * The current selection is first cleared, then the new items are selected.
+ *
+ * @param indices the indices of the items to select
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
@@ -1264,23 +1264,23 @@ public void setSelection(int[] indices) {
showSelection ();
}
-/**
- * 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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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)
+/**
+ * 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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 (String [] items) {
checkWidget();
@@ -1304,17 +1304,17 @@ public void setSelection (String [] items) {
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>
+/**
+ * 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();
@@ -1328,18 +1328,18 @@ public void setTopIndex (int index) {
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 IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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 IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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();
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
index fab7f3a7db..357ea3c399 100644
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -28,13 +28,13 @@ import org.eclipse.swt.graphics.*;
* 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 imItem, imSeparator, imHandle;
-
+public class Menu extends Widget {
+ int x, y;
+ boolean hasLocation;
+ MenuItem cascade, selectedItem;
+ Decorations parent;
+ int imItem, imSeparator, imHandle;
+
/**
* Constructs a new instance of this class given its parent,
* and sets the style for the instance so that the instance
@@ -54,10 +54,10 @@ public class Menu extends Widget {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Menu (Control parent) {
- this (parent.getShell (), SWT.POP_UP);
-}
-
+public Menu (Control parent) {
+ this (parent.getShell (), SWT.POP_UP);
+}
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Decorations</code>) and a style value
@@ -89,12 +89,12 @@ public Menu (Control parent) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Menu (Decorations parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
-
+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
@@ -115,10 +115,10 @@ public Menu (Decorations parent, int style) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Menu (Menu parentMenu) {
- this (parentMenu.parent, SWT.DROP_DOWN);
-}
-
+public Menu (Menu parentMenu) {
+ this (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
@@ -139,22 +139,22 @@ public Menu (Menu parentMenu) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Menu (MenuItem parentItem) {
- this (parentItem.parent);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
-}
-
-void addAccelerators (int accelGroup) {
- MenuItem [] items = getItems ();
+public Menu (MenuItem parentItem) {
+ this (parentItem.parent);
+}
+
+static int checkStyle (int style) {
+ return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
+}
+
+void addAccelerators (int 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
@@ -174,14 +174,14 @@ void addAccelerators (int accelGroup) {
* @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);
-}
-
+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,
@@ -201,62 +201,62 @@ public void addMenuListener (MenuListener listener) {
* @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 parentHandle = parent.fixedHandle;
- OS.gtk_container_add (parentHandle, handle);
- } else {
- handle = OS.gtk_menu_new ();
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- }
-}
-
-void createIMMenu (int 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 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.add (this);
-}
-
+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 parentHandle = parent.fixedHandle;
+ OS.gtk_container_add (parentHandle, handle);
+ } else {
+ handle = OS.gtk_menu_new ();
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ }
+}
+
+void createIMMenu (int 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 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.add (this);
+}
+
/**
* Returns the default menu item or null if none has
* been previously set.
@@ -269,17 +269,17 @@ void createWidget (int index) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public MenuItem getDefaultItem () {
- checkWidget();
- return null;
-}
-
-public Display getDisplay () {
- Decorations parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+public MenuItem getDefaultItem () {
+ checkWidget();
+ return null;
+}
+
+public Display getDisplay () {
+ Decorations parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> otherwise. A disabled control is typically
@@ -293,11 +293,11 @@ public Display getDisplay () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean getEnabled () {
- checkWidget();
- return OS.GTK_WIDGET_SENSITIVE (handle);
-}
-
+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.
@@ -313,20 +313,20 @@ public boolean getEnabled () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public MenuItem getItem (int index) {
- checkWidget();
- int 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 data = OS.g_list_nth_data (list, index);
- OS.g_list_free (list);
- if (data == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- return (MenuItem) WidgetTable.get (data);
-}
-
+public MenuItem getItem (int index) {
+ checkWidget();
+ int 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 data = OS.g_list_nth_data (list, index);
+ OS.g_list_free (list);
+ if (data == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
+ return (MenuItem) WidgetTable.get (data);
+}
+
/**
* Returns the number of items contained in the receiver.
*
@@ -337,17 +337,17 @@ public MenuItem getItem (int index) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public int getItemCount () {
- checkWidget();
- int 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;
-}
-
+public int getItemCount () {
+ checkWidget();
+ int 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 an array of <code>MenuItem</code>s which are the items
* in the receiver.
@@ -364,35 +364,35 @@ public int getItemCount () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public MenuItem [] getItems () {
- checkWidget();
- int 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];
- for (int i=0; i<count; i++) {
- int data = OS.g_list_nth_data (list, i);
- items [i] = (MenuItem) WidgetTable.get (data);
- }
- OS.g_list_free (list);
- 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;
-}
-
+public MenuItem [] getItems () {
+ checkWidget();
+ int 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];
+ for (int i=0; i<count; i++) {
+ int data = OS.g_list_nth_data (list, i);
+ items [i] = (MenuItem) WidgetTable.get (data);
+ }
+ OS.g_list_free (list);
+ 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>.
*
@@ -403,11 +403,11 @@ String getNameText () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Decorations getParent () {
- checkWidget();
- return parent;
-}
-
+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
@@ -420,11 +420,11 @@ public Decorations getParent () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public MenuItem getParentItem () {
- checkWidget();
- return cascade;
-}
-
+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
@@ -437,12 +437,12 @@ public MenuItem getParentItem () {
* <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 ();
-}
-
+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
@@ -458,11 +458,11 @@ public Menu getParentMenu () {
*
* @see #getParent
*/
-public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-
+public Shell getShell () {
+ checkWidget();
+ return parent.getShell ();
+}
+
/**
* Returns <code>true</code> if the receiver is visible, and
* <code>false</code> otherwise.
@@ -480,43 +480,43 @@ public Shell getShell () {
* <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_MAPPED (handle);
-}
-
-int GtkMenuPositionFunc (int menu, int x, int y, int push_in, int user_data) {
- if (x != 0) OS.memmove (x, new int [] {this.x}, 4);
- if (y != 0) OS.memmove (y, new int [] {this.y}, 4);
- return 0;
-}
-
-int gtk_hide (int widget) {
- sendEvent (SWT.Hide);
- return 0;
-}
-
-int gtk_show (int widget) {
- if ((style & SWT.POP_UP) != 0) return 0;
- sendEvent (SWT.Show);
- return 0;
-}
-
-int gtk_show_help (int widget, int helpType) {
- if (sendHelpEvent (helpType)) OS.gtk_menu_shell_deactivate (handle);
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- Display display = getDisplay ();
- int windowProc2 = display.windowProc2;
- int windowProc3 = display.windowProc3;
- OS.g_signal_connect (handle, OS.show, windowProc2, SHOW);
- OS.g_signal_connect (handle, OS.hide, windowProc2, HIDE);
- OS.g_signal_connect (handle, OS.show_help, windowProc3, SHOW_HELP);
-}
-
+public boolean getVisible () {
+ checkWidget();
+ return OS.GTK_WIDGET_MAPPED (handle);
+}
+
+int GtkMenuPositionFunc (int menu, int x, int y, int push_in, int user_data) {
+ if (x != 0) OS.memmove (x, new int [] {this.x}, 4);
+ if (y != 0) OS.memmove (y, new int [] {this.y}, 4);
+ return 0;
+}
+
+int gtk_hide (int widget) {
+ sendEvent (SWT.Hide);
+ return 0;
+}
+
+int gtk_show (int widget) {
+ if ((style & SWT.POP_UP) != 0) return 0;
+ sendEvent (SWT.Show);
+ return 0;
+}
+
+int gtk_show_help (int widget, int helpType) {
+ if (sendHelpEvent (helpType)) OS.gtk_menu_shell_deactivate (handle);
+ return 0;
+}
+
+void hookEvents () {
+ super.hookEvents ();
+ Display display = getDisplay ();
+ int windowProc2 = display.windowProc2;
+ int windowProc3 = display.windowProc3;
+ OS.g_signal_connect (handle, OS.show, windowProc2, SHOW);
+ OS.g_signal_connect (handle, OS.hide, windowProc2, HIDE);
+ OS.g_signal_connect (handle, OS.show_help, windowProc3, SHOW_HELP);
+}
+
/**
* Searches the receiver's list starting at the first item
* (index 0) until an item is found that is equal to the
@@ -534,78 +534,78 @@ void hookEvents () {
* <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 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 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 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();
- 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 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 releaseChild () {
- super.releaseChild ();
- if (cascade != null) cascade.setMenu (null);
- if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
- parent.setMenuBar (null);
- }
-}
-
-void releaseWidget () {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (!item.isDisposed ()) item.releaseResources ();
- }
- if (parent != null) parent.remove (this);
- super.releaseWidget ();
- parent = null;
- cascade = null;
- imItem = imSeparator = imHandle = 0;
-}
-
+public boolean isVisible () {
+ checkWidget();
+ return getVisible ();
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ if (cascade != null) cascade.setMenu (null);
+ if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
+ parent.setMenuBar (null);
+ }
+}
+
+void releaseWidget () {
+ MenuItem [] items = getItems ();
+ for (int i=0; i<items.length; i++) {
+ MenuItem item = items [i];
+ if (!item.isDisposed ()) item.releaseResources ();
+ }
+ if (parent != null) parent.remove (this);
+ super.releaseWidget ();
+ parent = null;
+ cascade = null;
+ imItem = imSeparator = imHandle = 0;
+}
+
/**
* Removes the listener from the collection of listeners who will
* be notified when the menu events are generated for the control.
@@ -623,22 +623,22 @@ void releaseWidget () {
* @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 accelGroup) {
- MenuItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items[i];
- item.removeAccelerators (accelGroup);
- }
-}
-
+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 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.
@@ -656,27 +656,27 @@ void removeAccelerators (int accelGroup) {
* @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 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);
-}
-
+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 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>.
@@ -691,10 +691,10 @@ boolean sendHelpEvent (int helpType) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setDefaultItem (MenuItem item) {
- checkWidget();
-}
-
+public void setDefaultItem (MenuItem item) {
+ checkWidget();
+}
+
/**
* Enables the receiver if the argument is <code>true</code>,
* and disables it otherwise. A disabled control is typically
@@ -708,15 +708,15 @@ public void setDefaultItem (MenuItem item) {
* <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);
- }
-}
-
+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 receiver's location to the point specified by
* the arguments which are relative to the display.
@@ -733,20 +733,20 @@ public void setEnabled (boolean enabled) {
* <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;
-}
-
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
+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;
+}
+
+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.
@@ -763,26 +763,26 @@ public void setLocation (Point location) {
* <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 == OS.GTK_WIDGET_MAPPED (handle)) return;
- if (visible) {
- sendEvent (SWT.Show);
- if (getItemCount () != 0) {
- int address = 0;
- Callback GtkMenuPositionFunc = null;
- if (hasLocation) {
- GtkMenuPositionFunc = new Callback (this, "GtkMenuPositionFunc", 5);
- address = GtkMenuPositionFunc.getAddress ();
- }
- OS.gtk_menu_popup (handle, 0, 0, address, 0, 0, OS.gtk_get_current_event_time());
- if (GtkMenuPositionFunc != null) GtkMenuPositionFunc.dispose ();
- } else {
- sendEvent (SWT.Hide);
- }
- } else {
- OS.gtk_menu_popdown (handle);
- }
-}
-}
+public void setVisible (boolean visible) {
+ checkWidget();
+ if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
+ if (visible == OS.GTK_WIDGET_MAPPED (handle)) return;
+ if (visible) {
+ sendEvent (SWT.Show);
+ if (getItemCount () != 0) {
+ int address = 0;
+ Callback GtkMenuPositionFunc = null;
+ if (hasLocation) {
+ GtkMenuPositionFunc = new Callback (this, "GtkMenuPositionFunc", 5);
+ address = GtkMenuPositionFunc.getAddress ();
+ }
+ OS.gtk_menu_popup (handle, 0, 0, address, 0, 0, OS.gtk_get_current_event_time());
+ if (GtkMenuPositionFunc != null) GtkMenuPositionFunc.dispose ();
+ } else {
+ sendEvent (SWT.Hide);
+ }
+ } else {
+ OS.gtk_menu_popdown (handle);
+ }
+}
+}
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
index 66fc22a16e..df4d279723 100644
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -29,10 +29,10 @@ import org.eclipse.swt.events.*;
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
-public class MenuItem extends Item {
- Menu parent, menu;
- int accelerator;
-
+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
@@ -67,12 +67,12 @@ public class MenuItem extends Item {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public MenuItem (Menu parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (parent.getItemCount ());
-}
-
+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
@@ -108,25 +108,25 @@ public MenuItem (Menu parent, int style) {
* @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 accelGroup) {
- updateAccelerator (accelGroup, true);
-}
-
-void addAccelerators (int accelGroup) {
- addAccelerator (accelGroup);
- if (menu != null) menu.addAccelerators (accelGroup);
-}
-
+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 accelGroup) {
+ updateAccelerator (accelGroup, true);
+}
+
+void addAccelerators (int 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
@@ -146,13 +146,13 @@ void addAccelerators (int accelGroup) {
* @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);
-}
-
+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
@@ -172,81 +172,81 @@ public void addArmListener (ArmListener listener) {
* @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 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 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 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 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 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);
-}
-
-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:
-// handle = OS.gtk_radio_menu_item_new_with_label (0, 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 label = OS.gtk_bin_get_child (handle);
- OS.gtk_accel_label_set_accel_widget (label, 0);
- }
- int 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);
-}
-
+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);
+}
+
+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:
+// handle = OS.gtk_radio_menu_item_new_with_label (0, 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 label = OS.gtk_bin_get_child (handle);
+ OS.gtk_accel_label_set_accel_widget (label, 0);
+ }
+ int 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);
+}
+
/**
* Return the widget accelerator. An accelerator is the bit-wise
* OR of zero or more modifier masks and a key. Examples:
@@ -260,26 +260,26 @@ void createHandle (int index) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public int getAccelerator () {
- checkWidget();
- return accelerator;
-}
-
-int getAccelGroup () {
- Menu menu = parent;
- while (menu != null && menu.cascade != null) {
- menu = menu.cascade.parent;
- }
- Decorations shell = menu.parent;
- return shell.menuBar == menu ? shell.accelGroup : 0;
-}
-
-public Display getDisplay () {
- Menu parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+public int getAccelerator () {
+ checkWidget();
+ return accelerator;
+}
+
+int getAccelGroup () {
+ Menu menu = parent;
+ while (menu != null && menu.cascade != null) {
+ menu = menu.cascade.parent;
+ }
+ Decorations shell = menu.parent;
+ return shell.menuBar == menu ? shell.accelGroup : 0;
+}
+
+public Display getDisplay () {
+ Menu parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> otherwise. A disabled control is typically
@@ -293,11 +293,11 @@ public Display getDisplay () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean getEnabled () {
- checkWidget();
- return OS.GTK_WIDGET_SENSITIVE(handle);
-}
-
+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
@@ -312,11 +312,11 @@ public boolean getEnabled () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Menu getMenu () {
- checkWidget();
- return menu;
-}
-
+public Menu getMenu () {
+ checkWidget();
+ return menu;
+}
+
/**
* Returns the receiver's parent, which must be a <code>Menu</code>.
*
@@ -327,11 +327,11 @@ public Menu getMenu () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Menu getParent () {
- checkWidget();
- return parent;
-}
-
+public Menu getParent () {
+ checkWidget();
+ return parent;
+}
+
/**
* Returns <code>true</code> if the receiver is selected,
* and false otherwise.
@@ -346,124 +346,124 @@ public Menu getParent () {
* <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 gtk_activate (int 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 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 gtk_select (int item) {
- parent.selectedItem = this;
- postEvent (SWT.Arm);
- return 0;
-}
-
-int gtk_show_help (int widget, int helpType) {
- boolean hooks = hooks (SWT.Help);
- if (hooks) {
- postEvent (SWT.Help);
- } else {
- hooks = parent.sendHelpEvent (helpType);
- }
- if (hooks) OS.gtk_menu_shell_deactivate (parent.handle);
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- Display display = getDisplay ();
- int windowProc2 = display.windowProc2;
- int windowProc3 = display.windowProc3;
- OS.g_signal_connect (handle, OS.activate, windowProc2, ACTIVATE);
- OS.g_signal_connect (handle, OS.select, windowProc2, SELECT);
- OS.g_signal_connect (handle, OS.show_help, windowProc3, SHOW_HELP);
-}
-
-/**
- * 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 getSelection () {
+ checkWidget();
+ if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
+ return OS.gtk_check_menu_item_get_active(handle);
+}
+
+int gtk_activate (int 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 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 gtk_select (int item) {
+ parent.selectedItem = this;
+ postEvent (SWT.Arm);
+ return 0;
+}
+
+int gtk_show_help (int widget, int helpType) {
+ boolean hooks = hooks (SWT.Help);
+ if (hooks) {
+ postEvent (SWT.Help);
+ } else {
+ hooks = parent.sendHelpEvent (helpType);
+ }
+ if (hooks) OS.gtk_menu_shell_deactivate (parent.handle);
+ return 0;
+}
+
+void hookEvents () {
+ super.hookEvents ();
+ Display display = getDisplay ();
+ int windowProc2 = display.windowProc2;
+ int windowProc3 = display.windowProc3;
+ OS.g_signal_connect (handle, OS.activate, windowProc2, ACTIVATE);
+ OS.g_signal_connect (handle, OS.select, windowProc2, SELECT);
+ OS.g_signal_connect (handle, OS.show_help, windowProc3, SHOW_HELP);
+}
+
+/**
+ * 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 () {
- return getEnabled () && parent.isEnabled ();
-}
-
-void releaseChild () {
- super.releaseChild ();
- if (menu != null) {
- if (menu.selectedItem == this) menu.selectedItem = null;
- menu.dispose ();
- }
- menu = null;
-}
-
-void releaseWidget () {
- if (menu != null) menu.releaseResources ();
- menu = null;
- super.releaseWidget ();
- int accelGroup = getAccelGroup ();
- if (accelGroup != 0) removeAccelerator (accelGroup);
- accelerator = 0;
- parent = null;
-}
-
-void removeAccelerator (int accelGroup) {
- updateAccelerator (accelGroup, false);
-}
-
-void removeAccelerators (int accelGroup) {
- removeAccelerator (accelGroup);
- if (menu != null) menu.removeAccelerators (accelGroup);
-}
-
+public boolean isEnabled () {
+ return getEnabled () && parent.isEnabled ();
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ if (menu != null) {
+ if (menu.selectedItem == this) menu.selectedItem = null;
+ menu.dispose ();
+ }
+ menu = null;
+}
+
+void releaseWidget () {
+ if (menu != null) menu.releaseResources ();
+ menu = null;
+ super.releaseWidget ();
+ int accelGroup = getAccelGroup ();
+ if (accelGroup != 0) removeAccelerator (accelGroup);
+ accelerator = 0;
+ parent = null;
+}
+
+void removeAccelerator (int accelGroup) {
+ updateAccelerator (accelGroup, false);
+}
+
+void removeAccelerators (int 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.
@@ -481,13 +481,13 @@ void removeAccelerators (int accelGroup) {
* @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);
-}
-
+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.
@@ -505,13 +505,13 @@ public void removeArmListener (ArmListener listener) {
* @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);
-}
-
+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.
@@ -529,23 +529,23 @@ public void removeHelpListener (HelpListener listener) {
* @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);
-}
+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:
@@ -559,15 +559,15 @@ void selectRadio () {
* <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 accelGroup = getAccelGroup ();
- if (accelGroup != 0) removeAccelerator (accelGroup);
- this.accelerator = accelerator;
- if (accelGroup != 0) addAccelerator (accelGroup);
-}
-
+public void setAccelerator (int accelerator) {
+ checkWidget();
+ if (this.accelerator == accelerator) return;
+ int 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 control is typically
@@ -581,11 +581,11 @@ public void setAccelerator (int accelerator) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setEnabled (boolean enabled) {
- checkWidget();
- OS.gtk_widget_set_sensitive (handle, enabled);
-}
-
+public void setEnabled (boolean enabled) {
+ checkWidget();
+ OS.gtk_widget_set_sensitive (handle, enabled);
+}
+
/**
* Sets the image the receiver will display to the argument.
* <p>
@@ -599,20 +599,20 @@ public void setEnabled (boolean enabled) {
* <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 ((style & SWT.PUSH) == 0) return;
- if (image != null) {
- int imageHandle = OS.gtk_image_new_from_pixmap (image.pixmap, image.mask);
- OS.gtk_image_menu_item_set_image (handle, imageHandle);
- OS.gtk_widget_show (imageHandle);
- } else {
- OS.gtk_image_menu_item_set_image (handle, 0);
- }
-}
-
+public void setImage (Image image) {
+ checkWidget();
+ if ((style & SWT.SEPARATOR) != 0) return;
+ super.setImage (image);
+ if ((style & SWT.PUSH) == 0) return;
+ if (image != null) {
+ int imageHandle = OS.gtk_image_new_from_pixmap (image.pixmap, image.mask);
+ 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
@@ -633,52 +633,52 @@ public void setImage (Image image) {
* <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 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);
-}
-
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-
+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 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);
+}
+
+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>
@@ -692,57 +692,57 @@ boolean setRadioSelection (boolean value) {
* <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);
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ACTIVATE);
-}
-
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) 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, false);
- int label = OS.gtk_bin_get_child (handle);
- OS.gtk_label_set_text_with_mnemonic (label, buffer);
- buffer = Converter.wcsToMbcs (null, accelString, true);
- int ptr = OS.g_malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- int oldPtr = OS.GTK_ACCEL_LABEL_ACCEL_STRING (label);
- OS.GTK_ACCEL_LABEL_ACCEL_STRING (label, ptr);
- if (oldPtr != 0) OS.g_free (oldPtr);
-}
-
-void updateAccelerator (int accelGroup, boolean add) {
- if (accelerator == 0) return;
- int mask = 0;
- if ((accelerator & SWT.ALT) != 0) mask |= OS.GDK_MOD1_MASK;
- if ((accelerator & SWT.SHIFT) != 0) mask |= OS.GDK_SHIFT_MASK;
- if ((accelerator & SWT.CONTROL) != 0) mask |= OS.GDK_CONTROL_MASK;
- int keysym = accelerator & SWT.KEY_MASK;
- int newKey = Display.untranslateKey (keysym);
- if (newKey != 0) {
- keysym = newKey;
- } else {
- switch (keysym) {
- case '\r': keysym = OS.GDK_Return; break;
- default: keysym = wcsToMbcs ((char) keysym);
- }
- }
- 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);
- }
-}
-}
+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);
+ OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ACTIVATE);
+}
+
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.SEPARATOR) != 0) 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, false);
+ int label = OS.gtk_bin_get_child (handle);
+ OS.gtk_label_set_text_with_mnemonic (label, buffer);
+ buffer = Converter.wcsToMbcs (null, accelString, true);
+ int ptr = OS.g_malloc (buffer.length);
+ OS.memmove (ptr, buffer, buffer.length);
+ int oldPtr = OS.GTK_ACCEL_LABEL_ACCEL_STRING (label);
+ OS.GTK_ACCEL_LABEL_ACCEL_STRING (label, ptr);
+ if (oldPtr != 0) OS.g_free (oldPtr);
+}
+
+void updateAccelerator (int accelGroup, boolean add) {
+ if (accelerator == 0) return;
+ int mask = 0;
+ if ((accelerator & SWT.ALT) != 0) mask |= OS.GDK_MOD1_MASK;
+ if ((accelerator & SWT.SHIFT) != 0) mask |= OS.GDK_SHIFT_MASK;
+ if ((accelerator & SWT.CONTROL) != 0) mask |= OS.GDK_CONTROL_MASK;
+ int keysym = accelerator & SWT.KEY_MASK;
+ int newKey = Display.untranslateKey (keysym);
+ if (newKey != 0) {
+ keysym = newKey;
+ } else {
+ switch (keysym) {
+ case '\r': keysym = OS.GDK_Return; break;
+ default: keysym = wcsToMbcs ((char) keysym);
+ }
+ }
+ 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/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java
index a8c7eef48d..06237750a3 100644
--- 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
@@ -1,43 +1,43 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class TabFolder extends Composite {
- TabItem [] items;
-
+
+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>(none)</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 TabFolder extends Composite {
+ TabItem [] items;
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -66,233 +66,233 @@ public class TabFolder extends Composite {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public TabFolder (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);
-}
-
-
-/**
- * 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 TabFolder (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);
+}
+
+
+/**
+ * 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 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 ();
- int width = OS.GTK_WIDGET_WIDTH (fixedHandle);
- int height = OS.GTK_WIDGET_HEIGHT (fixedHandle);
- OS.gtk_widget_set_size_request (handle, wHint, hHint);
- GtkRequisition requisition = new GtkRequisition ();
- boolean scrollable = OS.gtk_notebook_get_scrollable (handle);
- OS.gtk_notebook_set_scrollable (handle, false);
- OS.gtk_widget_size_request (handle, requisition);
- OS.gtk_notebook_set_scrollable (handle, scrollable);
- OS.gtk_widget_set_size_request (handle, width, height);
- width = wHint == SWT.DEFAULT ? requisition.width : wHint;
- height = hHint == SWT.DEFAULT ? requisition.height : hHint;
- Point size;
- if (layout != null) {
- size = layout.computeSize (this, wHint, hHint, changed);
- } else {
- size = minimumSize (wHint, hHint, changed);
- }
- Rectangle trim = computeTrim (0, 0, size.x, size.y);
- size.x = trim.width; size.y = trim.height;
- 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);
- return new Point (width, height);
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int clientHandle = clientHandle ();
- 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;
- fixedHandle = OS.gtk_fixed_new ();
- 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);
- int parentHandle = parent.parentingHandle ();
- OS.gtk_container_add (parentHandle, fixedHandle);
- OS.gtk_container_add (fixedHandle, handle);
- OS.gtk_widget_show (handle);
- OS.gtk_widget_show (fixedHandle);
- OS.gtk_notebook_set_scrollable (handle, true);
- OS.gtk_notebook_set_show_tabs (handle, true);
-}
-
-void createWidget (int index) {
- super.createWidget(index);
- items = new TabItem [4];
-}
-
-void createItem (TabItem item, int index) {
- int 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_ITEM_NOT_ADDED);
- if (itemCount == items.length) {
- TabItem [] newItems = new TabItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- int boxHandle = OS.gtk_hbox_new (false, 0);
- if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int labelHandle = OS.gtk_label_new_with_mnemonic (null);
- if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int 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 pageHandle = OS.gtk_fixed_new ();
- 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;
- item.setForegroundColor (getForegroundColor ());
- item.setFontDescription (getFontDescription ());
- if (itemCount == 1) {
- fixPage ();
- Event event = new Event();
- event.item = items[0];
- sendEvent (SWT.Selection, event);
- // the widget could be destroyed at this point
- }
-}
-
-void fixPage () {
- /*
- * Feature in GTK. For some reason, the positioning of
- * tab labels and pages become corrupted when when there
- * is no current page. The fix is to force the notebook
- * to resize which causes the current page to be set.
- */
-// int index = OS.gtk_notebook_get_current_page (handle);
-// if (index != -1) return;
- OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
- int flags = OS.GTK_WIDGET_FLAGS (handle);
- OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_VISIBLE);
- GtkRequisition requisition = new GtkRequisition ();
- OS.gtk_widget_size_request (handle, requisition);
- OS.gtk_container_resize_children (handle);
- if ((flags & OS.GTK_VISIBLE) == 0) {
- OS.GTK_WIDGET_UNSET_FLAGS(handle, OS.GTK_VISIBLE);
- }
- OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
-}
-
-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;
- item.handle = 0;
- if (index == oldIndex) {
- fixPage ();
- 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
- }
- }
-}
-
-void enableWidget (boolean enabled) {
- OS.gtk_widget_set_sensitive (handle, enabled);
-}
-
-int eventHandle () {
- return fixedHandle;
-}
-
+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 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 ();
+ int width = OS.GTK_WIDGET_WIDTH (fixedHandle);
+ int height = OS.GTK_WIDGET_HEIGHT (fixedHandle);
+ OS.gtk_widget_set_size_request (handle, wHint, hHint);
+ GtkRequisition requisition = new GtkRequisition ();
+ boolean scrollable = OS.gtk_notebook_get_scrollable (handle);
+ OS.gtk_notebook_set_scrollable (handle, false);
+ OS.gtk_widget_size_request (handle, requisition);
+ OS.gtk_notebook_set_scrollable (handle, scrollable);
+ OS.gtk_widget_set_size_request (handle, width, height);
+ width = wHint == SWT.DEFAULT ? requisition.width : wHint;
+ height = hHint == SWT.DEFAULT ? requisition.height : hHint;
+ Point size;
+ if (layout != null) {
+ size = layout.computeSize (this, wHint, hHint, changed);
+ } else {
+ size = minimumSize (wHint, hHint, changed);
+ }
+ Rectangle trim = computeTrim (0, 0, size.x, size.y);
+ size.x = trim.width; size.y = trim.height;
+ 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);
+ return new Point (width, height);
+}
+
+public Rectangle computeTrim (int x, int y, int width, int height) {
+ checkWidget();
+ int clientHandle = clientHandle ();
+ 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;
+ fixedHandle = OS.gtk_fixed_new ();
+ 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);
+ int parentHandle = parent.parentingHandle ();
+ OS.gtk_container_add (parentHandle, fixedHandle);
+ OS.gtk_container_add (fixedHandle, handle);
+ OS.gtk_widget_show (handle);
+ OS.gtk_widget_show (fixedHandle);
+ OS.gtk_notebook_set_scrollable (handle, true);
+ OS.gtk_notebook_set_show_tabs (handle, true);
+}
+
+void createWidget (int index) {
+ super.createWidget(index);
+ items = new TabItem [4];
+}
+
+void createItem (TabItem item, int index) {
+ int 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_ITEM_NOT_ADDED);
+ if (itemCount == items.length) {
+ TabItem [] newItems = new TabItem [items.length + 4];
+ System.arraycopy (items, 0, newItems, 0, items.length);
+ items = newItems;
+ }
+ int boxHandle = OS.gtk_hbox_new (false, 0);
+ if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ int labelHandle = OS.gtk_label_new_with_mnemonic (null);
+ if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ int 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 pageHandle = OS.gtk_fixed_new ();
+ 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;
+ item.setForegroundColor (getForegroundColor ());
+ item.setFontDescription (getFontDescription ());
+ if (itemCount == 1) {
+ fixPage ();
+ Event event = new Event();
+ event.item = items[0];
+ sendEvent (SWT.Selection, event);
+ // the widget could be destroyed at this point
+ }
+}
+
+void fixPage () {
+ /*
+ * Feature in GTK. For some reason, the positioning of
+ * tab labels and pages become corrupted when when there
+ * is no current page. The fix is to force the notebook
+ * to resize which causes the current page to be set.
+ */
+// int index = OS.gtk_notebook_get_current_page (handle);
+// if (index != -1) return;
+ OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
+ int flags = OS.GTK_WIDGET_FLAGS (handle);
+ OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_VISIBLE);
+ GtkRequisition requisition = new GtkRequisition ();
+ OS.gtk_widget_size_request (handle, requisition);
+ OS.gtk_container_resize_children (handle);
+ if ((flags & OS.GTK_VISIBLE) == 0) {
+ OS.GTK_WIDGET_UNSET_FLAGS(handle, OS.GTK_VISIBLE);
+ }
+ OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
+}
+
+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;
+ item.handle = 0;
+ if (index == oldIndex) {
+ fixPage ();
+ 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
+ }
+ }
+}
+
+void enableWidget (boolean enabled) {
+ OS.gtk_widget_set_sensitive (handle, enabled);
+}
+
+int 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.
@@ -308,17 +308,17 @@ int eventHandle () {
* <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 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];
-}
-
+public TabItem getItem (int index) {
+ checkWidget();
+ if (!(0 <= index && index < getItemCount())) error (SWT.ERROR_INVALID_RANGE);
+ int 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.
*
@@ -329,15 +329,15 @@ public TabItem getItem (int index) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public int getItemCount () {
- checkWidget();
- int 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;
-}
-
+public int getItemCount () {
+ checkWidget();
+ int 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.
@@ -354,14 +354,14 @@ public int getItemCount () {
* <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;
-}
-
+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
@@ -378,13 +378,13 @@ public TabItem [] getItems () {
* <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]};
-}
-
+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.
@@ -396,36 +396,36 @@ public TabItem [] getSelection () {
* <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 gtk_switch_page (int widget, int page, int 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);
- }
- }
- Control control = items [page_num].getControl ();
- if (control != null && !control.isDisposed ()) {
- control.setBounds(getClientArea());
- control.setVisible (true);
- }
- Event event = new Event();
- event.item = items[page_num];
- postEvent(SWT.Selection, event);
- return 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- Display display = getDisplay ();
- OS.g_signal_connect (handle, OS.switch_page, display.windowProc4, SWITCH_PAGE);
-}
-
+public int getSelectionIndex () {
+ checkWidget();
+ return OS.gtk_notebook_get_current_page (handle);
+}
+
+int gtk_switch_page (int widget, int page, int 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);
+ }
+ }
+ Control control = items [page_num].getControl ();
+ if (control != null && !control.isDisposed ()) {
+ control.setBounds(getClientArea());
+ control.setVisible (true);
+ }
+ Event event = new Event();
+ event.item = items[page_num];
+ postEvent(SWT.Selection, event);
+ return 0;
+}
+
+void hookEvents () {
+ super.hookEvents ();
+ Display display = getDisplay ();
+ OS.g_signal_connect (handle, OS.switch_page, display.windowProc4, SWITCH_PAGE);
+}
+
/**
* Searches the receiver's list starting at the first item
* (index 0) until an item is found that is equal to the
@@ -443,58 +443,58 @@ void hookEvents () {
* <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 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 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);
-}
-
-void releaseWidget () {
- int count = getItemCount ();
- for (int i=0; i<count; i++) {
- TabItem item = items [i];
- if (!item.isDisposed ()) item.releaseResources ();
- }
- items = null;
- super.releaseWidget ();
-}
-
+public int indexOf (TabItem item) {
+ checkWidget();
+ if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int 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 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);
+}
+
+void releaseWidget () {
+ int count = getItemCount ();
+ for (int i=0; i<count; i++) {
+ TabItem item = items [i];
+ if (!item.isDisposed ()) item.releaseResources ();
+ }
+ items = null;
+ super.releaseWidget ();
+}
+
/**
* Removes the listener from the collection of listeners who will
* be notified when the receiver's selection changes.
@@ -512,49 +512,49 @@ void releaseWidget () {
* @see SelectionListener
* @see #addSelectionListener
*/
-public void removeSelectionListener (SelectionListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-
-boolean 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) {
- int index = getSelectionIndex ();
- if (index != -1) {
- TabItem item = items [index];
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getClientArea ());
- }
- }
- }
- return changed;
-}
-
-void setFontDescription (int 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);
- }
- }
-}
-
+public void removeSelectionListener (SelectionListener listener) {
+ checkWidget ();
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Selection, listener);
+ eventTable.unhook (SWT.DefaultSelection,listener);
+}
+
+boolean 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) {
+ int index = getSelectionIndex ();
+ if (index != -1) {
+ TabItem item = items [index];
+ Control control = item.control;
+ if (control != null && !control.isDisposed ()) {
+ control.setBounds (getClientArea ());
+ }
+ }
+ }
+ return changed;
+}
+
+void setFontDescription (int 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.
@@ -568,40 +568,40 @@ void setForegroundColor (GdkColor color) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setSelection (int index) {
- checkWidget ();
- 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);
- }
- }
-}
-
+public void setSelection (int index) {
+ checkWidget ();
+ 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 be the given array of items.
* The current selected is first cleared, then the new items are
@@ -614,17 +614,17 @@ void setSelection (int index, boolean notify) {
* <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);
- return;
- }
- for (int i=items.length-1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) setSelection (index);
- }
-}
-
-}
+public void setSelection (TabItem [] items) {
+ checkWidget();
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (items.length == 0) {
+ setSelection (-1);
+ return;
+ }
+ for (int i=items.length-1; i>=0; --i) {
+ int index = indexOf (items [i]);
+ if (index != -1) setSelection (index);
+ }
+}
+
+}
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
index 4d97d71115..b1b55d03c2 100644
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -25,12 +25,12 @@ import org.eclipse.swt.graphics.*;
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
-public class TabItem extends Item {
- int labelHandle, imageHandle, pageHandle;
- Control control;
- TabFolder parent;
- String toolTipText;
-
+public class TabItem extends Item {
+ int 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
@@ -61,12 +61,12 @@ public class TabItem extends Item {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public TabItem (TabFolder parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
-}
-
+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
@@ -98,12 +98,12 @@ public TabItem (TabFolder parent, int style) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public TabItem (TabFolder parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
-}
-
+public TabItem (TabFolder parent, int style, int index) {
+ super (parent, style);
+ this.parent = parent;
+ parent.createItem (this, index);
+}
+
/**
* Returns the control that is used to fill the client area of
* the tab folder when the user selects the tab item. If no
@@ -116,17 +116,17 @@ public TabItem (TabFolder parent, int style, int index) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Control getControl () {
- checkWidget ();
- return control;
-}
-
-public Display getDisplay () {
- TabFolder parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+public Control getControl () {
+ checkWidget ();
+ return control;
+}
+
+public Display getDisplay () {
+ TabFolder parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns the receiver's parent, which must be a <code>TabFolder</code>.
*
@@ -137,11 +137,11 @@ public Display getDisplay () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public TabFolder getParent () {
- checkWidget ();
- return parent;
-}
-
+public TabFolder getParent () {
+ checkWidget ();
+ return parent;
+}
+
/**
* Returns the receiver's tool tip text, or null if it has
* not been set.
@@ -153,30 +153,30 @@ public TabFolder getParent () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public String getToolTipText () {
- checkWidget ();
- return toolTipText;
-}
-
-void releaseChild () {
- super.releaseChild ();
- int index = parent.indexOf (this);
- if (index == parent.getSelectionIndex ()) {
- if (control != null) control.setVisible (false);
- }
- parent.destroyItem (this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- pageHandle = labelHandle = imageHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
-}
-
+public String getToolTipText () {
+ checkWidget ();
+ return toolTipText;
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ int index = parent.indexOf (this);
+ if (index == parent.getSelectionIndex ()) {
+ if (control != null) control.setVisible (false);
+ }
+ parent.destroyItem (this);
+}
+
+void releaseHandle () {
+ super.releaseHandle ();
+ pageHandle = labelHandle = imageHandle = 0;
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ parent = null;
+}
+
/**
* Sets the control that is used to fill the client area of
* the tab folder when the user selects the tab item.
@@ -192,60 +192,60 @@ void releaseWidget () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setControl (Control control) {
- checkWidget ();
- 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 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, 0, color);
- OS.gtk_widget_modify_fg (imageHandle, 0, color);
-}
-
-public void setImage (Image image) {
- checkWidget ();
- super.setImage (image);
- if (image != null) {
- OS.gtk_image_set_from_pixmap (imageHandle, image.pixmap, image.mask);
- OS.gtk_widget_show (imageHandle);
- } else {
- OS.gtk_image_set_from_pixmap (imageHandle, 0, 0);
- OS.gtk_widget_hide (imageHandle);
- }
- parent.fixPage ();
-}
-
-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, false);
- 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.fixPage ();
-}
-
+public void setControl (Control control) {
+ checkWidget ();
+ 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 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, 0, color);
+ OS.gtk_widget_modify_fg (imageHandle, 0, color);
+}
+
+public void setImage (Image image) {
+ checkWidget ();
+ super.setImage (image);
+ if (image != null) {
+ OS.gtk_image_set_from_pixmap (imageHandle, image.pixmap, image.mask);
+ OS.gtk_widget_show (imageHandle);
+ } else {
+ OS.gtk_image_set_from_pixmap (imageHandle, 0, 0);
+ OS.gtk_widget_hide (imageHandle);
+ }
+ parent.fixPage ();
+}
+
+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, false);
+ 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.fixPage ();
+}
+
/**
* Sets the receiver's tool tip text to the argument, which
* may be null indicating that no tool tip text should be shown.
@@ -257,9 +257,9 @@ public void setText (String string) {
* <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;
-}
-
-}
+public void setToolTipText (String string) {
+ checkWidget ();
+ toolTipText = string;
+}
+
+}
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
index dd18eebabf..e82690e095 100644
--- 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
@@ -259,8 +259,8 @@ public int indexOf (ToolItem item) {
// TEMPORARY CODE
ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- if (item == items[i]) return i;
+ for (int i=0; i<items.length; i++) {
+ if (item == items[i]) return i;
}
return -1;
}
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
index 66fd6cf59e..62f8bea8fa 100644
--- 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
@@ -1,46 +1,46 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- Display display;
- int cursor, lastCursor;
- boolean tracking, stippled;
- Rectangle [] rectangles = new Rectangle [0];
- int xWindow;
- int ptrGrabResult;
-
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+ Display display;
+ int cursor, lastCursor;
+ boolean tracking, stippled;
+ Rectangle [] rectangles = new Rectangle [0];
+ int xWindow;
+ int ptrGrabResult;
+
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -73,13 +73,13 @@ public class Tracker extends Widget {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Tracker (Composite parent, int style) {
- super (parent, checkStyle(style));
- this.parent = parent;
- display = parent.getDisplay ();
- xWindow = calculateWindow();
-}
-
+public Tracker (Composite parent, int style) {
+ super (parent, checkStyle(style));
+ this.parent = parent;
+ display = parent.getDisplay ();
+ xWindow = calculateWindow();
+}
+
/**
* Constructs a new instance of this class given the display
* to create it on and a style value describing its behavior
@@ -114,115 +114,115 @@ public Tracker (Composite parent, int style) {
* @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;
- xWindow = calculateWindow();
-}
-
-
-/*
- * === ADD / REMOVE LISTENERS ===
- */
-
-/**
- * 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 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;
+ xWindow = calculateWindow();
+}
+
+
+/*
+ * === ADD / REMOVE LISTENERS ===
*/
-public void addControlListener(ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Move,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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+
+/**
+ * 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 removeControlListener (ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
-}
-
-
-
-
-/*
- * === PUBLIC ACCESSORS ===
- */
-
-public Display getDisplay () {
- return display;
-}
-
-/**
- * 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 void addControlListener(ControlListener listener) {
+ checkWidget();
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Move,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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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);
+}
+
+
+
+
+/*
+ * === PUBLIC ACCESSORS ===
+ */
+
+public Display getDisplay () {
+ return display;
+}
+
+/**
+ * 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();
- return rectangles;
-}
-
-/**
- * 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 Rectangle [] getRectangles () {
+ checkWidget();
+ return rectangles;
+}
+
+/**
+ * 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;
-}
-
+public boolean getStippled () {
+ checkWidget();
+ return stippled;
+}
+
/**
* Specifies the rectangles that should be drawn, expressed relative to the parent
* widget. If the parent is a Display then these are screen coordinates.
@@ -234,207 +234,207 @@ public boolean getStippled () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setRectangles (Rectangle [] rectangles) {
- checkWidget();
- this.rectangles = 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 setRectangles (Rectangle [] rectangles) {
+ checkWidget();
+ this.rectangles = 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;
+}
+
+
+
+/*
+ * === PUBLIC FUNCTIONALITY ===
+ */
+
+/**
+ * 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;
+}
+
+/**
+ * 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();
+ boolean cancelled=false;
+ tracking = true;
+ drawRectangles ();
+
+ int[] newX = new int[1];
+ int[] newY = new int[1];
+ int[] oldX = new int[1];
+ int[] oldY = new int[1];
+ OS.gdk_window_get_pointer(xWindow, oldX,oldY, null);
+ grab();
+
+ /*
+ * Tracker behaves like a Dialog with its own OS event loop.
+ */
+ while (tracking) {
+ if (parent != null && parent.isDisposed ()) break;
+ // wait for an event
+ int eventPtr;
+ while (true) {
+ eventPtr = OS.gdk_event_get();
+ if (eventPtr != 0) {
+ break;
+ }
+ else {
+ try { Thread.sleep(50); } catch (Exception ex) {}
+ }
+ }
+
+ GdkEvent osEvent = new GdkEvent();
+ OS.memmove(osEvent, eventPtr, GdkEvent.sizeof);
+ int eventType = osEvent.type;
+ switch (eventType) {
+ case OS.GDK_BUTTON_RELEASE:
+ case OS.GDK_MOTION_NOTIFY:
+ if (cursor != lastCursor) { ungrab(); grab(); }
+ OS.gdk_window_get_pointer(xWindow, newX,newY, null);
+ if (oldX [0] != newX [0] || oldY [0] != newY [0]) {
+ drawRectangles ();
+ for (int i=0; i<rectangles.length; i++) {
+ rectangles [i].x += newX [0] - oldX [0];
+ rectangles [i].y += newY [0] - oldY [0];
+ }
+ Event event = new Event();
+ event.x = newX[0];
+ event.y = newY[0];
+ sendEvent (SWT.Move,event);
+ drawRectangles ();
+ oldX [0] = newX [0]; oldY [0] = newY [0];
+ }
+ tracking = (eventType != OS.GDK_BUTTON_RELEASE);
+ break;
+ case OS.GDK_KEY_PRESS:
+ GdkEventKey gdkEvent = new GdkEventKey ();
+ OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
+ switch (gdkEvent.keyval) {
+ case OS.GDK_Escape:
+ cancelled = true;
+ // fallthrough
+ case OS.GDK_Return:
+ tracking = false;
+ break;
+ }
+ break;
+ } // switch
+ OS.gdk_event_free(eventPtr);
+ } // while
+ drawRectangles();
+ ungrab();
+ return !cancelled;
+}
+
+private void drawRectangles () {
+ if (parent != null) {
+ if (parent.isDisposed ()) return;
+ parent.getShell ().update ();
+ } else {
+ display.update ();
+ }
+
+ int gc = OS.gdk_gc_new(xWindow);
+ if (gc==0) error(SWT.ERROR_UNSPECIFIED);
+
+ /* White foreground */
+ int colormap = OS.gdk_colormap_get_system();
+ GdkColor color = new GdkColor();
+ OS.gdk_color_white(colormap, color);
+ OS.gdk_gc_set_foreground(gc, color);
+
+ /* Draw on top of inferior widgets */
+ OS.gdk_gc_set_subwindow(gc, OS.GDK_INCLUDE_INFERIORS);
+
+ /* XOR */
+ OS.gdk_gc_set_function(gc, OS.GDK_XOR);
+
+ for (int i=0; i<rectangles.length; i++) {
+ Rectangle rect = rectangles [i];
+ OS.gdk_draw_rectangle(xWindow, gc, 0, rect.x, rect.y, rect.width, rect.height);
+ }
+ OS.g_object_unref(gc);
+}
+
+/*
+ * Figure which GdkWindow we'll draw on.
+ * That's normally the root X window, or the parent's GdkWindow if we have a parent.
+ */
+private int calculateWindow() {
+ int answer;
+ if (parent == null) answer = OS.GDK_ROOT_PARENT();
+ else answer = OS.GTK_WIDGET_WINDOW(parent.paintHandle());
+ if (answer==0) error(SWT.ERROR_UNSPECIFIED);
+ return answer;
+}
+
+/**
+ * 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 setStippled (boolean stippled) {
- checkWidget();
- this.stippled = stippled;
-}
-
-
-
-/*
- * === PUBLIC FUNCTIONALITY ===
- */
-
-/**
- * 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;
-}
-
-/**
- * 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();
- boolean cancelled=false;
- tracking = true;
- drawRectangles ();
-
- int[] newX = new int[1];
- int[] newY = new int[1];
- int[] oldX = new int[1];
- int[] oldY = new int[1];
- OS.gdk_window_get_pointer(xWindow, oldX,oldY, null);
- grab();
-
- /*
- * Tracker behaves like a Dialog with its own OS event loop.
- */
- while (tracking) {
- if (parent != null && parent.isDisposed ()) break;
- // wait for an event
- int eventPtr;
- while (true) {
- eventPtr = OS.gdk_event_get();
- if (eventPtr != 0) {
- break;
- }
- else {
- try { Thread.sleep(50); } catch (Exception ex) {}
- }
- }
-
- GdkEvent osEvent = new GdkEvent();
- OS.memmove(osEvent, eventPtr, GdkEvent.sizeof);
- int eventType = osEvent.type;
- switch (eventType) {
- case OS.GDK_BUTTON_RELEASE:
- case OS.GDK_MOTION_NOTIFY:
- if (cursor != lastCursor) { ungrab(); grab(); }
- OS.gdk_window_get_pointer(xWindow, newX,newY, null);
- if (oldX [0] != newX [0] || oldY [0] != newY [0]) {
- drawRectangles ();
- for (int i=0; i<rectangles.length; i++) {
- rectangles [i].x += newX [0] - oldX [0];
- rectangles [i].y += newY [0] - oldY [0];
- }
- Event event = new Event();
- event.x = newX[0];
- event.y = newY[0];
- sendEvent (SWT.Move,event);
- drawRectangles ();
- oldX [0] = newX [0]; oldY [0] = newY [0];
- }
- tracking = (eventType != OS.GDK_BUTTON_RELEASE);
- break;
- case OS.GDK_KEY_PRESS:
- GdkEventKey gdkEvent = new GdkEventKey ();
- OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof);
- switch (gdkEvent.keyval) {
- case OS.GDK_Escape:
- cancelled = true;
- // fallthrough
- case OS.GDK_Return:
- tracking = false;
- break;
- }
- break;
- } // switch
- OS.gdk_event_free(eventPtr);
- } // while
- drawRectangles();
- ungrab();
- return !cancelled;
-}
-
-private void drawRectangles () {
- if (parent != null) {
- if (parent.isDisposed ()) return;
- parent.getShell ().update ();
- } else {
- display.update ();
- }
-
- int gc = OS.gdk_gc_new(xWindow);
- if (gc==0) error(SWT.ERROR_UNSPECIFIED);
-
- /* White foreground */
- int colormap = OS.gdk_colormap_get_system();
- GdkColor color = new GdkColor();
- OS.gdk_color_white(colormap, color);
- OS.gdk_gc_set_foreground(gc, color);
-
- /* Draw on top of inferior widgets */
- OS.gdk_gc_set_subwindow(gc, OS.GDK_INCLUDE_INFERIORS);
-
- /* XOR */
- OS.gdk_gc_set_function(gc, OS.GDK_XOR);
-
- for (int i=0; i<rectangles.length; i++) {
- Rectangle rect = rectangles [i];
- OS.gdk_draw_rectangle(xWindow, gc, 0, rect.x, rect.y, rect.width, rect.height);
- }
- OS.g_object_unref(gc);
-}
-
-/*
- * Figure which GdkWindow we'll draw on.
- * That's normally the root X window, or the parent's GdkWindow if we have a parent.
- */
-private int calculateWindow() {
- int answer;
- if (parent == null) answer = OS.GDK_ROOT_PARENT();
- else answer = OS.GTK_WIDGET_WINDOW(parent.paintHandle());
- if (answer==0) error(SWT.ERROR_UNSPECIFIED);
- return answer;
-}
-
-/**
- * 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;
-}
-void grab() {
- ptrGrabResult = OS.gdk_pointer_grab(xWindow,
- false,
- OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_RELEASE_MASK,
- xWindow,
- cursor,
- OS.GDK_CURRENT_TIME);
- lastCursor = cursor;
-}
-void ungrab() {
- if (ptrGrabResult == OS.GDK_GRAB_SUCCESS)
- OS.gdk_pointer_ungrab(OS.GDK_CURRENT_TIME);
-
-}
-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;
-}
-}
+public void setCursor (Cursor value) {
+ checkWidget ();
+ cursor = 0;
+ if (value != null) cursor = value.handle;
+}
+void grab() {
+ ptrGrabResult = OS.gdk_pointer_grab(xWindow,
+ false,
+ OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_RELEASE_MASK,
+ xWindow,
+ cursor,
+ OS.GDK_CURRENT_TIME);
+ lastCursor = cursor;
+}
+void ungrab() {
+ if (ptrGrabResult == OS.GDK_GRAB_SUCCESS)
+ OS.gdk_pointer_ungrab(OS.GDK_CURRENT_TIME);
+
+}
+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;
+}
+}
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
index 862665c731..226329cb51 100644
--- 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
@@ -1,35 +1,35 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class TreeItem extends Item {
- Tree parent;
- boolean grayed;
-
+
+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;
+ boolean grayed;
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Tree</code> or a <code>TreeItem</code>)
@@ -60,12 +60,12 @@ public class TreeItem extends Item {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public TreeItem (Tree parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, 0, -1);
-}
-
+public TreeItem (Tree parent, int style) {
+ super (parent, style);
+ this.parent = parent;
+ parent.createItem (this, 0, -1);
+}
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Tree</code> or a <code>TreeItem</code>),
@@ -97,13 +97,13 @@ public TreeItem (Tree parent, int style) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public TreeItem (Tree parent, int style, int index) {
- super (parent, style);
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- this.parent = parent;
- parent.createItem (this, 0, index);
-}
-
+public TreeItem (Tree parent, int style, int index) {
+ super (parent, style);
+ if (index < 0) error (SWT.ERROR_INVALID_RANGE);
+ this.parent = parent;
+ parent.createItem (this, 0, index);
+}
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Tree</code> or a <code>TreeItem</code>)
@@ -134,12 +134,12 @@ public TreeItem (Tree parent, int style, int index) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public TreeItem (TreeItem parentItem, int style) {
- super (checkNull (parentItem).parent, style);
- this.parent = parentItem.parent;
- parent.createItem (this, parentItem.handle, -1);
-}
-
+public TreeItem (TreeItem parentItem, int style) {
+ super (checkNull (parentItem).parent, style);
+ this.parent = parentItem.parent;
+ parent.createItem (this, parentItem.handle, -1);
+}
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Tree</code> or a <code>TreeItem</code>),
@@ -171,41 +171,41 @@ public TreeItem (TreeItem parentItem, int style) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public TreeItem (TreeItem parentItem, int style, int index) {
- super (checkNull (parentItem).parent, style);
- if (index < 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- this.parent = parentItem.parent;
- parent.createItem (this, parentItem.handle, index);
-}
-
-static TreeItem checkNull (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-/**
- * 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 ();
- int[] ptr = new int[1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, 3, ptr, -1);
- if (ptr [0] == 0) return parent.getBackground ();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (getDisplay (), gdkColor);
-}
-
+public TreeItem (TreeItem parentItem, int style, int index) {
+ super (checkNull (parentItem).parent, style);
+ if (index < 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ this.parent = parentItem.parent;
+ parent.createItem (this, parentItem.handle, index);
+}
+
+static TreeItem checkNull (TreeItem item) {
+ if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ return item;
+}
+
+/**
+ * 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 ();
+ int[] ptr = new int[1];
+ OS.gtk_tree_model_get (parent.modelHandle, handle, 3, ptr, -1);
+ if (ptr [0] == 0) return parent.getBackground ();
+ GdkColor gdkColor = new GdkColor ();
+ OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
+ return Color.gtk_new (getDisplay (), gdkColor);
+}
+
/**
* Returns a rectangle describing the receiver's size and location
* relative to its parent.
@@ -217,17 +217,17 @@ public Color getBackground () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Rectangle getBounds () {
- checkWidget ();
- int parentHandle = parent.handle;
- GdkRectangle rect = new GdkRectangle ();
- int column = OS.gtk_tree_view_get_column (parentHandle, 0);
- int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect);
- OS.gtk_tree_path_free (path);
- return new Rectangle (rect.x, rect.y, rect.width, rect.height);
-}
-
+public Rectangle getBounds () {
+ checkWidget ();
+ int parentHandle = parent.handle;
+ GdkRectangle rect = new GdkRectangle ();
+ int column = OS.gtk_tree_view_get_column (parentHandle, 0);
+ int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
+ OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect);
+ OS.gtk_tree_path_free (path);
+ return new Rectangle (rect.x, rect.y, rect.width, rect.height);
+}
+
/**
* Returns <code>true</code> if the receiver is checked,
* and false otherwise. When the parent does not have
@@ -241,19 +241,19 @@ public Rectangle getBounds () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean getChecked () {
- checkWidget();
- if ((parent.style & SWT.CHECK) == 0) return false;
- int [] ptr = new int [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, 5, ptr, -1);
- return ptr [0] != 0;
-}
-
-public Display getDisplay () {
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+public boolean getChecked () {
+ checkWidget();
+ if ((parent.style & SWT.CHECK) == 0) return false;
+ int [] ptr = new int [1];
+ OS.gtk_tree_model_get (parent.modelHandle, handle, 5, ptr, -1);
+ return ptr [0] != 0;
+}
+
+public Display getDisplay () {
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns <code>true</code> if the receiver is expanded,
* and false otherwise.
@@ -266,37 +266,37 @@ public Display getDisplay () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean getExpanded () {
- checkWidget();
- int 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 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 boolean getExpanded () {
+ checkWidget();
+ int 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 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 ();
- int [] ptr = new int [1];
- OS.gtk_tree_model_get (parent.modelHandle, handle, 2, ptr, -1);
- if (ptr [0]==0) return parent.getForeground();
- GdkColor gdkColor = new GdkColor ();
- OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
- return Color.gtk_new (getDisplay (), gdkColor);
-}
-
+public Color getForeground () {
+ checkWidget ();
+ int [] ptr = new int [1];
+ OS.gtk_tree_model_get (parent.modelHandle, handle, 2, ptr, -1);
+ if (ptr [0]==0) return parent.getForeground();
+ GdkColor gdkColor = new GdkColor ();
+ OS.memmove (gdkColor, ptr [0], GdkColor.sizeof);
+ return Color.gtk_new (getDisplay (), gdkColor);
+}
+
/**
* Returns <code>true</code> if the receiver is grayed,
* and false otherwise. When the parent does not have
@@ -310,12 +310,12 @@ public Color getForeground () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean getGrayed() {
- checkWidget();
- //NOT IMPLEMENTED
- return grayed;
-}
-
+public boolean getGrayed() {
+ checkWidget();
+ //NOT IMPLEMENTED
+ return grayed;
+}
+
/**
* Returns the number of items contained in the receiver
* that are direct item children of the receiver.
@@ -327,32 +327,32 @@ public boolean getGrayed() {
* <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 (parent.modelHandle, handle);
-}
-
-/**
- * Returns an 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 int getItemCount () {
+ checkWidget();
+ return OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle);
+}
+
+/**
+ * Returns an 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();
- return parent.getItems (handle);
-}
-
+public TreeItem [] getItems () {
+ checkWidget();
+ return parent.getItems (handle);
+}
+
/**
* Returns the receiver's parent, which must be a <code>Tree</code>.
*
@@ -363,11 +363,11 @@ public TreeItem [] getItems () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Tree getParent () {
- checkWidget();
- return parent;
-}
-
+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
@@ -380,35 +380,35 @@ public Tree getParent () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public TreeItem getParentItem () {
- checkWidget();
- int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
- if (OS.gtk_tree_path_get_depth (path) < 2) {
- OS.gtk_tree_path_free (path);
- return null;
- }
- OS.gtk_tree_path_up (path);
- int iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
- OS.gtk_tree_model_get_iter (parent.modelHandle, iter, path);
- int [] index = new int [1];
- OS.gtk_tree_model_get (parent.modelHandle, iter, 4, index, -1);
- OS.g_free (iter);
- OS.gtk_tree_path_free (path);
- return parent.items [index [0]];
-}
-
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (handle != 0) OS.g_free (handle);
- handle = 0;
- parent = null;
-}
-
+public TreeItem getParentItem () {
+ checkWidget();
+ int path = OS.gtk_tree_model_get_path (parent.modelHandle, handle);
+ if (OS.gtk_tree_path_get_depth (path) < 2) {
+ OS.gtk_tree_path_free (path);
+ return null;
+ }
+ OS.gtk_tree_path_up (path);
+ int iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
+ OS.gtk_tree_model_get_iter (parent.modelHandle, iter, path);
+ int [] index = new int [1];
+ OS.gtk_tree_model_get (parent.modelHandle, iter, 4, index, -1);
+ OS.g_free (iter);
+ OS.gtk_tree_path_free (path);
+ return parent.items [index [0]];
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ if (handle != 0) OS.g_free (handle);
+ handle = 0;
+ parent = null;
+}
+
/**
* Sets the receiver's background color to the color specified
* by the argument, or to the default system color for the item
@@ -427,15 +427,15 @@ void releaseWidget () {
* @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, 3, gdkColor, -1);
-}
-
+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, 3, gdkColor, -1);
+}
+
/**
* Sets the checked state of the receiver.
* <p>
@@ -447,12 +447,12 @@ public void setBackground (Color color) {
* <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, 5, checked, -1);
-}
-
+public void setChecked (boolean checked) {
+ checkWidget();
+ if ((parent.style & SWT.CHECK) == 0) return;
+ OS.gtk_tree_store_set (parent.modelHandle, handle, 5, checked, -1);
+}
+
/**
* Sets the grayed state of the receiver.
* <p>
@@ -464,12 +464,12 @@ public void setChecked (boolean checked) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setGrayed (boolean grayed) {
- checkWidget();
- //NOT IMPLEMENTED
- this.grayed = grayed;
-}
-
+public void setGrayed (boolean grayed) {
+ checkWidget();
+ //NOT IMPLEMENTED
+ this.grayed = grayed;
+}
+
/**
* Sets the expanded state of the receiver.
* <p>
@@ -481,21 +481,21 @@ public void setGrayed (boolean grayed) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setExpanded (boolean expanded) {
- checkWidget();
- int 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, ROW_EXPANDED);
- 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, ROW_EXPANDED);
- } else {
- OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ROW_COLLAPSED);
- 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, ROW_COLLAPSED);
- }
- OS.gtk_tree_path_free (path);
-}
-
+public void setExpanded (boolean expanded) {
+ checkWidget();
+ int 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, ROW_EXPANDED);
+ 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, ROW_EXPANDED);
+ } else {
+ OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ROW_COLLAPSED);
+ 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, ROW_COLLAPSED);
+ }
+ OS.gtk_tree_path_free (path);
+}
+
/**
* Sets the receiver's foreground color to the color specified
* by the argument, or to the default system color for the item
@@ -516,43 +516,43 @@ public void setExpanded (boolean expanded) {
* @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, 2, gdkColor, -1);
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- super.setImage (image);
- int 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);
- }
- OS.gtk_tree_store_set (parent.modelHandle, handle, 1, pixbuf, -1);
-}
-
+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, 2, gdkColor, -1);
+}
+
+public void setImage (Image image) {
+ checkWidget();
+ if (image != null && image.isDisposed()) {
+ error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ super.setImage (image);
+ int 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);
+ }
+ OS.gtk_tree_store_set (parent.modelHandle, handle, 1, pixbuf, -1);
+}
+
/**
* This label will be displayed to the right of the bitmap,
* or, if the receiver doesn't have a bitmap to the right of
* the horizontal hierarchy connector line.
*/
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- byte[] buffer = Converter.wcsToMbcs (null, string, true);
- OS.gtk_tree_store_set (parent.modelHandle, handle, 0, buffer, -1);
-}
-
-}
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ super.setText (string);
+ byte[] buffer = Converter.wcsToMbcs (null, string, true);
+ OS.gtk_tree_store_set (parent.modelHandle, handle, 0, buffer, -1);
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/WidgetTable.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/WidgetTable.java
index 91b7a1e07a..0f0bc86331 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/WidgetTable.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/WidgetTable.java
@@ -1,103 +1,103 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-class WidgetTable {
- static int FreeSlot = 0;
- static int GrowSize = 1024;
- static int [] IndexTable = new int [GrowSize];
- static Widget [] WidgetTable = new Widget [GrowSize];
- static final int SWT_OBJECT_INDEX;
- static {
- byte [] buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX", true);
- SWT_OBJECT_INDEX = OS.g_quark_from_string (buffer);
- 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;
- int index = OS.g_object_get_qdata (handle, SWT_OBJECT_INDEX) - 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;
- }
- 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;
-}
-
-public static synchronized Widget remove (int handle) {
- if (handle == 0) return null;
- Widget widget = null;
- int index = 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;
-}
-
-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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.gtk.*;
+
+class WidgetTable {
+ static int FreeSlot = 0;
+ static int GrowSize = 1024;
+ static int [] IndexTable = new int [GrowSize];
+ static Widget [] WidgetTable = new Widget [GrowSize];
+ static final int SWT_OBJECT_INDEX;
+ static {
+ byte [] buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX", true);
+ SWT_OBJECT_INDEX = OS.g_quark_from_string (buffer);
+ 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;
+ int index = OS.g_object_get_qdata (handle, SWT_OBJECT_INDEX) - 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;
+ }
+ 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;
+}
+
+public static synchronized Widget remove (int handle) {
+ if (handle == 0) return null;
+ Widget widget = null;
+ int index = 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;
+}
+
+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/gtk1x/org/eclipse/swt/graphics/DefaultGtkStyle.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/DefaultGtkStyle.java
index e45c97f342..0b6860b5fd 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/DefaultGtkStyle.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/DefaultGtkStyle.java
@@ -1,118 +1,118 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-
-class DefaultGtkStyle {
-
- private static DefaultGtkStyle instance = null;
- private GtkStyle style = null;
- private int defaultFont;
-
- public Color foregroundColorNORMAL() {
- return new Color(null,
- ((short)0xFF00 & style.fg0_red)>>8,
- ((short)0xFF00 & style.fg0_green)>>8,
- ((short)0xFF00 & style.fg0_blue)>>8);
- }
-
- public Color backgroundColorNORMAL() {
- return new Color(null,
- ((short)0xFF00 & style.bg0_red)>>8,
- ((short)0xFF00 & style.bg0_green)>>8,
- ((short)0xFF00 & style.bg0_blue)>>8);
- }
-
- public Color foregroundColorACTIVE() {
- return new Color(null,
- ((short)0xFF00 & style.fg1_red)>>8,
- ((short)0xFF00 & style.fg1_green)>>8,
- ((short)0xFF00 & style.fg1_blue)>>8);
- }
-
- public Color backgroundColorACTIVE() {
- return new Color(null,
- ((short)0xFF00 & style.bg1_red)>>8,
- ((short)0xFF00 & style.bg1_green)>>8,
- ((short)0xFF00 & style.bg1_blue)>>8);
- }
-
- public Color foregroundColorPRELIGHT() {
- return new Color(null,
- ((short)0xFF00 & style.fg2_red)>>8,
- ((short)0xFF00 & style.fg2_green)>>8,
- ((short)0xFF00 & style.fg2_blue)>>8);
- }
-
- public Color backgroundColorPRELIGHT() {
- return new Color(null,
- ((short)0xFF00 & style.bg2_red)>>8,
- ((short)0xFF00 & style.bg2_green)>>8,
- ((short)0xFF00 & style.bg2_blue)>>8);
- }
-
- public Color foregroundColorSELECTED() {
- return new Color(null,
- ((short)0xFF00 & style.fg3_red)>>8,
- ((short)0xFF00 & style.fg3_green)>>8,
- ((short)0xFF00 & style.fg3_blue)>>8);
- }
-
- public Color backgroundColorSELECTED() {
- return new Color(null,
- ((short)0xFF00 & style.bg3_red)>>8,
- ((short)0xFF00 & style.bg3_green)>>8,
- ((short)0xFF00 & style.bg3_blue)>>8);
- }
-
- public Color foregroundColorINSENSITIVE() {
- return new Color(null,
- ((short)0xFF00 & style.fg4_red)>>8,
- ((short)0xFF00 & style.fg4_green)>>8,
- ((short)0xFF00 & style.fg4_blue)>>8);
- }
-
- public Color backgroundColorINSENSITIVE() {
- return new Color(null,
- ((short)0xFF00 & style.bg4_red)>>8,
- ((short)0xFF00 & style.bg4_green)>>8,
- ((short)0xFF00 & style.bg4_blue)>>8);
- }
-
- public int loadDefaultFont() {
- if (defaultFont == 0) {
- int fnames = Font.getFontNameList(style.font);
- int slength = OS.g_slist_length(fnames);
- if (slength < 1) SWT.error(SWT.ERROR_UNSPECIFIED);
- int name1 = OS.g_slist_nth_data(fnames, 0);
- int length = OS.strlen(name1);
- byte [] buffer1 = new byte[length];
- OS.memmove(buffer1, name1, length);
- defaultFont = OS.gdk_font_load(buffer1);
- if (defaultFont==0) SWT.error(SWT.ERROR_UNSPECIFIED);
- GdkFont gdkFont = new GdkFont();
- OS.memmove(gdkFont, defaultFont, GdkFont.sizeof);
- if (gdkFont.type != OS.GDK_FONT_FONT) SWT.error(SWT.ERROR_UNSPECIFIED);
- }
- return defaultFont;
- }
-
- public static DefaultGtkStyle instance() {
- if (instance==null) instance = new DefaultGtkStyle();
- return instance;
- }
-
- private DefaultGtkStyle() {
- style = new GtkStyle();
- OS.memmove(style, OS.gtk_widget_get_default_style(), GtkStyle.sizeof);
- }
-
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.internal.gtk.*;
+
+class DefaultGtkStyle {
+
+ private static DefaultGtkStyle instance = null;
+ private GtkStyle style = null;
+ private int defaultFont;
+
+ public Color foregroundColorNORMAL() {
+ return new Color(null,
+ ((short)0xFF00 & style.fg0_red)>>8,
+ ((short)0xFF00 & style.fg0_green)>>8,
+ ((short)0xFF00 & style.fg0_blue)>>8);
+ }
+
+ public Color backgroundColorNORMAL() {
+ return new Color(null,
+ ((short)0xFF00 & style.bg0_red)>>8,
+ ((short)0xFF00 & style.bg0_green)>>8,
+ ((short)0xFF00 & style.bg0_blue)>>8);
+ }
+
+ public Color foregroundColorACTIVE() {
+ return new Color(null,
+ ((short)0xFF00 & style.fg1_red)>>8,
+ ((short)0xFF00 & style.fg1_green)>>8,
+ ((short)0xFF00 & style.fg1_blue)>>8);
+ }
+
+ public Color backgroundColorACTIVE() {
+ return new Color(null,
+ ((short)0xFF00 & style.bg1_red)>>8,
+ ((short)0xFF00 & style.bg1_green)>>8,
+ ((short)0xFF00 & style.bg1_blue)>>8);
+ }
+
+ public Color foregroundColorPRELIGHT() {
+ return new Color(null,
+ ((short)0xFF00 & style.fg2_red)>>8,
+ ((short)0xFF00 & style.fg2_green)>>8,
+ ((short)0xFF00 & style.fg2_blue)>>8);
+ }
+
+ public Color backgroundColorPRELIGHT() {
+ return new Color(null,
+ ((short)0xFF00 & style.bg2_red)>>8,
+ ((short)0xFF00 & style.bg2_green)>>8,
+ ((short)0xFF00 & style.bg2_blue)>>8);
+ }
+
+ public Color foregroundColorSELECTED() {
+ return new Color(null,
+ ((short)0xFF00 & style.fg3_red)>>8,
+ ((short)0xFF00 & style.fg3_green)>>8,
+ ((short)0xFF00 & style.fg3_blue)>>8);
+ }
+
+ public Color backgroundColorSELECTED() {
+ return new Color(null,
+ ((short)0xFF00 & style.bg3_red)>>8,
+ ((short)0xFF00 & style.bg3_green)>>8,
+ ((short)0xFF00 & style.bg3_blue)>>8);
+ }
+
+ public Color foregroundColorINSENSITIVE() {
+ return new Color(null,
+ ((short)0xFF00 & style.fg4_red)>>8,
+ ((short)0xFF00 & style.fg4_green)>>8,
+ ((short)0xFF00 & style.fg4_blue)>>8);
+ }
+
+ public Color backgroundColorINSENSITIVE() {
+ return new Color(null,
+ ((short)0xFF00 & style.bg4_red)>>8,
+ ((short)0xFF00 & style.bg4_green)>>8,
+ ((short)0xFF00 & style.bg4_blue)>>8);
+ }
+
+ public int loadDefaultFont() {
+ if (defaultFont == 0) {
+ int fnames = Font.getFontNameList(style.font);
+ int slength = OS.g_slist_length(fnames);
+ if (slength < 1) SWT.error(SWT.ERROR_UNSPECIFIED);
+ int name1 = OS.g_slist_nth_data(fnames, 0);
+ int length = OS.strlen(name1);
+ byte [] buffer1 = new byte[length];
+ OS.memmove(buffer1, name1, length);
+ defaultFont = OS.gdk_font_load(buffer1);
+ if (defaultFont==0) SWT.error(SWT.ERROR_UNSPECIFIED);
+ GdkFont gdkFont = new GdkFont();
+ OS.memmove(gdkFont, defaultFont, GdkFont.sizeof);
+ if (gdkFont.type != OS.GDK_FONT_FONT) SWT.error(SWT.ERROR_UNSPECIFIED);
+ }
+ return defaultFont;
+ }
+
+ public static DefaultGtkStyle instance() {
+ if (instance==null) instance = new DefaultGtkStyle();
+ return instance;
+ }
+
+ private DefaultGtkStyle() {
+ style = new GtkStyle();
+ OS.memmove(style, OS.gtk_widget_get_default_style(), GtkStyle.sizeof);
+ }
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontData.java
index 5a7775fcef..7ee07bde3f 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontData.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontData.java
@@ -1,121 +1,121 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe operating system fonts.
- * Only the public API of this type is platform independent.
- * <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.
- */
- public String foundry;
- /**
- * The common name of the font
- * Warning: This field is platform dependent.
- */
- public String fontFamily;
- /**
- * The weight ("normal", "bold")
- * Warning: This field is platform dependent.
- */
- public String weight;
- /**
- * The slant ("o" for oblique, "i" for italic)
- * Warning: This field is platform dependent.
- */
- public String slant;
- /**
- * The set width of the font
- * Warning: This field is platform dependent.
- */
- public String setWidth;
- /**
- * Additional font styles
- * Warning: This field is platform dependent.
- */
- public String addStyle;
- /**
- * The height of the font in pixels
- * Warning: This field is platform dependent.
- */
- public int pixels;
- /**
- * The height of the font in tenths of a point
- * Warning: This field is platform dependent.
- */
- public int points;
- /**
- * The horizontal screen resolution for which the font was designed
- * Warning: This field is platform dependent.
- */
- public int horizontalResolution;
- /**
- * The vertical screen resolution for which the font was designed
- * Warning: This field is platform dependent.
- */
- public int verticalResolution;
- /**
- * The font spacing ("m" for monospace, "p" for proportional)
- * Warning: This field is platform dependent.
- */
- public String spacing;
- /**
- * The average character width for the font
- * Warning: This field is platform dependent.
- */
- public int averageWidth;
- /**
- * The ISO character set registry
- * Warning: This field is platform dependent.
- */
- public String characterSetRegistry;
- /**
- * The ISO character set name
- * Warning: This field is platform dependent.
- */
- public String characterSetName;
- /**
- * The locales of the font
- * (Warning: These fields are platform dependent)
- */
- String lang, country, variant;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+
+/**
+ * Instances of this class describe operating system fonts.
+ * Only the public API of this type is platform independent.
+ * <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.
+ */
+ public String foundry;
+ /**
+ * The common name of the font
+ * Warning: This field is platform dependent.
+ */
+ public String fontFamily;
+ /**
+ * The weight ("normal", "bold")
+ * Warning: This field is platform dependent.
+ */
+ public String weight;
+ /**
+ * The slant ("o" for oblique, "i" for italic)
+ * Warning: This field is platform dependent.
+ */
+ public String slant;
+ /**
+ * The set width of the font
+ * Warning: This field is platform dependent.
+ */
+ public String setWidth;
+ /**
+ * Additional font styles
+ * Warning: This field is platform dependent.
+ */
+ public String addStyle;
+ /**
+ * The height of the font in pixels
+ * Warning: This field is platform dependent.
+ */
+ public int pixels;
+ /**
+ * The height of the font in tenths of a point
+ * Warning: This field is platform dependent.
+ */
+ public int points;
+ /**
+ * The horizontal screen resolution for which the font was designed
+ * Warning: This field is platform dependent.
+ */
+ public int horizontalResolution;
+ /**
+ * The vertical screen resolution for which the font was designed
+ * Warning: This field is platform dependent.
+ */
+ public int verticalResolution;
+ /**
+ * The font spacing ("m" for monospace, "p" for proportional)
+ * Warning: This field is platform dependent.
+ */
+ public String spacing;
+ /**
+ * The average character width for the font
+ * Warning: This field is platform dependent.
+ */
+ public int averageWidth;
+ /**
+ * The ISO character set registry
+ * Warning: This field is platform dependent.
+ */
+ public String characterSetRegistry;
+ /**
+ * The ISO character set name
+ * Warning: This field is platform dependent.
+ */
+ public String characterSetName;
+ /**
+ * The locales of the font
+ * (Warning: These fields are platform dependent)
+ */
+ String lang, country, variant;
+
/**
* Constructs a new un-initialized font data.
*/
-public FontData () {
-}
+public FontData () {
+}
/**
* Constructs a new FontData given a string representation
* in the form generated by the <code>FontData.toString</code>
@@ -135,75 +135,75 @@ public FontData () {
*
* @see #toString
*/
-public FontData(String string) {
- if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- int start = 0;
- int end = string.indexOf('|');
- if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
- String version1 = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
- String name = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
- int height = 0;
- try {
- height = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
- int style = 0;
- try {
- style = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- 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);
-}
+public FontData(String string) {
+ if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
+ int start = 0;
+ int end = string.indexOf('|');
+ if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
+ String version1 = string.substring(start, end);
+
+ start = end + 1;
+ end = string.indexOf('|', start);
+ if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
+ String name = string.substring(start, end);
+
+ start = end + 1;
+ end = string.indexOf('|', start);
+ if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
+ int height = 0;
+ try {
+ height = Integer.parseInt(string.substring(start, end));
+ } catch (NumberFormatException e) {
+ error(SWT.ERROR_NULL_ARGUMENT);
+ }
+
+ start = end + 1;
+ end = string.indexOf('|', start);
+ if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
+ int style = 0;
+ try {
+ style = Integer.parseInt(string.substring(start, end));
+ } catch (NumberFormatException e) {
+ 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,
@@ -218,119 +218,119 @@ public FontData(String string) {
* <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) 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;
- if ((style & SWT.BOLD) != 0) {
- weight = "bold";
- } else {
- weight = "medium";
- }
- if ((style & SWT.ITALIC) != 0) {
- slant = "i";
- } else {
- slant = "r";
- }
-}
-
-
-
-/*
- * Public getters
- */
-
-/**
- * Returns the height of the receiver in points.
- *
- * @return the height of this FontData
- *
- * @see #setHeight
- */
-public int getHeight() {
- return points / 10;
-}
-
-/**
- * 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.equals("bold"))
- style |= SWT.BOLD;
- if (slant.equals("i"))
- style |= SWT.ITALIC;
- return style;
-}
-
-/**
- * We need this in FontDialog, so we can't just get rid of it or make it private.
- */
-public String gtk_getXlfd() { return getXlfd(); }
-
-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;
-// The following line has been intentionally commented.
-// we don not know the exact average width as in the font definition,
-// so if someone tries to get a similar font, they'd get something weird
-// if (averageWidth != 0) s12 = Integer.toString(averageWidth);
- if (characterSetRegistry != null) s13 = characterSetRegistry;
- if (characterSetName != null) s14 = characterSetName;
-
- String xlfd = "-" + s1+ "-" + s2 + "-" + s3 + "-" + s4 + "-" + s5 + "-" + s6 + "-" + s7 + "-" + s8 + "-"
- + s9 + "-" + s10 + "-" + s11 + "-" + s12 + "-" + s13 + "-" + s14;
- return xlfd;
-}
-public static FontData gtk_new(String xlfd) {
- FontData fontData = new FontData();
- fontData.setXlfd(xlfd);
- return fontData;
-}
+public FontData(String name, int height, int style) {
+ if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (height < 0) 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;
+ if ((style & SWT.BOLD) != 0) {
+ weight = "bold";
+ } else {
+ weight = "medium";
+ }
+ if ((style & SWT.ITALIC) != 0) {
+ slant = "i";
+ } else {
+ slant = "r";
+ }
+}
+
+
+
+/*
+ * Public getters
+ */
+
+/**
+ * Returns the height of the receiver in points.
+ *
+ * @return the height of this FontData
+ *
+ * @see #setHeight
+ */
+public int getHeight() {
+ return points / 10;
+}
+
+/**
+ * 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.equals("bold"))
+ style |= SWT.BOLD;
+ if (slant.equals("i"))
+ style |= SWT.ITALIC;
+ return style;
+}
+
+/**
+ * We need this in FontDialog, so we can't just get rid of it or make it private.
+ */
+public String gtk_getXlfd() { return getXlfd(); }
+
+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;
+// The following line has been intentionally commented.
+// we don not know the exact average width as in the font definition,
+// so if someone tries to get a similar font, they'd get something weird
+// if (averageWidth != 0) s12 = Integer.toString(averageWidth);
+ if (characterSetRegistry != null) s13 = characterSetRegistry;
+ if (characterSetName != null) s14 = characterSetName;
+
+ String xlfd = "-" + s1+ "-" + s2 + "-" + s3 + "-" + s4 + "-" + s5 + "-" + s6 + "-" + s7 + "-" + s8 + "-"
+ + s9 + "-" + s10 + "-" + s11 + "-" + s12 + "-" + s13 + "-" + s14;
+ return xlfd;
+}
+public static FontData gtk_new(String xlfd) {
+ FontData fontData = new FontData();
+ fontData.setXlfd(xlfd);
+ return fontData;
+}
/**
* Returns an integer hash code for the receiver. Any two
* objects which return <code>true</code> when passed to
@@ -341,9 +341,9 @@ public static FontData gtk_new(String xlfd) {
*
* @see #equals
*/
-public int hashCode () {
- return getXlfd().hashCode();
-}
+public int hashCode () {
+ return getXlfd().hashCode();
+}
/**
* Sets the height of the receiver. The parameter is
* specified in terms of points, where a point is one
@@ -357,47 +357,47 @@ public int hashCode () {
*
* @see #getHeight
*/
-public void setHeight(int height) {
- if (height < 0) error(SWT.ERROR_INVALID_ARGUMENT);
- points = height * 10;
-}
-
-/**
- * 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 which 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);
- }
-}
+public void setHeight(int height) {
+ if (height < 0) error(SWT.ERROR_INVALID_ARGUMENT);
+ points = height * 10;
+}
+
+/**
+ * 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 which 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>
@@ -423,16 +423,16 @@ public void setLocale(String locale) {
*
* @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;
- }
-}
+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 style of the receiver to the argument which must
* be a bitwise OR of one or more of the <code>SWT</code>
@@ -442,79 +442,79 @@ public void setName(String name) {
*
* @see #getStyle
*/
-public void setStyle(int style) {
- if ((style & SWT.BOLD) == SWT.BOLD)
- weight = "bold";
- else
- weight = "medium";
- if ((style & SWT.ITALIC) == SWT.ITALIC)
- slant = "i";
- else
- slant = "r";
-}
-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("*"))
- 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;
-}
+public void setStyle(int style) {
+ if ((style & SWT.BOLD) == SWT.BOLD)
+ weight = "bold";
+ else
+ weight = "medium";
+ if ((style & SWT.ITALIC) == SWT.ITALIC)
+ slant = "i";
+ else
+ slant = "r";
+}
+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("*"))
+ 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
@@ -524,11 +524,11 @@ void setXlfd(String xlfd) {
*
* @see FontData
*/
-public String toString() {
- return "1|" + fontFamily + "|" + getHeight() + "|" + getStyle() + "|" +
- "GTK|1|" + getXlfd();
-}
-
+public String toString() {
+ return "1|" + fontFamily + "|" + getHeight() + "|" + getStyle() + "|" +
+ "GTK|1|" + getXlfd();
+}
+
/**
* Compares the argument to the receiver, and returns true
* if they represent the <em>same</em> object using a class
@@ -539,11 +539,11 @@ public String toString() {
*
* @see #hashCode
*/
-public boolean equals (Object object) {
- return (object == this) || ((object instanceof FontData) &&
- getXlfd().equals(((FontData)object).getXlfd()));
-}
-void error(int code) {
- throw new SWTError(code);
-}
-}
+public boolean equals (Object object) {
+ return (object == this) || ((object instanceof FontData) &&
+ getXlfd().equals(((FontData)object).getXlfd()));
+}
+void error(int code) {
+ throw new SWTError(code);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java
index b813e7c3e2..0d1cc835b4 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java
@@ -1,14 +1,14 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.gtk.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.gtk.*;
+
/**
* Instances of this class provide measurement information
* about fonts including ascent, descent, height, leading
@@ -18,11 +18,11 @@ import org.eclipse.swt.internal.gtk.*;
*
* @see GC#getFontMetrics
*/
-
-public final class FontMetrics {
- int ascent, descent, averageCharWidth, leading, height;
-FontMetrics() {
-}
+
+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
@@ -33,14 +33,14 @@ FontMetrics() {
*
* @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;
-}
+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
@@ -49,18 +49,18 @@ public boolean equals (Object object) {
*
* @return the ascent of the font
*/
-public int getAscent() {
- return ascent;
-}
+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;
-}
+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
@@ -69,9 +69,9 @@ public int getAverageCharWidth() {
*
* @return the descent of the font
*/
-public int getDescent() {
- return descent;
-}
+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
@@ -83,9 +83,9 @@ public int getDescent() {
* @see #getDescent
* @see #getLeading
*/
-public int getHeight() {
- return height;
-}
+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
@@ -93,21 +93,21 @@ public int getHeight() {
*
* @return the leading space of the font
*/
-public int getLeading() {
- return leading;
-}
-public static FontMetrics gtk_new(int fontHandle) {
- GdkFont f = new GdkFont();
- OS.memmove (f, fontHandle, GdkFont.sizeof);
-
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.ascent = f.ascent;
- fontMetrics.descent = f.descent;
- fontMetrics.averageCharWidth = OS.gdk_char_width(fontHandle, (byte)'a');
- fontMetrics.leading = 3;
- fontMetrics.height = fontMetrics.ascent+fontMetrics.descent+3;
- return fontMetrics;
-}
+public int getLeading() {
+ return leading;
+}
+public static FontMetrics gtk_new(int fontHandle) {
+ GdkFont f = new GdkFont();
+ OS.memmove (f, fontHandle, GdkFont.sizeof);
+
+ FontMetrics fontMetrics = new FontMetrics();
+ fontMetrics.ascent = f.ascent;
+ fontMetrics.descent = f.descent;
+ fontMetrics.averageCharWidth = OS.gdk_char_width(fontHandle, (byte)'a');
+ fontMetrics.leading = 3;
+ fontMetrics.height = fontMetrics.ascent+fontMetrics.descent+3;
+ return fontMetrics;
+}
/**
* Returns an integer hash code for the receiver. Any two
* objects which return <code>true</code> when passed to
@@ -118,7 +118,7 @@ public static FontMetrics gtk_new(int fontHandle) {
*
* @see #equals
*/
-public int hashCode() {
- return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
-}
-}
+public int hashCode() {
+ return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GCData.java
index a974c8f92a..1ea5305461 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GCData.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GCData.java
@@ -1,14 +1,14 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+
/**
* Instances of this class are descriptions of GCs in terms
* of unallocated platform-specific data fields.
@@ -21,10 +21,10 @@ import org.eclipse.swt.*;
*
* @private
*/
-public final class GCData {
- public Image image;
- public int drawable;
- public int clipRgn;
- public int lineStyle = SWT.LINE_SOLID;
- public int renderTable;
+public final class GCData {
+ public Image image;
+ public int drawable;
+ public int clipRgn;
+ public int lineStyle = SWT.LINE_SOLID;
+ public int renderTable;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Region.java
index e94f7cf2d3..b0eadc948d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Region.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Region.java
@@ -1,15 +1,15 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -20,21 +20,21 @@ import org.eclipse.swt.*;
* when those instances are no longer required.
* </p>
*/
-public final class Region {
+public final class Region {
/**
* the OS resource for the region
* (Warning: This field is platform dependent)
*/
- public int handle;
+ public int handle;
/**
* Constructs a new empty region.
*/
-public Region() {
- handle = OS.gdk_region_new();
-}
-Region(int handle) {
- this.handle = handle;
-}
+public Region() {
+ handle = OS.gdk_region_new();
+}
+Region(int handle) {
+ this.handle = handle;
+}
/**
* Adds the given rectangle to the collection of rectangles
* the receiver maintains to describe its area.
@@ -49,22 +49,22 @@ Region(int handle) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public void add(Rectangle rect) {
- if (rect == null) error(SWT.ERROR_NULL_ARGUMENT);
- if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- GdkRectangle gdkRect = new GdkRectangle();
- gdkRect.x = (short)rect.x;
- gdkRect.y = (short)rect.y;
- gdkRect.width = (short)rect.width;
- gdkRect.height = (short)rect.height;
- int hOld = handle;
- /**
- * Feature in GDK. Due to the way the GDK region calls work,
- * we have to reassign the handle and destroy the old one.
- */
- handle = OS.gdk_region_union_with_rect(handle, gdkRect);
- OS.gdk_region_destroy(hOld);
-}
+public void add(Rectangle rect) {
+ if (rect == null) error(SWT.ERROR_NULL_ARGUMENT);
+ if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ GdkRectangle gdkRect = new GdkRectangle();
+ gdkRect.x = (short)rect.x;
+ gdkRect.y = (short)rect.y;
+ gdkRect.width = (short)rect.width;
+ gdkRect.height = (short)rect.height;
+ int hOld = handle;
+ /**
+ * Feature in GDK. Due to the way the GDK region calls work,
+ * we have to reassign the handle and destroy the old one.
+ */
+ handle = OS.gdk_region_union_with_rect(handle, gdkRect);
+ OS.gdk_region_destroy(hOld);
+}
/**
* Adds all of the rectangles which make up the area covered
* by the argument to the collection of rectangles the receiver
@@ -80,16 +80,16 @@ public void add(Rectangle rect) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public void add(Region region) {
- if (region == null) error(SWT.ERROR_NULL_ARGUMENT);
- /**
- * Feature in GDK. Due to the way the GDK region calls work,
- * we have to reassign the handle and destroy the old one.
- */
- int hOld = handle;
- handle = OS.gdk_regions_union(handle, region.handle);
- OS.gdk_region_destroy(hOld);
-}
+public void add(Region region) {
+ if (region == null) error(SWT.ERROR_NULL_ARGUMENT);
+ /**
+ * Feature in GDK. Due to the way the GDK region calls work,
+ * we have to reassign the handle and destroy the old one.
+ */
+ int hOld = handle;
+ handle = OS.gdk_regions_union(handle, region.handle);
+ OS.gdk_region_destroy(hOld);
+}
/**
* Returns <code>true</code> if the point specified by the
* arguments is inside the area specified by the receiver,
@@ -103,9 +103,9 @@ public void add(Region region) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public boolean contains(int x, int y) {
- return OS.gdk_region_point_in(handle, x, y);
-}
+public boolean contains(int x, int y) {
+ 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>
@@ -121,19 +121,19 @@ public boolean contains(int x, int y) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public boolean contains(Point pt) {
- if (pt == null) error(SWT.ERROR_NULL_ARGUMENT);
- return contains(pt.x, pt.y);
-}
+public boolean contains(Point pt) {
+ if (pt == null) 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) OS.gdk_region_destroy(handle);
- handle = 0;
-}
+public void dispose() {
+ if (handle != 0) OS.gdk_region_destroy(handle);
+ handle = 0;
+}
/**
* Compares the argument to the receiver, and returns true
* if they represent the <em>same</em> object using a class
@@ -144,17 +144,17 @@ public void dispose() {
*
* @see #hashCode
*/
-public boolean equals(Object object) {
- if (this == object) return true;
- if (!(object instanceof Region)) return false;
- int xRegion = ((Region)object).handle;
- if (handle == xRegion) return true;
- if (xRegion == 0) return false;
- return OS.gdk_region_equal(handle, xRegion);
-}
-void error(int code) {
- throw new SWTError(code);
-}
+public boolean equals(Object object) {
+ if (this == object) return true;
+ if (!(object instanceof Region)) return false;
+ int xRegion = ((Region)object).handle;
+ if (handle == xRegion) return true;
+ if (xRegion == 0) return false;
+ return OS.gdk_region_equal(handle, xRegion);
+}
+void error(int code) {
+ throw new SWTError(code);
+}
/**
* Returns a rectangle which represents the rectangular
* union of the collection of rectangles the receiver
@@ -168,14 +168,14 @@ void error(int code) {
*
* @see Rectangle#union
*/
-public Rectangle getBounds() {
- GdkRectangle rect = new GdkRectangle();
- OS.gdk_region_get_clipbox(handle, rect);
- return new Rectangle(rect.x, rect.y, rect.width, rect.height);
-}
-public static Region gtk_new(int handle) {
- return new Region(handle);
-}
+public Rectangle getBounds() {
+ GdkRectangle rect = new GdkRectangle();
+ OS.gdk_region_get_clipbox(handle, rect);
+ return new Rectangle(rect.x, rect.y, rect.width, rect.height);
+}
+public static Region gtk_new(int handle) {
+ return new Region(handle);
+}
/**
* Returns an integer hash code for the receiver. Any two
* objects which return <code>true</code> when passed to
@@ -186,9 +186,9 @@ public static Region gtk_new(int handle) {
*
* @see #equals
*/
-public int hashCode() {
- return handle;
-}
+public int hashCode() {
+ return handle;
+}
/**
* Returns <code>true</code> if the rectangle described by the
* arguments intersects with any of the rectangles the receiver
@@ -206,14 +206,14 @@ public int hashCode() {
*
* @see Rectangle#intersects
*/
-public boolean intersects (int x, int y, int width, int height) {
- GdkRectangle osRect = new GdkRectangle();
- osRect.x = (short)x;
- osRect.y = (short)y;
- osRect.width = (short)width;
- osRect.height = (short)height;
- return OS.gdk_region_rect_in(handle, osRect) != OS.GDK_OVERLAP_RECTANGLE_OUT;
-}
+public boolean intersects (int x, int y, int width, int height) {
+ GdkRectangle osRect = new GdkRectangle();
+ osRect.x = (short)x;
+ osRect.y = (short)y;
+ osRect.width = (short)width;
+ osRect.height = (short)height;
+ return OS.gdk_region_rect_in(handle, osRect) != OS.GDK_OVERLAP_RECTANGLE_OUT;
+}
/**
* Returns <code>true</code> if the given rectangle intersects
* with any of the rectangles the receiver mainains to describe
@@ -231,10 +231,10 @@ public boolean intersects (int x, int y, int width, int height) {
*
* @see Rectangle#intersects
*/
-public boolean intersects(Rectangle rect) {
- if (rect == null) error(SWT.ERROR_NULL_ARGUMENT);
- return intersects(rect.x, rect.y, rect.width, rect.height);
-}
+public boolean intersects(Rectangle rect) {
+ if (rect == null) 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.
@@ -245,9 +245,9 @@ public boolean intersects(Rectangle rect) {
*
* @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
*/
-public boolean isDisposed() {
- return handle == 0;
-}
+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
@@ -259,17 +259,17 @@ public boolean isDisposed() {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public boolean isEmpty() {
- return OS.gdk_region_empty(handle);
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
-}
+public boolean isEmpty() {
+ return OS.gdk_region_empty(handle);
+}
+/**
+ * Returns a string containing a concise, human-readable
+ * description of the receiver.
+ *
+ * @return a string representation of the receiver
+ */
+public String toString () {
+ if (isDisposed()) return "Region {*DISPOSED*}";
+ return "Region {" + handle + "}";
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/internal/Converter.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/internal/Converter.java
index 642aaa1fef..0efeadd167 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/internal/Converter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/internal/Converter.java
@@ -1,12 +1,12 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
/**
* This class implements the conversions between unicode characters
* and the <em>platform supported</em> representation for characters.
@@ -14,59 +14,59 @@ package org.eclipse.swt.internal;
* 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 char [] NullCharArray = new char [1];
- public static final byte [] EmptyByteArray = new byte [0];
- public static final char [] EmptyCharArray = new char [0];
+ */
+public final class Converter {
+ public static final byte [] NullByteArray = new byte [1];
+ public static final char [] NullCharArray = new char [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 null;
-}
-static boolean is7BitAscii (byte [] buffer) {
- for (int i=0; i<buffer.length; i++) {
- if ((buffer [i] & 0xFF) > 0x7F) return false;
- }
- return true;
-}
-static boolean is7BitAscii (char [] buffer) {
- for (int i=0; i<buffer.length; i++) {
- if (buffer [i] > 0x7F) return false;
- }
- return true;
-}
-public static char [] mbcsToWcs (String codePage, byte [] buffer) {
- //SLOW AND BOGUS
- return new String (buffer).toCharArray ();
-}
-/* TEMPORARY CODE */
-public static byte [] wcsToMbcs (String codePage, String string) {
- return wcsToMbcs (codePage, string, false);
-}
-public static byte [] wcsToMbcs (String codePage, String string, boolean terminate) {
- //SLOW AND BOGUS
- int count = string.length ();
- if (terminate) count++;
- char [] buffer = new char [count];
- string.getChars (0, string.length (), buffer, 0);
- return wcsToMbcs (codePage, buffer, false);
-}
-/* TEMPORARY CODE */
-public static byte [] wcsToMbcs (String codePage, char [] buffer) {
- return wcsToMbcs (codePage, buffer, false);
-}
-public static byte [] wcsToMbcs (String codePage, char [] buffer, boolean terminate) {
- //SLOW AND BOGUS
- if (!terminate) return new String (buffer).getBytes ();
- byte [] buffer1 = new String (buffer).getBytes ();
- byte [] buffer2 = new byte [buffer1.length + 1];
- System.arraycopy (buffer1, 0, buffer2, 0, buffer1.length);
- return buffer2;
-}
-}
+public static String defaultCodePage () {
+ return null;
+}
+static boolean is7BitAscii (byte [] buffer) {
+ for (int i=0; i<buffer.length; i++) {
+ if ((buffer [i] & 0xFF) > 0x7F) return false;
+ }
+ return true;
+}
+static boolean is7BitAscii (char [] buffer) {
+ for (int i=0; i<buffer.length; i++) {
+ if (buffer [i] > 0x7F) return false;
+ }
+ return true;
+}
+public static char [] mbcsToWcs (String codePage, byte [] buffer) {
+ //SLOW AND BOGUS
+ return new String (buffer).toCharArray ();
+}
+/* TEMPORARY CODE */
+public static byte [] wcsToMbcs (String codePage, String string) {
+ return wcsToMbcs (codePage, string, false);
+}
+public static byte [] wcsToMbcs (String codePage, String string, boolean terminate) {
+ //SLOW AND BOGUS
+ int count = string.length ();
+ if (terminate) count++;
+ char [] buffer = new char [count];
+ string.getChars (0, string.length (), buffer, 0);
+ return wcsToMbcs (codePage, buffer, false);
+}
+/* TEMPORARY CODE */
+public static byte [] wcsToMbcs (String codePage, char [] buffer) {
+ return wcsToMbcs (codePage, buffer, false);
+}
+public static byte [] wcsToMbcs (String codePage, char [] buffer, boolean terminate) {
+ //SLOW AND BOGUS
+ if (!terminate) return new String (buffer).getBytes ();
+ byte [] buffer1 = new String (buffer).getBytes ();
+ byte [] buffer2 = new byte [buffer1.length + 1];
+ System.arraycopy (buffer1, 0, buffer2, 0, buffer1.length);
+ return buffer2;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ColorDialog.java
index 623dd809bc..c7c4f0db46 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ColorDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ColorDialog.java
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -25,9 +25,9 @@ import org.eclipse.swt.graphics.*;
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
* </p>
- */
-public class ColorDialog extends Dialog {
- RGB rgb;
+ */
+public class ColorDialog extends Dialog {
+ RGB rgb;
/**
* Constructs a new instance of this class given only its parent.
*
@@ -45,9 +45,9 @@ public class ColorDialog extends Dialog {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public ColorDialog (Shell parent) {
- this (parent, SWT.NULL);
-}
+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.
@@ -76,18 +76,18 @@ public ColorDialog (Shell parent) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public ColorDialog (Shell parent, int style) {
- super (parent, style);
- checkSubclass ();
-}
-int cancelFunc (int widget, int callData) {
- OS.gtk_widget_destroy (callData);
- return 0;
-}
-int destroyFunc (int widget, int colorInfo) {
- OS.gtk_main_quit ();
- return 0;
-}
+public ColorDialog (Shell parent, int style) {
+ super (parent, style);
+ checkSubclass ();
+}
+int cancelFunc (int widget, int callData) {
+ OS.gtk_widget_destroy (callData);
+ return 0;
+}
+int destroyFunc (int widget, int colorInfo) {
+ OS.gtk_main_quit ();
+ return 0;
+}
/**
* Returns the currently selected color in the receiver.
*
@@ -95,18 +95,18 @@ int destroyFunc (int widget, int colorInfo) {
*
* @see PaletteData#getRGBs
*/
-public RGB getRGB () {
- return rgb;
-}
-int okFunc (int widget, int callData) {
- GtkColorSelectionDialog dialog = new GtkColorSelectionDialog ();
- OS.memmove (dialog, callData, GtkColorSelectionDialog.sizeof);
- double [] color = new double [4];
- OS.gtk_color_selection_get_color (dialog.colorsel, color);
- rgb = new RGB ((int)(color [0] * 256), (int)(color [1] * 256), (int)(color [2] * 256));
- OS.gtk_widget_destroy (callData);
- return 0;
-}
+public RGB getRGB () {
+ return rgb;
+}
+int okFunc (int widget, int callData) {
+ GtkColorSelectionDialog dialog = new GtkColorSelectionDialog ();
+ OS.memmove (dialog, callData, GtkColorSelectionDialog.sizeof);
+ double [] color = new double [4];
+ OS.gtk_color_selection_get_color (dialog.colorsel, color);
+ rgb = new RGB ((int)(color [0] * 256), (int)(color [1] * 256), (int)(color [2] * 256));
+ OS.gtk_widget_destroy (callData);
+ return 0;
+}
/**
* Makes the receiver visible and brings it to the front
* of the display.
@@ -120,43 +120,43 @@ int okFunc (int widget, int callData) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public RGB open () {
- int handle;
- byte [] titleBytes;
- titleBytes = Converter.wcsToMbcs (null, title, true);
- handle = OS.gtk_color_selection_dialog_new (titleBytes);
- if (parent!=null) {
- OS.gtk_window_set_modal(handle, true);
- OS.gtk_window_set_transient_for(handle, parent.topHandle());
- } GtkColorSelectionDialog dialog = new GtkColorSelectionDialog ();
- OS.memmove (dialog, handle, GtkColorSelectionDialog.sizeof);
- OS.gtk_widget_hide (dialog.help_button);
- if (rgb != null) {
- double [] color = new double [4];
- color [0] = (double)rgb.red / 256;
- color [1] = (double)rgb.green / 256;
- color [2] = (double)rgb.blue / 256;
- OS.gtk_color_selection_set_color (dialog.colorsel, color);
- }
- Callback destroyCallback = new Callback (this, "destroyFunc", 2);
- int destroyFunc = destroyCallback.getAddress ();
- byte [] destroy = Converter.wcsToMbcs (null, "destroy", true);
- OS.gtk_signal_connect (handle, destroy, destroyFunc, handle);
- byte [] clicked = Converter.wcsToMbcs (null, "clicked", true);
- Callback okCallback = new Callback (this, "okFunc", 2);
- int okFunc = okCallback.getAddress ();
- Callback cancelCallback = new Callback (this, "cancelFunc", 2);
- int cancelFunc = cancelCallback.getAddress ();
- OS.gtk_signal_connect (dialog.ok_button, clicked, okFunc, handle);
- OS.gtk_signal_connect (dialog.cancel_button, clicked, cancelFunc, handle);
- rgb = null;
- OS.gtk_widget_show_now (handle);
- OS.gtk_main ();
- destroyCallback.dispose ();
- okCallback.dispose ();
- cancelCallback.dispose ();
- return rgb;
-}
+public RGB open () {
+ int handle;
+ byte [] titleBytes;
+ titleBytes = Converter.wcsToMbcs (null, title, true);
+ handle = OS.gtk_color_selection_dialog_new (titleBytes);
+ if (parent!=null) {
+ OS.gtk_window_set_modal(handle, true);
+ OS.gtk_window_set_transient_for(handle, parent.topHandle());
+ } GtkColorSelectionDialog dialog = new GtkColorSelectionDialog ();
+ OS.memmove (dialog, handle, GtkColorSelectionDialog.sizeof);
+ OS.gtk_widget_hide (dialog.help_button);
+ if (rgb != null) {
+ double [] color = new double [4];
+ color [0] = (double)rgb.red / 256;
+ color [1] = (double)rgb.green / 256;
+ color [2] = (double)rgb.blue / 256;
+ OS.gtk_color_selection_set_color (dialog.colorsel, color);
+ }
+ Callback destroyCallback = new Callback (this, "destroyFunc", 2);
+ int destroyFunc = destroyCallback.getAddress ();
+ byte [] destroy = Converter.wcsToMbcs (null, "destroy", true);
+ OS.gtk_signal_connect (handle, destroy, destroyFunc, handle);
+ byte [] clicked = Converter.wcsToMbcs (null, "clicked", true);
+ Callback okCallback = new Callback (this, "okFunc", 2);
+ int okFunc = okCallback.getAddress ();
+ Callback cancelCallback = new Callback (this, "cancelFunc", 2);
+ int cancelFunc = cancelCallback.getAddress ();
+ OS.gtk_signal_connect (dialog.ok_button, clicked, okFunc, handle);
+ OS.gtk_signal_connect (dialog.cancel_button, clicked, cancelFunc, handle);
+ rgb = null;
+ OS.gtk_widget_show_now (handle);
+ OS.gtk_main ();
+ destroyCallback.dispose ();
+ okCallback.dispose ();
+ cancelCallback.dispose ();
+ return rgb;
+}
/**
* Returns the receiver's selected color to be the argument.
*
@@ -166,7 +166,7 @@ public RGB open () {
*
* @see PaletteData#getRGBs
*/
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-}
+public void setRGB (RGB rgb) {
+ this.rgb = rgb;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Decorations.java
index f060d6a0d3..3ea79e4c4c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Decorations.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Decorations.java
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.gtk.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.graphics.*;
+
/**
* Instances of this class provide the appearance and
* behavior of <code>Shells</code>, but are not top
@@ -84,17 +84,17 @@ import org.eclipse.swt.graphics.*;
* @see #getMaximized
* @see Shell
* @see SWT
- */
-
-public class Decorations extends Canvas {
- String text;
- Image image;
- Menu menuBar;
- Menu [] menus;
- Button defaultButton, saveDefault;
-Decorations () {
- /* Do nothing */
-}
+ */
+
+public class Decorations extends Canvas {
+ String text;
+ Image image;
+ Menu menuBar;
+ Menu [] menus;
+ 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.
@@ -122,36 +122,36 @@ Decorations () {
* @see SWT
* @see Widget#checkSubclass
* @see Widget#getStyle
- */
-public Decorations (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-static int checkStyle (int style) {
- 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 createWidget (int index) {
- super.createWidget (index);
- text = "";
-}
-
+ */
+public Decorations (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+static int checkStyle (int style) {
+ 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 createWidget (int index) {
+ super.createWidget (index);
+ text = "";
+}
+
/**
* Returns the receiver's default button if one had
* previously been set, otherwise returns null.
@@ -164,11 +164,11 @@ void createWidget (int index) {
* </ul>
*
* @see #setDefaultButton
- */
-public Button getDefaultButton () {
- checkWidget();
- return defaultButton;
-}
+ */
+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
@@ -189,11 +189,11 @@ public Button getDefaultButton () {
* <li>ERROR_WIDGET_DISPOSED - if 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;
-}
+ */
+public Image getImage () {
+ checkWidget();
+ return image;
+}
/**
* Returns <code>true</code> if the receiver is currently
* maximized, and false otherwise.
@@ -207,11 +207,11 @@ public Image getImage () {
* </ul>
*
* @see #setMaximized
- */
-public boolean getMaximized () {
- checkWidget();
- return false;
-}
+ */
+public boolean getMaximized () {
+ checkWidget();
+ return false;
+}
/**
* Returns the receiver's menu bar if one had previously
* been set, otherwise returns null.
@@ -222,11 +222,11 @@ public boolean getMaximized () {
* <li>ERROR_WIDGET_DISPOSED - if 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;
-}
+ */
+public Menu getMenuBar () {
+ checkWidget();
+ return menuBar;
+}
/**
* Returns <code>true</code> if the receiver is currently
* minimized, and false otherwise.
@@ -240,14 +240,14 @@ public Menu getMenuBar () {
* </ul>
*
* @see #setMinimized
- */
-public boolean getMinimized () {
- checkWidget();
- return false;
-}
-String getNameText () {
- return getText ();
-}
+ */
+public boolean getMinimized () {
+ checkWidget();
+ return false;
+}
+String getNameText () {
+ return getText ();
+}
/**
* Returns the receiver's text, which is the string that the
* window manager will typically display as the receiver's
@@ -260,44 +260,44 @@ String getNameText () {
* <li>ERROR_WIDGET_DISPOSED - if 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;
-}
-Decorations menuShell () {
- return this;
-}
-
-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 releaseWidget () {
- if (menuBar != null) {
- menuBar.releaseWidget ();
- menuBar.releaseHandle ();
- }
- menuBar = null;
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- }
- }
- menus = null;
- super.releaseWidget ();
- image = null;
- defaultButton = saveDefault = null;
-}
+ */
+public String getText () {
+ checkWidget();
+ return text;
+}
+Decorations menuShell () {
+ return this;
+}
+
+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 releaseWidget () {
+ if (menuBar != null) {
+ menuBar.releaseWidget ();
+ menuBar.releaseHandle ();
+ }
+ menuBar = null;
+ if (menus != null) {
+ for (int i=0; i<menus.length; i++) {
+ Menu menu = menus [i];
+ if (menu != null && !menu.isDisposed ()) {
+ menu.dispose ();
+ }
+ }
+ }
+ menus = null;
+ super.releaseWidget ();
+ image = null;
+ defaultButton = saveDefault = null;
+}
/**
* If the argument is not null, sets the receiver's default
* button to the argument, and if the argument is null, sets
@@ -317,10 +317,10 @@ void releaseWidget () {
* <li>ERROR_WIDGET_DISPOSED - if the 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();
-}
+ */
+public void setDefaultButton (Button button) {
+ checkWidget();
+}
/**
* Sets the receiver's image to the argument, which may
* be null. The image is typically displayed by the window
@@ -337,19 +337,19 @@ public void setDefaultButton (Button button) {
* <li>ERROR_WIDGET_DISPOSED - if the 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;
- int pixmap = 0, mask = 0;
- if (image != null) {
- pixmap = image.pixmap;
- mask = image.mask;
- }
- GtkWidget widget = new GtkWidget ();
- OS.memmove(widget, topHandle(), GtkWidget.sizeof);
- OS.gdk_window_set_icon (widget.window, 0, pixmap, mask);
-}
+ */
+public void setImage (Image image) {
+ checkWidget();
+ this.image = image;
+ int pixmap = 0, mask = 0;
+ if (image != null) {
+ pixmap = image.pixmap;
+ mask = image.mask;
+ }
+ GtkWidget widget = new GtkWidget ();
+ OS.memmove(widget, topHandle(), GtkWidget.sizeof);
+ OS.gdk_window_set_icon (widget.window, 0, pixmap, mask);
+}
/**
* Sets the maximized state of the receiver.
* If the argument is <code>true</code> causes the receiver
@@ -372,10 +372,10 @@ public void setImage (Image image) {
* </ul>
*
* @see #setMinimized
- */
-public void setMaximized (boolean maximized) {
- checkWidget();
-}
+ */
+public void setMaximized (boolean maximized) {
+ checkWidget();
+}
/**
* Sets the receiver's menu bar to the argument, which
* may be null.
@@ -390,16 +390,16 @@ public void setMaximized (boolean maximized) {
* <li>ERROR_WIDGET_DISPOSED - if the 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;
-}
+ */
+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
@@ -422,10 +422,10 @@ public void setMenuBar (Menu menu) {
* </ul>
*
* @see #setMaximized
- */
-public void setMinimized (boolean minimized) {
- checkWidget();
-}
+ */
+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
@@ -440,10 +440,10 @@ public void setMinimized (boolean minimized) {
* <li>ERROR_WIDGET_DISPOSED - if the 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;
-}
-}
+ */
+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/gtk1x/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/DirectoryDialog.java
index 2e5c13d72d..65074221a7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/DirectoryDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/DirectoryDialog.java
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.widgets.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.gtk.*;
+import org.eclipse.swt.widgets.*;
+
/**
* Instances of this class allow the user to navigate
* the file system and select a directory.
@@ -19,12 +19,12 @@ import org.eclipse.swt.widgets.*;
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
* </p>
- */
-
-public class DirectoryDialog extends GtkFileDialog {
- String message = "", filterPath = "";
- String directoryPath;
-
+ */
+
+public class DirectoryDialog extends GtkFileDialog {
+ String message = "", filterPath = "";
+ String directoryPath;
+
/**
* Constructs a new instance of this class given only its
* parent.
@@ -47,9 +47,9 @@ public class DirectoryDialog extends GtkFileDialog {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public DirectoryDialog (Shell parent) {
- this (parent, SWT.PRIMARY_MODAL);
-}
+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.
@@ -80,19 +80,19 @@ public DirectoryDialog (Shell parent) {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public DirectoryDialog (Shell parent, int style) {
- super (parent, style);
- checkSubclass ();
-}
+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
*/
-public String getFilterPath () {
- return filterPath;
-}
+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
@@ -100,10 +100,10 @@ public String getFilterPath () {
*
* @return the message
*/
-public String getMessage () {
- return message;
-}
-
+public String getMessage () {
+ return message;
+}
+
/**
* Makes the dialog visible and brings it to the front
* of the display.
@@ -116,10 +116,10 @@ public String getMessage () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
* </ul>
*/
-public String open () {
- return super.open();
-}
-
+public String open () {
+ return super.open();
+}
+
/**
* Sets the path which the dialog will use to filter
* the directories it shows to the argument, which may be
@@ -127,9 +127,9 @@ public String open () {
*
* @param string the filter path
*/
-public void setFilterPath (String string) {
- filterPath = string;
-}
+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
@@ -137,15 +137,15 @@ public void setFilterPath (String string) {
*
* @param string the message
*/
-public void setMessage (String string) {
- message = string;
-}
-
-boolean getAnswer() {
- String fileNameFromOS = getFileNameFromOS();
- int separatorIndex = calculateLastSeparatorIndex(fileNameFromOS);
- if (separatorIndex+1 != fileNameFromOS.length()) return false; // the user selected a file
- directoryPath = answer = fileNameFromOS;
- return true;
-}
-}
+public void setMessage (String string) {
+ message = string;
+}
+
+boolean getAnswer() {
+ String fileNameFromOS = getFileNameFromOS();
+ int separatorIndex = calculateLastSeparatorIndex(fileNameFromOS);
+ if (separatorIndex+1 != fileNameFromOS.length()) return false; // the user selected a file
+ directoryPath = answer = fileNameFromOS;
+ return true;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FileDialog.java
index d4e21d8e7e..0c9691c09d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FileDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FileDialog.java
@@ -1,14 +1,14 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+
/**
* Instances of this class allow the user to navigate
* the file system and select or enter a file name.
@@ -22,12 +22,12 @@ import org.eclipse.swt.*;
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
* </p>
- */
-public class FileDialog extends GtkFileDialog {
-
- String fullPath, fileName, filterPath;
- String[] filterNames, filterExtensions;
-
+ */
+public class FileDialog extends GtkFileDialog {
+
+ String fullPath, fileName, filterPath;
+ String[] filterNames, filterExtensions;
+
/**
* Constructs a new instance of this class given only its
* parent.
@@ -50,9 +50,9 @@ public class FileDialog extends GtkFileDialog {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public FileDialog (Shell parent) {
- this (parent, SWT.PRIMARY_MODAL);
-}
+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.
@@ -83,11 +83,11 @@ public FileDialog (Shell parent) {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public FileDialog (Shell parent, int style) {
- super (parent, style);
- checkSubclass ();
-}
-
+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,
@@ -95,47 +95,47 @@ public FileDialog (Shell parent, int style) {
*
* @return the relative path of the file
*/
-public String getFileName () {
- return fileName;
-}
-/**
- * Returns the paths of all files that were selected
- * in the dialog relative to the filter path, or null
- * if none are available.
- *
- * @return the relative paths of the files
- */
-public String [] getFileNames () {
- return new String[] {fileName};
-}
+public String getFileName () {
+ return fileName;
+}
+/**
+ * Returns the paths of all files that were selected
+ * in the dialog relative to the filter path, or null
+ * if none are available.
+ *
+ * @return the relative paths of the files
+ */
+public String [] getFileNames () {
+ 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;
-}
+public String [] getFilterExtensions () {
+ return filterExtensions;
+}
/**
* Returns the file names which the dialog will
* use to filter the files it shows.
*
* @return the file name filter
*/
-public String [] getFilterNames () {
- return filterNames;
-}
+public String [] getFilterNames () {
+ return filterNames;
+}
/**
* Returns the path which the dialog will use to filter
* the files it shows.
*
* @return the filter path
*/
-public String getFilterPath () {
- return filterPath;
-}
-
+public String getFilterPath () {
+ return filterPath;
+}
+
/**
* Set the initial filename which the dialog will
* select by default when opened to the argument,
@@ -144,9 +144,9 @@ public String getFilterPath () {
*
* @param string the file name
*/
-public void setFileName (String string) {
- fileName = string;
-}
+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,
@@ -154,9 +154,9 @@ public void setFileName (String string) {
*
* @param extensions the file extension filter
*/
-public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
+public void setFilterExtensions (String [] extensions) {
+ filterExtensions = extensions;
+}
/**
* Sets the file names which the dialog will
* use to filter the files it shows to the argument,
@@ -164,9 +164,9 @@ public void setFilterExtensions (String [] extensions) {
*
* @param names the file name filter
*/
-public void setFilterNames (String [] names) {
- filterNames = names;
-}
+public void setFilterNames (String [] names) {
+ filterNames = names;
+}
/**
* Sets the path which the dialog will use to filter
* the files it shows to the argument, which may be
@@ -174,17 +174,17 @@ public void setFilterNames (String [] names) {
*
* @param string the filter path
*/
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-boolean getAnswer() {
- String fileNameFromOS = getFileNameFromOS();
- int separatorIndex = calculateLastSeparatorIndex(fileNameFromOS);
- if (separatorIndex+1 == fileNameFromOS.length()) return false; // the user selected a directory
- fullPath = answer = fileNameFromOS;
- fileName = fullPath.substring (separatorIndex + 1, fullPath.length ());
- filterPath = fullPath.substring (0, separatorIndex);
- return true;
-}
-}
+public void setFilterPath (String string) {
+ filterPath = string;
+}
+
+boolean getAnswer() {
+ String fileNameFromOS = getFileNameFromOS();
+ int separatorIndex = calculateLastSeparatorIndex(fileNameFromOS);
+ if (separatorIndex+1 == fileNameFromOS.length()) return false; // the user selected a directory
+ fullPath = answer = fileNameFromOS;
+ fileName = fullPath.substring (separatorIndex + 1, fullPath.length ());
+ filterPath = fullPath.substring (0, separatorIndex);
+ return true;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FontDialog.java
index baf03d3b6e..bbd078290d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FontDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FontDialog.java
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -19,10 +19,10 @@ import org.eclipse.swt.graphics.*;
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
* </p>
- */
-
-public class FontDialog extends Dialog {
- FontData fontData;
+ */
+
+public class FontDialog extends Dialog {
+ FontData fontData;
/**
* Constructs a new instance of this class given only its
* parent.
@@ -45,9 +45,9 @@ public class FontDialog extends Dialog {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public FontDialog (Shell parent) {
- this (parent, SWT.PRIMARY_MODAL);
-}
+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.
@@ -78,37 +78,37 @@ public FontDialog (Shell parent) {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public FontDialog (Shell parent, int style) {
- super (parent, style);
- checkSubclass ();
-}
-int cancelFunc (int widget, int callData) {
- OS.gtk_widget_destroy (callData);
- return 0;
-}
-int destroyFunc (int widget, int colorInfo) {
- OS.gtk_main_quit ();
- return 0;
-}
+public FontDialog (Shell parent, int style) {
+ super (parent, style);
+ checkSubclass ();
+}
+int cancelFunc (int widget, int callData) {
+ OS.gtk_widget_destroy (callData);
+ return 0;
+}
+int destroyFunc (int widget, int colorInfo) {
+ OS.gtk_main_quit ();
+ return 0;
+}
/**
* 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
*/
-public FontData getFontData() {
- return fontData;
-}
-int okFunc (int widget, int callData) {
- int hFontName = OS.gtk_font_selection_dialog_get_font_name (callData);
- int fontSize = OS.strlen (hFontName);
- byte [] buffer = new byte [fontSize];
- OS.memmove (buffer, hFontName, fontSize);
- char [] fontName = Converter.mbcsToWcs (null, buffer);
- fontData = FontData.gtk_new(new String (fontName));
- OS.gtk_widget_destroy (callData);
- return 0;
-}
+public FontData getFontData() {
+ return fontData;
+}
+int okFunc (int widget, int callData) {
+ int hFontName = OS.gtk_font_selection_dialog_get_font_name (callData);
+ int fontSize = OS.strlen (hFontName);
+ byte [] buffer = new byte [fontSize];
+ OS.memmove (buffer, hFontName, fontSize);
+ char [] fontName = Converter.mbcsToWcs (null, buffer);
+ fontData = FontData.gtk_new(new String (fontName));
+ OS.gtk_widget_destroy (callData);
+ return 0;
+}
/**
* Makes the dialog visible and brings it to the front
* of the display.
@@ -121,40 +121,40 @@ int okFunc (int widget, int callData) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
* </ul>
*/
-public FontData open () {
- int handle;
- byte [] titleBytes;
- titleBytes = Converter.wcsToMbcs (null, title, true);
- handle = OS.gtk_font_selection_dialog_new (titleBytes);
- GtkFontSelectionDialog dialog = new GtkFontSelectionDialog ();
- OS.memmove (dialog, handle, GtkFontSelectionDialog.sizeof);
- if (parent!=null) {
- OS.gtk_window_set_modal(handle, true);
- OS.gtk_window_set_transient_for(handle, parent.topHandle);
- }
- if (fontData != null) {
- byte[] buffer = Converter.wcsToMbcs(null, fontData.gtk_getXlfd(), true);
- OS.gtk_font_selection_set_font_name(dialog.fontsel, buffer);
- }
- Callback destroyCallback = new Callback (this, "destroyFunc", 2);
- int destroyFunc = destroyCallback.getAddress ();
- byte [] destroy = Converter.wcsToMbcs (null, "destroy", true);
- OS.gtk_signal_connect (handle, destroy, destroyFunc, handle);
- byte [] clicked = Converter.wcsToMbcs (null, "clicked", true);
- Callback okCallback = new Callback (this, "okFunc", 2);
- int okFunc = okCallback.getAddress ();
- Callback cancelCallback = new Callback (this, "cancelFunc", 2);
- int cancelFunc = cancelCallback.getAddress ();
- OS.gtk_signal_connect (dialog.ok_button, clicked, okFunc, handle);
- OS.gtk_signal_connect (dialog.cancel_button, clicked, cancelFunc, handle);
- fontData = null;
- OS.gtk_widget_show_now (handle);
- OS.gtk_main ();
- destroyCallback.dispose ();
- okCallback.dispose ();
- cancelCallback.dispose ();
- return fontData;
-}
+public FontData open () {
+ int handle;
+ byte [] titleBytes;
+ titleBytes = Converter.wcsToMbcs (null, title, true);
+ handle = OS.gtk_font_selection_dialog_new (titleBytes);
+ GtkFontSelectionDialog dialog = new GtkFontSelectionDialog ();
+ OS.memmove (dialog, handle, GtkFontSelectionDialog.sizeof);
+ if (parent!=null) {
+ OS.gtk_window_set_modal(handle, true);
+ OS.gtk_window_set_transient_for(handle, parent.topHandle);
+ }
+ if (fontData != null) {
+ byte[] buffer = Converter.wcsToMbcs(null, fontData.gtk_getXlfd(), true);
+ OS.gtk_font_selection_set_font_name(dialog.fontsel, buffer);
+ }
+ Callback destroyCallback = new Callback (this, "destroyFunc", 2);
+ int destroyFunc = destroyCallback.getAddress ();
+ byte [] destroy = Converter.wcsToMbcs (null, "destroy", true);
+ OS.gtk_signal_connect (handle, destroy, destroyFunc, handle);
+ byte [] clicked = Converter.wcsToMbcs (null, "clicked", true);
+ Callback okCallback = new Callback (this, "okFunc", 2);
+ int okFunc = okCallback.getAddress ();
+ Callback cancelCallback = new Callback (this, "cancelFunc", 2);
+ int cancelFunc = cancelCallback.getAddress ();
+ OS.gtk_signal_connect (dialog.ok_button, clicked, okFunc, handle);
+ OS.gtk_signal_connect (dialog.cancel_button, clicked, cancelFunc, handle);
+ fontData = null;
+ OS.gtk_widget_show_now (handle);
+ OS.gtk_main ();
+ destroyCallback.dispose ();
+ okCallback.dispose ();
+ cancelCallback.dispose ();
+ return fontData;
+}
/**
* Sets a FontData object describing the font to be
* selected by default in the dialog, or null to let
@@ -162,7 +162,7 @@ public FontData open () {
*
* @param fontData the FontData to use initially, or null
*/
-public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-}
+public void setFontData (FontData fontData) {
+ this.fontData = fontData;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Menu.java
index a0bfbd3eb2..441561ed44 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Menu.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Menu.java
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 user interface objects that contain
* menu items.
@@ -22,42 +22,42 @@ import org.eclipse.swt.events.*;
* <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.
- * </p><p>
+ * <p>
+ * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified.
+ * </p><p>
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
- */
-
-public class Menu extends Widget {
- MenuItem cascade;
- Decorations parent;
-/**
-* Creates a new instance of the widget.
-*/
-public Menu (Control parent) {
- this (parent.getShell (), SWT.POP_UP);
-}
-/**
-* Creates a new instance of the widget.
-*/
-public Menu (Decorations parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
-/**
-* Creates a new instance of the widget.
-*/
-public Menu (Menu parentMenu) {
- this (parentMenu.parent, SWT.DROP_DOWN);
-}
-/**
-* Creates a new instance of the widget.
-*/
-public Menu (MenuItem parentItem) {
- this (parentItem.parent);
-}
+ */
+
+public class Menu extends Widget {
+ MenuItem cascade;
+ Decorations parent;
+/**
+* Creates a new instance of the widget.
+*/
+public Menu (Control parent) {
+ this (parent.getShell (), SWT.POP_UP);
+}
+/**
+* Creates a new instance of the widget.
+*/
+public Menu (Decorations parent, int style) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ createWidget (0);
+}
+/**
+* Creates a new instance of the widget.
+*/
+public Menu (Menu parentMenu) {
+ this (parentMenu.parent, SWT.DROP_DOWN);
+}
+/**
+* Creates a new instance of the widget.
+*/
+public Menu (MenuItem parentItem) {
+ this (parentItem.parent);
+}
/**
* Adds the listener to the collection of listeners who will
* be notified when the help events are generated for the control, by sending
@@ -76,16 +76,16 @@ public Menu (MenuItem parentItem) {
*
* @see MenuListener
* @see #removeMenuListener
- */
-public void addMenuListener (MenuListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Hide,typedListener);
- addListener (SWT.Show,typedListener);
-}
-
+ */
+public void addMenuListener (MenuListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 the help events are generated for the control, by sending
@@ -105,33 +105,33 @@ public void addMenuListener (MenuListener listener) {
* @see HelpListener
* @see #removeHelpListener
*/
-public void addHelpListener (HelpListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
-}
-void createHandle (int index) {
- state |= HANDLE;
- if ((style & SWT.BAR) != 0) {
- handle = OS.gtk_menu_bar_new ();
- OS.gtk_widget_show (handle);
- } else {
- handle = OS.gtk_menu_new ();
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- parent.add (this);
-}
-
+public void addHelpListener (HelpListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Help, typedListener);
+}
+
+static int checkStyle (int style) {
+ return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+ if ((style & SWT.BAR) != 0) {
+ handle = OS.gtk_menu_bar_new ();
+ OS.gtk_widget_show (handle);
+ } else {
+ handle = OS.gtk_menu_new ();
+ }
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+
+void createWidget (int index) {
+ super.createWidget (index);
+ parent.add (this);
+}
+
/**
* Returns the default menu item or null if none has
* been previously set.
@@ -143,17 +143,17 @@ void createWidget (int index) {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return null;
-}
-public Display getDisplay () {
- Decorations parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
+ */
+public MenuItem getDefaultItem () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return null;
+}
+public Display getDisplay () {
+ Decorations parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> otherwise. A disabled control is typically
@@ -166,14 +166,14 @@ public Display getDisplay () {
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
- */
-public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- GtkWidget widget = new GtkWidget ();
- OS.memmove (widget, handle, GtkWidget.sizeof);
- return (widget.flags & OS.GTK_SENSITIVE) != 0;
-}
+ */
+public boolean getEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ GtkWidget widget = new GtkWidget ();
+ OS.memmove (widget, handle, GtkWidget.sizeof);
+ return (widget.flags & OS.GTK_SENSITIVE) != 0;
+}
/**
* Returns the item at the given, zero-relative index in the
* receiver. Throws an exception if the index is out of range.
@@ -188,15 +188,15 @@ public boolean getEnabled () {
* <li>ERROR_WIDGET_DISPOSED - if 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (handle);
- int data = OS.g_list_nth_data (list, index);
- if (data == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- return (MenuItem) WidgetTable.get (data);
-}
+ */
+public MenuItem getItem (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int list = OS.gtk_container_children (handle);
+ int data = OS.g_list_nth_data (list, index);
+ if (data == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
+ return (MenuItem) WidgetTable.get (data);
+}
/**
* Returns the number of items contained in the receiver.
*
@@ -206,13 +206,13 @@ public MenuItem getItem (int index) {
* <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (handle);
- return OS.g_list_length (list);
-}
+ */
+public int getItemCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int list = OS.gtk_container_children (handle);
+ return OS.g_list_length (list);
+}
/**
* Returns an array of <code>MenuItem</code>s which are the items
* in the receiver.
@@ -228,19 +228,19 @@ public int getItemCount () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (handle);
- int count = OS.g_list_length (list);
- MenuItem [] items = new MenuItem [count];
- for (int i=0; i<count; i++) {
- int data = OS.g_list_nth_data (list, i);
- items [i] = (MenuItem) WidgetTable.get (data);
- }
- return items;
-}
+ */
+public MenuItem [] getItems () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int list = OS.gtk_container_children (handle);
+ int count = OS.g_list_length (list);
+ MenuItem [] items = new MenuItem [count];
+ for (int i=0; i<count; i++) {
+ int data = OS.g_list_nth_data (list, i);
+ items [i] = (MenuItem) WidgetTable.get (data);
+ }
+ return items;
+}
/**
* Returns the receiver's parent, which must be a <code>Decorations</code>.
*
@@ -250,12 +250,12 @@ public MenuItem [] getItems () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent;
-}
+ */
+public Decorations getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
/**
* Returns the receiver's parent item, which must be a
* <code>MenuItem</code> or null when the receiver is a
@@ -267,12 +267,12 @@ public Decorations getParent () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return cascade;
-}
+ */
+public MenuItem getParentItem () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return cascade;
+}
/**
* Returns the receiver's parent item, which must be a
* <code>Menu</code> or null when the receiver is a
@@ -284,13 +284,13 @@ public MenuItem getParentItem () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (cascade == null) return null;
- return cascade.getParent ();
-}
+ */
+public Menu getParentMenu () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
@@ -305,12 +305,12 @@ public Menu getParentMenu () {
* </ul>
*
* @see #getParent
- */
-public Shell getShell () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getShell ();
-}
+ */
+public Shell getShell () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getShell ();
+}
/**
* Returns <code>true</code> if the receiver is visible, and
* <code>false</code> otherwise.
@@ -327,14 +327,14 @@ public Shell getShell () {
* <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- GtkWidget widget = new GtkWidget ();
- OS.memmove (widget, handle, GtkWidget.sizeof);
- return (widget.flags & OS.GTK_MAPPED) != 0;
-}
+ */
+public boolean getVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ GtkWidget widget = new GtkWidget ();
+ OS.memmove (widget, handle, GtkWidget.sizeof);
+ return (widget.flags & OS.GTK_MAPPED) != 0;
+}
/**
* Searches the receiver's list starting at the first item
* (index 0) until an item is found that is equal to the
@@ -351,17 +351,17 @@ public boolean getVisible () {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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;
-}
+ */
+public int indexOf (MenuItem item) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
* <code>false</code> otherwise. A disabled control is typically
@@ -374,12 +374,12 @@ public int indexOf (MenuItem item) {
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
- */
-public boolean isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return getEnabled () && getParent ().getEnabled ();
-}
+ */
+public boolean isEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getEnabled () && getParent ().getEnabled ();
+}
/**
* Returns <code>true</code> if the receiver is visible, and
* <code>false</code> otherwise.
@@ -396,33 +396,33 @@ public boolean isEnabled () {
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
- */
-public boolean isVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return getVisible ();
-}
-void releaseChild () {
- super.releaseChild ();
- if (cascade != null) cascade.setMenu (null);
- if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
- parent.setMenuBar (null);
- }
-}
-void releaseWidget () {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (!item.isDisposed ()) {
- item.releaseWidget ();
- item.releaseHandle ();
- }
- }
- if (parent != null) parent.remove (this);
- super.releaseWidget ();
- parent = null;
- cascade = null;
-}
+ */
+public boolean isVisible () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return getVisible ();
+}
+void releaseChild () {
+ super.releaseChild ();
+ if (cascade != null) cascade.setMenu (null);
+ if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
+ parent.setMenuBar (null);
+ }
+}
+void releaseWidget () {
+ MenuItem [] items = getItems ();
+ for (int i=0; i<items.length; i++) {
+ MenuItem item = items [i];
+ if (!item.isDisposed ()) {
+ item.releaseWidget ();
+ item.releaseHandle ();
+ }
+ }
+ if (parent != null) parent.remove (this);
+ super.releaseWidget ();
+ parent = null;
+ cascade = null;
+}
/**
* Removes the listener from the collection of listeners who will
* be notified when the menu events are generated for the control.
@@ -439,16 +439,16 @@ void releaseWidget () {
*
* @see MenuListener
* @see #addMenuListener
- */
-public void removeMenuListener (MenuListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Hide, listener);
- eventTable.unhook (SWT.Show, listener);
-}
-
+ */
+public void removeMenuListener (MenuListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Hide, listener);
+ eventTable.unhook (SWT.Show, listener);
+}
+
/**
* Removes the listener from the collection of listeners who will
* be notified when the help events are generated for the control.
@@ -466,14 +466,14 @@ public void removeMenuListener (MenuListener listener) {
* @see HelpListener
* @see #addHelpListener
*/
-public void removeHelpListener (HelpListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
+public void removeHelpListener (HelpListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Help, listener);
+}
+
/**
* Sets the default menu item to the argument or removes
* the default emphasis when the argument is <code>null</code>.
@@ -487,11 +487,11 @@ public void removeHelpListener (HelpListener listener) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-}
+ */
+public void setDefaultItem (MenuItem item) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+}
/**
* Enables the receiver if the argument is <code>true</code>,
* and disables it otherwise. A disabled control is typically
@@ -504,13 +504,13 @@ public void setDefaultItem (MenuItem item) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- OS.gtk_widget_set_sensitive (handle, enabled);
-}
-
+ */
+public void setEnabled (boolean enabled) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ OS.gtk_widget_set_sensitive (handle, enabled);
+}
+
/**
* Sets the receiver's location to the point specified by
* the arguments which are relative to the display.
@@ -527,15 +527,15 @@ public void setEnabled (boolean enabled) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setLocation (int x, int y) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
-// OS.gtk_widget_set_uposition(handle, x, y);
-// OS.gtk_widget_set_uposition(handle, 0, 0);
- sendEvent(SWT.Move);
-}
-
+public void setLocation (int x, int y) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
+// OS.gtk_widget_set_uposition(handle, x, y);
+// OS.gtk_widget_set_uposition(handle, 0, 0);
+ sendEvent(SWT.Move);
+}
+
/**
* Marks the receiver as visible if the argument is <code>true</code>,
* and marks it invisible otherwise.
@@ -551,17 +551,17 @@ public void setLocation (int x, int y) {
* <li>ERROR_WIDGET_DISPOSED - if the 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 (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((style & SWT.BAR) != 0) return;
- if (visible) {
- sendEvent(SWT.Show);
- OS.gtk_menu_popup (handle, 0, 0, 0, 0, 3, 0);
- } else {
- OS.gtk_menu_popdown (handle);
- sendEvent(SWT.Hide);
- }
-}
-}
+ */
+public void setVisible (boolean visible) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & SWT.BAR) != 0) return;
+ if (visible) {
+ sendEvent(SWT.Show);
+ OS.gtk_menu_popup (handle, 0, 0, 0, 0, 3, 0);
+ } else {
+ OS.gtk_menu_popdown (handle);
+ sendEvent(SWT.Hide);
+ }
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/MenuItem.java
index ce8f52cd1d..6a898c9365 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/MenuItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/MenuItem.java
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -22,18 +22,18 @@ import org.eclipse.swt.events.*;
* <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>
+ * <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;
-
+ */
+
+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
@@ -63,12 +63,12 @@ public class MenuItem extends Item {
* @see SWT
* @see Widget#checkSubclass
* @see Widget#getStyle
- */
-public MenuItem (Menu parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (parent.getItemCount ());
-}
+ */
+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
@@ -99,33 +99,33 @@ public MenuItem (Menu parent, int style) {
* @see SWT
* @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_ITEM_NOT_ADDED);
- }
- createWidget (index);
-}
-void addAccelerator (int accel_group) {
- if (accel_group == 0) return;
- if (accelerator == 0) return;
- byte [] activate = Converter.wcsToMbcs (null, "activate", true);
- int mask = 0;
- if ((accelerator & SWT.CONTROL) != 0) mask |= OS.GDK_CONTROL_MASK;
- if ((accelerator & SWT.ALT) != 0) mask |= OS.GDK_MOD1_MASK;
- if ((accelerator & SWT.SHIFT) != 0) mask |= OS.GDK_SHIFT_MASK;
- int keysym = accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CTRL);
- int newKey = Display.untranslateKey (keysym);
- if (newKey != 0) {
- keysym = newKey;
- } else {
- keysym = wcsToMbcs ((char) keysym);
- }
- OS.gtk_widget_add_accelerator (handle, activate, accel_group, keysym, mask, OS.GTK_ACCEL_VISIBLE);
-}
+ */
+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_ITEM_NOT_ADDED);
+ }
+ createWidget (index);
+}
+void addAccelerator (int accel_group) {
+ if (accel_group == 0) return;
+ if (accelerator == 0) return;
+ byte [] activate = Converter.wcsToMbcs (null, "activate", true);
+ int mask = 0;
+ if ((accelerator & SWT.CONTROL) != 0) mask |= OS.GDK_CONTROL_MASK;
+ if ((accelerator & SWT.ALT) != 0) mask |= OS.GDK_MOD1_MASK;
+ if ((accelerator & SWT.SHIFT) != 0) mask |= OS.GDK_SHIFT_MASK;
+ int keysym = accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CTRL);
+ int newKey = Display.untranslateKey (keysym);
+ if (newKey != 0) {
+ keysym = newKey;
+ } else {
+ keysym = wcsToMbcs ((char) keysym);
+ }
+ OS.gtk_widget_add_accelerator (handle, activate, accel_group, keysym, mask, OS.GTK_ACCEL_VISIBLE);
+}
/**
* Adds the listener to the collection of listeners who will
* be notified when the arm events are generated for the control, by sending
@@ -144,15 +144,15 @@ void addAccelerator (int accel_group) {
*
* @see ArmListener
* @see #removeArmListener
- */
-public void addArmListener (ArmListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Arm, typedListener);
-}
-
+ */
+public void addArmListener (ArmListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
@@ -172,79 +172,79 @@ public void addArmListener (ArmListener listener) {
* @see HelpListener
* @see #removeHelpListener
*/
-public void addHelpListener (HelpListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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);
-}
-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_menu_item_new ();
- break;
- case SWT.RADIO:
-// handle = OS.gtk_radio_menu_item_new_with_label (0, buffer);
-// break;
- case SWT.CHECK:
- handle = OS.gtk_check_menu_item_new_with_label (buffer);
- break;
- case SWT.PUSH:
- default:
- handle = OS.gtk_menu_item_new_with_label (buffer);
- break;
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- OS.gtk_check_menu_item_set_show_toggle (handle, true);
- }
- if ((parent.style & SWT.BAR) != 0) {
- OS.gtk_menu_bar_insert (parent.handle, handle, index);
- } else {
- OS.gtk_menu_insert (parent.handle, handle, index);
- }
- OS.gtk_widget_show (handle);
-}
+public void addHelpListener (HelpListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 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 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) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
+}
+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_menu_item_new ();
+ break;
+ case SWT.RADIO:
+// handle = OS.gtk_radio_menu_item_new_with_label (0, buffer);
+// break;
+ case SWT.CHECK:
+ handle = OS.gtk_check_menu_item_new_with_label (buffer);
+ break;
+ case SWT.PUSH:
+ default:
+ handle = OS.gtk_menu_item_new_with_label (buffer);
+ break;
+ }
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
+ OS.gtk_check_menu_item_set_show_toggle (handle, true);
+ }
+ if ((parent.style & SWT.BAR) != 0) {
+ OS.gtk_menu_bar_insert (parent.handle, handle, index);
+ } else {
+ OS.gtk_menu_insert (parent.handle, handle, index);
+ }
+ OS.gtk_widget_show (handle);
+}
/**
* Return the widget accelerator. An accelerator is the bit-wise
* OR of zero or more modifier masks and a key. Examples:
@@ -257,17 +257,17 @@ void createHandle (int index) {
* <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return accelerator;
-}
-public Display getDisplay () {
- Menu parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
+ */
+public int getAccelerator () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return accelerator;
+}
+public Display getDisplay () {
+ Menu parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> otherwise. A disabled control is typically
@@ -280,14 +280,14 @@ public Display getDisplay () {
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
- */
-public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- GtkWidget widget = new GtkWidget ();
- OS.memmove (widget, handle, GtkWidget.sizeof);
- return (widget.flags & OS.GTK_SENSITIVE) != 0;
-}
+ */
+public boolean getEnabled () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ GtkWidget widget = new GtkWidget ();
+ OS.memmove (widget, handle, GtkWidget.sizeof);
+ return (widget.flags & OS.GTK_SENSITIVE) != 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
@@ -301,12 +301,12 @@ public boolean getEnabled () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return menu;
-}
+ */
+public Menu getMenu () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return menu;
+}
/**
* Returns the receiver's parent, which must be a <code>Menu</code>.
*
@@ -316,12 +316,12 @@ public Menu getMenu () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent;
-}
+ */
+public Menu getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
/**
* Returns <code>true</code> if the receiver is selected,
* and false otherwise.
@@ -335,22 +335,22 @@ public Menu getParent () {
* <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- GtkCheckMenuItem menuItem = new GtkCheckMenuItem ();
- OS.memmove (menuItem, handle, GtkCheckMenuItem.sizeof);
- return menuItem.active != 0;
-}
-void hookEvents () {
- super.hookEvents ();
- Display display = getDisplay ();
- int windowProc2 = display.windowProc2;
- byte [] activate_event = Converter.wcsToMbcs (null, "activate", true);
- OS.gtk_signal_connect (handle, activate_event, windowProc2, SWT.Selection);
-}
+ */
+public boolean getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
+ GtkCheckMenuItem menuItem = new GtkCheckMenuItem ();
+ OS.memmove (menuItem, handle, GtkCheckMenuItem.sizeof);
+ return menuItem.active != 0;
+}
+void hookEvents () {
+ super.hookEvents ();
+ Display display = getDisplay ();
+ int windowProc2 = display.windowProc2;
+ byte [] activate_event = Converter.wcsToMbcs (null, "activate", true);
+ OS.gtk_signal_connect (handle, activate_event, windowProc2, SWT.Selection);
+}
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> otherwise. A disabled control is typically
@@ -363,48 +363,48 @@ void hookEvents () {
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
- */
-public boolean isEnabled () {
- return getEnabled ();
-}
-int processSelection (int int0, int int1, int int2) {
- postEvent (SWT.Selection);
- return 0;
-}
-void releaseChild () {
- super.releaseChild ();
- if (menu != null) menu.dispose ();
- menu = null;
-}
-void releaseWidget () {
- if (menu != null) {
- menu.releaseWidget ();
- menu.releaseHandle ();
- }
- menu = null;
- super.releaseWidget ();
- int accel_group = parent.getShell ().accelGroup;
- removeAccelerator (accel_group);
- accelerator = 0;
- parent = null;
-}
-void removeAccelerator (int accel_group) {
- if (accel_group == 0) return;
- if (accelerator == 0) return;
- int mask = 0;
- if ((accelerator & SWT.CONTROL) != 0) mask |= OS.GDK_CONTROL_MASK;
- if ((accelerator & SWT.ALT) != 0) mask |= OS.GDK_MOD1_MASK;
- if ((accelerator & SWT.SHIFT) != 0) mask |= OS.GDK_SHIFT_MASK;
- int keysym = accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CTRL);
- int newKey = Display.untranslateKey (keysym);
- if (newKey != 0) {
- keysym = newKey;
- } else {
- keysym = wcsToMbcs ((char) keysym);
- }
- OS.gtk_widget_remove_accelerator (handle, accel_group, keysym, mask);
- accelerator = 0;
-}
+ */
+public boolean isEnabled () {
+ return getEnabled ();
+}
+int processSelection (int int0, int int1, int int2) {
+ postEvent (SWT.Selection);
+ return 0;
+}
+void releaseChild () {
+ super.releaseChild ();
+ if (menu != null) menu.dispose ();
+ menu = null;
+}
+void releaseWidget () {
+ if (menu != null) {
+ menu.releaseWidget ();
+ menu.releaseHandle ();
+ }
+ menu = null;
+ super.releaseWidget ();
+ int accel_group = parent.getShell ().accelGroup;
+ removeAccelerator (accel_group);
+ accelerator = 0;
+ parent = null;
+}
+void removeAccelerator (int accel_group) {
+ if (accel_group == 0) return;
+ if (accelerator == 0) return;
+ int mask = 0;
+ if ((accelerator & SWT.CONTROL) != 0) mask |= OS.GDK_CONTROL_MASK;
+ if ((accelerator & SWT.ALT) != 0) mask |= OS.GDK_MOD1_MASK;
+ if ((accelerator & SWT.SHIFT) != 0) mask |= OS.GDK_SHIFT_MASK;
+ int keysym = accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CTRL);
+ int newKey = Display.untranslateKey (keysym);
+ if (newKey != 0) {
+ keysym = newKey;
+ } else {
+ keysym = wcsToMbcs ((char) keysym);
+ }
+ OS.gtk_widget_remove_accelerator (handle, accel_group, keysym, mask);
+ accelerator = 0;
+}
/**
* Removes the listener from the collection of listeners who will
* be notified when the arm events are generated for the control.
@@ -421,15 +421,15 @@ void removeAccelerator (int accel_group) {
*
* @see ArmListener
* @see #addArmListener
- */
-public void removeArmListener (ArmListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Arm, listener);
-}
-
+ */
+public void removeArmListener (ArmListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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.
@@ -447,14 +447,14 @@ public void removeArmListener (ArmListener listener) {
* @see HelpListener
* @see #addHelpListener
*/
-public void removeHelpListener (HelpListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
+public void removeHelpListener (HelpListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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.
@@ -471,15 +471,15 @@ public void removeHelpListener (HelpListener listener) {
*
* @see SelectionListener
* @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
+ */
+public void removeSelectionListener (SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Selection, listener);
+ eventTable.unhook (SWT.DefaultSelection,listener);
+}
/**
* Sets the widget accelerator. An accelerator is the bit-wise
* OR of zero or more modifier masks and a key. Examples:
@@ -492,15 +492,15 @@ public void removeSelectionListener (SelectionListener listener) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int accel_group = parent.getShell ().accelGroup;
- if (accelerator != 0) removeAccelerator (accel_group);
- this.accelerator = accelerator;
- if (accelerator != 0) addAccelerator (accel_group);
-}
+ */
+public void setAccelerator (int accelerator) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int accel_group = parent.getShell ().accelGroup;
+ if (accelerator != 0) removeAccelerator (accel_group);
+ this.accelerator = accelerator;
+ if (accelerator != 0) addAccelerator (accel_group);
+}
/**
* Enables the receiver if the argument is <code>true</code>,
* and disables it otherwise. A disabled control is typically
@@ -513,15 +513,15 @@ public void setAccelerator (int accelerator) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- OS.gtk_widget_set_sensitive (handle, enabled);
-}
-
-
-
+ */
+public void setEnabled (boolean enabled) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ OS.gtk_widget_set_sensitive (handle, enabled);
+}
+
+
+
/**
* Sets the receiver's pull down menu to the argument.
* Only <code>CASCADE</code> menu items can have a
@@ -541,42 +541,42 @@ public void setEnabled (boolean enabled) {
* <li>ERROR_WIDGET_DISPOSED - if the 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;
- if (oldMenu != null) {
- oldMenu.cascade = null;
- /*
- * Add a reference to the menu we are about
- * to replace or GTK will destroy it.
- */
- OS.gtk_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);
- }
-
-
-}
+ */
+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;
+ if (oldMenu != null) {
+ oldMenu.cascade = null;
+ /*
+ * Add a reference to the menu we are about
+ * to replace or GTK will destroy it.
+ */
+ OS.gtk_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);
+ }
+
+
+}
/**
* Sets the selection state of the receiver.
* <p>
@@ -589,48 +589,48 @@ public void setMenu (Menu menu) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- OS.gtk_signal_handler_block_by_data (handle, SWT.Selection);
- OS.gtk_check_menu_item_set_active (handle, selected);
- OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection);
-}
-public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- text = string;
- if ((style & SWT.ARROW) != 0) return;
- int length = string.length ();
- int index = string.indexOf('\t');
- if (index != -1) length = index;
- char [] text = new char [length + 1];
- char [] pattern = new char [length + 1];
- string.getChars (0, length, text, 0);
- int i = 0, j = 0;
- while (i < length) {
- pattern [j] = ' ';
- if (text [i] == '&') {
- i++;
- if (i < length && text [i] != '&') {
- pattern [j] = '_';
- }
- }
- text [j++] = text [i++];
- }
- while (j < i) {
- text [j] = pattern [j] = '\0';
- j++;
- }
- int list = OS.gtk_container_children (handle);
- int label = OS.g_list_nth_data (list, 0);
- byte [] buffer1 = Converter.wcsToMbcs (null, text);
- OS.gtk_label_set_text (label, buffer1);
- byte [] buffer2 = Converter.wcsToMbcs (null, pattern);
- OS.gtk_label_set_pattern (label, buffer2);
-}
-}
+ */
+public void setSelection (boolean selected) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
+ OS.gtk_signal_handler_block_by_data (handle, SWT.Selection);
+ OS.gtk_check_menu_item_set_active (handle, selected);
+ OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection);
+}
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.SEPARATOR) != 0) return;
+ text = string;
+ if ((style & SWT.ARROW) != 0) return;
+ int length = string.length ();
+ int index = string.indexOf('\t');
+ if (index != -1) length = index;
+ char [] text = new char [length + 1];
+ char [] pattern = new char [length + 1];
+ string.getChars (0, length, text, 0);
+ int i = 0, j = 0;
+ while (i < length) {
+ pattern [j] = ' ';
+ if (text [i] == '&') {
+ i++;
+ if (i < length && text [i] != '&') {
+ pattern [j] = '_';
+ }
+ }
+ text [j++] = text [i++];
+ }
+ while (j < i) {
+ text [j] = pattern [j] = '\0';
+ j++;
+ }
+ int list = OS.gtk_container_children (handle);
+ int label = OS.g_list_nth_data (list, 0);
+ byte [] buffer1 = Converter.wcsToMbcs (null, text);
+ OS.gtk_label_set_text (label, buffer1);
+ byte [] buffer2 = Converter.wcsToMbcs (null, pattern);
+ OS.gtk_label_set_pattern (label, buffer2);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabFolder.java
index 7334f0b75b..cd946c1657 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabFolder.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabFolder.java
@@ -1,273 +1,273 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>(none)</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 TabFolder extends Composite {
- int notebookHandle;
- TabItem [] items;
-
-
-/*
- * == CONSTRUCTORS ==
- */
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * for all SWT widget classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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));
-}
-
-/*
- * == HANDLE DANCES, FIRST SPECIES ==
- */
-
-void createHandle (int index) {
- state |= HANDLE;
- eventBoxHandle = OS.gtk_event_box_new();
- fixedHandle = OS.gtk_fixed_new ();
- notebookHandle = OS.gtk_notebook_new ();
- handle = OS.gtk_fixed_new();
-}
-
-void configure () {
- _connectParent();
- OS.gtk_container_add(eventBoxHandle, fixedHandle);
- OS.gtk_fixed_put (fixedHandle, notebookHandle, (short)0, (short)0);
- OS.gtk_fixed_put (fixedHandle, handle, (short)2, (short)33);
-}
-
-void showHandle() {
- OS.gtk_widget_show(eventBoxHandle);
- OS.gtk_widget_show(fixedHandle);
- OS.gtk_widget_show(notebookHandle);
- OS.gtk_widget_show(handle);
- OS.gtk_widget_realize (notebookHandle);
- OS.gtk_widget_realize (handle);
-}
-
-void register () {
- super.register ();
- WidgetTable.put (notebookHandle, this);
-}
-
-void hookEvents () {
- super.hookEvents ();
- signal_connect (notebookHandle, "size_allocate", SWT.Resize, 3);
- signal_connect (notebookHandle, "switch_page", SWT.Selection, 4);
-}
-
-void createWidget (int index) {
- super.createWidget(index);
- items = new TabItem [4];
-}
-
-int topHandle () { return eventBoxHandle; }
-int paintHandle () { return notebookHandle; }
-int parentingHandle () { return handle; }
-boolean isMyHandle(int h) {
- if (h==eventBoxHandle) return true;
- if (h==notebookHandle) return true;
- if (h==fixedHandle) return true;
- if (h==handle) return true;
- return false;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- //notebookHandle
- int width = _computeSize(wHint, hHint, changed).x;
- int height = 0;
- Point size;
- if (layout != null) {
- size = layout.computeSize (this, wHint, hHint, changed);
- } 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;
- 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);
-}
-
-/**
-* Computes the widget trim.
-*/
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- return new Rectangle(x-2, y-33, width+4, height+35);
-}
-
-/*
- **** Layout code ****
- */
-
-boolean _setSize(int width, int height) {
- boolean differentExtent = UtilFuncs.setSize(eventBoxHandle, width,height);
- UtilFuncs.setSize (fixedHandle, width,height);
- UtilFuncs.setSize (notebookHandle, width,height);
- UtilFuncs.setSize (handle, width-4, height-35);
- layoutCurrent();
- return differentExtent;
-}
-
-public Rectangle _getClientArea () {
- org.eclipse.swt.graphics.Point size = _getSize();
- int x = Math.max(size.x-4, 3);
- int y = Math.max(size.y-35, 3);
- return new Rectangle(0,0, x, y);
-}
-
-void layoutCurrent() {
- int index=getSelectionIndex();
- if (index==-1) return;
- Control control = items[index].control;
- if (control==null) return;
- if (control.isDisposed()) return;
- control.setBounds(getClientArea());
-}
-
-void createItem (TabItem item, int index) {
- int list = OS.gtk_container_children (notebookHandle);
- int itemCount = OS.g_list_length (list);
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_ITEM_NOT_ADDED);
- if (itemCount == items.length) {
- TabItem [] newItems = new TabItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
-
- // create a new label
- byte [] buffer = new byte [] {0};
- int labelHandle = OS.gtk_label_new (buffer);
-
- // create a new fake page
- int stubPage = OS.gtk_fixed_new();
-
- // put the label and the fake page inside the notebook
- OS.gtk_signal_handler_block_by_data (notebookHandle, SWT.Selection);
- OS.gtk_notebook_append_page(notebookHandle, stubPage, labelHandle);
- OS.gtk_signal_handler_unblock_by_data (notebookHandle, SWT.Selection);
-
- OS.gtk_widget_show(labelHandle);
- OS.gtk_widget_show(stubPage);
-
- item.state |= HANDLE;
- item.handle = labelHandle;
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
- OS.gtk_notebook_set_show_tabs (notebookHandle, 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>
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-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);
- OS.gtk_notebook_remove_page (notebookHandle, index);
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- item.handle = 0;
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>(none)</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 TabFolder extends Composite {
+ int notebookHandle;
+ TabItem [] items;
+
+
+/*
+ * == CONSTRUCTORS ==
+ */
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * for all SWT widget classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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));
+}
+
+/*
+ * == HANDLE DANCES, FIRST SPECIES ==
+ */
+
+void createHandle (int index) {
+ state |= HANDLE;
+ eventBoxHandle = OS.gtk_event_box_new();
+ fixedHandle = OS.gtk_fixed_new ();
+ notebookHandle = OS.gtk_notebook_new ();
+ handle = OS.gtk_fixed_new();
+}
+
+void configure () {
+ _connectParent();
+ OS.gtk_container_add(eventBoxHandle, fixedHandle);
+ OS.gtk_fixed_put (fixedHandle, notebookHandle, (short)0, (short)0);
+ OS.gtk_fixed_put (fixedHandle, handle, (short)2, (short)33);
+}
+
+void showHandle() {
+ OS.gtk_widget_show(eventBoxHandle);
+ OS.gtk_widget_show(fixedHandle);
+ OS.gtk_widget_show(notebookHandle);
+ OS.gtk_widget_show(handle);
+ OS.gtk_widget_realize (notebookHandle);
+ OS.gtk_widget_realize (handle);
+}
+
+void register () {
+ super.register ();
+ WidgetTable.put (notebookHandle, this);
+}
+
+void hookEvents () {
+ super.hookEvents ();
+ signal_connect (notebookHandle, "size_allocate", SWT.Resize, 3);
+ signal_connect (notebookHandle, "switch_page", SWT.Selection, 4);
+}
+
+void createWidget (int index) {
+ super.createWidget(index);
+ items = new TabItem [4];
+}
+
+int topHandle () { return eventBoxHandle; }
+int paintHandle () { return notebookHandle; }
+int parentingHandle () { return handle; }
+boolean isMyHandle(int h) {
+ if (h==eventBoxHandle) return true;
+ if (h==notebookHandle) return true;
+ if (h==fixedHandle) return true;
+ if (h==handle) return true;
+ return false;
+}
+
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ checkWidget ();
+ //notebookHandle
+ int width = _computeSize(wHint, hHint, changed).x;
+ int height = 0;
+ Point size;
+ if (layout != null) {
+ size = layout.computeSize (this, wHint, hHint, changed);
+ } 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;
+ 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);
+}
+
+/**
+* Computes the widget trim.
+*/
+public Rectangle computeTrim (int x, int y, int width, int height) {
+ checkWidget();
+ return new Rectangle(x-2, y-33, width+4, height+35);
+}
+
+/*
+ **** Layout code ****
+ */
+
+boolean _setSize(int width, int height) {
+ boolean differentExtent = UtilFuncs.setSize(eventBoxHandle, width,height);
+ UtilFuncs.setSize (fixedHandle, width,height);
+ UtilFuncs.setSize (notebookHandle, width,height);
+ UtilFuncs.setSize (handle, width-4, height-35);
+ layoutCurrent();
+ return differentExtent;
+}
+
+public Rectangle _getClientArea () {
+ org.eclipse.swt.graphics.Point size = _getSize();
+ int x = Math.max(size.x-4, 3);
+ int y = Math.max(size.y-35, 3);
+ return new Rectangle(0,0, x, y);
+}
+
+void layoutCurrent() {
+ int index=getSelectionIndex();
+ if (index==-1) return;
+ Control control = items[index].control;
+ if (control==null) return;
+ if (control.isDisposed()) return;
+ control.setBounds(getClientArea());
+}
+
+void createItem (TabItem item, int index) {
+ int list = OS.gtk_container_children (notebookHandle);
+ int itemCount = OS.g_list_length (list);
+ if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_ITEM_NOT_ADDED);
+ if (itemCount == items.length) {
+ TabItem [] newItems = new TabItem [items.length + 4];
+ System.arraycopy (items, 0, newItems, 0, items.length);
+ items = newItems;
+ }
+
+ // create a new label
+ byte [] buffer = new byte [] {0};
+ int labelHandle = OS.gtk_label_new (buffer);
+
+ // create a new fake page
+ int stubPage = OS.gtk_fixed_new();
+
+ // put the label and the fake page inside the notebook
+ OS.gtk_signal_handler_block_by_data (notebookHandle, SWT.Selection);
+ OS.gtk_notebook_append_page(notebookHandle, stubPage, labelHandle);
+ OS.gtk_signal_handler_unblock_by_data (notebookHandle, SWT.Selection);
+
+ OS.gtk_widget_show(labelHandle);
+ OS.gtk_widget_show(stubPage);
+
+ item.state |= HANDLE;
+ item.handle = labelHandle;
+ System.arraycopy (items, index, items, index + 1, itemCount++ - index);
+ items [index] = item;
+ OS.gtk_notebook_set_show_tabs (notebookHandle, 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>
+ * 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) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection,typedListener);
+ addListener(SWT.DefaultSelection,typedListener);
+}
+
+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);
+ OS.gtk_notebook_remove_page (notebookHandle, index);
+ System.arraycopy (items, index + 1, items, index, --itemCount - index);
+ items [itemCount] = null;
+ item.handle = 0;
+}
/**
* Returns the item at the given, zero-relative index in the
* receiver. Throws an exception if the index is out of range.
@@ -282,16 +282,16 @@ void destroyItem (TabItem item) {
* <li>ERROR_WIDGET_DISPOSED - if 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (notebookHandle);
- int itemCount = OS.g_list_length (list);
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_CANNOT_GET_ITEM);
- return items [index];
-}
+ */
+
+public TabItem getItem (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int list = OS.gtk_container_children (notebookHandle);
+ int itemCount = OS.g_list_length (list);
+ if (!(0 <= index && index < itemCount)) error (SWT.ERROR_CANNOT_GET_ITEM);
+ return items [index];
+}
/**
* Returns the number of items contained in the receiver.
*
@@ -301,14 +301,14 @@ public TabItem getItem (int index) {
* <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- //return itemCount;
- int list = OS.gtk_container_children (notebookHandle);
- return OS.g_list_length (list);
-}
+ */
+public int getItemCount () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ //return itemCount;
+ int list = OS.gtk_container_children (notebookHandle);
+ return OS.g_list_length (list);
+}
/**
* Returns an array of <code>TabItem</code>s which are the items
* in the receiver.
@@ -324,16 +324,16 @@ public int getItemCount () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (notebookHandle);
- int itemCount = OS.g_list_length (list);
- TabItem [] result = new TabItem [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
+ */
+public TabItem [] getItems () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int list = OS.gtk_container_children (notebookHandle);
+ int itemCount = OS.g_list_length (list);
+ TabItem [] result = new TabItem [itemCount];
+ System.arraycopy (items, 0, result, 0, itemCount);
+ return result;
+}
/**
* Returns an array of <code>TabItem</code>s that are currently
* selected in the receiver. An empty array indicates that no
@@ -349,14 +349,14 @@ public TabItem [] getItems () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int index = OS.gtk_notebook_get_current_page (notebookHandle);
- if (index == -1) return new TabItem [0];
- return new TabItem [] {items [index]};
-}
+ */
+public TabItem [] getSelection () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int index = OS.gtk_notebook_get_current_page (notebookHandle);
+ 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.
@@ -367,13 +367,13 @@ public TabItem [] getSelection () {
* <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return OS.gtk_notebook_get_current_page (notebookHandle);
-}
-
+ */
+public int getSelectionIndex () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return OS.gtk_notebook_get_current_page (notebookHandle);
+}
+
/**
* Searches the receiver's list starting at the first item
* (index 0) until an item is found that is equal to the
@@ -390,38 +390,38 @@ public int getSelectionIndex () {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int list = OS.gtk_container_children (notebookHandle);
- int itemCount = OS.g_list_length (list);
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-int processSelection (int int0, int int1, int int2) {
- int index = OS.gtk_notebook_get_current_page (notebookHandle);
- if (index != -1) {
- Control control = items [index].getControl ();
- if (control != null && !control.isDisposed ()) {
- control.setVisible (false);
- }
- }
- Control control = items [int1].getControl ();
- if (control != null && !control.isDisposed ()) {
- control.setBounds(getClientArea());
- control.setVisible (true);
- }
- Event event = new Event();
- event.item = items[int1];
- postEvent(SWT.Selection, event);
- return 0;
-}
-
+ */
+public int indexOf (TabItem item) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int list = OS.gtk_container_children (notebookHandle);
+ int itemCount = OS.g_list_length (list);
+ for (int i=0; i<itemCount; i++) {
+ if (items [i] == item) return i;
+ }
+ return -1;
+}
+
+int processSelection (int int0, int int1, int int2) {
+ int index = OS.gtk_notebook_get_current_page (notebookHandle);
+ if (index != -1) {
+ Control control = items [index].getControl ();
+ if (control != null && !control.isDisposed ()) {
+ control.setVisible (false);
+ }
+ }
+ Control control = items [int1].getControl ();
+ if (control != null && !control.isDisposed ()) {
+ control.setBounds(getClientArea());
+ control.setVisible (true);
+ }
+ Event event = new Event();
+ event.item = items[int1];
+ postEvent(SWT.Selection, event);
+ return 0;
+}
+
/**
* Removes the listener from the collection of listeners who will
* be notified when the receiver's selection changes.
@@ -438,15 +438,15 @@ int processSelection (int int0, int int1, int int2) {
*
* @see SelectionListener
* @see #addSelectionListener
- */
-public void removeSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
+ */
+public void removeSelectionListener (SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Selection, listener);
+ eventTable.unhook (SWT.DefaultSelection,listener);
+}
/**
* Selects the item at the given zero-relative index in the receiver.
* If the item at the index was already selected, it remains selected.
@@ -459,15 +459,15 @@ public void removeSelectionListener (SelectionListener listener) {
* <li>ERROR_WIDGET_DISPOSED - if the 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 (index == -1) return;
- OS.gtk_signal_handler_block_by_data (notebookHandle, SWT.Selection);
- OS.gtk_notebook_set_page (notebookHandle, index);
- OS.gtk_signal_handler_unblock_by_data (notebookHandle, SWT.Selection);
-}
-
+ */
+public void setSelection (int index) {
+ checkWidget();
+ if (index == -1) return;
+ OS.gtk_signal_handler_block_by_data (notebookHandle, SWT.Selection);
+ OS.gtk_notebook_set_page (notebookHandle, index);
+ OS.gtk_signal_handler_unblock_by_data (notebookHandle, SWT.Selection);
+}
+
/**
* Sets the receiver's selection to be the given array of items.
* The current selected is first cleared, then the new items are
@@ -479,78 +479,78 @@ public void setSelection (int index) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (items.length == 0) {
- setSelection (-1);
- return;
- }
- for (int i=items.length-1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) setSelection (index);
- }
-}
-
-/*
- * == DESTRUCTION ===
- */
-
-void deregister () {
- super.deregister ();
- WidgetTable.remove (notebookHandle);
-}
-
-void releaseChildren() {
- int list = OS.gtk_container_children (notebookHandle);
- int itemCount = OS.g_list_length (list);
- for (int i=0; i<itemCount; i++) {
- TabItem item = items [i];
- if (!item.isDisposed ()) {
- item.releaseWidget ();
- item.releaseHandle ();
- }
- }
-
- // Now, the non-item children
- list = OS.gtk_container_children(parentingHandle());
- int childCount = OS.g_list_length (list);
- for (int i=0; i<childCount; i++) {
- int childHandle = OS.g_list_nth_data(list, i);
- if (!isMyHandle(childHandle)) {
- Widget w = WidgetTable.get(childHandle);
- if (!(w==null) && !(w.isDisposed())) {
- w.releaseWidget();
- w.releaseHandle();
- }
- }
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- notebookHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget();
- items = null;
-}
-
-/*
- * == AS YET UNCLASSIFIED ===
- */
-
-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);
-}
-}
+ */
+public void setSelection (TabItem [] items) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (items.length == 0) {
+ setSelection (-1);
+ return;
+ }
+ for (int i=items.length-1; i>=0; --i) {
+ int index = indexOf (items [i]);
+ if (index != -1) setSelection (index);
+ }
+}
+
+/*
+ * == DESTRUCTION ===
+ */
+
+void deregister () {
+ super.deregister ();
+ WidgetTable.remove (notebookHandle);
+}
+
+void releaseChildren() {
+ int list = OS.gtk_container_children (notebookHandle);
+ int itemCount = OS.g_list_length (list);
+ for (int i=0; i<itemCount; i++) {
+ TabItem item = items [i];
+ if (!item.isDisposed ()) {
+ item.releaseWidget ();
+ item.releaseHandle ();
+ }
+ }
+
+ // Now, the non-item children
+ list = OS.gtk_container_children(parentingHandle());
+ int childCount = OS.g_list_length (list);
+ for (int i=0; i<childCount; i++) {
+ int childHandle = OS.g_list_nth_data(list, i);
+ if (!isMyHandle(childHandle)) {
+ Widget w = WidgetTable.get(childHandle);
+ if (!(w==null) && !(w.isDisposed())) {
+ w.releaseWidget();
+ w.releaseHandle();
+ }
+ }
+ }
+}
+
+void releaseHandle () {
+ super.releaseHandle ();
+ notebookHandle = 0;
+}
+
+void releaseWidget () {
+ super.releaseWidget();
+ items = null;
+}
+
+/*
+ * == AS YET UNCLASSIFIED ===
+ */
+
+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);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabItem.java
index 13a5eab531..2e2fb57381 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabItem.java
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -24,11 +24,11 @@ import org.eclipse.swt.graphics.*;
* <p>
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
- */
-
-public class TabItem extends Item {
- Control control;
- TabFolder parent;
+ */
+
+public class TabItem extends Item {
+ Control control;
+ TabFolder parent;
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>TabFolder</code>) and a style value
@@ -58,12 +58,12 @@ public class TabItem extends Item {
* @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 ());
-}
+ */
+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
@@ -94,12 +94,12 @@ public TabItem (TabFolder parent, int style) {
* @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);
-}
+ */
+public TabItem (TabFolder parent, int style, int index) {
+ super (parent, style);
+ this.parent = parent;
+ parent.createItem (this, index);
+}
/**
* Returns the control that is used to fill the client area of
* the tab folder when the user selects the tab item. If no
@@ -111,17 +111,17 @@ public TabItem (TabFolder parent, int style, int index) {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return control;
-}
-public Display getDisplay () {
- TabFolder parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
+ */
+public Control getControl () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return control;
+}
+public Display getDisplay () {
+ TabFolder parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
/**
* Returns the receiver's parent, which must be a <code>TabFolder</code>.
*
@@ -131,12 +131,12 @@ public Display getDisplay () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent;
-}
+ */
+public TabFolder getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
/**
* Returns the receiver's tool tip text, or null if it has
* not been set.
@@ -147,20 +147,20 @@ public TabFolder getParent () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return "";
-}
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
-}
+ */
+public String getToolTipText () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return "";
+}
+void releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+void releaseWidget () {
+ super.releaseWidget ();
+ parent = null;
+}
/**
* Sets the control that is used to fill the client area of
* the tab folder when the user selects the tab item.
@@ -175,33 +175,33 @@ void releaseWidget () {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- Control oldControl = this.control, newControl = control;
- this.control = control;
- int index = parent.indexOf (this);
- if (index != parent.getSelectionIndex ()) return;
- if (newControl != null) {
- newControl.setBounds (parent.getClientArea ());
- newControl.setVisible (true);
- }
- if (oldControl != null) oldControl.setVisible (false);
-}
-public void setImage (Image image) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- super.setImage (image);
-}
-public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- byte [] buffer = string2bytesConvertMnemonic(string);
- OS.gtk_label_parse_uline(handle, buffer);
-}
+ */
+public void setControl (Control control) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ Control oldControl = this.control, newControl = control;
+ this.control = control;
+ int index = parent.indexOf (this);
+ if (index != parent.getSelectionIndex ()) return;
+ if (newControl != null) {
+ newControl.setBounds (parent.getClientArea ());
+ newControl.setVisible (true);
+ }
+ if (oldControl != null) oldControl.setVisible (false);
+}
+public void setImage (Image image) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ super.setImage (image);
+}
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ super.setText (string);
+ byte [] buffer = string2bytesConvertMnemonic(string);
+ OS.gtk_label_parse_uline(handle, buffer);
+}
/**
* Sets the receiver's tool tip text to the argument, which
* may be null indicating that no tool tip text should be shown.
@@ -212,9 +212,9 @@ public void setText (String string) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-}
+ */
+public void setToolTipText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableColumn.java
index 021c46b64b..db974376ea 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableColumn.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableColumn.java
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
* <dl>
@@ -21,15 +21,15 @@ import org.eclipse.swt.events.*;
* <dt><b>Events:</b></dt>
* <dd> Move, Resize, Selection</dd>
* </dl>
- * <p>
- * Note: Only one of the styles LEFT, RIGHT and CENTER may be specified.
- * </p><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;
+ */
+
+public class TableColumn extends Item {
+ Table parent;
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Table</code>) and a style value
@@ -59,12 +59,12 @@ public class TableColumn extends Item {
* @see SWT
* @see Widget#checkSubclass
* @see Widget#getStyle
- */
-public TableColumn (Table parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (parent.getColumnCount ());
-}
+ */
+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
@@ -95,12 +95,12 @@ public TableColumn (Table parent, int style) {
* @see SWT
* @see Widget#checkSubclass
* @see Widget#getStyle
- */
-public TableColumn (Table parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (index);
-}
+ */
+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
@@ -119,54 +119,54 @@ public TableColumn (Table parent, int style, int index) {
*
* @see ControlListener
* @see #removeControlListener
- */
-public void addControlListener(ControlListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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);
-}
-void createWidget (int index) {
- parent.createItem (this, index);
- text = "";
-}
+ */
+public void addControlListener(ControlListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
+}
+void createWidget (int index) {
+ parent.createItem (this, index);
+ text = "";
+}
/**
* Returns a value which describes the position of the
* text or image in the receiver. The value will be one of
@@ -178,20 +178,20 @@ void createWidget (int index) {
* <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 Display getDisplay () {
- Table parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
+ */
+public int getAlignment () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 Display getDisplay () {
+ Table parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
/**
* Returns the receiver's parent, which must be a <code>Table</code>.
*
@@ -201,12 +201,12 @@ public Display getDisplay () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent;
-}
+ */
+public Table getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
/**
* Gets the resizable attribute. A column that is
* not resizable cannot be dragged by the user but
@@ -218,19 +218,19 @@ public Table getParent () {
* <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int index = parent.indexOf (this);
- if (index == -1) return false;
- GtkCList gtkclist = new GtkCList();
- OS.memmove(gtkclist, parent.handle, GtkCList.sizeof);
- int chandle=gtkclist.column;
- GtkCListColumn gtkcolumn = new GtkCListColumn();
- OS.memmove(gtkcolumn, chandle+index*GtkCListColumn.sizeof, GtkCListColumn.sizeof);
- return (gtkcolumn.resizeable == 1) ? true : false;
-}
+ */
+public boolean getResizable () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int index = parent.indexOf (this);
+ if (index == -1) return false;
+ GtkCList gtkclist = new GtkCList();
+ OS.memmove(gtkclist, parent.handle, GtkCList.sizeof);
+ int chandle=gtkclist.column;
+ GtkCListColumn gtkcolumn = new GtkCListColumn();
+ OS.memmove(gtkcolumn, chandle+index*GtkCListColumn.sizeof, GtkCListColumn.sizeof);
+ return (gtkcolumn.resizeable == 1) ? true : false;
+}
/**
* Gets the width of the receiver.
*
@@ -240,19 +240,19 @@ public boolean getResizable () {
* <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int index = parent.indexOf (this);
- if (index == -1) return 0;
- GtkCList gtkclist = new GtkCList();
- OS.memmove(gtkclist, parent.handle, GtkCList.sizeof);
- int chandle=gtkclist.column;
- GtkCListColumn gtkcolumn = new GtkCListColumn();
- OS.memmove(gtkcolumn, chandle+index*GtkCListColumn.sizeof, GtkCListColumn.sizeof);
- return gtkcolumn.width;
-}
+ */
+public int getWidth () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int index = parent.indexOf (this);
+ if (index == -1) return 0;
+ GtkCList gtkclist = new GtkCList();
+ OS.memmove(gtkclist, parent.handle, GtkCList.sizeof);
+ int chandle=gtkclist.column;
+ GtkCListColumn gtkcolumn = new GtkCListColumn();
+ OS.memmove(gtkcolumn, chandle+index*GtkCListColumn.sizeof, GtkCListColumn.sizeof);
+ return gtkcolumn.width;
+}
/**
* Causes the receiver to be resized to its preferred size.
* For a composite, this involves computing the preferred size
@@ -263,20 +263,20 @@ public int getWidth () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*
- */
-public void pack () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-void releaseWidget () {
- super.releaseWidget ();
- text = null;
- parent = null;
-}
+ */
+public void pack () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+}
+void releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+void releaseWidget () {
+ super.releaseWidget ();
+ text = null;
+ parent = null;
+}
/**
* Removes the listener from the collection of listeners who will
* be notified when the control is moved or resized.
@@ -293,15 +293,15 @@ void releaseWidget () {
*
* @see ControlListener
* @see #addControlListener
- */
-public void removeControlListener (ControlListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
+ */
+public void removeControlListener (ControlListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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.
@@ -318,15 +318,15 @@ public void removeControlListener (ControlListener listener) {
*
* @see SelectionListener
* @see #addSelectionListener
- */
-public void removeSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
+ */
+public void removeSelectionListener(SelectionListener listener) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
@@ -338,22 +338,22 @@ public void removeSelectionListener(SelectionListener listener) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- int table = parent.handle;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- int justification = 0;
- if ((style & SWT.LEFT) == SWT.LEFT) justification |= OS.GTK_JUSTIFY_LEFT;
- if ((style & SWT.CENTER) == SWT.CENTER) justification |= OS.GTK_JUSTIFY_CENTER;
- if ((style & SWT.RIGHT) == SWT.RIGHT) justification |= OS.GTK_JUSTIFY_RIGHT;
- OS.gtk_clist_set_column_justification (table, index, justification);
-}
+ */
+public void setAlignment (int alignment) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
+ int index = parent.indexOf (this);
+ if (index == -1 || index == 0) return;
+ int table = parent.handle;
+ style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
+ style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
+ int justification = 0;
+ if ((style & SWT.LEFT) == SWT.LEFT) justification |= OS.GTK_JUSTIFY_LEFT;
+ if ((style & SWT.CENTER) == SWT.CENTER) justification |= OS.GTK_JUSTIFY_CENTER;
+ if ((style & SWT.RIGHT) == SWT.RIGHT) justification |= OS.GTK_JUSTIFY_RIGHT;
+ OS.gtk_clist_set_column_justification (table, index, justification);
+}
/**
* Sets the resizable attribute. A column that is
* not resizable cannot be dragged by the user but
@@ -365,26 +365,26 @@ public void setAlignment (int alignment) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int index = parent.indexOf (this);
- if (index == -1) return;
- int table = parent.handle;
- OS.gtk_clist_set_column_resizeable (table, index, resizable);
-}
-public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- int index = parent.indexOf (this);
- if (index == -1) return;
- int table = parent.handle;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- OS.gtk_clist_set_column_title (table, index, buffer);
-}
+ */
+public void setResizable (boolean resizable) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int index = parent.indexOf (this);
+ if (index == -1) return;
+ int table = parent.handle;
+ OS.gtk_clist_set_column_resizeable (table, index, resizable);
+}
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ super.setText (string);
+ int index = parent.indexOf (this);
+ if (index == -1) return;
+ int table = parent.handle;
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ OS.gtk_clist_set_column_title (table, index, buffer);
+}
/**
* Sets the width of the receiver.
*
@@ -394,14 +394,14 @@ public void setText (String string) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int index = parent.indexOf (this);
- if (index == -1) return;
- int table = parent.handle;
- OS.gtk_clist_set_column_width (table, index, width);
-}
-
-}
+ */
+public void setWidth (int width) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int index = parent.indexOf (this);
+ if (index == -1) return;
+ int table = parent.handle;
+ OS.gtk_clist_set_column_width (table, index, width);
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableItem.java
index fcf6cad597..82239af3c2 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableItem.java
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.gtk.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.graphics.*;
+
/**
* Instances of this class represent a selectable user interface object
* that represents an item in a table.
@@ -25,10 +25,10 @@ import org.eclipse.swt.graphics.*;
* <p>
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
- */
-
-public class TableItem extends Item {
- Table parent;
+ */
+
+public class TableItem extends Item {
+ Table parent;
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Table</code>) and a style value
@@ -59,12 +59,12 @@ public class TableItem extends Item {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public TableItem (Table parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
- _setChecked(false);
-}
+public TableItem (Table parent, int style) {
+ super (parent, style);
+ this.parent = parent;
+ parent.createItem (this, parent.getItemCount ());
+ _setChecked(false);
+}
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Table</code>), a style value
@@ -96,30 +96,30 @@ public TableItem (Table parent, int style) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public TableItem (Table parent, int style, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
- _setChecked(false);
-}
-/**
- * Returns the receiver's background color.
- *
- * @return the background color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getBackground () {
- checkWidget ();
- Table parent = getParent();
- return parent.getBackground();
-}
+public TableItem (Table parent, int style, int index) {
+ super (parent, style);
+ this.parent = parent;
+ parent.createItem (this, index);
+ _setChecked(false);
+}
+/**
+ * Returns the receiver's background color.
+ *
+ * @return the background color
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @since 2.0
+ *
+ */
+public Color getBackground () {
+ checkWidget ();
+ Table parent = getParent();
+ return parent.getBackground();
+}
/**
* Returns a rectangle describing the receiver's size and location
* relative to its parent at a column in the table.
@@ -131,38 +131,38 @@ public Color getBackground () {
* <li>ERROR_WIDGET_DISPOSED - if 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int CELL_SPACING=1;
- GtkCList table = new GtkCList();
- OS.memmove(table, parent.handle, GtkCList.sizeof);
- int columnHandle = table.column;
- columnHandle= columnHandle+index*GtkCListColumn.sizeof;
- GtkCListColumn column=new GtkCListColumn();
- OS.memmove(column, columnHandle, GtkCListColumn.sizeof);
- GtkAdjustment adjustment=new GtkAdjustment();
- OS.memmove(adjustment, table.vadjustment, GtkAdjustment.sizeof);
- float vaj = adjustment.value;
- OS.memmove(adjustment, table.hadjustment, GtkAdjustment.sizeof);
- float haj = adjustment.value;
- int x=(short)column.area_x+table.hoffset;
- int width=(short)column.area_width;
- int height=parent.getItemHeight();
- int row=parent.indexOf(this);
- int y=table.column_title_area_height+height*row+(row+2)*CELL_SPACING-(int)vaj;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Return whether or not the receiver has a check box and can
- * be checked.
- */
-boolean isCheckable() {
- return (parent.style & SWT.CHECK) != 0;
-}
-
+ */
+public Rectangle getBounds (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int CELL_SPACING=1;
+ GtkCList table = new GtkCList();
+ OS.memmove(table, parent.handle, GtkCList.sizeof);
+ int columnHandle = table.column;
+ columnHandle= columnHandle+index*GtkCListColumn.sizeof;
+ GtkCListColumn column=new GtkCListColumn();
+ OS.memmove(column, columnHandle, GtkCListColumn.sizeof);
+ GtkAdjustment adjustment=new GtkAdjustment();
+ OS.memmove(adjustment, table.vadjustment, GtkAdjustment.sizeof);
+ float vaj = adjustment.value;
+ OS.memmove(adjustment, table.hadjustment, GtkAdjustment.sizeof);
+ float haj = adjustment.value;
+ int x=(short)column.area_x+table.hoffset;
+ int width=(short)column.area_width;
+ int height=parent.getItemHeight();
+ int row=parent.indexOf(this);
+ int y=table.column_title_area_height+height*row+(row+2)*CELL_SPACING-(int)vaj;
+ return new Rectangle (x, y, width, height);
+}
+
+/**
+ * Return whether or not the receiver has a check box and can
+ * be checked.
+ */
+boolean isCheckable() {
+ return (parent.style & SWT.CHECK) != 0;
+}
+
/**
* Returns <code>true</code> if the receiver is checked,
* and false otherwise. When the parent does not have
@@ -174,50 +174,50 @@ boolean isCheckable() {
* <li>ERROR_WIDGET_DISPOSED - if the 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.style & SWT.CHECK) == 0) return false;
- return _getChecked();
-}
-
-boolean _getChecked () {
- int row = parent.indexOf (this);
- if (row == -1) return false;
- int clist = parent.handle;
-
- int[] text = new int[1];
- int[] spacing = new int[1];
- int[] pixmap = new int[1];
- int[] mask = new int[1];
- OS.gtk_clist_get_pixtext(clist, row, 0, text, spacing, pixmap, mask);
-
- return pixmap[0]==parent.check;
-}
-
-public Display getDisplay () {
- Table parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/**
- * 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 ();
- Table parent = getParent();
- return parent.getForeground();
-}
+ */
+public boolean getChecked () {
+ checkWidget();
+ if ((parent.style & SWT.CHECK) == 0) return false;
+ return _getChecked();
+}
+
+boolean _getChecked () {
+ int row = parent.indexOf (this);
+ if (row == -1) return false;
+ int clist = parent.handle;
+
+ int[] text = new int[1];
+ int[] spacing = new int[1];
+ int[] pixmap = new int[1];
+ int[] mask = new int[1];
+ OS.gtk_clist_get_pixtext(clist, row, 0, text, spacing, pixmap, mask);
+
+ return pixmap[0]==parent.check;
+}
+
+public Display getDisplay () {
+ Table parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+ * 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 ();
+ Table parent = getParent();
+ return parent.getForeground();
+}
/**
* Returns <code>true</code> if the receiver is grayed,
* and false otherwise. When the parent does not have
@@ -229,36 +229,36 @@ public Color getForeground () {
* <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return false;
-}
-
-/**
-* Gets the image at an index.
-* <p>
-* Indexing is zero based.
-*
-* This operation will fail when the index is out
-* of range or an item could not be queried from
-* the OS.
-*
-* @param index the index of the image
-* @return the image
-*
-* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
-* when called from the wrong thread
-* @exception SWTError(ERROR_WIDGET_DISPOSED)
-* when the widget has been disposed
-*/
-public Image getImage (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return null;
-}
+ */
+public boolean getGrayed () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if ((parent.style & SWT.CHECK) == 0) return false;
+ return false;
+}
+
+/**
+* Gets the image at an index.
+* <p>
+* Indexing is zero based.
+*
+* This operation will fail when the index is out
+* of range or an item could not be queried from
+* the OS.
+*
+* @param index the index of the image
+* @return the image
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Image getImage (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return null;
+}
/**
* Returns a rectangle describing the size and location
* relative to its parent of an image at a column in the
@@ -271,12 +271,12 @@ public Image getImage (int index) {
* <li>ERROR_WIDGET_DISPOSED - if 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return new Rectangle (0, 0, 0, 0);
-}
+ */
+public Rectangle getImageBounds (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return new Rectangle (0, 0, 0, 0);
+}
/**
* Gets the image indent.
*
@@ -286,12 +286,12 @@ public Rectangle getImageBounds (int index) {
* <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return 0;
-}
+ */
+public int getImageIndent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return 0;
+}
/**
* Returns the receiver's parent, which must be a <code>Table</code>.
*
@@ -301,67 +301,67 @@ public int getImageIndent () {
* <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent;
-}
-/**
-* Gets the item text at an index.
-* <p>
-* Indexing is zero based.
-*
-* This operation will fail when the index is out
-* of range or an item could not be queried from
-* the OS.
-*
-* @param index the index of the item
-* @return the item
-*
-* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
-* when called from the wrong thread
-* @exception SWTError(ERROR_WIDGET_DISPOSED)
-* when the widget has been disposed
-* @exception SWTError(ERROR_CANNOT_GET_TEXT)
-* when the operation fails
-*/
-public String getText (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return "";
-}
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-void releaseWidget () {
- super.releaseWidget ();
- parent = 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);
-}
+ */
+public Table getParent () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent;
+}
+/**
+* Gets the item text at an index.
+* <p>
+* Indexing is zero based.
+*
+* This operation will fail when the index is out
+* of range or an item could not be queried from
+* the OS.
+*
+* @param index the index of the item
+* @return the item
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+* @exception SWTError(ERROR_CANNOT_GET_TEXT)
+* when the operation fails
+*/
+public String getText (int index) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ return "";
+}
+void releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+void releaseWidget () {
+ super.releaseWidget ();
+ parent = 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);
+}
/**
* Sets the checked state of the receiver.
*
@@ -371,46 +371,46 @@ public void setBackground (Color color) {
* <li>ERROR_WIDGET_DISPOSED - if the 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();
- _setChecked (checked);
-}
-void _setChecked (boolean checked) {
- if ((parent.style & SWT.CHECK) == 0) return; /* needed here because we don't verify in the constructor */
-
- int row = parent.indexOf (this);
- if (row == -1) return;
- int ctable = parent.handle;
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- if (checked) OS.gtk_clist_set_pixtext (ctable, row, 0, buffer, (byte) 2, parent.check, 0);
- else OS.gtk_clist_set_pixtext (ctable, row, 0, buffer, (byte) 2, parent.uncheck, 0);
-}
-
-/**
- * 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);
-}
-
+ */
+public void setChecked (boolean checked) {
+ checkWidget();
+ _setChecked (checked);
+}
+void _setChecked (boolean checked) {
+ if ((parent.style & SWT.CHECK) == 0) return; /* needed here because we don't verify in the constructor */
+
+ int row = parent.indexOf (this);
+ if (row == -1) return;
+ int ctable = parent.handle;
+ byte [] buffer = Converter.wcsToMbcs (null, text, true);
+ if (checked) OS.gtk_clist_set_pixtext (ctable, row, 0, buffer, (byte) 2, parent.check, 0);
+ else OS.gtk_clist_set_pixtext (ctable, row, 0, buffer, (byte) 2, parent.uncheck, 0);
+}
+
+/**
+ * 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);
+}
+
/**
* Sets the grayed state of the receiver.
*
@@ -420,10 +420,10 @@ public void setForeground (Color color){
* <li>ERROR_WIDGET_DISPOSED - if the 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();
-}
+ */
+public void setGrayed (boolean grayed) {
+ checkWidget();
+}
/**
* Sets the receiver's image at a column.
*
@@ -437,48 +437,48 @@ public void setGrayed (boolean grayed) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-// if (index == 0) {
-// setImage (image);
-// return;
-// }
- int row = parent.indexOf (this);
- if (row == -1) return;
- int pixmap = 0, mask = 0;
- if (image != null) {
- pixmap = image.pixmap;
- mask = image.mask;
- }
- int ctable = parent.handle;
- if (text != null) {
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- OS.gtk_clist_set_pixtext (ctable, row, index, buffer, (byte) 2, pixmap, mask);
- } else {
- OS.gtk_clist_set_pixmap (ctable, row, index, pixmap, mask);
- }
-}
-public void setImage (Image image) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int row = parent.indexOf (this);
- if (row == -1) return;
- super.setImage (image);
- int ctable = parent.handle;
- int pixmap = 0, mask = 0;
- if (image != null) {
- pixmap = image.pixmap;
- mask = image.mask;
- }
- if (text != null) {
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- OS.gtk_clist_set_pixtext (ctable, row, 0, buffer, (byte) 2, pixmap, mask);
- } else {
- OS.gtk_clist_set_pixmap (ctable, row, 0, pixmap, mask);
- }
-}
+ */
+public void setImage (int index, Image image) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+// if (index == 0) {
+// setImage (image);
+// return;
+// }
+ int row = parent.indexOf (this);
+ if (row == -1) return;
+ int pixmap = 0, mask = 0;
+ if (image != null) {
+ pixmap = image.pixmap;
+ mask = image.mask;
+ }
+ int ctable = parent.handle;
+ if (text != null) {
+ byte [] buffer = Converter.wcsToMbcs (null, text, true);
+ OS.gtk_clist_set_pixtext (ctable, row, index, buffer, (byte) 2, pixmap, mask);
+ } else {
+ OS.gtk_clist_set_pixmap (ctable, row, index, pixmap, mask);
+ }
+}
+public void setImage (Image image) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ int row = parent.indexOf (this);
+ if (row == -1) return;
+ super.setImage (image);
+ int ctable = parent.handle;
+ int pixmap = 0, mask = 0;
+ if (image != null) {
+ pixmap = image.pixmap;
+ mask = image.mask;
+ }
+ if (text != null) {
+ byte [] buffer = Converter.wcsToMbcs (null, text, true);
+ OS.gtk_clist_set_pixtext (ctable, row, 0, buffer, (byte) 2, pixmap, mask);
+ } else {
+ OS.gtk_clist_set_pixmap (ctable, row, 0, pixmap, mask);
+ }
+}
/**
* Sets the image for multiple columns in the Table.
*
@@ -492,15 +492,15 @@ public void setImage (Image image) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
+ */
+public void setImage (Image [] images) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
+ for (int i=0; i<images.length; i++) {
+ setImage (i, images [i]);
+ }
+}
/**
* Sets the image indent.
*
@@ -511,11 +511,11 @@ public void setImage (Image [] images) {
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
- */
-public void setImageIndent (int indent) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-}
+ */
+public void setImageIndent (int indent) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+}
/**
* Sets the receiver's text at a column
*
@@ -529,40 +529,40 @@ public void setImageIndent (int indent) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == 0) {
- setText (string);
- return;
- }
- int row = parent.indexOf (this);
- if (row == -1) return;
- int ctree = parent.handle;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- if (image != null) {
- OS.gtk_clist_set_pixtext(ctree, row, index, buffer, (byte) 2, image.pixmap, image.mask);
- } else {
- OS.gtk_clist_set_text (ctree, row, index, buffer);
- }
-}
-public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int row = parent.indexOf (this);
- if (row == -1) return;
- super.setText (string);
- int ctree = parent.handle;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- if (image != null) {
- OS.gtk_clist_set_pixtext(ctree, row, 0, buffer, (byte) 2, image.pixmap, image.mask);
- } else {
- OS.gtk_clist_set_text (ctree, row, 0, buffer);
- }
-}
+ */
+public void setText (int index, String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (index == 0) {
+ setText (string);
+ return;
+ }
+ int row = parent.indexOf (this);
+ if (row == -1) return;
+ int ctree = parent.handle;
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ if (image != null) {
+ OS.gtk_clist_set_pixtext(ctree, row, index, buffer, (byte) 2, image.pixmap, image.mask);
+ } else {
+ OS.gtk_clist_set_text (ctree, row, index, buffer);
+ }
+}
+public void setText (String string) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int row = parent.indexOf (this);
+ if (row == -1) return;
+ super.setText (string);
+ int ctree = parent.handle;
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ if (image != null) {
+ OS.gtk_clist_set_pixtext(ctree, row, 0, buffer, (byte) 2, image.pixmap, image.mask);
+ } else {
+ OS.gtk_clist_set_text (ctree, row, 0, buffer);
+ }
+}
/**
* Sets the text for multiple columns in the table.
*
@@ -575,14 +575,14 @@ public void setText (String string) {
* <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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);
- }
-}
-}
+ */
+public void setText (String [] strings) {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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/gtk1x/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ToolBar.java
index 827c071bd8..ceaf15f7d6 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ToolBar.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ToolBar.java
@@ -307,8 +307,8 @@ public int indexOf (ToolItem item) {
// TEMPORARY CODE
ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- if (item == items[i]) return i;
+ for (int i=0; i<items.length; i++) {
+ if (item == items[i]) return i;
}
return -1;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Tracker.java
index 9d9e66a476..5e7acf50c9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Tracker.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Tracker.java
@@ -1,392 +1,392 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 rubber banding rectangles.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Move</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
-public class Tracker extends Widget {
- Composite parent;
- Display display;
- boolean tracking, stippled;
- Rectangle [] rectangles = new Rectangle [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
- * for all SWT widget classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </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
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tracker (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- display = parent.getDisplay ();
-}
-
-/**
- * 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
- * for all SWT widget classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </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>
- */
-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 = style;
- this.display = display;
-}
-
-
-
-/*
- * === ADD / REMOVE LISTENERS ===
- */
-
-/**
- * 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.Move,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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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);
-}
-
-
-
-
-/*
- * === PUBLIC ACCESSORS ===
- */
-
-public Display getDisplay () {
- return display;
-}
-
-/**
- * Returns the bounds that are being drawn, expressed relative to the parent
- * widget. If the parent is a Display 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();
- return rectangles;
-}
-
-/**
- * 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;
-}
-
-/**
- * Specify 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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();
- this.rectangles = rectangles;
-}
-
-/**
- * Change 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;
-}
-
-
-
-/*
- * === PUBLIC FUNCTIONALITY ===
- */
-
-/**
- * Stop displaying the tracker 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 void close () {
- checkWidget();
- tracking = false;
-}
-
-/**
- * Start displaying the Tracker 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 open () {
- checkWidget();
- int xWindow = calculateWindow();
- boolean cancelled=false;
- tracking = true;
- drawRectangles ();
-
- int[] newX = new int[1];
- int[] newY = new int[1];
- int[] oldX = new int[1];
- int[] oldY = new int[1];
- OS.gdk_window_get_pointer(xWindow, oldX,oldY, 0);
-
- while (tracking) {
- if (parent != null && parent.isDisposed ()) break;
- int eventType = waitEvent();
- switch (eventType) {
- case OS.GDK_BUTTON_RELEASE:
- case OS.GDK_MOTION_NOTIFY:
- OS.gdk_window_get_pointer(xWindow, newX,newY, 0);
- if (oldX [0] != newX [0] || oldY [0] != newY [0]) {
- drawRectangles ();
- for (int i=0; i<rectangles.length; i++) {
- rectangles [i].x += newX [0] - oldX [0];
- rectangles [i].y += newY [0] - oldY [0];
- }
- Event event = new Event();
- event.x = newX[0];
- event.y = newY[0];
- sendEvent (SWT.Move,event);
- drawRectangles ();
- oldX [0] = newX [0]; oldY [0] = newY [0];
- }
- tracking = (eventType != OS.GDK_BUTTON_RELEASE);
- break;
- case OS.GDK_KEY_PRESS:
-// error(SWT.ERROR_NOT_IMPLEMENTED);
- /*
- XKeyEvent keyEvent = new XKeyEvent ();
- OS.memmove (keyEvent, xEvent, XKeyEvent.sizeof);
- if (keyEvent.keycode != 0) {
- int [] keysym = new int [1];
- OS.XLookupString (keyEvent, null, 0, keysym, null);
- keysym [0] &= 0xFFFF;
- tracking = keysym [0] != OS.XK_Escape && keysym [0] != OS.XK_Cancel;
- cancelled = !tracking;
- }*/
- break;
- } // switch
- } // while
- drawRectangles(); // clean up our mess
- tracking = false;
- return !cancelled;
-}
-
-
-
-private void drawRectangles () {
- int xWindow = calculateWindow();
- if (parent != null) {
- if (parent.isDisposed ()) return;
- parent.getShell ().update ();
- } else {
- display.update ();
- }
-
- int gc = OS.gdk_gc_new(xWindow);
- if (gc==0) error(SWT.ERROR_UNSPECIFIED);
-
- /* White foreground */
- int colormap = OS.gdk_colormap_get_system();
- GdkColor color = new GdkColor();
- OS.gdk_color_white(colormap, color);
- OS.gdk_gc_set_foreground(gc, color);
-
- /* Draw on top of inferior widgets */
- OS.gdk_gc_set_subwindow(gc, OS.GDK_INCLUDE_INFERIORS);
-
- /* XOR */
- OS.gdk_gc_set_function(gc, OS.GDK_XOR);
-
- for (int i=0; i<rectangles.length; i++) {
- Rectangle rect = rectangles [i];
- OS.gdk_draw_rectangle(xWindow, gc, 0, rect.x, rect.y, rect.width, rect.height);
- }
- OS.gdk_gc_destroy(gc);
-}
-/*
- * Wait for an event to show up.
- * Return the event's type as a GdkEventType.
- */
-private int waitEvent() {
- int[] eventType = new int[1];
- int eventPtr;
-
- while (true) {
- eventPtr = OS.gdk_event_get();
- if (eventPtr != 0) {
- // hack, must implement memmove properly
- // GdkEvent event = new GdkEvent(eventPtr);
- OS.memmove(eventType, eventPtr, 4);
- OS.gdk_event_free(eventPtr);
- return eventType[0];
- }
- else {
- try { Thread.sleep(50); } catch (Exception ex) {}
- }
- }
-}
-
-/*
- * Figure which GdkWindow we'll draw on.
- * That's normally the root X window, or the parent's GdkWindow if we have a parent.
- */
-private int calculateWindow() {
- int answer;
- if (parent == null) {
- answer = OS.GDK_ROOT_PARENT();
- } else {
- answer = parent._gdkWindow();
- }
- if (answer==0) error(SWT.ERROR_UNSPECIFIED);
- return answer;
-}
-
-public void setCursor (Cursor value) {
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 rubber banding rectangles.
+ *
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>(none)</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>Move</dd>
+ * </dl>
+ * <p>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ * </p>
+ */
+public class Tracker extends Widget {
+ Composite parent;
+ Display display;
+ boolean tracking, stippled;
+ Rectangle [] rectangles = new Rectangle [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
+ * for all SWT widget classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </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
+ * @see Widget#checkSubclass
+ * @see Widget#getStyle
+ */
+public Tracker (Composite parent, int style) {
+ super (parent, style);
+ this.parent = parent;
+ display = parent.getDisplay ();
+}
+
+/**
+ * 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
+ * for all SWT widget classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </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>
+ */
+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 = style;
+ this.display = display;
+}
+
+
+
+/*
+ * === ADD / REMOVE LISTENERS ===
+ */
+
+/**
+ * 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.Move,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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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);
+}
+
+
+
+
+/*
+ * === PUBLIC ACCESSORS ===
+ */
+
+public Display getDisplay () {
+ return display;
+}
+
+/**
+ * Returns the bounds that are being drawn, expressed relative to the parent
+ * widget. If the parent is a Display 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();
+ return rectangles;
+}
+
+/**
+ * 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;
+}
+
+/**
+ * Specify 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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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();
+ this.rectangles = rectangles;
+}
+
+/**
+ * Change 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;
+}
+
+
+
+/*
+ * === PUBLIC FUNCTIONALITY ===
+ */
+
+/**
+ * Stop displaying the tracker 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 void close () {
+ checkWidget();
+ tracking = false;
+}
+
+/**
+ * Start displaying the Tracker 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 open () {
+ checkWidget();
+ int xWindow = calculateWindow();
+ boolean cancelled=false;
+ tracking = true;
+ drawRectangles ();
+
+ int[] newX = new int[1];
+ int[] newY = new int[1];
+ int[] oldX = new int[1];
+ int[] oldY = new int[1];
+ OS.gdk_window_get_pointer(xWindow, oldX,oldY, 0);
+
+ while (tracking) {
+ if (parent != null && parent.isDisposed ()) break;
+ int eventType = waitEvent();
+ switch (eventType) {
+ case OS.GDK_BUTTON_RELEASE:
+ case OS.GDK_MOTION_NOTIFY:
+ OS.gdk_window_get_pointer(xWindow, newX,newY, 0);
+ if (oldX [0] != newX [0] || oldY [0] != newY [0]) {
+ drawRectangles ();
+ for (int i=0; i<rectangles.length; i++) {
+ rectangles [i].x += newX [0] - oldX [0];
+ rectangles [i].y += newY [0] - oldY [0];
+ }
+ Event event = new Event();
+ event.x = newX[0];
+ event.y = newY[0];
+ sendEvent (SWT.Move,event);
+ drawRectangles ();
+ oldX [0] = newX [0]; oldY [0] = newY [0];
+ }
+ tracking = (eventType != OS.GDK_BUTTON_RELEASE);
+ break;
+ case OS.GDK_KEY_PRESS:
+// error(SWT.ERROR_NOT_IMPLEMENTED);
+ /*
+ XKeyEvent keyEvent = new XKeyEvent ();
+ OS.memmove (keyEvent, xEvent, XKeyEvent.sizeof);
+ if (keyEvent.keycode != 0) {
+ int [] keysym = new int [1];
+ OS.XLookupString (keyEvent, null, 0, keysym, null);
+ keysym [0] &= 0xFFFF;
+ tracking = keysym [0] != OS.XK_Escape && keysym [0] != OS.XK_Cancel;
+ cancelled = !tracking;
+ }*/
+ break;
+ } // switch
+ } // while
+ drawRectangles(); // clean up our mess
+ tracking = false;
+ return !cancelled;
+}
+
+
+
+private void drawRectangles () {
+ int xWindow = calculateWindow();
+ if (parent != null) {
+ if (parent.isDisposed ()) return;
+ parent.getShell ().update ();
+ } else {
+ display.update ();
+ }
+
+ int gc = OS.gdk_gc_new(xWindow);
+ if (gc==0) error(SWT.ERROR_UNSPECIFIED);
+
+ /* White foreground */
+ int colormap = OS.gdk_colormap_get_system();
+ GdkColor color = new GdkColor();
+ OS.gdk_color_white(colormap, color);
+ OS.gdk_gc_set_foreground(gc, color);
+
+ /* Draw on top of inferior widgets */
+ OS.gdk_gc_set_subwindow(gc, OS.GDK_INCLUDE_INFERIORS);
+
+ /* XOR */
+ OS.gdk_gc_set_function(gc, OS.GDK_XOR);
+
+ for (int i=0; i<rectangles.length; i++) {
+ Rectangle rect = rectangles [i];
+ OS.gdk_draw_rectangle(xWindow, gc, 0, rect.x, rect.y, rect.width, rect.height);
+ }
+ OS.gdk_gc_destroy(gc);
+}
+/*
+ * Wait for an event to show up.
+ * Return the event's type as a GdkEventType.
+ */
+private int waitEvent() {
+ int[] eventType = new int[1];
+ int eventPtr;
+
+ while (true) {
+ eventPtr = OS.gdk_event_get();
+ if (eventPtr != 0) {
+ // hack, must implement memmove properly
+ // GdkEvent event = new GdkEvent(eventPtr);
+ OS.memmove(eventType, eventPtr, 4);
+ OS.gdk_event_free(eventPtr);
+ return eventType[0];
+ }
+ else {
+ try { Thread.sleep(50); } catch (Exception ex) {}
+ }
+ }
+}
+
+/*
+ * Figure which GdkWindow we'll draw on.
+ * That's normally the root X window, or the parent's GdkWindow if we have a parent.
+ */
+private int calculateWindow() {
+ int answer;
+ if (parent == null) {
+ answer = OS.GDK_ROOT_PARENT();
+ } else {
+ answer = parent._gdkWindow();
+ }
+ if (answer==0) error(SWT.ERROR_UNSPECIFIED);
+ return answer;
+}
+
+public void setCursor (Cursor value) {
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TreeItem.java
index aa258edf77..ef23d5cc0d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TreeItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TreeItem.java
@@ -1,109 +1,109 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- int index;
-
-/**
- * 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
- * for all SWT widget classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, 0, -1);
-}
-
-/**
- * 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
- * for all SWT widget classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </p>
- *
- * @param 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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
- super (parent, style);
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- this.parent = parent;
- parent.createItem (this, 0, index);
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+ int index;
+
+/**
+ * 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
+ * for all SWT widget classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
+ super (parent, style);
+ this.parent = parent;
+ parent.createItem (this, 0, -1);
+}
+
+/**
+ * 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
+ * for all SWT widget classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </p>
+ *
+ * @param 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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
+ super (parent, style);
+ if (index < 0) error (SWT.ERROR_INVALID_RANGE);
+ this.parent = parent;
+ parent.createItem (this, 0, index);
+}
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Tree</code> or a <code>TreeItem</code>)
@@ -133,13 +133,13 @@ public TreeItem (Tree parent, int style, int index) {
* @see SWT
* @see Widget#checkSubclass
* @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style) {
- super (checkNull (parentItem).getParent(), style);
- this.parent = parentItem.getParent ();
- parent.createItem (this, parentItem.handle, -1);
-}
-
+ */
+public TreeItem (TreeItem parentItem, int style) {
+ super (checkNull (parentItem).getParent(), style);
+ this.parent = parentItem.getParent ();
+ parent.createItem (this, parentItem.handle, -1);
+}
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Tree</code> or a <code>TreeItem</code>),
@@ -170,38 +170,38 @@ public TreeItem (TreeItem parentItem, int style) {
* @see SWT
* @see Widget#checkSubclass
* @see Widget#getStyle
- */
-public TreeItem (TreeItem parentItem, int style, int index) {
- super (checkNull (parentItem).getParent (), style);
- if (index < 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- this.parent = parentItem.getParent ();
- parent.createItem (this, parentItem.handle, index);
-}
-
-static TreeItem checkNull (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-/**
- * 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 ();
- Tree parent = getParent();
- return parent.getBackground();
-}
-
+ */
+public TreeItem (TreeItem parentItem, int style, int index) {
+ super (checkNull (parentItem).getParent (), style);
+ if (index < 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ this.parent = parentItem.getParent ();
+ parent.createItem (this, parentItem.handle, index);
+}
+
+static TreeItem checkNull (TreeItem item) {
+ if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ return item;
+}
+
+/**
+ * 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 ();
+ Tree parent = getParent();
+ return parent.getBackground();
+}
+
/**
* Returns a rectangle describing the receiver's size and location
* relative to its parent.
@@ -213,56 +213,56 @@ public Color getBackground () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Rectangle getBounds () {
- int ctree = parent.handle;
- GtkCTree tree = new GtkCTree();
- OS.memmove(tree, ctree, GtkCTree.sizeof);
-
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, tree.vadjustment, GtkAdjustment.sizeof);
- float vaj = adjustment.value;
- OS.memmove (adjustment, tree.hadjustment, GtkAdjustment.sizeof);
- float haj = adjustment.value;
- int columnHandle = tree.column;
-
- int height=parent.getItemHeight();
-
- int row_list = tree.row_list; int level=0;
- int count = OS.g_list_length (row_list);
- int index=0;
- while (index<count) {
- int data = OS.g_list_nth (row_list, index);
- if (handle == data){
- int rowHandle = OS.g_list_nth_data (row_list, index);
- GtkCTreeRow row = new GtkCTreeRow();
- OS.memmove(row, rowHandle, GtkCTreeRow.sizeof);
- level = row.level;
- break;
- }
- index++;
- }
- int y = height*index + Tree.CELL_SPACING + tree.voffset + 2;
-
- int [] buffer = new int [1]; byte [] spacing = new byte [1];
- boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
- int [] pixmap_closed = new int [1], mask_closed= new int [1], pixmap_opened= new int [1], mask_opened= new int [1];
- OS.gtk_ctree_get_node_info (ctree, handle, buffer, spacing, pixmap_closed, mask_closed, pixmap_opened, mask_opened, is_leaf, expanded);
- int length = OS.strlen (buffer[0]);
- byte [] buffer1 = new byte [length];
- OS.memmove (buffer1, buffer[0], length);
- int styleHandle = OS.gtk_ctree_node_get_row_style(ctree, handle);
- if (styleHandle == 0)
- styleHandle = OS.gtk_widget_get_style(ctree);
- GtkStyle style = new GtkStyle();
- OS.memmove(style, styleHandle, GtkStyle.sizeof);
- int width = OS.gdk_string_width(style.font, buffer1);
-
-// x = (short)column.area_x+tree.tree_indent*(level-1)+spacing[0]+tree.hoffset;
- int x = 33+tree.tree_indent*(level-1)+spacing[0]+tree.hoffset;
-
- return new Rectangle (x, y, width, height);
-}
-
+public Rectangle getBounds () {
+ int ctree = parent.handle;
+ GtkCTree tree = new GtkCTree();
+ OS.memmove(tree, ctree, GtkCTree.sizeof);
+
+ GtkAdjustment adjustment = new GtkAdjustment ();
+ OS.memmove (adjustment, tree.vadjustment, GtkAdjustment.sizeof);
+ float vaj = adjustment.value;
+ OS.memmove (adjustment, tree.hadjustment, GtkAdjustment.sizeof);
+ float haj = adjustment.value;
+ int columnHandle = tree.column;
+
+ int height=parent.getItemHeight();
+
+ int row_list = tree.row_list; int level=0;
+ int count = OS.g_list_length (row_list);
+ int index=0;
+ while (index<count) {
+ int data = OS.g_list_nth (row_list, index);
+ if (handle == data){
+ int rowHandle = OS.g_list_nth_data (row_list, index);
+ GtkCTreeRow row = new GtkCTreeRow();
+ OS.memmove(row, rowHandle, GtkCTreeRow.sizeof);
+ level = row.level;
+ break;
+ }
+ index++;
+ }
+ int y = height*index + Tree.CELL_SPACING + tree.voffset + 2;
+
+ int [] buffer = new int [1]; byte [] spacing = new byte [1];
+ boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
+ int [] pixmap_closed = new int [1], mask_closed= new int [1], pixmap_opened= new int [1], mask_opened= new int [1];
+ OS.gtk_ctree_get_node_info (ctree, handle, buffer, spacing, pixmap_closed, mask_closed, pixmap_opened, mask_opened, is_leaf, expanded);
+ int length = OS.strlen (buffer[0]);
+ byte [] buffer1 = new byte [length];
+ OS.memmove (buffer1, buffer[0], length);
+ int styleHandle = OS.gtk_ctree_node_get_row_style(ctree, handle);
+ if (styleHandle == 0)
+ styleHandle = OS.gtk_widget_get_style(ctree);
+ GtkStyle style = new GtkStyle();
+ OS.memmove(style, styleHandle, GtkStyle.sizeof);
+ int width = OS.gdk_string_width(style.font, buffer1);
+
+// x = (short)column.area_x+tree.tree_indent*(level-1)+spacing[0]+tree.hoffset;
+ int x = 33+tree.tree_indent*(level-1)+spacing[0]+tree.hoffset;
+
+ return new Rectangle (x, y, width, height);
+}
+
/**
* Returns <code>true</code> if the receiver is checked,
* and false otherwise. When the parent does not have
@@ -275,21 +275,21 @@ public Rectangle getBounds () {
* <li>ERROR_WIDGET_DISPOSED - if the 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.style & SWT.CHECK) == 0) return false;
- int ctree = parent.handle;
- int [] pixmap = new int [1];
- OS.gtk_ctree_get_node_info (ctree, handle, null, null, pixmap, null, null, null, null, null);
- return pixmap [0] == parent.check;
-}
-
-public Display getDisplay () {
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+ */
+public boolean getChecked () {
+ checkWidget();
+ if ((parent.style & SWT.CHECK) == 0) return false;
+ int ctree = parent.handle;
+ int [] pixmap = new int [1];
+ OS.gtk_ctree_get_node_info (ctree, handle, null, null, pixmap, null, null, null, null, null);
+ return pixmap [0] == parent.check;
+}
+
+public Display getDisplay () {
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns <code>true</code> if the receiver is expanded,
* and false otherwise.
@@ -301,34 +301,34 @@ public Display getDisplay () {
* <li>ERROR_WIDGET_DISPOSED - if the 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 ctree = parent.handle;
- boolean [] buffer = new boolean [1];
- OS.gtk_ctree_get_node_info (ctree, handle, null, null, null, null, null, null, null, buffer);
- return buffer [0];
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- Tree parent = getParent();
- return parent.getForeground();
-}
-
+ */
+public boolean getExpanded () {
+ checkWidget();
+ int ctree = parent.handle;
+ boolean [] buffer = new boolean [1];
+ OS.gtk_ctree_get_node_info (ctree, handle, null, null, null, null, null, null, null, buffer);
+ return buffer [0];
+}
+
+/**
+ * Returns the foreground color that the receiver will use to draw.
+ *
+ * @return the receiver's foreground color
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @since 2.0
+ *
+ */
+public Color getForeground () {
+ checkWidget ();
+ Tree parent = getParent();
+ return parent.getForeground();
+}
+
/**
* Returns <code>true</code> if the receiver is grayed,
* and false otherwise. When the parent does not have
@@ -342,11 +342,11 @@ public Color getForeground () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean getGrayed() {
- checkWidget();
- return false;
-}
-
+public boolean getGrayed() {
+ checkWidget();
+ return false;
+}
+
/**
* Returns the number of items contained in the receiver
* that are direct item children of the receiver.
@@ -357,33 +357,33 @@ public boolean getGrayed() {
* <li>ERROR_WIDGET_DISPOSED - if the 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 parent.getItemCount (handle);
-}
-
-/**
- * Returns an 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();
- return parent.getItems (handle);
-}
-
+ */
+public int getItemCount () {
+ checkWidget();
+ return parent.getItemCount (handle);
+}
+
+/**
+ * Returns an 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();
+ return parent.getItems (handle);
+}
+
/**
* Returns the receiver's parent, which must be a <code>Tree</code>.
*
@@ -393,12 +393,12 @@ public TreeItem [] getItems () {
* <li>ERROR_WIDGET_DISPOSED - if 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;
-}
-
+ */
+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
@@ -410,52 +410,52 @@ public Tree getParent () {
* <li>ERROR_WIDGET_DISPOSED - if 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 data = OS.g_list_nth_data (handle, 0);
- GtkCTreeRow row = new GtkCTreeRow ();
- OS.memmove (row, data, GtkCTreeRow.sizeof);
- if (row.parent == 0) return null;
- int ctree = parent.handle;
- int index = OS.gtk_ctree_node_get_row_data (ctree, row.parent) - 1;
- return parent.items [index];
-}
-
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = 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);
-}
-
+ */
+public TreeItem getParentItem () {
+ checkWidget();
+ int data = OS.g_list_nth_data (handle, 0);
+ GtkCTreeRow row = new GtkCTreeRow ();
+ OS.memmove (row, data, GtkCTreeRow.sizeof);
+ if (row.parent == 0) return null;
+ int ctree = parent.handle;
+ int index = OS.gtk_ctree_node_get_row_data (ctree, row.parent) - 1;
+ return parent.items [index];
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ parent = 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);
+}
+
/**
* Sets the checked state of the receiver.
* <p>
@@ -466,48 +466,48 @@ public void setBackground (Color color) {
* <li>ERROR_WIDGET_DISPOSED - if the 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 ctree = parent.handle;
- byte [] spacing = new byte [1];
- int [] pixmap = new int [1], mask = new int [1];
- boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, pixmap, mask, pixmap, mask, is_leaf, expanded);
- if (checked && pixmap [0] == parent.check) return;
- if (!checked && pixmap [0] == parent.uncheck) return;
- pixmap [0] = checked ? parent.check : parent.uncheck;
- OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap [0], mask [0], pixmap [0], mask [0], is_leaf [0], expanded [0]);
-}
-
-/**
- * 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);
-}
-
+ */
+public void setChecked (boolean checked) {
+ checkWidget();
+ if ((parent.style & SWT.CHECK) == 0) return;
+ int ctree = parent.handle;
+ byte [] spacing = new byte [1];
+ int [] pixmap = new int [1], mask = new int [1];
+ boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
+ byte [] buffer = Converter.wcsToMbcs (null, text, true);
+ OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, pixmap, mask, pixmap, mask, is_leaf, expanded);
+ if (checked && pixmap [0] == parent.check) return;
+ if (!checked && pixmap [0] == parent.uncheck) return;
+ pixmap [0] = checked ? parent.check : parent.uncheck;
+ OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap [0], mask [0], pixmap [0], mask [0], is_leaf [0], expanded [0]);
+}
+
+/**
+ * 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);
+}
+
/**
* Sets the grayed state of the receiver.
* <p>
@@ -519,10 +519,10 @@ public void setForeground (Color color) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setGrayed (boolean grayed) {
- checkWidget();
-}
-
+public void setGrayed (boolean grayed) {
+ checkWidget();
+}
+
/**
* Sets the expanded state of the receiver.
* <p>
@@ -533,54 +533,54 @@ public void setGrayed (boolean grayed) {
* <li>ERROR_WIDGET_DISPOSED - if the 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 ctree = parent.handle;
- if (expanded) {
- OS.gtk_signal_handler_block_by_data (ctree, SWT.Expand);
- OS.gtk_ctree_expand (ctree, handle);
- OS.gtk_signal_handler_unblock_by_data (ctree, SWT.Expand);
- } else {
- OS.gtk_signal_handler_block_by_data (ctree, SWT.Collapse);
- OS.gtk_ctree_collapse (ctree, handle);
- OS.gtk_signal_handler_unblock_by_data (ctree, SWT.Collapse);
- }
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((parent.style & SWT.CHECK) != 0) return;
- this.image = image;
- int pixmap = 0, mask = 0;
- if (image != null) {
- pixmap = image.pixmap;
- mask = image.mask;
- }
- int ctree = parent.handle;
- byte [] spacing = new byte [1];
- boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, null, null, null, null, is_leaf, expanded);
- OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap, mask, pixmap, mask, is_leaf [0], expanded [0]);
-}
-
+ */
+public void setExpanded (boolean expanded) {
+ checkWidget();
+ int ctree = parent.handle;
+ if (expanded) {
+ OS.gtk_signal_handler_block_by_data (ctree, SWT.Expand);
+ OS.gtk_ctree_expand (ctree, handle);
+ OS.gtk_signal_handler_unblock_by_data (ctree, SWT.Expand);
+ } else {
+ OS.gtk_signal_handler_block_by_data (ctree, SWT.Collapse);
+ OS.gtk_ctree_collapse (ctree, handle);
+ OS.gtk_signal_handler_unblock_by_data (ctree, SWT.Collapse);
+ }
+}
+
+public void setImage (Image image) {
+ checkWidget();
+ if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ if ((parent.style & SWT.CHECK) != 0) return;
+ this.image = image;
+ int pixmap = 0, mask = 0;
+ if (image != null) {
+ pixmap = image.pixmap;
+ mask = image.mask;
+ }
+ int ctree = parent.handle;
+ byte [] spacing = new byte [1];
+ boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
+ byte [] buffer = Converter.wcsToMbcs (null, text, true);
+ OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, null, null, null, null, is_leaf, expanded);
+ OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap, mask, pixmap, mask, is_leaf [0], expanded [0]);
+}
+
/**
* This label will be displayed to the right of the bitmap,
* or, if the receiver doesn't have a bitmap to the right of
* the horizontal hierarchy connector line.
- */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- int ctree = parent.handle;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- byte [] spacing = new byte [1];
- boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
- int [] pixmap_closed = new int [1], mask_closed= new int [1], pixmap_opened= new int [1], mask_opened= new int [1];
- OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, pixmap_closed, mask_closed, pixmap_opened, mask_opened, is_leaf, expanded);
- OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap_closed [0], mask_closed [0], pixmap_opened [0], mask_opened [0], is_leaf [0], expanded [0]);
-}
-}
+ */
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ super.setText (string);
+ int ctree = parent.handle;
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ byte [] spacing = new byte [1];
+ boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
+ int [] pixmap_closed = new int [1], mask_closed= new int [1], pixmap_opened= new int [1], mask_opened= new int [1];
+ OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, pixmap_closed, mask_closed, pixmap_opened, mask_opened, is_leaf, expanded);
+ OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap_closed [0], mask_closed [0], pixmap_opened [0], mask_opened [0], is_leaf [0], expanded [0]);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/WidgetTable.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/WidgetTable.java
index c8a98801ef..cce97ee237 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/WidgetTable.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/WidgetTable.java
@@ -1,91 +1,91 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.gtk.*;
-
-class WidgetTable {
- static int FreeSlot = 0;
- static int GrowSize = 1024;
- static int [] IndexTable = new int [GrowSize];
- static Widget [] WidgetTable = new Widget [GrowSize];
- 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;
- int index = OS.gtk_object_get_user_data (handle) - 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;
- }
- int index = FreeSlot + 1;
- OS.gtk_object_set_user_data (handle, index);
- int oldSlot = FreeSlot;
- FreeSlot = IndexTable[oldSlot];
- IndexTable [oldSlot] = -2;
- WidgetTable [oldSlot] = widget;
-}
-
-public static synchronized Widget remove (int handle) {
- if (handle == 0) return null;
- Widget widget = null;
- int index = OS.gtk_object_get_user_data (handle) - 1;
- if (0 <= index && index < WidgetTable.length) {
- widget = WidgetTable [index];
- WidgetTable [index] = null;
- IndexTable [index] = FreeSlot;
- FreeSlot = index;
- OS.gtk_object_set_user_data (handle, 0);
- }
- 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) {
- result [index++] = (Shell) widget;
- }
- }
- return result;
-}
-
-public static synchronized int size () {
- int size = 0;
- for (int i=0; i<WidgetTable.length; i++) {
- if (WidgetTable [i] != null) size++;
- }
- return size;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.gtk.*;
+
+class WidgetTable {
+ static int FreeSlot = 0;
+ static int GrowSize = 1024;
+ static int [] IndexTable = new int [GrowSize];
+ static Widget [] WidgetTable = new Widget [GrowSize];
+ 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;
+ int index = OS.gtk_object_get_user_data (handle) - 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;
+ }
+ int index = FreeSlot + 1;
+ OS.gtk_object_set_user_data (handle, index);
+ int oldSlot = FreeSlot;
+ FreeSlot = IndexTable[oldSlot];
+ IndexTable [oldSlot] = -2;
+ WidgetTable [oldSlot] = widget;
+}
+
+public static synchronized Widget remove (int handle) {
+ if (handle == 0) return null;
+ Widget widget = null;
+ int index = OS.gtk_object_get_user_data (handle) - 1;
+ if (0 <= index && index < WidgetTable.length) {
+ widget = WidgetTable [index];
+ WidgetTable [index] = null;
+ IndexTable [index] = FreeSlot;
+ FreeSlot = index;
+ OS.gtk_object_set_user_data (handle, 0);
+ }
+ 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) {
+ result [index++] = (Shell) widget;
+ }
+ }
+ return result;
+}
+
+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/motif/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java
index bfb0a3d75d..704ff260d2 100755
--- 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
@@ -1,15 +1,15 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -23,20 +23,20 @@ import org.eclipse.swt.*;
*
* @see RGB
*/
-public final class Color {
+public final class Color {
/**
* the handle to the OS color resource
* (Warning: This field is platform dependent)
*/
- public XColor handle;
-
- /**
- * The device where this image was created.
+ public XColor handle;
+
+ /**
+ * The device where this image was created.
*/
- Device device;
-
-Color() {
-}
+ Device device;
+
+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
@@ -61,12 +61,12 @@ Color() {
*
* @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);
-}
+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.
@@ -89,35 +89,35 @@ public Color (Device device, int red, int green, int blue) {
*
* @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);
-}
+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() {
+public void dispose() {
if (handle == null) return;
- if (device.isDisposed()) 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;
-}
+ 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
@@ -128,15 +128,15 @@ public void dispose() {
*
* @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;
-}
+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.
*
@@ -146,10 +146,10 @@ public boolean equals (Object object) {
* <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;
-}
+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.
*
@@ -159,10 +159,10 @@ public int getBlue () {
* <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;
-}
+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.
*
@@ -172,10 +172,10 @@ public int getGreen () {
* <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;
-}
+public int getRed () {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ return (handle.red >> 8) & 0xFF;
+}
/**
* Returns an <code>RGB</code> representing the receiver.
*
@@ -183,10 +183,10 @@ public int getRed () {
* <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);
-}
+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 which return <code>true</code> when passed to
@@ -197,117 +197,117 @@ public RGB getRGB () {
*
* @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.
+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.
+ 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++) {
+ 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.
+ 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]++;
- }
-}
+ 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.
@@ -318,24 +318,24 @@ void init(Device device, int red, int green, int blue) {
*
* @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;
-}
+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() + "}";
-}
-}
+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
index d08bbf56dc..faf2c8696d 100755
--- 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
@@ -1,15 +1,15 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -34,20 +34,20 @@ import org.eclipse.swt.*;
* Note: Only one of the above styles may be specified.
* </p>
*/
-public final class Cursor {
+public final class Cursor {
/**
* the handle to the OS cursor resource
* (Warning: This field is platform dependent)
*/
- public int handle;
-
- /**
- * The device where this image was created.
+ public int handle;
+
+ /**
+ * The device where this image was created.
*/
- Device device;
-
-Cursor () {
-}
+ Device device;
+
+Cursor () {
+}
/**
* Constructs a new cursor given a device and a style
* constant describing the desired cursor appearance.
@@ -89,40 +89,40 @@ Cursor () {
* @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_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_APPSTARTING: shape = OS.XC_watch; break;
- case SWT.CURSOR_HELP: shape = OS.XC_question_arrow; break;
- case SWT.CURSOR_SIZEALL: shape = OS.XC_diamond_cross; 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);
- }
- this.handle = OS.XCreateFontCursor(device.xDisplay, shape);
- if (device.tracking) device.new_Object(this);
-}
+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_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_APPSTARTING: shape = OS.XC_watch; break;
+ case SWT.CURSOR_HELP: shape = OS.XC_question_arrow; break;
+ case SWT.CURSOR_SIZEALL: shape = OS.XC_diamond_cross; 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);
+ }
+ this.handle = OS.XCreateFontCursor(device.xDisplay, shape);
+ 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
@@ -155,92 +155,92 @@ public Cursor (Device device, int style) {
* <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 depths */
- if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (source.depth != 1) 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);
- }
- /* Swap the bits if necessary */
- byte[] sourceData = new byte[source.data.length];
- byte[] maskData = new byte[mask.data.length];
- /* Swap the bits in each byte */
- 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];
- }
- 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];
- }
- int xDisplay = device.xDisplay;
- int drawable = OS.XDefaultRootWindow(xDisplay);
- int sourcePixmap = OS.XCreateBitmapFromData(xDisplay, drawable, sourceData, source.width, source.height);
- int maskPixmap = OS.XCreateBitmapFromData(xDisplay, drawable, maskData, source.width, source.height);
- /* Get the colors */
- int screenNum = OS.XDefaultScreen(xDisplay);
- XColor foreground = new XColor();
- foreground.pixel = OS.XBlackPixel(xDisplay, screenNum);
- foreground.red = foreground.green = foreground.blue = 0;
- XColor background = new XColor();
- background.pixel = OS.XWhitePixel(xDisplay, screenNum);
- background.red = background.green = background.blue = (short)0xFFFF;
- /* Create the cursor */
- handle = OS.XCreatePixmapCursor(xDisplay, maskPixmap, sourcePixmap, foreground, background, hotspotX, hotspotY);
- /* Dispose the pixmaps */
- OS.XFreePixmap(xDisplay, sourcePixmap);
- OS.XFreePixmap(xDisplay, maskPixmap);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
+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 depths */
+ if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ if (source.depth != 1) 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);
+ }
+ /* Swap the bits if necessary */
+ byte[] sourceData = new byte[source.data.length];
+ byte[] maskData = new byte[mask.data.length];
+ /* Swap the bits in each byte */
+ 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];
+ }
+ 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];
+ }
+ int xDisplay = device.xDisplay;
+ int drawable = OS.XDefaultRootWindow(xDisplay);
+ int sourcePixmap = OS.XCreateBitmapFromData(xDisplay, drawable, sourceData, source.width, source.height);
+ int maskPixmap = OS.XCreateBitmapFromData(xDisplay, drawable, maskData, source.width, source.height);
+ /* Get the colors */
+ int screenNum = OS.XDefaultScreen(xDisplay);
+ XColor foreground = new XColor();
+ foreground.pixel = OS.XBlackPixel(xDisplay, screenNum);
+ foreground.red = foreground.green = foreground.blue = 0;
+ XColor background = new XColor();
+ background.pixel = OS.XWhitePixel(xDisplay, screenNum);
+ background.red = background.green = background.blue = (short)0xFFFF;
+ /* Create the cursor */
+ handle = OS.XCreatePixmapCursor(xDisplay, maskPixmap, sourcePixmap, foreground, background, hotspotX, hotspotY);
+ /* Dispose the pixmaps */
+ OS.XFreePixmap(xDisplay, sourcePixmap);
+ OS.XFreePixmap(xDisplay, maskPixmap);
+ 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 cursor. Applications must dispose of all cursors which
* they allocate.
*/
-public void dispose () {
+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;
-}
+ 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
@@ -251,12 +251,12 @@ public void dispose () {
*
* @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;
-}
+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 which return <code>true</code> when passed to
@@ -267,9 +267,9 @@ public boolean equals (Object object) {
*
* @see #equals
*/
-public int hashCode () {
- return handle;
-}
+public int hashCode () {
+ return handle;
+}
/**
* Returns <code>true</code> if the cursor has been disposed,
* and <code>false</code> otherwise.
@@ -280,24 +280,24 @@ public int hashCode () {
*
* @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 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 + "}";
-}
-}
+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
index 091c2cdf36..b8d8bc4d6c 100755
--- 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
@@ -1,100 +1,100 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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)
+public abstract class Device implements Drawable {
+ /**
+ * the handle to the X Display
+ * (Warning: This field is platform dependent)
+ */
+ public int xDisplay;
+
+ /**
+ * whether the XLFD resolution should match the
+ * resolution of the device when fonts are created
+ * (Warning: This field is platform dependent)
*/
- public int xDisplay;
-
- /**
- * whether the XLFD resolution should match the
- * resolution of the device when fonts are created
- * (Warning: This field is platform dependent)
- */
- // 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;
+ // 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;
-
- /* Warning and Error Handlers */
- boolean warnings = true;
- Callback xErrorCallback, xtWarningCallback, xIOErrorCallback, xtErrorCallback;
- int xErrorProc, xtWarningProc, xIOErrorProc, xtErrorProc;
- int xNullErrorProc, xtNullWarningProc, xNullIOErrorProc, xtNullErrorProc;
-
- /* Parsing Tables */
- int tabMapping, crMapping, tabPointer, crPointer;
-
- /*
- * 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 Device getDevice () {
- if (DeviceFinder != null) DeviceFinder.run();
- Device device = CurrentDevice;
- CurrentDevice = null;
- return device;
-}
-
+ Font systemFont;
+
+ /* Warning and Error Handlers */
+ boolean warnings = true;
+ Callback xErrorCallback, xtWarningCallback, xIOErrorCallback, xtErrorCallback;
+ int xErrorProc, xtWarningProc, xIOErrorProc, xtErrorProc;
+ int xNullErrorProc, xtNullWarningProc, xNullIOErrorProc, xtNullErrorProc;
+
+ /* Parsing Tables */
+ int tabMapping, crMapping, tabPointer, crPointer;
+
+ /*
+ * 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 Device getDevice () {
+ if (DeviceFinder != null) DeviceFinder.run();
+ Device device = CurrentDevice;
+ CurrentDevice = null;
+ return device;
+}
+
/**
* Constructs a new instance of this class.
* <p>
@@ -107,35 +107,35 @@ static Device getDevice () {
* @see #init
* @see DeviceData
*/
-public Device(DeviceData data) {
- 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 ();
+public Device(DeviceData data) {
+ 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 ();
- /* Initialize the system font slot */
- systemFont = getSystemFont ();
-}
-
-protected void checkDevice () {
- if (xDisplay == 0) SWT.error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-protected void create (DeviceData data) {
-}
-
-protected void destroy () {
-}
-
+ /* Initialize the system font slot */
+ systemFont = getSystemFont ();
+}
+
+protected void checkDevice () {
+ if (xDisplay == 0) SWT.error (SWT.ERROR_DEVICE_DISPOSED);
+}
+
+protected void create (DeviceData data) {
+}
+
+protected void destroy () {
+}
+
/**
* Disposes of the operating system resources associated with
* the receiver. After this method has been invoked, the receiver
@@ -146,28 +146,28 @@ protected void destroy () {
* @see #destroy
* @see #checkDevice
*/
-public void dispose () {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- 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;
- }
- }
-}
-
+public void dispose () {
+ if (isDisposed()) return;
+ checkDevice ();
+ release ();
+ destroy ();
+ 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;
+ }
+ }
+}
+
/**
* Returns a rectangle describing the receiver's size and location.
*
@@ -177,14 +177,14 @@ void dispose_Object (Object object) {
* <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);
-}
-
+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.
@@ -197,10 +197,10 @@ public Rectangle getBounds () {
*
* @see #getBounds
*/
-public Rectangle getClientArea () {
- return 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
@@ -213,12 +213,12 @@ public Rectangle getClientArea () {
* <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);
-}
-
+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
@@ -232,32 +232,32 @@ public int getDepth () {
*
* @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;
-}
-
+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
@@ -269,21 +269,21 @@ public DeviceData getDeviceData () {
* <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);
-}
-
+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
@@ -297,49 +297,49 @@ public Point getDPI () {
* <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);
- 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;
- }
- 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;
-}
-
+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);
+ 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;
+ }
+ 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
@@ -358,31 +358,31 @@ public FontData [] getFontList (String faceName, boolean scalable) {
*
* @see SWT
*/
-public Color getSystemColor (int id) {
- checkDevice ();
- XColor xColor = null;
- 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;
- }
- if (xColor == null) return COLOR_BLACK;
- return Color.motif_new (this, xColor);
-}
-
+public Color getSystemColor (int id) {
+ checkDevice ();
+ XColor xColor = null;
+ 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;
+ }
+ if (xColor == null) return COLOR_BLACK;
+ return Color.motif_new (this, xColor);
+}
+
/**
* Returns a reasonable font for applications to use.
* On some platforms, this will match the "default font"
@@ -403,11 +403,11 @@ public Color getSystemColor (int id) {
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public Font getSystemFont () {
- checkDevice ();
- return systemFont;
-}
-
+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>
@@ -419,93 +419,93 @@ public Font getSystemFont () {
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public boolean getWarnings () {
- checkDevice ();
- return warnings;
-}
-
-protected void init () {
-
- /* Create the warning and error callbacks */
- xErrorCallback = new Callback (this, "xErrorProc", 2);
- xNullErrorProc = xErrorCallback.getAddress ();
- if (xNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- xtWarningCallback = new Callback (this, "xtWarningProc", 1);
- xtNullWarningProc = xtWarningCallback.getAddress ();
- if (xtNullWarningProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- xIOErrorCallback = new Callback (this, "xIOErrorProc", 1);
- xNullIOErrorProc = xIOErrorCallback.getAddress ();
- if (xNullIOErrorProc == 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);
-
- /* Set the warning and error handlers */
- if (debug) OS.XSynchronize (xDisplay, true);
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- xErrorProc = OS.XSetErrorHandler (xNullErrorProc);
- if (!debug) OS.XSetErrorHandler (xErrorProc);
- xtWarningProc = OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc);
- if (!debug) OS.XtAppSetWarningHandler (xtContext, xtWarningProc);
- xIOErrorProc = OS.XSetIOErrorHandler (xNullIOErrorProc);
- if (!debug) OS.XSetIOErrorHandler (xIOErrorProc);
- xtErrorProc = OS.XtAppSetErrorHandler (xtContext, xtNullErrorProc);
- if (!debug) OS.XtAppSetErrorHandler (xtContext, xtErrorProc);
-
- /* 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);
-
- /* 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);
-}
-
+public boolean getWarnings () {
+ checkDevice ();
+ return warnings;
+}
+
+protected void init () {
+
+ /* Create the warning and error callbacks */
+ xErrorCallback = new Callback (this, "xErrorProc", 2);
+ xNullErrorProc = xErrorCallback.getAddress ();
+ if (xNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
+ xtWarningCallback = new Callback (this, "xtWarningProc", 1);
+ xtNullWarningProc = xtWarningCallback.getAddress ();
+ if (xtNullWarningProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
+ xIOErrorCallback = new Callback (this, "xIOErrorProc", 1);
+ xNullIOErrorProc = xIOErrorCallback.getAddress ();
+ if (xNullIOErrorProc == 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);
+
+ /* Set the warning and error handlers */
+ if (debug) OS.XSynchronize (xDisplay, true);
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ xErrorProc = OS.XSetErrorHandler (xNullErrorProc);
+ if (!debug) OS.XSetErrorHandler (xErrorProc);
+ xtWarningProc = OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc);
+ if (!debug) OS.XtAppSetWarningHandler (xtContext, xtWarningProc);
+ xIOErrorProc = OS.XSetIOErrorHandler (xNullIOErrorProc);
+ if (!debug) OS.XSetIOErrorHandler (xIOErrorProc);
+ xtErrorProc = OS.XtAppSetErrorHandler (xtContext, xtNullErrorProc);
+ if (!debug) OS.XtAppSetErrorHandler (xtContext, xtErrorProc);
+
+ /* 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);
+
+ /* 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>
@@ -521,8 +521,8 @@ protected void init () {
*
* @private
*/
-public abstract int internal_new_GC (GCData data);
-
+public abstract int internal_new_GC (GCData data);
+
/**
* Invokes platform specific functionality to dispose a GC handle.
* <p>
@@ -538,8 +538,8 @@ public abstract int internal_new_GC (GCData data);
*
* @private
*/
-public abstract void internal_dispose_GC (int handle, GCData 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.
@@ -550,61 +550,61 @@ public abstract void internal_dispose_GC (int handle, GCData data);
*
* @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;
-}
-
-protected void release () {
- /* Free the parsing tables */
- OS.XtFree(tabPointer);
- OS.XtFree(crPointer);
- OS.XmParseMappingFree(tabMapping);
- OS.XmParseMappingFree(crMapping);
- tabPointer = crPointer = tabMapping = crMapping = 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;
+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;
+}
+
+protected void release () {
+ /* Free the parsing tables */
+ OS.XtFree(tabPointer);
+ OS.XtFree(crPointer);
+ OS.XmParseMappingFree(tabMapping);
+ OS.XmParseMappingFree(crMapping);
+ tabPointer = crPointer = tabMapping = crMapping = 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);
@@ -637,9 +637,9 @@ protected void release () {
OS.XSetErrorHandler (xNullErrorProc);
// OS.XSetErrorHandler (xErrorProc);
// xErrorCallback.dispose (); xErrorCallback = null;
-// xNullErrorProc = xErrorProc = 0;
-}
-
+// xNullErrorProc = xErrorProc = 0;
+}
+
/**
* If the underlying window system supports printing warning messages
* to the console, setting warnings to <code>true</code> prevents these
@@ -652,50 +652,50 @@ protected void release () {
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public void setWarnings (boolean warnings) {
- checkDevice ();
- this.warnings = warnings;
- if (debug) return;
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- if (warnings) {
- OS.XSetErrorHandler (xErrorProc);
- OS.XtAppSetWarningHandler (xtContext, xtWarningProc);
- } else {
- OS.XSetErrorHandler (xNullErrorProc);
- OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc);
- }
-}
-
-int xErrorProc (int xDisplay, int xErrorEvent) {
- if (DEBUG || (debug && warnings)) {
- new SWTError ().printStackTrace ();
- OS.Call (xErrorProc, xDisplay, xErrorEvent);
- }
- return 0;
-}
-
-int xIOErrorProc (int xDisplay) {
- if (DEBUG || 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 (DEBUG || (debug && warnings)) {
- new SWTError ().printStackTrace ();
- OS.Call (xtWarningProc, message, 0);
- }
- return 0;
-}
-
+public void setWarnings (boolean warnings) {
+ checkDevice ();
+ this.warnings = warnings;
+ if (debug) return;
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ if (warnings) {
+ OS.XSetErrorHandler (xErrorProc);
+ OS.XtAppSetWarningHandler (xtContext, xtWarningProc);
+ } else {
+ OS.XSetErrorHandler (xNullErrorProc);
+ OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc);
+ }
+}
+
+int xErrorProc (int xDisplay, int xErrorEvent) {
+ if (DEBUG || (debug && warnings)) {
+ new SWTError ().printStackTrace ();
+ OS.Call (xErrorProc, xDisplay, xErrorEvent);
+ }
+ return 0;
+}
+
+int xIOErrorProc (int xDisplay) {
+ if (DEBUG || 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 (DEBUG || (debug && warnings)) {
+ 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
index ed4d6ba458..aad8e1fe72 100755
--- 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
@@ -1,26 +1,26 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index 837fbe51d9..dcaab66578 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -24,29 +24,29 @@ import org.eclipse.swt.*;
*
* @see FontData
*/
-public final class Font {
+public final class Font {
/**
* the handle to the OS font resource
* (Warning: This field is platform dependent)
*/
- public int handle;
-
- /**
- * the code page of the font
- * (Warning: This field is platform dependent)
- *
- * @since 2.0
+ public int handle;
+
+ /**
+ * the code page of the font
+ * (Warning: This field is platform dependent)
+ *
+ * @since 2.0
*/
- public String codePage;
-
- /**
- * The device where this image was created.
+ public String codePage;
+
+ /**
+ * The device where this image was created.
*/
- Device device;
-
-Font () {
-}
-
+ Device device;
+
+Font () {
+}
+
/**
* Constructs a new font given a device and font data
* which describes the desired font's appearance.
@@ -65,46 +65,46 @@ Font () {
* <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 font datas
- * 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>
- */
-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);
-}
-
+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 font datas
+ * 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>
+ */
+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
@@ -127,29 +127,29 @@ public Font (Device device, FontData[] fds) {
* <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);
-}
-
+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 () {
+public void dispose () {
if (handle == 0) return;
- if (device.isDisposed()) return;
+ if (device.isDisposed()) return;
if (handle == device.systemFont.handle) return;
- OS.XmFontListFree (handle);
- handle = 0;
+ OS.XmFontListFree (handle);
+ handle = 0;
if (device.tracking) device.dispose_Object(this);
- device = null;
-}
-
+ device = null;
+}
+
/**
* Compares the argument to the receiver, and returns true
* if they represent the <em>same</em> object using a class
@@ -160,87 +160,87 @@ public void dispose () {
*
* @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++) {
- /* Reef through properties looking 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;
-}
-
+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++) {
+ /* Reef through properties looking 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,
@@ -253,102 +253,102 @@ static String getCodePage (int xDisplay, int fontList) {
* <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.
- * If a font context can not be created, return null.
+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.
+ * If a font context can not be created, return null.
*/
- int[] buffer = new int[1];
- if (!OS.XmFontListInitFontContext(buffer, handle)) return null;
- int context = buffer[0];
- XFontStruct fontStruct = new XFontStruct();
- int fontListEntry;
- int[] fontStructPtr = new int[1];
- int[] fontNamePtr = new int[1];
- String[] xlfds = new String[0];
- /* 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++) {
- /* Reef through properties looking 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();
- /* Add the xlfd to the array */
- String[] newXlfds = new String[xlfds.length + 1];
- System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length);
- newXlfds[newXlfds.length - 1] = xlfd;
- xlfds = newXlfds;
- OS.XtFree(ptr);
- 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++) {
- // Reef through properties looking 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);
- String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
- /* Add the xlfd to the array */
- String[] newXlfds = new String[xlfds.length + 1];
- System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length);
- newXlfds[newXlfds.length - 1] = xlfd;
- xlfds = newXlfds;
- OS.XFree(ptr);
- break;
- }
- propPtr += 8;
- }
- }
- }
- }
- OS.XmFontListFreeFontContext(context);
- if (xlfds.length == 0) return null;
- FontData[] fontData = new FontData[xlfds.length];
- /* Construct each fontData out of the xlfd */
- try {
- for (int i = 0; i < xlfds.length; i++) {
- fontData[i] = FontData.motif_new(xlfds[i]);
- }
- } 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. Return null.
+ int[] buffer = new int[1];
+ if (!OS.XmFontListInitFontContext(buffer, handle)) return null;
+ int context = buffer[0];
+ XFontStruct fontStruct = new XFontStruct();
+ int fontListEntry;
+ int[] fontStructPtr = new int[1];
+ int[] fontNamePtr = new int[1];
+ String[] xlfds = new String[0];
+ /* 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++) {
+ /* Reef through properties looking 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();
+ /* Add the xlfd to the array */
+ String[] newXlfds = new String[xlfds.length + 1];
+ System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length);
+ newXlfds[newXlfds.length - 1] = xlfd;
+ xlfds = newXlfds;
+ OS.XtFree(ptr);
+ 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++) {
+ // Reef through properties looking 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);
+ String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
+ /* Add the xlfd to the array */
+ String[] newXlfds = new String[xlfds.length + 1];
+ System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length);
+ newXlfds[newXlfds.length - 1] = xlfd;
+ xlfds = newXlfds;
+ OS.XFree(ptr);
+ break;
+ }
+ propPtr += 8;
+ }
+ }
+ }
+ }
+ OS.XmFontListFreeFontContext(context);
+ if (xlfds.length == 0) return null;
+ FontData[] fontData = new FontData[xlfds.length];
+ /* Construct each fontData out of the xlfd */
+ try {
+ for (int i = 0; i < xlfds.length; i++) {
+ fontData[i] = FontData.motif_new(xlfds[i]);
+ }
+ } 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. Return null.
*/
- return null;
- }
- return fontData;
-}
-
+ return null;
+ }
+ return fontData;
+}
+
/**
* Returns an integer hash code for the receiver. Any two
* objects which return <code>true</code> when passed to
@@ -359,93 +359,93 @@ public FontData[] getFontData() {
*
* @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);
- }
-
- /* 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++) {
- 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());
- stringBuffer.append(',');
- 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 (OS.IsAIX && OS.IsDBLocale) {
- stringBuffer.append(newFd.getXlfd());
- } else {
- newFd.weight = firstFd.weight;
- newFd.slant = firstFd.slant;
- 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, OS.XmFONT_IS_FONTSET, 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);
- byte[] codeset = new byte[length];
- OS.memmove(codeset, codesetPtr, length);
- codePage = new String(Converter.mbcsToWcs(null, codeset));
- } 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);
-}
-
+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);
+ }
+
+ /* 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++) {
+ 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());
+ stringBuffer.append(',');
+ 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 (OS.IsAIX && OS.IsDBLocale) {
+ stringBuffer.append(newFd.getXlfd());
+ } else {
+ newFd.weight = firstFd.weight;
+ newFd.slant = firstFd.slant;
+ 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, OS.XmFONT_IS_FONTSET, 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);
+ byte[] codeset = new byte[length];
+ OS.memmove(codeset, codesetPtr, length);
+ codePage = new String(Converter.mbcsToWcs(null, codeset));
+ } 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.
@@ -456,27 +456,27 @@ void init (Device device, FontData[] fds) {
*
* @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 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 + "}";
-}
-}
+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
index d6dfc76f5e..32fd6df6c9 100755
--- 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
@@ -1,14 +1,14 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+
/**
* Instances of this class describe operating system fonts.
* Only the public API of this type is platform independent.
@@ -34,88 +34,88 @@ import org.eclipse.swt.*;
*
* @see Font
*/
-public final class FontData {
- /**
- * The company that produced the font
- * Warning: This field is platform dependent.
+public final class FontData {
+ /**
+ * The company that produced the font
+ * Warning: This field is platform dependent.
*/
- public String foundry;
- /**
- * The common name of the font
- * Warning: This field is platform dependent.
+ public String foundry;
+ /**
+ * The common name of the font
+ * Warning: This field is platform dependent.
*/
- public String fontFamily;
- /**
- * The weight ("medium", "bold")
- * Warning: This field is platform dependent.
+ public String fontFamily;
+ /**
+ * The weight ("medium", "bold")
+ * Warning: This field is platform dependent.
*/
- public String weight;
- /**
- * The slant ("o" for oblique, "i" for italic)
- * Warning: This field is platform dependent.
+ public String weight;
+ /**
+ * The slant ("o" for oblique, "i" for italic)
+ * Warning: This field is platform dependent.
*/
- public String slant;
- /**
- * The set width of the font
- * Warning: This field is platform dependent.
+ public String slant;
+ /**
+ * The set width of the font
+ * Warning: This field is platform dependent.
*/
- public String setWidth;
- /**
- * Additional font styles
- * Warning: This field is platform dependent.
+ public String setWidth;
+ /**
+ * Additional font styles
+ * Warning: This field is platform dependent.
*/
- public String addStyle;
- /**
- * The height of the font in pixels
- * Warning: This field is platform dependent.
+ public String addStyle;
+ /**
+ * The height of the font in pixels
+ * Warning: This field is platform dependent.
*/
- public int pixels;
- /**
- * The height of the font in tenths of a point
- * Warning: This field is platform dependent.
+ public int pixels;
+ /**
+ * The height of the font in tenths of a point
+ * Warning: This field is platform dependent.
*/
- public int points;
- /**
- * The horizontal screen resolution for which the font was designed
- * Warning: This field is platform dependent.
+ public int points;
+ /**
+ * The horizontal screen resolution for which the font was designed
+ * Warning: This field is platform dependent.
*/
- public int horizontalResolution;
- /**
- * The vertical screen resolution for which the font was designed
- * Warning: This field is platform dependent.
+ public int horizontalResolution;
+ /**
+ * The vertical screen resolution for which the font was designed
+ * Warning: This field is platform dependent.
*/
- public int verticalResolution;
- /**
- * The font spacing ("m" for monospace, "p" for proportional)
- * Warning: This field is platform dependent.
+ public int verticalResolution;
+ /**
+ * The font spacing ("m" for monospace, "p" for proportional)
+ * Warning: This field is platform dependent.
*/
- public String spacing;
- /**
- * The average character width for the font
- * Warning: This field is platform dependent.
+ public String spacing;
+ /**
+ * The average character width for the font
+ * Warning: This field is platform dependent.
*/
- public int averageWidth;
- /**
- * The ISO character set registry
- * Warning: This field is platform dependent.
+ public int averageWidth;
+ /**
+ * The ISO character set registry
+ * Warning: This field is platform dependent.
*/
- public String characterSetRegistry;
- /**
- * The ISO character set name
- * Warning: This field is platform dependent.
+ public String characterSetRegistry;
+ /**
+ * The ISO character set name
+ * Warning: This field is platform dependent.
*/
- public String characterSetName;
-
- /**
- * The locales of the font
- * (Warning: These fields are platform dependent)
+ public String characterSetName;
+
+ /**
+ * The locales of the font
+ * (Warning: These fields are platform dependent)
*/
- String lang, country, variant;
+ String lang, country, variant;
/**
* Constructs a new un-initialized font data.
*/
-public FontData () {
-}
+public FontData () {
+}
/**
* Constructs a new FontData given a string representation
* in the form generated by the <code>FontData.toString</code>
@@ -135,80 +135,80 @@ public FontData () {
*
* @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);
-}
+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,
@@ -223,20 +223,20 @@ public FontData(String string) {
* <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
* </ul>
*/
-public FontData (String name, int height, int style) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int dash = name.indexOf('-');
- if (dash != -1) {
- foundry = name.substring(0, dash);
- fontFamily = name.substring(dash + 1);
- } else {
- fontFamily = name;
- }
- points = height * 10;
- weight = (style & SWT.BOLD) != 0 ? "bold" : "medium";
- slant = (style & SWT.ITALIC) != 0 ? "i" : "r";
-}
+public FontData (String name, 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
@@ -247,10 +247,10 @@ public FontData (String name, int height, int style) {
*
* @see #hashCode
*/
-public boolean equals (Object object) {
- return (object == this) || ((object instanceof FontData) &&
- getXlfd().equals(((FontData)object).getXlfd()));
-}
+public boolean equals (Object object) {
+ return (object == this) || ((object instanceof FontData) &&
+ getXlfd().equals(((FontData)object).getXlfd()));
+}
/**
* Returns the height of the receiver in points.
*
@@ -258,9 +258,9 @@ public boolean equals (Object object) {
*
* @see #setHeight
*/
-public int getHeight() {
- return points / 10;
-}
+public int getHeight() {
+ return points / 10;
+}
/**
* Returns the name of the receiver.
* On platforms that support font foundries, the return value will
@@ -270,15 +270,15 @@ public int getHeight() {
*
* @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();
-}
+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
@@ -288,34 +288,34 @@ public String getName() {
*
* @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;
-}
+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 which return <code>true</code> when passed to
@@ -326,14 +326,14 @@ String getXlfd() {
*
* @see #equals
*/
-public int hashCode () {
- return getXlfd().hashCode();
-}
-public static FontData motif_new(String xlfd) {
- FontData fontData = new FontData();
- fontData.setXlfd(xlfd);
- return fontData;
-}
+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
@@ -347,10 +347,10 @@ public static FontData motif_new(String xlfd) {
*
* @see #getHeight
*/
-public void setHeight(int height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- points = height * 10;
-}
+public void setHeight(int height) {
+ if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ points = height * 10;
+}
/**
* Sets the name of the receiver.
* <p>
@@ -376,52 +376,52 @@ public void setHeight(int height) {
*
* @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 which 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 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 which 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);
- }
-}
+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>
@@ -431,74 +431,74 @@ public void setLocale(String locale) {
*
* @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("*"))
- 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;
-}
+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("*"))
+ 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
@@ -508,8 +508,8 @@ void setXlfd(String xlfd) {
*
* @see FontData
*/
-public String toString() {
- return "1|" + fontFamily + "|" + getHeight() + "|" + getStyle() + "|" +
- "MOTIF|1|" + getXlfd();
-}
-}
+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
index 8deaa41af6..2a04827982 100755
--- 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
@@ -1,25 +1,25 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * 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
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public final class FontMetrics {
- int ascent, descent, averageCharWidth, leading, height;
-FontMetrics() {
-}
+
+/**
+ * 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
@@ -30,14 +30,14 @@ FontMetrics() {
*
* @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;
-}
+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
@@ -46,18 +46,18 @@ public boolean equals (Object object) {
*
* @return the ascent of the font
*/
-public int getAscent() {
- return ascent;
-}
+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;
-}
+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
@@ -66,9 +66,9 @@ public int getAverageCharWidth() {
*
* @return the descent of the font
*/
-public int getDescent() {
- return descent;
-}
+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
@@ -80,9 +80,9 @@ public int getDescent() {
* @see #getDescent
* @see #getLeading
*/
-public int getHeight() {
- return height;
-}
+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
@@ -90,9 +90,9 @@ public int getHeight() {
*
* @return the leading space of the font
*/
-public int getLeading() {
- return leading;
-}
+public int getLeading() {
+ return leading;
+}
/**
* Returns an integer hash code for the receiver. Any two
* objects which return <code>true</code> when passed to
@@ -103,16 +103,16 @@ public int getLeading() {
*
* @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;
-}
-}
+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
index 7e604386c8..d09e66a986 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.*;
+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
@@ -25,18 +25,18 @@ import org.eclipse.swt.*;
*
* @see org.eclipse.swt.events.PaintEvent
*/
-public final class GC {
+public final class GC {
/**
* the handle to the OS device context
* (Warning: This field is platform dependent)
*/
- public int handle;
-
- Drawable drawable;
- GCData data;
-
-GC() {
-}
+ public int handle;
+
+ Drawable drawable;
+ GCData data;
+
+GC() {
+}
/**
* Constructs a new instance of this class which has been
* configured to draw on the specified drawable. Sets the
@@ -58,18 +58,18 @@ GC() {
* <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li>
* </ul>
*/
-public GC (Drawable drawable) {
- if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- GCData data = new GCData();
- 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);
- data.device = device;
- init(drawable, data, xGC);
- if (device.tracking) device.new_Object(this);
-}
-
+public GC (Drawable drawable) {
+ if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ GCData data = new GCData();
+ 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);
+ data.device = device;
+ init(drawable, data, xGC);
+ if (device.tracking) device.new_Object(this);
+}
+
/**
* Copies a rectangular area of the receiver at the source
* position onto the receiver at the destination position.
@@ -85,33 +85,33 @@ public GC (Drawable drawable) {
* <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) {
- 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;
- OS.XSetGraphicsExposures (xDisplay, handle, true);
- OS.XCopyArea(xDisplay, xDrawable, xDrawable, handle, x, y, width, height, destX, destY);
- OS.XSetGraphicsExposures (xDisplay, handle, false);
- if (data.image != null) return;
- 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);
- }
- }
-}
+public void copyArea(int x, int y, int width, int height, int destX, int destY) {
+ 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;
+ OS.XSetGraphicsExposures (xDisplay, handle, true);
+ OS.XCopyArea(xDisplay, xDrawable, xDrawable, handle, x, y, width, height, destX, destY);
+ OS.XSetGraphicsExposures (xDisplay, handle, false);
+ if (data.image != null) return;
+ 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>.
@@ -127,53 +127,53 @@ public void copyArea(int x, int y, int width, int height, int destX, int destY)
* <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);
-}
+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 () {
+public void dispose () {
if (handle == 0) return;
- if (data.device.isDisposed()) return;
-
- /* 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);
-
- /* Dispose the GC */
- Device device = data.device;
- drawable.internal_dispose_GC(handle, data);
-
- data.display = data.drawable = data.colormap = data.fontList =
- data.clipRgn = data.renderTable = 0;
- drawable = null;
- handle = 0;
- data.image = null;
- data.codePage = null;
- if (device.tracking) device.dispose_Object(this);
- data.device = null;
- data = null;
-}
+ if (data.device.isDisposed()) return;
+
+ /* 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);
+
+ /* Dispose the GC */
+ Device device = data.device;
+ drawable.internal_dispose_GC(handle, data);
+
+ data.display = data.drawable = data.colormap = data.fontList =
+ data.clipRgn = data.renderTable = 0;
+ drawable = null;
+ handle = 0;
+ data.image = null;
+ data.codePage = 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.
@@ -206,21 +206,21 @@ public void dispose () {
* <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 endAngle) {
- 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 || endAngle == 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- OS.XDrawArc(data.display,data.drawable,handle,x,y,width,height,startAngle * 64 ,endAngle * 64);
-}
+public void drawArc(int x, int y, int width, int height, int startAngle, int endAngle) {
+ 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 || endAngle == 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ OS.XDrawArc(data.display,data.drawable,handle,x,y,width,height,startAngle * 64 ,endAngle * 64);
+}
/**
* Draws a rectangle, based on the specified arguments, which has
* the appearance of the platform's <em>focus rectangle</em> if the
@@ -238,37 +238,37 @@ public void drawArc(int x, int y, int width, int height, int startAngle, int end
*
* @see #drawRectangle
*/
-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);
-}
+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.
@@ -288,329 +288,329 @@ public void drawFocus (int x, int y, int width, int height) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</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 SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</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 SWTError <ul>
+ * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</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);
- }
- }
- 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;
- }
-
- /* 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) SWT.error(SWT.ERROR_NO_HANDLES);
- 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) SWT.error(SWT.ERROR_NO_HANDLES);
- 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;
- int colorPixmap = srcImage.pixmap;
- /* Generate the mask if necessary. */
- if (srcImage.transparentPixel != -1) srcImage.createMask();
- int maskPixmap = srcImage.mask;
- int foreground = 0x00000000;
- if (!(simple || (srcWidth == destWidth && srcHeight == destHeight))) {
- /* Stretch the color and mask*/
- int xImagePtr = scalePixmap(xDisplay, colorPixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
- int xMaskPtr = scalePixmap(xDisplay, maskPixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
-
- /* 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.XDestroyImage(xImagePtr);
- 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.XDestroyImage(xMaskPtr);
- OS.XFreeGC(xDisplay, tempGC);
-
- /* Change the source rectangle */
- srcX = srcY = 0;
- srcWidth = destWidth;
- srcHeight = destHeight;
-
- foreground = ~foreground;
- }
-
- /* Do the blts */
- 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 (srcImage.pixmap != colorPixmap) OS.XFreePixmap(xDisplay, colorPixmap);
- if (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 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;
- }
-
- /* Streching case */
- int xImagePtr = scalePixmap(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
- 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) SWT.error(SWT.ERROR_NO_HANDLES);
- 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);
- int error = 0, 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) break;
- 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];
- 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) break;
- 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,
- 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;
- }
- default:
- error = SWT.ERROR_UNSUPPORTED_DEPTH;
- }
- OS.XDestroyImage(xSrcImagePtr);
- if (xImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (error != 0) {
- if (xImagePtr != 0) OS.XDestroyImage(xImagePtr);
- SWT.error(error);
- }
- return xImagePtr;
-}
+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);
+ }
+ }
+ 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;
+ }
+
+ /* 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) SWT.error(SWT.ERROR_NO_HANDLES);
+ 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) SWT.error(SWT.ERROR_NO_HANDLES);
+ 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;
+ int colorPixmap = srcImage.pixmap;
+ /* Generate the mask if necessary. */
+ if (srcImage.transparentPixel != -1) srcImage.createMask();
+ int maskPixmap = srcImage.mask;
+ int foreground = 0x00000000;
+ if (!(simple || (srcWidth == destWidth && srcHeight == destHeight))) {
+ /* Stretch the color and mask*/
+ int xImagePtr = scalePixmap(xDisplay, colorPixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
+ int xMaskPtr = scalePixmap(xDisplay, maskPixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
+
+ /* 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.XDestroyImage(xImagePtr);
+ 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.XDestroyImage(xMaskPtr);
+ OS.XFreeGC(xDisplay, tempGC);
+
+ /* Change the source rectangle */
+ srcX = srcY = 0;
+ srcWidth = destWidth;
+ srcHeight = destHeight;
+
+ foreground = ~foreground;
+ }
+
+ /* Do the blts */
+ 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 (srcImage.pixmap != colorPixmap) OS.XFreePixmap(xDisplay, colorPixmap);
+ if (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 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;
+ }
+
+ /* Streching case */
+ int xImagePtr = scalePixmap(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
+ 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) SWT.error(SWT.ERROR_NO_HANDLES);
+ 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);
+ int error = 0, 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) break;
+ 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];
+ 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) break;
+ 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,
+ 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;
+ }
+ default:
+ error = SWT.ERROR_UNSUPPORTED_DEPTH;
+ }
+ OS.XDestroyImage(xSrcImagePtr);
+ if (xImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ if (error != 0) {
+ if (xImagePtr != 0) OS.XDestroyImage(xImagePtr);
+ SWT.error(error);
+ }
+ 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>).
@@ -624,10 +624,10 @@ static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth
* <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);
- OS.XDrawLine (data.display, data.drawable, handle, x1, y1, x2, y2);
-}
+public void drawLine (int x1, int y1, int x2, int y2) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ 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.
@@ -649,18 +649,18 @@ public void drawLine (int x1, int y1, int x2, int y2) {
* <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;
- }
- OS.XDrawArc(data.display, data.drawable, handle, x, y, width, height, 0, 23040);
-}
+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;
+ }
+ OS.XDrawArc(data.display, data.drawable, handle, x, y, width, height, 0, 23040);
+}
/**
* Draws the closed polygon which is defined by the specified array
* of integer coordinates, using the receiver's foreground color. The array
@@ -678,48 +678,48 @@ public void drawOval(int x, int y, int width, int height) {
* <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);
-
- // 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);
-}
+public void drawPolygon(int[] pointArray) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+
+ // 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
@@ -737,15 +737,15 @@ public void drawPolygon(int[] pointArray) {
* <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[] 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);
-}
+public void drawPolyline(int[] pointArray) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ 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);
+}
/**
* Draws the outline of the rectangle specified by the arguments,
* using the receiver's foreground color. The left and right edges
@@ -761,18 +761,18 @@ public void drawPolyline(int[] pointArray) {
* <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;
- }
- OS.XDrawRectangle (data.display, data.drawable, handle, x, y, width, height);
-}
+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;
+ }
+ 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
@@ -789,10 +789,10 @@ public void drawRectangle (int x, int y, int width, int height) {
* <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);
-}
+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
@@ -812,65 +812,65 @@ public void drawRectangle (Rectangle rect) {
* <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);
-
- // X does not have a native for drawing round rectangles. Do the work in Java
- // and use drawLine() drawArc() calls.
-
- 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;
-
- 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);
- }
- }
-}
+public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+
+ // X does not have a native for drawing round rectangles. Do the work in Java
+ // and use drawLine() drawArc() calls.
+
+ 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;
+
+ 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
@@ -889,9 +889,9 @@ public void drawRoundRectangle (int x, int y, int width, int height, int arcWidt
* <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);
-}
+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
@@ -912,71 +912,71 @@ public void drawString (String string, int x, int y) {
* <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);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreate (buffer, OS.XmFONTLIST_DEFAULT_TAG);
- if (isTransparent) {
- OS.XmStringDraw (data.display, data.drawable, data.fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- } else {
- OS.XmStringDrawImage (data.display, data.drawable, data.fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- }
-// OS.XmStringDrawUnderline (display, drawable, fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, 0);
- OS.XmStringFree (xmString);
-}
-void createRenderTable() {
- int xDisplay = data.display;
- int fontList = data.fontList;
- /* 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 widgetClass = OS.TopLevelShellWidgetClass ();
- int[] renditions = new int[4]; int renditionCount = 0;
-
- /* Create a rendition for each entry in the font list */
- int shellHandle = OS.XtAppCreateShell (null, null, widgetClass, xDisplay, null, 0);
- 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(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);
- OS.XtDestroyWidget (shellHandle);
-
- /* 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]);
-}
+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);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
+ int xmString = OS.XmStringCreate (buffer, OS.XmFONTLIST_DEFAULT_TAG);
+ if (isTransparent) {
+ OS.XmStringDraw (data.display, data.drawable, data.fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
+ } else {
+ OS.XmStringDrawImage (data.display, data.drawable, data.fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
+ }
+// OS.XmStringDrawUnderline (display, drawable, fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, 0);
+ OS.XmStringFree (xmString);
+}
+void createRenderTable() {
+ int xDisplay = data.display;
+ int fontList = data.fontList;
+ /* 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 widgetClass = OS.TopLevelShellWidgetClass ();
+ int[] renditions = new int[4]; int renditionCount = 0;
+
+ /* Create a rendition for each entry in the font list */
+ int shellHandle = OS.XtAppCreateShell (null, null, widgetClass, xDisplay, null, 0);
+ 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(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);
+ OS.XtDestroyWidget (shellHandle);
+
+ /* 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
@@ -995,9 +995,9 @@ void createRenderTable() {
* <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);
-}
+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
@@ -1018,78 +1018,78 @@ public void drawText (String string, int x, int y) {
* <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, 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 (data.renderTable == 0) createRenderTable();
- int renderTable = data.renderTable;
-
- 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 = stripMnemonic(text);
-
- String codePage = getCodePage();
- byte[] buffer = Converter.wcsToMbcs(codePage, text, true);
- int xmString = 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);
- int xmStringUnderline = OS.XmStringCreate (buffer1, OS.XmFONTLIST_DEFAULT_TAG);
- OS.XmStringDrawUnderline(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, xmStringUnderline);
- OS.XmStringFree(xmStringUnderline);
- } else {
- if ((flags & SWT.DRAW_TRANSPARENT) != 0) {
- OS.XmStringDraw(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- } else {
- OS.XmStringDrawImage(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- }
- }
- OS.XmStringFree(xmString);
-}
+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 (data.renderTable == 0) createRenderTable();
+ int renderTable = data.renderTable;
+
+ 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 = stripMnemonic(text);
+
+ String codePage = getCodePage();
+ byte[] buffer = Converter.wcsToMbcs(codePage, text, true);
+ int xmString = 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);
+ int xmStringUnderline = OS.XmStringCreate (buffer1, OS.XmFONTLIST_DEFAULT_TAG);
+ OS.XmStringDrawUnderline(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, xmStringUnderline);
+ OS.XmStringFree(xmStringUnderline);
+ } else {
+ if ((flags & SWT.DRAW_TRANSPARENT) != 0) {
+ OS.XmStringDraw(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
+ } else {
+ OS.XmStringDrawImage(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
+ }
+ }
+ OS.XmStringFree(xmString);
+}
/**
* Compares the argument to the receiver, and returns true
* if they represent the <em>same</em> object using a class
@@ -1100,11 +1100,11 @@ public void drawText (String string, int x, int y, int flags) {
*
* @see #hashCode
*/
-public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof GC)) return false;
- return handle == ((GC)object).handle;
-}
+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
@@ -1140,125 +1140,125 @@ public boolean equals (Object object) {
*
* @see #drawArc
*/
-public void fillArc(int x, int y, int width, int height, int startAngle, int endAngle) {
- 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 || endAngle == 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int xDisplay = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- OS.XSetForeground (xDisplay, handle, values.background);
- OS.XFillArc(xDisplay,data.drawable,handle,x,y,width,height,startAngle * 64 ,endAngle * 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
+public void fillArc(int x, int y, int width, int height, int startAngle, int endAngle) {
+ 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 || endAngle == 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ int xDisplay = data.display;
+ XGCValues values = new XGCValues ();
+ OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
+ OS.XSetForeground (xDisplay, handle, values.background);
+ OS.XFillArc(xDisplay,data.drawable,handle,x,y,width,height,startAngle * 64 ,endAngle * 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
*/
-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);
-
- 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.
+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);
+
+ 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;
-}
-
+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
@@ -1275,23 +1275,23 @@ static int getChannelWidth(int mask) {
*
* @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);
- OS.XSetForeground (display, handle, values.background);
- OS.XFillArc (display, data.drawable, handle, x, y, width, height, 0, 23040);
- OS.XSetForeground (display, handle, values.foreground);
-}
+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);
+ 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 interior of the closed polygon which is defined by the
* specified array of integer coordinates, using the receiver's
@@ -1311,20 +1311,20 @@ public void fillOval (int x, int y, int width, int height) {
*
* @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[] xPoints = new short[pointArray.length];
- for (int i = 0; i<pointArray.length;i++) {
- xPoints[i] = (short) pointArray[i];
- }
- int xDisplay = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- 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);
-}
+public void fillPolygon(int[] pointArray) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ short[] xPoints = new short[pointArray.length];
+ for (int i = 0; i<pointArray.length;i++) {
+ xPoints[i] = (short) pointArray[i];
+ }
+ int xDisplay = data.display;
+ XGCValues values = new XGCValues ();
+ OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
+ 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.
@@ -1340,23 +1340,23 @@ public void fillPolygon(int[] pointArray) {
*
* @see #drawRectangle
*/
-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);
- OS.XSetForeground (xDisplay, handle, values.background);
- OS.XFillRectangle (xDisplay, data.drawable, handle, x, y, width, height);
- OS.XSetForeground (xDisplay, handle, values.foreground);
-}
+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);
+ 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.
@@ -1372,10 +1372,10 @@ public void fillRectangle (int x, int y, int width, int height) {
*
* @see #drawRectangle
*/
-public void fillRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- fillRectangle(rect.x, rect.y, rect.width, rect.height);
-}
+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.
@@ -1393,62 +1393,62 @@ public void fillRectangle (Rectangle rect) {
*
* @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 naw2 = naw / 2;
- int nah2 = nah / 2;
-
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- 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 - naw, nah2);
- OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nah, 0, 5760);
- OS.XFillRectangle(xDisplay, xDrawable, handle, nx, ny + nah2, nw, nh - nah);
- 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 - naw, 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 - naw, 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 - nah);
- 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);
-}
+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 naw2 = naw / 2;
+ int nah2 = nah / 2;
+
+ int xDisplay = data.display;
+ int xDrawable = data.drawable;
+ XGCValues values = new XGCValues ();
+ OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
+ 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 - naw, nah2);
+ OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nah, 0, 5760);
+ OS.XFillRectangle(xDisplay, xDrawable, handle, nx, ny + nah2, nw, nh - nah);
+ 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 - naw, 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 - naw, 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 - nah);
+ 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);
+}
/**
* Returns the <em>advance width</em> of the specified character in
* the font which is currently selected into the receiver.
@@ -1464,94 +1464,94 @@ public void fillRoundRectangle (int x, int y, int width, int height, int arcWidt
* <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.fontList;
- 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 */
- OS.memmove(charStruct, fontStruct.per_char + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.width;
- }
- }
- } 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 offset = row * charsPerRow + col;
- OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.width;
- }
- }
- }
- } 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 */
- OS.memmove(charStruct, fontStruct.per_char + (val - fontStruct.min_char_or_byte2 * XCharStruct.sizeof), XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.width;
- }
- }
- } 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 offset = row * charsPerRow + col;
- OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.width;
- }
- }
- }
- }
- }
- }
- OS.XmFontListFreeFontContext(context);
- return 0;
-}
+public int getAdvanceWidth(char ch) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ int fontList = data.fontList;
+ 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 */
+ OS.memmove(charStruct, fontStruct.per_char + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.width;
+ }
+ }
+ } 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 offset = row * charsPerRow + col;
+ OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.width;
+ }
+ }
+ }
+ } 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 */
+ OS.memmove(charStruct, fontStruct.per_char + (val - fontStruct.min_char_or_byte2 * XCharStruct.sizeof), XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.width;
+ }
+ }
+ } 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 offset = row * charsPerRow + col;
+ OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.width;
+ }
+ }
+ }
+ }
+ }
+ }
+ OS.XmFontListFreeFontContext(context);
+ return 0;
+}
/**
* Returns the background color.
*
@@ -1561,17 +1561,17 @@ public int getAdvanceWidth(char ch) {
* <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);
-
-}
+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 width of the specified character in the font
* selected into the receiver.
@@ -1588,94 +1588,94 @@ public Color getBackground() {
* <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.fontList;
- 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 */
- OS.memmove(charStruct, fontStruct.per_char + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.rbearing - charStruct.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 offset = row * charsPerRow + col;
- OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.rbearing - charStruct.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 */
- OS.memmove(charStruct, fontStruct.per_char + (val - fontStruct.min_char_or_byte2 * XCharStruct.sizeof), XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.rbearing - charStruct.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 offset = row * charsPerRow + col;
- OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.rbearing - charStruct.lbearing;
- }
- }
- }
- }
- }
- }
- OS.XmFontListFreeFontContext(context);
- return 0;
-}
+public int getCharWidth(char ch) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ int fontList = data.fontList;
+ 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 */
+ OS.memmove(charStruct, fontStruct.per_char + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.rbearing - charStruct.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 offset = row * charsPerRow + col;
+ OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.rbearing - charStruct.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 */
+ OS.memmove(charStruct, fontStruct.per_char + (val - fontStruct.min_char_or_byte2 * XCharStruct.sizeof), XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.rbearing - charStruct.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 offset = row * charsPerRow + col;
+ OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
+ if (charStruct.width != 0) {
+ OS.XmFontListFreeFontContext(context);
+ return charStruct.rbearing - charStruct.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
@@ -1688,19 +1688,19 @@ public int getCharWidth(char ch) {
* <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 clipRgn = data.clipRgn;
- if (clipRgn == 0) {
- int[] width = new int[1]; int[] height = new int[1];
- int[] unused = new int[1];
- OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused);
- return new Rectangle(0, 0, width[0], height[0]);
- }
- XRectangle rect = new XRectangle();
- OS.XClipBox(clipRgn, rect);
- return new Rectangle(rect.x, rect.y, rect.width, rect.height);
-}
+public Rectangle getClipping() {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ int clipRgn = data.clipRgn;
+ if (clipRgn == 0) {
+ int[] width = new int[1]; int[] height = new int[1];
+ int[] unused = new int[1];
+ OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused);
+ return new Rectangle(0, 0, width[0], height[0]);
+ }
+ XRectangle rect = new XRectangle();
+ OS.XClipBox(clipRgn, rect);
+ 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.
@@ -1714,28 +1714,28 @@ public Rectangle getClipping() {
* <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;
- int clipRgn = data.clipRgn;
- if (clipRgn == 0) {
- int[] width = new int[1]; int[] height = new int[1];
- int[] unused = new int[1];
- OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused);
- OS.XSubtractRegion (hRegion, hRegion, hRegion);
- 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);
- return;
- }
- OS.XSubtractRegion (hRegion, hRegion, hRegion);
- OS.XUnionRegion (clipRgn, hRegion, hRegion);
-}
-String getCodePage () {
- return data.codePage;
-}
+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;
+ int clipRgn = data.clipRgn;
+ if (clipRgn == 0) {
+ int[] width = new int[1]; int[] height = new int[1];
+ int[] unused = new int[1];
+ OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused);
+ OS.XSubtractRegion (hRegion, hRegion, hRegion);
+ 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);
+ return;
+ }
+ OS.XSubtractRegion (hRegion, hRegion, hRegion);
+ OS.XUnionRegion (clipRgn, hRegion, hRegion);
+}
+String getCodePage () {
+ return data.codePage;
+}
/**
* Returns the font currently being used by the receiver
* to draw and measure text.
@@ -1746,52 +1746,52 @@ String getCodePage () {
* <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.fontList);
-}
-int getFontHeight () {
- int fontList = data.fontList;
- /* 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;
- 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;
-}
+public Font getFont () {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ return Font.motif_new(data.device, data.fontList);
+}
+int getFontHeight () {
+ int fontList = data.fontList;
+ /* 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;
+ 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;
+}
/**
* Returns a FontMetrics which contains information
* about the font currently being used by the receiver
@@ -1803,158 +1803,158 @@ int getFontHeight () {
* <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;
- int fontList = data.fontList;
- /* 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 = ascent > fontStruct.max_bounds_ascent ? ascent : fontStruct.max_bounds_ascent;
- descent = descent > fontStruct.descent ? descent : fontStruct.descent;
- int tmp = fontStruct.ascent + fontStruct.descent;
- height = height > tmp ? height : tmp;
- tmp = fontStruct.ascent - fontStruct.max_bounds_ascent;
- leading = leading > tmp ? leading : tmp;
- /* Calculate average character width */
- int propPtr = fontStruct.properties;
- for (int i = 0; i < fontStruct.n_properties; i++) {
- /* Reef through properties looking 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 */
- StringBuffer stringBuffer = new StringBuffer();
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int strPtr = ptr;
- byte[] c = new byte[1];
- OS.memmove(c, strPtr, 1);
- while (c[0] != 0) {
- stringBuffer.append((char)c[0]);
- strPtr++;
- OS.memmove(c, strPtr, 1);
- }
- String xlfd = stringBuffer.toString().toLowerCase();
- int avg = FontData.motif_new(xlfd).averageWidth / 10;
- OS.XtFree(ptr);
- 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.
+public FontMetrics getFontMetrics() {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ int xDisplay = data.display;
+ int fontList = data.fontList;
+ /* 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 = ascent > fontStruct.max_bounds_ascent ? ascent : fontStruct.max_bounds_ascent;
+ descent = descent > fontStruct.descent ? descent : fontStruct.descent;
+ int tmp = fontStruct.ascent + fontStruct.descent;
+ height = height > tmp ? height : tmp;
+ tmp = fontStruct.ascent - fontStruct.max_bounds_ascent;
+ leading = leading > tmp ? leading : tmp;
+ /* Calculate average character width */
+ int propPtr = fontStruct.properties;
+ for (int i = 0; i < fontStruct.n_properties; i++) {
+ /* Reef through properties looking 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 */
+ StringBuffer stringBuffer = new StringBuffer();
+ int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
+ int strPtr = ptr;
+ byte[] c = new byte[1];
+ OS.memmove(c, strPtr, 1);
+ while (c[0] != 0) {
+ stringBuffer.append((char)c[0]);
+ strPtr++;
+ OS.memmove(c, strPtr, 1);
+ }
+ String xlfd = stringBuffer.toString().toLowerCase();
+ int avg = FontData.motif_new(xlfd).averageWidth / 10;
+ OS.XtFree(ptr);
+ 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 sum = 0, count = 0;
- int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int perCharPtr = fontStruct.per_char;
- 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 = ascent > fontStruct.max_bounds_ascent ? ascent : fontStruct.max_bounds_ascent;
- descent = descent > fontStruct.descent ? descent : fontStruct.descent;
- int tmp = fontStruct.ascent + fontStruct.descent;
- height = height > tmp ? height : tmp;
- tmp = fontStruct.ascent - fontStruct.max_bounds_ascent;
- leading = leading > tmp ? leading : tmp;
- /* Calculate average character width */
- int propPtr = fontStruct.properties;
- for (int j = 0; j < fontStruct.n_properties; j++) {
- /* Reef through properties looking 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 */
- StringBuffer stringBuffer = new StringBuffer();
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int strPtr = ptr;
- byte[] c = new byte[1];
- OS.memmove(c, strPtr, 1);
- while (c[0] != 0) {
- stringBuffer.append((char)c[0]);
- strPtr++;
- OS.memmove(c, strPtr, 1);
- }
- String xlfd = stringBuffer.toString().toLowerCase();
- int avg = FontData.motif_new(xlfd).averageWidth / 10;
- OS.XFree(ptr);
- 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 sum = 0, count = 0;
+ int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
+ int perCharPtr = fontStruct.per_char;
+ 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 = ascent > fontStruct.max_bounds_ascent ? ascent : fontStruct.max_bounds_ascent;
+ descent = descent > fontStruct.descent ? descent : fontStruct.descent;
+ int tmp = fontStruct.ascent + fontStruct.descent;
+ height = height > tmp ? height : tmp;
+ tmp = fontStruct.ascent - fontStruct.max_bounds_ascent;
+ leading = leading > tmp ? leading : tmp;
+ /* Calculate average character width */
+ int propPtr = fontStruct.properties;
+ for (int j = 0; j < fontStruct.n_properties; j++) {
+ /* Reef through properties looking 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 */
+ StringBuffer stringBuffer = new StringBuffer();
+ int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
+ int strPtr = ptr;
+ byte[] c = new byte[1];
+ OS.memmove(c, strPtr, 1);
+ while (c[0] != 0) {
+ stringBuffer.append((char)c[0]);
+ strPtr++;
+ OS.memmove(c, strPtr, 1);
+ }
+ String xlfd = stringBuffer.toString().toLowerCase();
+ int avg = FontData.motif_new(xlfd).averageWidth / 10;
+ OS.XFree(ptr);
+ 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 sum = 0, count = 0;
- int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int perCharPtr = fontStruct.per_char;
- 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);
-}
+ int sum = 0, count = 0;
+ int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
+ int perCharPtr = fontStruct.per_char;
+ 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.
*
@@ -1964,17 +1964,17 @@ public FontMetrics getFontMetrics() {
* <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);
-
-}
+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 receiver's line style, which will be one
* of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
@@ -1987,10 +1987,10 @@ public Color getForeground() {
* <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;
-}
+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,
@@ -2003,12 +2003,12 @@ public int getLineStyle() {
* <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;
-}
+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 <code>true</code> if this GC is drawing in the mode
* where the resulting color in the destination is the
@@ -2023,12 +2023,12 @@ public int getLineWidth() {
* <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;
-}
+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 which return <code>true</code> when passed to
@@ -2043,29 +2043,29 @@ public boolean getXORMode() {
*
* @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;
-}
+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;
+}
/**
* Returns <code>true</code> if the receiver has a clipping
* region set into it, and <code>false</code> otherwise.
@@ -2080,10 +2080,10 @@ void init(Drawable drawable, GCData data, int xGC) {
* <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;
-}
+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.
@@ -2094,15 +2094,15 @@ public boolean isClipped() {
*
* @return <code>true</code> when the GC is disposed and <code>false</code> otherwise
*/
-public boolean isDisposed() {
- return handle == 0;
-}
-public static GC motif_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- int xGC = drawable.internal_new_GC(data);
- gc.init(drawable, data, xGC);
- return gc;
-}
+public boolean isDisposed() {
+ return handle == 0;
+}
+public static GC motif_new(Drawable drawable, GCData data) {
+ GC gc = new GC();
+ int xGC = drawable.internal_new_GC(data);
+ gc.init(drawable, data, xGC);
+ return gc;
+}
/**
* Sets the background color. The background color is used
* for fill operations and as the background color when text
@@ -2118,12 +2118,12 @@ public static GC motif_new(Drawable drawable, GCData data) {
* <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);
-}
+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);
+}
/**
* Sets the area of the receiver which can be changed
* by drawing operations to the rectangular area specified
@@ -2138,20 +2138,20 @@ public void setBackground (Color color) {
* <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 clipRgn = data.clipRgn;
- if (clipRgn == 0) {
- data.clipRgn = clipRgn = OS.XCreateRegion ();
- } else {
- OS.XSubtractRegion (clipRgn, clipRgn, clipRgn);
- }
- XRectangle rect = new XRectangle ();
- rect.x = (short) x; rect.y = (short) y;
- rect.width = (short) width; rect.height = (short) height;
- OS.XSetClipRectangles (data.display, handle, 0, 0, rect, 1, OS.Unsorted);
- OS.XUnionRectWithRegion(rect, clipRgn, clipRgn);
-}
+public void setClipping (int x, int y, int width, int height) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ int clipRgn = data.clipRgn;
+ if (clipRgn == 0) {
+ data.clipRgn = clipRgn = OS.XCreateRegion ();
+ } else {
+ OS.XSubtractRegion (clipRgn, clipRgn, clipRgn);
+ }
+ XRectangle rect = new XRectangle ();
+ rect.x = (short) x; rect.y = (short) y;
+ rect.width = (short) width; rect.height = (short) height;
+ OS.XSetClipRectangles (data.display, handle, 0, 0, rect, 1, OS.Unsorted);
+ OS.XUnionRectWithRegion(rect, clipRgn, clipRgn);
+}
/**
* Sets the area of the receiver which can be changed
* by drawing operations to the rectangular area specified
@@ -2163,19 +2163,19 @@ public void setClipping (int x, int y, int width, int height) {
* <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) {
- OS.XSetClipMask (data.display, handle, OS.None);
- int clipRgn = data.clipRgn;
- if (clipRgn != 0) {
- OS.XDestroyRegion (clipRgn);
- data.clipRgn = 0;
- }
- return;
- }
- setClipping (rect.x, rect.y, rect.width, rect.height);
-}
+public void setClipping (Rectangle rect) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (rect == null) {
+ OS.XSetClipMask (data.display, handle, OS.None);
+ int clipRgn = data.clipRgn;
+ if (clipRgn != 0) {
+ OS.XDestroyRegion (clipRgn);
+ data.clipRgn = 0;
+ }
+ return;
+ }
+ 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
@@ -2187,25 +2187,25 @@ public void setClipping (Rectangle rect) {
* <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);
- int clipRgn = data.clipRgn;
- if (region == null) {
- OS.XSetClipMask (data.display, handle, OS.None);
- if (clipRgn != 0) {
- OS.XDestroyRegion (clipRgn);
- data.clipRgn = 0;
- }
- } else {
- if (clipRgn == 0) {
- data.clipRgn = clipRgn = OS.XCreateRegion ();
- } else {
- OS.XSubtractRegion (clipRgn, clipRgn, clipRgn);
- }
- OS.XUnionRegion (region.handle, clipRgn, clipRgn);
- OS.XSetRegion (data.display, handle, region.handle);
- }
-}
+public void setClipping (Region region) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ int clipRgn = data.clipRgn;
+ if (region == null) {
+ OS.XSetClipMask (data.display, handle, OS.None);
+ if (clipRgn != 0) {
+ OS.XDestroyRegion (clipRgn);
+ data.clipRgn = 0;
+ }
+ } else {
+ if (clipRgn == 0) {
+ data.clipRgn = clipRgn = OS.XCreateRegion ();
+ } else {
+ OS.XSubtractRegion (clipRgn, clipRgn, clipRgn);
+ }
+ OS.XUnionRegion (region.handle, clipRgn, clipRgn);
+ OS.XSetRegion (data.display, handle, region.handle);
+ }
+}
/**
* Sets the font which will be used by the receiver
* to draw and measure text to the argument. If the
@@ -2222,14 +2222,14 @@ public void setClipping (Region region) {
* </ul>
*/
public void setFont (Font font) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ 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.fontList = font.handle;
- data.codePage = font.codePage;
- if (data.renderTable != 0) OS.XmRenderTableFree(data.renderTable);
- data.renderTable = 0;
-}
+ if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ data.fontList = font.handle;
+ data.codePage = font.codePage;
+ if (data.renderTable != 0) OS.XmRenderTableFree(data.renderTable);
+ data.renderTable = 0;
+}
/**
* Sets the foreground color. The foreground color is used
* for drawing operations including when text is drawn.
@@ -2244,12 +2244,12 @@ public void setFont (Font font) {
* <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);
-}
+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);
+}
/**
* 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>,
@@ -2262,33 +2262,33 @@ public void setForeground (Color color) {
* <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;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- data.lineStyle = lineStyle;
- OS.XSetLineAttributes(xDisplay, handle, 0, OS.LineSolid, OS.CapButt, OS.JoinMiter);
- return;
- case SWT.LINE_DASH:
- OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2},2);
- break;
- case SWT.LINE_DOT:
- OS.XSetDashes(xDisplay,handle,0, new byte[] {3, 1},2);
- break;
- case SWT.LINE_DASHDOT:
- OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2, 3, 1},4);
- break;
- case SWT.LINE_DASHDOTDOT:
- OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2, 3, 1, 3, 1},6);
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineStyle = lineStyle;
- OS.XSetLineAttributes(xDisplay, handle, 0, OS.LineOnOffDash, OS.CapButt, OS.JoinMiter);
-
-}
+public void setLineStyle(int lineStyle) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ int xDisplay = data.display;
+ switch (lineStyle) {
+ case SWT.LINE_SOLID:
+ data.lineStyle = lineStyle;
+ OS.XSetLineAttributes(xDisplay, handle, 0, OS.LineSolid, OS.CapButt, OS.JoinMiter);
+ return;
+ case SWT.LINE_DASH:
+ OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2},2);
+ break;
+ case SWT.LINE_DOT:
+ OS.XSetDashes(xDisplay,handle,0, new byte[] {3, 1},2);
+ break;
+ case SWT.LINE_DASHDOT:
+ OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2, 3, 1},4);
+ break;
+ case SWT.LINE_DASHDOTDOT:
+ OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2, 3, 1, 3, 1},6);
+ break;
+ default:
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ data.lineStyle = lineStyle;
+ OS.XSetLineAttributes(xDisplay, handle, 0, OS.LineOnOffDash, OS.CapButt, OS.JoinMiter);
+
+}
/**
* Sets the width that will be used when drawing lines
* for all of the figure drawing operations (that is,
@@ -2301,14 +2301,14 @@ public void setLineStyle(int lineStyle) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public void setLineWidth(int width) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineStyle == SWT.LINE_SOLID) {
- OS.XSetLineAttributes(data.display, handle, width, OS.LineSolid, OS.CapButt, OS.JoinMiter);
- } else {
- OS.XSetLineAttributes(data.display, handle, width, OS.LineDoubleDash, OS.CapButt, OS.JoinMiter);
- }
-}
+public void setLineWidth(int width) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (data.lineStyle == SWT.LINE_SOLID) {
+ OS.XSetLineAttributes(data.display, handle, width, OS.LineSolid, OS.CapButt, OS.JoinMiter);
+ } else {
+ OS.XSetLineAttributes(data.display, handle, width, OS.LineDoubleDash, OS.CapButt, OS.JoinMiter);
+ }
+}
/**
* If the argument is <code>true</code>, puts the receiver
* in a drawing mode where the resulting color in the destination
@@ -2323,13 +2323,13 @@ public void setLineWidth(int width) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public void setXORMode(boolean xor) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (xor)
- OS.XSetFunction(data.display, handle, OS.GXxor);
- else
- OS.XSetFunction(data.display, handle, OS.GXcopy);
-}
+public void setXORMode(boolean xor) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (xor)
+ OS.XSetFunction(data.display, handle, OS.GXxor);
+ else
+ OS.XSetFunction(data.display, handle, OS.GXcopy);
+}
/**
* Returns the extent of the given string. No tab
* expansion or carriage return processing will be performed.
@@ -2349,32 +2349,32 @@ public void setXORMode(boolean xor) {
* <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);
- if (string.length () == 0) return new Point(0, getFontHeight());
- byte[] buffer = Converter.wcsToMbcs(getCodePage (), string, true);
- int xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG);
- int fontList = data.fontList;
- int width = OS.XmStringWidth(fontList, xmString);
- int height = OS.XmStringHeight(fontList, xmString);
- OS.XmStringFree(xmString);
- return new Point(width, height);
-}
-char stripMnemonic(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;
-}
+public Point stringExtent(String string) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (string.length () == 0) return new Point(0, getFontHeight());
+ byte[] buffer = Converter.wcsToMbcs(getCodePage (), string, true);
+ int xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG);
+ int fontList = data.fontList;
+ int width = OS.XmStringWidth(fontList, xmString);
+ int height = OS.XmStringHeight(fontList, xmString);
+ OS.XmStringFree(xmString);
+ return new Point(width, height);
+}
+char stripMnemonic(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 extent of the given string. Tab expansion and
* carriage return processing are performed.
@@ -2394,71 +2394,71 @@ char stripMnemonic(char[] text) {
* <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) {
+ 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 (string.length () == 0) return new Point(0, getFontHeight());
- if (data.renderTable == 0) createRenderTable();
- int renderTable = data.renderTable;
-
- 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) stripMnemonic(text);
-
- byte[] buffer = Converter.wcsToMbcs(getCodePage(), text, true);
- int xmString = OS.XmStringParseText(buffer, 0, OS.XmFONTLIST_DEFAULT_TAG, OS.XmCHARSET_TEXT, parseTable, tableLength, 0);
- int width = OS.XmStringWidth(renderTable, xmString);
- int height = OS.XmStringHeight(renderTable, xmString);
- OS.XmStringFree(xmString);
- return new Point(width, height);
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
+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 (string.length () == 0) return new Point(0, getFontHeight());
+ if (data.renderTable == 0) createRenderTable();
+ int renderTable = data.renderTable;
+
+ 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) stripMnemonic(text);
+
+ byte[] buffer = Converter.wcsToMbcs(getCodePage(), text, true);
+ int xmString = OS.XmStringParseText(buffer, 0, OS.XmFONTLIST_DEFAULT_TAG, OS.XmCHARSET_TEXT, parseTable, tableLength, 0);
+ int width = OS.XmStringWidth(renderTable, xmString);
+ int height = OS.XmStringHeight(renderTable, xmString);
+ OS.XmStringFree(xmString);
+ return new Point(width, 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 + "}";
-}
-}
+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
index 4fb1992908..24a3018664 100755
--- 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
@@ -1,14 +1,14 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+
/**
* Instances of this class are descriptions of GCs in terms
* of unallocated platform-specific data fields.
@@ -21,17 +21,17 @@ import org.eclipse.swt.*;
*
* @private
*/
-public final class GCData {
- public Device device;
- public Image image;
- public int display;
- public int drawable;
- public int foreground = -1;
- public int background = -1;
- public int fontList;
- public String codePage;
- public int colormap;
- public int clipRgn;
- public int lineStyle = SWT.LINE_SOLID;
- public int renderTable;
+public final class GCData {
+ public Device device;
+ public Image image;
+ public int display;
+ public int drawable;
+ public int foreground = -1;
+ public int background = -1;
+ public int fontList;
+ public String codePage;
+ public int colormap;
+ public int clipRgn;
+ public int lineStyle = SWT.LINE_SOLID;
+ public int renderTable;
}
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
index 351184f934..3016d74a47 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import java.io.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -58,62 +58,62 @@ import java.io.*;
* @see ImageData
* @see ImageLoader
*/
-public final class Image implements Drawable {
+public final class Image implements Drawable {
/**
* specifies whether the receiver is a bitmap or an icon
* (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
*/
- public int type;
-
- /**
- * The handle to the OS pixmap resource.
- * Warning: This field is platform dependent.
+ public int type;
+
+ /**
+ * The handle to the OS pixmap resource.
+ * Warning: This field is platform dependent.
*/
- public int pixmap;
-
- /**
- * The handle to the OS mask resource.
- * Warning: This field is platform dependent.
+ public int pixmap;
+
+ /**
+ * The handle to the OS mask resource.
+ * Warning: This field is platform dependent.
*/
- public int mask;
-
- /**
- * The device where this image was created.
+ public int mask;
+
+ /**
+ * The device where this image was created.
*/
- Device device;
-
- /**
- * specifies the transparent pixel
- * (Warning: This field is platform dependent)
+ Device device;
+
+ /**
+ * specifies the transparent pixel
+ * (Warning: This field is platform dependent)
*/
- int transparentPixel = -1;
-
- /**
- * The GC the image is currently selected in.
- * Warning: This field is platform dependent.
+ int transparentPixel = -1;
+
+ /**
+ * The GC the image is currently selected in.
+ * Warning: This field is platform dependent.
*/
- GC memGC;
-
- /**
- * The alpha data of the image.
- * Warning: This field is platform dependent.
+ GC memGC;
+
+ /**
+ * The alpha data of the image.
+ * Warning: This field is platform dependent.
*/
- byte[] alphaData;
-
- /**
- * The global alpha value to be used for every pixel.
- * Warning: This field is platform dependent.
+ byte[] alphaData;
+
+ /**
+ * The global alpha value to be used for every pixel.
+ * Warning: This field is platform dependent.
*/
- int alpha = -1;
-
- /**
- * Specifies the default scanline padding.
- * Warning: This field is platform dependent.
+ int alpha = -1;
+
+ /**
+ * Specifies the default scanline padding.
+ * Warning: This field is platform dependent.
*/
- static final int DEFAULT_SCANLINE_PAD = 4;
-
-Image() {
-}
+ 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
@@ -144,12 +144,12 @@ Image() {
* <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);
-}
+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
@@ -181,280 +181,280 @@ public Image(Device device, int width, int height) {
* <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.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);
- XImage destXImage = new XImage();
- int destXImagePtr = OS.XGetImage(xDisplay, drawable, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
- OS.memmove(destXImage, destXImagePtr, XImage.sizeof);
- byte[] destData = new byte[destXImage.bytes_per_line * destXImage.height];
- /* 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.
+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.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);
+ XImage destXImage = new XImage();
+ int destXImagePtr = OS.XGetImage(xDisplay, drawable, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
+ OS.memmove(destXImage, destXImagePtr, XImage.sizeof);
+ byte[] destData = new byte[destXImage.bytes_per_line * destXImage.height];
+ /* 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();
- int screenNum = OS.XDefaultScreen(xDisplay);
- int visualPtr = OS.XDefaultVisual(xDisplay, screenNum);
- 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();
- screenNum = OS.XDefaultScreen(xDisplay);
- visualPtr = OS.XDefaultVisual(xDisplay, screenNum);
- 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);
- 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.maskData = data.maskData;
- newData.maskPad = data.maskPad;
-
- /* 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];
- 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;
- newData.data[offset++] =
- (byte)((red+red+green+green+green+green+green+blue) >> 3);
- }
- }
- }
- init (device, newData);
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (device.tracking) device.new_Object(this);
-}
+ 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();
+ int screenNum = OS.XDefaultScreen(xDisplay);
+ int visualPtr = OS.XDefaultVisual(xDisplay, screenNum);
+ 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();
+ screenNum = OS.XDefaultScreen(xDisplay);
+ visualPtr = OS.XDefaultVisual(xDisplay, screenNum);
+ 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);
+ 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.maskData = data.maskData;
+ newData.maskPad = data.maskPad;
+
+ /* 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];
+ 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;
+ newData.data[offset++] =
+ (byte)((red+red+green+green+green+green+green+blue) >> 3);
+ }
+ }
+ }
+ 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
@@ -485,13 +485,13 @@ public Image(Device device, Image srcImage, int flag) {
* <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);
-}
+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>.
@@ -507,12 +507,12 @@ public Image(Device device, Rectangle bounds) {
* <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);
-}
+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>
@@ -542,21 +542,21 @@ public Image(Device device, ImageData image) {
* <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);
- }
- if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- 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);
-}
+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);
+ }
+ if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ 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
@@ -589,12 +589,12 @@ public Image(Device device, ImageData source, ImageData mask) {
* <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);
-}
+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
@@ -620,53 +620,53 @@ public Image(Device device, InputStream stream) {
* <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.
+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 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;
+}
/**
* 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;
+public void dispose () {
+ if (pixmap == 0) return;
if (device.isDisposed()) return;
- int xDisplay = device.xDisplay;
- if (pixmap != 0) OS.XFreePixmap (xDisplay, pixmap);
- if (mask != 0) OS.XFreePixmap (xDisplay, mask);
- memGC = null;
- pixmap = mask = 0;
- if (device.tracking) device.dispose_Object(this);
- device = null;
-}
-/**
- * Destroy the receiver's mask if it exists.
+ int xDisplay = device.xDisplay;
+ if (pixmap != 0) OS.XFreePixmap (xDisplay, pixmap);
+ if (mask != 0) OS.XFreePixmap (xDisplay, mask);
+ memGC = null;
+ pixmap = mask = 0;
+ 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;
-}
+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
@@ -677,12 +677,12 @@ void destroyMask() {
*
* @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;
-}
+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.
@@ -701,16 +701,16 @@ public boolean equals (Object object) {
* <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);
-}
+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
@@ -723,12 +723,12 @@ public Color getBackground() {
* <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);
- 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);
- return new Rectangle(0, 0, width [0], height [0]);
-}
+public Rectangle getBounds () {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ 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);
+ return new Rectangle(0, 0, width [0], height [0]);
+}
/**
* Returns an <code>ImageData</code> based on the receiver
* Modifications made to this <code>ImageData</code> will not
@@ -743,205 +743,205 @@ public Rectangle getBounds () {
*
* @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 = data.maskData = new byte[xMask.bytes_per_line * xMask.height];
- data.maskPad = xMask.bitmap_pad / 8;
- OS.memmove(maskData, xMask.data, maskData.length);
- OS.XDestroyImage(xMaskPtr);
- /* 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.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.
+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 = data.maskData = new byte[xMask.bytes_per_line * xMask.height];
+ data.maskPad = xMask.bitmap_pad / 8;
+ OS.memmove(maskData, xMask.data, maskData.length);
+ OS.XDestroyImage(xMaskPtr);
+ /* 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.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;
-}
+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 which return <code>true</code> when passed to
@@ -952,78 +952,78 @@ static boolean getOffsetForMask(int bitspp, int mask, int byteOrder, int[] poff)
*
* @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);
- }
- }
- this.pixmap = pixmap;
-}
+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);
+ }
+ }
+ this.pixmap = pixmap;
+}
/**
* Invokes platform specific functionality to allocate a new GC handle.
* <p>
@@ -1039,25 +1039,25 @@ void init(Device device, ImageData image) {
*
* @private
*/
-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) {
- data.device = device;
- data.display = xDisplay;
- data.drawable = pixmap;
- data.fontList = device.systemFont.handle;
- data.codePage = device.systemFont.codePage;
- data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay));
- data.image = this;
- }
- return xGC;
-}
+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) {
+ data.device = device;
+ data.display = xDisplay;
+ data.drawable = pixmap;
+ data.fontList = device.systemFont.handle;
+ data.codePage = device.systemFont.codePage;
+ data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay));
+ data.image = this;
+ }
+ return xGC;
+}
/**
* Invokes platform specific functionality to dispose a GC handle.
* <p>
@@ -1073,13 +1073,13 @@ public int internal_new_GC (GCData data) {
*
* @private
*/
-public void internal_dispose_GC (int gc, GCData 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);
-}
+ 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.
@@ -1090,250 +1090,250 @@ public void internal_dispose_GC (int gc, GCData data) {
*
* @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.
+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>
+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 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 + "}";
-}
-}
+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
index 09ed1152da..e96a080d69 100755
--- 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
@@ -1,15 +1,15 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -20,12 +20,12 @@ import org.eclipse.swt.*;
* when those instances are no longer required.
* </p>
*/
-public final class Region {
+public final class Region {
/**
* the OS resource for the region
* (Warning: This field is platform dependent)
*/
- public int handle;
+ public int handle;
/**
* Constructs a new empty region.
*
@@ -33,12 +33,12 @@ public final class Region {
* <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
* </ul>
*/
-public Region () {
- handle = OS.XCreateRegion ();
-}
-Region (int handle) {
- this.handle = handle;
-}
+public Region () {
+ handle = OS.XCreateRegion ();
+}
+Region (int handle) {
+ this.handle = handle;
+}
/**
* Adds the given rectangle to the collection of rectangles
* the receiver maintains to describe its area.
@@ -53,18 +53,18 @@ Region (int handle) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public void add (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- XRectangle xRect = new XRectangle();
- xRect.x = (short)rect.x;
- xRect.y = (short)rect.y;
- xRect.width = (short)rect.width;
- xRect.height = (short)rect.height;
- OS.XUnionRectWithRegion(xRect, handle, handle);
-}
+public void add (Rectangle rect) {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+
+ XRectangle xRect = new XRectangle();
+ xRect.x = (short)rect.x;
+ xRect.y = (short)rect.y;
+ xRect.width = (short)rect.width;
+ xRect.height = (short)rect.height;
+ OS.XUnionRectWithRegion(xRect, handle, handle);
+}
/**
* Adds all of the rectangles which make up the area covered
* by the argument to the collection of rectangles the receiver
@@ -80,12 +80,12 @@ public void add (Rectangle rect) {
* <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);
-}
+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,
@@ -99,10 +99,10 @@ public void add (Region region) {
* <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);
-}
+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>
@@ -118,19 +118,19 @@ public boolean contains (int x, int y) {
* <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);
-}
+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) OS.XDestroyRegion(handle);
- handle = 0;
-}
+public void dispose () {
+ if (handle != 0) OS.XDestroyRegion(handle);
+ handle = 0;
+}
/**
* Compares the argument to the receiver, and returns true
* if they represent the <em>same</em> object using a class
@@ -141,12 +141,12 @@ public void dispose () {
*
* @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;
-}
+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 rectangles the receiver
@@ -160,12 +160,12 @@ public boolean equals (Object object) {
*
* @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);
-}
+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 which return <code>true</code> when passed to
@@ -176,9 +176,9 @@ public Rectangle getBounds() {
*
* @see #equals
*/
-public int hashCode () {
- return handle;
-}
+public int hashCode () {
+ return handle;
+}
/**
* Returns <code>true</code> if the rectangle described by the
* arguments intersects with any of the rectangles the receiver
@@ -196,10 +196,10 @@ public int hashCode () {
*
* @see Rectangle#intersects
*/
-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;
-}
+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 rectangles the receiver mainains to describe
@@ -217,10 +217,10 @@ public boolean intersects (int x, int y, int width, int height) {
*
* @see Rectangle#intersects
*/
-public boolean intersects (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return intersects(rect.x, rect.y, rect.width, rect.height);
-}
+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.
@@ -231,9 +231,9 @@ public boolean intersects (Rectangle rect) {
*
* @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
*/
-public boolean isDisposed() {
- return handle == 0;
-}
+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
@@ -245,21 +245,21 @@ public boolean isDisposed() {
* <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(int handle) {
- return new Region(handle);
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
+public boolean isEmpty () {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ return OS.XEmptyRegion(handle);
+}
+public static Region motif_new(int handle) {
+ return new Region(handle);
+}
+/**
+ * Returns a string containing a concise, human-readable
+ * description of the receiver.
+ *
+ * @return a string representation of the receiver
*/
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
-}
+public String toString () {
+ if (isDisposed()) return "Region {*DISPOSED*}";
+ return "Region {" + handle + "}";
+}
+}
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
index 49dd363819..8d48870665 100755
--- 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
@@ -1,14 +1,14 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.motif.*;
+
/**
* This class implements the conversions between unicode characters
* and the <em>platform supported</em> representation for characters.
@@ -16,300 +16,300 @@ import org.eclipse.swt.internal.motif.*;
* 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 byte[] Unicode;
-
- static final Object LOCK = new Object ();
-
- /* Converter cache */
- static String LastMBToWCCodePage;
- static String LastWCToMBCodePage;
- static int LastWCToMB;
- static int LastMBToWC;
-
- /* Buffers cache */
- static int BufferSize;
- static int BufferTimes2;
- static int BufferTimes4;
-
- static {
- Unicode = getAsciiBytes("UCS-2");
-
- 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";
- }
-
- BufferSize = 512;
- BufferTimes2 = OS.XtMalloc (BufferSize * 2);
- BufferTimes4 = OS.XtMalloc (BufferSize * 4);
- }
-
-/**
- * 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) {
- String cp = codePage != null ? codePage : CodePage;
- if (LastMBToWC != 0 && !cp.equals (LastMBToWCCodePage)) {
- OS.iconv_close (LastMBToWC);
- LastMBToWC = 0;
- }
- if (LastMBToWC == 0) {
- LastMBToWCCodePage = cp;
- LastMBToWC = OS.iconv_open (Unicode, getAsciiBytes (cp));
- if (LastMBToWC == -1) LastMBToWC = 0;
- }
- int cd = LastMBToWC;
- if (cd == 0) return EMPTY_CHAR_ARRAY;
- int inBytes = length;
- int outBytes = length * 2;
- int ptr1, ptr2;
- if (length <= BufferSize * 2) {
- ptr1 = BufferTimes2;
- ptr2 = BufferTimes4;
- } else {
- ptr1 = OS.XtMalloc (inBytes);
- ptr2 = OS.XtMalloc (outBytes);
- }
- int [] inBuf = {ptr1};
- int [] inBytesLeft = {inBytes};
- int [] outBuf = {ptr2};
- int [] outBytesLeft = {outBytes};
- OS.memmove (ptr1, buffer, inBytes);
- OS.iconv (cd, inBuf, inBytesLeft, outBuf, outBytesLeft);
- outBytes = outBuf [0] - ptr2;
- wideCharStr = new char [outBytes / 2];
- OS.memmove (wideCharStr, ptr2, outBytes);
- if (ptr1 != BufferTimes2) OS.XtFree (ptr1);
- if (ptr2 != BufferTimes4) OS.XtFree (ptr2);
- }
- return wideCharStr;
- }
- }
- return wideCharStr;
-}
-
-/**
- * Free any cached resources.
- */
-public static void release () {
- synchronized (LOCK) {
- if (BufferTimes2 != 0) OS.XtFree (BufferTimes2);
- if (BufferTimes4 != 0) OS.XtFree (BufferTimes4);
- if (LastWCToMB != 0) OS.iconv_close (LastWCToMB);
- if (LastMBToWC != 0) OS.iconv_close (LastMBToWC);
- LastMBToWC = LastWCToMB = BufferTimes4 = BufferTimes2 = 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) {
- String cp = codePage != null ? codePage : CodePage;
- if (LastWCToMB != 0 && !cp.equals (LastWCToMBCodePage)) {
- OS.iconv_close (LastWCToMB);
- LastWCToMB = 0;
- }
- if (LastWCToMB == 0) {
- LastWCToMBCodePage = cp;
- LastWCToMB = OS.iconv_open (getAsciiBytes (cp), Unicode);
- if (LastWCToMB == -1) LastWCToMB = 0;
- }
- int cd = LastWCToMB;
- if (cd == 0) return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY;
- int inBytes = length * 2;
- int outBytes = length * 4;
- int ptr1, ptr2;
- if (length <= BufferSize) {
- ptr1 = BufferTimes2;
- ptr2 = BufferTimes4;
- } else {
- ptr1 = OS.XtMalloc (inBytes);
- ptr2 = OS.XtMalloc (outBytes);
- }
- int [] inBuf = {ptr1};
- int [] inBytesLeft = {inBytes};
- int [] outBuf = {ptr2};
- int [] outBytesLeft = {outBytes};
- OS.memmove (ptr1, buffer, inBytes);
- while (inBytesLeft [0] > 0) {
- OS.iconv (cd, inBuf, inBytesLeft, outBuf, outBytesLeft);
- if (inBytesLeft [0] != 0) {
- inBuf [0] += 2;
- inBytesLeft [0] -= 2;
- }
- }
- outBytes = outBuf [0] - ptr2;
- mbcs = new byte [terminate ? outBytes + 1 : outBytes];
- OS.memmove (mbcs, ptr2, outBytes);
- if (ptr1 != BufferTimes2) OS.XtFree (ptr1);
- if (ptr2 != BufferTimes4) OS.XtFree (ptr2);
- }
- 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);
- }
-}
-
-}
+ */
+
+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 byte[] Unicode;
+
+ static final Object LOCK = new Object ();
+
+ /* Converter cache */
+ static String LastMBToWCCodePage;
+ static String LastWCToMBCodePage;
+ static int LastWCToMB;
+ static int LastMBToWC;
+
+ /* Buffers cache */
+ static int BufferSize;
+ static int BufferTimes2;
+ static int BufferTimes4;
+
+ static {
+ Unicode = getAsciiBytes("UCS-2");
+
+ 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";
+ }
+
+ BufferSize = 512;
+ BufferTimes2 = OS.XtMalloc (BufferSize * 2);
+ BufferTimes4 = OS.XtMalloc (BufferSize * 4);
+ }
+
+/**
+ * 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) {
+ String cp = codePage != null ? codePage : CodePage;
+ if (LastMBToWC != 0 && !cp.equals (LastMBToWCCodePage)) {
+ OS.iconv_close (LastMBToWC);
+ LastMBToWC = 0;
+ }
+ if (LastMBToWC == 0) {
+ LastMBToWCCodePage = cp;
+ LastMBToWC = OS.iconv_open (Unicode, getAsciiBytes (cp));
+ if (LastMBToWC == -1) LastMBToWC = 0;
+ }
+ int cd = LastMBToWC;
+ if (cd == 0) return EMPTY_CHAR_ARRAY;
+ int inBytes = length;
+ int outBytes = length * 2;
+ int ptr1, ptr2;
+ if (length <= BufferSize * 2) {
+ ptr1 = BufferTimes2;
+ ptr2 = BufferTimes4;
+ } else {
+ ptr1 = OS.XtMalloc (inBytes);
+ ptr2 = OS.XtMalloc (outBytes);
+ }
+ int [] inBuf = {ptr1};
+ int [] inBytesLeft = {inBytes};
+ int [] outBuf = {ptr2};
+ int [] outBytesLeft = {outBytes};
+ OS.memmove (ptr1, buffer, inBytes);
+ OS.iconv (cd, inBuf, inBytesLeft, outBuf, outBytesLeft);
+ outBytes = outBuf [0] - ptr2;
+ wideCharStr = new char [outBytes / 2];
+ OS.memmove (wideCharStr, ptr2, outBytes);
+ if (ptr1 != BufferTimes2) OS.XtFree (ptr1);
+ if (ptr2 != BufferTimes4) OS.XtFree (ptr2);
+ }
+ return wideCharStr;
+ }
+ }
+ return wideCharStr;
+}
+
+/**
+ * Free any cached resources.
+ */
+public static void release () {
+ synchronized (LOCK) {
+ if (BufferTimes2 != 0) OS.XtFree (BufferTimes2);
+ if (BufferTimes4 != 0) OS.XtFree (BufferTimes4);
+ if (LastWCToMB != 0) OS.iconv_close (LastWCToMB);
+ if (LastMBToWC != 0) OS.iconv_close (LastMBToWC);
+ LastMBToWC = LastWCToMB = BufferTimes4 = BufferTimes2 = 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) {
+ String cp = codePage != null ? codePage : CodePage;
+ if (LastWCToMB != 0 && !cp.equals (LastWCToMBCodePage)) {
+ OS.iconv_close (LastWCToMB);
+ LastWCToMB = 0;
+ }
+ if (LastWCToMB == 0) {
+ LastWCToMBCodePage = cp;
+ LastWCToMB = OS.iconv_open (getAsciiBytes (cp), Unicode);
+ if (LastWCToMB == -1) LastWCToMB = 0;
+ }
+ int cd = LastWCToMB;
+ if (cd == 0) return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY;
+ int inBytes = length * 2;
+ int outBytes = length * 4;
+ int ptr1, ptr2;
+ if (length <= BufferSize) {
+ ptr1 = BufferTimes2;
+ ptr2 = BufferTimes4;
+ } else {
+ ptr1 = OS.XtMalloc (inBytes);
+ ptr2 = OS.XtMalloc (outBytes);
+ }
+ int [] inBuf = {ptr1};
+ int [] inBytesLeft = {inBytes};
+ int [] outBuf = {ptr2};
+ int [] outBytesLeft = {outBytes};
+ OS.memmove (ptr1, buffer, inBytes);
+ while (inBytesLeft [0] > 0) {
+ OS.iconv (cd, inBuf, inBytesLeft, outBuf, outBytesLeft);
+ if (inBytesLeft [0] != 0) {
+ inBuf [0] += 2;
+ inBytesLeft [0] -= 2;
+ }
+ }
+ outBytes = outBuf [0] - ptr2;
+ mbcs = new byte [terminate ? outBytes + 1 : outBytes];
+ OS.memmove (mbcs, ptr2, outBytes);
+ if (ptr1 != BufferTimes2) OS.XtFree (ptr1);
+ if (ptr2 != BufferTimes4) OS.XtFree (ptr2);
+ }
+ 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
index b79ce639ca..8fe272413f 100755
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -36,20 +36,20 @@ import org.eclipse.swt.events.*;
* within the SWT implementation.
* </p>
*/
-public class Button extends Control {
- 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;
- }
+public class Button extends Control {
+ 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.
@@ -86,234 +86,234 @@ public class Button extends Control {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Button (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected, by 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 Button (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notified when the control is selected, by 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) != 0) {
- return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
- }
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) {
- return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
- }
- if ((style & SWT.ARROW) != 0) {
- return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
- }
- return style;
-}
-void click () {
- OS.XtCallActionProc (handle, ARM_AND_ACTIVATE, new XAnyEvent (), null, 0);
-}
-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) {
- Display display = getDisplay ();
- 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.
+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) != 0) {
+ return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
+ }
+ if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) {
+ return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
+ }
+ if ((style & SWT.ARROW) != 0) {
+ return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
+ }
+ return style;
+}
+void click () {
+ OS.XtCallActionProc (handle, ARM_AND_ACTIVATE, new XAnyEvent (), null, 0);
+}
+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) {
+ Display display = getDisplay ();
+ 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 (OS.XmStringEmpty (xmString)) height += getFontHeight ();
- if (xmString != 0) 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) {
- state |= HANDLE;
- 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.
- */
- Display display = getDisplay ();
- 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 getDisplay ().buttonBackground;
-}
-Font defaultFont () {
- return getDisplay ().buttonFont;
-}
-int defaultForeground () {
- return getDisplay ().buttonForeground;
-}
+ 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 (OS.XmStringEmpty (xmString)) height += getFontHeight ();
+ if (xmString != 0) 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) {
+ state |= HANDLE;
+ 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.
+ */
+ Display display = getDisplay ();
+ 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 getDisplay ().buttonBackground;
+}
+Font defaultFont () {
+ return getDisplay ().buttonFont;
+}
+int defaultForeground () {
+ return getDisplay ().buttonForeground;
+}
/**
* Returns a value which describes the position of the
* text or image in the receiver. The value will be one of
@@ -330,50 +330,50 @@ int defaultForeground () {
* <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;
-}
-/**
- * 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 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;
+}
+/**
+ * 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 ();
-}
+public Image getImage () {
+ checkWidget();
+ return image;
+}
+String getNameText () {
+ return getText ();
+}
/**
* Returns <code>true</code> if the receiver is selected,
* and false otherwise.
@@ -390,148 +390,148 @@ String getNameText () {
* <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.
- *
- * @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 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.
+ *
+ * @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 "";
- int [] argList = {OS.XmNlabelString, 0, OS.XmNmnemonic, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int xmString = argList [1];
- int mnemonic = argList [3];
- if (mnemonic == OS.XK_VoidSymbol) mnemonic = 0;
- if (xmString == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
- char [] result = null;
- int address = OS.XmStringUnparse (
- xmString,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (address != 0) {
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- result = Converter.mbcsToWcs (getCodePage (), buffer);
- }
- OS.XmStringFree (xmString);
- int count = 0;
- if (mnemonic != 0) count++;
- for (int i=0; i<result.length-1; i++)
- if (result [i] == Mnemonic) count++;
- char [] newResult = result;
- if ((count != 0) || (mnemonic != 0)) {
- newResult = new char [result.length + count];
- int i = 0, j = 0;
- while (i < result.length) {
- if ((mnemonic != 0) && (result [i] == mnemonic)) {
- if (j < newResult.length) newResult [j++] = Mnemonic;
- mnemonic = 0;
- }
- if ((newResult [j++] = result [i++]) == Mnemonic)
- if (j < newResult.length) newResult [j++] = Mnemonic;
- }
- }
- return new String (newResult);
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = getDisplay ().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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 String getText () {
+ checkWidget();
+ if ((style & SWT.ARROW) != 0) return "";
+ int [] argList = {OS.XmNlabelString, 0, OS.XmNmnemonic, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int xmString = argList [1];
+ int mnemonic = argList [3];
+ if (mnemonic == OS.XK_VoidSymbol) mnemonic = 0;
+ if (xmString == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
+ char [] result = null;
+ int address = OS.XmStringUnparse (
+ xmString,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (address != 0) {
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ result = Converter.mbcsToWcs (getCodePage (), buffer);
+ }
+ OS.XmStringFree (xmString);
+ int count = 0;
+ if (mnemonic != 0) count++;
+ for (int i=0; i<result.length-1; i++)
+ if (result [i] == Mnemonic) count++;
+ char [] newResult = result;
+ if ((count != 0) || (mnemonic != 0)) {
+ newResult = new char [result.length + count];
+ int i = 0, j = 0;
+ while (i < result.length) {
+ if ((mnemonic != 0) && (result [i] == mnemonic)) {
+ if (j < newResult.length) newResult [j++] = Mnemonic;
+ mnemonic = 0;
+ }
+ if ((newResult [j++] = result [i++]) == Mnemonic)
+ if (j < newResult.length) newResult [j++] = Mnemonic;
+ }
+ }
+ return new String (newResult);
+}
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
-}
+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
@@ -548,99 +548,99 @@ void selectRadio () {
* <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);
- int [] argList = {OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == OS.XmPIXMAP) setBitmap (image);
-}
-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);
- Display display = getDisplay ();
- switch (image.type) {
- case SWT.BITMAP:
- labelPixmap = image.pixmap;
- disabled = new Image (display, image, SWT.IMAGE_DISABLE);
- labelInsensitivePixmap = disabled.pixmap;
- break;
- 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, OS.XmPIXMAP,
- OS.XmNlabelPixmap, labelPixmap,
- OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-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);
-}
-/**
- * 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 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);
+ int [] argList = {OS.XmNlabelType, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [1] == OS.XmPIXMAP) setBitmap (image);
+}
+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);
+ Display display = getDisplay ();
+ switch (image.type) {
+ case SWT.BITMAP:
+ labelPixmap = image.pixmap;
+ disabled = new Image (display, image, SWT.IMAGE_DISABLE);
+ labelInsensitivePixmap = disabled.pixmap;
+ break;
+ 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, OS.XmPIXMAP,
+ OS.XmNlabelPixmap, labelPixmap,
+ OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap,
+ };
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+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);
+}
+/**
+ * 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();
- setBitmap (this.image = image);
-}
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
+public void setImage (Image image) {
+ checkWidget();
+ setBitmap (this.image = 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>.
@@ -657,108 +657,108 @@ boolean setRadioSelection (boolean value) {
* <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>
- *
- * @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 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>
+ *
+ * @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;
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- int i=0, j=0, mnemonic=0;
- while (i < text.length) {
- if ((text [j++] = text [i++]) == Mnemonic) {
- if (i == text.length) {continue;}
- if (text [i] == Mnemonic) {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
- j--;
- }
- }
- while (j < text.length) text [j++] = 0;
- 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);
-}
-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);
- Display display = getDisplay ();
- int pixel = argList1 [1] == OS.XmUNSET ? display.compositeBottomShadow : display.compositeTopShadow;
- int [] argList2 = {OS.XmNtopShadowColor, pixel};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
-}
-int xFocusIn () {
- super.xFocusIn ();
- // 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 () {
- super.xFocusOut ();
- // 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;
-}
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.ARROW) != 0) return;
+ char [] text = new char [string.length ()];
+ string.getChars (0, text.length, text, 0);
+ int i=0, j=0, mnemonic=0;
+ while (i < text.length) {
+ if ((text [j++] = text [i++]) == Mnemonic) {
+ if (i == text.length) {continue;}
+ if (text [i] == Mnemonic) {i++; continue;}
+ if (mnemonic == 0) mnemonic = text [i];
+ j--;
+ }
+ }
+ while (j < text.length) text [j++] = 0;
+ 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);
+}
+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);
+ Display display = getDisplay ();
+ int pixel = argList1 [1] == OS.XmUNSET ? display.compositeBottomShadow : display.compositeTopShadow;
+ int [] argList2 = {OS.XmNtopShadowColor, pixel};
+ OS.XtSetValues (handle, argList2, argList2.length / 2);
+ }
+}
+int xFocusIn () {
+ super.xFocusIn ();
+ // 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 () {
+ super.xFocusOut ();
+ // 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;
+}
} \ No newline at end of file
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
index 3bb6190123..04a8f715d1 100755
--- 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
@@ -1,41 +1,41 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class Canvas extends Composite {
- Caret caret;
-
-Canvas () {
- /* Do nothing */
-}
+
+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.
@@ -64,188 +64,188 @@ Canvas () {
* @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 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;
-}
-
-short [] getIMCaretPos () {
- if (caret == null) return super.getIMCaretPos ();
- int width = caret.width;
- if (width <= 0) width = 2;
- return new short[]{(short) (caret.x + width), (short) (caret.y + caret.height)};
-}
-void redrawWidget (int x, int y, int width, int height, boolean all) {
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- super.redrawWidget (x, y, width, height, all);
- if (isFocus) caret.setFocus ();
-}
-
-void releaseWidget () {
- if (caret != null) caret.releaseResources ();
- caret = null;
- super.releaseWidget();
-}
-
-/**
- * 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 Caret getCaret () {
+ checkWidget();
+ return caret;
+}
+
+short [] getIMCaretPos () {
+ if (caret == null) return super.getIMCaretPos ();
+ int width = caret.width;
+ if (width <= 0) width = 2;
+ return new short[]{(short) (caret.x + width), (short) (caret.y + caret.height)};
+}
+void redrawWidget (int x, int y, int width, int height, boolean all) {
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+ super.redrawWidget (x, y, width, height, all);
+ if (isFocus) caret.setFocus ();
+}
+
+void releaseWidget () {
+ if (caret != null) caret.releaseResources ();
+ caret = null;
+ super.releaseWidget();
+}
+
+/**
+ * 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;
-
- /* Hide the caret */
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
-
- /* Flush outstanding exposes */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- XAnyEvent xEvent = new XAnyEvent ();
- OS.XSync (xDisplay, false); OS.XSync (xDisplay, false);
- while (OS.XCheckWindowEvent (xDisplay, xWindow, OS.ExposureMask, xEvent)) {
- OS.XtDispatchEvent (xEvent);
- }
-
- /* Scroll the window */
- 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);
- }
- }
-
- /* Show the caret */
- 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 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;
+
+ /* Hide the caret */
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+
+ /* Flush outstanding exposes */
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return;
+ XAnyEvent xEvent = new XAnyEvent ();
+ OS.XSync (xDisplay, false); OS.XSync (xDisplay, false);
+ while (OS.XCheckWindowEvent (xDisplay, xWindow, OS.ExposureMask, xEvent)) {
+ OS.XtDispatchEvent (xEvent);
+ }
+
+ /* Scroll the window */
+ 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);
+ }
+ }
+
+ /* Show the caret */
+ 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();
- super.setFont (font);
- if (caret != null) caret.setFont (font);
-}
-void updateCaret () {
- if (caret == null) return;
- if (!OS.IsDBLocale) return;
- short [] point = getIMCaretPos ();
- int ptr = OS.XtMalloc (4);
- OS.memmove (ptr, point, 4);
- int[] argList = {OS.XmNspotLocation, ptr};
- OS.XmImSetValues (handle, argList, argList.length / 2);
- if (ptr != 0) OS.XtFree (ptr);
-}
-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 () {
- int result = super.xFocusIn ();
- if (caret != null) caret.setFocus ();
- return result;
-}
-int xFocusOut () {
- int result = super.xFocusOut ();
- if (caret != null) caret.killFocus ();
- return result;
-}
-}
+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();
+ super.setFont (font);
+ if (caret != null) caret.setFont (font);
+}
+void updateCaret () {
+ if (caret == null) return;
+ if (!OS.IsDBLocale) return;
+ short [] point = getIMCaretPos ();
+ int ptr = OS.XtMalloc (4);
+ OS.memmove (ptr, point, 4);
+ int[] argList = {OS.XmNspotLocation, ptr};
+ OS.XmImSetValues (handle, argList, argList.length / 2);
+ if (ptr != 0) OS.XtFree (ptr);
+}
+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 () {
+ int result = super.xFocusIn ();
+ if (caret != null) caret.setFocus ();
+ return result;
+}
+int xFocusOut () {
+ int result = super.xFocusOut ();
+ 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
index bf3179bf36..cfd6c68efd 100755
--- 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
@@ -1,37 +1,37 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class Caret extends Widget {
- Canvas parent;
- int x, y, width, height;
- boolean isVisible, isShowing;
- int blinkRate = 500;
- Image image;
- Font font;
+
+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 = 500;
+ Image image;
+ Font font;
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -60,424 +60,424 @@ public class Caret extends Widget {
* @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);
- 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 [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int foreground = argList [1];
- int background = argList [3];
- 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);
- int nWidth = width, nHeight = height;
- if (image != null) {
- Rectangle rect = image.getBounds ();
- nWidth = rect.width;
- nHeight = rect.height;
- }
- if (nWidth <= 0) nWidth = 2;
- 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 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;
+ 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 [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int foreground = argList [1];
+ int background = argList [3];
+ 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);
+ int nWidth = width, nHeight = height;
+ if (image != null) {
+ Rectangle rect = image.getBounds ();
+ nWidth = rect.width;
+ nHeight = rect.height;
+ }
+ if (nWidth <= 0) nWidth = 2;
+ 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);
-}
-public Display getDisplay () {
- Composite parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/**
- * 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 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);
+}
+public Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+ * 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 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 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 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 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 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 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;
-}
-void killFocus () {
- Display display = getDisplay ();
- if (display.currentCaret != this) return;
- display.setCurrentCaret (null);
- if (isVisible) hideCaret ();
-}
-void releaseChild () {
- super.releaseChild ();
- 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 boolean isVisible () {
+ checkWidget();
+ return isVisible && parent.isVisible () && parent.hasFocus ();
+}
+boolean isFocusCaret () {
+ Display display = getDisplay ();
+ return this == display.currentCaret;
+}
+void killFocus () {
+ Display display = getDisplay ();
+ if (display.currentCaret != this) return;
+ display.setCurrentCaret (null);
+ if (isVisible) hideCaret ();
+}
+void releaseChild () {
+ super.releaseChild ();
+ 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) hideCaret ();
- this.x = x; this.y = y;
- this.width = width; this.height = height;
- parent.updateCaret ();
- if (isFocus) 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 (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) hideCaret ();
+ this.x = x; this.y = y;
+ this.width = width; this.height = height;
+ parent.updateCaret ();
+ if (isFocus) 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 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;
- if (isVisible && parent.hasFocus()) {
- int handle = parent.handle;
- int [] argList = {OS.XmNfontList, font.handle};
- OS.XmImSetValues (handle, argList, argList.length / 2);
- }
-}
-/**
- * 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 font the new font (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 setFont (Font font) {
+ checkWidget();
+ if (font != null && font.isDisposed ()) {
+ error (SWT.ERROR_INVALID_ARGUMENT);
+ }
+ this.font = font;
+ if (isVisible && parent.hasFocus()) {
+ int handle = parent.handle;
+ int [] argList = {OS.XmNfontList, font.handle};
+ OS.XmImSetValues (handle, argList, argList.length / 2);
+ }
+}
+/**
+ * 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 font the new font (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) hideCaret ();
- this.image = image;
- if (isFocus) 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 setImage (Image image) {
+ checkWidget();
+ if (image != null && image.isDisposed ()) {
+ error (SWT.ERROR_INVALID_ARGUMENT);
+ }
+ boolean isFocus = isFocusCaret ();
+ if (isFocus) hideCaret ();
+ this.image = image;
+ if (isFocus) 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 (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 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
- * @param height the new height 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 (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
+ * @param height the new height 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 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 ();
-}
-}
+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
index 3661875923..0c9ec0e7a3 100755
--- 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
@@ -1,68 +1,68 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-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 boolean okSelected;
- private RGB rgb;
- private int colorDepth; // color depth of the display
- 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 (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
- * @see Widget#checkSubclass
- * @see Widget#getStyle
+
+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 boolean okSelected;
+ private RGB rgb;
+ private int colorDepth; // color depth of the display
+ 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 (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
+ * @see Widget#checkSubclass
+ * @see Widget#getStyle
*/
-public ColorDialog(Shell parent) {
- this(parent, SWT.NULL);
-}
+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.
@@ -91,357 +91,357 @@ public ColorDialog(Shell parent) {
* @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);
-
- int colorChooserWidth = colorSwatchExtent * colorGrid.length;
- int colorChooserHeight = colorSwatchExtent * colorGrid[0].length;
- 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 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);
+
+ int colorChooserWidth = colorSwatchExtent * colorGrid.length;
+ int colorChooserHeight = colorSwatchExtent * colorGrid[0].length;
+ 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.getDisplay();
-
- 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.getDisplay();
- 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.getDisplay();
- 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) { // hack to evenly distribute 256 colors on 32 columns
- blue += iterationStep;
- }
- for (green = 0; green <= 255; green += iterationStep) {
- if (row == 2 || row == 5) { // hack to 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.getDisplay();
- 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
- 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 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.getDisplay();
+
+ 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.getDisplay();
+ 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.getDisplay();
+ 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) { // hack to evenly distribute 256 colors on 32 columns
+ blue += iterationStep;
+ }
+ for (green = 0; green <= 255; green += iterationStep) {
+ if (row == 2 || row == 5) { // hack to 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.getDisplay();
+ 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
+ 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);
- setColorDepth(shell.getDisplay().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.
- Rectangle displayRect = dialog.getDisplay().getBounds();
- int widthLimit = displayRect.width * 7 / 8;
- int heightLimit = displayRect.height * 7 / 8;
- if (pt.x > widthLimit) {
- pt = dialog.computeSize (widthLimit, -1, false);
- }
-
- // centre the dialog on its parent, and ensure that the
- // whole dialog appears within the screen bounds
- Rectangle parentBounds = getParent ().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.getDisplay();
- 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) {
- colorDepth = 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 to select a default when
- * open() is called
- * @see PaletteData#getRGBs
+public RGB open() {
+ shell = new Shell(parent, getStyle() | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
+ setColorDepth(shell.getDisplay().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.
+ Rectangle displayRect = dialog.getDisplay().getBounds();
+ int widthLimit = displayRect.width * 7 / 8;
+ int heightLimit = displayRect.height * 7 / 8;
+ if (pt.x > widthLimit) {
+ pt = dialog.computeSize (widthLimit, -1, false);
+ }
+
+ // centre the dialog on its parent, and ensure that the
+ // whole dialog appears within the screen bounds
+ Rectangle parentBounds = getParent ().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.getDisplay();
+ 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) {
+ colorDepth = 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 to select a default when
+ * open() is called
+ * @see PaletteData#getRGBs
*/
-public void setRGB(RGB rgb) {
- this.rgb = rgb;
-}
-}
+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
index 5c681bcfda..f8a799d641 100755
--- 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
@@ -1,71 +1,71 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-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
+
+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 {
+ /**
+ * 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;
+ 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.
@@ -96,1345 +96,1345 @@ public class Combo extends Composite {
* @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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- *
- * @see #add(String,int)
+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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- *
- * @see #add(String)
+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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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 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 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);
-}
-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 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) {
+ /*
+ * 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) {
- state |= HANDLE;
-
- /*
- * 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);
-}
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 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 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)) {
- Display display = getDisplay ();
- 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 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) {
+ state |= HANDLE;
+
+ /*
+ * 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);
+}
+/**
+ * Cuts the selected text.
+ * <p>
+ * The current selection is first copied to the
+ * clipboard and then deleted from the widget.
+ * </p>
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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)) {
+ Display display = getDisplay ();
+ 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);
- Display display = getDisplay ();
- 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
- * </ul>
+public void deselectAll () {
+ checkWidget();
+ int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ Display display = getDisplay ();
+ 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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 address = OS.XmStringUnparse (
+ ptr,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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 address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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.XtGetValues (listHandleArgs[1], argList, argList.length / 2);
+ int spacing = argList [1], highlight = argList [3];
+ /* Result is from empirical analysis on Linux and AIX */
+ return getFontHeight () + spacing + (2 * highlight);
+}
+/**
+ * Returns an 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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.XtGetValues (listHandleArgs[1], argList, argList.length / 2);
- int spacing = argList [1], highlight = argList [3];
- /* Result is from empirical analysis on Linux and AIX */
- return getFontHeight () + spacing + (2 * highlight);
-}
-/**
- * Returns an 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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 address = OS.XmStringUnparse (
+ ptr,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 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;
+}
+
+String getNameText () {
+ return getText ();
+}
+
+/**
+ * Returns a <code>Point</code> whose x coordinate is the start
+ * of the selection in the receiver's text field, and whose y
+ * coordinate is the end of the selection. The returned values
+ * are zero-relative. An "empty" selection as indicated by
+ * the the x and y coordinates having the same value.
+ *
+ * @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 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 address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 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;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * Returns a <code>Point</code> whose x coordinate is the start
- * of the selection in the receiver's text field, and whose y
- * coordinate is the end of the selection. The returned values
- * are zero-relative. An "empty" selection as indicated by
- * the the x and y coordinates having the same value.
- *
- * @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 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.
+ *
+ * @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 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.
- *
- * @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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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 ();
+ 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>
*/
-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 ();
- 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>
+public int getTextLimit () {
+ checkWidget();
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return OS.XmTextGetMaxLength (argList[1]);
+}
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNselectionCallback, windowProc, SELECTION_CALLBACK);
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ OS.XtAddCallback (argList[1], OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
+ OS.XtAddCallback (argList[1], OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
+ OS.XtAddEventHandler (argList[1], OS.KeyPressMask, false, windowProc, KEY_PRESS);
+ OS.XtAddEventHandler (argList[1], OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
+ OS.XtInsertEventHandler (argList[1], 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 getTextLimit () {
- checkWidget();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return OS.XmTextGetMaxLength (argList[1]);
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = getDisplay ().windowProc;
- OS.XtAddCallback (handle, OS.XmNselectionCallback, windowProc, SELECTION_CALLBACK);
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XtAddCallback (argList[1], OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- OS.XtAddCallback (argList[1], OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddEventHandler (argList[1], OS.KeyPressMask, false, windowProc, KEY_PRESS);
- OS.XtAddEventHandler (argList[1], OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
- OS.XtInsertEventHandler (argList[1], 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
+ * @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
- * @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 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();
- Display display = getDisplay ();
- 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+public void paste () {
+ checkWidget();
+ Display display = getDisplay ();
+ 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</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.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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</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.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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- /*
- * 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 <= start && start < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int newEnd = Math.min (end, argList [1] - 1);
- for (int i = start; i <= newEnd; i++) {
- OS.XmComboBoxDeletePos (handle, start + 1);
- }
- if (end >= argList [1]) error (SWT.ERROR_INVALID_RANGE);
-}
-void register () {
- super.register ();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- WidgetTable.put(argList[1], this);
-}
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+public void remove (int start, int end) {
+ checkWidget();
+ if (start > end) return;
+ /*
+ * 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 <= start && start < argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ int newEnd = Math.min (end, argList [1] - 1);
+ for (int i = start; i <= newEnd; i++) {
+ OS.XmComboBoxDeletePos (handle, start + 1);
+ }
+ if (end >= argList [1]) error (SWT.ERROR_INVALID_RANGE);
+}
+void register () {
+ super.register ();
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ WidgetTable.put(argList[1], this);
+}
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</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.XtGetValues (handle, argList, argList.length / 2);
- int index = OS.XmListItemPos (argList[1], xmString);
-
- OS.XmStringFree (xmString);
- if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT);
- OS.XmComboBoxDeletePos (handle, index);
-}
-/**
- * Removes all of the items from the receiver's list.
- * <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 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.XtGetValues (handle, argList, argList.length / 2);
+ int index = OS.XmListItemPos (argList[1], xmString);
+
+ OS.XmStringFree (xmString);
+ if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT);
+ OS.XmComboBoxDeletePos (handle, index);
+}
+/**
+ * Removes all of the items from the receiver's list.
+ * <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);
-
- Display display = getDisplay ();
- 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 removeAll () {
+ checkWidget();
+ int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0, OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+
+ Display display = getDisplay ();
+ 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 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);
-}
-/**
- * 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 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) {
- int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- Display display = getDisplay ();
- 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;
- }
-}
-byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) {
- /*
- * 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 [] mbcs = super.sendIMKeyEvent (type, xEvent);
- if (mbcs == null || xEvent.keycode != 0) return null;
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int textHandle = argList[1];
- int [] unused = new int [1];
- byte [] buffer = new byte [2];
- int length = OS.XmImMbLookupString (textHandle, xEvent, buffer, buffer.length, unused, unused);
- if (length != 0) return null;
- 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);
- }
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextReplace (textHandle, start [0], end [0], mbcs);
- int position = start [0] + mbcs.length - 1;
- OS.XmTextSetInsertionPosition (textHandle, position);
- display.setWarnings (warnings);
- return mbcs;
-}
-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();
- super.setFont (font);
-
- /*
- * 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 layed out properly by temporarily growing and then shrinking
- * the widget.
- *
- * NOTE: This problem also occurs for simple combo boxes.
- */
- if (OS.XtIsRealized (handle)) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XtResizeWidget (handle, argList [1], argList [3] + 1, argList [5]);
- OS.XtResizeWidget (handle, argList [1], argList [3], argList [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 <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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
- * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</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);
+ Display display = getDisplay ();
+ 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;
+ }
+}
+byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) {
+ /*
+ * 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 [] mbcs = super.sendIMKeyEvent (type, xEvent);
+ if (mbcs == null || xEvent.keycode != 0) return null;
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int textHandle = argList[1];
+ int [] unused = new int [1];
+ byte [] buffer = new byte [2];
+ int length = OS.XmImMbLookupString (textHandle, xEvent, buffer, buffer.length, unused, unused);
+ if (length != 0) return null;
+ 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);
+ }
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextReplace (textHandle, start [0], end [0], mbcs);
+ int position = start [0] + mbcs.length - 1;
+ OS.XmTextSetInsertionPosition (textHandle, position);
+ display.setWarnings (warnings);
+ return mbcs;
+}
+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();
+ super.setFont (font);
+
+ /*
+ * 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 layed out properly by temporarily growing and then shrinking
+ * the widget.
+ *
+ * NOTE: This problem also occurs for simple combo boxes.
+ */
+ if (OS.XtIsRealized (handle)) {
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ OS.XtResizeWidget (handle, argList [1], argList [3] + 1, argList [5]);
+ OS.XtResizeWidget (handle, argList [1], argList [3], argList [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 <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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
+ * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_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];
- if (string == null) break;
- 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);
- Display display = getDisplay ();
- 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 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 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 setItems (String [] items) {
+ checkWidget();
+ if (items == null) error (SWT.ERROR_NULL_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];
+ if (string == null) break;
+ 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);
+ Display display = getDisplay ();
+ 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 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 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();
-
- 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);
- Display display = getDisplay ();
- 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 text 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 setSelection (Point selection) {
+ checkWidget();
+
+ 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);
+ Display display = getDisplay ();
+ 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 text 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. */
- Display display = getDisplay ();
- 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.
- *
- * @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>
+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. */
+ Display display = getDisplay ();
+ 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.
+ *
+ * @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>
*/
-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);
-}
-
-void deregister () {
- super.deregister ();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- WidgetTable.remove (argList[1]);
-}
-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.
+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);
+}
+
+void deregister () {
+ super.deregister ();
+ int [] argList = {OS.XmNtextField, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ WidgetTable.remove (argList[1]);
+}
+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 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 XmNselectionCallback (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 XmNvalueChangedCallback (int w, int client_data, int call_data) {
- sendEvent (SWT.Modify);
- return 0;
-}
-}
+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 XmNselectionCallback (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 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
index 05c80050d1..9c03f3471b 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -34,14 +34,14 @@ import org.eclipse.swt.graphics.*;
*
* @see Canvas
*/
-public class Composite extends Scrollable {
- Layout layout;
- int damagedRegion;
- Control [] tabList;
-
-Composite () {
- /* Do nothing */
-}
+public class Composite extends Scrollable {
+ Layout layout;
+ int damagedRegion;
+ Control [] tabList;
+
+Composite () {
+ /* Do nothing */
+}
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -72,232 +72,232 @@ Composite () {
* @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);
- Control [] children = new Control [count];
- int i = 0, j = 0;
- while (i < count) {
- int handle = handles [i];
- if (handle != 0) {
- Widget widget = WidgetTable.get (handle);
- if (widget != null && widget != this) {
- if (widget instanceof Control) {
- children [j++] = (Control) widget;
- }
- }
- }
- i++;
- }
- 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;
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- Point size;
- if (layout != null) {
- if ((wHint == SWT.DEFAULT) || (hHint == SWT.DEFAULT)) {
- size = layout.computeSize (this, wHint, hHint, 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);
-}
-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;
-}
-protected void checkSubclass () {
- /* Do nothing - Subclassing is allowed */
-}
-void createHandle (int index) {
- state |= HANDLE | CANVAS;
- int parentHandle = parent.handle;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- int border = (style & SWT.BORDER) != 0 ? 1 : 0;
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNborderWidth, border,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
- };
- handle = OS.XmCreateDrawingArea (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- } else {
- createScrolledHandle (parentHandle);
- }
-}
-void createScrolledHandle (int topHandle) {
- int [] argList = {OS.XmNancestorSensitive, 1};
- scrolledHandle = OS.XmCreateMainWindow (topHandle, null, argList, argList.length / 2);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) {
- Display display = getDisplay ();
- int thickness = display.buttonShadowThickness;
- int [] argList1 = {
- OS.XmNmarginWidth, 3,
- OS.XmNmarginHeight, 3,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNshadowType, OS.XmSHADOW_IN,
- OS.XmNshadowThickness, thickness,
- };
- 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,
- };
- handle = OS.XmCreateDrawingArea (formHandle, null, argList2, argList2.length / 2);
- } else {
- int [] argList3 = {
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
- };
- handle = OS.XmCreateDrawingArea (scrolledHandle, null, argList3, argList3.length / 2);
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-int defaultBackground () {
- return getDisplay ().compositeBackground;
-}
-int defaultForeground () {
- return getDisplay ().compositeForeground;
-}
-public boolean forceFocus () {
- checkWidget();
- /*
- * 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 = getDisplay ();
- boolean oldFocusOut = display.postFocusOut;
- Control [] children = _getChildren ();
- int [] traversals = new int [children.length];
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- for (int i=0; i<children.length; i++) {
- int childHandle = children [i].topHandle ();
- OS.XtGetValues (childHandle, argList, argList.length / 2);
- if ((traversals [i] = argList [1]) != 0) {
- argList [1] = 0;
- display.postFocusOut = true;
- OS.XtSetValues (childHandle, argList, argList.length / 2);
- }
- }
- boolean result = super.forceFocus ();
- for (int i=0; i<children.length; i++) {
- argList [1] = traversals [i];
- Control control = children [i];
- if (!control.isDisposed ()) {
- int childHandle = control.topHandle ();
- OS.XtSetValues (childHandle, argList, argList.length / 2);
- if (argList [1] != 0) control.overrideTranslations ();
- }
- }
- display.postFocusOut = oldFocusOut;
- if (!display.postFocusOut) display.runFocusOutEvents ();
- return result;
-}
-/**
- * Returns an array containing the receiver's children.
- * <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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 (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);
+ Control [] children = new Control [count];
+ int i = 0, j = 0;
+ while (i < count) {
+ int handle = handles [i];
+ if (handle != 0) {
+ Widget widget = WidgetTable.get (handle);
+ if (widget != null && widget != this) {
+ if (widget instanceof Control) {
+ children [j++] = (Control) widget;
+ }
+ }
+ }
+ i++;
+ }
+ 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;
+}
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ checkWidget();
+ Point size;
+ if (layout != null) {
+ if ((wHint == SWT.DEFAULT) || (hHint == SWT.DEFAULT)) {
+ size = layout.computeSize (this, wHint, hHint, 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);
+}
+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;
+}
+protected void checkSubclass () {
+ /* Do nothing - Subclassing is allowed */
+}
+void createHandle (int index) {
+ state |= HANDLE | CANVAS;
+ int parentHandle = parent.handle;
+ if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
+ int border = (style & SWT.BORDER) != 0 ? 1 : 0;
+ int [] argList = {
+ OS.XmNancestorSensitive, 1,
+ OS.XmNborderWidth, border,
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
+ };
+ handle = OS.XmCreateDrawingArea (parentHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ } else {
+ createScrolledHandle (parentHandle);
+ }
+}
+void createScrolledHandle (int topHandle) {
+ int [] argList = {OS.XmNancestorSensitive, 1};
+ scrolledHandle = OS.XmCreateMainWindow (topHandle, null, argList, argList.length / 2);
+ if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
+ if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) {
+ Display display = getDisplay ();
+ int thickness = display.buttonShadowThickness;
+ int [] argList1 = {
+ OS.XmNmarginWidth, 3,
+ OS.XmNmarginHeight, 3,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNshadowType, OS.XmSHADOW_IN,
+ OS.XmNshadowThickness, thickness,
+ };
+ 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,
+ };
+ handle = OS.XmCreateDrawingArea (formHandle, null, argList2, argList2.length / 2);
+ } else {
+ int [] argList3 = {
+ OS.XmNmarginWidth, 0,
+ OS.XmNmarginHeight, 0,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
+ };
+ handle = OS.XmCreateDrawingArea (scrolledHandle, null, argList3, argList3.length / 2);
+ }
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+int defaultBackground () {
+ return getDisplay ().compositeBackground;
+}
+int defaultForeground () {
+ return getDisplay ().compositeForeground;
+}
+public boolean forceFocus () {
+ checkWidget();
+ /*
+ * 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 = getDisplay ();
+ boolean oldFocusOut = display.postFocusOut;
+ Control [] children = _getChildren ();
+ int [] traversals = new int [children.length];
+ int [] argList = new int [] {OS.XmNtraversalOn, 0};
+ for (int i=0; i<children.length; i++) {
+ int childHandle = children [i].topHandle ();
+ OS.XtGetValues (childHandle, argList, argList.length / 2);
+ if ((traversals [i] = argList [1]) != 0) {
+ argList [1] = 0;
+ display.postFocusOut = true;
+ OS.XtSetValues (childHandle, argList, argList.length / 2);
+ }
+ }
+ boolean result = super.forceFocus ();
+ for (int i=0; i<children.length; i++) {
+ argList [1] = traversals [i];
+ Control control = children [i];
+ if (!control.isDisposed ()) {
+ int childHandle = control.topHandle ();
+ OS.XtSetValues (childHandle, argList, argList.length / 2);
+ if (argList [1] != 0) control.overrideTranslations ();
+ }
+ }
+ display.postFocusOut = oldFocusOut;
+ if (!display.postFocusOut) display.runFocusOutEvents ();
+ return result;
+}
+/**
+ * Returns an array containing the receiver's children.
+ * <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
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 [] argList = {OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- 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 Control [] getChildren () {
+ checkWidget();
+ return _getChildren ();
+}
+int getChildrenCount () {
+ /*
+ * NOTE: The current implementation will count
+ * non-registered children.
+ * */
+ int [] argList = {OS.XmNnumChildren, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ 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;
-}
+public Layout getLayout () {
+ checkWidget();
+ return layout;
+}
/**
* Gets the last specified tabbing order for the control.
*
@@ -310,235 +310,235 @@ public Layout getLayout () {
*
* @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;
-}
-void hookEvents () {
- super.hookEvents ();
- if ((state & CANVAS) != 0) {
- int windowProc = getDisplay ().windowProc;
- OS.XtInsertEventHandler (handle, 0, true, windowProc, NON_MASKABLE, OS.XtListTail);
- }
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
-}
-
-/**
- * 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 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;
+}
+void hookEvents () {
+ super.hookEvents ();
+ if ((state & CANVAS) != 0) {
+ int windowProc = getDisplay ().windowProc;
+ OS.XtInsertEventHandler (handle, 0, true, windowProc, NON_MASKABLE, OS.XtListTail);
+ }
+}
+
+boolean hooksKeys () {
+ return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
+}
+
+/**
+ * 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 the argument is <code>true</code> the layout must not rely
- * on any cached information it is keeping about the children. If it
- * is <code>false</code> the layout may (potentially) simplify the
- * work it is doing by assuming that the state of the none of the
- * receiver's children has changed since the last layout.
- * If the receiver does not have a layout, do nothing.
- *
- * @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 () {
+ 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 the argument is <code>true</code> the layout must not rely
+ * on any cached information it is keeping about the children. If it
+ * is <code>false</code> the layout may (potentially) simplify the
+ * work it is doing by assuming that the state of the none of the
+ * receiver's children has changed since the last layout.
+ * If the receiver does not have a layout, do nothing.
+ *
+ * @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;
- int count = getChildrenCount ();
- if (count == 0) return;
- layout.layout (this, changed);
-}
-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 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 ();
- }
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_BACKGROUND) == 0 && (style & SWT.NO_REDRAW_RESIZE) != 0) return;
- 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) != 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 redrawWidget (int x, int y, int width, int height, boolean all) {
- super.redrawWidget (x, y, width, height, all);
- if (!all) 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, all);
- }
-}
-void releaseChildren () {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (!child.isDisposed ()) child.releaseResources ();
- }
-}
-void releaseWidget () {
- releaseChildren ();
- super.releaseWidget ();
- layout = null;
- tabList = null;
- if (damagedRegion != 0) OS.XDestroyRegion (damagedRegion);
- damagedRegion = 0;
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_BACKGROUND) != 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 && layout != null) layout.layout (this, false);
- return changed;
-}
-public boolean setFocus () {
- checkWidget ();
- if ((style & SWT.NO_FOCUS) != 0) return false;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.setFocus ()) return true;
- }
- return forceFocus ();
-}
+public void layout (boolean changed) {
+ checkWidget();
+ if (layout == null) return;
+ int count = getChildrenCount ();
+ if (count == 0) return;
+ layout.layout (this, changed);
+}
+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 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 ();
+ }
+ if ((state & CANVAS) != 0) {
+ if ((style & SWT.NO_BACKGROUND) == 0 && (style & SWT.NO_REDRAW_RESIZE) != 0) return;
+ 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) != 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 redrawWidget (int x, int y, int width, int height, boolean all) {
+ super.redrawWidget (x, y, width, height, all);
+ if (!all) 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, all);
+ }
+}
+void releaseChildren () {
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (!child.isDisposed ()) child.releaseResources ();
+ }
+}
+void releaseWidget () {
+ releaseChildren ();
+ super.releaseWidget ();
+ layout = null;
+ tabList = null;
+ if (damagedRegion != 0) OS.XDestroyRegion (damagedRegion);
+ damagedRegion = 0;
+}
+void setBackgroundPixel (int pixel) {
+ super.setBackgroundPixel (pixel);
+ if ((state & CANVAS) != 0) {
+ if ((style & SWT.NO_BACKGROUND) != 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 && layout != null) layout.layout (this, false);
+ return changed;
+}
+public boolean setFocus () {
+ checkWidget ();
+ if ((style & SWT.NO_FOCUS) != 0) return false;
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (child.setFocus ()) return true;
+ }
+ return forceFocus ();
+}
/**
* Sets the layout which is associated with the receiver to be
* the argument which may be null.
@@ -550,182 +550,182 @@ public boolean setFocus () {
* <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;
-}
-/**
- * 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 setLayout (Layout layout) {
+ checkWidget();
+ this.layout = layout;
+}
+/**
+ * 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);
- /*
- * This code is intentionally commented.
- * Tab lists are currently only supported
- * for the direct children of a composite.
- */
-// Shell shell = control.getShell ();
-// while (control != shell && control != this) {
-// control = control.parent;
-// }
-// if (control != this) error (SWT.ERROR_INVALID_PARENT);
- if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- Control [] newList = new Control [tabList.length];
- System.arraycopy (tabList, 0, newList, 0, tabList.length);
- tabList = newList;
- }
- this.tabList = tabList;
-}
-boolean setTabGroupFocus () {
- if (isTabItem ()) return setTabItemFocus ();
- if ((style & SWT.NO_FOCUS) == 0) {
- boolean takeFocus = true;
- 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;
-}
-boolean setTabItemFocus () {
- if ((style & SWT.NO_FOCUS) == 0) {
- boolean takeFocus = true;
- if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
- if (takeFocus) {
- if (!isShowing ()) return false;
- if (forceFocus ()) return true;
- }
- }
- return super.setTabItemFocus ();
-}
-void setScrollbarVisible (int barHandle, boolean visible) {
- /*
- * 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 = getDisplay ();
- boolean oldFocusOut = display.postFocusOut;
- Control [] children = _getChildren ();
- int [] traversals = new int [children.length];
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- for (int i=0; i<children.length; i++) {
- int childHandle = children [i].topHandle ();
- OS.XtGetValues (childHandle, argList, argList.length / 2);
- if ((traversals [i] = argList [1]) != 0) {
- argList [1] = 0;
- display.postFocusOut = true;
- OS.XtSetValues (children [i].handle, argList, argList.length / 2);
- }
- }
- super.setScrollbarVisible(barHandle, visible);
- for (int i=0; i<children.length; i++) {
- argList [1] = traversals [i];
- Control control = children [i];
- if (!control.isDisposed ()) {
- int childHandle = control.topHandle ();
- OS.XtSetValues (childHandle, argList, argList.length / 2);
- if (argList [1] != 0) control.overrideTranslations ();
- }
- }
- display.postFocusOut = oldFocusOut;
- if (!display.postFocusOut) display.runFocusOutEvents ();
-}
-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 (char key, XKeyEvent xEvent) {
- if (super.translateMnemonic (key, xEvent)) return true;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.translateMnemonic (key, xEvent)) return true;
- }
- return false;
-}
-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 ((style & SWT.NO_MERGE_PAINTS) != 0) {
- return super.XExposure (w, client_data, call_data, continue_to_dispatch);
- }
- 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) {
- XAnyEvent xAnyEvent = new XAnyEvent ();
- Display display = getDisplay ();
- display.exposeCount = display.lastExpose = 0;
- int checkExposeProc = display.checkExposeProc;
- OS.XCheckIfEvent (xEvent.display, xAnyEvent, 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);
- }
- }
- }
- if (exposeCount == 0 && damagedRegion == 0) {
- return super.XExposure (w, client_data, call_data, continue_to_dispatch);
- }
- if (damagedRegion == 0) damagedRegion = OS.XCreateRegion ();
- OS.XtAddExposureToRegion (call_data, damagedRegion);
- if (exposeCount != 0) return 0;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return 0;
- Event event = new Event ();
- GC gc = event.gc = new GC (this);
- Region region = Region.motif_new (damagedRegion);
- gc.setClipping (region);
- XRectangle rect = new XRectangle ();
- OS.XClipBox (damagedRegion, rect);
- event.x = rect.x; event.y = rect.y;
- event.width = rect.width; event.height = rect.height;
- sendEvent (SWT.Paint, event);
- gc.dispose ();
- event.gc = null;
- OS.XDestroyRegion (damagedRegion);
- damagedRegion = 0;
- return 0;
-}
-int XNonMaskable (int w, int client_data, int call_data, int continue_to_dispatch) {
- if ((state & CANVAS) != 0) {
- XExposeEvent xEvent = new XExposeEvent ();
- OS.memmove (xEvent, call_data, XExposeEvent.sizeof);
- if (xEvent.type == OS.GraphicsExpose) return XExposure (w, client_data, call_data, continue_to_dispatch);
- }
- return 0;
-}
-}
+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);
+ /*
+ * This code is intentionally commented.
+ * Tab lists are currently only supported
+ * for the direct children of a composite.
+ */
+// Shell shell = control.getShell ();
+// while (control != shell && control != this) {
+// control = control.parent;
+// }
+// if (control != this) error (SWT.ERROR_INVALID_PARENT);
+ if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
+ }
+ Control [] newList = new Control [tabList.length];
+ System.arraycopy (tabList, 0, newList, 0, tabList.length);
+ tabList = newList;
+ }
+ this.tabList = tabList;
+}
+boolean setTabGroupFocus () {
+ if (isTabItem ()) return setTabItemFocus ();
+ if ((style & SWT.NO_FOCUS) == 0) {
+ boolean takeFocus = true;
+ 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;
+}
+boolean setTabItemFocus () {
+ if ((style & SWT.NO_FOCUS) == 0) {
+ boolean takeFocus = true;
+ if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
+ if (takeFocus) {
+ if (!isShowing ()) return false;
+ if (forceFocus ()) return true;
+ }
+ }
+ return super.setTabItemFocus ();
+}
+void setScrollbarVisible (int barHandle, boolean visible) {
+ /*
+ * 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 = getDisplay ();
+ boolean oldFocusOut = display.postFocusOut;
+ Control [] children = _getChildren ();
+ int [] traversals = new int [children.length];
+ int [] argList = new int [] {OS.XmNtraversalOn, 0};
+ for (int i=0; i<children.length; i++) {
+ int childHandle = children [i].topHandle ();
+ OS.XtGetValues (childHandle, argList, argList.length / 2);
+ if ((traversals [i] = argList [1]) != 0) {
+ argList [1] = 0;
+ display.postFocusOut = true;
+ OS.XtSetValues (children [i].handle, argList, argList.length / 2);
+ }
+ }
+ super.setScrollbarVisible(barHandle, visible);
+ for (int i=0; i<children.length; i++) {
+ argList [1] = traversals [i];
+ Control control = children [i];
+ if (!control.isDisposed ()) {
+ int childHandle = control.topHandle ();
+ OS.XtSetValues (childHandle, argList, argList.length / 2);
+ if (argList [1] != 0) control.overrideTranslations ();
+ }
+ }
+ display.postFocusOut = oldFocusOut;
+ if (!display.postFocusOut) display.runFocusOutEvents ();
+}
+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 (char key, XKeyEvent xEvent) {
+ if (super.translateMnemonic (key, xEvent)) return true;
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (child.translateMnemonic (key, xEvent)) return true;
+ }
+ return false;
+}
+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 ((style & SWT.NO_MERGE_PAINTS) != 0) {
+ return super.XExposure (w, client_data, call_data, continue_to_dispatch);
+ }
+ 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) {
+ XAnyEvent xAnyEvent = new XAnyEvent ();
+ Display display = getDisplay ();
+ display.exposeCount = display.lastExpose = 0;
+ int checkExposeProc = display.checkExposeProc;
+ OS.XCheckIfEvent (xEvent.display, xAnyEvent, 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);
+ }
+ }
+ }
+ if (exposeCount == 0 && damagedRegion == 0) {
+ return super.XExposure (w, client_data, call_data, continue_to_dispatch);
+ }
+ if (damagedRegion == 0) damagedRegion = OS.XCreateRegion ();
+ OS.XtAddExposureToRegion (call_data, damagedRegion);
+ if (exposeCount != 0) return 0;
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return 0;
+ Event event = new Event ();
+ GC gc = event.gc = new GC (this);
+ Region region = Region.motif_new (damagedRegion);
+ gc.setClipping (region);
+ XRectangle rect = new XRectangle ();
+ OS.XClipBox (damagedRegion, rect);
+ event.x = rect.x; event.y = rect.y;
+ event.width = rect.width; event.height = rect.height;
+ sendEvent (SWT.Paint, event);
+ gc.dispose ();
+ event.gc = null;
+ OS.XDestroyRegion (damagedRegion);
+ damagedRegion = 0;
+ return 0;
+}
+int XNonMaskable (int w, int client_data, int call_data, int continue_to_dispatch) {
+ if ((state & CANVAS) != 0) {
+ XExposeEvent xEvent = new XExposeEvent ();
+ OS.memmove (xEvent, call_data, XExposeEvent.sizeof);
+ if (xEvent.type == OS.GraphicsExpose) return XExposure (w, client_data, call_data, continue_to_dispatch);
+ }
+ return 0;
+}
+}
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
index 34ec2e8925..818fa23e41 100755
--- 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
@@ -1,45 +1,45 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-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>
- * <dt><b>Events:</b>
- * <dd>FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter,
- * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize</dd>
- * </dl>
- * <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;
- Font font;
- Menu menu;
- String toolTipText;
- Object layoutData;
- Accessible accessible;
-
-Control () {
- /* Do nothing */
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+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>
+ * <dt><b>Events:</b>
+ * <dd>FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter,
+ * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize</dd>
+ * </dl>
+ * <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;
+ Font font;
+ Menu menu;
+ 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.
@@ -68,63 +68,63 @@ Control () {
* @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);
-}
+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,
@@ -144,167 +144,167 @@ public void addFocusListener(FocusListener listener) {
* @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);
-}
+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);
+}
/**
* Returns the preferred size of the receiver.
* <p>
@@ -332,9 +332,9 @@ public void addTraverseListener (TraverseListener listener) {
* @see #pack
* @see "computeTrim, getClientArea for controls that implement them"
*/
-public Point computeSize (int wHint, int hHint) {
- return computeSize (wHint, hHint, true);
-}
+public Point computeSize (int wHint, int hHint) {
+ return computeSize (wHint, hHint, true);
+}
/**
* Returns the preferred size of the receiver.
* <p>
@@ -369,165 +369,165 @@ public Point computeSize (int wHint, int hHint) {
* @see #pack
* @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);
- setParentTraversal ();
-
- /*
- * 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);
- }
-
- /*
- * 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 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.
- */
- Display display = getDisplay ();
- 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 getDisplay ().defaultBackground;
-}
-Font defaultFont () {
- return getDisplay ().defaultFont;
-}
-int defaultForeground () {
- return getDisplay ().defaultForeground;
-}
-void enableWidget (boolean enabled) {
- enableHandle (enabled, handle);
-}
-char findMnemonic (String string) {
- int index = 0;
- int length = string.length ();
- do {
- while (index < length && string.charAt (index) != Mnemonic) index++;
- if (++index >= length) return '\0';
- if (string.charAt (index) != Mnemonic) return string.charAt (index);
- index++;
- } while (index < length);
- return '\0';
-}
-void fixFocus () {
- Shell shell = getShell ();
- Control control = this;
- while ((control = control.parent) != null) {
- if (control.setFocus () || control == shell) return;
- }
-}
-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();
- Decorations shell = menuShell ();
- shell.setSavedFocus (this);
- shell.bringToTop (false);
- return XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT);
-}
-
+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);
+ setParentTraversal ();
+
+ /*
+ * 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);
+ }
+
+ /*
+ * 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 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.
+ */
+ Display display = getDisplay ();
+ 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 getDisplay ().defaultBackground;
+}
+Font defaultFont () {
+ return getDisplay ().defaultFont;
+}
+int defaultForeground () {
+ return getDisplay ().defaultForeground;
+}
+void enableWidget (boolean enabled) {
+ enableHandle (enabled, handle);
+}
+char findMnemonic (String string) {
+ int index = 0;
+ int length = string.length ();
+ do {
+ while (index < length && string.charAt (index) != Mnemonic) index++;
+ if (++index >= length) return '\0';
+ if (string.charAt (index) != Mnemonic) return string.charAt (index);
+ index++;
+ } while (index < length);
+ return '\0';
+}
+void fixFocus () {
+ Shell shell = getShell ();
+ Control control = this;
+ while ((control = control.parent) != null) {
+ if (control.setFocus () || control == shell) return;
+ }
+}
+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();
+ Decorations shell = menuShell ();
+ shell.setSavedFocus (this);
+ shell.bringToTop (false);
+ return XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT);
+}
+
/**
* Returns the accessible object for the receiver.
* If this is the first time this object is requested,
@@ -545,2310 +545,2310 @@ public boolean forceFocus () {
*
* @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();
- return Color.motif_new (getDisplay (), getXColor (getBackgroundPixel ()));
-}
-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 topHandle = topHandle ();
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (topHandle, 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).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Rectangle getBounds () {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- int borders = argList [9] * 2;
- return new Rectangle ((short) argList [1], (short) argList [3], argList [5] + borders, argList [7] + borders);
-}
-Point getClientLocation () {
- short [] handle_x = new short [1], handle_y = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, handle_x, handle_y);
- short [] topHandle_x = new short [1], topHandle_y = new short [1];
- OS.XtTranslateCoords (parent.handle, (short) 0, (short) 0, topHandle_x, topHandle_y);
- return new Point (handle_x [0] - topHandle_x [0], handle_y [0] - topHandle_y [0]);
-}
-String getCodePage () {
- return font.codePage;
-}
-/**
- * Returns the display that the receiver was created on.
- *
- * @return the receiver's 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 Display getDisplay () {
- Composite parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/**
- * 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>
- */
-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 () {
-
- /* Create a font context to iterate over each element in the font list */
- int [] buffer = new int [1];
- if (!OS.XmFontListInitFontContext (buffer, font.handle)) {
- 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);
- int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
- if (fontAscent > ascent) ascent = fontAscent;
- } 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 fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
- if (fontAscent > ascent) ascent = fontAscent;
- }
- }
- }
-
- OS.XmFontListFreeFontContext (context);
- return ascent;
-}
-
-int getFontHeight () {
-
- /* Create a font context to iterate over each element in the font list */
- int [] buffer = new int [1];
- if (!OS.XmFontListInitFontContext (buffer, font.handle)) {
- 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 fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
- int fontDescent = Math.max (fontStruct.descent, fontStruct.max_bounds_descent);
- int fontHeight = fontAscent + fontDescent;
- 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 fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
- int fontDescent = Math.max (fontStruct.descent, fontStruct.max_bounds_descent);
- int fontHeight = fontAscent + fontDescent;
- 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 (getDisplay (), getXColor (getForegroundPixel ()));
-}
-int getForegroundPixel () {
- int [] argList = {OS.XmNforeground, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-short [] getIMCaretPos () {
- return new short[]{0, 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).
- *
- * @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 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 == getDisplay ().getFocusControl ();
-}
-/**
- * Returns true if the widget has native IM support
- */
-boolean hasIMSupport() {
- return false;
-}
-void hookEvents () {
- int windowProc = getDisplay ().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.XtInsertEventHandler (handle, OS.ExposureMask, false, windowProc, EXPOSURE, OS.XtListTail);
- OS.XtInsertEventHandler (handle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
- OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK);
-}
-int hoverProc (int id) {
- return hoverProc (id, true);
-}
-int hoverProc (int id, boolean showTip) {
- Display display = getDisplay ();
- if (showTip) display.showToolTip (handle, toolTipText);
- sendMouseEvent (SWT.MouseHover, 0);
- 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
- *
- * @private
- */
-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);
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNcolormap, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (data != null) {
- data.device = getDisplay ();
- data.display = xDisplay;
- data.drawable = xWindow;
- data.foreground = argList [1];
- data.background = argList [3];
- data.fontList = font.handle;
- data.codePage = font.codePage;
- data.colormap = argList [5];
- }
- 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 handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
- */
-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
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */
-public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-boolean isFocusAncestor () {
- Display display = getDisplay ();
- 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 == 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
- * 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 () {
- OS.XtSetMappedWhenManaged (handle, false);
- /*
- * Feature in Motif. When a widget is managed and an
- * ancestor in the widget hierarchy has focus, Motif
- * assigns focus to another widget in the shell. This
- * happens because Motif does not expect a non-leaf
- * widget to have the focus. The fix is to save the
- * current value of XmNtraversalOn, set the new value
- * to false, then manage the widget and restore the
- * value. This relies on the fact that Motif will
- * not reassign focus when the new widget is not
- * traversable.
- *
- * NOTE: This code currently does not work when a
- * sibling will take focus.
- */
- int topHandle = topHandle ();
- int [] argList1 = {OS.XmNtraversalOn, 0};
- OS.XtGetValues (topHandle, argList1, argList1.length / 2);
- if (argList1 [1] != 0) {
- int [] argList2 = {OS.XmNtraversalOn, 0};
- OS.XtSetValues (topHandle, argList2, argList2.length / 2);
- }
- OS.XtManageChild (handle);
- if (argList1 [1] != 0) {
- OS.XtSetValues (topHandle, argList1, argList1.length / 2);
- }
- overrideTranslations ();
- int [] argList3 = {OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList3, argList3.length / 2);
- OS.XtResizeWidget (handle, 1, 1, argList3 [1]);
- OS.XtSetMappedWhenManaged (handle, true);
-}
-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 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>
- */
-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 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>
- */
-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 () {
- Display display = getDisplay ();
- OS.XtOverrideTranslations (handle, display.tabTranslations);
- OS.XtOverrideTranslations (handle, 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
- */
-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>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
- */
-public void pack (boolean changed) {
- checkWidget();
- setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
-}
-void propagateChildren (boolean enabled) {
- propagateWidget (enabled);
-}
-void propagateWidget (boolean enabled) {
- propagateHandle (enabled, handle);
-}
-void realizeChildren () {
- if (!isEnabled ()) propagateWidget (false);
-}
-/**
- * Causes the entire bounds of the receiver to be marked
- * as needing to be redrawn. The next time a paint request
- * is processed, the control will be completely painted.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
- */
-public void redraw () {
- checkWidget();
- redrawWidget (0, 0, 0, 0, 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. 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
- */
-public void redraw (int x, int y, int width, int height, boolean all) {
- checkWidget ();
- if (width <= 0 || height <= 0) return;
- redrawWidget (x, y, width, height, all);
-}
-void redrawWidget (int x, int y, int width, int height, boolean all) {
- redrawHandle (x, y, width, height, handle);
-}
-void 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);
- }
- super.releaseWidget ();
- Display display = getDisplay ();
- display.releaseToolTipHandle (handle);
- toolTipText = null;
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- menu = null;
- if (!hasIMSupport()) {
- OS.XmImUnregister (handle);
- }
- parent = null;
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 sendHelpEvent (int callData) {
- Control control = this;
- while (control != null) {
- if (control.hooks (SWT.Help)) {
- control.postEvent (SWT.Help);
- return;
- }
- control = control.parent;
- }
-}
-byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) {
- /*
- * 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 length = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, unused, status);
- if (status [0] == OS.XBufferOverflow) {
- buffer = new byte [length];
- length = OS.XmImMbLookupString (handle, xEvent, buffer, length, unused, status);
- }
- if (length == 0) return null;
-
- /* Convert from MBCS to UNICODE and send the event */
- /* Use the character encoding for the default locale */
- char [] result = Converter.mbcsToWcs (null, buffer);
- int index = 0;
- while (index < result.length) {
- if (result [index] == 0) break;
- Event event = new Event ();
- event.time = xEvent.time;
- event.character = result [index];
- setInputState (event, xEvent);
- postEvent (type, event);
- index++;
- }
- return buffer;
-}
-void sendKeyEvent (int type, XKeyEvent xEvent) {
- Event event = new Event ();
- event.time = xEvent.time;
- setKeyState (event, xEvent);
- Control control = this;
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) {
- Display display = getDisplay ();
- control = display.getFocusControl ();
- }
- }
- if (control != null) {
- control.postEvent (type, event);
- }
-}
-void sendMouseEvent (int type, int button) {
- int xDisplay = OS.XtDisplay (handle);
- int 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);
- Event event = new Event ();
- event.x = windowX [0];
- event.y = windowY [0];
- setInputState (event, mask [0]);
- postEvent (type, event);
-}
-void sendMouseEvent (int type, int button, XCrossingEvent xEvent) {
- Event event = new Event ();
- event.time = xEvent.time;
- event.button = button;
- event.x = xEvent.x;
- event.y = xEvent.y;
- int [] unused = new int [1], mask = new int [1];
- OS.XQueryPointer (xEvent.display, xEvent.window, unused, unused, unused, unused, unused, unused, mask);
- setInputState (event, mask [0]);
- postEvent (type, event);
-}
-void sendMouseEvent (int type, int button, XInputEvent xEvent) {
- Event event = new Event ();
- event.time = xEvent.time;
- event.button = button;
- event.x = xEvent.x;
- event.y = xEvent.y;
- setInputState (event, xEvent);
- postEvent (type, event);
-}
-/**
- * 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) {
- setBackgroundPixel (defaultBackground ());
- } else {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- setBackgroundPixel (color.handle.pixel);
- }
-}
-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;
- OS.XtConfigureWidget (topHandle, x, y, width, height, argList [9]);
- if (!sameOrigin) 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);
- 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;
- OS.XtResizeWidget (topHandle, width, height, argList [5]);
- 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).
- * <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);
-}
-/**
- * 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, true, true);
-}
-/**
- * If the argument is <code>true</code>, causes the receiver to have
- * all mouse events delivered to it until the method is called with
- * <code>false</code> as the argument.
- *
- * @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();
- int display = OS.XtDisplay (handle);
- if (display == 0) return;
- int window = OS.XtWindow (handle);
- if (window == 0) {
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
- window = OS.XtWindow (handle);
- if (window == 0) return;
- }
- if (cursor == null) {
- OS.XUndefineCursor (display, window);
- } else {
- if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int xCursor = cursor.handle;
- OS.XDefineCursor (display, window, xCursor);
- OS.XFlush (display);
- }
-}
-/**
- * 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();
- boolean fixFocus = false;
- if (!enabled) fixFocus = isFocusAncestor ();
- enableWidget (enabled);
- if (fixFocus) fixFocus ();
- 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.
- *
- * @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();
- Decorations shell = menuShell ();
- shell.setSavedFocus (this);
- shell.bringToTop (false);
- return XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT);
-}
-/**
- * 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);
- if (!hasIMSupport()) {
- OS.XmImSetValues (handle, argList2, argList2.length / 2);
- }
-
- /* Restore the widget size */
- OS.XtSetValues (handle, argList1, argList1.length / 2);
-}
-/**
- * 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) {
- setForegroundPixel (defaultForeground ());
- } else {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- setForegroundPixel (color.handle.pixel);
- }
-}
-void setForegroundPixel (int pixel) {
- int [] argList = {OS.XmNforeground, pixel};
- OS.XtSetValues (handle, argList, argList.length / 2);
- 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 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).
- *
- * @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 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);
- 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.
- *
- * @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.
- * Answers <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>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
- * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
- * </ul>
- */
-public boolean setParent (Composite parent) {
- checkWidget();
- if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-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.
- * <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
- * @see #update
- */
-public void setRedraw (boolean redraw) {
- checkWidget();
-}
-boolean setTabGroupFocus () {
- return setTabItemFocus ();
-}
-boolean setTabItemFocus () {
- if (!isShowing ()) return false;
- return setFocus ();
-}
-/**
- * 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);
-}
-/**
- * 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
- * @param height the new height 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 display = getDisplay ();
- 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;
- boolean fixFocus = false;
- if (!visible) fixFocus = isFocusAncestor ();
- OS.XtSetMappedWhenManaged (topHandle, visible);
- if (fixFocus) fixFocus ();
- 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;
- if (control == null) {
- 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 topHandle2 = control.topHandle ();
- if (display != OS.XtDisplay (topHandle2)) return;
- if (!OS.XtIsRealized (topHandle2)) {
- Shell shell = control.getShell ();
- shell.realizeWidget ();
- }
- int window2 = OS.XtWindow (topHandle2);
- if (window2 == 0) return;
- XWindowChanges struct = new XWindowChanges ();
- struct.sibling = window2;
- struct.stack_mode = above ? OS.Above : 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);
- }
-}
-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)
- *
- * @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);
-}
-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)
- *
- * @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 (int key, int keysym, XKeyEvent xEvent) {
- return menuShell ().translateAccelerator (key, keysym, xEvent);
-}
-boolean translateMnemonic (char key, XKeyEvent xEvent) {
- if (!isVisible () || !isEnabled ()) return false;
- Event event = new Event();
- event.doit = mnemonicMatch (key);
- event.detail = SWT.TRAVERSE_MNEMONIC;
- event.time = xEvent.time;
- setKeyState (event, xEvent);
- return traverse (event);
-}
-boolean translateMnemonic (int key, XKeyEvent xEvent) {
- if (xEvent.state == 0) {
- int code = traversalCode (key, xEvent);
- if ((code & SWT.TRAVERSE_MNEMONIC) == 0) return false;
- } else {
- if (xEvent.state != OS.Mod1Mask) return false;
- }
- Decorations shell = menuShell ();
- if (shell.isVisible () && shell.isEnabled ()) {
- char ch = mbcsToWcs (key);
- return ch >= 0x20 && shell.translateMnemonic (ch, xEvent);
- }
- 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:
- case OS.XK_Cancel: {
- 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;
- /*
- * NOTE: This code causes Shift+Tab and Ctrl+Tab to
- * always attempt traversal which is not correct.
- * The default should be the same as a plain Tab key.
- * This behavior is currently relied on by StyledText.
- *
- * The correct behavior is to give every key to any
- * control that wants to see every key. The default
- * behavior for a Canvas should be to see every key.
- */
- switch (xEvent.state) {
- case OS.ControlMask:
- case OS.ShiftMask:
- code |= SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT;
- }
- 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;
- /*
- * NOTE: This code causes Ctrl+PgUp and Ctrl+PgDn to always
- * attempt traversal which is not correct. This behavior is
- * currently relied on by StyledText.
- *
- * The correct behavior is to give every key to any
- * control that wants to see every key. The default
- * behavior for a Canvas should be to see every key.
- */
- code |= SWT.TRAVERSE_PAGE_NEXT | SWT.TRAVERSE_PAGE_PREVIOUS;
- 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;
- setKeyState (event, xEvent);
- 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;
- 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 false;
- 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();
- if (!isFocusControl () && !setFocus ()) return false;
- 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 ()) {
- if (!isDisposed () && !isFocusControl ()) 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.
- */
- 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);
-}
-boolean traverseReturn () {
- return false;
-}
-/**
- * Forces all outstanding paint requests for the widget tree
- * 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
- */
-public void update () {
- checkWidget();
- update (false);
-}
-void update (boolean all) {
-// checkWidget();
- if (all) {
- Display display = getDisplay ();
- display.update ();
- } else {
- int display = OS.XtDisplay (handle);
- if (display == 0) return;
- int window = OS.XtWindow (handle);
- if (window == 0) return;
- XAnyEvent event = new XAnyEvent ();
- OS.XSync (display, false); OS.XSync (display, false);
- while (OS.XCheckWindowEvent (display, window, OS.ExposureMask, event)) {
- OS.XtDispatchEvent (event);
- }
- }
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
- Shell shell = getShell ();
- display.hideToolTip ();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- sendMouseEvent (SWT.MouseDown, xEvent.button, xEvent);
- if (xEvent.button == 2 && hooks (SWT.DragDetect)) {
- postEvent (SWT.DragDetect);
- }
- if (xEvent.button == 3 && menu != null) {
- setFocus ();
-// menu.setLocation (xEvent.x_root, xEvent.y_root);
- menu.setVisible (true);
- }
- 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) {
- sendMouseEvent (SWT.MouseDoubleClick, eventButton, xEvent);
- }
- display.lastTime = eventTime == 0 ? 1 : eventTime;
- display.lastButton = eventButton;
-
- /*
- * 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);
- }
- return 0;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
- display.hideToolTip ();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- sendMouseEvent (SWT.MouseUp, xEvent.button, xEvent);
- 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) return 0;
- if (xEvent.subwindow != 0) return 0;
- sendMouseEvent (SWT.MouseEnter, 0, xEvent);
- 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;
- Event event = new Event ();
- event.count = xEvent.count;
- event.x = xEvent.x; event.y = xEvent.y;
- event.width = xEvent.width; event.height = xEvent.height;
- GC gc = event.gc = new GC (this);
- gc.setClipping (event.x, event.y, event.width, event.height);
- sendEvent (SWT.Paint, event);
- if (!gc.isDisposed ()) gc.dispose ();
- event.gc = null;
- 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;
-
- /*
- * Ignore focus change events when the window getting or losing
- * focus is a menu. Because XmGetFocusWidget() does not answer
- * the menu shell (it answers the menu parent), it is necessary
- * to use XGetInputFocus() to get the real X focus window.
- */
- int xDisplay = xEvent.display;
- if (xDisplay == 0) return 0;
- int [] unused = new int [1], xWindow = new int [1];
- OS.XGetInputFocus (xDisplay, xWindow, unused);
- if (xWindow [0] != 0) {
- int widget = OS.XtWindowToWidget (xDisplay, xWindow [0]);
- if (widget != 0 && OS.XtClass (widget) == OS.XmMenuShellWidgetClass ()) return 0;
- }
-
- /* Process the focus change for the widget */
- switch (xEvent.type) {
- case OS.FocusIn: {
- Shell shell = getShell ();
- xFocusIn ();
- // 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: {
- Shell shell = getShell ();
- Display display = getDisplay ();
-
- xFocusOut ();
- // 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 ()) {
- Control control = display.getFocusControl ();
- if (control == null || shell != control.getShell () ) {
- shell.setActiveControl (null);
- }
- }
- break;
- }
- }
- return 0;
-}
-int xFocusIn () {
- sendEvent (SWT.FocusIn);
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if (!hasIMSupport()) {
- if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
- short [] point = getIMCaretPos ();
- int ptr = OS.XtMalloc (4);
- OS.memmove (ptr, point, 4);
- /*
- * Bug in Motif. On Linux Japanese only, XmImSetFocusValues() causes
- * a GP when the XmNfontList resources does not containt a FontSet.
- * The fix is to call XmImSetValues() to set the values and then call
- * XmImSetFocusValues() with no parameters to set the IME focus.
- */
- int[] argList = {
-// OS.XmNforeground, getForegroundPixel(),
-// OS.XmNbackground, getBackgroundPixel(),
- OS.XmNspotLocation, ptr,
- OS.XmNfontList, font.handle,
- };
- OS.XmImSetValues (handle, argList, argList.length / 2);
- OS.XmImSetFocusValues (handle, null, 0);
- if (ptr != 0) OS.XtFree (ptr);
- }
- }
- return 0;
-}
-int xFocusOut () {
- Display display = getDisplay ();
- if (display.postFocusOut) {
- postEvent (SWT.FocusOut);
- } else {
- sendEvent (SWT.FocusOut);
- // widget could be disposed at this point
- if (handle == 0) return 0;
- }
- if (!hasIMSupport()) {
- if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
- OS.XmImUnsetFocus (handle);
- }
- }
- 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);
- if (xEvent.keycode != 0) {
- sendKeyEvent (SWT.KeyDown, xEvent);
- } else {
- sendIMKeyEvent (SWT.KeyDown, xEvent);
- }
- 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) {
- menu.setVisible (true);
- return 0;
- }
- }
- sendKeyEvent (SWT.KeyUp, xEvent);
- return 0;
-}
-int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
- display.removeMouseHoverTimeOut ();
- display.hideToolTip ();
- XCrossingEvent xEvent = new XCrossingEvent ();
- OS.memmove (xEvent, call_data, XCrossingEvent.sizeof);
- if (xEvent.mode != OS.NotifyNormal) return 0;
- if (xEvent.subwindow != 0) return 0;
- sendMouseEvent (SWT.MouseExit, 0, xEvent);
- 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 display = getDisplay ();
- display.addMouseHoverTimeOut (handle);
- XMotionEvent xEvent = new XMotionEvent ();
- OS.memmove (xEvent, call_data, XMotionEvent.sizeof);
- sendMouseEvent (SWT.MouseMove, 0, xEvent);
- return 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();
+ return Color.motif_new (getDisplay (), getXColor (getBackgroundPixel ()));
+}
+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 topHandle = topHandle ();
+ int [] argList = {OS.XmNborderWidth, 0};
+ OS.XtGetValues (topHandle, 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).
+ *
+ * @return the receiver's bounding rectangle
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public Rectangle getBounds () {
+ checkWidget();
+ int topHandle = topHandle ();
+ int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
+ OS.XtGetValues (topHandle, argList, argList.length / 2);
+ int borders = argList [9] * 2;
+ return new Rectangle ((short) argList [1], (short) argList [3], argList [5] + borders, argList [7] + borders);
+}
+Point getClientLocation () {
+ short [] handle_x = new short [1], handle_y = new short [1];
+ OS.XtTranslateCoords (handle, (short) 0, (short) 0, handle_x, handle_y);
+ short [] topHandle_x = new short [1], topHandle_y = new short [1];
+ OS.XtTranslateCoords (parent.handle, (short) 0, (short) 0, topHandle_x, topHandle_y);
+ return new Point (handle_x [0] - topHandle_x [0], handle_y [0] - topHandle_y [0]);
+}
+String getCodePage () {
+ return font.codePage;
+}
+/**
+ * Returns the display that the receiver was created on.
+ *
+ * @return the receiver's 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 Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+ * 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>
+ */
+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 () {
+
+ /* Create a font context to iterate over each element in the font list */
+ int [] buffer = new int [1];
+ if (!OS.XmFontListInitFontContext (buffer, font.handle)) {
+ 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);
+ int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
+ if (fontAscent > ascent) ascent = fontAscent;
+ } 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 fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
+ if (fontAscent > ascent) ascent = fontAscent;
+ }
+ }
+ }
+
+ OS.XmFontListFreeFontContext (context);
+ return ascent;
+}
+
+int getFontHeight () {
+
+ /* Create a font context to iterate over each element in the font list */
+ int [] buffer = new int [1];
+ if (!OS.XmFontListInitFontContext (buffer, font.handle)) {
+ 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 fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
+ int fontDescent = Math.max (fontStruct.descent, fontStruct.max_bounds_descent);
+ int fontHeight = fontAscent + fontDescent;
+ 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 fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
+ int fontDescent = Math.max (fontStruct.descent, fontStruct.max_bounds_descent);
+ int fontHeight = fontAscent + fontDescent;
+ 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 (getDisplay (), getXColor (getForegroundPixel ()));
+}
+int getForegroundPixel () {
+ int [] argList = {OS.XmNforeground, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+short [] getIMCaretPos () {
+ return new short[]{0, 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).
+ *
+ * @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 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 == getDisplay ().getFocusControl ();
+}
+/**
+ * Returns true if the widget has native IM support
+ */
+boolean hasIMSupport() {
+ return false;
+}
+void hookEvents () {
+ int windowProc = getDisplay ().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.XtInsertEventHandler (handle, OS.ExposureMask, false, windowProc, EXPOSURE, OS.XtListTail);
+ OS.XtInsertEventHandler (handle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
+ OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK);
+}
+int hoverProc (int id) {
+ return hoverProc (id, true);
+}
+int hoverProc (int id, boolean showTip) {
+ Display display = getDisplay ();
+ if (showTip) display.showToolTip (handle, toolTipText);
+ sendMouseEvent (SWT.MouseHover, 0);
+ 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
+ *
+ * @private
+ */
+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);
+ int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNcolormap, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (data != null) {
+ data.device = getDisplay ();
+ data.display = xDisplay;
+ data.drawable = xWindow;
+ data.foreground = argList [1];
+ data.background = argList [3];
+ data.fontList = font.handle;
+ data.codePage = font.codePage;
+ data.colormap = argList [5];
+ }
+ 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 handle the platform specific GC handle
+ * @param data the platform specific GC data
+ *
+ * @private
+ */
+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
+ * of the receiver's ancestors are enabled, and <code>false</code>
+ * otherwise. A disabled control is typically not selectable from the
+ * user interface and draws with an inactive or "grayed" look.
+ *
+ * @return the receiver's enabled state
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @see #getEnabled
+ */
+public boolean isEnabled () {
+ checkWidget();
+ return getEnabled () && parent.isEnabled ();
+}
+boolean isFocusAncestor () {
+ Display display = getDisplay ();
+ 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 == 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
+ * 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 () {
+ OS.XtSetMappedWhenManaged (handle, false);
+ /*
+ * Feature in Motif. When a widget is managed and an
+ * ancestor in the widget hierarchy has focus, Motif
+ * assigns focus to another widget in the shell. This
+ * happens because Motif does not expect a non-leaf
+ * widget to have the focus. The fix is to save the
+ * current value of XmNtraversalOn, set the new value
+ * to false, then manage the widget and restore the
+ * value. This relies on the fact that Motif will
+ * not reassign focus when the new widget is not
+ * traversable.
+ *
+ * NOTE: This code currently does not work when a
+ * sibling will take focus.
+ */
+ int topHandle = topHandle ();
+ int [] argList1 = {OS.XmNtraversalOn, 0};
+ OS.XtGetValues (topHandle, argList1, argList1.length / 2);
+ if (argList1 [1] != 0) {
+ int [] argList2 = {OS.XmNtraversalOn, 0};
+ OS.XtSetValues (topHandle, argList2, argList2.length / 2);
+ }
+ OS.XtManageChild (handle);
+ if (argList1 [1] != 0) {
+ OS.XtSetValues (topHandle, argList1, argList1.length / 2);
+ }
+ overrideTranslations ();
+ int [] argList3 = {OS.XmNborderWidth, 0};
+ OS.XtGetValues (handle, argList3, argList3.length / 2);
+ OS.XtResizeWidget (handle, 1, 1, argList3 [1]);
+ OS.XtSetMappedWhenManaged (handle, true);
+}
+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 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>
+ */
+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 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>
+ */
+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 () {
+ Display display = getDisplay ();
+ OS.XtOverrideTranslations (handle, display.tabTranslations);
+ OS.XtOverrideTranslations (handle, 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
+ */
+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>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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
+ */
+public void pack (boolean changed) {
+ checkWidget();
+ setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
+}
+void propagateChildren (boolean enabled) {
+ propagateWidget (enabled);
+}
+void propagateWidget (boolean enabled) {
+ propagateHandle (enabled, handle);
+}
+void realizeChildren () {
+ if (!isEnabled ()) propagateWidget (false);
+}
+/**
+ * Causes the entire bounds of the receiver to be marked
+ * as needing to be redrawn. The next time a paint request
+ * is processed, the control will be completely painted.
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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
+ */
+public void redraw () {
+ checkWidget();
+ redrawWidget (0, 0, 0, 0, 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. 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
+ */
+public void redraw (int x, int y, int width, int height, boolean all) {
+ checkWidget ();
+ if (width <= 0 || height <= 0) return;
+ redrawWidget (x, y, width, height, all);
+}
+void redrawWidget (int x, int y, int width, int height, boolean all) {
+ redrawHandle (x, y, width, height, handle);
+}
+void 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);
+ }
+ super.releaseWidget ();
+ Display display = getDisplay ();
+ display.releaseToolTipHandle (handle);
+ toolTipText = null;
+ if (menu != null && !menu.isDisposed ()) {
+ menu.dispose ();
+ }
+ menu = null;
+ if (!hasIMSupport()) {
+ OS.XmImUnregister (handle);
+ }
+ parent = null;
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 sendHelpEvent (int callData) {
+ Control control = this;
+ while (control != null) {
+ if (control.hooks (SWT.Help)) {
+ control.postEvent (SWT.Help);
+ return;
+ }
+ control = control.parent;
+ }
+}
+byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) {
+ /*
+ * 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 length = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, unused, status);
+ if (status [0] == OS.XBufferOverflow) {
+ buffer = new byte [length];
+ length = OS.XmImMbLookupString (handle, xEvent, buffer, length, unused, status);
+ }
+ if (length == 0) return null;
+
+ /* Convert from MBCS to UNICODE and send the event */
+ /* Use the character encoding for the default locale */
+ char [] result = Converter.mbcsToWcs (null, buffer);
+ int index = 0;
+ while (index < result.length) {
+ if (result [index] == 0) break;
+ Event event = new Event ();
+ event.time = xEvent.time;
+ event.character = result [index];
+ setInputState (event, xEvent);
+ postEvent (type, event);
+ index++;
+ }
+ return buffer;
+}
+void sendKeyEvent (int type, XKeyEvent xEvent) {
+ Event event = new Event ();
+ event.time = xEvent.time;
+ setKeyState (event, xEvent);
+ Control control = this;
+ if ((state & CANVAS) != 0) {
+ if ((style & SWT.NO_FOCUS) != 0) {
+ Display display = getDisplay ();
+ control = display.getFocusControl ();
+ }
+ }
+ if (control != null) {
+ control.postEvent (type, event);
+ }
+}
+void sendMouseEvent (int type, int button) {
+ int xDisplay = OS.XtDisplay (handle);
+ int 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);
+ Event event = new Event ();
+ event.x = windowX [0];
+ event.y = windowY [0];
+ setInputState (event, mask [0]);
+ postEvent (type, event);
+}
+void sendMouseEvent (int type, int button, XCrossingEvent xEvent) {
+ Event event = new Event ();
+ event.time = xEvent.time;
+ event.button = button;
+ event.x = xEvent.x;
+ event.y = xEvent.y;
+ int [] unused = new int [1], mask = new int [1];
+ OS.XQueryPointer (xEvent.display, xEvent.window, unused, unused, unused, unused, unused, unused, mask);
+ setInputState (event, mask [0]);
+ postEvent (type, event);
+}
+void sendMouseEvent (int type, int button, XInputEvent xEvent) {
+ Event event = new Event ();
+ event.time = xEvent.time;
+ event.button = button;
+ event.x = xEvent.x;
+ event.y = xEvent.y;
+ setInputState (event, xEvent);
+ postEvent (type, event);
+}
+/**
+ * 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) {
+ setBackgroundPixel (defaultBackground ());
+ } else {
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ setBackgroundPixel (color.handle.pixel);
+ }
+}
+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;
+ OS.XtConfigureWidget (topHandle, x, y, width, height, argList [9]);
+ if (!sameOrigin) 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);
+ 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;
+ OS.XtResizeWidget (topHandle, width, height, argList [5]);
+ 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).
+ * <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);
+}
+/**
+ * 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, true, true);
+}
+/**
+ * If the argument is <code>true</code>, causes the receiver to have
+ * all mouse events delivered to it until the method is called with
+ * <code>false</code> as the argument.
+ *
+ * @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();
+ int display = OS.XtDisplay (handle);
+ if (display == 0) return;
+ int window = OS.XtWindow (handle);
+ if (window == 0) {
+ if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
+ window = OS.XtWindow (handle);
+ if (window == 0) return;
+ }
+ if (cursor == null) {
+ OS.XUndefineCursor (display, window);
+ } else {
+ if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ int xCursor = cursor.handle;
+ OS.XDefineCursor (display, window, xCursor);
+ OS.XFlush (display);
+ }
+}
+/**
+ * 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();
+ boolean fixFocus = false;
+ if (!enabled) fixFocus = isFocusAncestor ();
+ enableWidget (enabled);
+ if (fixFocus) fixFocus ();
+ 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.
+ *
+ * @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();
+ Decorations shell = menuShell ();
+ shell.setSavedFocus (this);
+ shell.bringToTop (false);
+ return XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT);
+}
+/**
+ * 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);
+ if (!hasIMSupport()) {
+ OS.XmImSetValues (handle, argList2, argList2.length / 2);
+ }
+
+ /* Restore the widget size */
+ OS.XtSetValues (handle, argList1, argList1.length / 2);
+}
+/**
+ * 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) {
+ setForegroundPixel (defaultForeground ());
+ } else {
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ setForegroundPixel (color.handle.pixel);
+ }
+}
+void setForegroundPixel (int pixel) {
+ int [] argList = {OS.XmNforeground, pixel};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ 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 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).
+ *
+ * @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 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);
+ 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.
+ *
+ * @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.
+ * Answers <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>
+ * </ul>
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * </ul>
+ */
+public boolean setParent (Composite parent) {
+ checkWidget();
+ if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ return false;
+}
+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.
+ * <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
+ * @see #update
+ */
+public void setRedraw (boolean redraw) {
+ checkWidget();
+}
+boolean setTabGroupFocus () {
+ return setTabItemFocus ();
+}
+boolean setTabItemFocus () {
+ if (!isShowing ()) return false;
+ return setFocus ();
+}
+/**
+ * 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);
+}
+/**
+ * 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
+ * @param height the new height 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 display = getDisplay ();
+ 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;
+ boolean fixFocus = false;
+ if (!visible) fixFocus = isFocusAncestor ();
+ OS.XtSetMappedWhenManaged (topHandle, visible);
+ if (fixFocus) fixFocus ();
+ 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;
+ if (control == null) {
+ 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 topHandle2 = control.topHandle ();
+ if (display != OS.XtDisplay (topHandle2)) return;
+ if (!OS.XtIsRealized (topHandle2)) {
+ Shell shell = control.getShell ();
+ shell.realizeWidget ();
+ }
+ int window2 = OS.XtWindow (topHandle2);
+ if (window2 == 0) return;
+ XWindowChanges struct = new XWindowChanges ();
+ struct.sibling = window2;
+ struct.stack_mode = above ? OS.Above : 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);
+ }
+}
+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)
+ *
+ * @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);
+}
+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)
+ *
+ * @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 (int key, int keysym, XKeyEvent xEvent) {
+ return menuShell ().translateAccelerator (key, keysym, xEvent);
+}
+boolean translateMnemonic (char key, XKeyEvent xEvent) {
+ if (!isVisible () || !isEnabled ()) return false;
+ Event event = new Event();
+ event.doit = mnemonicMatch (key);
+ event.detail = SWT.TRAVERSE_MNEMONIC;
+ event.time = xEvent.time;
+ setKeyState (event, xEvent);
+ return traverse (event);
+}
+boolean translateMnemonic (int key, XKeyEvent xEvent) {
+ if (xEvent.state == 0) {
+ int code = traversalCode (key, xEvent);
+ if ((code & SWT.TRAVERSE_MNEMONIC) == 0) return false;
+ } else {
+ if (xEvent.state != OS.Mod1Mask) return false;
+ }
+ Decorations shell = menuShell ();
+ if (shell.isVisible () && shell.isEnabled ()) {
+ char ch = mbcsToWcs (key);
+ return ch >= 0x20 && shell.translateMnemonic (ch, xEvent);
+ }
+ 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:
+ case OS.XK_Cancel: {
+ 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;
+ /*
+ * NOTE: This code causes Shift+Tab and Ctrl+Tab to
+ * always attempt traversal which is not correct.
+ * The default should be the same as a plain Tab key.
+ * This behavior is currently relied on by StyledText.
+ *
+ * The correct behavior is to give every key to any
+ * control that wants to see every key. The default
+ * behavior for a Canvas should be to see every key.
+ */
+ switch (xEvent.state) {
+ case OS.ControlMask:
+ case OS.ShiftMask:
+ code |= SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT;
+ }
+ 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;
+ /*
+ * NOTE: This code causes Ctrl+PgUp and Ctrl+PgDn to always
+ * attempt traversal which is not correct. This behavior is
+ * currently relied on by StyledText.
+ *
+ * The correct behavior is to give every key to any
+ * control that wants to see every key. The default
+ * behavior for a Canvas should be to see every key.
+ */
+ code |= SWT.TRAVERSE_PAGE_NEXT | SWT.TRAVERSE_PAGE_PREVIOUS;
+ 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;
+ setKeyState (event, xEvent);
+ 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;
+ 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 false;
+ 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();
+ if (!isFocusControl () && !setFocus ()) return false;
+ 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 ()) {
+ if (!isDisposed () && !isFocusControl ()) 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.
+ */
+ 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);
+}
+boolean traverseReturn () {
+ return false;
+}
+/**
+ * Forces all outstanding paint requests for the widget tree
+ * 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
+ */
+public void update () {
+ checkWidget();
+ update (false);
+}
+void update (boolean all) {
+// checkWidget();
+ if (all) {
+ Display display = getDisplay ();
+ display.update ();
+ } else {
+ int display = OS.XtDisplay (handle);
+ if (display == 0) return;
+ int window = OS.XtWindow (handle);
+ if (window == 0) return;
+ XAnyEvent event = new XAnyEvent ();
+ OS.XSync (display, false); OS.XSync (display, false);
+ while (OS.XCheckWindowEvent (display, window, OS.ExposureMask, event)) {
+ OS.XtDispatchEvent (event);
+ }
+ }
+}
+int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
+ Display display = getDisplay ();
+ Shell shell = getShell ();
+ display.hideToolTip ();
+ XButtonEvent xEvent = new XButtonEvent ();
+ OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
+ sendMouseEvent (SWT.MouseDown, xEvent.button, xEvent);
+ if (xEvent.button == 2 && hooks (SWT.DragDetect)) {
+ postEvent (SWT.DragDetect);
+ }
+ if (xEvent.button == 3 && menu != null) {
+ setFocus ();
+// menu.setLocation (xEvent.x_root, xEvent.y_root);
+ menu.setVisible (true);
+ }
+ 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) {
+ sendMouseEvent (SWT.MouseDoubleClick, eventButton, xEvent);
+ }
+ display.lastTime = eventTime == 0 ? 1 : eventTime;
+ display.lastButton = eventButton;
+
+ /*
+ * 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);
+ }
+ return 0;
+}
+int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
+ Display display = getDisplay ();
+ display.hideToolTip ();
+ XButtonEvent xEvent = new XButtonEvent ();
+ OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
+ sendMouseEvent (SWT.MouseUp, xEvent.button, xEvent);
+ 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) return 0;
+ if (xEvent.subwindow != 0) return 0;
+ sendMouseEvent (SWT.MouseEnter, 0, xEvent);
+ 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;
+ Event event = new Event ();
+ event.count = xEvent.count;
+ event.x = xEvent.x; event.y = xEvent.y;
+ event.width = xEvent.width; event.height = xEvent.height;
+ GC gc = event.gc = new GC (this);
+ gc.setClipping (event.x, event.y, event.width, event.height);
+ sendEvent (SWT.Paint, event);
+ if (!gc.isDisposed ()) gc.dispose ();
+ event.gc = null;
+ 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;
+
+ /*
+ * Ignore focus change events when the window getting or losing
+ * focus is a menu. Because XmGetFocusWidget() does not answer
+ * the menu shell (it answers the menu parent), it is necessary
+ * to use XGetInputFocus() to get the real X focus window.
+ */
+ int xDisplay = xEvent.display;
+ if (xDisplay == 0) return 0;
+ int [] unused = new int [1], xWindow = new int [1];
+ OS.XGetInputFocus (xDisplay, xWindow, unused);
+ if (xWindow [0] != 0) {
+ int widget = OS.XtWindowToWidget (xDisplay, xWindow [0]);
+ if (widget != 0 && OS.XtClass (widget) == OS.XmMenuShellWidgetClass ()) return 0;
+ }
+
+ /* Process the focus change for the widget */
+ switch (xEvent.type) {
+ case OS.FocusIn: {
+ Shell shell = getShell ();
+ xFocusIn ();
+ // 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: {
+ Shell shell = getShell ();
+ Display display = getDisplay ();
+
+ xFocusOut ();
+ // 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 ()) {
+ Control control = display.getFocusControl ();
+ if (control == null || shell != control.getShell () ) {
+ shell.setActiveControl (null);
+ }
+ }
+ break;
+ }
+ }
+ return 0;
+}
+int xFocusIn () {
+ sendEvent (SWT.FocusIn);
+ // widget could be disposed at this point
+ if (handle == 0) return 0;
+ if (!hasIMSupport()) {
+ if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
+ short [] point = getIMCaretPos ();
+ int ptr = OS.XtMalloc (4);
+ OS.memmove (ptr, point, 4);
+ /*
+ * Bug in Motif. On Linux Japanese only, XmImSetFocusValues() causes
+ * a GP when the XmNfontList resources does not containt a FontSet.
+ * The fix is to call XmImSetValues() to set the values and then call
+ * XmImSetFocusValues() with no parameters to set the IME focus.
+ */
+ int[] argList = {
+// OS.XmNforeground, getForegroundPixel(),
+// OS.XmNbackground, getBackgroundPixel(),
+ OS.XmNspotLocation, ptr,
+ OS.XmNfontList, font.handle,
+ };
+ OS.XmImSetValues (handle, argList, argList.length / 2);
+ OS.XmImSetFocusValues (handle, null, 0);
+ if (ptr != 0) OS.XtFree (ptr);
+ }
+ }
+ return 0;
+}
+int xFocusOut () {
+ Display display = getDisplay ();
+ if (display.postFocusOut) {
+ postEvent (SWT.FocusOut);
+ } else {
+ sendEvent (SWT.FocusOut);
+ // widget could be disposed at this point
+ if (handle == 0) return 0;
+ }
+ if (!hasIMSupport()) {
+ if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
+ OS.XmImUnsetFocus (handle);
+ }
+ }
+ 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);
+ if (xEvent.keycode != 0) {
+ sendKeyEvent (SWT.KeyDown, xEvent);
+ } else {
+ sendIMKeyEvent (SWT.KeyDown, xEvent);
+ }
+ 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) {
+ menu.setVisible (true);
+ return 0;
+ }
+ }
+ sendKeyEvent (SWT.KeyUp, xEvent);
+ return 0;
+}
+int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
+ Display display = getDisplay ();
+ display.removeMouseHoverTimeOut ();
+ display.hideToolTip ();
+ XCrossingEvent xEvent = new XCrossingEvent ();
+ OS.memmove (xEvent, call_data, XCrossingEvent.sizeof);
+ if (xEvent.mode != OS.NotifyNormal) return 0;
+ if (xEvent.subwindow != 0) return 0;
+ sendMouseEvent (SWT.MouseExit, 0, xEvent);
+ 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 display = getDisplay ();
+ display.addMouseHoverTimeOut (handle);
+ XMotionEvent xEvent = new XMotionEvent ();
+ OS.memmove (xEvent, call_data, XMotionEvent.sizeof);
+ sendMouseEvent (SWT.MouseMove, 0, xEvent);
+ return 0;
+}
} \ No newline at end of file
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
index 74a4f6e6df..820b62cbe8 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -83,18 +83,18 @@ import org.eclipse.swt.graphics.*;
* @see Shell
* @see SWT
*/
-public class Decorations extends Canvas {
- String label;
- Image image;
- int dialogHandle;
- boolean minimized, maximized;
- Menu menuBar;
- Menu [] menus;
- Control savedFocus;
- Button defaultButton, saveDefault;
-Decorations () {
- /* Do nothing */
-}
+public class Decorations extends Canvas {
+ String label;
+ Image image;
+ 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.
@@ -133,352 +133,352 @@ Decorations () {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Decorations (Composite parent, int style) {
- super (parent, checkStyle (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);
-}
-static int checkStyle (int style) {
- 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);
-}
-
-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 |= HANDLE | CANVAS;
- createScrolledHandle (parent.handle);
-}
-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 Decorations (Composite parent, int style) {
+ super (parent, checkStyle (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);
+}
+static int checkStyle (int style) {
+ 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);
+}
+
+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 |= HANDLE | CANVAS;
+ createScrolledHandle (parent.handle);
+}
+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 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 <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 Image getImage () {
+ checkWidget();
+ return image;
+}
+/**
+ * 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 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 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 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]);
-}
-void releaseHandle () {
- super.releaseHandle ();
- dialogHandle = 0;
-}
-void releaseWidget () {
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) menu.releaseResources ();
- }
- }
- menuBar = null;
- menus = null;
- super.releaseWidget ();
- 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 remove (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.
- *
- * @param the new default button
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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]);
+}
+void releaseHandle () {
+ super.releaseHandle ();
+ dialogHandle = 0;
+}
+void releaseWidget () {
+ if (menus != null) {
+ for (int i=0; i<menus.length; i++) {
+ Menu menu = menus [i];
+ if (menu != null && !menu.isDisposed ()) menu.releaseResources ();
+ }
+ }
+ menuBar = null;
+ menus = null;
+ super.releaseWidget ();
+ 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 remove (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.
+ *
+ * @param the new default button
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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();
- setDefaultButton (button, true);
-}
-void setDefaultButton (Button button, boolean save) {
- if (button == null) {
- if (defaultButton == saveDefault) {
- if (save) saveDefault = null;
- return;
- }
- } else {
- if (button.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- 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 setDefaultButton (Button button) {
+ checkWidget();
+ setDefaultButton (button, true);
+}
+void setDefaultButton (Button button, boolean save) {
+ if (button == null) {
+ if (defaultButton == saveDefault) {
+ if (save) saveDefault = null;
+ return;
+ }
+ } else {
+ if (button.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ 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();
- int pixmap = 0, mask = 0;
- if (image != null) {
- if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- switch (image.type) {
- case SWT.BITMAP:
- pixmap = image.pixmap;
- break;
- case SWT.ICON:
- pixmap = image.pixmap;
- mask = image.mask;
- break;
- default:
- error (SWT.ERROR_INVALID_IMAGE);
- }
- }
- this.image = image;
- int [] argList = {
- OS.XmNiconPixmap, pixmap,
- OS.XmNiconMask, mask,
- };
- int topHandle = topHandle ();
- OS.XtSetValues (topHandle, argList, argList.length / 2);
-}
-/**
- * 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 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 setImage (Image image) {
+ checkWidget();
+ int pixmap = 0, mask = 0;
+ if (image != null) {
+ if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ switch (image.type) {
+ case SWT.BITMAP:
+ pixmap = image.pixmap;
+ break;
+ case SWT.ICON:
+ pixmap = image.pixmap;
+ mask = image.mask;
+ break;
+ default:
+ error (SWT.ERROR_INVALID_IMAGE);
+ }
+ }
+ this.image = image;
+ int [] argList = {
+ OS.XmNiconPixmap, pixmap,
+ OS.XmNiconMask, mask,
+ };
+ int topHandle = topHandle ();
+ OS.XtSetValues (topHandle, argList, argList.length / 2);
+}
+/**
+ * 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 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;
-}
+public void setMaximized (boolean maximized) {
+ checkWidget();
+ this.maximized = maximized;
+}
/**
* Sets the receiver's menu bar to the argument, which
* may be null.
@@ -494,207 +494,207 @@ public void setMaximized (boolean maximized) {
* <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);
- }
- menuBar.removeAccelerators ();
- }
- if (menu != null) {
- if (!isEnabled ()) {
- propagateHandle (false, menu.handle);
- }
- 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 layed 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) layout (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 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 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);
+ }
+ menuBar.removeAccelerators ();
+ }
+ if (menu != null) {
+ if (!isEnabled ()) {
+ propagateHandle (false, menu.handle);
+ }
+ 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 layed 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) layout (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 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 may not be null.
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+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 may not be null.
+ *
+ * @param text the new text
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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;
-}
-boolean translateAccelerator (int key, int keysym, XKeyEvent xEvent) {
- /*
- * 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) {
- if (menuBar != null && menuBar.getEnabled ()) {
- /* Ignore modifiers. */
- switch (keysym) {
- case OS.XK_Control_L:
- case OS.XK_Control_R:
- case OS.XK_Alt_L:
- case OS.XK_Alt_R:
- case OS.XK_Shift_L:
- case OS.XK_Shift_R:
- return false;
- }
-
- /*
- * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not
- * translated correctly by XLookupString(). They are mapped
- * to 0x1005FF10 and 0x1005FF11 respectively. The fix is to
- * look for these values explicitly and correct them.
- */
- if (keysym != 0) {
- switch (keysym) {
- case 0x1005FF10:
- keysym = OS.XK_F11;
- key = 0;
- break;
- case 0x1005FF11:
- keysym = OS.XK_F12;
- key = 0;
- 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 &= 0xFFFF;
- }
-
- /*
- * 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) {
- case OS.XK_ISO_Left_Tab: key = '\t'; break;
- case OS.XK_space: key = ' '; break;
- }
-
- 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);
- }
- }
- 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;
-}
-}
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ label = string;
+}
+boolean translateAccelerator (int key, int keysym, XKeyEvent xEvent) {
+ /*
+ * 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) {
+ if (menuBar != null && menuBar.getEnabled ()) {
+ /* Ignore modifiers. */
+ switch (keysym) {
+ case OS.XK_Control_L:
+ case OS.XK_Control_R:
+ case OS.XK_Alt_L:
+ case OS.XK_Alt_R:
+ case OS.XK_Shift_L:
+ case OS.XK_Shift_R:
+ return false;
+ }
+
+ /*
+ * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not
+ * translated correctly by XLookupString(). They are mapped
+ * to 0x1005FF10 and 0x1005FF11 respectively. The fix is to
+ * look for these values explicitly and correct them.
+ */
+ if (keysym != 0) {
+ switch (keysym) {
+ case 0x1005FF10:
+ keysym = OS.XK_F11;
+ key = 0;
+ break;
+ case 0x1005FF11:
+ keysym = OS.XK_F12;
+ key = 0;
+ 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 &= 0xFFFF;
+ }
+
+ /*
+ * 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) {
+ case OS.XK_ISO_Left_Tab: key = '\t'; break;
+ case OS.XK_space: key = ' '; break;
+ }
+
+ 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);
+ }
+ }
+ 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;
+}
+}
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
index 2ce65c05c3..d83c444350 100755
--- 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
@@ -1,53 +1,53 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class DirectoryDialog extends Dialog {
- String filterPath = "";
- boolean cancel = true;
- String message = "";
-/**
- * Constructs a new instance of this class given only its
- * parent.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
+
+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.
+ * <p>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation.
+ * </p>
+ */
+public class DirectoryDialog extends Dialog {
+ String filterPath = "";
+ boolean cancel = true;
+ String message = "";
+/**
+ * Constructs a new instance of this class given only its
+ * parent.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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);
-}
+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.
@@ -78,241 +78,241 @@ public DirectoryDialog (Shell parent) {
* <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
+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
*/
-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 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 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 () {
-
- /* Get the parent */
- boolean destroyContext;
- Display appContext = Display.getCurrent ();
- if (destroyContext = (appContext == null)) appContext = new Display ();
- int display = appContext.xDisplay;
- int parentHandle = appContext.shellHandle;
- if ((parent != null) && (parent.getDisplay () == appContext)) {
- if (OS.IsAIX) parent.realizeWidget (); /* Fix for bug 17507 */
- parentHandle = parent.shellHandle;
- }
-
- /* 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 = " ";
-
- /* 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);
- int xmStringPtr2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Compute the filter path */
- if (filterPath == null) filterPath = "";
- /* 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, "Selection", true);
- int xmStringPtr4 = OS.XmStringParseText (
- buffer7,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Create the dialog */
- int [] argList1 = {
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL,
- OS.XmNwidth, OS.XDisplayWidth (display, OS.XDefaultScreen (display)) * 4 / 9,
- OS.XmNdialogTitle, xmStringPtr1,
- OS.XmNpattern, xmStringPtr2,
- OS.XmNdirectory, xmStringPtr3,
- OS.XmNpathMode, OS.XmPATH_MODE_FULL,
- OS.XmNfilterLabelString, xmStringPtr4
- };
-
- /*
- * 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 [] argList = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString1
- };
- int textArea = OS.XmCreateLabel(dialog, name, argList, argList.length/2);
- OS.XtManageChild(textArea);
- OS.XmStringFree (xmString1);
-
- /* Hook the callbacks. */
- Callback callback = new Callback (this, "activate", 3);
- int address = callback.getAddress ();
- 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;
- OS.XtManageChild (dialog);
-
- // Should be a pure OS message loop (no SWT AppContext)
- while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
- if (!appContext.readAndDispatch ()) appContext.sleep ();
-
- /* Set the new path, file name and filter. */
- String directoryPath="";
- if (!cancel) {
- int [] argList2 = {OS.XmNdirMask, 0};
- OS.XtGetValues (dialog, argList2, argList2.length / 2);
- int xmString3 = argList2 [1];
- int ptr = OS.XmStringUnparse (
- xmString3,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 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 (length != 0) {
- if (directoryPath.charAt (length -1) == '/') {
- directoryPath = directoryPath.substring (0, length - 1);
- } else {
- if (length > 1 && directoryPath.charAt (length - 2) == '/' && directoryPath.charAt (length - 1) == '*') {
- directoryPath = directoryPath.substring (0, length - 2);
- }
- }
- }
- filterPath = directoryPath;
- }
-
- /* Destroy the dialog and update the display. */
- if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
- if (destroyContext) appContext.dispose ();
- callback.dispose ();
-
- if (cancel) return null;
- return directoryPath;
-}
-/**
- * Sets the path which the dialog will use to filter
- * the directories it shows to the argument, which may be
- * null.
- *
- * @param string the filter path
+public String open () {
+
+ /* Get the parent */
+ boolean destroyContext;
+ Display appContext = Display.getCurrent ();
+ if (destroyContext = (appContext == null)) appContext = new Display ();
+ int display = appContext.xDisplay;
+ int parentHandle = appContext.shellHandle;
+ if ((parent != null) && (parent.getDisplay () == appContext)) {
+ if (OS.IsAIX) parent.realizeWidget (); /* Fix for bug 17507 */
+ parentHandle = parent.shellHandle;
+ }
+
+ /* 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 = " ";
+
+ /* 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);
+ int xmStringPtr2 = OS.XmStringParseText (
+ buffer2,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+
+ /* Compute the filter path */
+ if (filterPath == null) filterPath = "";
+ /* 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, "Selection", true);
+ int xmStringPtr4 = OS.XmStringParseText (
+ buffer7,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+
+ /* Create the dialog */
+ int [] argList1 = {
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL,
+ OS.XmNwidth, OS.XDisplayWidth (display, OS.XDefaultScreen (display)) * 4 / 9,
+ OS.XmNdialogTitle, xmStringPtr1,
+ OS.XmNpattern, xmStringPtr2,
+ OS.XmNdirectory, xmStringPtr3,
+ OS.XmNpathMode, OS.XmPATH_MODE_FULL,
+ OS.XmNfilterLabelString, xmStringPtr4
+ };
+
+ /*
+ * 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 [] argList = {
+ OS.XmNlabelType, OS.XmSTRING,
+ OS.XmNlabelString, xmString1
+ };
+ int textArea = OS.XmCreateLabel(dialog, name, argList, argList.length/2);
+ OS.XtManageChild(textArea);
+ OS.XmStringFree (xmString1);
+
+ /* Hook the callbacks. */
+ Callback callback = new Callback (this, "activate", 3);
+ int address = callback.getAddress ();
+ 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;
+ OS.XtManageChild (dialog);
+
+ // Should be a pure OS message loop (no SWT AppContext)
+ while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
+ if (!appContext.readAndDispatch ()) appContext.sleep ();
+
+ /* Set the new path, file name and filter. */
+ String directoryPath="";
+ if (!cancel) {
+ int [] argList2 = {OS.XmNdirMask, 0};
+ OS.XtGetValues (dialog, argList2, argList2.length / 2);
+ int xmString3 = argList2 [1];
+ int ptr = OS.XmStringUnparse (
+ xmString3,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 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 (length != 0) {
+ if (directoryPath.charAt (length -1) == '/') {
+ directoryPath = directoryPath.substring (0, length - 1);
+ } else {
+ if (length > 1 && directoryPath.charAt (length - 2) == '/' && directoryPath.charAt (length - 1) == '*') {
+ directoryPath = directoryPath.substring (0, length - 2);
+ }
+ }
+ }
+ filterPath = directoryPath;
+ }
+
+ /* Destroy the dialog and update the display. */
+ if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
+ if (destroyContext) appContext.dispose ();
+ callback.dispose ();
+
+ if (cancel) return null;
+ return directoryPath;
+}
+/**
+ * Sets the path which the dialog will use to filter
+ * the directories it shows to the argument, which may be
+ * null.
+ *
+ * @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
+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
*/
-public void setMessage (String string) {
- message = string;
-}
-}
+public void setMessage (String string) {
+ 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
index fba8edb639..389bbf0213 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -87,2266 +87,2266 @@ import org.eclipse.swt.graphics.*;
* @see #sleep
* @see #dispose
*/
-public class Display extends Device {
-
- /* Motif Only Public Fields */
- public XAnyEvent xEvent = new XAnyEvent ();
- int lastSerial;
-
- /* Windows, Events and Callbacks */
- Callback windowCallback;
- int windowProc, shellHandle;
- static boolean XtInitialized;
- static Object XInitLock = new Object ();
- static String APP_NAME = "SWT";
- byte [] displayName, appName, appClass;
- Event [] eventQueue;
- XKeyEvent keyEvent = new XKeyEvent ();
- EventTable eventTable, filterTable;
- boolean postFocusOut;
-
- /* Default Fonts, Colors, Insets, Widths and Heights. */
- Font defaultFont;
- Font listFont, textFont, buttonFont, labelFont;
- int dialogBackground, dialogForeground;
- int buttonBackground, buttonForeground, buttonShadowThickness;
- int compositeBackground, compositeForeground;
- int compositeTopShadow, compositeBottomShadow, compositeBorder;
- int listBackground, listForeground, listSelect, textBackground, textForeground;
- int labelBackground, labelForeground, scrollBarBackground, scrollBarForeground;
- int scrolledInsetX, scrolledInsetY, scrolledMarginX, scrolledMarginY;
- int defaultBackground, defaultForeground;
- int textHighlightThickness;
-
- /* 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;
-
- /* 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;
-
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer = new Synchronizer (this);
- Thread thread;
-
- /* Display Shutdown */
- Runnable [] disposeList;
-
- /* 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_Shift_L, SWT.SHIFT},
- {OS.XK_Shift_R, SWT.SHIFT},
- {OS.XK_Control_L, SWT.CONTROL},
- {OS.XK_Control_R, SWT.CONTROL},
-
-// {OS.VK_LBUTTON, SWT.BUTTON1},
-// {OS.VK_MBUTTON, SWT.BUTTON3},
-// {OS.VK_RBUTTON, SWT.BUTTON2},
-
- /* Non-Numeric Keypad Keys */
- {OS.XK_Up, SWT.ARROW_UP},
- {OS.XK_Down, SWT.ARROW_DOWN},
- {OS.XK_Left, SWT.ARROW_LEFT},
- {OS.XK_Right, SWT.ARROW_RIGHT},
- {OS.XK_Page_Up, SWT.PAGE_UP},
- {OS.XK_Page_Down, SWT.PAGE_DOWN},
- {OS.XK_Home, SWT.HOME},
- {OS.XK_End, SWT.END},
- {OS.XK_Insert, SWT.INSERT},
-
- /* Virtual and Ascii Keys */
- {OS.XK_BackSpace, SWT.BS},
- {OS.XK_Return, SWT.CR},
- {OS.XK_KP_Enter, SWT.CR},
- {OS.XK_Delete, SWT.DEL},
- {OS.XK_Escape, SWT.ESC},
- {OS.XK_Cancel, 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},
-
- /* Numeric Keypad Constants */
- /*
- {OS.XK_KP_Add, SWT.KP_PLUS},
- {OS.XK_KP_Subtract, SWT.KP_MINUS},
- {OS.XK_KP_Multiply, SWT.KP_TIMES},
- {OS.XK_KP_Divide, SWT.KP_DIVIDE},
- {OS.XK_KP_Decimal, SWT.KP_PERIOD},
- {OS.XK_KP_Enter, SWT.KP_ENTER},
- {OS.XK_KP_0, SWT.KP_0},
- {OS.XK_KP_1, SWT.KP_1},
- {OS.XK_KP_2, SWT.KP_2},
- {OS.XK_KP_3, SWT.KP_3},
- {OS.XK_KP_4, SWT.KP_4},
- {OS.XK_KP_5, SWT.KP_5},
- {OS.XK_KP_6, SWT.KP_6},
- {OS.XK_KP_7, SWT.KP_7},
- {OS.XK_KP_8, SWT.KP_8},
- {OS.XK_KP_9, SWT.KP_9},
- */
- };
-
- /* 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);
-// }
-
- /* 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 ();
-
- /* 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 not called from the thread that created the parent</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 class Display extends Device {
+
+ /* Motif Only Public Fields */
+ public XAnyEvent xEvent = new XAnyEvent ();
+ int lastSerial;
+
+ /* Windows, Events and Callbacks */
+ Callback windowCallback;
+ int windowProc, shellHandle;
+ static boolean XtInitialized;
+ static Object XInitLock = new Object ();
+ static String APP_NAME = "SWT";
+ byte [] displayName, appName, appClass;
+ Event [] eventQueue;
+ XKeyEvent keyEvent = new XKeyEvent ();
+ EventTable eventTable, filterTable;
+ boolean postFocusOut;
+
+ /* Default Fonts, Colors, Insets, Widths and Heights. */
+ Font defaultFont;
+ Font listFont, textFont, buttonFont, labelFont;
+ int dialogBackground, dialogForeground;
+ int buttonBackground, buttonForeground, buttonShadowThickness;
+ int compositeBackground, compositeForeground;
+ int compositeTopShadow, compositeBottomShadow, compositeBorder;
+ int listBackground, listForeground, listSelect, textBackground, textForeground;
+ int labelBackground, labelForeground, scrollBarBackground, scrollBarForeground;
+ int scrolledInsetX, scrolledInsetY, scrolledMarginX, scrolledMarginY;
+ int defaultBackground, defaultForeground;
+ int textHighlightThickness;
+
+ /* 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;
+
+ /* 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;
+
+ /* Sync/Async Widget Communication */
+ Synchronizer synchronizer = new Synchronizer (this);
+ Thread thread;
+
+ /* Display Shutdown */
+ Runnable [] disposeList;
+
+ /* 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_Shift_L, SWT.SHIFT},
+ {OS.XK_Shift_R, SWT.SHIFT},
+ {OS.XK_Control_L, SWT.CONTROL},
+ {OS.XK_Control_R, SWT.CONTROL},
+
+// {OS.VK_LBUTTON, SWT.BUTTON1},
+// {OS.VK_MBUTTON, SWT.BUTTON3},
+// {OS.VK_RBUTTON, SWT.BUTTON2},
+
+ /* Non-Numeric Keypad Keys */
+ {OS.XK_Up, SWT.ARROW_UP},
+ {OS.XK_Down, SWT.ARROW_DOWN},
+ {OS.XK_Left, SWT.ARROW_LEFT},
+ {OS.XK_Right, SWT.ARROW_RIGHT},
+ {OS.XK_Page_Up, SWT.PAGE_UP},
+ {OS.XK_Page_Down, SWT.PAGE_DOWN},
+ {OS.XK_Home, SWT.HOME},
+ {OS.XK_End, SWT.END},
+ {OS.XK_Insert, SWT.INSERT},
+
+ /* Virtual and Ascii Keys */
+ {OS.XK_BackSpace, SWT.BS},
+ {OS.XK_Return, SWT.CR},
+ {OS.XK_KP_Enter, SWT.CR},
+ {OS.XK_Delete, SWT.DEL},
+ {OS.XK_Escape, SWT.ESC},
+ {OS.XK_Cancel, 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},
+
+ /* Numeric Keypad Constants */
+ /*
+ {OS.XK_KP_Add, SWT.KP_PLUS},
+ {OS.XK_KP_Subtract, SWT.KP_MINUS},
+ {OS.XK_KP_Multiply, SWT.KP_TIMES},
+ {OS.XK_KP_Divide, SWT.KP_DIVIDE},
+ {OS.XK_KP_Decimal, SWT.KP_PERIOD},
+ {OS.XK_KP_Enter, SWT.KP_ENTER},
+ {OS.XK_KP_0, SWT.KP_0},
+ {OS.XK_KP_1, SWT.KP_1},
+ {OS.XK_KP_2, SWT.KP_2},
+ {OS.XK_KP_3, SWT.KP_3},
+ {OS.XK_KP_4, SWT.KP_4},
+ {OS.XK_KP_5, SWT.KP_5},
+ {OS.XK_KP_6, SWT.KP_6},
+ {OS.XK_KP_7, SWT.KP_7},
+ {OS.XK_KP_8, SWT.KP_8},
+ {OS.XK_KP_9, SWT.KP_9},
+ */
+ };
+
+ /* 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);
+// }
+
+ /* 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 ();
+
+ /* 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 not called from the thread that created the parent</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);
-}
-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 (!isValidThread ()) 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;
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notifed when an event of the given type occurs anywhere
- * in SWT. When the event does occur, 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>
- * </ul>
- *
- * @see Listener
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 2.1
- */
-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 notifed when an event of the given type occurs. 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>
- * </ul>
- *
- * @see Listener
- * @see #removeListener
- *
- * @since 2.0
+public Display () {
+ this (null);
+}
+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 (!isValidThread ()) 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;
+}
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notifed when an event of the given type occurs anywhere
+ * in SWT. When the event does occur, 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>
+ * </ul>
+ *
+ * @see Listener
+ * @see #removeFilter
+ * @see #removeListener
+ *
+ * @since 2.1
*/
-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.
- *
- * @param runnable code to run on the user-interface thread.
- *
- * @see #syncExec
+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 notifed when an event of the given type occurs. 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>
+ * </ul>
+ *
+ * @see Listener
+ * @see #removeListener
+ *
+ * @since 2.0
*/
-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).
+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.
+ *
+ * @param runnable code to run on the user-interface thread.
+ *
+ * @see #syncExec
*/
-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;
- 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) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] != null && Displays [i].thread == thread) {
- SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
-}
-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>
- * </ul>
- *
- * @see #dispose
- *
- * @since 2.0
+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).
*/
-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 ();
-}
-protected void create (DeviceData data) {
- checkSubclass ();
- checkDisplay (thread = Thread.currentThread ());
- createDisplay (data);
- register (this);
- if (Default == null) Default = this;
-}
-void createDisplay (DeviceData data) {
-
- /* Initialize X and Xt */
- synchronized (XInitLock) {
- if (!XtInitialized) {
- /*
- * This code is intentionally commented.
- */
-// OS.XInitThreads ();
-// OS.XtToolkitThreadInitialize ();
- OS.XtToolkitInitialize ();
- }
- XtInitialized = true;
- }
-
- /* Create the AppContext */
- int [] argc = new int [] {0};
- int xtContext = OS.XtCreateApplicationContext ();
- OS.XtSetLanguageProc (xtContext, 0, 0);
-
- /*
- * Feature in Linux. On some DBCS Linux platforms, the default
- * font is not be properly initialized to contain a font set.
- * This causes the IME to fail. The fix is to set a fallback
- * resource with an appropriated font to ensure a font set is
- * found. */
- int ptr1 = 0, ptr2 = 0;
- if (OS.IsLinux && OS.IsDBLocale) {
- String resource = "*fontList: -*-*-medium-r-*-*-*-120-*-*-*-*-*-*:";
- 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);
-}
-synchronized static void deregister (Display display) {
- for (int i=0; i<Displays.length; i++) {
- if (display == Displays [i]) Displays [i] = null;
- }
-}
-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:
- *
- * int xContext = OS.XtCreateApplicationContext();
- * int xDisplay = OS.XtOpenDisplay(xContext, null, null, null, null, 0, new int[1], null);
- * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0);
- * OS.XtDestroyApplicationContext(xContext);
- * xContext = OS.XtCreateApplicationContext();
- * xDisplay = OS.XtOpenDisplay(xContext, null, null, null, null, 0, new int[1], null);
- * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0);
- * OS.XtDestroyApplicationContext(xContext);
- */
- 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.
- *
- * @param runnable code to run at dispose time.
+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;
+ 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) {
+ for (int i=0; i<Displays.length; i++) {
+ if (Displays [i] != null && Displays [i].thread == thread) {
+ SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ }
+ }
+}
+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>
+ * </ul>
+ *
+ * @see #dispose
+ *
+ * @since 2.0
*/
-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 (XAnyEvent event) {
-
- /* Check the event and find the widget */
- if (event.type != OS.KeyPress) return false;
- OS.memmove (keyEvent, event, XKeyEvent.sizeof);
- 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 = WidgetTable.get (handle);
- if (widget == null) return false;
-
- /* Get the unaffected character and keysym */
- int oldState = keyEvent.state;
- keyEvent.state = 0;
- byte [] buffer1 = new byte [4];
- int [] buffer2 = new int [1];
- int key = 0;
- if (OS.XLookupString (keyEvent, buffer1, 1, buffer2, null) != 0) {
- key = buffer1 [0] & 0xFF;
- }
- int keysym = buffer2 [0] & 0xFFFF;
- keyEvent.state = oldState;
-
- /*
- * 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 == OS.XK_Return || keysym == 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 (event.serial != lastSerial) {
- if (OS.XFilterEvent (event, OS.XtWindow (handle))) return true;
- lastSerial = event.serial;
- }
- }
-
- /* Check for an accelerator key */
- if (widget.translateAccelerator (key, keysym, keyEvent)) return true;
-
- /* Check for a mnemonic key */
- if (key != 0) {
- if (widget.translateMnemonic (key, keyEvent)) return true;
- }
-
- /* Check for a traversal key */
- if (keysym == 0) return false;
- switch (keysym) {
- case OS.XK_Escape:
- case OS.XK_Cancel:
- 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 (widget.translateTraversal (keysym, 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.
- *
- * @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>
- * </ul>
+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 ();
+}
+protected void create (DeviceData data) {
+ checkSubclass ();
+ checkDisplay (thread = Thread.currentThread ());
+ createDisplay (data);
+ register (this);
+ if (Default == null) Default = this;
+}
+void createDisplay (DeviceData data) {
+
+ /* Initialize X and Xt */
+ synchronized (XInitLock) {
+ if (!XtInitialized) {
+ /*
+ * This code is intentionally commented.
+ */
+// OS.XInitThreads ();
+// OS.XtToolkitThreadInitialize ();
+ OS.XtToolkitInitialize ();
+ }
+ XtInitialized = true;
+ }
+
+ /* Create the AppContext */
+ int [] argc = new int [] {0};
+ int xtContext = OS.XtCreateApplicationContext ();
+ OS.XtSetLanguageProc (xtContext, 0, 0);
+
+ /*
+ * Feature in Linux. On some DBCS Linux platforms, the default
+ * font is not be properly initialized to contain a font set.
+ * This causes the IME to fail. The fix is to set a fallback
+ * resource with an appropriated font to ensure a font set is
+ * found. */
+ int ptr1 = 0, ptr2 = 0;
+ if (OS.IsLinux && OS.IsDBLocale) {
+ String resource = "*fontList: -*-*-medium-r-*-*-*-120-*-*-*-*-*-*:";
+ 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);
+}
+synchronized static void deregister (Display display) {
+ for (int i=0; i<Displays.length; i++) {
+ if (display == Displays [i]) Displays [i] = null;
+ }
+}
+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:
+ *
+ * int xContext = OS.XtCreateApplicationContext();
+ * int xDisplay = OS.XtOpenDisplay(xContext, null, null, null, null, 0, new int[1], null);
+ * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0);
+ * OS.XtDestroyApplicationContext(xContext);
+ * xContext = OS.XtCreateApplicationContext();
+ * xDisplay = OS.XtOpenDisplay(xContext, null, null, null, null, 0, new int[1], null);
+ * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0);
+ * OS.XtDestroyApplicationContext(xContext);
+ */
+ 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.
+ *
+ * @param runnable code to run at dispose time.
*/
-public Widget findWidget (int handle) {
- checkDevice ();
- return WidgetTable.get (handle);
-}
-/**
- * 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>
- * </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 (XAnyEvent event) {
+
+ /* Check the event and find the widget */
+ if (event.type != OS.KeyPress) return false;
+ OS.memmove (keyEvent, event, XKeyEvent.sizeof);
+ 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 = WidgetTable.get (handle);
+ if (widget == null) return false;
+
+ /* Get the unaffected character and keysym */
+ int oldState = keyEvent.state;
+ keyEvent.state = 0;
+ byte [] buffer1 = new byte [4];
+ int [] buffer2 = new int [1];
+ int key = 0;
+ if (OS.XLookupString (keyEvent, buffer1, 1, buffer2, null) != 0) {
+ key = buffer1 [0] & 0xFF;
+ }
+ int keysym = buffer2 [0] & 0xFFFF;
+ keyEvent.state = oldState;
+
+ /*
+ * 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 == OS.XK_Return || keysym == 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 (event.serial != lastSerial) {
+ if (OS.XFilterEvent (event, OS.XtWindow (handle))) return true;
+ lastSerial = event.serial;
+ }
+ }
+
+ /* Check for an accelerator key */
+ if (widget.translateAccelerator (key, keysym, keyEvent)) return true;
+
+ /* Check for a mnemonic key */
+ if (key != 0) {
+ if (widget.translateMnemonic (key, keyEvent)) return true;
+ }
+
+ /* Check for a traversal key */
+ if (keysym == 0) return false;
+ switch (keysym) {
+ case OS.XK_Escape:
+ case OS.XK_Cancel:
+ 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 (widget.translateTraversal (keysym, 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.
+ *
+ * @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>
+ * </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 = WidgetTable.get (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 Widget findWidget (int handle) {
+ checkDevice ();
+ return WidgetTable.get (handle);
+}
+/**
+ * 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>
+ * </ul>
*/
-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.
- *
- * @param thread the user-interface thread
- * @return the display for the given thread
+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 = WidgetTable.get (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 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 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>
- * </ul>
+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.
+ *
+ * @param thread the user-interface thread
+ * @return the display for the given thread
*/
-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 = WidgetTable.get (handle);
- if (widget != null && widget instanceof Control) {
- Control control = (Control) widget;
- if (control.getEnabled ()) 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>
- * </ul>
+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 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>
+ * </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 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 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 = WidgetTable.get (handle);
+ if (widget != null && widget instanceof Control) {
+ Control control = (Control) widget;
+ if (control.getEnabled ()) 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>
+ * </ul>
*/
-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 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>
- * </ul>
- *
- * @see #setData
- * @see #disposeExec
+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 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 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 provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @return the display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #setData
- * @see #disposeExec
+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 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>
+ * </ul>
+ *
+ * @see #setData
+ * @see #disposeExec
*/
-public Object getData () {
- checkDevice ();
- return data;
-}
-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>
- * </ul>
+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 provide a
+ * <code>disposeExec()</code> handler which does so.
+ * </p>
+ *
+ * @return the display specific data
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
+ * </ul>
+ *
+ * @see #setData
+ * @see #disposeExec
*/
-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>
- * </ul>
+public Object getData () {
+ checkDevice ();
+ return data;
+}
+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>
+ * </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 = WidgetTable.get (handle);
- if (widget != null && widget instanceof Control) {
- Control window = (Control) widget;
- if (window.getEnabled ()) return window;
- }
- } while ((handle = OS.XtParent (handle)) != 0);
- return null;
-}
-/**
- * Returns the maximum allowed depth of icons on this display.
- * 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>
- * </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>
+ * </ul>
*/
-public int getIconDepth () {
- return getDepth ();
-}
-int getLastEventTime () {
- return OS.XtLastTimestampProcessed (xDisplay);
-}
-/**
- * Returns an 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>
- * </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 = WidgetTable.get (handle);
+ if (widget != null && widget instanceof Control) {
+ Control window = (Control) widget;
+ if (window.getEnabled ()) return window;
+ }
+ } while ((handle = OS.XtParent (handle)) != 0);
+ return null;
+}
+/**
+ * Returns the maximum allowed depth of icons on this display.
+ * 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>
+ * </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.getDisplay ()) {
- 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.getDisplay ()) {
- result [index++] = shell;
- }
- }
- 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
+public int getIconDepth () {
+ return getDepth ();
+}
+int getLastEventTime () {
+ return OS.XtLastTimestampProcessed (xDisplay);
+}
+/**
+ * Returns an 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>
+ * </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>
- * </ul>
- *
- * @see SWT
+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.getDisplay ()) {
+ 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.getDisplay ()) {
+ result [index++] = shell;
+ }
+ }
+ 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
*/
-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 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>
- * </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>
+ * </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 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>
+ * </ul>
*/
-public Font getSystemFont () {
- checkDevice ();
- return defaultFont;
-}
-/**
- * Returns the user-interface thread for the receiver.
- *
- * @return the receiver's user-interface thread
+public Font getSystemFont () {
+ checkDevice ();
+ return defaultFont;
+}
+/**
+ * Returns the user-interface thread for the receiver.
+ *
+ * @return the receiver's user-interface thread
*/
-public Thread getThread () {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return thread;
-}
-void hideToolTip () {
- if (toolTipHandle != 0) {
- int shellHandle = OS.XtParent(toolTipHandle);
- OS.XtDestroyWidget(shellHandle);
- }
- toolTipHandle = 0;
-}
-protected void init () {
- super.init ();
- initializeDisplay ();
- initializeButton ();
- initializeComposite ();
- initializeDialog ();
- initializeLabel ();
- initializeList ();
- initializeScrollBar ();
- initializeText ();
- initializeSystemColors ();
- initializeDefaults ();
- initializeTranslations ();
-}
-void initializeButton () {
-
- int shellHandle, widgetHandle;
- int widgetClass = OS.TopLevelShellWidgetClass ();
-
- /* Get the push button information */
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- widgetHandle = OS.XmCreatePushButton (shellHandle, null, 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.
+public Thread getThread () {
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+ return thread;
+}
+void hideToolTip () {
+ if (toolTipHandle != 0) {
+ int shellHandle = OS.XtParent(toolTipHandle);
+ OS.XtDestroyWidget(shellHandle);
+ }
+ toolTipHandle = 0;
+}
+protected void init () {
+ super.init ();
+ initializeDisplay ();
+ initializeButton ();
+ initializeComposite ();
+ initializeDialog ();
+ initializeLabel ();
+ initializeList ();
+ initializeScrollBar ();
+ initializeText ();
+ initializeSystemColors ();
+ initializeDefaults ();
+ initializeTranslations ();
+}
+void initializeButton () {
+
+ int shellHandle, widgetHandle;
+ int widgetClass = OS.TopLevelShellWidgetClass ();
+
+ /* Get the push button information */
+ shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
+ widgetHandle = OS.XmCreatePushButton (shellHandle, null, 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 */
- 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);
-
- /*
- * Bug in MOTIF. For some reason, calls to XmGetPixmap ()
- * and XmGetPixmapByDepth fail to find the pixmap unless at
- * least one message box has been created. The fix is to
- * create and destroy a message box.
- */
-// int dialog = OS.XmCreateInformationDialog (shellHandle, null, null, 0);
-// OS.XtDestroyWidget (dialog);
-}
-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.
+
+ 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 */
+ 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);
+
+ /*
+ * Bug in MOTIF. For some reason, calls to XmGetPixmap ()
+ * and XmGetPixmapByDepth fail to find the pixmap unless at
+ * least one message box has been created. The fix is to
+ * create and destroy a message box.
+ */
+// int dialog = OS.XmCreateInformationDialog (shellHandle, null, null, 0);
+// OS.XtDestroyWidget (dialog);
+}
+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 [0], 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.
+
+ 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 [0], 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.
- */
+
+ 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 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 [0], 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.XtGetValues (widgetHandle, argList, argList.length / 2);
- textForeground = argList [1]; textBackground = argList [3];
- textHighlightThickness = argList[7];
- /*
- * 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.
+ 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 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 [0], 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.XtGetValues (widgetHandle, argList, argList.length / 2);
+ textForeground = argList [1]; textBackground = argList [3];
+ textHighlightThickness = argList[7];
+ /*
+ * 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);
-}
-/**
- * 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
- *
- * @private
+
+ 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);
+}
+/**
+ * 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
+ *
+ * @private
*/
-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) {
- data.device = this;
- data.display = xDisplay;
- data.drawable = xDrawable;
- data.fontList = defaultFont.handle;
- data.codePage = defaultFont.codePage;
- 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 handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
+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) {
+ data.device = this;
+ data.display = xDisplay;
+ data.drawable = xDrawable;
+ data.fontList = defaultFont.handle;
+ data.codePage = defaultFont.codePage;
+ 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 handle the platform specific GC handle
+ * @param data the platform specific GC data
+ *
+ * @private
*/
-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);
-}
-int mouseHoverProc (int handle, int id) {
- mouseHoverID = mouseHoverHandle = 0;
- Widget widget = WidgetTable.get (handle);
- if (widget == null) return 0;
- return widget.hoverProc (id);
-}
-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>
- * </ul>
- *
- * @see #sleep
- * @see #wake
+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);
+}
+int mouseHoverProc (int handle, int id) {
+ mouseHoverID = mouseHoverHandle = 0;
+ Widget widget = WidgetTable.get (handle);
+ if (widget == null) return 0;
+ return widget.hoverProc (id);
+}
+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>
+ * </ul>
+ *
+ * @see #sleep
+ * @see #wake
*/
-public boolean readAndDispatch () {
- checkDevice ();
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- int status = OS.XtAppPending (xtContext);
- if (status == 0) {
- OS.XtAppAddTimeOut (xtContext, 1, 0, 0);
- OS.XtAppProcessEvent (xtContext, OS.XtIMTimer);
- } else {
- 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);
- }
- runDeferredEvents ();
- return true;
- }
- return runAsyncMessages ();
-}
-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;
-}
-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.getDisplay ()) shell.dispose ();
- }
- }
- 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 hidden Override shell parent */
- if (shellHandle != 0) 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);
-
- /* 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);
-
- /* Release references */
- thread = null;
- xEvent = 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;
-}
-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;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notifed when an event of the given type occurs anywhere in SWT.
- *
- * @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 #addFilter
- * @see #addListener
- *
- * @since 2.1
- */
-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 notifed when an event of the given type occurs.
- *
- * @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 #addListener
- *
- * @since 2.0
+public boolean readAndDispatch () {
+ checkDevice ();
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+ int status = OS.XtAppPending (xtContext);
+ if (status == 0) {
+ OS.XtAppAddTimeOut (xtContext, 1, 0, 0);
+ OS.XtAppProcessEvent (xtContext, OS.XtIMTimer);
+ } else {
+ 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);
+ }
+ runDeferredEvents ();
+ return true;
+ }
+ return runAsyncMessages ();
+}
+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;
+}
+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.getDisplay ()) shell.dispose ();
+ }
+ }
+ 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 hidden Override shell parent */
+ if (shellHandle != 0) 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);
+
+ /* 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);
+
+ /* Release references */
+ thread = null;
+ xEvent = 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;
+}
+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;
+}
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notifed when an event of the given type occurs anywhere in SWT.
+ *
+ * @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 #addFilter
+ * @see #addListener
+ *
+ * @since 2.1
*/
-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 () {
- return synchronizer.runAsyncMessages ();
-}
-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;
-}
-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);
- }
-}
-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
- * @since 2.0
- * @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
- * </ul>
+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 notifed when an event of the given type occurs.
+ *
+ * @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 #addListener
+ *
+ * @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.
- *
- * @param name the new app name
+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 () {
+ return synchronizer.runAsyncMessages ();
+}
+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;
+}
+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);
+ }
+}
+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
+ * @since 2.0
+ * @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
+ * </ul>
*/
-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>
- * </ul>
- *
- * @see #setData
- * @see #disposeExec
+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.
+ *
+ * @param name the new app name
*/
-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 - when called from the wrong thread</li>
- * </ul>
- *
- * @see #getData
- * @see #disposeExec
+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>
+ * </ul>
+ *
+ * @see #setData
+ * @see #disposeExec
+ */
+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 - when called from the wrong thread</li>
+ * </ul>
+ *
+ * @see #getData
+ * @see #disposeExec
*/
-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>
- * </ul>
+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>
+ * </ul>
*/
-public void setSynchronizer (Synchronizer synchronizer) {
- checkDevice ();
- if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (this.synchronizer != null) {
- this.synchronizer.runAsyncMessages();
- }
- 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>
- * </ul>
- *
- * @see #wake
+public void setSynchronizer (Synchronizer synchronizer) {
+ checkDevice ();
+ if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (this.synchronizer != null) {
+ this.synchronizer.runAsyncMessages();
+ }
+ 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>
+ * </ul>
+ *
+ * @see #wake
*/
-public boolean sleep () {
- checkDevice ();
- /*
- * This code is intentionally commented.
- */
-// int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
-// /*
-// * 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, 100, 0, 0);
-// boolean result = OS.XtAppPeekEvent (xtContext, xEvent);
-// if (sleepID != 0) OS.XtRemoveTimeOut (sleepID);
-// return result;
-
- int display_fd = OS.ConnectionNumber (xDisplay);
- int max_fd = display_fd > read_fd ? display_fd : read_fd;
- OS.FD_ZERO (fd_set);
- OS.FD_SET (display_fd, fd_set);
- OS.FD_SET (read_fd, fd_set);
- timeout [0] = 0;
- timeout [1] = 100000;
- OS.select (max_fd + 1, fd_set, null, null, timeout);
- 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.
- *
- * @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
+public boolean sleep () {
+ checkDevice ();
+ /*
+ * This code is intentionally commented.
+ */
+// int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+// /*
+// * 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, 100, 0, 0);
+// boolean result = OS.XtAppPeekEvent (xtContext, xEvent);
+// if (sleepID != 0) OS.XtRemoveTimeOut (sleepID);
+// return result;
+
+ int display_fd = OS.ConnectionNumber (xDisplay);
+ int max_fd = display_fd > read_fd ? display_fd : read_fd;
+ OS.FD_ZERO (fd_set);
+ OS.FD_SET (display_fd, fd_set);
+ OS.FD_SET (read_fd, fd_set);
+ timeout [0] = 0;
+ timeout [1] = 100000;
+ OS.select (max_fd + 1, fd_set, null, null, timeout);
+ 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.
+ *
+ * @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
*/
-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.
- *
- * @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>
- * </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.
+ *
+ * @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>
+ * </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;
-}
+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.
*
* @see Control#update
*/
-public void update () {
- checkDevice ();
- XAnyEvent event = new XAnyEvent ();
- 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);
-}
-/**
- * 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.
- *
- * @see #sleep
+public void update () {
+ checkDevice ();
+ XAnyEvent event = new XAnyEvent ();
+ 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);
+}
+/**
+ * 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.
+ *
+ * @see #sleep
*/
-public void wake () {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (thread == Thread.currentThread ()) return;
- /* Write a single byte to the wake up pipe */
- while (OS.write (write_fd, wake_buffer, 1) != 1);
-}
-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);
- return 0;
-}
-int windowTimerProc (int handle, int id) {
- Widget widget = WidgetTable.get (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 = WidgetTable.get (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 ();
-}
-}
+public void wake () {
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+ if (thread == Thread.currentThread ()) return;
+ /* Write a single byte to the wake up pipe */
+ while (OS.write (write_fd, wake_buffer, 1) != 1);
+}
+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);
+ return 0;
+}
+int windowTimerProc (int handle, int id) {
+ Widget widget = WidgetTable.get (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 = WidgetTable.get (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
index 753c673000..c41a948d6e 100755
--- 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
@@ -1,68 +1,68 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import java.io.*;
-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>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class FileDialog extends Dialog {
- int dialog;
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String [] fileNames;
- String fileName = "";
- String filterPath = "";
- String fullPath;
- boolean cancel = false;
- static final String FILTER = "*";
-
-/**
- * Constructs a new instance of this class given only its
- * parent.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
+
+import java.io.*;
+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>
+ * 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;
+ String fileName = "";
+ String filterPath = "";
+ String fullPath;
+ boolean cancel = false;
+ static final String FILTER = "*";
+
+/**
+ * Constructs a new instance of this class given only its
+ * parent.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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);
-}
-
+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.
@@ -93,57 +93,57 @@ public FileDialog (Shell parent) {
* <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) {
- cancel = true;
- OS.XtUnmanageChild (widget);
- return 0;
-}
+public FileDialog (Shell parent, int style) {
+ super (parent, style);
+ checkSubclass ();
+}
+
+int cancelPressed (int widget, int client, int call) {
+ cancel = true;
+ OS.XtUnmanageChild (widget);
+ return 0;
+}
/**
* Returns the path of the first file that was
* selected in the dialog relative to the filter path
*
* @return the relative path of the file
*/
-public String getFileName () {
- return fileName;
-}
-
-/**
- * Returns the paths of all files that were selected
- * in the dialog relative to the filter path, or null
- * if none are available.
- *
- * @return the relative paths of the files
+public String getFileName () {
+ return fileName;
+}
+
+/**
+ * Returns the paths of all files that were selected
+ * in the dialog relative to the filter path, or null
+ * if none are available.
+ *
+ * @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 [] 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 file names which the dialog will
- * use to filter the files it shows.
- *
- * @return the file name filter
+public String [] getFilterExtensions () {
+ return filterExtensions;
+}
+
+/**
+ * Returns the file names which the dialog will
+ * use to filter the files it shows.
+ *
+ * @return the file name filter
*/
-public String [] getFilterNames () {
- return filterNames;
-}
-
+public String [] getFilterNames () {
+ return filterNames;
+}
+
/**
* Returns the directory path that the dialog will use.
* File names in this path will appear in the dialog,
@@ -153,347 +153,347 @@ public String [] getFilterNames () {
*
* @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;
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 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];
- int ptr = OS.XmStringUnparse (
- xmString1,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 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,
- null,
- 0,
- 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 ('/');
- 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 ('/');
- fileName = fullPath.substring (index + 1, fullPath.length ());
- fileNames = new String [] {fileName};
- }
- } else {
- int index = fullPath.lastIndexOf ('/');
- fileName = fullPath.substring (index + 1, fullPath.length ());
- fileNames = new String [] {fileName};
- }
-
- // if no file selected then go into the current directory
- if (fileName.equals("")) {
- 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,
- null,
- 0,
- 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);
- if (filterPath.endsWith("/")) {
- filterPath = filterPath.substring (0, filterPath.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 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;
+ int address = OS.XmStringUnparse (
+ ptr,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 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];
+ int ptr = OS.XmStringUnparse (
+ xmString1,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 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,
+ null,
+ 0,
+ 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 ('/');
+ 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 ('/');
+ fileName = fullPath.substring (index + 1, fullPath.length ());
+ fileNames = new String [] {fileName};
+ }
+ } else {
+ int index = fullPath.lastIndexOf ('/');
+ fileName = fullPath.substring (index + 1, fullPath.length ());
+ fileNames = new String [] {fileName};
+ }
+
+ // if no file selected then go into the current directory
+ if (fileName.equals("")) {
+ 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,
+ null,
+ 0,
+ 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);
+ if (filterPath.endsWith("/")) {
+ filterPath = filterPath.substring (0, filterPath.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 () {
-
- /* Get the parent */
- boolean destroyContext;
- Display appContext = Display.getCurrent ();
- if (destroyContext = (appContext == null)) appContext = new Display ();
- int display = appContext.xDisplay;
- int parentHandle = appContext.shellHandle;
- if ((parent != null) && (parent.getDisplay () == appContext)) {
- if (OS.IsAIX) parent.realizeWidget (); /* Fix for bug 17507 */
- parentHandle = parent.shellHandle;
- }
-
- /* 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 = " ";
- /* 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 = null;
-
- /* 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 = "";
- if (!filterPath.endsWith ("/")) {
- File dir = new File (filterPath);
- if (dir.exists () && dir.isDirectory ()) filterPath += '/';
- }
- /* 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 */
- int [] argList1 = {
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL,
- OS.XmNwidth, OS.XDisplayWidth (display, OS.XDefaultScreen (display)) * 4 / 9,
- OS.XmNpathMode, OS.XmPATH_MODE_FULL,
- OS.XmNdialogTitle, xmStringPtr1,
- OS.XmNpattern, xmStringPtr2,
- OS.XmNdirMask, xmStringPtr3,
- };
- /*
- * 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);
-
- /* Hook the callbacks. */
- Callback cancelCallback = new Callback (this, "cancelPressed", 3);
- int cancelAddress = cancelCallback.getAddress ();
- OS.XtAddCallback (dialog, OS.XmNcancelCallback, cancelAddress, 0);
- Callback okCallback = new Callback (this, "okPressed", 3);
- int okAddress = okCallback.getAddress ();
- 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 [] argList2 = {OS.XmNselectionPolicy, OS.XmEXTENDED_SELECT};
- OS.XtSetValues(child, argList2, argList2.length / 2);
- selectCallback = new Callback (this, "itemSelected", 3);
- int selectAddress = selectCallback.getAddress ();
- if (selectAddress == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.XtAddCallback (child, OS.XmNextendedSelectionCallback, selectAddress, 0);
- }
- }
-
- OS.XtManageChild (dialog);
-
- // Should be a pure OS message loop (no SWT AppContext)
- while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
- if (!appContext.readAndDispatch ()) appContext.sleep ();
-
- /* Destroy the dialog and update the display. */
- if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
- if (destroyContext) appContext.dispose ();
- 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 String open () {
+
+ /* Get the parent */
+ boolean destroyContext;
+ Display appContext = Display.getCurrent ();
+ if (destroyContext = (appContext == null)) appContext = new Display ();
+ int display = appContext.xDisplay;
+ int parentHandle = appContext.shellHandle;
+ if ((parent != null) && (parent.getDisplay () == appContext)) {
+ if (OS.IsAIX) parent.realizeWidget (); /* Fix for bug 17507 */
+ parentHandle = parent.shellHandle;
+ }
+
+ /* 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 = " ";
+ /* 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 = null;
+
+ /* 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 = "";
+ if (!filterPath.endsWith ("/")) {
+ File dir = new File (filterPath);
+ if (dir.exists () && dir.isDirectory ()) filterPath += '/';
+ }
+ /* 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 */
+ int [] argList1 = {
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL,
+ OS.XmNwidth, OS.XDisplayWidth (display, OS.XDefaultScreen (display)) * 4 / 9,
+ OS.XmNpathMode, OS.XmPATH_MODE_FULL,
+ OS.XmNdialogTitle, xmStringPtr1,
+ OS.XmNpattern, xmStringPtr2,
+ OS.XmNdirMask, xmStringPtr3,
+ };
+ /*
+ * 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);
+
+ /* Hook the callbacks. */
+ Callback cancelCallback = new Callback (this, "cancelPressed", 3);
+ int cancelAddress = cancelCallback.getAddress ();
+ OS.XtAddCallback (dialog, OS.XmNcancelCallback, cancelAddress, 0);
+ Callback okCallback = new Callback (this, "okPressed", 3);
+ int okAddress = okCallback.getAddress ();
+ 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 [] argList2 = {OS.XmNselectionPolicy, OS.XmEXTENDED_SELECT};
+ OS.XtSetValues(child, argList2, argList2.length / 2);
+ selectCallback = new Callback (this, "itemSelected", 3);
+ int selectAddress = selectCallback.getAddress ();
+ if (selectAddress == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+ OS.XtAddCallback (child, OS.XmNextendedSelectionCallback, selectAddress, 0);
+ }
+ }
+
+ OS.XtManageChild (dialog);
+
+ // Should be a pure OS message loop (no SWT AppContext)
+ while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
+ if (!appContext.readAndDispatch ()) appContext.sleep ();
+
+ /* Destroy the dialog and update the display. */
+ if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
+ if (destroyContext) appContext.dispose ();
+ 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.
- *
- * @param extensions the file extension filter
+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.
+ *
+ * @param extensions the file extension filter
*/
-public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-
-/**
- * Sets the file names which the dialog will
- * use to filter the files it shows to the argument,
- * which may be null.
- *
- * @param names the file name filter
+public void setFilterExtensions (String [] extensions) {
+ filterExtensions = extensions;
+}
+
+/**
+ * Sets the file names which the dialog will
+ * use to filter the files it shows to the argument,
+ * which may be null.
+ *
+ * @param names the file name filter
*/
-public void setFilterNames (String [] names) {
- filterNames = names;
-}
-
+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
@@ -504,7 +504,7 @@ public void setFilterNames (String [] names) {
*
* @see #setFilterExtensions
*/
-public void setFilterPath (String string) {
- filterPath = string;
-}
-}
+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
index 6ecb04481c..cb8df954fc 100755
--- 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
@@ -1,118 +1,118 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class FontDialog extends Dialog {
-
- private FontData fontData;
- private Font sampleFont; // the current displayed sample font
- private RGB rgb;
- private Color sampleColor; // the current displayed sample color
-
- /*
- * 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 ();
-
- private boolean okSelected = false;
- private boolean ignoreEvents = false;
-
- // widgets
- private Shell shell;
- private Combo charSetCombo;
- private Combo faceNameCombo;
- private Combo fontSizeCombo;
- private Combo fontStyleCombo;
- private Combo extStyleCombo;
- private Label sampleLabel;
- private Button okButton;
- private Button cancelButton;
- private Button colorButton;
-
- // constants
- private static final String TEXT_SAMPLE = "AaBbYyZz";
- private static final String SCALABLE_SIZES[] = new String[] {"8", "10", "11", "12", "14", "16", "18", "22", "24", "26"};
- 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 Integer NO_SELECTION = new Integer (-1);
- private static final int COLUMN1_WIDTH = 200;
- private static final int COLUMN2_WIDTH = 150;
- private static final int COLUMN3_WIDTH = 100;
- 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")
- };
-
-/**
- * Constructs a new instance of this class given only its
- * parent.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
+
+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.
+ * <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 Font sampleFont; // the current displayed sample font
+ private RGB rgb;
+ private Color sampleColor; // the current displayed sample color
+
+ /*
+ * 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 ();
+
+ private boolean okSelected = false;
+ private boolean ignoreEvents = false;
+
+ // widgets
+ private Shell shell;
+ private Combo charSetCombo;
+ private Combo faceNameCombo;
+ private Combo fontSizeCombo;
+ private Combo fontStyleCombo;
+ private Combo extStyleCombo;
+ private Label sampleLabel;
+ private Button okButton;
+ private Button cancelButton;
+ private Button colorButton;
+
+ // constants
+ private static final String TEXT_SAMPLE = "AaBbYyZz";
+ private static final String SCALABLE_SIZES[] = new String[] {"8", "10", "11", "12", "14", "16", "18", "22", "24", "26"};
+ 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 Integer NO_SELECTION = new Integer (-1);
+ private static final int COLUMN1_WIDTH = 200;
+ private static final int COLUMN2_WIDTH = 150;
+ private static final int COLUMN3_WIDTH = 100;
+ 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")
+ };
+
+/**
+ * Constructs a new instance of this class given only its
+ * parent.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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);
-}
-
+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.
@@ -143,845 +143,845 @@ public FontDialog (Shell parent) {
* <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.
+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);
+ 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);
+ }
+}
+
+/**
+ * Create the widgets of the dialog.
*/
-void addFonts (FontData fonts[]) {
-
- for (int i = 0; i < fonts.length; i++) {
- FontData font = fonts [i];
-
- String charSetName = getTranslatedCharSet (font);
- 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);
- }
-}
-
-/**
- * Create the widgets of the dialog.
+void createChildren () {
+ Label characterSetLabel = new Label (shell, SWT.NONE);
+ Label faceNameLabel = new Label (shell, SWT.NONE);
+ Label extendedStyleLabel = new Label (shell, SWT.NONE);
+ GridLayout layout = new GridLayout ();
+
+ layout.numColumns = 4;
+ layout.marginWidth = 15;
+ layout.marginHeight = 15;
+ layout.horizontalSpacing = 10;
+ layout.verticalSpacing = 2;
+ shell.setLayout (layout);
+
+ // row one
+ characterSetLabel.setText (SWT.getMessage ("SWT_Character_set") + ":");
+ faceNameLabel.setText (SWT.getMessage ("SWT_Font") + ":");
+ extendedStyleLabel.setText (SWT.getMessage ("SWT_Extended_style") + ":");
+
+ new Label (shell, SWT.NONE);
+
+ // row two
+ charSetCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
+ GridData gridData = new GridData ();
+ gridData.widthHint = COLUMN1_WIDTH;
+ gridData.heightHint = 150;
+ gridData.verticalSpan = 3;
+ charSetCombo.setLayoutData (gridData);
+ charSetCombo.setData (NO_SELECTION);
+
+ faceNameCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
+ gridData = new GridData ();
+ gridData.widthHint = COLUMN2_WIDTH;
+ gridData.heightHint = 150;
+ gridData.verticalSpan = 3;
+ gridData.verticalAlignment = GridData.FILL;
+ faceNameCombo.setLayoutData (gridData);
+ faceNameCombo.setData (NO_SELECTION);
+
+ extStyleCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
+ gridData = new GridData ();
+ gridData.widthHint = COLUMN3_WIDTH;
+ gridData.heightHint = 150;
+ gridData.verticalSpan = 3;
+ gridData.verticalAlignment = GridData.FILL;
+ extStyleCombo.setLayoutData (gridData);
+ extStyleCombo.setData (NO_SELECTION);
+
+ // create ok, cancel, and color buttons (row two, three, and four)
+ createButtons ();
+
+ // row four
+ createEmptyRow ();
+
+ // row five
+ Label fontSizeLabel = new Label (shell, SWT.NONE);
+ fontSizeLabel.setText (SWT.getMessage ("SWT_Size") + ":");
+ Label fontStyleLabel = new Label (shell, SWT.NONE);
+ fontStyleLabel.setText (SWT.getMessage ("SWT_Style") + ":");
+
+ Label fillLabel = new Label (shell, SWT.NONE);
+ gridData = new GridData ();
+ gridData.horizontalSpan = 2;
+ fillLabel.setLayoutData (gridData);
+
+ // row six
+ fontSizeCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
+ gridData = new GridData ();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.heightHint = 110;
+ fontSizeCombo.setLayoutData (gridData);
+ fontSizeCombo.setData (NO_SELECTION);
+
+ fontStyleCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
+ gridData = new GridData ();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ fontStyleCombo.setLayoutData (gridData);
+ fontStyleCombo.setData (NO_SELECTION);
+
+ fillLabel = new Label (shell, SWT.NONE);
+ gridData = new GridData ();
+ gridData.horizontalSpan = 2;
+ fillLabel.setLayoutData (gridData);
+
+ // row seven
+ createEmptyRow ();
+
+ // row eight
+ Group sampleGroup = new Group (shell, SWT.NONE);
+ sampleGroup.setText (SWT.getMessage ("SWT_Sample"));
+ gridData = new GridData ();
+ gridData.heightHint = 70;
+ gridData.horizontalSpan = 3;
+ gridData.horizontalAlignment = GridData.FILL;
+ sampleGroup.setLayoutData (gridData);
+
+ // setup group box with sample text
+ 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);
+ shell.setSize (445, 410);
+}
+
+/**
+ * Fill one row in the grid layout with empty widgets.
+ * Used to achieve a bigger vertical spacing between separate
+ * groups of widgets (ie. new rows of Text/Combo combinations).
*/
-void createChildren () {
- Label characterSetLabel = new Label (shell, SWT.NONE);
- Label faceNameLabel = new Label (shell, SWT.NONE);
- Label extendedStyleLabel = new Label (shell, SWT.NONE);
- GridLayout layout = new GridLayout ();
-
- layout.numColumns = 4;
- layout.marginWidth = 15;
- layout.marginHeight = 15;
- layout.horizontalSpacing = 10;
- layout.verticalSpacing = 2;
- shell.setLayout (layout);
-
- // row one
- characterSetLabel.setText (SWT.getMessage ("SWT_Character_set") + ":");
- faceNameLabel.setText (SWT.getMessage ("SWT_Font") + ":");
- extendedStyleLabel.setText (SWT.getMessage ("SWT_Extended_style") + ":");
-
- new Label (shell, SWT.NONE);
-
- // row two
- charSetCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
- GridData gridData = new GridData ();
- gridData.widthHint = COLUMN1_WIDTH;
- gridData.heightHint = 150;
- gridData.verticalSpan = 3;
- charSetCombo.setLayoutData (gridData);
- charSetCombo.setData (NO_SELECTION);
-
- faceNameCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
- gridData = new GridData ();
- gridData.widthHint = COLUMN2_WIDTH;
- gridData.heightHint = 150;
- gridData.verticalSpan = 3;
- gridData.verticalAlignment = GridData.FILL;
- faceNameCombo.setLayoutData (gridData);
- faceNameCombo.setData (NO_SELECTION);
-
- extStyleCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
- gridData = new GridData ();
- gridData.widthHint = COLUMN3_WIDTH;
- gridData.heightHint = 150;
- gridData.verticalSpan = 3;
- gridData.verticalAlignment = GridData.FILL;
- extStyleCombo.setLayoutData (gridData);
- extStyleCombo.setData (NO_SELECTION);
-
- // create ok, cancel, and color buttons (row two, three, and four)
- createButtons ();
-
- // row four
- createEmptyRow ();
-
- // row five
- Label fontSizeLabel = new Label (shell, SWT.NONE);
- fontSizeLabel.setText (SWT.getMessage ("SWT_Size") + ":");
- Label fontStyleLabel = new Label (shell, SWT.NONE);
- fontStyleLabel.setText (SWT.getMessage ("SWT_Style") + ":");
-
- Label fillLabel = new Label (shell, SWT.NONE);
- gridData = new GridData ();
- gridData.horizontalSpan = 2;
- fillLabel.setLayoutData (gridData);
-
- // row six
- fontSizeCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
- gridData = new GridData ();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.FILL;
- gridData.heightHint = 110;
- fontSizeCombo.setLayoutData (gridData);
- fontSizeCombo.setData (NO_SELECTION);
-
- fontStyleCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
- gridData = new GridData ();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.FILL;
- fontStyleCombo.setLayoutData (gridData);
- fontStyleCombo.setData (NO_SELECTION);
-
- fillLabel = new Label (shell, SWT.NONE);
- gridData = new GridData ();
- gridData.horizontalSpan = 2;
- fillLabel.setLayoutData (gridData);
-
- // row seven
- createEmptyRow ();
-
- // row eight
- Group sampleGroup = new Group (shell, SWT.NONE);
- sampleGroup.setText (SWT.getMessage ("SWT_Sample"));
- gridData = new GridData ();
- gridData.heightHint = 70;
- gridData.horizontalSpan = 3;
- gridData.horizontalAlignment = GridData.FILL;
- sampleGroup.setLayoutData (gridData);
-
- // setup group box with sample text
- 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);
- shell.setSize (445, 410);
-}
-
-/**
- * Fill one row in the grid layout with empty widgets.
- * Used to achieve a bigger vertical spacing between separate
- * groups of widgets (ie. new rows of Text/Combo combinations).
+void createEmptyRow () {
+ Label fillLabel = new Label (shell, SWT.NONE);
+ GridData gridData = new GridData ();
+
+ gridData.heightHint = 5;
+ gridData.horizontalSpan = ((GridLayout) shell.getLayout ()).numColumns;
+ fillLabel.setLayoutData (gridData);
+}
+
+/**
+ * Create the widgets of the dialog.
+ */
+void createButtons () {
+ okButton = new Button (shell, SWT.PUSH);
+ okButton.setText (SWT.getMessage ("SWT_OK"));
+ shell.setDefaultButton (okButton);
+ GridData gridData = new GridData ();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.widthHint = 70;
+ okButton.setLayoutData (gridData);
+
+ cancelButton = new Button (shell, SWT.PUSH);
+ cancelButton.setText (SWT.getMessage ("SWT_Cancel"));
+ gridData = new GridData ();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.BEGINNING;
+ cancelButton.setLayoutData (gridData);
+
+ colorButton = new Button (shell, SWT.PUSH);
+ colorButton.setText (SWT.getMessage ("SWT_Color"));
+ gridData = new GridData ();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.BEGINNING;
+ colorButton.setLayoutData (gridData);
+}
+
+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
*/
-void createEmptyRow () {
- Label fillLabel = new Label (shell, SWT.NONE);
- GridData gridData = new GridData ();
-
- gridData.heightHint = 5;
- gridData.horizontalSpan = ((GridLayout) shell.getLayout ()).numColumns;
- fillLabel.setLayoutData (gridData);
-}
-
-/**
- * Create the widgets of the dialog.
+public FontData getFontData () {
+ return fontData;
+}
+
+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 the collection of fonts that are displayed by the
+ * receiver.
+ * See the class definition for an explanation of the structure
+ * of the returned Hashtable.
*/
-void createButtons () {
- okButton = new Button (shell, SWT.PUSH);
- okButton.setText (SWT.getMessage ("SWT_OK"));
- shell.setDefaultButton (okButton);
- GridData gridData = new GridData ();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.widthHint = 70;
- okButton.setLayoutData (gridData);
-
- cancelButton = new Button (shell, SWT.PUSH);
- cancelButton.setText (SWT.getMessage ("SWT_Cancel"));
- gridData = new GridData ();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.BEGINNING;
- cancelButton.setLayoutData (gridData);
-
- colorButton = new Button (shell, SWT.PUSH);
- colorButton.setText (SWT.getMessage ("SWT_Color"));
- gridData = new GridData ();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.BEGINNING;
- colorButton.setLayoutData (gridData);
-}
-
-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
+Hashtable getFonts () {
+ return characterSets;
+}
+
+/**
+ * Returns the currently selected color in the receiver.
+ *
+ * @return the RGB value for the selected color, may be null
+ *
+ * @see PaletteData#getRGBs
*/
-public FontData getFontData () {
- return fontData;
-}
-
-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 the collection of fonts that are displayed by the
- * receiver.
- * See the class definition for an explanation of the structure
- * of the returned Hashtable.
+public RGB getRGB () {
+ return rgb;
+}
+
+/**
+ * Returns a FontData object that can be used to load the selected
+ * font.
*/
-Hashtable getFonts () {
- return characterSets;
-}
-
-/**
- * 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;
-}
-
-/**
- * Returns a FontData object that can be used to load the selected
- * font.
+FontData getSelectionFontData () {
+ String charSetName = charSetCombo.getText ();
+ String faceName = faceNameCombo.getText ();
+ String extStyle = extStyleCombo.getText ();
+ int size = DEFAULT_SIZE;
+ try {
+ size = Integer.valueOf (fontSizeCombo.getText ()).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 = fontStyleCombo.getText ();
+ FontData result = getFontData (charSetName, faceName, extStyle, size, style);
+
+ if (result == null) {
+ /*
+ * 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.
*/
-FontData getSelectionFontData () {
- String charSetName = charSetCombo.getText ();
- String faceName = faceNameCombo.getText ();
- String extStyle = extStyleCombo.getText ();
- int size = DEFAULT_SIZE;
- try {
- size = Integer.valueOf (fontSizeCombo.getText ()).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 = fontStyleCombo.getText ();
- FontData result = getFontData (charSetName, faceName, extStyle, size, style);
-
- if (result == null) {
- /*
- * 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) {
+ 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 += "-" + 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 (translatedCharSet != null) {
+ translatedCharSet += " (" + characterSet + ')';
+ }
+ 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 box 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 getTranslatedCharSet (FontData fontData) {
- 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 += "-" + 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 (translatedCharSet != null) {
- translatedCharSet += " (" + characterSet + ')';
- }
- 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 box 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.
+ * Combo selections cause the downstream combos to be initialized
+ * with font data and the sample text to be updated.
*/
-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.
- * Combo selections cause the downstream combos to be initialized
- * with font data and the sample text to be updated.
+void handleEvent (Event event) {
+ if (ignoreEvents) return;
+ if (event.widget instanceof Combo) {
+ Combo combo = (Combo) event.widget;
+ int prevSelectIndex = ((Integer) combo.getData ()).intValue ();
+ String text = combo.getText ();
+ int newSelectIndex = combo.indexOf (text);
+ if (prevSelectIndex != newSelectIndex || newSelectIndex == -1) {
+ ignoreEvents = true;
+ combo.setData (new Integer (newSelectIndex));
+ if (combo == charSetCombo) initFaceNameCombo ();
+ else if (combo == faceNameCombo) initExtStyleCombo ();
+ else if (combo == extStyleCombo) initSizeCombo ();
+ else if (combo == fontSizeCombo) initStyleCombo ();
+ updateSampleFont ();
+ if (newSelectIndex != -1) {
+ // in case it came by typing the name
+ combo.select (newSelectIndex);
+ }
+ ignoreEvents = false;
+ }
+ }
+ else
+ 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 ();
+ }
+ }
+}
+
+/**
+ * Initialize the extended styles combo with the extended styles
+ * available for the selected font.
+ * Downstream combos are initialized as well (style and size).
*/
-void handleEvent (Event event) {
- if (ignoreEvents) return;
- if (event.widget instanceof Combo) {
- Combo combo = (Combo) event.widget;
- int prevSelectIndex = ((Integer) combo.getData ()).intValue ();
- String text = combo.getText ();
- int newSelectIndex = combo.indexOf (text);
- if (prevSelectIndex != newSelectIndex || newSelectIndex == -1) {
- ignoreEvents = true;
- combo.setData (new Integer (newSelectIndex));
- if (combo == charSetCombo) initFaceNameCombo ();
- else if (combo == faceNameCombo) initExtStyleCombo ();
- else if (combo == extStyleCombo) initSizeCombo ();
- else if (combo == fontSizeCombo) initStyleCombo ();
- updateSampleFont ();
- if (newSelectIndex != -1) {
- // in case it came by typing the name
- combo.select (newSelectIndex);
- }
- ignoreEvents = false;
- }
- }
- else
- 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 ();
- }
- }
-}
-
-/**
- * Initialize the extended styles combo with the extended styles
- * available for the selected font.
- * Downstream combos are initialized as well (style and size).
+void initExtStyleCombo () {
+ String oldSelect = extStyleCombo.getText ();
+ extStyleCombo.removeAll ();
+
+ String characterSet = charSetCombo.getText ();
+ String faceName = faceNameCombo.getText ();
+ Hashtable extStyles = getExtStyles (characterSet, faceName);
+ setItemsSorted (extStyleCombo, extStyles);
+
+ int selectIndex = extStyleCombo.indexOf (oldSelect);
+ selectIndex = Math.max (0, selectIndex);
+ extStyleCombo.select (selectIndex);
+ extStyleCombo.setData (new Integer (selectIndex));
+ initSizeCombo ();
+}
+
+/**
+ * Initialize the face name combo box with all font names
+ * available in the selected character set.
+ * Downstream combos are initialized as well (extended style).
*/
-void initExtStyleCombo () {
- String oldSelect = extStyleCombo.getText ();
- extStyleCombo.removeAll ();
-
- String characterSet = charSetCombo.getText ();
- String faceName = faceNameCombo.getText ();
- Hashtable extStyles = getExtStyles (characterSet, faceName);
- setItemsSorted (extStyleCombo, extStyles);
-
- int selectIndex = extStyleCombo.indexOf (oldSelect);
- selectIndex = Math.max (0, selectIndex);
- extStyleCombo.select (selectIndex);
- extStyleCombo.setData (new Integer (selectIndex));
- initSizeCombo ();
-}
-
-/**
- * Initialize the face name combo box with all font names
- * available in the selected character set.
- * Downstream combos are initialized as well (extended style).
+void initFaceNameCombo () {
+ String oldSelect = faceNameCombo.getText ();
+ faceNameCombo.removeAll ();
+ String charSetText = charSetCombo.getText ();
+ if (charSetText.length () == 0) return;
+
+ Hashtable faceNames = getFaces (charSetText);
+ setItemsSorted (faceNameCombo, faceNames);
+
+ int selectIndex = faceNameCombo.indexOf (oldSelect);
+ selectIndex = Math.max (0, selectIndex);
+ faceNameCombo.select (selectIndex);
+ faceNameCombo.setData (new Integer (selectIndex));
+ initExtStyleCombo ();
+}
+
+/**
+ * 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 combo boxes.
*/
-void initFaceNameCombo () {
- String oldSelect = faceNameCombo.getText ();
- faceNameCombo.removeAll ();
- String charSetText = charSetCombo.getText ();
- if (charSetText.length () == 0) return;
-
- Hashtable faceNames = getFaces (charSetText);
- setItemsSorted (faceNameCombo, faceNames);
-
- int selectIndex = faceNameCombo.indexOf (oldSelect);
- selectIndex = Math.max (0, selectIndex);
- faceNameCombo.select (selectIndex);
- faceNameCombo.setData (new Integer (selectIndex));
- initExtStyleCombo ();
-}
-
-/**
- * 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 combo boxes.
+void initializeWidgets () {
+ Display display = shell.getDisplay ();
+ addFonts (display.getFontList (null, false)); // get all fonts availabe on the current display
+ addFonts (display.getFontList (null, true));
+ setItemsSorted (charSetCombo, getFonts ());
+ if (fontData != null) {
+ Font font = new Font (display, fontData); // verify that the initial font data is a valid font
+ ignoreEvents = true;
+ setFontCombos (font.getFontData ()[0]);
+ ignoreEvents = false;
+ font.dispose ();
+ }
+ updateSampleFont ();
+ updateSampleColor ();
+}
+
+/**
+ * Initialize the size combo with the sizes the selected font
+ * is available in.
+ * If the selected font is scalable a selection of preset sizes
+ * is used.
*/
-void initializeWidgets () {
- Display display = shell.getDisplay ();
- addFonts (display.getFontList (null, false)); // get all fonts availabe on the current display
- addFonts (display.getFontList (null, true));
- setItemsSorted (charSetCombo, getFonts ());
- if (fontData != null) {
- Font font = new Font (display, fontData); // verify that the initial font data is a valid font
- ignoreEvents = true;
- setFontCombos (font.getFontData ()[0]);
- ignoreEvents = false;
- font.dispose ();
- }
- updateSampleFont ();
- updateSampleColor ();
-}
-
-/**
- * Initialize the size combo with the sizes the selected font
- * is available in.
- * If the selected font is scalable a selection of preset sizes
- * is used.
+void initSizeCombo () {
+ String oldSelect = fontSizeCombo.getText ();
+ fontSizeCombo.removeAll ();
+
+ String characterSet = charSetCombo.getText ();
+ String faceName = faceNameCombo.getText ();
+ String extStyle = extStyleCombo.getText ();
+ 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 = fontSizeCombo.indexOf (oldSelect);
+ if (selectIndex == -1) {
+ selectIndex = fontSizeCombo.indexOf (String.valueOf (DEFAULT_SIZE));
+ }
+ selectIndex = Math.max (0, selectIndex);
+ fontSizeCombo.select (selectIndex);
+ fontSizeCombo.setData (new Integer (selectIndex));
+ initStyleCombo ();
+}
+
+/**
+ * Initialize the styles combo with the styles the selected font
+ * is available in.
*/
-void initSizeCombo () {
- String oldSelect = fontSizeCombo.getText ();
- fontSizeCombo.removeAll ();
-
- String characterSet = charSetCombo.getText ();
- String faceName = faceNameCombo.getText ();
- String extStyle = extStyleCombo.getText ();
- 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 = fontSizeCombo.indexOf (oldSelect);
- if (selectIndex == -1) {
- selectIndex = fontSizeCombo.indexOf (String.valueOf (DEFAULT_SIZE));
- }
- selectIndex = Math.max (0, selectIndex);
- fontSizeCombo.select (selectIndex);
- fontSizeCombo.setData (new Integer (selectIndex));
- initStyleCombo ();
-}
-
-/**
- * Initialize the styles combo with the styles the selected font
- * is available in.
+void initStyleCombo () {
+ String oldSelect = fontStyleCombo.getText ();
+ fontStyleCombo.removeAll ();
+
+ String characterSet = charSetCombo.getText ();
+ String faceName = faceNameCombo.getText ();
+ String extStyle = extStyleCombo.getText ();
+ try {
+ int size = Integer.valueOf (fontSizeCombo.getText ()).intValue ();
+ if (size > 0) {
+ Hashtable styles = getStyles (characterSet, faceName, extStyle, size);
+ setItemsSorted (fontStyleCombo, styles);
+ }
+ } catch (NumberFormatException e) {
+ // fall through
+ }
+
+ int selectIndex = fontStyleCombo.indexOf (oldSelect);
+ if (selectIndex == -1) {
+ selectIndex = fontStyleCombo.indexOf (String.valueOf (DEFAULT_STYLE));
+ }
+ selectIndex = Math.max (0, selectIndex);
+ fontStyleCombo.select (selectIndex);
+ fontStyleCombo.setData (new Integer (selectIndex));
+ fontStyleCombo.select (Math.max (0, selectIndex));
+}
+
+/**
+ * Register the receiver to receive events.
*/
-void initStyleCombo () {
- String oldSelect = fontStyleCombo.getText ();
- fontStyleCombo.removeAll ();
-
- String characterSet = charSetCombo.getText ();
- String faceName = faceNameCombo.getText ();
- String extStyle = extStyleCombo.getText ();
- try {
- int size = Integer.valueOf (fontSizeCombo.getText ()).intValue ();
- if (size > 0) {
- Hashtable styles = getStyles (characterSet, faceName, extStyle, size);
- setItemsSorted (fontStyleCombo, styles);
- }
- } catch (NumberFormatException e) {
- // fall through
- }
-
- int selectIndex = fontStyleCombo.indexOf (oldSelect);
- if (selectIndex == -1) {
- selectIndex = fontStyleCombo.indexOf (String.valueOf (DEFAULT_STYLE));
- }
- selectIndex = Math.max (0, selectIndex);
- fontStyleCombo.select (selectIndex);
- fontStyleCombo.setData (new Integer (selectIndex));
- fontStyleCombo.select (Math.max (0, selectIndex));
-}
-
-/**
- * Register the receiver to receive events.
+void installListeners () {
+ 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);
+ charSetCombo.addListener (SWT.Selection, listener);
+ charSetCombo.addListener (SWT.Modify, listener);
+ faceNameCombo.addListener (SWT.Modify, listener);
+ fontStyleCombo.addListener (SWT.Modify, listener);
+ extStyleCombo.addListener (SWT.Modify, listener);
+ fontSizeCombo.addListener (SWT.Modify, listener);
+}
+
+/**
+ * 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>
*/
-void installListeners () {
- 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);
- charSetCombo.addListener (SWT.Selection, listener);
- charSetCombo.addListener (SWT.Modify, listener);
- faceNameCombo.addListener (SWT.Modify, listener);
- fontStyleCombo.addListener (SWT.Modify, listener);
- extStyleCombo.addListener (SWT.Modify, listener);
- fontSizeCombo.addListener (SWT.Modify, listener);
-}
-
-/**
- * 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);
+ createChildren ();
+ installListeners ();
+
+ FontData originalFontData = fontData;
+ RGB originalRGB = rgb;
+ initializeWidgets ();
+ openDialog ();
+ Display display = shell.getDisplay ();
+ while (!shell.isDisposed ()) {
+ if (!display.readAndDispatch ()) display.sleep ();
+ }
+
+ FontData result = null;
+ if (okSelected) {
+ result = fontData;
+ } 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.
*/
-public FontData open () {
- shell = new Shell (getParent (), getStyle () | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
- createChildren ();
- installListeners ();
-
- FontData originalFontData = fontData;
- RGB originalRGB = rgb;
- initializeWidgets ();
- openDialog ();
- Display display = shell.getDisplay ();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
-
- FontData result = null;
- if (okSelected) {
- result = fontData;
- } 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.
+ Rectangle displayRect = shell.getDisplay().getBounds();
+ int widthLimit = displayRect.width * 7 / 8;
+ int heightLimit = displayRect.height * 7 / 8;
+ if (pt.x > widthLimit) {
+ pt = shell.computeSize (widthLimit, SWT.DEFAULT, false);
+ }
+
+ // centre the dialog on its parent, and ensure that the
+ // whole dialog appears within the screen bounds
+ Rectangle parentBounds = getParent ().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 combo boxes with the data of the preselected
+ * font specified by the user.
*/
-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.
- Rectangle displayRect = shell.getDisplay().getBounds();
- int widthLimit = displayRect.width * 7 / 8;
- int heightLimit = displayRect.height * 7 / 8;
- if (pt.x > widthLimit) {
- pt = shell.computeSize (widthLimit, SWT.DEFAULT, false);
- }
-
- // centre the dialog on its parent, and ensure that the
- // whole dialog appears within the screen bounds
- Rectangle parentBounds = getParent ().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 combo boxes with the data of the preselected
- * font specified by the user.
+void setFontCombos (FontData fontData) {
+ String characterSet = getTranslatedCharSet (fontData);
+ String faceName = getTranslatedFaceName (fontData);
+ charSetCombo.setText (characterSet);
+ charSetCombo.setData (new Integer (charSetCombo.indexOf (characterSet)));
+
+ initFaceNameCombo ();
+ faceNameCombo.setText (faceName);
+ faceNameCombo.setData (new Integer (faceNameCombo.indexOf (faceName)));
+
+ initExtStyleCombo ();
+ extStyleCombo.setText (fontData.addStyle);
+ extStyleCombo.setData (new Integer (extStyleCombo.indexOf (fontData.addStyle)));
+
+ initSizeCombo ();
+ String value = String.valueOf (fontData.getHeight ());
+ fontSizeCombo.setText (value);
+ fontSizeCombo.setData (new Integer (fontSizeCombo.indexOf (value)));
+
+ initStyleCombo ();
+ fontStyleCombo.setText (fontData.weight);
+ fontStyleCombo.setData (new Integer (fontStyleCombo.indexOf (fontData.weight)));
+}
+
+/**
+ * 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
*/
-void setFontCombos (FontData fontData) {
- String characterSet = getTranslatedCharSet (fontData);
- String faceName = getTranslatedFaceName (fontData);
- charSetCombo.setText (characterSet);
- charSetCombo.setData (new Integer (charSetCombo.indexOf (characterSet)));
-
- initFaceNameCombo ();
- faceNameCombo.setText (faceName);
- faceNameCombo.setData (new Integer (faceNameCombo.indexOf (faceName)));
-
- initExtStyleCombo ();
- extStyleCombo.setText (fontData.addStyle);
- extStyleCombo.setData (new Integer (extStyleCombo.indexOf (fontData.addStyle)));
-
- initSizeCombo ();
- String value = String.valueOf (fontData.getHeight ());
- fontSizeCombo.setText (value);
- fontSizeCombo.setData (new Integer (fontSizeCombo.indexOf (value)));
-
- initStyleCombo ();
- fontStyleCombo.setText (fontData.weight);
- fontStyleCombo.setData (new Integer (fontStyleCombo.indexOf (fontData.weight)));
-}
-
-/**
- * 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
+public void setFontData (FontData fontData) {
+ this.fontData = fontData;
+}
+
+/**
+ * Returns 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 to select a default when
+ * open() is called
+ *
+ * @see PaletteData#getRGBs
*/
-public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-
-/**
- * Returns 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 to select a default when
- * open() is called
- *
- * @see PaletteData#getRGBs
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-/**
- * Set the contents of 'combo' to the keys of 'items'.
- * Keys are sorted in ascending order first and have to be Strings.
+public void setRGB (RGB rgb) {
+ this.rgb = rgb;
+}
+
+/**
+ * Set the contents of 'combo' to the keys of 'items'.
+ * Keys are sorted in ascending order first and have to be Strings.
*/
-void setItemsSorted (Combo combo, 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);
- combo.setItems (sortedItems);
-}
-
-/**
- * Set the contents of the size combo to the keys of 'items'.
- * Keys are sorted in ascending order first and have to be Integers.
+void setItemsSorted (Combo combo, 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);
+ combo.setItems (sortedItems);
+}
+
+/**
+ * Set the contents of the size combo 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 ());
- }
- fontSizeCombo.setItems (sortedItemStrings);
-}
-
-/**
- * Sort 'items' in ascending order.
+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 ());
+ }
+ fontSizeCombo.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 (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;
- }
- }
- }
- }
-}
-
-/**
- * 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 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;
+ }
+ }
+ }
+ }
+}
+
+/**
+ * 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 ();
- sampleFont = new Font (shell.getDisplay (), selectionFontData);
- fontData = selectionFontData;
- sampleLabel.setFont (sampleFont);
-}
-
-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 (getParent ().getDisplay (), rgb);
- sampleLabel.setForeground (sampleColor);
-}
+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 ();
+ sampleFont = new Font (shell.getDisplay (), selectionFontData);
+ fontData = selectionFontData;
+ sampleLabel.setFont (sampleFont);
+}
+
+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 (getParent ().getDisplay (), rgb);
+ sampleLabel.setForeground (sampleColor);
+}
} \ No newline at end of file
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
index 5f11b7872e..61eaa1672a 100755
--- 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
@@ -1,40 +1,40 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class Group extends Composite {
- int labelHandle;
-
+
+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;
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -67,242 +67,242 @@ public class Group extends Composite {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Group (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- 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);
- XtWidgetGeometry result = new XtWidgetGeometry ();
- OS.XtQueryGeometry (labelHandle, null, result);
- int titleWidth = result.width + 2 * (argList2 [5] + marginWidth + thickness + borderWidth);
- trimWidth = Math.max (trimWidth, titleWidth);
- }
- return new Rectangle (trimX, trimY, trimWidth, trimHeight);
-}
-void createHandle (int index) {
- state |= HANDLE;
-
- /*
- * 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);
-}
-void createWidget (int index) {
- super.createWidget (index);
- /*
- * 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.
- */
- getShell ().realizeWidget ();
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- enableHandle (enabled, labelHandle);
-}
-int fontHandle () {
- return labelHandle;
-}
-public Rectangle getClientArea () {
- checkWidget();
- 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 Group (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+static int checkStyle (int style) {
+ style |= SWT.NO_FOCUS;
+ /*
+ * Even though it is legal to create this widget
+ * with scroll bars, they serve no useful purpose
+ * because they do not automatically scroll the
+ * widget's client area. The fix is to clear
+ * the SWT style.
+ */
+ return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+public Rectangle computeTrim (int x, int y, int width, int height) {
+ checkWidget();
+ 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);
+ XtWidgetGeometry result = new XtWidgetGeometry ();
+ OS.XtQueryGeometry (labelHandle, null, result);
+ int titleWidth = result.width + 2 * (argList2 [5] + marginWidth + thickness + borderWidth);
+ trimWidth = Math.max (trimWidth, titleWidth);
+ }
+ return new Rectangle (trimX, trimY, trimWidth, trimHeight);
+}
+void createHandle (int index) {
+ state |= HANDLE;
+
+ /*
+ * 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);
+}
+void createWidget (int index) {
+ super.createWidget (index);
+ /*
+ * 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.
+ */
+ getShell ().realizeWidget ();
+}
+void enableWidget (boolean enabled) {
+ super.enableWidget (enabled);
+ enableHandle (enabled, labelHandle);
+}
+int fontHandle () {
+ return labelHandle;
+}
+public Rectangle getClientArea () {
+ checkWidget();
+ 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();
- int [] argList = {OS.XmNlabelString, 0};
- OS.XtGetValues (labelHandle, argList, 1);
- int xmString = argList [1];
- int address = OS.XmStringUnparse (
- xmString,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (address == 0) return "";
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- OS.XmStringFree (xmString);
- return new String (Converter.mbcsToWcs (getCodePage (), buffer));
-}
-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);
-}
-void redrawWidget (int x, int y, int width, int height, boolean all) {
- super.redrawWidget (x, y, width, height, all);
- 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, labelHandle);
-}
-void releaseHandle () {
- super.releaseHandle ();
- labelHandle = 0;
-}
-/**
- * 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.
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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.XmNlabelString, 0};
+ OS.XtGetValues (labelHandle, argList, 1);
+ int xmString = argList [1];
+ int address = OS.XmStringUnparse (
+ xmString,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ OS.XmOUTPUT_ALL);
+ if (address == 0) return "";
+ int length = OS.strlen (address);
+ byte [] buffer = new byte [length];
+ OS.memmove (buffer, address, length);
+ OS.XtFree (address);
+ OS.XmStringFree (xmString);
+ return new String (Converter.mbcsToWcs (getCodePage (), buffer));
+}
+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);
+}
+void redrawWidget (int x, int y, int width, int height, boolean all) {
+ super.redrawWidget (x, y, width, height, all);
+ 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, labelHandle);
+}
+void releaseHandle () {
+ super.releaseHandle ();
+ labelHandle = 0;
+}
+/**
+ * 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.
+ *
+ * @param text the new text
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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);
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- int i=0, j=0, mnemonic=0;
- while (i < text.length) {
- if ((text [j++] = text [i++]) == Mnemonic) {
- if (i == text.length) {continue;}
- if (text [i] == Mnemonic) {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
- j--;
- }
- }
- while (j < text.length) text [j++] = 0;
- 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;
-}
-}
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ char [] text = new char [string.length ()];
+ string.getChars (0, text.length, text, 0);
+ int i=0, j=0, mnemonic=0;
+ while (i < text.length) {
+ if ((text [j++] = text [i++]) == Mnemonic) {
+ if (i == text.length) {continue;}
+ if (text [i] == Mnemonic) {i++; continue;}
+ if (mnemonic == 0) mnemonic = text [i];
+ j--;
+ }
+ }
+ while (j < text.length) text [j++] = 0;
+ 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
index 69a29cf108..a9628ee464 100755
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -35,10 +35,10 @@ import org.eclipse.swt.graphics.*;
* within the SWT implementation.
* </p>
*/
-public class Label extends Control {
- String text = "";
- Image image, bitmap, disabled;
-
+public class Label extends Control {
+ 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.
@@ -76,402 +76,402 @@ public class Label extends Control {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Label (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-static int checkStyle (int style) {
- if ((style & SWT.SEPARATOR) != 0) return style;
- return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 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.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 [] argList = {OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int labelType = argList [1];
- if (labelType == OS.XmSTRING && (style & SWT.WRAP) != 0 && wHint != SWT.DEFAULT) {
- /* If we are wrapping text, calculate the height based on wHint. */
- int [] argList4 = {
- OS.XmNmarginTop, 0, /* 1 */
- OS.XmNmarginBottom, 0, /* 3 */
- OS.XmNmarginHeight, 0, /* 5 */
- OS.XmNmarginWidth, 0, /* 7 */
- };
- OS.XtGetValues (handle, argList4, argList4.length / 2);
- int unavailable = 2 * (argList4 [7] + getBorderWidth());
- Display display = getDisplay ();
- String string = display.wrapText (text, font, wHint - unavailable);
- GC gc = new GC(this);
- Point extent = gc.textExtent(string);
- gc.dispose();
- height = extent.y + argList4 [1] + argList4 [3] + argList4 [5] * 2 + border * 2;
- } else {
- /* If we are not wrapping, ask the widget for its geometry. */
- 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 label'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.
- */
- if (labelType == OS.XmSTRING && text.length () == 0) {
- height += getFontHeight ();
- width = 0;
- }
- 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;
- 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 alignment = OS.XmALIGNMENT_BEGINNING;
- if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER;
- if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END;
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNrecomputeSize, 0,
- OS.XmNalignment, alignment,
- OS.XmNborderWidth, borderWidth,
- };
- handle = OS.XmCreateLabel (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-int defaultBackground () {
- return getDisplay ().labelBackground;
-}
-Font defaultFont () {
- return getDisplay ().labelFont;
-}
-int defaultForeground () {
- return getDisplay ().labelForeground;
-}
-public boolean forceFocus () {
- checkWidget();
- int [] argList = new int [] {OS.XmNtraversalOn, 1};
- OS.XtSetValues (handle, argList, argList.length / 2);
- overrideTranslations ();
- if (super.forceFocus ()) return true;
- argList [1] = 0;
- OS.XtSetValues (handle, argList, argList.length / 2);
- return false;
-}
-/**
- * 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 Label (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+static int checkStyle (int style) {
+ if ((style & SWT.SEPARATOR) != 0) return style;
+ return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 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.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 [] argList = {OS.XmNlabelType, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int labelType = argList [1];
+ if (labelType == OS.XmSTRING && (style & SWT.WRAP) != 0 && wHint != SWT.DEFAULT) {
+ /* If we are wrapping text, calculate the height based on wHint. */
+ int [] argList4 = {
+ OS.XmNmarginTop, 0, /* 1 */
+ OS.XmNmarginBottom, 0, /* 3 */
+ OS.XmNmarginHeight, 0, /* 5 */
+ OS.XmNmarginWidth, 0, /* 7 */
+ };
+ OS.XtGetValues (handle, argList4, argList4.length / 2);
+ int unavailable = 2 * (argList4 [7] + getBorderWidth());
+ Display display = getDisplay ();
+ String string = display.wrapText (text, font, wHint - unavailable);
+ GC gc = new GC(this);
+ Point extent = gc.textExtent(string);
+ gc.dispose();
+ height = extent.y + argList4 [1] + argList4 [3] + argList4 [5] * 2 + border * 2;
+ } else {
+ /* If we are not wrapping, ask the widget for its geometry. */
+ 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 label'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.
+ */
+ if (labelType == OS.XmSTRING && text.length () == 0) {
+ height += getFontHeight ();
+ width = 0;
+ }
+ 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;
+ 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 alignment = OS.XmALIGNMENT_BEGINNING;
+ if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER;
+ if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END;
+ int [] argList = {
+ OS.XmNancestorSensitive, 1,
+ OS.XmNrecomputeSize, 0,
+ OS.XmNalignment, alignment,
+ OS.XmNborderWidth, borderWidth,
+ };
+ handle = OS.XmCreateLabel (parentHandle, null, argList, argList.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+}
+int defaultBackground () {
+ return getDisplay ().labelBackground;
+}
+Font defaultFont () {
+ return getDisplay ().labelFont;
+}
+int defaultForeground () {
+ return getDisplay ().labelForeground;
+}
+public boolean forceFocus () {
+ checkWidget();
+ int [] argList = new int [] {OS.XmNtraversalOn, 1};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ overrideTranslations ();
+ if (super.forceFocus ()) return true;
+ argList [1] = 0;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ return false;
+}
+/**
+ * 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 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 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 ();
- 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.XmSHADOW_ETCHED_IN;
-}
-/**
- * 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 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 ();
+ 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.XmSHADOW_ETCHED_IN;
+}
+/**
+ * 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);
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- int [] argList = {OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == OS.XmPIXMAP) setBitmap (image);
-}
-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);
- Display display = getDisplay ();
- switch (image.type) {
- case SWT.BITMAP:
- labelPixmap = image.pixmap;
- disabled = new Image (display, image, SWT.IMAGE_DISABLE);
- labelInsensitivePixmap = disabled.pixmap;
- break;
- 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, 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) setText (text);
- return changed;
-}
-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 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);
+}
+void setBackgroundPixel (int pixel) {
+ super.setBackgroundPixel (pixel);
+ int [] argList = {OS.XmNlabelType, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [1] == OS.XmPIXMAP) setBitmap (image);
+}
+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);
+ Display display = getDisplay ();
+ switch (image.type) {
+ case SWT.BITMAP:
+ labelPixmap = image.pixmap;
+ disabled = new Image (display, image, SWT.IMAGE_DISABLE);
+ labelInsensitivePixmap = disabled.pixmap;
+ break;
+ 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, 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) setText (text);
+ return changed;
+}
+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;
- setBitmap (this.image = image);
-}
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the widget label. The label may include
- * the mnemonic characters 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 setImage (Image image) {
+ checkWidget();
+ if ((style & SWT.SEPARATOR) != 0) return;
+ setBitmap (this.image = image);
+}
+/**
+ * Sets the receiver's text.
+ * <p>
+ * This method sets the widget label. The label may include
+ * the mnemonic characters 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 ((style & SWT.SEPARATOR) != 0) return;
- text = string;
-
- /* Strip out mnemonic marker symbols, and remember the mnemonic. */
- char [] unicode = new char [string.length ()];
- string.getChars (0, unicode.length, unicode, 0);
- int i=0, j=0, mnemonic=0;
- while (i < unicode.length) {
- if ((unicode [j++] = unicode [i++]) == Mnemonic) {
- if (i == unicode.length) {continue;}
- if (unicode [i] == Mnemonic) {i++; continue;}
- if (mnemonic == 0) mnemonic = unicode [i];
- j--;
- }
- }
- while (j < unicode.length) unicode [j++] = 0;
-
- /* Wrap the text if necessary, and convert to mbcs. */
- byte [] buffer;
- if ((style & SWT.WRAP) != 0) {
- int [] argList = {
- OS.XmNwidth, 0, /* 1 */
- OS.XmNmarginLeft, 0, /* 3 */
- OS.XmNmarginRight, 0, /* 5 */
- OS.XmNborderWidth, 0, /* 7 */
- OS.XmNmarginWidth, 0, /* 9 */
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int width = argList [1] - argList [3] - argList [5] - argList [7] * 2 - argList [9] * 2;
- Display display = getDisplay ();
- 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);
-}
-int xFocusOut () {
- int result = super.xFocusOut ();
- if (handle == 0) return result;
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] != 0) {
- argList [1] = 0;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- return result;
-}
-}
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.SEPARATOR) != 0) return;
+ text = string;
+
+ /* Strip out mnemonic marker symbols, and remember the mnemonic. */
+ char [] unicode = new char [string.length ()];
+ string.getChars (0, unicode.length, unicode, 0);
+ int i=0, j=0, mnemonic=0;
+ while (i < unicode.length) {
+ if ((unicode [j++] = unicode [i++]) == Mnemonic) {
+ if (i == unicode.length) {continue;}
+ if (unicode [i] == Mnemonic) {i++; continue;}
+ if (mnemonic == 0) mnemonic = unicode [i];
+ j--;
+ }
+ }
+ while (j < unicode.length) unicode [j++] = 0;
+
+ /* Wrap the text if necessary, and convert to mbcs. */
+ byte [] buffer;
+ if ((style & SWT.WRAP) != 0) {
+ int [] argList = {
+ OS.XmNwidth, 0, /* 1 */
+ OS.XmNmarginLeft, 0, /* 3 */
+ OS.XmNmarginRight, 0, /* 5 */
+ OS.XmNborderWidth, 0, /* 7 */
+ OS.XmNmarginWidth, 0, /* 9 */
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int width = argList [1] - argList [3] - argList [5] - argList [7] * 2 - argList [9] * 2;
+ Display display = getDisplay ();
+ 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);
+}
+int xFocusOut () {
+ int result = super.xFocusOut ();
+ if (handle == 0) return result;
+ int [] argList = new int [] {OS.XmNtraversalOn, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [1] != 0) {
+ argList [1] = 0;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+ 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
index 628edf905a..c7a8f56b54 100755
--- 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
@@ -1,37 +1,37 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 notificiation
- * when a string 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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class List extends Scrollable {
+
+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 notificiation
+ * when a string 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.
@@ -61,1296 +61,1296 @@ public class List extends Scrollable {
* @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.
+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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- *
- * @see #add(String,int)
+ 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- *
- * @see #add(String)
+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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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 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();
- Display display = getDisplay ();
- 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.
+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();
+ Display display = getDisplay ();
+ 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) {
- state |= HANDLE;
-
- /*
- * 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 [0], argList2, argList2.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- scrolledHandle = OS.XtParent (handle);
- }
-}
-ScrollBar createScrollBar (int type) {
- return createStandardBar (type);
-}
-int defaultBackground () {
- return getDisplay ().listBackground;
-}
-Font defaultFont () {
- return getDisplay ().listFont;
-}
-int defaultForeground () {
- return getDisplay ().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>
+ 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) {
+ state |= HANDLE;
+
+ /*
+ * 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 [0], argList2, argList2.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ scrolledHandle = OS.XtParent (handle);
+ }
+}
+ScrollBar createScrollBar (int type) {
+ return createStandardBar (type);
+}
+int defaultBackground () {
+ return getDisplay ().listBackground;
+}
+Font defaultFont () {
+ return getDisplay ().listFont;
+}
+int defaultForeground () {
+ return getDisplay ().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 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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 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 is currently
- * has the focus in the receiver, or -1 if no item is 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 void deselectAll () {
+ checkWidget();
+ OS.XmListDeselectAllItems (handle);
+}
+/**
+ * Returns the zero-relative index of the item which is currently
+ * has the focus in the receiver, or -1 if no item is 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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 address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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 address = OS.XmStringUnparse (
+ ptr,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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 () + spacing + highlight + 1;
-}
-/**
- * Returns an 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</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 () + spacing + highlight + 1;
+}
+/**
+ * Returns an 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</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 address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 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. 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure while getting the selection</li>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</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 address = OS.XmStringUnparse (
+ ptr,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 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. 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure while getting the selection</li>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</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 address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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 address = OS.XmStringUnparse (
+ ptr,
+ null,
+ OS.XmCHARSET_TEXT,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</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
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</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 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</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 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</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 [] 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 = getDisplay ().windowProc;
- OS.XtAddCallback (handle, OS.XmNbrowseSelectionCallback, windowProc, BROWSE_SELECTION_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNextendedSelectionCallback, windowProc, EXTENDED_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 getTopIndex () {
+ checkWidget();
+ int [] argList = {OS.XmNtopItemPosition, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] - 1;
+}
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNbrowseSelectionCallback, windowProc, BROWSE_SELECTION_CALLBACK);
+ OS.XtAddCallback (handle, OS.XmNextendedSelectionCallback, windowProc, EXTENDED_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
- * @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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</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
+ * @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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</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 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 () {
- Display display = getDisplay ();
- 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+public boolean isSelected (int index) {
+ checkWidget();
+ if (index == -1) return false;
+ return OS.XmListPosSelected (handle, index + 1);
+}
+void overrideTranslations () {
+ Display display = getDisplay ();
+ 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
-public void remove (int start, int end) {
- checkWidget();
- if (start > end) return;
- int count = end - start + 1;
- /*
- * 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 <= start && start < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- OS.XmListDeleteItemsPos (handle, count, start + 1);
- if (end >= argList [1]) error (SWT.ERROR_INVALID_RANGE);
-}
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+public void remove (int start, int end) {
+ checkWidget();
+ if (start > end) return;
+ int count = end - start + 1;
+ /*
+ * 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 <= start && start < argList [1])) {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ OS.XmListDeleteItemsPos (handle, count, start + 1);
+ if (end >= argList [1]) error (SWT.ERROR_INVALID_RANGE);
+}
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
-public void remove (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- /*
- * 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);
- int length = 0, count = argList [1];
- int [] newIndices = new int [indices.length];
- for (int i=0; i<indices.length; i++) {
- int index = indices [i];
- if (!(0 <= index && index < count)) break;
- newIndices [length++] = index + 1;
- }
- OS.XmListDeletePositions (handle, newIndices, length);
- if (length < indices.length) error (SWT.ERROR_INVALID_RANGE);
-}
-/**
- * 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 remove (int [] indices) {
+ checkWidget();
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
+ /*
+ * 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);
+ int length = 0, count = argList [1];
+ int [] newIndices = new int [indices.length];
+ for (int i=0; i<indices.length; i++) {
+ int index = indices [i];
+ if (!(0 <= index && index < count)) break;
+ newIndices [length++] = index + 1;
+ }
+ OS.XmListDeletePositions (handle, newIndices, length);
+ if (length < indices.length) error (SWT.ERROR_INVALID_RANGE);
+}
+/**
+ * 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 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 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 at the given zero-relative indices in the receiver.
- * If the item at the index was already selected, it remains
- * selected. The range of the indices is inclusive. Indices that are
- * out of range 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>
+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 at the given zero-relative indices in the receiver.
+ * If the item at the index was already selected, it remains
+ * selected. The range of the indices is inclusive. Indices that are
+ * out of range 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>
*/
-public void select (int start, int end) {
- checkWidget();
- if (start > end) return;
- if ((style & SWT.SINGLE) != 0) {
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int index = Math.min (argList[1] - 1, end) + 1;
- if (index != 0 && index >= start + 1) OS.XmListSelectPos (handle, index, 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.
- */
- 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=start; i<=end; i++) {
- int index = 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);
- }
-}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is not selected, it is selected. If the item at the index
- * was selected, it remains selected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 start, int end) {
+ checkWidget();
+ if (start > end) return;
+ if ((style & SWT.SINGLE) != 0) {
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int index = Math.min (argList[1] - 1, end) + 1;
+ if (index != 0 && index >= start + 1) OS.XmListSelectPos (handle, index, 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.
+ */
+ 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=start; i<=end; i++) {
+ int index = 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);
+ }
+}
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * If the item at the given zero-relative index in the receiver
+ * is not selected, it is selected. If the item at the index
+ * was selected, it remains selected. Indices that are out
+ * of range and duplicate indices are ignored.
+ *
+ * @param indices the array of indices for the items to select
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SINGLE) != 0) {
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int count = argList [1];
- for (int i = 0; i < indices.length; i++) {
- int index = indices [i];
- if (0 <= index && index < count) {
- select (index);
- return;
- }
- }
- 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<indices.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 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 void select (int [] indices) {
+ checkWidget();
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.SINGLE) != 0) {
+ int [] argList = {OS.XmNitemCount, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int count = argList [1];
+ for (int i = 0; i < indices.length; i++) {
+ int index = indices [i];
+ if (0 <= index && index < count) {
+ select (index);
+ return;
+ }
+ }
+ 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<indices.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 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 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 layed
- * 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) {
- OS.XmListSetKbdItemPos (handle, index + 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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
- * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</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 layed
+ * 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) {
+ OS.XmListSetKbdItemPos (handle, index + 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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
+ * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
+ * </ul>
*/
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_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];
- if (string == null) break;
- 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 selected 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>
- * @see List#deselectAll()
- * @see List#select(int)
+public void setItems (String [] items) {
+ checkWidget();
+ if (items == null) error (SWT.ERROR_NULL_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];
+ if (string == null) break;
+ 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 selected 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>
+ * @see List#deselectAll()
+ * @see List#select(int)
*/
-public void setSelection (int index) {
- checkWidget();
- if ((style & SWT.MULTI) != 0) deselectAll ();
- select (index);
- showSelection ();
-}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selected if first cleared, then the new items are selected.
- *
- * @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 index) {
+ checkWidget();
+ if ((style & SWT.MULTI) != 0) deselectAll ();
+ select (index);
+ showSelection ();
+}
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * The current selected if first cleared, then the new items are selected.
+ *
+ * @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();
- if ((style & SWT.MULTI) != 0) deselectAll ();
- select (start, end);
- showSelection ();
-}
+public void setSelection (int start, int end) {
+ checkWidget();
+ if ((style & SWT.MULTI) != 0) deselectAll ();
+ select (start, end);
+ showSelection ();
+}
/**
* Selects the items at the given zero-relative indices in the receiver.
* The current selection is first cleared, then the new items are selected.
@@ -1368,153 +1368,153 @@ public void setSelection (int start, int end) {
* @see List#deselectAll()
* @see List#select(int[])
*/
-public void setSelection(int[] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- select (indices);
- showSelection ();
-}
-/**
- * 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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 ();
+ select (indices);
+ showSelection ();
+}
+/**
+ * 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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- String codePage = getCodePage ();
- if ((style & SWT.SINGLE) != 0) {
- for (int i=items.length-1; i>=0; --i) {
- String string = items [i];
- 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;
- }
- }
- }
- }
- OS.XmListDeselectAllItems (handle);
- return;
- }
- OS.XmListDeselectAllItems (handle);
- int length = 0;
- int [] table = new int [items.length];
- for (int i=0; i<items.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 [length++] = xmString;
- }
- }
- int ptr = OS.XtMalloc (length * 4);
- OS.memmove (ptr, table, length * 4);
- int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, length};
- OS.XtSetValues (handle, argList, argList.length / 2);
- for (int i=0; i<length; i++) 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 setSelection (String [] items) {
+ checkWidget();
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+ String codePage = getCodePage ();
+ if ((style & SWT.SINGLE) != 0) {
+ for (int i=items.length-1; i>=0; --i) {
+ String string = items [i];
+ 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;
+ }
+ }
+ }
+ }
+ OS.XmListDeselectAllItems (handle);
+ return;
+ }
+ OS.XmListDeselectAllItems (handle);
+ int length = 0;
+ int [] table = new int [items.length];
+ for (int i=0; i<items.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 [length++] = xmString;
+ }
+ }
+ int ptr = OS.XtMalloc (length * 4);
+ OS.memmove (ptr, table, length * 4);
+ int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, length};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ for (int i=0; i<length; i++) 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 IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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;
-}
-}
+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;
+}
+}
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
index 6936e67c53..e46db0de49 100755
--- 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
@@ -1,36 +1,36 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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</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.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class Menu extends Widget {
- boolean hasLocation;
- MenuItem cascade, defaultItem;
- Decorations parent;
+
+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</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.
+ * </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
@@ -50,9 +50,9 @@ public class Menu extends Widget {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Menu (Control parent) {
- this (checkNull(parent).getShell (), SWT.POP_UP);
-}
+public Menu (Control parent) {
+ this (checkNull(parent).getShell (), SWT.POP_UP);
+}
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Decorations</code>) and a style value
@@ -84,11 +84,11 @@ public Menu (Control parent) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Menu (Decorations parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
+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
@@ -109,9 +109,9 @@ public Menu (Decorations parent, int style) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Menu (Menu parentMenu) {
- this (checkNull(parentMenu).parent, SWT.DROP_DOWN);
-}
+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
@@ -132,16 +132,16 @@ public Menu (Menu parentMenu) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Menu (MenuItem parentItem) {
- this (checkNull(parentItem).parent);
-}
-void addAccelerators () {
- MenuItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items[i];
- item.addAccelerators ();
- }
-}
+public Menu (MenuItem parentItem) {
+ this (checkNull(parentItem).parent);
+}
+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,
@@ -161,12 +161,12 @@ void addAccelerators () {
* @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);
-}
+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
@@ -186,656 +186,656 @@ public void addHelpListener (HelpListener listener) {
* @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) {
- state |= HANDLE;
-
- /*
- * 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.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 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) {
+ state |= HANDLE;
+
+ /*
+ * 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.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;
-}
-public Display getDisplay () {
- Decorations parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/**
- * 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>
+public MenuItem getDefaultItem () {
+ checkWidget();
+ return defaultItem;
+}
+public Display getDisplay () {
+ Decorations parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+ * 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>
*/
-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 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 = WidgetTable.get (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 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 = WidgetTable.get (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 an 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 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 an 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 = WidgetTable.get (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 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 = WidgetTable.get (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 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 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 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 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();
- return OS.XtIsManaged (handle);
-}
-void hookEvents () {
- int windowProc = getDisplay ().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 boolean getVisible () {
+ checkWidget();
+ return OS.XtIsManaged (handle);
+}
+void hookEvents () {
+ int windowProc = getDisplay ().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 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 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 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();
- 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 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 releaseChild () {
- super.releaseChild ();
- if (cascade != null) cascade.setMenu (null);
- if ((style & SWT.BAR) != 0 && this == parent.menuBar) parent.setMenuBar (null);
-}
-void releaseWidget () {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (!item.isDisposed ()) item.releaseResources ();
- }
- super.releaseWidget ();
- if (parent != null) parent.remove (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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 boolean isVisible () {
+ checkWidget();
+ return getVisible ();
+}
+void releaseChild () {
+ super.releaseChild ();
+ if (cascade != null) cascade.setMenu (null);
+ if ((style & SWT.BAR) != 0 && this == parent.menuBar) parent.setMenuBar (null);
+}
+void releaseWidget () {
+ MenuItem [] items = getItems ();
+ for (int i=0; i<items.length; i++) {
+ MenuItem item = items [i];
+ if (!item.isDisposed ()) item.releaseResources ();
+ }
+ super.releaseWidget ();
+ if (parent != null) parent.remove (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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 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 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 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 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 receiver's location to the point specified by
- * the arguments which are relative to the display.
- * <p>
- * Note: 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 setEnabled (boolean enabled) {
+ checkWidget();
+ int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+ * Sets the receiver's location to the point specified by
+ * the arguments which are relative to the display.
+ * <p>
+ * Note: 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 ((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;
-}
-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 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;
+}
+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) {
- 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);
- }
-}
-boolean translateAccelerator (int accel) {
- if (!getEnabled ()) return false;
- MenuItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items [i];
- if (item.translateAccelerator (accel)) 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;
- /*
- * SWT.Selection events are posted to allow stepping
- * in the VA/Java debugger. SWT.Show events are
- * sent to ensure that application event handler
- * code runs before the menu is displayed. This
- * means that SWT.Show events would normally occur
- * before SWT.Selection events. While this is not
- * strictly incorrect, applications often use the
- * SWT.Selection event to update the state of menu
- * items and would like the ordering of events to
- * be the other way around.
- *
- * The fix is to run the deferred events before
- * the menu is shown. This means that stepping
- * through a selection event that was caused by
- * a popup menu will fail in VA/Java.
- */
- Display display = getDisplay ();
- display.runDeferredEvents ();
- sendEvent (SWT.Show);
- return 0;
-}
-int XmNunmapCallback (int w, int client_data, int call_data) {
- sendEvent (SWT.Hide);
- return 0;
-}
-}
+public void setVisible (boolean visible) {
+ checkWidget();
+ 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);
+ }
+}
+boolean translateAccelerator (int accel) {
+ if (!getEnabled ()) return false;
+ MenuItem [] items = getItems ();
+ for (int i = 0; i < items.length; i++) {
+ MenuItem item = items [i];
+ if (item.translateAccelerator (accel)) 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;
+ /*
+ * SWT.Selection events are posted to allow stepping
+ * in the VA/Java debugger. SWT.Show events are
+ * sent to ensure that application event handler
+ * code runs before the menu is displayed. This
+ * means that SWT.Show events would normally occur
+ * before SWT.Selection events. While this is not
+ * strictly incorrect, applications often use the
+ * SWT.Selection event to update the state of menu
+ * items and would like the ordering of events to
+ * be the other way around.
+ *
+ * The fix is to run the deferred events before
+ * the menu is shown. This means that stepping
+ * through a selection event that was caused by
+ * a popup menu will fail in VA/Java.
+ */
+ Display display = getDisplay ();
+ display.runDeferredEvents ();
+ 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
index fd62d8e11c..dd232c3970 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+
/**
* Instances of this class represent a selectable user interface object
* that issues notification when pressed and released.
@@ -28,10 +28,10 @@ import org.eclipse.swt.events.*;
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
-public class MenuItem extends Item {
- int accelerator;
- Menu parent, menu;
-
+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
@@ -66,12 +66,12 @@ public class MenuItem extends Item {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public MenuItem (Menu parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (OS.XmLAST_POSITION);
-}
-
+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
@@ -107,538 +107,538 @@ public MenuItem (Menu parent, int style) {
* @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) 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 = wcsToMbcs ((char) keysym);
- }
- /*
- * Feature in Motif. Motif does not activate an accelerator
- * when the CapsLoc, NumLoc and NumLock+CapsLoc keys are pressed.
- * In order to activate accelerators when these keys are pressed,
- * it is necessary to look for all of these key sequences.
- */
- String key = ctrl + alt + shift + "<Key>" + keysymName (keysym);
- String allKeys = key + ",Lock " + key + ",Mod2 " + key + ",Lock Mod2 " + 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 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) 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 = wcsToMbcs ((char) keysym);
+ }
+ /*
+ * Feature in Motif. Motif does not activate an accelerator
+ * when the CapsLoc, NumLoc and NumLock+CapsLoc keys are pressed.
+ * In order to activate accelerators when these keys are pressed,
+ * it is necessary to look for all of these key sequences.
+ */
+ String key = ctrl + alt + shift + "<Key>" + keysymName (keysym);
+ String allKeys = key + ",Lock " + key + ",Mod2 " + key + ",Lock Mod2 " + 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 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 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 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 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 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 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;
- 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 ();
-}
-/**
- * Return 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>.
- *
- * @return the accelerator
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+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;
+ 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 ();
+}
+/**
+ * Return 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>.
+ *
+ * @return the accelerator
+ *
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 Display getDisplay () {
- Menu parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/**
- * 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>
+public int getAccelerator () {
+ checkWidget();
+ return accelerator;
+}
+public Display getDisplay () {
+ Menu parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+ * 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>
*/
-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 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 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 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 = getDisplay ().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;
- }
- 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 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 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 = getDisplay ().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;
+ }
+ 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 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 () {
- return getEnabled () && parent.isEnabled ();
-}
-String keysymName (int keysym) {
- switch (keysym) {
- case 8: return "BackSpace";
- case 9: 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 10:
-// case OS.XK_Linefeed: return "Linefeed";
- case 10:
- case OS.XK_Linefeed:
- case 13: return "Return";
- case 27: return "Escape";
- case 127: 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.
+public boolean isEnabled () {
+ return getEnabled () && parent.isEnabled ();
+}
+String keysymName (int keysym) {
+ switch (keysym) {
+ case 8: return "BackSpace";
+ case 9: 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 10:
+// case OS.XK_Linefeed: return "Linefeed";
+ case 10:
+ case OS.XK_Linefeed:
+ case 13: return "Return";
+ case 27: return "Escape";
+ case 127: 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 releaseChild () {
- super.releaseChild ();
- if (menu != null) menu.dispose ();
- menu = null;
-}
-void releaseWidget () {
- if (menu != null && !menu.isDisposed ()) menu.releaseResources ();
- menu = null;
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
+ 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 releaseChild () {
+ super.releaseChild ();
+ if (menu != null) menu.dispose ();
+ menu = null;
+}
+void releaseWidget () {
+ if (menu != null && !menu.isDisposed ()) menu.releaseResources ();
+ menu = null;
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
- *
- * @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 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.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>.
+ *
+ * @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 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 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 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);
-}
+public void setEnabled (boolean enabled) {
+ checkWidget();
+ int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
/**
* Sets the receiver's pull down menu to the argument.
* Only <code>CASCADE</code> menu items can have a
@@ -659,236 +659,236 @@ public void setEnabled (boolean enabled) {
* <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;
-
+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 ();
+ */
+ 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};
+
+ 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>
+
+ 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);
-}
-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++]) == Mnemonic) {
- if (i == text.length) {continue;}
- if (text [i] == Mnemonic) {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
- j--;
- }
- }
- byte [] buffer2;
- 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 */
- buffer2 = Converter.wcsToMbcs (null, accelText, true);
- } else {
- buffer2 = new byte [1];
- }
- int xmString2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- 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.XmNlabelType, OS.XmSTRING,
- 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) {
- if (!getEnabled ()) return false;
- if (menu != null) return menu.translateAccelerator (accel);
- 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) {
- postEvent (SWT.Selection);
- return true;
- }
- return false;
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- if ((style & SWT.CASCADE) != 0) {
- postEvent (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, XAnyEvent.sizeof);
- event.time = xEvent.time;
- switch (xEvent.type) {
- case OS.ButtonPress:
- case OS.ButtonRelease:
- case OS.KeyPress:
- case OS.KeyRelease:
- setInputState (event, xEvent);
- break;
- }
- }
- postEvent (SWT.Selection, event);
- return 0;
-}
-int XmNarmCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Arm);
- return 0;
-}
-int XmNcascadingCallback (int w, int client_data, int call_data) {
- postEvent (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, XAnyEvent.sizeof);
- event.time = xEvent.time;
- switch (xEvent.type) {
- case OS.ButtonPress:
- case OS.ButtonRelease:
- case OS.KeyPress:
- case OS.KeyRelease:
- setInputState (event, xEvent);
- break;
- }
- }
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- postEvent (SWT.Selection, event);
- return 0;
-}
-
-}
+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);
+}
+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++]) == Mnemonic) {
+ if (i == text.length) {continue;}
+ if (text [i] == Mnemonic) {i++; continue;}
+ if (mnemonic == 0) mnemonic = text [i];
+ j--;
+ }
+ }
+ byte [] buffer2;
+ 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 */
+ buffer2 = Converter.wcsToMbcs (null, accelText, true);
+ } else {
+ buffer2 = new byte [1];
+ }
+ int xmString2 = OS.XmStringParseText (
+ buffer2,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ 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.XmNlabelType, OS.XmSTRING,
+ 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) {
+ if (!getEnabled ()) return false;
+ if (menu != null) return menu.translateAccelerator (accel);
+ 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) {
+ postEvent (SWT.Selection);
+ return true;
+ }
+ return false;
+}
+int XmNactivateCallback (int w, int client_data, int call_data) {
+ if ((style & SWT.CASCADE) != 0) {
+ postEvent (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, XAnyEvent.sizeof);
+ event.time = xEvent.time;
+ switch (xEvent.type) {
+ case OS.ButtonPress:
+ case OS.ButtonRelease:
+ case OS.KeyPress:
+ case OS.KeyRelease:
+ setInputState (event, xEvent);
+ break;
+ }
+ }
+ postEvent (SWT.Selection, event);
+ return 0;
+}
+int XmNarmCallback (int w, int client_data, int call_data) {
+ postEvent (SWT.Arm);
+ return 0;
+}
+int XmNcascadingCallback (int w, int client_data, int call_data) {
+ postEvent (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, XAnyEvent.sizeof);
+ event.time = xEvent.time;
+ switch (xEvent.type) {
+ case OS.ButtonPress:
+ case OS.ButtonRelease:
+ case OS.KeyPress:
+ case OS.KeyRelease:
+ setInputState (event, xEvent);
+ 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
index d9609a1cfa..b2a2b8d0ab 100755
--- 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
@@ -1,67 +1,67 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class MessageBox extends Dialog {
- int button;
- String message = "";
-
-/**
- * Constructs a new instance of this class given only its
- * parent.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
+
+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 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 = "";
+
+/**
+ * Constructs a new instance of this class given only its
+ * parent.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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);
-}
-
+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.
@@ -92,322 +92,322 @@ public MessageBox (Shell parent) {
* <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);
- return OS.XmCreateMessageDialog (parentHandle, null, argList, argList.length / 2);
-}
-
-/**
- * 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 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);
+ return OS.XmCreateMessageDialog (parentHandle, null, argList, argList.length / 2);
+}
+
+/**
+ * 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 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 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 () {
-
- /* Create the dialog.*/
- boolean destroyContext;
- Display appContext = Display.getCurrent ();
- if (destroyContext = (appContext == null)) appContext = new Display ();
- int parentHandle = appContext.shellHandle;
- if (parent != null && parent.getDisplay () == appContext)
- parentHandle = parent.shellHandle;
-
- /* 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 = " ";
- /* 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 (parent != null && dialogStyle == OS.XmDIALOG_MODELESS) {
- dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL;
- }
- int [] argList = {
- OS.XmNnoResize, 1,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNdialogStyle, dialogStyle,
- OS.XmNdialogTitle, xmStringPtr,
- };
- int dialog = createHandle (parentHandle, argList);
- OS.XmStringFree (xmStringPtr);
- setMessage (dialog);
- setButtons (dialog);
-
- /* Hook the callbacks. */
- Callback callback = new Callback (this, "activate", 3);
- int address = callback.getAddress ();
- 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. */
- OS.XtManageChild (dialog);
-
- // Should be a pure OS message loop (no SWT AppContext)
- while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
- if (!appContext.readAndDispatch()) appContext.sleep ();
-
- /* Destroy the dialog and update the display. */
- if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
- if (destroyContext) appContext.dispose ();
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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.getDisplay ();
- 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
+public int open () {
+
+ /* Create the dialog.*/
+ boolean destroyContext;
+ Display appContext = Display.getCurrent ();
+ if (destroyContext = (appContext == null)) appContext = new Display ();
+ int parentHandle = appContext.shellHandle;
+ if (parent != null && parent.getDisplay () == appContext)
+ parentHandle = parent.shellHandle;
+
+ /* 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 = " ";
+ /* 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 (parent != null && dialogStyle == OS.XmDIALOG_MODELESS) {
+ dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL;
+ }
+ int [] argList = {
+ OS.XmNnoResize, 1,
+ OS.XmNresizePolicy, OS.XmRESIZE_NONE,
+ OS.XmNdialogStyle, dialogStyle,
+ OS.XmNdialogTitle, xmStringPtr,
+ };
+ int dialog = createHandle (parentHandle, argList);
+ OS.XmStringFree (xmStringPtr);
+ setMessage (dialog);
+ setButtons (dialog);
+
+ /* Hook the callbacks. */
+ Callback callback = new Callback (this, "activate", 3);
+ int address = callback.getAddress ();
+ 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. */
+ OS.XtManageChild (dialog);
+
+ // Should be a pure OS message loop (no SWT AppContext)
+ while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
+ if (!appContext.readAndDispatch()) appContext.sleep ();
+
+ /* Destroy the dialog and update the display. */
+ if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
+ if (destroyContext) appContext.dispose ();
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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.getDisplay ();
+ 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
*/
-public void setMessage (String string) {
- message = string;
-}
-}
+public void setMessage (String string) {
+ 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
index a49debf6f5..d1a5fca885 100755
--- 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
@@ -1,38 +1,38 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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</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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class ProgressBar extends Control {
- int timerId;
- static final int DELAY = 100;
- int lastForeground = defaultForeground ();
-
+
+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</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 lastForeground = defaultForeground ();
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -63,329 +63,329 @@ public class ProgressBar extends Control {
* @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) {
- 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;
- Display display = getDisplay ();
- 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 |= HANDLE;
- 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 createTimer () {
- Display display = getDisplay ();
- 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;
-}
-void disableButtonPress () {
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int event_mask = OS.XtBuildEventMask (handle);
- XSetWindowAttributes attributes = new XSetWindowAttributes ();
- attributes.event_mask = event_mask & ~OS.ButtonPressMask;
- OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWEventMask, attributes);
-}
-int getForegroundPixel () {
- boolean invisible = lastForeground != -1;
- if (invisible) return lastForeground;
- return super.getForegroundPixel ();
-}
-/**
- * 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 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) {
+ 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;
+ Display display = getDisplay ();
+ 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 |= HANDLE;
+ 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 createTimer () {
+ Display display = getDisplay ();
+ 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;
+}
+void disableButtonPress () {
+ int xWindow = OS.XtWindow (handle);
+ if (xWindow == 0) return;
+ int xDisplay = OS.XtDisplay (handle);
+ if (xDisplay == 0) return;
+ int event_mask = OS.XtBuildEventMask (handle);
+ XSetWindowAttributes attributes = new XSetWindowAttributes ();
+ attributes.event_mask = event_mask & ~OS.ButtonPressMask;
+ OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWEventMask, attributes);
+}
+int getForegroundPixel () {
+ boolean invisible = lastForeground != -1;
+ if (invisible) return lastForeground;
+ return super.getForegroundPixel ();
+}
+/**
+ * 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 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 <em>selection</em> 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];
+ boolean invisible = lastForeground != -1;
+ if (invisible) sliderSize = 0;
+ return minimum + sliderSize;
+}
+void propagateWidget (boolean enabled) {
+ super.propagateWidget (enabled);
+ if (enabled) disableButtonPress ();
+}
+void realizeChildren () {
+ super.realizeChildren ();
+ disableButtonPress ();
+}
+void releaseWidget () {
+ super.releaseWidget ();
+ destroyTimer ();
+}
+/**
+ * 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 int getMinimum () {
- checkWidget();
- int [] argList = {OS.XmNminimum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the single <em>selection</em> 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 void setBackground (Color color) {
+ checkWidget();
+ super.setBackground (color);
+ boolean invisible = lastForeground != -1;
+ if (invisible) {
+ int [] argList = {
+ OS.XmNtroughColor, 0
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ setForegroundPixel (argList [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 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];
- boolean invisible = lastForeground != -1;
- if (invisible) sliderSize = 0;
- return minimum + sliderSize;
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- if (enabled) disableButtonPress ();
-}
-void realizeChildren () {
- super.realizeChildren ();
- disableButtonPress ();
-}
-void releaseWidget () {
- super.releaseWidget ();
- destroyTimer ();
-}
-/**
- * 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();
- super.setBackground (color);
- boolean invisible = lastForeground != -1;
- if (invisible) {
- int [] argList = {
- OS.XmNtroughColor, 0
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- setForegroundPixel (argList [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();
- boolean invisible = lastForeground != -1;
- if (invisible) {
- lastForeground = color.handle.pixel;
- } else {
- super.setForeground (color);
- }
-}
-/**
- * Sets the maximum value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new maximum (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 setForeground (Color color) {
+ checkWidget();
+ boolean invisible = lastForeground != -1;
+ if (invisible) {
+ lastForeground = color.handle.pixel;
+ } else {
+ super.setForeground (color);
+ }
+}
+/**
+ * Sets the maximum value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new maximum (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 setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {OS.XmNmaximum, value, OS.XmNvalue, 0};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the minimum value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new minimum (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 setMaximum (int value) {
+ checkWidget();
+ if (value < 0) return;
+ int [] argList = {OS.XmNmaximum, value, OS.XmNvalue, 0};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+ * Sets the minimum value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new minimum (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 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;
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
- setThumb(selection - value);
-}
-/**
- * Sets the single <em>selection</em> 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 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;
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+ setThumb(selection - value);
+}
+/**
+ * Sets the single <em>selection</em> 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);
-}
-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];
-
- boolean invisible = lastForeground != -1;
- if (sliderSize == 0) {
- if (!invisible) {
- lastForeground = getForegroundPixel ();
- setForegroundPixel (troughColor);
- }
- } else {
- if (invisible) {
- setForegroundPixel (lastForeground);
- lastForeground = -1;
- }
- }
- int [] argList2 = new int [] {
- OS.XmNsliderSize, (sliderSize == 0) ? 1 : sliderSize,
- OS.XmNvalue, argList1 [3]
- };
-
- Display display = getDisplay ();
- 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;
-}
-}
+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);
+}
+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];
+
+ boolean invisible = lastForeground != -1;
+ if (sliderSize == 0) {
+ if (!invisible) {
+ lastForeground = getForegroundPixel ();
+ setForegroundPixel (troughColor);
+ }
+ } else {
+ if (invisible) {
+ setForegroundPixel (lastForeground);
+ lastForeground = -1;
+ }
+ }
+ int [] argList2 = new int [] {
+ OS.XmNsliderSize, (sliderSize == 0) ? 1 : sliderSize,
+ OS.XmNvalue, argList1 [3]
+ };
+
+ Display display = getDisplay ();
+ 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;
+}
+}
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
index a6974f77c4..198d9fbbbe 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -29,15 +29,15 @@ import org.eclipse.swt.events.*;
* within the SWT implementation.
* </p>
*/
-public class Sash extends Control {
- boolean dragging;
- int startX, startY, lastX, lastY;
- int cursor;
-
- // constants
- private final static int INCREMENT = 1;
- private final static int PAGE_INCREMENT = 9;
-
+public class Sash extends Control {
+ boolean dragging;
+ int startX, startY, lastX, lastY;
+ int cursor;
+
+ // constants
+ 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.
@@ -67,344 +67,344 @@ public class Sash extends Control {
* @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 reciever 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 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 reciever 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 |= HANDLE;
- 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) {
- int display = OS.XtDisplay (parent.handle);
- if (display == 0) return;
- int window = OS.XtWindow (parent.handle);
- if (window == 0) return;
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- OS.XtGetValues (parent.handle, argList, argList.length / 2);
- int color = argList [1] ^ argList [3];
- 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 realizeChildren () {
- super.realizeChildren ();
- int window = OS.XtWindow (handle);
- if (window == 0) return;
- int display = OS.XtDisplay (handle);
- if (display == 0) return;
- if ((style & SWT.HORIZONTAL) != 0) {
- cursor = OS.XCreateFontCursor (display, OS.XC_sb_v_double_arrow);
- } else {
- cursor = OS.XCreateFontCursor (display, OS.XC_sb_h_double_arrow);
- }
- OS.XDefineCursor (display, window, cursor);
-}
-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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 |= HANDLE;
+ 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) {
+ int display = OS.XtDisplay (parent.handle);
+ if (display == 0) return;
+ int window = OS.XtWindow (parent.handle);
+ if (window == 0) return;
+ int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
+ OS.XtGetValues (parent.handle, argList, argList.length / 2);
+ int color = argList [1] ^ argList [3];
+ 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 realizeChildren () {
+ super.realizeChildren ();
+ int window = OS.XtWindow (handle);
+ if (window == 0) return;
+ int display = OS.XtDisplay (handle);
+ if (display == 0) return;
+ if ((style & SWT.HORIZONTAL) != 0) {
+ cursor = OS.XCreateFontCursor (display, OS.XC_sb_v_double_arrow);
+ } else {
+ cursor = OS.XCreateFontCursor (display, OS.XC_sb_h_double_arrow);
+ }
+ OS.XDefineCursor (display, window, cursor);
+}
+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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 boolean setFocus () {
- checkWidget();
- int [] argList = new int [] {OS.XmNtraversalOn, 1};
- OS.XtSetValues (handle, argList, argList.length / 2);
- overrideTranslations ();
- if (super.setFocus ()) return true;
- argList [1] = 0;
- OS.XtSetValues (handle, argList, argList.length / 2);
- return false;
-}
-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;
- startX = xEvent.x; startY = xEvent.y;
- 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;
- /* The event must be sent because its doit flag is used. */
- Event event = new Event ();
- event.detail = SWT.DRAG;
- event.time = xEvent.time;
- event.x = lastX; event.y = lastY;
- event.width = width; event.height = height;
- /*
- * It is possible (but unlikely) that client code could have disposed
- * the widget in the selection event. If this happens end the processing
- * of this message by returning.
- */
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- dragging = true;
- OS.XmUpdateDisplay (handle);
- drawBand (lastX = event.x, lastY = event.y, width, height);
- }
- 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);
- /* The event must be sent because its doit flag is used. */
- 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);
- /* widget could be disposed here */
- return result;
-}
-int xFocusIn () {
- int result = super.xFocusIn ();
- 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 xFocusOut () {
- int result = super.xFocusOut ();
- if (handle == 0) return result;
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
- 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 = getDisplay().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);
-
- /* The event must be sent because its doit flag is used. */
- 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);
-
- /*
- * It is possible (but unlikely) that client code could have disposed
- * the widget in the selection event. If this happens end the processing
- * of this message by returning.
- */
- if (isDisposed ()) break;
- if (event.doit) {
- lastX = event.x; lastY = event.y;
- /* Adjust the pointer position */
- int cursorX = newX; int cursorY = newY;
- 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;
- 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, xEvent.x + x - startX - parentBorder), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, xEvent.y + y - startY - parentBorder), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return result;
- drawBand (lastX, lastY, width, height);
- /* The event must be sent because its doit flag is used. */
- Event event = new Event ();
- event.detail = SWT.DRAG;
- event.time = xEvent.time;
- event.x = newX; event.y = newY;
- event.width = width; event.height = height;
- /*
- * It is possible (but unlikely) that client code could have disposed
- * the widget in the selection event. If this happens end the processing
- * of this message by returning.
- */
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- lastX = event.x; lastY = event.y;
- OS.XmUpdateDisplay (handle);
- drawBand (lastX, lastY, width, height);
- }
- return result;
-}
-}
+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 boolean setFocus () {
+ checkWidget();
+ int [] argList = new int [] {OS.XmNtraversalOn, 1};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ overrideTranslations ();
+ if (super.setFocus ()) return true;
+ argList [1] = 0;
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ return false;
+}
+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;
+ startX = xEvent.x; startY = xEvent.y;
+ 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;
+ /* The event must be sent because its doit flag is used. */
+ Event event = new Event ();
+ event.detail = SWT.DRAG;
+ event.time = xEvent.time;
+ event.x = lastX; event.y = lastY;
+ event.width = width; event.height = height;
+ /*
+ * It is possible (but unlikely) that client code could have disposed
+ * the widget in the selection event. If this happens end the processing
+ * of this message by returning.
+ */
+ sendEvent (SWT.Selection, event);
+ if (isDisposed ()) return result;
+ if (event.doit) {
+ dragging = true;
+ OS.XmUpdateDisplay (handle);
+ drawBand (lastX = event.x, lastY = event.y, width, height);
+ }
+ 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);
+ /* The event must be sent because its doit flag is used. */
+ 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);
+ /* widget could be disposed here */
+ return result;
+}
+int xFocusIn () {
+ int result = super.xFocusIn ();
+ 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 xFocusOut () {
+ int result = super.xFocusOut ();
+ if (handle == 0) return result;
+ int [] argList = new int [] {OS.XmNtraversalOn, 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ 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 = getDisplay().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);
+
+ /* The event must be sent because its doit flag is used. */
+ 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);
+
+ /*
+ * It is possible (but unlikely) that client code could have disposed
+ * the widget in the selection event. If this happens end the processing
+ * of this message by returning.
+ */
+ if (isDisposed ()) break;
+ if (event.doit) {
+ lastX = event.x; lastY = event.y;
+ /* Adjust the pointer position */
+ int cursorX = newX; int cursorY = newY;
+ 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;
+ 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, xEvent.x + x - startX - parentBorder), parentWidth - width);
+ } else {
+ newY = Math.min (Math.max (0, xEvent.y + y - startY - parentBorder), parentHeight - height);
+ }
+ if (newX == lastX && newY == lastY) return result;
+ drawBand (lastX, lastY, width, height);
+ /* The event must be sent because its doit flag is used. */
+ Event event = new Event ();
+ event.detail = SWT.DRAG;
+ event.time = xEvent.time;
+ event.x = newX; event.y = newY;
+ event.width = width; event.height = height;
+ /*
+ * It is possible (but unlikely) that client code could have disposed
+ * the widget in the selection event. If this happens end the processing
+ * of this message by returning.
+ */
+ sendEvent (SWT.Selection, event);
+ if (isDisposed ()) return result;
+ if (event.doit) {
+ lastX = event.x; lastY = event.y;
+ OS.XmUpdateDisplay (handle);
+ drawBand (lastX, lastY, width, height);
+ }
+ 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
index 2c8baea84f..b346ac3429 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -30,7 +30,7 @@ import org.eclipse.swt.graphics.*;
* within the SWT implementation.
* </p>
*/
-public class Scale extends Control {
+public class Scale extends Control {
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -60,296 +60,296 @@ public class Scale extends Control {
* @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.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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.
+ *
+ * @param listener the listener which should be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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;
- Display display = getDisplay ();
- 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 |= HANDLE;
- 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);
-}
-/**
- * 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 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;
+ Display display = getDisplay ();
+ 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 |= HANDLE;
+ 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);
+}
+/**
+ * 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 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 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 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 single <em>selection</em> 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 getPageIncrement () {
+ checkWidget();
+ int [] argList = {OS.XmNscaleMultiple, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+ * Returns the single <em>selection</em> 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.XmNvalue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = getDisplay ().windowProc;
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK);
-}
-void overrideTranslations () {
- Display display = getDisplay ();
- 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 int getSelection () {
+ checkWidget();
+ int [] argList = {OS.XmNvalue, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().windowProc;
+ OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
+ OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK);
+}
+void overrideTranslations () {
+ Display display = getDisplay ();
+ 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);
-}
-/**
- * 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 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 increment) {
- checkWidget();
-}
-/**
- * Sets the maximum value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new maximum (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 setIncrement (int increment) {
+ checkWidget();
+}
+/**
+ * Sets the maximum value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new maximum (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 setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {OS.XmNmaximum, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the minimum value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new minimum (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 setMaximum (int value) {
+ checkWidget();
+ if (value < 0) return;
+ int [] argList = {OS.XmNmaximum, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+ * Sets the minimum value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new minimum (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 setMinimum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {OS.XmNminimum, value};
- Display display = getDisplay ();
- 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.
- *
- * @return 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 setMinimum (int value) {
+ checkWidget();
+ if (value < 0) return;
+ int [] argList = {OS.XmNminimum, value};
+ Display display = getDisplay ();
+ 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.
+ *
+ * @return 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};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * 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 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 setPageIncrement (int pageIncrement) {
+ checkWidget();
+ if (pageIncrement < 1) return;
+ int [] argList = {OS.XmNscaleMultiple, pageIncrement};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+ * 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 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};
- Display display = getDisplay ();
- 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;
-}
-}
+public void setSelection (int selection) {
+ checkWidget();
+ int [] argList = {OS.XmNvalue, selection};
+ Display display = getDisplay ();
+ 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
index aa747274b5..8887ae6463 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -75,608 +75,608 @@ import org.eclipse.swt.events.*;
* @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>0</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 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>0</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;
- 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);
-}
-public Display getDisplay () {
- Scrollable parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/**
- * 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 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 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;
+ 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);
+}
+public Display getDisplay () {
+ Scrollable parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+ * 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 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 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 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 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 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 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 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 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 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 <em>selection</em> 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 Scrollable getParent () {
+ checkWidget();
+ return parent;
+}
+/**
+ * Returns the single <em>selection</em> 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 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);
-}
-/**
- * Answers 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 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);
+}
+/**
+ * Answers 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 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 = getDisplay ().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 getVisible () {
+ checkWidget();
+ return OS.XtIsManaged (handle);
+}
+void hookEvents () {
+ int windowProc = getDisplay ().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 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 () {
- OS.XtManageChild (handle);
-}
-void propagateWidget (boolean enabled) {
- propagateHandle (enabled, handle);
-}
-void releaseChild () {
- super.releaseChild ();
- 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 boolean isVisible () {
+ checkWidget();
+ return getVisible () && parent.isVisible ();
+}
+void manageChildren () {
+ OS.XtManageChild (handle);
+}
+void propagateWidget (boolean enabled) {
+ propagateHandle (enabled, handle);
+}
+void releaseChild () {
+ super.releaseChild ();
+ 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 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 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 value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new maximum (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 setIncrement (int value) {
+ checkWidget();
+ if (value < 1) return;
+ int [] argList = {OS.XmNincrement, value};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+ * Sets the maximum value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new maximum (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 setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {OS.XmNmaximum, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the minimum value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new minimum (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 setMaximum (int value) {
+ checkWidget();
+ if (value < 0) return;
+ int [] argList = {OS.XmNmaximum, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+ * Sets the minimum value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new minimum (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 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;
- Display display = getDisplay ();
- 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.
- *
- * @return 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 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;
+ Display display = getDisplay ();
+ 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.
+ *
+ * @return 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 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 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 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};
- Display display = getDisplay ();
- 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 to the
- * argument which must be at least one.
- *
- * @param value the new thumb value (must be at least 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 ScrollBar
+public void setSelection (int selection) {
+ checkWidget();
+ int [] argList = {OS.XmNvalue, selection};
+ Display display = getDisplay ();
+ 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 to the
+ * argument which must be at least one.
+ *
+ * @param value the new thumb value (must be at least 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 ScrollBar
*/
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- int [] argList = {OS.XmNsliderSize, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.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 equivalent 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 setThumb (int value) {
+ checkWidget();
+ if (value < 1) return;
+ int [] argList = {OS.XmNsliderSize, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.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 equivalent 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 (maximum - minimum - thumb < 0) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- int [] argList = {
- OS.XmNvalue, selection,
- OS.XmNminimum, minimum,
- OS.XmNmaximum, maximum,
- OS.XmNsliderSize, thumb,
- OS.XmNincrement, increment,
- OS.XmNpageIncrement, pageIncrement,
- };
- Display display = getDisplay ();
- 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 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 (maximum - minimum - thumb < 0) return;
+ if (increment < 1) return;
+ if (pageIncrement < 1) return;
+ int [] argList = {
+ OS.XmNvalue, selection,
+ OS.XmNminimum, minimum,
+ OS.XmNmaximum, maximum,
+ OS.XmNsliderSize, thumb,
+ OS.XmNincrement, increment,
+ OS.XmNpageIncrement, pageIncrement,
+ };
+ Display display = getDisplay ();
+ 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 (handle, 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;
-}
+public void setVisible (boolean visible) {
+ checkWidget();
+ parent.setScrollbarVisible (handle, 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;
+}
} \ No newline at end of file
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
index 7aa4a6a2a2..68f489b465 100755
--- 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
@@ -1,36 +1,36 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public abstract class Scrollable extends Control {
- int scrolledHandle, formHandle;
- ScrollBar horizontalBar, verticalBar;
-Scrollable () {
- /* Do nothing */
-}
+
+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.
@@ -60,268 +60,268 @@ Scrollable () {
* @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>
- *
- * @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 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>
+ *
+ * @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) {
- Display display = getDisplay ();
- 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) {
- Display display = getDisplay ();
- 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.state |= HANDLE;
- 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) WidgetTable.remove (formHandle);
- if (scrolledHandle != 0) WidgetTable.remove (scrolledHandle);
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- if (formHandle != 0) enableHandle (enabled, formHandle);
- if (scrolledHandle != 0) {
- enableHandle (enabled, scrolledHandle);
- int [] argList = {
- OS.XmNhorizontalScrollBar, 0,
- OS.XmNverticalScrollBar, 0,
- };
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- if (argList [1] != 0) enableHandle (enabled, argList [1]);
- if (argList [3] != 0) enableHandle (enabled, argList [3]);
- }
-}
-/**
- * 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 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) {
+ Display display = getDisplay ();
+ 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) {
+ Display display = getDisplay ();
+ 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.state |= HANDLE;
+ 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) WidgetTable.remove (formHandle);
+ if (scrolledHandle != 0) WidgetTable.remove (scrolledHandle);
+}
+void enableWidget (boolean enabled) {
+ super.enableWidget (enabled);
+ if (formHandle != 0) enableHandle (enabled, formHandle);
+ if (scrolledHandle != 0) {
+ enableHandle (enabled, scrolledHandle);
+ int [] argList = {
+ OS.XmNhorizontalScrollBar, 0,
+ OS.XmNverticalScrollBar, 0,
+ };
+ OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
+ if (argList [1] != 0) enableHandle (enabled, argList [1]);
+ if (argList [3] != 0) enableHandle (enabled, argList [3]);
+ }
+}
+/**
+ * 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 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 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 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);
- if (scrolledHandle != 0) {
- propagateHandle (enabled, scrolledHandle);
- if (horizontalBar != null) horizontalBar.propagateWidget (enabled);
- if (verticalBar != null) verticalBar.propagateWidget (enabled);
- }
-}
-void redrawWidget (int x, int y, int width, int height, boolean all) {
- super.redrawWidget (x, y, width, height, all);
- /*
- * Uncomment this code to force the window trimmings to redraw.
- */
-// 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, 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, 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, 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, verticalHandle);
-// }
-// }
-}
-void register () {
- super.register ();
- if (formHandle != 0) WidgetTable.put (formHandle, this);
- if (scrolledHandle != 0) WidgetTable.put (scrolledHandle, this);
-}
-void releaseHandle () {
- super.releaseHandle ();
- scrolledHandle = formHandle = 0;
-}
-void releaseWidget () {
- if (horizontalBar != null) horizontalBar.releaseResources ();
- if (verticalBar != null) verticalBar.releaseResources ();
- horizontalBar = verticalBar = null;
- super.releaseWidget ();
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- 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 setScrollbarVisible (int barHandle, boolean visible) {
- if (scrolledHandle == 0) return;
- /*
- * 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.XtGetValues (scrolledHandle, argList, argList.length / 2);
-
- /* Hide or show the scroll bar */
- if (visible) {
- OS.XtManageChild (barHandle);
- } else {
- OS.XtUnmanageChild (barHandle);
- }
-
- /* Restore the size */
- OS.XtSetValues (scrolledHandle, argList, argList.length / 2);
-}
-int topHandle () {
- if (scrolledHandle != 0) return scrolledHandle;
- if (formHandle != 0) return formHandle;
- return handle;
-}
-}
+public ScrollBar getVerticalBar () {
+ checkWidget();
+ return verticalBar;
+}
+boolean isTabGroup () {
+ if ((state & CANVAS) != 0) return true;
+ return super.isTabGroup ();
+}
+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);
+ if (scrolledHandle != 0) {
+ propagateHandle (enabled, scrolledHandle);
+ if (horizontalBar != null) horizontalBar.propagateWidget (enabled);
+ if (verticalBar != null) verticalBar.propagateWidget (enabled);
+ }
+}
+void redrawWidget (int x, int y, int width, int height, boolean all) {
+ super.redrawWidget (x, y, width, height, all);
+ /*
+ * Uncomment this code to force the window trimmings to redraw.
+ */
+// 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, 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, 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, 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, verticalHandle);
+// }
+// }
+}
+void register () {
+ super.register ();
+ if (formHandle != 0) WidgetTable.put (formHandle, this);
+ if (scrolledHandle != 0) WidgetTable.put (scrolledHandle, this);
+}
+void releaseHandle () {
+ super.releaseHandle ();
+ scrolledHandle = formHandle = 0;
+}
+void releaseWidget () {
+ if (horizontalBar != null) horizontalBar.releaseResources ();
+ if (verticalBar != null) verticalBar.releaseResources ();
+ horizontalBar = verticalBar = null;
+ super.releaseWidget ();
+}
+void setBackgroundPixel (int pixel) {
+ super.setBackgroundPixel (pixel);
+ 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 setScrollbarVisible (int barHandle, boolean visible) {
+ if (scrolledHandle == 0) return;
+ /*
+ * 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.XtGetValues (scrolledHandle, argList, argList.length / 2);
+
+ /* Hide or show the scroll bar */
+ if (visible) {
+ OS.XtManageChild (barHandle);
+ } else {
+ OS.XtUnmanageChild (barHandle);
+ }
+
+ /* Restore the size */
+ OS.XtSetValues (scrolledHandle, argList, argList.length / 2);
+}
+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
index a1acacf8bc..d98b21a6c2 100755
--- 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
@@ -1,120 +1,120 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- * 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
- * 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>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE</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
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class Shell extends Decorations {
- Display display;
- int shellHandle;
- boolean reparented, realized, configured;
- int oldX, oldY, oldWidth, oldHeight;
- Control lastActive;
-
- static final byte [] WM_DELETE_WINDOW = Converter.wcsToMbcs(null, "WM_DELETE_WINDOW\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>
+
+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>
+ * 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
+ * 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>.
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE</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 {
+ Display display;
+ int shellHandle;
+ boolean reparented, realized, configured;
+ int oldX, oldY, oldWidth, oldHeight;
+ Control lastActive;
+
+ static final byte [] WM_DELETE_WINDOW = Converter.wcsToMbcs(null, "WM_DELETE_WINDOW\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);
-}
+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
@@ -150,31 +150,31 @@ public Shell () {
* @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 (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);
-}
+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
@@ -218,48 +218,48 @@ public Shell (Display display) {
* @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);
- }
- 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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, 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);
+ }
+ 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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);
-}
+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.
@@ -302,180 +302,180 @@ public Shell (Shell parent) {
* @see SWT#APPLICATION_MODAL
* @see SWT#SYSTEM_MODAL
*/
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.getDisplay () : 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 Shell (Shell parent, int style) {
+ this (parent != null ? parent.getDisplay () : 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 (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
+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 (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];
-
- /* 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;
- }
-}
-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 ((style & SWT.ON_TOP) != 0) return;
- if (minimized) return;
- if (!isVisible ()) return;
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (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;
- }
- OS.XSetInputFocus (xDisplay, xWindow, OS.RevertToParent, OS.CurrentTime);
-}
+ 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];
+
+ /* 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;
+ }
+}
+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 ((style & SWT.ON_TOP) != 0) return;
+ if (minimized) return;
+ if (!isVisible ()) return;
+ int xDisplay = OS.XtDisplay (shellHandle);
+ if (xDisplay == 0) return;
+ int xWindow = OS.XtWindow (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;
+ }
+ OS.XSetInputFocus (xDisplay, xWindow, OS.RevertToParent, OS.CurrentTime);
+}
/**
* Requests that the window manager close the receiver in
* the same way it would be closed when the user clicks on
@@ -490,914 +490,914 @@ void bringToTop (boolean force) {
*
* @see #dispose
*/
-public void close () {
- checkWidget();
- closeWidget ();
-}
-void closeWidget () {
- if (!isEnabled ()) return;
- 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;
- }
- }
- }
- 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 ();
- trim.y -= trimTop ();
- trim.width += trimWidth () + (border * 2);
- trim.height += trimHeight () + imeHeight () + (border * 2);
- return trim;
-}
-void createHandle (int index) {
- state |= HANDLE | 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.
- */
- int orientations = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((style & ~orientations) == SWT.NONE || (style & (SWT.NO_TRIM | SWT.ON_TOP)) != 0) {
- 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.TopLevelShellWidgetClass ();
- 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);
-
- /* Create scrolled handle */
- createScrolledHandle (shellHandle);
-
- /*
- * 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 negociate 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 ();
- WidgetTable.remove (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 an override-redirected shell
- * is disposed, Motif does not assign a new active top
- * level shell. The parent shell appears to be active,
- * but XGetInputFocus returns the root window, not the
- * parent. The fix is to make the parent be the active
- * top level shell when the child shell is disposed.
- *
- * 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) {
- int [] argList = {OS.XmNoverrideRedirect, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- Shell activeShell = display.getActiveShell ();
- if (argList [1] != 0 || 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);
-}
-/**
- * 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) 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 close () {
+ checkWidget();
+ closeWidget ();
+}
+void closeWidget () {
+ if (!isEnabled ()) return;
+ 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;
+ }
+ }
+ }
+ 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 ();
+ trim.y -= trimTop ();
+ trim.width += trimWidth () + (border * 2);
+ trim.height += trimHeight () + imeHeight () + (border * 2);
+ return trim;
+}
+void createHandle (int index) {
+ state |= HANDLE | 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.
+ */
+ int orientations = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
+ if ((style & ~orientations) == SWT.NONE || (style & (SWT.NO_TRIM | SWT.ON_TOP)) != 0) {
+ 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.TopLevelShellWidgetClass ();
+ 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);
+
+ /* Create scrolled handle */
+ createScrolledHandle (shellHandle);
+
+ /*
+ * 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 negociate 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 ();
+ WidgetTable.remove (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 an override-redirected shell
+ * is disposed, Motif does not assign a new active top
+ * level shell. The parent shell appears to be active,
+ * but XGetInputFocus returns the root window, not the
+ * parent. The fix is to make the parent be the active
+ * top level shell when the child shell is disposed.
+ *
+ * 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) {
+ int [] argList = {OS.XmNoverrideRedirect, 0};
+ OS.XtGetValues (shellHandle, argList, argList.length / 2);
+ Shell activeShell = display.getActiveShell ();
+ if (argList [1] != 0 || 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);
+}
+/**
+ * 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) 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();
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
- if (reparented) {
- root_x [0] -= trimLeft ();
- root_y [0] -= trimTop ();
- }
- 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 ();
- int width = argList [1] + trimWidth + (border * 2);
- int height = argList [3] + trimHeight + (border * 2);
- return new Rectangle (root_x [0], root_y [0], width, height);
-}
-public Display getDisplay () {
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return display;
-}
-/**
- * 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 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();
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
+ if (reparented) {
+ root_x [0] -= trimLeft ();
+ root_y [0] -= trimTop ();
+ }
+ 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 ();
+ int width = argList [1] + trimWidth + (border * 2);
+ int height = argList [3] + trimHeight + (border * 2);
+ return new Rectangle (root_x [0], root_y [0], width, height);
+}
+public Display getDisplay () {
+ if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return display;
+}
+/**
+ * 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();
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
- if (reparented) {
- root_x [0] -= trimLeft ();
- root_y [0] -= trimTop ();
- }
- return new Point (root_x [0], root_y [0]);
-}
-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 int getImeInputMode () {
+ checkWidget();
+ return SWT.NONE;
+}
+public Point getLocation () {
+ checkWidget();
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
+ if (reparented) {
+ root_x [0] -= trimLeft ();
+ root_y [0] -= trimTop ();
+ }
+ return new Point (root_x [0], root_y [0]);
+}
+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 [] 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 ();
- int width = argList [1] + trimWidth + (border * 2);
- int height = argList [3] + trimHeight + (border * 2);
- return new Point (width, height);
-}
-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;
-}
-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);
-}
-public boolean isVisible () {
- checkWidget();
- return getVisible ();
-}
-void manageChildren () {
- OS.XtSetMappedWhenManaged (shellHandle, false);
- super.manageChildren ();
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay == 0) return;
- int width = OS.XDisplayWidth (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8;
- int 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,
- * and sets focus to its default button (if it has one)
- * 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 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 [] 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 ();
+ int width = argList [1] + trimWidth + (border * 2);
+ int height = argList [3] + trimHeight + (border * 2);
+ return new Point (width, height);
+}
+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;
+}
+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);
+}
+public boolean isVisible () {
+ checkWidget();
+ return getVisible ();
+}
+void manageChildren () {
+ OS.XtSetMappedWhenManaged (shellHandle, false);
+ super.manageChildren ();
+ int xDisplay = OS.XtDisplay (shellHandle);
+ if (xDisplay == 0) return;
+ int width = OS.XDisplayWidth (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8;
+ int 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,
+ * and sets focus to its default button (if it has one)
+ * 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 (!restoreFocus ()) traverseGroup (true);
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- propagateHandle (enabled, shellHandle);
-}
-void realizeWidget () {
- if (realized) return;
- OS.XtRealizeWidget (shellHandle);
- realizeChildren ();
- realized = true;
-}
-void register () {
- super.register ();
- WidgetTable.put (shellHandle, this);
-}
-void releaseHandle () {
- super.releaseHandle ();
- shellHandle = 0;
-}
-void releaseShells () {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.releaseResources ();
- }
-}
-void releaseWidget () {
- releaseShells ();
- super.releaseWidget ();
- display = null;
- lastActive = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when operations are performed on the receiver.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #addShellListener
+public void open () {
+ checkWidget();
+ setVisible (true);
+ if (!restoreFocus ()) traverseGroup (true);
+}
+void propagateWidget (boolean enabled) {
+ super.propagateWidget (enabled);
+ propagateHandle (enabled, shellHandle);
+}
+void realizeWidget () {
+ if (realized) return;
+ OS.XtRealizeWidget (shellHandle);
+ realizeChildren ();
+ realized = true;
+}
+void register () {
+ super.register ();
+ WidgetTable.put (shellHandle, this);
+}
+void releaseHandle () {
+ super.releaseHandle ();
+ shellHandle = 0;
+}
+void releaseShells () {
+ Shell [] shells = getShells ();
+ for (int i=0; i<shells.length; i++) {
+ Shell shell = shells [i];
+ if (!shell.isDisposed ()) shell.releaseResources ();
+ }
+}
+void releaseWidget () {
+ releaseShells ();
+ super.releaseWidget ();
+ display = null;
+ lastActive = null;
+}
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notified when operations are performed on the receiver.
+ *
+ * @param listener the listener which should no longer be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @see ShellListener
+ * @see #addShellListener
*/
-public void removeShellListener(ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Activate, listener);
- eventTable.unhook(SWT.Close, listener);
- eventTable.unhook(SWT.Deactivate, listener);
- eventTable.unhook(SWT.Iconify,listener);
- eventTable.unhook(SWT.Deiconify,listener);
-}
-void saveBounds () {
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- oldX = root_x [0];
- oldY = root_y [0];
- oldWidth = argList [1];
- oldHeight = argList [3];
-}
-
-/**
- * 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) 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 removeShellListener(ShellListener listener) {
+ checkWidget();
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook(SWT.Activate, listener);
+ eventTable.unhook(SWT.Close, listener);
+ eventTable.unhook(SWT.Deactivate, listener);
+ eventTable.unhook(SWT.Iconify,listener);
+ eventTable.unhook(SWT.Deiconify,listener);
+}
+void saveBounds () {
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (shellHandle, argList, argList.length / 2);
+ oldX = root_x [0];
+ oldY = root_y [0];
+ oldWidth = argList [1];
+ oldHeight = argList [3];
+}
+
+/**
+ * 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) 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 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) {
- if (resize) {
- /*
- * 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 - trimWidth (), 1);
- height = Math.max (height - trimHeight (), 1);
- }
- if (!reparented || !OS.XtIsRealized (shellHandle)) {
- return super.setBounds (x, y, width, height, move, resize);
- }
- if (move) {
- x += trimLeft ();
- y += trimTop ();
- }
- if (!configured) saveBounds ();
- configured = true;
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- 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 (isFocus) caret.setFocus ();
- return move || resize;
-}
-public void setMinimized (boolean minimized) {
- checkWidget();
-
- /*
- * 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.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 */
- argList [1] = (this.minimized = minimized) ? 1 : 0;
- 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);
-}
-void setParentTraversal () {
- /* Do nothing - Child shells do not affect the traversal of their parent shell */
-}
-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);
- int length = buffer1.length - 1;
-
- /*
- * 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;
- 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.XtSetValues (shellHandle, argList, argList.length / 2);
- OS.XtFree (ptr);
-}
-public void setVisible (boolean visible) {
- checkWidget();
- realizeWidget ();
-
- /* Show the shell */
- if (visible) {
-
- /* 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.
- */
- do {
- display.update ();
- } while (!isVisible ());
- adjustTrim ();
-
- sendEvent (SWT.Show);
- return;
- }
-
- /* 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;
-}
-int WM_DELETE_WINDOW (int w, int client_data, int call_data) {
- 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;
- switch (xEvent.detail) {
- case OS.NotifyNonlinear:
- case OS.NotifyNonlinearVirtual: {
- switch (xEvent.type) {
- case OS.FocusIn:
- postEvent (SWT.Activate);
- break;
- case OS.FocusOut:
- postEvent (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);
- switch (xEvent.type) {
- case OS.ReparentNotify: {
- if (reparented) return 0;
- reparented = true;
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- xEvent.x = root_x [0]; xEvent.y = root_y [0];
- xEvent.width = argList [1]; xEvent.height = argList [3];
- // FALL THROUGH
- }
- case OS.ConfigureNotify:
- if (!reparented) return 0;
- configured = false;
- if (oldX != xEvent.x || oldY != xEvent.y) sendEvent (SWT.Move);
- if (oldWidth != xEvent.width || oldHeight != xEvent.height) {
- XAnyEvent event = new XAnyEvent ();
- display.resizeWindow = xEvent.window;
- display.resizeWidth = xEvent.width;
- display.resizeHeight = xEvent.height;
- display.resizeCount = 0;
- int checkResizeProc = display.checkResizeProc;
- OS.XCheckIfEvent (xEvent.display, event, checkResizeProc, 0);
- if (display.resizeCount == 0) {
- sendEvent (SWT.Resize);
- if (layout != null) layout (false);
- }
- }
- if (xEvent.x != 0) oldX = xEvent.x;
- if (xEvent.y != 0) oldY = xEvent.y;
- oldWidth = xEvent.width;
- oldHeight = xEvent.height;
- 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;
-}
+public void setImeInputMode (int mode) {
+ checkWidget();
+}
+boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
+ if (resize) {
+ /*
+ * 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 - trimWidth (), 1);
+ height = Math.max (height - trimHeight (), 1);
+ }
+ if (!reparented || !OS.XtIsRealized (shellHandle)) {
+ return super.setBounds (x, y, width, height, move, resize);
+ }
+ if (move) {
+ x += trimLeft ();
+ y += trimTop ();
+ }
+ if (!configured) saveBounds ();
+ configured = true;
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+ 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 (isFocus) caret.setFocus ();
+ return move || resize;
+}
+public void setMinimized (boolean minimized) {
+ checkWidget();
+
+ /*
+ * 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.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 */
+ argList [1] = (this.minimized = minimized) ? 1 : 0;
+ 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);
+}
+void setParentTraversal () {
+ /* Do nothing - Child shells do not affect the traversal of their parent shell */
+}
+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);
+ int length = buffer1.length - 1;
+
+ /*
+ * 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;
+ 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.XtSetValues (shellHandle, argList, argList.length / 2);
+ OS.XtFree (ptr);
+}
+public void setVisible (boolean visible) {
+ checkWidget();
+ realizeWidget ();
+
+ /* Show the shell */
+ if (visible) {
+
+ /* 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.
+ */
+ do {
+ display.update ();
+ } while (!isVisible ());
+ adjustTrim ();
+
+ sendEvent (SWT.Show);
+ return;
+ }
+
+ /* 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;
+}
+int WM_DELETE_WINDOW (int w, int client_data, int call_data) {
+ 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;
+ switch (xEvent.detail) {
+ case OS.NotifyNonlinear:
+ case OS.NotifyNonlinearVirtual: {
+ switch (xEvent.type) {
+ case OS.FocusIn:
+ postEvent (SWT.Activate);
+ break;
+ case OS.FocusOut:
+ postEvent (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);
+ switch (xEvent.type) {
+ case OS.ReparentNotify: {
+ if (reparented) return 0;
+ reparented = true;
+ short [] root_x = new short [1], root_y = new short [1];
+ OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (shellHandle, argList, argList.length / 2);
+ xEvent.x = root_x [0]; xEvent.y = root_y [0];
+ xEvent.width = argList [1]; xEvent.height = argList [3];
+ // FALL THROUGH
+ }
+ case OS.ConfigureNotify:
+ if (!reparented) return 0;
+ configured = false;
+ if (oldX != xEvent.x || oldY != xEvent.y) sendEvent (SWT.Move);
+ if (oldWidth != xEvent.width || oldHeight != xEvent.height) {
+ XAnyEvent event = new XAnyEvent ();
+ display.resizeWindow = xEvent.window;
+ display.resizeWidth = xEvent.width;
+ display.resizeHeight = xEvent.height;
+ display.resizeCount = 0;
+ int checkResizeProc = display.checkResizeProc;
+ OS.XCheckIfEvent (xEvent.display, event, checkResizeProc, 0);
+ if (display.resizeCount == 0) {
+ sendEvent (SWT.Resize);
+ if (layout != null) layout (false);
+ }
+ }
+ if (xEvent.x != 0) oldX = xEvent.x;
+ if (xEvent.y != 0) oldY = xEvent.y;
+ oldWidth = xEvent.width;
+ oldHeight = xEvent.height;
+ 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;
+}
} \ No newline at end of file
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
index 97170862f0..b5fdfb91c7 100755
--- 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
@@ -1,66 +1,66 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 <em>selection</em> 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
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class Slider extends Control {
+
+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 <em>selection</em> 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.
@@ -90,447 +90,447 @@ public class Slider extends Control {
* @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>0</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 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>0</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;
- Display display = getDisplay ();
- 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 |= HANDLE;
- Display display = getDisplay ();
- 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,
- };
- 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 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;
+ Display display = getDisplay ();
+ 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 |= HANDLE;
+ Display display = getDisplay ();
+ 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,
+ };
+ 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 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 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 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 single <em>selection</em> 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 getPageIncrement () {
+ checkWidget();
+ int [] argList = {OS.XmNpageIncrement, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+/**
+ * Returns the single <em>selection</em> 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 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 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 = getDisplay ().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 () {
- Display display = getDisplay ();
- 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 int getThumb () {
+ checkWidget();
+ int [] argList = {OS.XmNsliderSize, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().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 () {
+ Display display = getDisplay ();
+ 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;
- sendEvent (SWT.Selection, event);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void 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);
+}
+/**
+ * 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 value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new maximum (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 setIncrement (int value) {
+ checkWidget();
+ if (value < 1) return;
+ int [] argList = {OS.XmNincrement, value};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+ * Sets the maximum value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new maximum (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 setMaximum (int value) {
- checkWidget();
- if (value < 0) return;
- int [] argList = {OS.XmNmaximum, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the minimum value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new minimum (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 setMaximum (int value) {
+ checkWidget();
+ if (value < 0) return;
+ int [] argList = {OS.XmNmaximum, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ display.setWarnings (warnings);
+}
+/**
+ * Sets the minimum value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new minimum (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 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;
- Display display = getDisplay ();
- 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.
- *
- * @return 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 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;
+ Display display = getDisplay ();
+ 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.
+ *
+ * @return 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 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 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 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};
- Display display = getDisplay ();
- 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 to the
- * argument which must be at least one.
- *
- * @param value the new thumb value (must be at least 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 ScrollBar
+public void setSelection (int value) {
+ checkWidget();
+ int [] argList = {OS.XmNvalue, value};
+ Display display = getDisplay ();
+ 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 to the
+ * argument which must be at least one.
+ *
+ * @param value the new thumb value (must be at least 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 ScrollBar
*/
-public void setThumb (int value) {
- checkWidget();
- if (value < 1) return;
- int [] argList = {OS.XmNsliderSize, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.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 equivalent 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 setThumb (int value) {
+ checkWidget();
+ if (value < 1) return;
+ int [] argList = {OS.XmNsliderSize, value};
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XtSetValues (handle, argList, argList.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 equivalent 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 (maximum - minimum - thumb < 0) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- int [] argList = {
- OS.XmNvalue, selection,
- OS.XmNminimum, minimum,
- OS.XmNmaximum, maximum,
- OS.XmNsliderSize, thumb,
- OS.XmNincrement, increment,
- OS.XmNpageIncrement, pageIncrement,
- };
- Display display = getDisplay ();
- 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;
-}
-}
+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 (maximum - minimum - thumb < 0) return;
+ if (increment < 1) return;
+ if (pageIncrement < 1) return;
+ int [] argList = {
+ OS.XmNvalue, selection,
+ OS.XmNminimum, minimum,
+ OS.XmNmaximum, maximum,
+ OS.XmNsliderSize, thumb,
+ OS.XmNincrement, increment,
+ OS.XmNpageIncrement, pageIncrement,
+ };
+ Display display = getDisplay ();
+ 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/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java
index 2c4cbb150d..6f07fdc41d 100755
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -29,28 +29,28 @@ import org.eclipse.swt.events.*;
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
-public class Text extends Scrollable {
- char echoCharacter;
- boolean ignoreChange;
- String hiddenText;
- XmTextVerifyCallbackStruct textVerify;
- int drawCount;
-
- static final boolean IsGB18030;
- public static final int LIMIT;
- 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");
- }
-
+public class Text extends Scrollable {
+ char echoCharacter;
+ boolean ignoreChange;
+ String hiddenText;
+ XmTextVerifyCallbackStruct textVerify;
+ int drawCount;
+
+ static final boolean IsGB18030;
+ public static final int LIMIT;
+ 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.
@@ -82,1030 +82,1030 @@ public class Text extends Scrollable {
* @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 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 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 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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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);
- Display display = getDisplay ();
- 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) {
- 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;
- 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 append (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int position = OS.XmTextGetLastPosition (handle);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
+ Display display = getDisplay ();
+ 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) {
+ 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;
+ 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);
- int xmString;
- if ((style & SWT.SINGLE) != 0) {
- xmString = OS.XmStringParseText (
- buffer,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- } else {
- xmString = OS.XmStringGenerate (
- buffer,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null);
- }
- int fontList = font.handle;
- if (hHint == SWT.DEFAULT) {
- if ((style & SWT.SINGLE) != 0) {
- height = getLineHeight ();
- } else {
- height = OS.XmStringHeight (fontList, xmString);
- }
- }
- if (wHint == SWT.DEFAULT) width = OS.XmStringWidth(fontList, xmString);
- OS.XmStringFree (xmString);
- }
- OS.XtFree (ptr);
- }
- if (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;
- }
- XRectangle rect = new XRectangle ();
- OS.XmWidgetGetDisplayRect (handle, rect);
- width += rect.x * 2; height += rect.y * 2;
- if ((style & (SWT.MULTI | SWT.BORDER)) != 0) 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);
- XRectangle rect = new XRectangle ();
- OS.XmWidgetGetDisplayRect (handle, rect);
- trim.x -= rect.x;
- trim.y -= rect.y;
- trim.width += rect.x;
- trim.height += rect.y;
- if ((style & (SWT.MULTI | SWT.BORDER)) != 0) trim.height += 3;
- return trim;
-}
-/**
- * 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 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);
+ int xmString;
+ if ((style & SWT.SINGLE) != 0) {
+ xmString = OS.XmStringParseText (
+ buffer,
+ 0,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null,
+ 0,
+ 0);
+ } else {
+ xmString = OS.XmStringGenerate (
+ buffer,
+ OS.XmFONTLIST_DEFAULT_TAG,
+ OS.XmCHARSET_TEXT,
+ null);
+ }
+ int fontList = font.handle;
+ if (hHint == SWT.DEFAULT) {
+ if ((style & SWT.SINGLE) != 0) {
+ height = getLineHeight ();
+ } else {
+ height = OS.XmStringHeight (fontList, xmString);
+ }
+ }
+ if (wHint == SWT.DEFAULT) width = OS.XmStringWidth(fontList, xmString);
+ OS.XmStringFree (xmString);
+ }
+ OS.XtFree (ptr);
+ }
+ if (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;
+ }
+ XRectangle rect = new XRectangle ();
+ OS.XmWidgetGetDisplayRect (handle, rect);
+ width += rect.x * 2; height += rect.y * 2;
+ if ((style & (SWT.MULTI | SWT.BORDER)) != 0) 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);
+ XRectangle rect = new XRectangle ();
+ OS.XmWidgetGetDisplayRect (handle, rect);
+ trim.x -= rect.x;
+ trim.y -= rect.y;
+ trim.width += rect.x;
+ trim.height += rect.y;
+ if ((style & (SWT.MULTI | SWT.BORDER)) != 0) trim.height += 3;
+ return trim;
+}
+/**
+ * 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) {
- state |= HANDLE;
- 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);
- 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);
- }
- } else {
- handle = OS.XmCreateScrolledText (parentHandle, new byte [0], argList1, argList1.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- scrolledHandle = OS.XtParent (handle);
- }
-}
-ScrollBar createScrollBar (int type) {
- return createStandardBar (type);
-}
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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) {
+ state |= HANDLE;
+ 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);
+ 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);
+ }
+ } else {
+ handle = OS.XmCreateScrolledText (parentHandle, new byte [0], argList1, argList1.length / 2);
+ if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ scrolledHandle = OS.XtParent (handle);
+ }
+}
+ScrollBar createScrollBar (int type) {
+ return createStandardBar (type);
+}
+/**
+ * Cuts the selected text.
+ * <p>
+ * The current selection is first copied to the
+ * clipboard and then deleted from the widget.
+ * </p>
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 getDisplay ().textBackground;
-}
-Font defaultFont () {
- return getDisplay ().textFont;
-}
-int defaultForeground () {
- return getDisplay ().textForeground;
-}
-/**
- * Gets the line number of the caret.
- * <p>
- * The line number of the caret is returned.
- * </p>
- *
- * @return the line number
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 getDisplay ().textBackground;
+}
+Font defaultFont () {
+ return getDisplay ().textFont;
+}
+int defaultForeground () {
+ return getDisplay ().textForeground;
+}
+/**
+ * Gets the line number of the caret.
+ * <p>
+ * The line number of the caret is returned.
+ * </p>
+ *
+ * @return the line number
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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));
-}
-/**
- * Gets the location of the caret.
- * <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 int getCaretLineNumber () {
+ checkWidget();
+ return getLineNumber (OS.XmTextGetInsertionPosition (handle));
+}
+/**
+ * Gets the location of the caret.
+ * <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;
- if (textVerify != null) {
- position = textVerify.currInsert;
- } else {
- 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 ());
-}
-/**
- * Gets the position of the caret.
- * <p>
- * The character position of the caret is returned.
- * </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 Point getCaretLocation () {
+ checkWidget();
+ int position;
+ if (textVerify != null) {
+ position = textVerify.currInsert;
+ } else {
+ 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 ());
+}
+/**
+ * Gets the position of the caret.
+ * <p>
+ * The character position of the caret is returned.
+ * </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);
-}
-/**
- * Gets 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 getCaretPosition () {
+ checkWidget();
+ return OS.XmTextGetInsertionPosition (handle);
+}
+/**
+ * Gets 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);
-}
-/**
- * Gets 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>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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);
+}
+/**
+ * Gets 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>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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;
-}
-/**
- * Gets 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>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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;
+}
+/**
+ * Gets 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>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
*/
-public char getEchoChar () {
- checkWidget();
- return echoCharacter;
-}
-/**
- * Gets the 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 char getEchoChar () {
+ checkWidget();
+ return echoCharacter;
+}
+/**
+ * Gets the 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 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;
-}
-/**
- * Gets 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 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;
+}
+/**
+ * Gets 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;
-}
-/**
- * Gets 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>
+public int getLineCount () {
+ checkWidget();
+ if ((style & SWT.SINGLE) != 0) return 1;
+ int lastChar = echoCharacter != '\0' ? hiddenText.length () : OS.XmTextGetLastPosition (handle);
+ return getLineNumber (lastChar) + 1;
+}
+/**
+ * Gets 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>
*/
-public String getLineDelimiter () {
- checkWidget();
- return "\n";
-}
-/**
- * Gets 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 String getLineDelimiter () {
+ checkWidget();
+ return "\n";
+}
+/**
+ * Gets 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 ();
-}
-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];
-}
-/**
- * Gets the position of the selected text.
- * <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 the start and end of 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 getLineHeight () {
+ checkWidget();
+ return getFontHeight ();
+}
+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];
+}
+/**
+ * Gets the position of the selected text.
+ * <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 the start and end of 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 Point getSelection () {
- checkWidget();
- if (textVerify != null) {
- return new Point (textVerify.startPos, textVerify.endPos);
- }
- 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]);
-}
-/**
- * Gets 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 Point getSelection () {
+ checkWidget();
+ if (textVerify != null) {
+ return new Point (textVerify.startPos, textVerify.endPos);
+ }
+ 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]);
+}
+/**
+ * Gets the number of selected characters.
+ *
+ * @return the number of selected characters.
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
*/
-public int getSelectionCount () {
- checkWidget();
- if (textVerify != null) {
- return textVerify.endPos - textVerify.startPos;
- }
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (handle, start, end);
- return end [0] - start [0];
-}
-/**
- * Gets the selected text.
- *
- * @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 int getSelectionCount () {
+ checkWidget();
+ if (textVerify != null) {
+ return textVerify.endPos - textVerify.startPos;
+ }
+ int [] start = new int [1], end = new int [1];
+ OS.XmTextGetSelectionPosition (handle, start, end);
+ return end [0] - start [0];
+}
+/**
+ * Gets the selected text.
+ *
+ * @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' || textVerify != null) {
- 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));
-}
-/**
- * Gets 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 String getSelectionText () {
+ checkWidget();
+ if (echoCharacter != '\0' || textVerify != null) {
+ 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));
+}
+/**
+ * Gets 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;
-}
-/**
- * Gets the widget text.
- * <p>
- * The text for a text widget is the characters in the widget.
- * </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 int getTabs () {
+ checkWidget();
+ /* Tabs are not supported in MOTIF. */
+ return 8;
+}
+/**
+ * Gets the widget text.
+ * <p>
+ * The text for a text widget is the characters in the widget.
+ * </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));
-}
-/**
- * Gets a range of text.
- * <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 () {
+ 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));
+}
+/**
+ * Gets a range of text.
+ * <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();
- int numChars = end - start + 1;
- if (numChars < 0 || start < 0) return "";
- if (echoCharacter != '\0') {
- return hiddenText.substring (start, Math.min (hiddenText.length (), end));
- }
- int length = (numChars * 4 /* MB_CUR_MAX */) + 1;
- byte [] buffer = new byte [length];
- int code = OS.XmTextGetSubstring (handle, start, numChars, length, buffer);
- if (code == OS.XmCOPY_FAILED) return "";
- char [] unicode = Converter.mbcsToWcs (getCodePage (), buffer);
- if (code == OS.XmCOPY_TRUNCATED) {
- numChars = OS.XmTextGetLastPosition (handle) - start;
- }
- 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>
+public String getText (int start, int end) {
+ checkWidget();
+ int numChars = end - start + 1;
+ if (numChars < 0 || start < 0) return "";
+ if (echoCharacter != '\0') {
+ return hiddenText.substring (start, Math.min (hiddenText.length (), end));
+ }
+ int length = (numChars * 4 /* MB_CUR_MAX */) + 1;
+ byte [] buffer = new byte [length];
+ int code = OS.XmTextGetSubstring (handle, start, numChars, length, buffer);
+ if (code == OS.XmCOPY_FAILED) return "";
+ char [] unicode = Converter.mbcsToWcs (getCodePage (), buffer);
+ if (code == OS.XmCOPY_TRUNCATED) {
+ numChars = OS.XmTextGetLastPosition (handle) - start;
+ }
+ 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>
*/
-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 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];
-}
-/**
- * Gets 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 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];
+}
+/**
+ * Gets 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 = getDisplay ().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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 = getDisplay ().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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextReplace (handle, start [0], end [0], buffer);
- int position = start [0] + buffer.length - 1;
- OS.XmTextSetInsertionPosition (handle, position);
- display.setWarnings (warnings);
-}
-void overrideTranslations () {
- if ((style & SWT.SINGLE) != 0) {
- Display display = getDisplay ();
- 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 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);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextReplace (handle, start [0], end [0], buffer);
+ int position = start [0] + buffer.length - 1;
+ OS.XmTextSetInsertionPosition (handle, position);
+ display.setWarnings (warnings);
+}
+void overrideTranslations () {
+ if ((style & SWT.SINGLE) != 0) {
+ Display display = getDisplay ();
+ 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();
- Display display = getDisplay ();
- 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;
- 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 paste () {
+ checkWidget();
+ Display display = getDisplay ();
+ 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;
+ 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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
+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
*/
-public void removeVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Verify, listener);
-}
-byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) {
- /*
- * 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 [] mbcs = super.sendIMKeyEvent (type, xEvent);
- if (mbcs == null || xEvent.keycode != 0) return null;
- int [] unused = new int [1];
- byte [] buffer = new byte [2];
- int length = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, unused, unused);
- if (length != 0) return null;
- 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);
- }
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextReplace (handle, start [0], end [0], mbcs);
- int position = start [0] + mbcs.length - 1;
- OS.XmTextSetInsertionPosition (handle, position);
- display.setWarnings (warnings);
- return mbcs;
-}
-/**
- * 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 removeVerifyListener (VerifyListener listener) {
+ checkWidget();
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Verify, listener);
+}
+byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) {
+ /*
+ * 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 [] mbcs = super.sendIMKeyEvent (type, xEvent);
+ if (mbcs == null || xEvent.keycode != 0) return null;
+ int [] unused = new int [1];
+ byte [] buffer = new byte [2];
+ int length = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, unused, unused);
+ if (length != 0) return null;
+ 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);
+ }
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextReplace (handle, start [0], end [0], mbcs);
+ int position = start [0] + mbcs.length - 1;
+ OS.XmTextSetInsertionPosition (handle, position);
+ display.setWarnings (warnings);
+ return mbcs;
+}
+/**
+ * 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;
- Display display = getDisplay ();
- 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.
- */
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- display.setWarnings(warnings);
-
- /*
- * Bug in Motif. When the receiver is a Text widget
- * (not a Text Field) and is resized to be smaller than
- * the inset that surrounds the text and the selection
- * is set, the receiver scrolls to the left. When the
- * receiver is resized larger, the text is not scrolled
- * back. The fix is to detect this case and scroll the
- * text back.
- */
-// inset := self inset.
-// nWidth := self dimensionAt: XmNwidth.
-// self noWarnings: [super resizeWidget].
-// nWidth > inset x ifTrue: [^self].
-// self showPosition: self topCharacter
- 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>
- *
- * @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 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;
+ Display display = getDisplay ();
+ 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.
+ */
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ boolean changed = super.setBounds (x, y, width, height, move, resize);
+ display.setWarnings(warnings);
+
+ /*
+ * Bug in Motif. When the receiver is a Text widget
+ * (not a Text Field) and is resized to be smaller than
+ * the inset that surrounds the text and the selection
+ * is set, the receiver scrolls to the left. When the
+ * receiver is resized larger, the text is not scrolled
+ * back. The fix is to detect this case and scroll the
+ * text back.
+ */
+// inset := self inset.
+// nWidth := self dimensionAt: XmNwidth.
+// self noWarnings: [super resizeWidget].
+// nWidth > inset x ifTrue: [^self].
+// self showPosition: self topCharacter
+ 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>
+ *
+ * @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);
-}
+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>
@@ -1126,52 +1126,52 @@ public void setDoubleClickEnabled (boolean doubleClick) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setEchoChar (char echo) {
- checkWidget();
- if (echoCharacter == echo) return;
- String newText;
- if (echo == 0) {
- newText = hiddenText;
- hiddenText = null;
- } 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 setEchoChar (char echo) {
+ checkWidget();
+ if (echoCharacter == echo) return;
+ String newText;
+ if (echo == 0) {
+ newText = hiddenText;
+ hiddenText = null;
+ } 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);
-}
-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);
- }
-}
+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);
+}
+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>
@@ -1195,23 +1195,23 @@ public void setRedraw (boolean redraw) {
* <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);
- Display display = getDisplay ();
- 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);
-}
+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);
+ Display display = getDisplay ();
+ 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.
* <p>
@@ -1236,36 +1236,36 @@ public void setSelection (int start) {
* <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;
- int nStart = Math.min (Math.max (Math.min (start, end), 0), position);
- int nEnd = Math.min (Math.max (Math.max (start, end), 0), position);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetSelection (handle, nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay));
-
- /* Force the i-beam to follow the highlight/selection. */
- OS.XmTextSetInsertionPosition (handle, nEnd);
- display.setWarnings (warnings);
-}
+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;
+ int nStart = Math.min (Math.max (Math.min (start, end), 0), position);
+ int nEnd = Math.min (Math.max (Math.max (start, end), 0), position);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetSelection (handle, nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay));
+
+ /* Force the i-beam to follow the highlight/selection. */
+ OS.XmTextSetInsertionPosition (handle, nEnd);
+ display.setWarnings (warnings);
+}
/**
* Sets the selection.
* <p>
@@ -1292,31 +1292,31 @@ public void setSelection (int start, int end) {
* <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 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. */
-}
+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
@@ -1332,23 +1332,23 @@ public void setTabs (int tabs) {
* <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);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (handle, buffer);
- OS.XmTextSetInsertionPosition (handle, 0);
- display.setWarnings(warnings);
- /*
- * Bug in Linux. When the widget is multi-line
- * it does not send a Modify to notify the application
- * that the text has changed. The fix is to send the event.
- */
- if (OS.IsLinux && (style & SWT.MULTI) != 0) sendEvent (SWT.Modify);
-}
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
+ Display display = getDisplay ();
+ boolean warnings = display.getWarnings ();
+ display.setWarnings (false);
+ OS.XmTextSetString (handle, buffer);
+ OS.XmTextSetInsertionPosition (handle, 0);
+ display.setWarnings(warnings);
+ /*
+ * Bug in Linux. When the widget is multi-line
+ * it does not send a Modify to notify the application
+ * that the text has changed. The fix is to send the event.
+ */
+ if (OS.IsLinux && (style & SWT.MULTI) != 0) sendEvent (SWT.Modify);
+}
/**
* Sets the maximum number of characters that the receiver
* is capable of holding to be the argument.
@@ -1369,153 +1369,153 @@ public void setText (String string) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-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 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 IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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();
- Display display = getDisplay ();
- 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 () {
- super.xFocusIn ();
- // 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 () {
- super.xFocusOut ();
- // 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) {
- 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);
- textVerify = null;
- return result;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- if (!ignoreChange) sendEvent (SWT.Modify);
- return 0;
-}
-}
+public void showSelection () {
+ checkWidget();
+ Display display = getDisplay ();
+ 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 () {
+ super.xFocusIn ();
+ // 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 () {
+ super.xFocusOut ();
+ // 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) {
+ 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);
+ textVerify = null;
+ 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
index bf9b6d4938..92ded275b6 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -34,9 +34,9 @@ import org.eclipse.swt.graphics.*;
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
-public class ToolBar extends Composite {
- int drawCount, itemCount;
- ToolItem [] items;
+public class ToolBar extends Composite {
+ int drawCount, itemCount;
+ ToolItem [] items;
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -69,380 +69,380 @@ public class ToolBar extends Composite {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public ToolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-
- /*
- * Ensure that either of HORIZONTAL or VERTICAL is set.
- * NOTE: HORIZONTAL and VERTICAL have the same values
- * as H_SCROLL and V_SCROLL so it is necessary to first
- * clear these bits to avoid scroll bars and then reset
- * the bits using the original style supplied by the
- * programmer.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- }
-}
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
- if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
- int [] result = layout (width, height, false);
- 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;
-}
-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;
-}
-/**
- * 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 ToolBar (Composite parent, int style) {
+ super (parent, checkStyle (style));
+
+ /*
+ * Ensure that either of HORIZONTAL or VERTICAL is set.
+ * NOTE: HORIZONTAL and VERTICAL have the same values
+ * as H_SCROLL and V_SCROLL so it is necessary to first
+ * clear these bits to avoid scroll bars and then reset
+ * the bits using the original style supplied by the
+ * programmer.
+ */
+ if ((style & SWT.VERTICAL) != 0) {
+ this.style |= SWT.VERTICAL;
+ } else {
+ this.style |= SWT.HORIZONTAL;
+ }
+}
+static int checkStyle (int style) {
+ /*
+ * Even though it is legal to create this widget
+ * with scroll bars, they serve no useful purpose
+ * because they do not automatically scroll the
+ * widget's client area. The fix is to clear
+ * the SWT style.
+ */
+ return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
+}
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ checkWidget();
+ int width = wHint, height = hHint;
+ if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
+ if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
+ int [] result = layout (width, height, false);
+ 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;
+}
+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;
+}
+/**
+ * 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();
- ToolItem [] items = getItems ();
- if (0 <= index && index < items.length) 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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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();
+ ToolItem [] items = getItems ();
+ if (0 <= index && index < items.length) 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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; 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 ToolItem getItem (Point pt) {
+ checkWidget();
+ ToolItem [] items = getItems ();
+ for (int i=0; i<items.length; 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>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 int getItemCount () {
+ checkWidget();
+ return itemCount;
+}
+/**
+ * Returns an array of <code>TabItem</code>s which are the items
+ * in the receiver.
+ * <p>
+ * Note: This is not the actual structure used by the receiver
+ * to maintain its list of items, so modifying the array will
+ * not affect the receiver.
+ * </p>
+ *
+ * @return the items in the receiver
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
*/
-public 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 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 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);
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-int [] layoutHorizontal (int nWidth, int nHeight, boolean resize) {
- int xSpacing = 0, ySpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2;
- int marginWidth = 0, marginHeight = 0;
- ToolItem [] children = getItems ();
- int length = children.length;
- int x = marginWidth, y = marginHeight;
- int maxHeight = 0, maxX = 0, rows = 1;
- boolean wrap = (style & SWT.WRAP) != 0;
- for (int i=0; i<length; i++) {
- ToolItem child = children [i];
- Rectangle rect = child.getBounds ();
- if (wrap && i != 0 && x + rect.width > nWidth) {
- rows++;
- x = marginWidth; y += ySpacing + maxHeight;
- maxHeight = 0;
- }
- maxHeight = Math.max (maxHeight, rect.height);
- if (resize) {
- child.setBounds (x, y, rect.width, rect.height);
- }
- x += xSpacing + rect.width;
- maxX = Math.max (maxX, x);
- }
- return new int [] {rows, maxX, y + maxHeight};
-}
-int [] layoutVertical (int nWidth, int nHeight, boolean resize) {
- int xSpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2, ySpacing = 0;
- int marginWidth = 0, marginHeight = 0;
- ToolItem [] children = getItems ();
- int length = children.length;
- int x = marginWidth, y = marginHeight;
- int maxWidth = 0, maxY = 0, cols = 1;
- boolean wrap = (style & SWT.WRAP) != 0;
- for (int i=0; i<length; i++) {
- ToolItem child = children [i];
- Rectangle rect = child.getBounds ();
- if (wrap && i != 0 && y + rect.height > nHeight) {
- cols++;
- x += xSpacing + maxWidth; y = marginHeight;
- maxWidth = 0;
- }
- maxWidth = Math.max (maxWidth, rect.width);
- if (resize) {
- child.setBounds (x, y, rect.width, rect.height);
- }
- y += ySpacing + rect.height;
- maxY = Math.max (maxY, y);
- }
- return new int [] {cols, x + maxWidth, 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 < items.length; i++) {
- ToolItem item = items [i];
- if (item != null) {
- char mnemonic = findMnemonic (item.getText ());
- if (mnemonic != '\0') {
- if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) {
- XmProcessTraversal (item.handle, OS.XmTRAVERSE_CURRENT);
- item.click (false, null);
- return true;
- }
- }
- }
- }
- return false;
-}
-boolean mnemonicMatch (char key) {
- for (int i = 0; i < items.length; i++) {
- ToolItem item = items [i];
- if (item != null && 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 relayout () {
- if (drawCount > 0) return;
- Rectangle rect = getClientArea ();
- layout (rect.width, rect.height, true);
-}
-void relayout (int width, int height) {
- if (drawCount > 0) return;
- layout (width, height, true);
-}
-void releaseWidget () {
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (!item.isDisposed ()) item.releaseResources ();
- }
- items = null;
- super.releaseWidget ();
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- for (int i = 0; i < items.length; i++) {
- if (items[i] != null) {
- items[i].setBackgroundPixel (pixel);
- }
- }
-}
-public void setBounds (int x, int y, int width, int height) {
- super.setBounds (x, y, width, height);
- Rectangle rect = getClientArea ();
- relayout (rect.width, rect.height);
-}
-public void setFont (Font font) {
- checkWidget();
- super.setFont (font);
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null) {
- Point size = item.computeSize ();
- item.setSize (size.x, size.y, false);
- }
- }
- relayout ();
-}
-void setForegroundPixel (int pixel) {
- super.setForegroundPixel (pixel);
- for (int i = 0; i < items.length; i++) {
- if (items[i] != null) {
- items[i].setForegroundPixel (pixel);
- }
- }
-}
-public void setRedraw (boolean redraw) {
- checkWidget();
- if (redraw) {
- if (--drawCount == 0) relayout();
- } else {
- drawCount++;
- }
-}
-public void setSize (int width, int height) {
- super.setSize (width, height);
- Rectangle rect = getClientArea ();
- relayout (rect.width, rect.height);
-}
-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 ();
-}
-int traversalCode (int key, XKeyEvent xEvent) {
- return super.traversalCode (key, xEvent) | SWT.TRAVERSE_MNEMONIC;
-}
-}
+public int indexOf (ToolItem item) {
+ checkWidget();
+ if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ ToolItem [] items = getItems ();
+ for (int i=0; i<items.length; i++) {
+ if (items [i] == item) return i;
+ }
+ return -1;
+}
+int [] layoutHorizontal (int nWidth, int nHeight, boolean resize) {
+ int xSpacing = 0, ySpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2;
+ int marginWidth = 0, marginHeight = 0;
+ ToolItem [] children = getItems ();
+ int length = children.length;
+ int x = marginWidth, y = marginHeight;
+ int maxHeight = 0, maxX = 0, rows = 1;
+ boolean wrap = (style & SWT.WRAP) != 0;
+ for (int i=0; i<length; i++) {
+ ToolItem child = children [i];
+ Rectangle rect = child.getBounds ();
+ if (wrap && i != 0 && x + rect.width > nWidth) {
+ rows++;
+ x = marginWidth; y += ySpacing + maxHeight;
+ maxHeight = 0;
+ }
+ maxHeight = Math.max (maxHeight, rect.height);
+ if (resize) {
+ child.setBounds (x, y, rect.width, rect.height);
+ }
+ x += xSpacing + rect.width;
+ maxX = Math.max (maxX, x);
+ }
+ return new int [] {rows, maxX, y + maxHeight};
+}
+int [] layoutVertical (int nWidth, int nHeight, boolean resize) {
+ int xSpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2, ySpacing = 0;
+ int marginWidth = 0, marginHeight = 0;
+ ToolItem [] children = getItems ();
+ int length = children.length;
+ int x = marginWidth, y = marginHeight;
+ int maxWidth = 0, maxY = 0, cols = 1;
+ boolean wrap = (style & SWT.WRAP) != 0;
+ for (int i=0; i<length; i++) {
+ ToolItem child = children [i];
+ Rectangle rect = child.getBounds ();
+ if (wrap && i != 0 && y + rect.height > nHeight) {
+ cols++;
+ x += xSpacing + maxWidth; y = marginHeight;
+ maxWidth = 0;
+ }
+ maxWidth = Math.max (maxWidth, rect.width);
+ if (resize) {
+ child.setBounds (x, y, rect.width, rect.height);
+ }
+ y += ySpacing + rect.height;
+ maxY = Math.max (maxY, y);
+ }
+ return new int [] {cols, x + maxWidth, 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 < items.length; i++) {
+ ToolItem item = items [i];
+ if (item != null) {
+ char mnemonic = findMnemonic (item.getText ());
+ if (mnemonic != '\0') {
+ if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) {
+ XmProcessTraversal (item.handle, OS.XmTRAVERSE_CURRENT);
+ item.click (false, null);
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+boolean mnemonicMatch (char key) {
+ for (int i = 0; i < items.length; i++) {
+ ToolItem item = items [i];
+ if (item != null && 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 relayout () {
+ if (drawCount > 0) return;
+ Rectangle rect = getClientArea ();
+ layout (rect.width, rect.height, true);
+}
+void relayout (int width, int height) {
+ if (drawCount > 0) return;
+ layout (width, height, true);
+}
+void releaseWidget () {
+ for (int i=0; i<itemCount; i++) {
+ ToolItem item = items [i];
+ if (!item.isDisposed ()) item.releaseResources ();
+ }
+ items = null;
+ super.releaseWidget ();
+}
+void setBackgroundPixel (int pixel) {
+ super.setBackgroundPixel (pixel);
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] != null) {
+ items[i].setBackgroundPixel (pixel);
+ }
+ }
+}
+public void setBounds (int x, int y, int width, int height) {
+ super.setBounds (x, y, width, height);
+ Rectangle rect = getClientArea ();
+ relayout (rect.width, rect.height);
+}
+public void setFont (Font font) {
+ checkWidget();
+ super.setFont (font);
+ for (int i=0; i<items.length; i++) {
+ ToolItem item = items [i];
+ if (item != null) {
+ Point size = item.computeSize ();
+ item.setSize (size.x, size.y, false);
+ }
+ }
+ relayout ();
+}
+void setForegroundPixel (int pixel) {
+ super.setForegroundPixel (pixel);
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] != null) {
+ items[i].setForegroundPixel (pixel);
+ }
+ }
+}
+public void setRedraw (boolean redraw) {
+ checkWidget();
+ if (redraw) {
+ if (--drawCount == 0) relayout();
+ } else {
+ drawCount++;
+ }
+}
+public void setSize (int width, int height) {
+ super.setSize (width, height);
+ Rectangle rect = getClientArea ();
+ relayout (rect.width, rect.height);
+}
+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 ();
+}
+int traversalCode (int key, XKeyEvent xEvent) {
+ return super.traversalCode (key, xEvent) | SWT.TRAVERSE_MNEMONIC;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java
index 519806e5eb..0315c71630 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java
@@ -1,39 +1,39 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.motif.*;
-
-class ToolDrawable implements Drawable {
-
- Device device;
- int display;
- int drawable;
- Font font;
- int colormap;
-
-public int internal_new_GC (GCData data) {
- int xGC = OS.XCreateGC (display, drawable, 0, null);
- if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (data != null) {
- data.device = device;
- data.display = display;
- data.drawable = drawable;
- data.fontList = font.handle;
- data.codePage = font.codePage;
- data.colormap = colormap;
- }
- return xGC;
-}
-
-public void internal_dispose_GC (int xGC, GCData data) {
- OS.XFreeGC (display, xGC);
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.internal.motif.*;
+
+class ToolDrawable implements Drawable {
+
+ Device device;
+ int display;
+ int drawable;
+ Font font;
+ int colormap;
+
+public int internal_new_GC (GCData data) {
+ int xGC = OS.XCreateGC (display, drawable, 0, null);
+ if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ if (data != null) {
+ data.device = device;
+ data.display = display;
+ data.drawable = drawable;
+ data.fontList = font.handle;
+ data.codePage = font.codePage;
+ data.colormap = colormap;
+ }
+ return xGC;
+}
+
+public void internal_dispose_GC (int xGC, GCData data) {
+ OS.XFreeGC (display, xGC);
+}
+}
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
index 66cde49cf1..3b29933977 100755
--- 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
@@ -1,44 +1,44 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class ToolItem extends Item {
- ToolBar parent;
- Image hotImage, disabledImage;
- String toolTipText;
- Control control;
- boolean set;
-
- static final int DEFAULT_WIDTH = 24;
- static final int DEFAULT_HEIGHT = 22;
- static final int DEFAULT_SEPARATOR_WIDTH = 8;
-
+
+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;
+ 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
@@ -73,13 +73,13 @@ public class ToolItem extends Item {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public ToolItem (ToolBar parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
- parent.relayout ();
-}
-
+public ToolItem (ToolBar parent, int style) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ parent.createItem (this, parent.getItemCount ());
+ parent.relayout ();
+}
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>ToolBar</code>), a style value
@@ -115,209 +115,209 @@ public ToolItem (ToolBar parent, int style) {
* @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);
- parent.relayout ();
-}
-
-/**
- * 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 ToolItem (ToolBar parent, int style, int index) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ parent.createItem (this, index);
+ parent.relayout ();
+}
+
+/**
+ * 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;
- 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);
- int pixel = parent.getBackgroundPixel ();
- setBackgroundPixel (pixel);
-}
-
-void click (boolean dropDown, XInputEvent xEvent) {
- 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 (xEvent != null) setInputState (event, xEvent);
- postEvent (SWT.Selection, event);
-}
-
-Point computeSize () {
- if ((style & SWT.SEPARATOR) != 0) {
- int [] argList = {
- OS.XmNwidth, 0,
- OS.XmNheight, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int width = argList [1], height = argList [3];
- 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) {
- Display display = getDisplay ();
- shadowThickness = Math.min (2, display.buttonShadowThickness);
- }
- int textWidth = 0, textHeight = 0;
- if (text.length () != 0) {
- GC gc = new GC (parent);
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
- Point textExtent = gc.textExtent (text, flags);
- textWidth = textExtent.x;
- textHeight = textExtent.y;
- gc.dispose ();
- }
- int imageWidth = 0, imageHeight = 0;
- if (image != null) {
- Rectangle rect = image.getBounds ();
- imageWidth = rect.width;
- imageHeight = rect.height;
- }
- int width = 0, height = 0;
- 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);
- }
- 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);
- parent.relayout ();
-}
-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 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;
+ 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);
+ int pixel = parent.getBackgroundPixel ();
+ setBackgroundPixel (pixel);
+}
+
+void click (boolean dropDown, XInputEvent xEvent) {
+ 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 (xEvent != null) setInputState (event, xEvent);
+ postEvent (SWT.Selection, event);
+}
+
+Point computeSize () {
+ if ((style & SWT.SEPARATOR) != 0) {
+ int [] argList = {
+ OS.XmNwidth, 0,
+ OS.XmNheight, 0,
+ };
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int width = argList [1], height = argList [3];
+ 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) {
+ Display display = getDisplay ();
+ shadowThickness = Math.min (2, display.buttonShadowThickness);
+ }
+ int textWidth = 0, textHeight = 0;
+ if (text.length () != 0) {
+ GC gc = new GC (parent);
+ int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
+ Point textExtent = gc.textExtent (text, flags);
+ textWidth = textExtent.x;
+ textHeight = textExtent.y;
+ gc.dispose ();
+ }
+ int imageWidth = 0, imageHeight = 0;
+ if (image != null) {
+ Rectangle rect = image.getBounds ();
+ imageWidth = rect.width;
+ imageHeight = rect.height;
+ }
+ int width = 0, height = 0;
+ 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);
+ }
+ 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);
+ parent.relayout ();
+}
+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 items 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 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 items 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;
-}
+public Control getControl () {
+ checkWidget();
+ return control;
+}
/**
* Returns the receiver's disabled image if it has one, or null
* if it does not.
@@ -332,68 +332,68 @@ public Control getControl () {
* <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.
- * <p>
- * A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- * </p>
- *
- * @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>
+public Image getDisabledImage () {
+ checkWidget();
+ return disabledImage;
+}
+/**
+ * Returns <code>true</code> if the receiver is enabled, and
+ * <code>false</code> otherwise.
+ * <p>
+ * A disabled control is typically not selectable from the
+ * user interface and draws with an inactive or "grayed" look.
+ * </p>
+ *
+ * @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>
*/
-public boolean getEnabled () {
- checkWidget();
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-public Display getDisplay () {
- Composite parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/**
- * 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 boolean getEnabled () {
+ checkWidget();
+ int [] argList = {OS.XmNsensitive, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1] != 0;
+}
+public Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+ * 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 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;
-}
+public ToolBar getParent () {
+ checkWidget();
+ return parent;
+}
/**
* Returns <code>true</code> if the receiver is selected,
* and false otherwise.
@@ -411,317 +411,317 @@ public ToolBar getParent () {
* <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 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 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 [] argList = {OS.XmNwidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-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 = getDisplay ().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 display = getDisplay ();
- 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 int getWidth () {
+ checkWidget();
+ int [] argList = {OS.XmNwidth, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ return argList [1];
+}
+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 = getDisplay ().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 display = getDisplay ();
+ 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 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 releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-void releaseWidget () {
- Display display = getDisplay ();
- display.releaseToolTipHandle (handle);
- super.releaseWidget ();
- parent = 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 boolean isEnabled () {
+ checkWidget();
+ return getEnabled () && parent.isEnabled ();
+}
+void manageChildren () {
+ OS.XtManageChild (handle);
+}
+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 releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+void releaseWidget () {
+ Display display = getDisplay ();
+ display.releaseToolTipHandle (handle);
+ super.releaseWidget ();
+ parent = 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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) {
- if (control != null) control.setBounds(x, y, width, 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 items 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 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) {
+ if (control != null) control.setBounds(x, y, width, 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 items 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;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getBounds ());
- /*
- * 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);
- }
-}
-/**
- * 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 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;
+ if (control != null && !control.isDisposed ()) {
+ control.setBounds (getBounds ());
+ /*
+ * 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);
+ }
+}
+/**
+ * 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);
- 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 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 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);
+ 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 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 ();
-}
-/**
- * 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 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 ();
+}
+/**
+ * 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);
- Point size = computeSize ();
- setSize (size.x, size.y, true);
- redraw ();
-}
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
+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);
+ Point size = computeSize ();
+ setSize (size.x, size.y, true);
+ redraw ();
+}
+boolean setRadioSelection (boolean value) {
+ if ((style & SWT.RADIO) == 0) return false;
+ if (getSelection () != value) {
+ setSelection (value);
+ postEvent (SWT.Selection);
+ }
+ return true;
+}
/**
* Sets the selection state of the receiver.
* <p>
@@ -737,387 +737,387 @@ boolean setRadioSelection (boolean value) {
* <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);
-}
-
-void setSize (int width, int height, boolean layout) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] != width || argList [3] != height) {
- OS.XtResizeWidget (handle, width, height, 0);
- if (layout) parent.relayout ();
- }
-}
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setText (string);
- Point size = computeSize ();
- setSize (size.x, size.y, true);
- 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 setSelection (boolean selected) {
+ checkWidget();
+ if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
+ if (selected == set) return;
+ set = selected;
+ setDrawPressed (set);
+}
+
+void setSize (int width, int height, boolean layout) {
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ if (argList [1] != width || argList [3] != height) {
+ OS.XtResizeWidget (handle, width, height, 0);
+ if (layout) parent.relayout ();
+ }
+}
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.SEPARATOR) != 0) return;
+ super.setText (string);
+ Point size = computeSize ();
+ setSize (size.x, size.y, true);
+ 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;
-}
-/**
- * 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 setToolTipText (String string) {
+ checkWidget();
+ toolTipText = string;
+}
+/**
+ * Sets the width of the receiver.
+ *
+ * @param width the new width
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
*/
-public void setWidth (int width) {
- checkWidget();
- if ((style & SWT.SEPARATOR) == 0) return;
- if (width < 0) return;
- int [] argList = {OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- setSize (width, argList [1], true);
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getBounds ());
- }
-}
-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 (int key, int keysym, XKeyEvent xEvent) {
- return parent.translateAccelerator (key, keysym, xEvent);
-}
-boolean translateMnemonic (int key, XKeyEvent xEvent) {
- return parent.translateMnemonic (key, xEvent);
-}
-boolean translateTraversal (int key, XKeyEvent xEvent) {
- return parent.translateTraversal (key, xEvent);
-}
-void propagateWidget (boolean enabled) {
- propagateHandle (enabled, handle);
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
-// Shell shell = parent.getShell ();
- display.hideToolTip ();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if (xEvent.button == 1) {
- if (!set && (style & SWT.RADIO) == 0) {
- setDrawPressed (!set);
- }
- }
-
- /*
- * 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);
- parent.XButtonPress (w, client_data, call_data, continue_to_dispatch);
-
- /*
- * 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 (parent);
-// }
- return 0;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
- display.hideToolTip();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if (xEvent.button == 1) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int width = argList [1], height = argList [3];
- if (0 <= xEvent.x && xEvent.x < width && 0 <= xEvent.y && xEvent.y < height) {
- click (xEvent.x > width - 12, xEvent);
- }
- setDrawPressed(set);
- }
-
- /*
- * 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);
- parent.XButtonRelease (w, client_data, call_data, continue_to_dispatch);
-
- 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.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);
-// TEMPORARY CODE - need to fix the window field in xEvent
-// OS.memmove (callData, xEvent, XFocusChangeEvent.sizeof);
-
- /*
- * This code is intentionally commented.
- */
-// parent.processSetFocus (callData);
- 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);
- 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);
- break;
- case OS.XK_KP_Enter:
- case OS.XK_Return:
- click (true, xEvent);
- 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);
- 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);
-
- /*
- * 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 display = getDisplay ();
- 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) {
- Display display = getDisplay ();
- 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;
- }
- }
-
- ToolDrawable wrapper = new ToolDrawable ();
- wrapper.device = getDisplay ();
- wrapper.display = xDisplay;
- wrapper.drawable = xWindow;
- wrapper.font = parent.font;
- wrapper.colormap = argList [1];
- GC gc = new GC (wrapper);
-
- 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) {
- Display display = getDisplay ();
- 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;
- 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 ();
-
- 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 display = getDisplay ();
- 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.
- */
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.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);
- parent.sendMouseEvent (SWT.MouseMove, 0, xEvent);
-
- return 0;
-}
-}
+public void setWidth (int width) {
+ checkWidget();
+ if ((style & SWT.SEPARATOR) == 0) return;
+ if (width < 0) return;
+ int [] argList = {OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ setSize (width, argList [1], true);
+ if (control != null && !control.isDisposed ()) {
+ control.setBounds (getBounds ());
+ }
+}
+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 (int key, int keysym, XKeyEvent xEvent) {
+ return parent.translateAccelerator (key, keysym, xEvent);
+}
+boolean translateMnemonic (int key, XKeyEvent xEvent) {
+ return parent.translateMnemonic (key, xEvent);
+}
+boolean translateTraversal (int key, XKeyEvent xEvent) {
+ return parent.translateTraversal (key, xEvent);
+}
+void propagateWidget (boolean enabled) {
+ propagateHandle (enabled, handle);
+}
+int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
+ Display display = getDisplay ();
+// Shell shell = parent.getShell ();
+ display.hideToolTip ();
+ XButtonEvent xEvent = new XButtonEvent ();
+ OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
+ if (xEvent.button == 1) {
+ if (!set && (style & SWT.RADIO) == 0) {
+ setDrawPressed (!set);
+ }
+ }
+
+ /*
+ * 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);
+ parent.XButtonPress (w, client_data, call_data, continue_to_dispatch);
+
+ /*
+ * 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 (parent);
+// }
+ return 0;
+}
+int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
+ Display display = getDisplay ();
+ display.hideToolTip();
+ XButtonEvent xEvent = new XButtonEvent ();
+ OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
+ if (xEvent.button == 1) {
+ int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ int width = argList [1], height = argList [3];
+ if (0 <= xEvent.x && xEvent.x < width && 0 <= xEvent.y && xEvent.y < height) {
+ click (xEvent.x > width - 12, xEvent);
+ }
+ setDrawPressed(set);
+ }
+
+ /*
+ * 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);
+ parent.XButtonRelease (w, client_data, call_data, continue_to_dispatch);
+
+ 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.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);
+// TEMPORARY CODE - need to fix the window field in xEvent
+// OS.memmove (callData, xEvent, XFocusChangeEvent.sizeof);
+
+ /*
+ * This code is intentionally commented.
+ */
+// parent.processSetFocus (callData);
+ 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);
+ 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);
+ break;
+ case OS.XK_KP_Enter:
+ case OS.XK_Return:
+ click (true, xEvent);
+ 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);
+ 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);
+
+ /*
+ * 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 display = getDisplay ();
+ 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) {
+ Display display = getDisplay ();
+ 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;
+ }
+ }
+
+ ToolDrawable wrapper = new ToolDrawable ();
+ wrapper.device = getDisplay ();
+ wrapper.display = xDisplay;
+ wrapper.drawable = xWindow;
+ wrapper.font = parent.font;
+ wrapper.colormap = argList [1];
+ GC gc = new GC (wrapper);
+
+ 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) {
+ Display display = getDisplay ();
+ 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;
+ 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 ();
+
+ 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 display = getDisplay ();
+ 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.
+ */
+ XButtonEvent xEvent = new XButtonEvent ();
+ OS.memmove (xEvent, call_data, XButtonEvent.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);
+ parent.sendMouseEvent (SWT.MouseMove, 0, xEvent);
+
+ 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
index 60161f6cdc..446340ebe4 100755
--- 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
@@ -1,46 +1,46 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- Display display;
- boolean tracking, stippled;
- Rectangle [] rectangles, proportions;
- int cursorOrientation = SWT.NONE;
- int cursor;
- final static int STEPSIZE_SMALL = 1;
- final static int STEPSIZE_LARGE = 9;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+ Display display;
+ boolean tracking, stippled;
+ Rectangle [] rectangles, proportions;
+ int cursorOrientation = SWT.NONE;
+ int cursor;
+ 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.
@@ -73,12 +73,12 @@ public class Tracker extends Widget {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Tracker (Composite parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- display = parent.getDisplay ();
-}
-
+public Tracker (Composite parent, int style) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ display = parent.getDisplay ();
+}
+
/**
* Constructs a new instance of this class given the display
* to create it on and a style value describing its behavior
@@ -113,530 +113,530 @@ public Tracker (Composite parent, int style) {
* @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 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.Move,typedListener);
-}
-
-Point adjustMoveCursor (int xDisplay, int xWindow) {
- final int unused[] = new int[1];
- int actualX[] = new int[1];
- int actualY[] = new int[1];
-
- Rectangle bounds = computeBounds ();
- int newX = bounds.x + bounds.width / 2;
- int newY = bounds.y;
-
- OS.XWarpPointer (xDisplay, OS.None, xWindow, 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, xWindow, unused, unused, actualX, actualY, unused, unused, unused);
- return new Point (actualX[0], actualY[0]);
-}
-Point adjustResizeCursor (int xDisplay, int xWindow) {
- int newX, newY;
- Rectangle bounds = computeBounds ();
-
- 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];
- OS.XWarpPointer (xDisplay, 0, xWindow, 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, xWindow, 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];
- Rectangle bounds = computeBounds ();
- for (int i = 0; i < rects.length; i++) {
- result[i] = new Rectangle (
- (rects[i].x - bounds.x) * 100 / bounds.width,
- (rects[i].y - bounds.y) * 100 / bounds.height,
- rects[i].width * 100 / bounds.width,
- rects[i].height * 100 / bounds.height);
- }
- return result;
-}
-
-void drawRectangles () {
- if (parent != null) {
- if (parent.isDisposed ()) return;
- parent.getShell ().update ();
- } else {
- display.update ();
- }
- 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 [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- OS.XtGetValues (parent.handle, argList, argList.length / 2);
- color = argList [1] ^ argList [3];
- }
- 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<rectangles.length; i++) {
- Rectangle rect = rectangles [i];
- OS.XDrawRectangle (xDisplay, xWindow, gc, rect.x, rect.y, rect.width, rect.height);
- }
- if (stippled) {
- OS.XFreePixmap (xDisplay, stipplePixmap);
- }
- OS.XFreeGC (xDisplay, gc);
-}
-public Display getDisplay () {
- return display;
-}
-/**
- * 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 void addControlListener (ControlListener listener) {
+ checkWidget ();
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Move,typedListener);
+}
+
+Point adjustMoveCursor (int xDisplay, int xWindow) {
+ final int unused[] = new int[1];
+ int actualX[] = new int[1];
+ int actualY[] = new int[1];
+
+ Rectangle bounds = computeBounds ();
+ int newX = bounds.x + bounds.width / 2;
+ int newY = bounds.y;
+
+ OS.XWarpPointer (xDisplay, OS.None, xWindow, 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, xWindow, unused, unused, actualX, actualY, unused, unused, unused);
+ return new Point (actualX[0], actualY[0]);
+}
+Point adjustResizeCursor (int xDisplay, int xWindow) {
+ int newX, newY;
+ Rectangle bounds = computeBounds ();
+
+ 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];
+ OS.XWarpPointer (xDisplay, 0, xWindow, 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, xWindow, 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 Rectangle [] getRectangles () {
- checkWidget ();
- return rectangles;
-}
-/**
- * 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 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];
+ Rectangle bounds = computeBounds ();
+ for (int i = 0; i < rects.length; i++) {
+ result[i] = new Rectangle (
+ (rects[i].x - bounds.x) * 100 / bounds.width,
+ (rects[i].y - bounds.y) * 100 / bounds.height,
+ rects[i].width * 100 / bounds.width,
+ rects[i].height * 100 / bounds.height);
+ }
+ return result;
+}
+
+void drawRectangles () {
+ if (parent != null) {
+ if (parent.isDisposed ()) return;
+ parent.getShell ().update ();
+ } else {
+ display.update ();
+ }
+ 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 [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
+ OS.XtGetValues (parent.handle, argList, argList.length / 2);
+ color = argList [1] ^ argList [3];
+ }
+ 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<rectangles.length; i++) {
+ Rectangle rect = rectangles [i];
+ OS.XDrawRectangle (xDisplay, xWindow, gc, rect.x, rect.y, rect.width, rect.height);
+ }
+ if (stippled) {
+ OS.XFreePixmap (xDisplay, stipplePixmap);
+ }
+ OS.XFreeGC (xDisplay, gc);
+}
+public Display getDisplay () {
+ return display;
+}
+/**
+ * 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 boolean getStippled () {
- checkWidget ();
- return stippled;
-}
-
-void moveRectangles (int xChange, int yChange) {
- if (xChange < 0 && ((style & SWT.LEFT) == 0)) return;
- if (xChange > 0 && ((style & SWT.RIGHT) == 0)) return;
- if (yChange < 0 && ((style & SWT.UP) == 0)) return;
- if (yChange > 0 && ((style & SWT.DOWN) == 0)) return;
- 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;
- int xWindow = OS.XDefaultRootWindow (xDisplay);
- if (parent != null) {
- xWindow = OS.XtWindow (parent.handle);
- if (xWindow == 0) return false;
- }
- boolean cancelled = false;
- tracking = true;
- drawRectangles ();
- int [] oldX = new int [1], oldY = new int [1];
- int [] unused = new int [1], mask = new int [1];
- OS.XQueryPointer (xDisplay, xWindow, unused, unused, oldX, oldY, unused, unused, mask);
- 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 (xDisplay, xWindow);
- } else {
- cursorPos = adjustMoveCursor (xDisplay, xWindow);
- }
- oldX [0] = cursorPos.x; oldY [0] = cursorPos.y;
- }
-
- XAnyEvent xEvent = new XAnyEvent ();
- int [] newX = new int [1], newY = new int [1];
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
-
- int ptrGrabResult = OS.XGrabPointer (
- xDisplay,
- xWindow,
- 0,
- OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
- OS.GrabModeAsync,
- OS.GrabModeAsync,
- OS.None,
- OS.None,
- OS.CurrentTime);
- int kbdGrabResult = OS.XGrabKeyboard (
- xDisplay,
- xWindow,
- 0,
- OS.GrabModeAsync,
- OS.GrabModeAsync,
- OS.CurrentTime);
-
- /*
- * Tracker behaves like a Dialog with its own OS event loop.
- */
- while (tracking) {
- if (parent != null && parent.isDisposed ()) break;
- OS.XtAppNextEvent (xtContext, xEvent);
- switch (xEvent.type) {
- case OS.MotionNotify:
- if (cursor != 0) {
- OS.XChangeActivePointerGrab (
- xDisplay,
- OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
- cursor,
- OS.CurrentTime);
- }
- // fall through
- case OS.ButtonRelease:
- OS.XQueryPointer (xDisplay, xWindow, unused, unused, newX, newY, unused, unused, unused);
- if (oldX [0] != newX [0] || oldY [0] != newY [0]) {
- drawRectangles ();
- Event event = new Event ();
- event.x = newX [0];
- event.y = newY [0];
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (newX [0] - oldX [0], newY [0] - oldY [0]);
- sendEvent (SWT.Resize, event);
- cursorPos = adjustResizeCursor (xDisplay, xWindow);
- newX [0] = cursorPos.x; newY [0] = cursorPos.y;
- } else {
- moveRectangles (newX [0] - oldX [0], newY [0] - oldY [0]);
- 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 ()) {
- if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
- if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime);
- return false;
- }
- drawRectangles ();
- oldX [0] = newX [0]; oldY [0] = newY [0];
- }
- tracking = xEvent.type != OS.ButtonRelease;
- break;
- case OS.KeyPress:
- XKeyEvent keyEvent = new XKeyEvent ();
- OS.memmove (keyEvent, xEvent, 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 (xtContext, xEvent);
- break;
- case OS.XK_Escape:
- case OS.XK_Cancel:
- tracking = false;
- cancelled = true;
- /*
- * Eat the subsequent KeyRelease event
- */
- OS.XtAppNextEvent (xtContext, xEvent);
- 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) {
- drawRectangles ();
- Event event = new Event ();
- event.x = oldX[0] + xChange;
- event.y = oldY[0] + yChange;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (xChange, yChange);
- sendEvent (SWT.Resize, event);
- cursorPos = adjustResizeCursor (xDisplay, xWindow);
- } else {
- moveRectangles (xChange, yChange);
- sendEvent (SWT.Move, event);
- cursorPos = adjustMoveCursor (xDisplay, xWindow);
- }
- /*
- * 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 ()) {
- if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
- if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime);
- return false;
- }
- drawRectangles ();
- oldX[0] = cursorPos.x; oldY[0] = cursorPos.y;
- }
- }
- break;
- case OS.EnterNotify:
- case OS.LeaveNotify:
- /*
- * Do not dispatch these
- */
- break;
- default:
- OS.XtDispatchEvent (xEvent);
- }
- }
- drawRectangles ();
- if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
- if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime);
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 Rectangle [] getRectangles () {
+ checkWidget ();
+ return rectangles;
+}
+/**
+ * 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 void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, 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;
- } else if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
- cursorOrientation |= SWT.RIGHT;
- } else if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
- cursorOrientation |= SWT.UP;
- } else if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
- cursorOrientation |= SWT.DOWN;
- }
- Rectangle bounds = computeBounds ();
- 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;
- }
- /*
- * The following are conditions under which the resize should not be applied
- */
- if (bounds.width < 0 || bounds.height < 0) return;
-
- 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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)) return;
+ if (xChange > 0 && ((style & SWT.RIGHT) == 0)) return;
+ if (yChange < 0 && ((style & SWT.UP) == 0)) return;
+ if (yChange > 0 && ((style & SWT.DOWN) == 0)) return;
+ 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 void setRectangles (Rectangle [] rectangles) {
- checkWidget ();
- this.rectangles = rectangles;
- 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 boolean open () {
+ checkWidget ();
+ if (rectangles == null) return false;
+ int xDisplay = display.xDisplay;
+ int xWindow = OS.XDefaultRootWindow (xDisplay);
+ if (parent != null) {
+ xWindow = OS.XtWindow (parent.handle);
+ if (xWindow == 0) return false;
+ }
+ boolean cancelled = false;
+ tracking = true;
+ drawRectangles ();
+ int [] oldX = new int [1], oldY = new int [1];
+ int [] unused = new int [1], mask = new int [1];
+ OS.XQueryPointer (xDisplay, xWindow, unused, unused, oldX, oldY, unused, unused, mask);
+ 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 (xDisplay, xWindow);
+ } else {
+ cursorPos = adjustMoveCursor (xDisplay, xWindow);
+ }
+ oldX [0] = cursorPos.x; oldY [0] = cursorPos.y;
+ }
+
+ XAnyEvent xEvent = new XAnyEvent ();
+ int [] newX = new int [1], newY = new int [1];
+ int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
+
+ int ptrGrabResult = OS.XGrabPointer (
+ xDisplay,
+ xWindow,
+ 0,
+ OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
+ OS.GrabModeAsync,
+ OS.GrabModeAsync,
+ OS.None,
+ OS.None,
+ OS.CurrentTime);
+ int kbdGrabResult = OS.XGrabKeyboard (
+ xDisplay,
+ xWindow,
+ 0,
+ OS.GrabModeAsync,
+ OS.GrabModeAsync,
+ OS.CurrentTime);
+
+ /*
+ * Tracker behaves like a Dialog with its own OS event loop.
+ */
+ while (tracking) {
+ if (parent != null && parent.isDisposed ()) break;
+ OS.XtAppNextEvent (xtContext, xEvent);
+ switch (xEvent.type) {
+ case OS.MotionNotify:
+ if (cursor != 0) {
+ OS.XChangeActivePointerGrab (
+ xDisplay,
+ OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
+ cursor,
+ OS.CurrentTime);
+ }
+ // fall through
+ case OS.ButtonRelease:
+ OS.XQueryPointer (xDisplay, xWindow, unused, unused, newX, newY, unused, unused, unused);
+ if (oldX [0] != newX [0] || oldY [0] != newY [0]) {
+ drawRectangles ();
+ Event event = new Event ();
+ event.x = newX [0];
+ event.y = newY [0];
+ if ((style & SWT.RESIZE) != 0) {
+ resizeRectangles (newX [0] - oldX [0], newY [0] - oldY [0]);
+ sendEvent (SWT.Resize, event);
+ cursorPos = adjustResizeCursor (xDisplay, xWindow);
+ newX [0] = cursorPos.x; newY [0] = cursorPos.y;
+ } else {
+ moveRectangles (newX [0] - oldX [0], newY [0] - oldY [0]);
+ 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 ()) {
+ if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
+ if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime);
+ return false;
+ }
+ drawRectangles ();
+ oldX [0] = newX [0]; oldY [0] = newY [0];
+ }
+ tracking = xEvent.type != OS.ButtonRelease;
+ break;
+ case OS.KeyPress:
+ XKeyEvent keyEvent = new XKeyEvent ();
+ OS.memmove (keyEvent, xEvent, 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 (xtContext, xEvent);
+ break;
+ case OS.XK_Escape:
+ case OS.XK_Cancel:
+ tracking = false;
+ cancelled = true;
+ /*
+ * Eat the subsequent KeyRelease event
+ */
+ OS.XtAppNextEvent (xtContext, xEvent);
+ 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) {
+ drawRectangles ();
+ Event event = new Event ();
+ event.x = oldX[0] + xChange;
+ event.y = oldY[0] + yChange;
+ if ((style & SWT.RESIZE) != 0) {
+ resizeRectangles (xChange, yChange);
+ sendEvent (SWT.Resize, event);
+ cursorPos = adjustResizeCursor (xDisplay, xWindow);
+ } else {
+ moveRectangles (xChange, yChange);
+ sendEvent (SWT.Move, event);
+ cursorPos = adjustMoveCursor (xDisplay, xWindow);
+ }
+ /*
+ * 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 ()) {
+ if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
+ if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime);
+ return false;
+ }
+ drawRectangles ();
+ oldX[0] = cursorPos.x; oldY[0] = cursorPos.y;
+ }
+ }
+ break;
+ case OS.EnterNotify:
+ case OS.LeaveNotify:
+ /*
+ * Do not dispatch these
+ */
+ break;
+ default:
+ OS.XtDispatchEvent (xEvent);
+ }
+ }
+ drawRectangles ();
+ if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
+ if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime);
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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);
+}
+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;
+ } else if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
+ cursorOrientation |= SWT.RIGHT;
+ } else if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
+ cursorOrientation |= SWT.UP;
+ } else if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
+ cursorOrientation |= SWT.DOWN;
+ }
+ Rectangle bounds = computeBounds ();
+ 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;
+ }
+ /*
+ * The following are conditions under which the resize should not be applied
+ */
+ if (bounds.width < 0 || bounds.height < 0) return;
+
+ 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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 ();
+ this.rectangles = rectangles;
+ 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;
-}
-}
+public void setStippled (boolean stippled) {
+ checkWidget ();
+ this.stippled = stippled;
+}
+}
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
index 5feb526856..b4a0452721 100755
--- 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
@@ -1,109 +1,109 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public abstract class Widget {
- public int handle;
- int style, state;
- EventTable eventTable;
- Object data;
- String [] keys;
- Object [] values;
-
- /* Global state flags */
-// static final int AUTOMATIC = 0x00000001;
-// static final int ACTIVE = 0x00000002;
-// static final int AUTOGRAB = 0x00000004;
-// static final int MULTIEXPOSE = 0x00000008;
-// static final int RESIZEREDRAW = 0x00000010;
-// static final int WRAP = 0x00000020;
-// static final int DISABLED = 0x00000040;
-// static final int HIDDEN = 0x00000080;
-// static final int FOREGROUND = 0x00000100;
-// static final int BACKGROUND = 0x00000200;
- static final int DISPOSED = 0x00000400;
- static final int HANDLE = 0x00000800;
- static final int CANVAS = 0x00001000;
-
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
- /* Global widget variables */
- static final char Mnemonic = '&';
-
- /* 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 SELECTION_CALLBACK = 22;
- static final int TO_BOTTOM_CALLBACK = 23;
- static final int TO_TOP_CALLBACK = 24;
- static final int VALUE_CHANGED_CALLBACK = 25;
- static final int NON_MASKABLE = 26;
- static final int POINTER_MOTION = 27;
- static final int STRUCTURE_NOTIFY = 28;
- static final int MAP_CALLBACK = 29;
- static final int UNMAP_CALLBACK = 30;
- static final int DELETE_WINDOW = 31;
- static final int EXPOSURE_CALLBACK = 32;
-
-Widget () {
- /* Do nothing */
-}
+
+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 {
+ public int handle;
+ int style, state;
+ EventTable eventTable;
+ Object data;
+ String [] keys;
+ Object [] values;
+
+ /* Global state flags */
+// static final int AUTOMATIC = 0x00000001;
+// static final int ACTIVE = 0x00000002;
+// static final int AUTOGRAB = 0x00000004;
+// static final int MULTIEXPOSE = 0x00000008;
+// static final int RESIZEREDRAW = 0x00000010;
+// static final int WRAP = 0x00000020;
+// static final int DISABLED = 0x00000040;
+// static final int HIDDEN = 0x00000080;
+// static final int FOREGROUND = 0x00000100;
+// static final int BACKGROUND = 0x00000200;
+ static final int DISPOSED = 0x00000400;
+ static final int HANDLE = 0x00000800;
+ static final int CANVAS = 0x00001000;
+
+ static final int DEFAULT_WIDTH = 64;
+ static final int DEFAULT_HEIGHT = 64;
+
+ /* Global widget variables */
+ static final char Mnemonic = '&';
+
+ /* 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 SELECTION_CALLBACK = 22;
+ static final int TO_BOTTOM_CALLBACK = 23;
+ static final int TO_TOP_CALLBACK = 24;
+ static final int VALUE_CHANGED_CALLBACK = 25;
+ static final int NON_MASKABLE = 26;
+ static final int POINTER_MOTION = 27;
+ static final int STRUCTURE_NOTIFY = 28;
+ static final int MAP_CALLBACK = 29;
+ static final int UNMAP_CALLBACK = 30;
+ static final int DELETE_WINDOW = 31;
+ static final int EXPOSURE_CALLBACK = 32;
+
+Widget () {
+ /* Do nothing */
+}
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -132,538 +132,538 @@ Widget () {
* @see #checkSubclass
* @see #getStyle
*/
-public Widget (Widget parent, int style) {
- checkSubclass ();
- checkParent (parent);
- this.style = style;
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notifed 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.
- *
- * @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 #removeListener
+public Widget (Widget parent, int style) {
+ checkSubclass ();
+ checkParent (parent);
+ this.style = style;
+}
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notifed 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.
+ *
+ * @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 #removeListener
*/
-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 notifed 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 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 notifed 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 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.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (parent.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
-}
-/**
- * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) 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;
- WidgetTable.remove (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 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 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.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (parent.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+}
+/**
+ * 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>
*/
-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);
- releaseChild ();
- releaseWidget ();
- destroyWidget ();
-}
-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) {
- Display display = getDisplay ();
- return display.filters (eventType);
-}
-/**
- * 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
+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 () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (isDisposed ()) 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;
+ WidgetTable.remove (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 Object getData () {
- checkWidget();
- return 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
+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);
+ releaseChild ();
+ releaseWidget ();
+ destroyWidget ();
+}
+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) {
+ Display display = getDisplay ();
+ return display.filters (eventType);
+}
+/**
+ * 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
+ */
+public Object getData () {
+ checkWidget();
+ return 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
+ */
+public Object getData (String key) {
+ checkWidget();
+ 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 <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>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
*/
-public Object getData (String key) {
- checkWidget();
- 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 <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>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public abstract Display getDisplay ();
+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 abstract Display getDisplay ();
-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 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 () {
+ if (handle != 0) return false;
+ if ((state & HANDLE) != 0) return true;
+ return (state & DISPOSED) != 0;
+}
+/**
+ * Return the listening state.
+ * <p>
+ * Returns true if there is a listener, listening for the eventType.
+ * Otherwise, returns false.
+ *
+ * @param eventType the type of event
+ * @return true if the event is hooked
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
+ * <li>ERROR_NULL_ARGUMENT when the name is null</li>
+ * </ul>
*/
-public boolean isDisposed () {
- if (handle != 0) return false;
- if ((state & HANDLE) != 0) return true;
- return (state & DISPOSED) != 0;
-}
-/**
- * Return the listening state.
- * <p>
- * Returns true if there is a listener, listening for the eventType.
- * Otherwise, returns false.
- *
- * @param eventType the type of event
- * @return true if the event is hooked
- *
- * @exception SWTError <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
- * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
- * <li>ERROR_NULL_ARGUMENT when the name is null</li>
- * </ul>
+protected boolean isListening (int eventType) {
+ checkWidget();
+ return hooks (eventType);
+}
+boolean isValidSubclass () {
+ return Display.isValidClass (getClass ());
+}
+boolean isValidThread () {
+ return getDisplay ().isValidThread ();
+}
+void manageChildren () {
+ /* Do nothing */
+}
+char mbcsToWcs (int ch) {
+ return mbcsToWcs (ch, null);
+}
+char mbcsToWcs (int ch, String codePage) {
+ 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 [] result = Converter.mbcsToWcs (codePage, buffer);
+ if (result.length == 0) return 0;
+ return result [0];
+}
+/**
+ * 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.
+ *
+ * @param eventType the type of event which has occurred
+ * @param event the event data
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
*/
-protected boolean isListening (int eventType) {
- checkWidget();
- return hooks (eventType);
-}
-boolean isValidSubclass () {
- return Display.isValidClass (getClass ());
-}
-boolean isValidThread () {
- return getDisplay ().isValidThread ();
-}
-void manageChildren () {
- /* Do nothing */
-}
-char mbcsToWcs (int ch) {
- return mbcsToWcs (ch, null);
-}
-char mbcsToWcs (int ch, String codePage) {
- 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 [] result = Converter.mbcsToWcs (codePage, buffer);
- if (result.length == 0) return 0;
- return result [0];
-}
-/**
- * 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.
- *
- * @param eventType the type of event which has occurred
- * @param event the event data
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void notifyListeners (int eventType, Event event) {
+ checkWidget();
+ if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
+ 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 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;
+ }
+ XSetWindowAttributes attributes = new XSetWindowAttributes ();
+ attributes.event_mask = event_mask;
+ attributes.do_not_propagate_mask = do_not_propagate_mask;
+ OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWDontPropagate | OS.CWEventMask, attributes);
+}
+void redrawHandle (int x, int y, int width, int height, int widgetHandle) {
+ int display = OS.XtDisplay (widgetHandle);
+ if (display == 0) return;
+ int window = OS.XtWindow (widgetHandle);
+ if (window == 0) return;
+ int [] argList = {OS.XmNborderWidth, 0, OS.XmNborderColor, 0};
+ OS.XtGetValues (widgetHandle, argList, argList.length / 2);
+ if (argList [1] != 0) {
+ /* Force the border to repaint by setting the color */
+ OS.XtSetValues (widgetHandle, argList, argList.length / 2);
+ }
+ OS.XClearArea (display, window, x, y, width, height, true);
+}
+void register () {
+ if (handle == 0) return;
+ WidgetTable.put (handle, this);
+}
+void releaseChild () {
+ /* Do nothing */
+}
+void releaseHandle () {
+ handle = 0;
+ state |= DISPOSED;
+}
+void releaseResources () {
+ releaseWidget ();
+ releaseHandle ();
+}
+void releaseWidget () {
+ sendEvent (SWT.Dispose);
+ deregister ();
+ eventTable = null;
+ data = null;
+ keys = null;
+ values = null;
+}
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notifed when an event of the given type occurs.
+ *
+ * @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
*/
-public void notifyListeners (int eventType, Event event) {
- checkWidget();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- 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 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;
- }
- XSetWindowAttributes attributes = new XSetWindowAttributes ();
- attributes.event_mask = event_mask;
- attributes.do_not_propagate_mask = do_not_propagate_mask;
- OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWDontPropagate | OS.CWEventMask, attributes);
-}
-void redrawHandle (int x, int y, int width, int height, int widgetHandle) {
- int display = OS.XtDisplay (widgetHandle);
- if (display == 0) return;
- int window = OS.XtWindow (widgetHandle);
- if (window == 0) return;
- int [] argList = {OS.XmNborderWidth, 0, OS.XmNborderColor, 0};
- OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- if (argList [1] != 0) {
- /* Force the border to repaint by setting the color */
- OS.XtSetValues (widgetHandle, argList, argList.length / 2);
- }
- OS.XClearArea (display, window, x, y, width, height, true);
-}
-void register () {
- if (handle == 0) return;
- WidgetTable.put (handle, this);
-}
-void releaseChild () {
- /* Do nothing */
-}
-void releaseHandle () {
- handle = 0;
- state |= DISPOSED;
-}
-void releaseResources () {
- releaseWidget ();
- releaseHandle ();
-}
-void releaseWidget () {
- sendEvent (SWT.Dispose);
- deregister ();
- eventTable = null;
- data = null;
- keys = null;
- values = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notifed when an event of the given type occurs.
- *
- * @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
+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 notifed 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
*/
-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 notifed 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);
-}
+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 notifed when the widget is disposed.
@@ -681,443 +681,443 @@ protected void removeListener (int eventType, SWTEventListener handler) {
* @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 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;
-}
-void setInputState (Event event, XInputEvent xEvent) {
- setInputState (event, xEvent.state);
-}
-void setKeyState (Event event, XKeyEvent xEvent) {
- if (xEvent.keycode != 0) {
- byte [] buffer = new byte [1];
- int [] keysym = new int [1];
- OS.XLookupString (xEvent, buffer, buffer.length, keysym, null);
-
- /*
- * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not
- * translated correctly by XLookupString(). They are mapped
- * to 0x1005FF10 and 0x1005FF11 respectively. The fix is to
- * look for these values explicitly and correct them.
- */
- if (OS.IsSunOS && keysym [0] != 0) {
- switch (keysym [0]) {
- case 0x1005FF10:
- keysym [0] = OS.XK_F11;
- buffer [0] = 0;
- break;
- case 0x1005FF11:
- keysym [0] = OS.XK_F12;
- buffer [0] = 0;
- 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;
- }
-
- /*
- * 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+[.
- */
- if ((xEvent.state & OS.ControlMask) != 0) {
- int key = keysym [0];
- if (0 <= key && key <= 0x7F) {
- if ('a' <= key && key <= 'z') {
- key -= 'a' - 'A';
- }
- if (!(64 <= key && key <= 95)) {
- buffer [0] = (byte) key;
- }
- }
- }
-
- /*
- * 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 explicitly and correct them. */
- if (OS.IsHPUX && keysym [0] != 0) {
- switch (keysym [0]) {
- case 0xFF91:
- keysym [0] = OS.XK_F9;
- break;
- case 0xFF92:
- keysym [0] = OS.XK_F10;
- break;
- case 0xFF93:
- keysym [0] = OS.XK_F11;
- break;
- case 0xFF94:
- keysym [0] = OS.XK_F12;
- 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_ISO_Left_Tab: buffer [0] = '\t'; break;
- case OS.XK_space: buffer [0] = ' '; break;
- }
-
- /* Fill in the event keyCode or character */
- if (keysym [0] != 0) {
- event.keyCode = Display.translateKey (keysym [0]);
- }
- if (buffer [0] != 0) {
- event.character = mbcsToWcs (buffer [0] & 0xFF);
- }
- }
- setInputState (event, xEvent);
-}
-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) {
- Display display = getDisplay ();
- 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>
+public void removeDisposeListener (DisposeListener listener) {
+ checkWidget();
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Dispose, listener);
+}
+void 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;
+}
+void setInputState (Event event, XInputEvent xEvent) {
+ setInputState (event, xEvent.state);
+}
+void setKeyState (Event event, XKeyEvent xEvent) {
+ if (xEvent.keycode != 0) {
+ byte [] buffer = new byte [1];
+ int [] keysym = new int [1];
+ OS.XLookupString (xEvent, buffer, buffer.length, keysym, null);
+
+ /*
+ * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not
+ * translated correctly by XLookupString(). They are mapped
+ * to 0x1005FF10 and 0x1005FF11 respectively. The fix is to
+ * look for these values explicitly and correct them.
+ */
+ if (OS.IsSunOS && keysym [0] != 0) {
+ switch (keysym [0]) {
+ case 0x1005FF10:
+ keysym [0] = OS.XK_F11;
+ buffer [0] = 0;
+ break;
+ case 0x1005FF11:
+ keysym [0] = OS.XK_F12;
+ buffer [0] = 0;
+ 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;
+ }
+
+ /*
+ * 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+[.
+ */
+ if ((xEvent.state & OS.ControlMask) != 0) {
+ int key = keysym [0];
+ if (0 <= key && key <= 0x7F) {
+ if ('a' <= key && key <= 'z') {
+ key -= 'a' - 'A';
+ }
+ if (!(64 <= key && key <= 95)) {
+ buffer [0] = (byte) key;
+ }
+ }
+ }
+
+ /*
+ * 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 explicitly and correct them. */
+ if (OS.IsHPUX && keysym [0] != 0) {
+ switch (keysym [0]) {
+ case 0xFF91:
+ keysym [0] = OS.XK_F9;
+ break;
+ case 0xFF92:
+ keysym [0] = OS.XK_F10;
+ break;
+ case 0xFF93:
+ keysym [0] = OS.XK_F11;
+ break;
+ case 0xFF94:
+ keysym [0] = OS.XK_F12;
+ 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_ISO_Left_Tab: buffer [0] = '\t'; break;
+ case OS.XK_space: buffer [0] = ' '; break;
+ }
+
+ /* Fill in the event keyCode or character */
+ if (keysym [0] != 0) {
+ event.keyCode = Display.translateKey (keysym [0]);
+ }
+ if (buffer [0] != 0) {
+ event.character = mbcsToWcs (buffer [0] & 0xFF);
+ }
+ }
+ setInputState (event, xEvent);
+}
+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) {
+ Display display = getDisplay ();
+ 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>
*/
-public void setData (Object data) {
- checkWidget();
- 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
+public void setData (Object data) {
+ checkWidget();
+ 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
*/
-public void setData (String key, Object value) {
- checkWidget();
- 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;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
+public void setData (String key, Object value) {
+ checkWidget();
+ 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;
+}
+
+/**
+ * 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 (int key, int keysym, XKeyEvent xEvent) {
- return false;
-}
-boolean translateMnemonic (int key, 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 = getDisplay ();
- boolean oldFocusOut = display.postFocusOut;
- display.postFocusOut = true;
- boolean result = OS.XmProcessTraversal (widget, direction);
- display.postFocusOut = oldFocusOut;
- if (!display.postFocusOut) display.runFocusOutEvents ();
- return result;
-}
-int wcsToMbcs (char ch) {
- return wcsToMbcs (ch, null);
-}
-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 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 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 PAGE_DECREMENT_CALLBACK: return XmNpageDecrementCallback (w, client_data, call_data);
- case PAGE_INCREMENT_CALLBACK: return XmNpageIncrementCallback (w, client_data, call_data);
- case SELECTION_CALLBACK: return XmNselectionCallback (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) {
- return 0;
-}
-int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- 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 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 XmNpageDecrementCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNpageIncrementCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNselectionCallback (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;
-}
-}
+public String toString () {
+ String string = "*Disposed*";
+ if (!isDisposed ()) {
+ string = "*Wrong Thread*";
+ if (isValidThread ()) string = getNameText ();
+ }
+ return getName () + " {" + string + "}";
+}
+int topHandle () {
+ return handle;
+}
+boolean translateAccelerator (int key, int keysym, XKeyEvent xEvent) {
+ return false;
+}
+boolean translateMnemonic (int key, 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 = getDisplay ();
+ boolean oldFocusOut = display.postFocusOut;
+ display.postFocusOut = true;
+ boolean result = OS.XmProcessTraversal (widget, direction);
+ display.postFocusOut = oldFocusOut;
+ if (!display.postFocusOut) display.runFocusOutEvents ();
+ return result;
+}
+int wcsToMbcs (char ch) {
+ return wcsToMbcs (ch, null);
+}
+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 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 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 PAGE_DECREMENT_CALLBACK: return XmNpageDecrementCallback (w, client_data, call_data);
+ case PAGE_INCREMENT_CALLBACK: return XmNpageIncrementCallback (w, client_data, call_data);
+ case SELECTION_CALLBACK: return XmNselectionCallback (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) {
+ return 0;
+}
+int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
+ 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 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 XmNpageDecrementCallback (int w, int client_data, int call_data) {
+ return 0;
+}
+int XmNpageIncrementCallback (int w, int client_data, int call_data) {
+ return 0;
+}
+int XmNselectionCallback (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/motif/org/eclipse/swt/widgets/WidgetTable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java
index ce5ac52d44..fec0c7d19e 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java
@@ -1,123 +1,123 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-
-class WidgetTable {
- static int FreeSlot = 0;
- static int GrowSize = 1024;
- static int [] IndexTable = new int [GrowSize];
- static Shell [] Shells = new Shell [GrowSize / 8];
- static Widget [] WidgetTable = new Widget [GrowSize];
- static int [] ArgList = {OS.XmNuserData, 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;
- if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
- for (int i=0; i<Shells.length; i++) {
- Widget shell = Shells [i];
- if ((shell != null) && (shell.topHandle () == handle)) return shell;
- }
- return null;
- }
- ArgList [1] = 0;
- OS.XtGetValues (handle, ArgList, ArgList.length / 2);
- if (ArgList [1] == 0) return null;
- int index = ArgList [1] - 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 (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
- for (int i=0; i<Shells.length; i++) {
- if (Shells [i] == null) {
- Shells [i] = (Shell) widget;
- return;
- }
- }
- Shell [] newShells = new Shell [Shells.length + GrowSize / 8];
- System.arraycopy (Shells, 0, newShells, 0, Shells.length);
- newShells [Shells.length] = (Shell) widget;
- Shells = newShells;
- 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;
- }
- ArgList [1] = FreeSlot + 1;
- OS.XtSetValues (handle, ArgList, ArgList.length / 2);
- int oldSlot = FreeSlot;
- FreeSlot = IndexTable [oldSlot];
- IndexTable [oldSlot] = -2;
- WidgetTable [oldSlot] = widget;
-}
-public static synchronized Widget remove (int handle) {
- if (handle == 0) return null;
- if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
- for (int i=0; i<Shells.length; i++) {
- Widget shell = Shells [i];
- if ((shell != null) && (shell.topHandle () == handle)) {
- Shells [i] = null;
- return shell;
- }
- }
- return null;
- }
- ArgList [1] = 0;
- Widget widget = null;
- OS.XtGetValues (handle, ArgList, ArgList.length / 2);
- int index = ArgList [1] - 1;
- if (0 <= index && index < WidgetTable.length) {
- widget = WidgetTable [index];
- WidgetTable [index] = null;
- IndexTable [index] = FreeSlot;
- FreeSlot = index;
- ArgList [1] = 0;
- OS.XtSetValues (handle, ArgList, ArgList.length / 2);
- }
- return widget;
-}
-public static synchronized Shell [] shells () {
- int length = 0;
- for (int i=0; i<Shells.length; i++) {
- if (Shells [i] != null) length++;
- }
- int index = 0;
- Shell [] result = new Shell [length];
- for (int i=0; i<Shells.length; i++) {
- Shell widget = Shells [i];
- if (widget != null) result [index++] = widget;
- }
- return result;
-}
-public static synchronized int size () {
- int length = 0;
- for (int i=0; i<Shells.length; i++) {
- if (Shells [i] != null) length++;
- }
- for (int i=0; i<WidgetTable.length; i++) {
- if (WidgetTable [i] != null) length++;
- }
- return length;
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.motif.*;
+
+class WidgetTable {
+ static int FreeSlot = 0;
+ static int GrowSize = 1024;
+ static int [] IndexTable = new int [GrowSize];
+ static Shell [] Shells = new Shell [GrowSize / 8];
+ static Widget [] WidgetTable = new Widget [GrowSize];
+ static int [] ArgList = {OS.XmNuserData, 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;
+ if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
+ for (int i=0; i<Shells.length; i++) {
+ Widget shell = Shells [i];
+ if ((shell != null) && (shell.topHandle () == handle)) return shell;
+ }
+ return null;
+ }
+ ArgList [1] = 0;
+ OS.XtGetValues (handle, ArgList, ArgList.length / 2);
+ if (ArgList [1] == 0) return null;
+ int index = ArgList [1] - 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 (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
+ for (int i=0; i<Shells.length; i++) {
+ if (Shells [i] == null) {
+ Shells [i] = (Shell) widget;
+ return;
+ }
+ }
+ Shell [] newShells = new Shell [Shells.length + GrowSize / 8];
+ System.arraycopy (Shells, 0, newShells, 0, Shells.length);
+ newShells [Shells.length] = (Shell) widget;
+ Shells = newShells;
+ 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;
+ }
+ ArgList [1] = FreeSlot + 1;
+ OS.XtSetValues (handle, ArgList, ArgList.length / 2);
+ int oldSlot = FreeSlot;
+ FreeSlot = IndexTable [oldSlot];
+ IndexTable [oldSlot] = -2;
+ WidgetTable [oldSlot] = widget;
+}
+public static synchronized Widget remove (int handle) {
+ if (handle == 0) return null;
+ if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
+ for (int i=0; i<Shells.length; i++) {
+ Widget shell = Shells [i];
+ if ((shell != null) && (shell.topHandle () == handle)) {
+ Shells [i] = null;
+ return shell;
+ }
+ }
+ return null;
+ }
+ ArgList [1] = 0;
+ Widget widget = null;
+ OS.XtGetValues (handle, ArgList, ArgList.length / 2);
+ int index = ArgList [1] - 1;
+ if (0 <= index && index < WidgetTable.length) {
+ widget = WidgetTable [index];
+ WidgetTable [index] = null;
+ IndexTable [index] = FreeSlot;
+ FreeSlot = index;
+ ArgList [1] = 0;
+ OS.XtSetValues (handle, ArgList, ArgList.length / 2);
+ }
+ return widget;
+}
+public static synchronized Shell [] shells () {
+ int length = 0;
+ for (int i=0; i<Shells.length; i++) {
+ if (Shells [i] != null) length++;
+ }
+ int index = 0;
+ Shell [] result = new Shell [length];
+ for (int i=0; i<Shells.length; i++) {
+ Shell widget = Shells [i];
+ if (widget != null) result [index++] = widget;
+ }
+ return result;
+}
+public static synchronized int size () {
+ int length = 0;
+ for (int i=0; i<Shells.length; i++) {
+ if (Shells [i] != null) length++;
+ }
+ for (int i=0; i<WidgetTable.length; i++) {
+ if (WidgetTable [i] != null) length++;
+ }
+ return length;
+}
+}
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
index e2c0de95a9..cf558e9838 100755
--- 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
@@ -1,14 +1,14 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -22,22 +22,22 @@ import org.eclipse.swt.*;
*
* @see RGB
*/
-public final class Color {
-
- /**
- * the handle to the OS color resource
- * (Warning: This field is platform dependent)
+public final class Color {
+
+ /**
+ * the handle to the OS color resource
+ * (Warning: This field is platform dependent)
*/
- public int handle;
-
- /**
- * the device where this color was created
+ public int handle;
+
+ /**
+ * the device where this color was created
*/
- Device device;
-
-Color() {
-}
-
+ Device device;
+
+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
@@ -62,13 +62,13 @@ Color() {
*
* @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);
-}
-
+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.
@@ -91,28 +91,28 @@ public Color (Device device, int red, int green, int blue) {
*
* @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);
-}
-
+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;
-}
-
+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
@@ -123,13 +123,13 @@ public void dispose() {
*
* @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);
-}
-
+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.
*
@@ -139,11 +139,11 @@ public boolean equals (Object object) {
* <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;
-}
-
+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.
*
@@ -153,11 +153,11 @@ public int getBlue () {
* <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;
-}
-
+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.
*
@@ -167,11 +167,11 @@ public int getGreen () {
* <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;
-}
-
+public int getRed () {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ return (handle & 0xFF0000) >> 16;
+}
+
/**
* Returns an <code>RGB</code> representing the receiver.
*
@@ -179,11 +179,11 @@ public int getRed () {
* <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);
-}
-
+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 which return <code>true</code> when passed to
@@ -194,18 +194,18 @@ public RGB getRGB () {
*
* @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);
-}
-
+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.
@@ -216,26 +216,26 @@ void init(Device device, int red, int green, int blue) {
*
* @return <code>true</code> when the color is disposed and <code>false</code> otherwise
*/
-public boolean isDisposed() {
- return handle == -1;
-}
-
+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;
-}
+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
index f03104f83c..870119152a 100755
--- 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
@@ -1,15 +1,15 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -34,28 +34,28 @@ import org.eclipse.swt.*;
* Note: Only one of the above styles may be specified.
* </p>
*/
-public final class Cursor {
-
- /**
- * the type to the OS cursor resource
- * (Warning: This field is platform dependent)
+public final class Cursor {
+
+ /**
+ * the type to the OS cursor resource
+ * (Warning: This field is platform dependent)
*/
- public int type;
-
- /**
- * the handle to the OS cursor resource
- * (Warning: This field is platform dependent)
+ public int type;
+
+ /**
+ * the handle to the OS cursor resource
+ * (Warning: This field is platform dependent)
*/
- public int bitmap;
-
- /**
- * the device where this cursor was created
+ public int bitmap;
+
+ /**
+ * the device where this cursor was created
*/
- Device device;
-
-Cursor() {
-}
-
+ Device device;
+
+Cursor() {
+}
+
/**
* Constructs a new cursor given a device and a style
* constant describing the desired cursor appearance.
@@ -97,40 +97,40 @@ Cursor() {
* @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);
-}
-
+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
@@ -163,105 +163,105 @@ public Cursor(Device device, int style) {
* <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 color depths */
- if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (source.depth != 1) 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);
- }
- 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);
-}
-
+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 color depths */
+ if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ if (source.depth != 1) 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);
+ }
+ 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);
+}
+
/**
* 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;
-}
-
+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
@@ -272,14 +272,14 @@ public void dispose () {
*
* @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;
-}
-
+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 which return <code>true</code> when passed to
@@ -290,10 +290,10 @@ public boolean equals (Object object) {
*
* @see #equals
*/
-public int hashCode () {
- return bitmap ^ type;
-}
-
+public int hashCode () {
+ return bitmap ^ type;
+}
+
/**
* Returns <code>true</code> if the cursor has been disposed,
* and <code>false</code> otherwise.
@@ -304,28 +304,28 @@ public int hashCode () {
*
* @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;
-}
-
+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 + "}";
-}
-
+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
index f1b87c1626..45deeb28af 100755
--- 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
@@ -1,62 +1,62 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
-
- /*
- * 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 Device getDevice () {
- if (DeviceFinder != null) DeviceFinder.run();
- Device device = CurrentDevice;
- CurrentDevice = null;
- return device;
-}
-
+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;
+
+ /*
+ * 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 Device getDevice () {
+ if (DeviceFinder != null) DeviceFinder.run();
+ Device device = CurrentDevice;
+ CurrentDevice = null;
+ return device;
+}
+
/**
* Constructs a new instance of this class.
* <p>
@@ -69,32 +69,32 @@ static Device getDevice () {
* @see #init
* @see DeviceData
*/
-public Device(DeviceData data) {
- 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;
-}
-
-protected void checkDevice () {
- if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
-}
-
-protected void create (DeviceData data) {
-}
-
-protected void destroy () {
-}
-
+public Device(DeviceData data) {
+ 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;
+}
+
+protected void checkDevice () {
+ if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
+}
+
+protected void create (DeviceData data) {
+}
+
+protected void destroy () {
+}
+
/**
* Disposes of the operating system resources associated with
* the receiver. After this method has been invoked, the receiver
@@ -105,28 +105,28 @@ protected void destroy () {
* @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;
- }
- }
-}
-
+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.
*
@@ -136,15 +136,15 @@ void dispose_Object (Object object) {
* <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);
-}
-
+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.
@@ -157,15 +157,15 @@ public Rectangle getBounds () {
*
* @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);
-}
-
+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
@@ -178,15 +178,15 @@ public Rectangle getClientArea () {
* <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;
-}
-
+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
@@ -200,29 +200,29 @@ public int getDepth () {
*
* @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;
-}
-
+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
@@ -234,12 +234,12 @@ public DeviceData getDeviceData () {
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public Point getDPI () {
- checkDevice ();
- //NOT DONE
- return new Point (96, 96);
-}
-
+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
@@ -253,66 +253,66 @@ public Point getDPI () {
* <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;
-}
-
+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
@@ -331,30 +331,30 @@ public FontData [] getFontList (String faceName, boolean scalable) {
*
* @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);
-}
-
+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"
@@ -375,11 +375,11 @@ public Color getSystemColor (int id) {
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public Font getSystemFont () {
- checkDevice ();
- return Font.photon_new (this, systemFont);
-}
-
+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>
@@ -391,14 +391,14 @@ public Font getSystemFont () {
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public boolean getWarnings () {
- checkDevice ();
- return false;
-}
-
-protected void init () {
-}
-
+public boolean getWarnings () {
+ checkDevice ();
+ return false;
+}
+
+protected void init () {
+}
+
/**
* Invokes platform specific functionality to allocate a new GC handle.
* <p>
@@ -414,8 +414,8 @@ protected void init () {
*
* @private
*/
-public abstract int internal_new_GC (GCData data);
-
+public abstract int internal_new_GC (GCData data);
+
/**
* Invokes platform specific functionality to dispose a GC handle.
* <p>
@@ -431,8 +431,8 @@ public abstract int internal_new_GC (GCData data);
*
* @private
*/
-public abstract void internal_dispose_GC (int handle, GCData 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.
@@ -443,31 +443,31 @@ public abstract void internal_dispose_GC (int handle, GCData data);
*
* @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;
-}
-
-protected void release () {
-}
-
+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;
+}
+
+protected void release () {
+}
+
/**
* If the underlying window system supports printing warning messages
* to the console, setting warnings to <code>true</code> prevents these
@@ -480,8 +480,8 @@ protected void release () {
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public void setWarnings (boolean warnings) {
- checkDevice ();
-}
-
+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
index 06e99bb30c..d36b10ff4a 100755
--- 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
@@ -1,19 +1,19 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index c5923cca91..c2ce18ab7c 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -24,22 +24,22 @@ import org.eclipse.swt.*;
*
* @see FontData
*/
-public final class Font {
-
- /**
- * the handle to the OS font resource
- * (Warning: This field is platform dependent)
+public final class Font {
+
+ /**
+ * the handle to the OS font resource
+ * (Warning: This field is platform dependent)
*/
- public byte[] handle;
-
- /**
- * the device where this font was created
+ public byte[] handle;
+
+ /**
+ * the device where this font was created
*/
- Device device;
-
-Font() {
-}
-
+ Device device;
+
+Font() {
+}
+
/**
* Constructs a new font given a device and font data
* which describes the desired font's appearance.
@@ -58,44 +58,44 @@ Font() {
* <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 font datas
- * 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>
- */
-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);
- FontData fd = fds[0];
- 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);
-}
+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 font datas
+ * 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>
+ */
+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);
+ FontData fd = fds[0];
+ 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, a font name,
* the height of the desired font in points, and a font
@@ -118,28 +118,28 @@ public Font(Device device, FontData[] fds) {
* <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);
-}
-
+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;
-}
-
+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
@@ -150,20 +150,20 @@ public void dispose() {
*
* @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;
-}
-
+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,
@@ -176,11 +176,11 @@ public boolean equals(Object object) {
* <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)};
-}
-
+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 which return <code>true</code> when passed to
@@ -191,11 +191,11 @@ public FontData[] getFontData() {
*
* @see #equals
*/
-public int hashCode () {
- if (handle == null) return 0;
- return handle.hashCode();
-}
-
+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.
@@ -206,61 +206,61 @@ public int hashCode () {
*
* @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];
- handle = OS.PfGenerateFontName(description, osStyle, height, 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);
- handle = OS.PfGenerateFontName(defaultFontName, osStyle, height, 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;
-}
-
+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];
+ handle = OS.PfGenerateFontName(description, osStyle, height, 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);
+ handle = OS.PfGenerateFontName(defaultFontName, osStyle, height, 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 + "}";
-}
-
+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
index 70731d5e22..807a35987f 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.photon.*;
+import org.eclipse.swt.*;
+
/**
* Instances of this class describe operating system fonts.
* Only the public API of this type is platform independent.
@@ -36,64 +36,64 @@ import org.eclipse.swt.*;
*
* @see Font
*/
-public final class FontData {
-
- /**
- * the font name
- * (Warning: This field is platform dependent)
+public final class FontData {
+
+ /**
+ * the font name
+ * (Warning: This field is platform dependent)
*/
- public String name;
-
+ public String name;
+
/**
* The height of the font data in points
* (Warning: This field is platform dependent)
*/
- public int height;
-
- /**
- * the font style
- * (Warning: This field is platform dependent)
+ public int height;
+
+ /**
+ * the font style
+ * (Warning: This field is platform dependent)
*/
- public int style;
-
- /**
- * A Photon stem
- * (Warning: This field is platform dependent)
+ public int style;
+
+ /**
+ * A Photon stem
+ * (Warning: This field is platform dependent)
*/
- public byte[] stem;
-
- /**
- * The locales of the font
- * (Warning: These fields are platform dependent)
+ public byte[] stem;
+
+ /**
+ * The locales of the font
+ * (Warning: These fields are platform dependent)
*/
- 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);
- }
-}
-
+ 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);
-}
-
+public FontData() {
+ this("", 12, SWT.NORMAL);
+}
+
/**
* Constructs a new FontData given a string representation
* in the form generated by the <code>FontData.toString</code>
@@ -113,61 +113,61 @@ public FontData() {
*
* @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;
- }
-}
-
+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,
@@ -182,12 +182,12 @@ public FontData(String string) {
* <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
* </ul>
*/
-public FontData(String name, int height, int style) {
- setName(name);
- setHeight(height);
- setStyle(style);
-}
-
+public FontData(String name, 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
@@ -198,13 +198,13 @@ public FontData(String name, int height, int style) {
*
* @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;
-}
-
+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.
*
@@ -212,10 +212,10 @@ public boolean equals (Object object) {
*
* @see #setHeight
*/
-public int getHeight() {
- return height;
-}
-
+public int getHeight() {
+ return height;
+}
+
/**
* Returns the name of the receiver.
* On platforms that support font foundries, the return value will
@@ -225,10 +225,10 @@ public int getHeight() {
*
* @see #setName
*/
-public String getName() {
- return name;
-}
-
+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
@@ -238,10 +238,10 @@ public String getName() {
*
* @see #setStyle
*/
-public int getStyle() {
- return style;
-}
-
+public int getStyle() {
+ return style;
+}
+
/**
* Returns an integer hash code for the receiver. Any two
* objects which return <code>true</code> when passed to
@@ -252,10 +252,10 @@ public int getStyle() {
*
* @see #equals
*/
-public int hashCode () {
- return name.hashCode() ^ height ^ style;
-}
-
+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
@@ -269,12 +269,12 @@ public int hashCode () {
*
* @see #getHeight
*/
-public void setHeight(int height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.height = height;
- this.stem = null;
-}
-
+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>
@@ -300,49 +300,49 @@ public void setHeight(int height) {
*
* @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 which 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 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 which 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);
- }
-}
-
+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>
@@ -352,11 +352,11 @@ public void setLocale(String locale) {
*
* @see #getStyle
*/
-public void setStyle(int style) {
- this.style = style;
- this.stem = null;
-}
-
+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
@@ -366,21 +366,21 @@ public void setStyle(int style) {
*
* @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);
-}
-
+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
index e51fb26cca..2f031d852a 100755
--- 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
@@ -1,14 +1,14 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.photon.*;
+
/**
* Instances of this class provide measurement information
* about fonts including ascent, descent, height, leading
@@ -18,18 +18,18 @@ import org.eclipse.swt.internal.photon.*;
*
* @see GC#getFontMetrics
*/
-public final class FontMetrics {
-
+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)
*/
- public FontQueryInfo handle;
-
-FontMetrics() {
-}
-
+ public FontQueryInfo handle;
+
+FontMetrics() {
+}
+
/**
* Compares the argument to the receiver, and returns true
* if they represent the <em>same</em> object using a class
@@ -40,33 +40,33 @@ FontMetrics() {
*
* @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;
-}
-
+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
@@ -75,21 +75,21 @@ public boolean equals (Object object) {
*
* @return the ascent of the font
*/
-public int getAscent() {
- return -handle.ascender;
-}
-
+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;
-}
-
+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
@@ -98,10 +98,10 @@ public int getAverageCharWidth() {
*
* @return the descent of the font
*/
-public int getDescent() {
- return handle.descender;
-}
-
+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
@@ -113,10 +113,10 @@ public int getDescent() {
* @see #getDescent
* @see #getLeading
*/
-public int getHeight() {
- return -handle.ascender + handle.descender;
-}
-
+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
@@ -124,10 +124,10 @@ public int getHeight() {
*
* @return the leading space of the font
*/
-public int getLeading() {
- return 0;
-}
-
+public int getLeading() {
+ return 0;
+}
+
/**
* Returns an integer hash code for the receiver. Any two
* objects which return <code>true</code> when passed to
@@ -138,17 +138,17 @@ public int getLeading() {
*
* @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 photon_new(FontQueryInfo handle) {
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.handle = handle;
- return fontMetrics;
-}
+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 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
index f49d994520..50b6168d27 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -25,41 +25,41 @@ import org.eclipse.swt.*;
*
* @see org.eclipse.swt.events.PaintEvent
*/
-public final class GC {
+public final class GC {
/**
* the handle to the OS device context
* (Warning: This field is platform dependent)
*/
- 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
- { 10, 4 }, // SWT.LINE_DASH
- { 2, 2 }, // SWT.LINE_DOT
- { 10, 4, 2, 4 }, // SWT.LINE_DASHDOT
- { 10, 4, 2, 4, 2, 4 } // 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_XORMODE = 1 << 6;
-
-GC() {
-}
-
+ 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
+ { 10, 4 }, // SWT.LINE_DASH
+ { 2, 2 }, // SWT.LINE_DOT
+ { 10, 4, 2, 4 }, // SWT.LINE_DASHDOT
+ { 10, 4, 2, 4, 2, 4 } // 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_XORMODE = 1 << 6;
+
+GC() {
+}
+
/**
* Constructs a new instance of this class which has been
* configured to draw on the specified drawable. Sets the
@@ -81,23 +81,23 @@ GC() {
* <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li>
* </ul>
*/
-public GC(Drawable drawable) {
- int flags = OS.PtEnter(0);
- try {
- if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- GCData data = new GCData ();
- 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);
- data.device = device;
- init (drawable, data, hDC);
- if (device.tracking) device.new_Object(this);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
+public GC(Drawable drawable) {
+ int flags = OS.PtEnter(0);
+ try {
+ if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ GCData data = new GCData ();
+ 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);
+ data.device = device;
+ init (drawable, data, hDC);
+ if (device.tracking) device.new_Object(this);
+ } finally {
+ if (flags >= 0) OS.PtLeave(flags);
+ }
+}
+
/**
* Copies a rectangular area of the receiver at the specified
* position into the image, which must be of type <code>SWT.BITMAP</code>.
@@ -113,67 +113,67 @@ public GC(Drawable drawable) {
* <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 = 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);
- }
-}
-
+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 = 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.
@@ -189,165 +189,165 @@ public void copyArea(Image image, int x, int y) {
* <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) {
- 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 = 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);
- }
-}
-
+public void copyArea(int x, int y, int width, int height, int destX, int destY) {
+ 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 = 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);
- }
-}
-
+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.
@@ -380,65 +380,65 @@ public void dispose() {
* <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 endAngle) {
- 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 || endAngle == 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (startAngle > 0) {
- if (endAngle > 0) {
- //No need to modify start angle.
- endAngle += startAngle;
- } else {
- int newStartAngle;
- int newStopAngle = startAngle;
- if (startAngle > Math.abs(endAngle)) {
- newStartAngle = startAngle - Math.abs(endAngle);
- } else {
- newStartAngle = startAngle + 360 - Math.abs(endAngle);
- }
- startAngle = newStartAngle;
- endAngle = newStopAngle;
- }
- } else {
- if (endAngle > 0) {
- endAngle = endAngle + startAngle;
- startAngle = 360 - Math.abs(startAngle);
- } else {
- int newStopAngle = 360 + startAngle;
- startAngle = newStopAngle - Math.abs(endAngle);
- endAngle = newStopAngle;
- }
- }
- startAngle = (int) (startAngle * 65536 / 360);
- endAngle = (int) (endAngle * 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, endAngle, OS.Pg_ARC | OS.Pg_DRAW_STROKE);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
+public void drawArc (int x, int y, int width, int height, int startAngle, int endAngle) {
+ 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 || endAngle == 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (startAngle > 0) {
+ if (endAngle > 0) {
+ //No need to modify start angle.
+ endAngle += startAngle;
+ } else {
+ int newStartAngle;
+ int newStopAngle = startAngle;
+ if (startAngle > Math.abs(endAngle)) {
+ newStartAngle = startAngle - Math.abs(endAngle);
+ } else {
+ newStartAngle = startAngle + 360 - Math.abs(endAngle);
+ }
+ startAngle = newStartAngle;
+ endAngle = newStopAngle;
+ }
+ } else {
+ if (endAngle > 0) {
+ endAngle = endAngle + startAngle;
+ startAngle = 360 - Math.abs(startAngle);
+ } else {
+ int newStopAngle = 360 + startAngle;
+ startAngle = newStopAngle - Math.abs(endAngle);
+ endAngle = newStopAngle;
+ }
+ }
+ startAngle = (int) (startAngle * 65536 / 360);
+ endAngle = (int) (endAngle * 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, endAngle, 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
@@ -456,23 +456,23 @@ public void drawArc (int x, int y, int width, int height, int startAngle, int en
*
* @see #drawRectangle
*/
-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);
- }
-}
-
+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.
@@ -492,379 +492,379 @@ public void drawFocus (int x, int y, int width, int height) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</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 SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</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 SWTError <ul>
+ * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</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);
- 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.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 = 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.Pt_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) SWT.error(SWT.ERROR_NO_HANDLES);
- int mc = OS.PmMemCreateMC(memImage, scale, trans);
- if (mc == 0) {
- Image.destroyImage(memImage);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- 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);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- mc = OS.PmMemCreateMC(maskImage, scale, trans);
- if (mc == 0) {
- Image.destroyImage(maskImage);
- Image.destroyImage(memImage);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- 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.Pt_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 = 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);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
-
- /* 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);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- mc = OS.PmMemCreateMC(alphaImage, scale, trans);
- if (mc == 0) {
- OS.free(palettePtr);
- OS.free(alphaPtr);
- Image.destroyImage(alphaImage);
- Image.destroyImage(memImage);
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- 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 = 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;
-}
-
+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);
+ 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.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 = 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.Pt_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) SWT.error(SWT.ERROR_NO_HANDLES);
+ int mc = OS.PmMemCreateMC(memImage, scale, trans);
+ if (mc == 0) {
+ Image.destroyImage(memImage);
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ 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);
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ mc = OS.PmMemCreateMC(maskImage, scale, trans);
+ if (mc == 0) {
+ Image.destroyImage(maskImage);
+ Image.destroyImage(memImage);
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ 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.Pt_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 = 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);
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+
+ /* 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);
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ mc = OS.PmMemCreateMC(alphaImage, scale, trans);
+ if (mc == 0) {
+ OS.free(palettePtr);
+ OS.free(alphaPtr);
+ Image.destroyImage(alphaImage);
+ Image.destroyImage(memImage);
+ SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ 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 = 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>).
@@ -878,19 +878,19 @@ static int scaleImage(Image image, PhImage_t phImage, int srcX, int srcY, int sr
* <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);
- }
-}
-
+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.
@@ -912,25 +912,25 @@ public void drawLine (int x1, int y1, int x2, int y2) {
* <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);
- }
-}
-
+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 closed polygon which is defined by the specified array
* of integer coordinates, using the receiver's foreground color. The array
@@ -948,26 +948,26 @@ public void drawOval (int x, int y, int width, int height) {
* <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);
- }
-}
-
+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
@@ -985,26 +985,26 @@ public void drawPolygon(int[] pointArray) {
* <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);
- }
-}
-
+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
@@ -1020,20 +1020,20 @@ public void drawPolyline(int[] pointArray) {
* <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);
- }
-}
-
+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
@@ -1050,11 +1050,11 @@ public void drawRectangle (int x, int y, int width, int height) {
* <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);
-}
-
+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
@@ -1074,26 +1074,26 @@ public void drawRectangle (Rectangle rect) {
* <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);
- }
-}
-
+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
@@ -1112,10 +1112,10 @@ public void drawRoundRectangle (int x, int y, int width, int height, int arcWidt
* <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);
-}
-
+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
@@ -1136,25 +1136,25 @@ public void drawString (String string, int x, int y) {
* <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();
- OS.PgDrawText(buffer, buffer.length, (short)x, (short)y, drawFlags);
- unsetGC(prevContext);
- } finally {
- if (flags >= 0) OS.PtLeave(flags);
- }
-}
-
+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();
+ OS.PgDrawText(buffer, buffer.length, (short)x, (short)y, drawFlags);
+ 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
@@ -1173,10 +1173,10 @@ public void drawString (String string, int x, int y, boolean isTransparent) {
* <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);
-}
-
+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
@@ -1197,136 +1197,136 @@ public void drawText (String string, int x, int y) {
* <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, 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);
-}
-
+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
@@ -1337,10 +1337,10 @@ Point drawText(String text, int x, int y, int flags, boolean draw) {
*
* @see #hashCode
*/
-public boolean equals (Object object) {
- return (object == this) || ((object instanceof GC) && (handle == ((GC)object).handle));
-}
-
+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
@@ -1376,123 +1376,123 @@ public boolean equals (Object object) {
*
* @see #drawArc
*/
-public void fillArc (int x, int y, int width, int height, int startAngle, int endAngle) {
- 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 || endAngle == 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (startAngle > 0) {
- if (endAngle > 0) {
- //No need to modify start angle.
- endAngle += startAngle;
- } else {
- int newStartAngle;
- int newStopAngle = startAngle;
- if (startAngle > Math.abs(endAngle)) {
- newStartAngle = startAngle - Math.abs(endAngle);
- } else {
- newStartAngle = startAngle + 360 - Math.abs(endAngle);
- }
- startAngle = newStartAngle;
- endAngle = newStopAngle;
- }
- } else {
- if (endAngle > 0) {
- endAngle = endAngle + startAngle;
- startAngle = 360 - Math.abs(startAngle);
- } else {
- int newStopAngle = 360 + startAngle;
- startAngle = newStopAngle - Math.abs(endAngle);
- endAngle = newStopAngle;
- }
- }
- startAngle = (int) (startAngle * 65536 / 360);
- endAngle = (int) (endAngle * 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, endAngle, 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
+public void fillArc (int x, int y, int width, int height, int startAngle, int endAngle) {
+ 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 || endAngle == 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (startAngle > 0) {
+ if (endAngle > 0) {
+ //No need to modify start angle.
+ endAngle += startAngle;
+ } else {
+ int newStartAngle;
+ int newStopAngle = startAngle;
+ if (startAngle > Math.abs(endAngle)) {
+ newStartAngle = startAngle - Math.abs(endAngle);
+ } else {
+ newStartAngle = startAngle + 360 - Math.abs(endAngle);
+ }
+ startAngle = newStartAngle;
+ endAngle = newStopAngle;
+ }
+ } else {
+ if (endAngle > 0) {
+ endAngle = endAngle + startAngle;
+ startAngle = 360 - Math.abs(startAngle);
+ } else {
+ int newStopAngle = 360 + startAngle;
+ startAngle = newStopAngle - Math.abs(endAngle);
+ endAngle = newStopAngle;
+ }
+ }
+ startAngle = (int) (startAngle * 65536 / 360);
+ endAngle = (int) (endAngle * 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, endAngle, 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
*/
-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;
- }
- 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);
- }
-}
-
+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;
+ }
+ 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
@@ -1509,25 +1509,25 @@ public void fillGradientRectangle(int x, int y, int width, int height, boolean v
*
* @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);
- }
-}
-
+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 interior of the closed polygon which is defined by the
* specified array of integer coordinates, using the receiver's
@@ -1547,26 +1547,26 @@ public void fillOval (int x, int y, int width, int height) {
*
* @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);
- }
-}
-
+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.
@@ -1582,20 +1582,20 @@ public void fillPolygon(int[] pointArray) {
*
* @see #drawRectangle
*/
-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);
- }
-}
-
+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.
@@ -1611,11 +1611,11 @@ public void fillRectangle (int x, int y, int width, int height) {
*
* @see #drawRectangle
*/
-public void fillRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- fillRectangle (rect.x, rect.y, rect.width, rect.height);
-}
-
+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.
@@ -1633,37 +1633,37 @@ public void fillRectangle (Rectangle rect) {
*
* @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.
+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);
-}
-
+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.
@@ -1679,10 +1679,10 @@ void flushImage () {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public int getAdvanceWidth(char ch) {
- return getCharWidth(ch);
-}
-
+public int getAdvanceWidth(char ch) {
+ return getCharWidth(ch);
+}
+
/**
* Returns the background color.
*
@@ -1692,11 +1692,11 @@ public int getAdvanceWidth(char ch) {
* <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);
-}
-
+public Color getBackground() {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ return Color.photon_new(data.device, data.background);
+}
+
/**
* Returns the width of the specified character in the font
* selected into the receiver.
@@ -1713,13 +1713,13 @@ public Color getBackground() {
* <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;
-}
-
+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
@@ -1732,48 +1732,48 @@ public int getCharWidth(char ch) {
* <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);
- }
-}
-
+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.
@@ -1787,40 +1787,40 @@ public Rectangle getClipping() {
* <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 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);
- }
-}
-
+public void getClipping (Region region) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (region == null) SWT.error (SWT.ERROR_NULL_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 font currently being used by the receiver
* to draw and measure text.
@@ -1831,11 +1831,11 @@ public void getClipping (Region region) {
* <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);
-}
-
+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
@@ -1847,13 +1847,13 @@ public Font getFont () {
* <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);
-}
-
+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.
*
@@ -1863,11 +1863,11 @@ public FontMetrics getFontMetrics() {
* <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);
-}
-
+public Color getForeground() {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ return Color.photon_new(data.device, data.foreground);
+}
+
/**
* Returns the receiver's line style, which will be one
* of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
@@ -1880,11 +1880,11 @@ public Color getForeground() {
* <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;
-}
-
+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,
@@ -1897,11 +1897,11 @@ public int getLineStyle() {
* <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;
-}
-
+public int getLineWidth() {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ return data.lineWidth;
+}
+
/**
* Returns <code>true</code> if this GC is drawing in the mode
* where the resulting color in the destination is the
@@ -1916,11 +1916,11 @@ public int getLineWidth() {
* <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;
-}
-
+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 which return <code>true</code> when passed to
@@ -1935,44 +1935,44 @@ public boolean getXORMode() {
*
* @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;
-}
-
+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.
@@ -1987,11 +1987,11 @@ void init(Drawable drawable, GCData data, int context) {
* <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;
-}
-
+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.
@@ -2002,10 +2002,10 @@ public boolean isClipped() {
*
* @return <code>true</code> when the GC is disposed and <code>false</code> otherwise
*/
-public boolean isDisposed() {
- return handle == 0;
-}
-
+public boolean isDisposed() {
+ return handle == 0;
+}
+
/**
* Sets the background color. The background color is used
* for fill operations and as the background color when text
@@ -2021,14 +2021,14 @@ public boolean isDisposed() {
* <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;
-}
-
+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 area of the receiver which can be changed
* by drawing operations to the rectangular area specified
@@ -2043,32 +2043,32 @@ public void setBackground (Color color) {
* <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;
-}
-
+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 rectangular area specified
@@ -2080,19 +2080,19 @@ public void setClipping (int x, int y, int width, int height) {
* <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);
- }
-}
-
+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
@@ -2104,27 +2104,27 @@ public void setClipping (Rectangle rect) {
* <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);
- 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);
- 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;
-}
-
+public void setClipping (Region region) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ 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);
+ 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 font which will be used by the receiver
* to draw and measure text to the argument. If the
@@ -2140,13 +2140,13 @@ public void setClipping (Region region) {
* <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;
-}
-
+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.
@@ -2161,14 +2161,14 @@ public void setFont (Font font) {
* <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;
-}
-
+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 line style to the argument, which must be one
* of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
@@ -2181,23 +2181,23 @@ public void setForeground (Color color) {
* <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;
- default:
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- return;
- }
- data.lineStyle = lineStyle;
- dirtyBits |= DIRTY_LINESTYLE;
-}
-
+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;
+ 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,
@@ -2210,158 +2210,158 @@ public void setLineStyle(int lineStyle) {
* <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_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;
- }
- OS.PgSetStrokeDash(dashList, dashList.length, 0x10000);
- }
- if ((dirtyBits & DIRTY_LINEWIDTH) != 0) {
- OS.PgSetStrokeWidth(data.lineWidth);
- }
- if ((dirtyBits & DIRTY_XORMODE) != 0) {
- if (data.xorMode) OS.PgSetDrawMode(OS.Pg_DRAWMODE_XOR);
- else OS.PgSetDrawMode(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) 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.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;
-}
-
+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_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;
+ }
+ OS.PgSetStrokeDash(dashList, dashList.length, 0x10000);
+ }
+ if ((dirtyBits & DIRTY_LINEWIDTH) != 0) {
+ OS.PgSetStrokeWidth(data.lineWidth);
+ }
+ if ((dirtyBits & DIRTY_XORMODE) != 0) {
+ if (data.xorMode) OS.PgSetDrawMode(OS.Pg_DRAWMODE_XOR);
+ else OS.PgSetDrawMode(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) 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.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;
+}
+
/**
* If the argument is <code>true</code>, puts the receiver
* in a drawing mode where the resulting color in the destination
@@ -2376,12 +2376,12 @@ int getClipping(int widget, int topWidget, boolean clipChildren, boolean clipSib
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public void setXORMode(boolean xor) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- data.xorMode = xor;
- dirtyBits |= DIRTY_XORMODE;
-}
-
+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.
@@ -2401,28 +2401,28 @@ public void setXORMode(boolean xor) {
* <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);
-}
-
+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.
@@ -2442,79 +2442,79 @@ public Point stringExtent(String string) {
* <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) {
+ 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) {
- return stringExtent(string);
- } else {
- return drawText(string, 0, 0, flags, false);
- }
-}
-
+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) {
+ 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.init(drawable, data, context);
- return gc;
-}
-
+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.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
index 30fb1135fd..0073e5acb8 100755
--- 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
@@ -1,14 +1,14 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+
/**
* Instances of this class are descriptions of GCs in terms
* of unallocated platform-specific data fields.
@@ -21,17 +21,17 @@ import org.eclipse.swt.*;
*
* @private
*/
-public final class GCData {
- public Device device;
- 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 lineWidth = 1;
- public int clipRectsCount;
- public int clipRects;
+public final class GCData {
+ public Device device;
+ 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 lineWidth = 1;
+ public int clipRectsCount;
+ public int clipRects;
}
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
index fceee38aa1..6e0e7d5b5e 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import java.io.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -58,46 +58,46 @@ import java.io.*;
* @see ImageData
* @see ImageLoader
*/
-public final class Image implements Drawable {
-
- /**
- * specifies whether the receiver is a bitmap or an icon
- * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
+public final class Image implements Drawable {
+
+ /**
+ * specifies whether the receiver is a bitmap or an icon
+ * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
*/
- public int type;
-
- /**
- * the OS resource of the image
- * (Warning: This field is platform dependent)
+ public int type;
+
+ /**
+ * the OS resource of the image
+ * (Warning: This field is platform dependent)
*/
- public int handle;
-
- /**
- * the device where this image was created
+ public int handle;
+
+ /**
+ * the device where this image was created
*/
- Device device;
-
- /**
- * specifies the transparent pixel
- * (Warning: This field is platform dependent)
+ Device device;
+
+ /**
+ * specifies the transparent pixel
+ * (Warning: This field is platform dependent)
*/
- int transparentPixel = -1;
-
- /**
- * the GC which is drawing on the image
- * (Warning: This field is platform dependent)
+ int transparentPixel = -1;
+
+ /**
+ * the GC which is drawing on the image
+ * (Warning: This field is platform dependent)
*/
- GC memGC;
-
- /**
- * specifies the default scanline padding
- * (Warning: This field is platform dependent)
+ GC memGC;
+
+ /**
+ * specifies the default scanline padding
+ * (Warning: This field is platform dependent)
*/
- static final int DEFAULT_SCANLINE_PAD = 4;
-
-Image () {
-}
-
+ 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
@@ -128,13 +128,13 @@ Image () {
* <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);
-}
-
+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
@@ -166,125 +166,125 @@ public Image(Device device, int width, int height) {
* <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.maskData = data.maskData;
- newData.maskPad = data.maskPad;
-
- /* 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];
- 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;
- newData.data[offset++] =
- (byte)((red+red+green+green+green+green+green+blue) >> 3);
- }
- }
- }
- init (device, newData);
- if (device.tracking) device.new_Object(this);
- return;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-}
-
+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.maskData = data.maskData;
+ newData.maskPad = data.maskPad;
+
+ /* 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];
+ 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;
+ newData.data[offset++] =
+ (byte)((red+red+green+green+green+green+green+blue) >> 3);
+ }
+ }
+ }
+ 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
@@ -315,14 +315,14 @@ public Image(Device device, Image srcImage, int flag) {
* <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);
-}
-
+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>.
@@ -338,13 +338,13 @@ public Image(Device device, Rectangle bounds) {
* <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);
-}
-
+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>
@@ -374,22 +374,22 @@ public Image(Device device, ImageData data) {
* <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);
- }
- if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- 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);
-}
-
+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);
+ }
+ if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ 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
@@ -422,13 +422,13 @@ public Image(Device device, ImageData source, ImageData mask) {
* <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);
-}
-
+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
@@ -454,28 +454,28 @@ public Image (Device device, InputStream stream) {
* <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);
-}
-
+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;
- destroyImage(handle);
- handle = 0;
- memGC = null;
- if (device.tracking) device.dispose_Object(this);
- device = null;
-}
-
+public void dispose () {
+ if (handle == 0) return;
+ if (device.isDisposed()) return;
+ 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
@@ -486,13 +486,13 @@ public void dispose () {
*
* @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;
-}
-
+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.
@@ -511,43 +511,43 @@ public boolean equals (Object object) {
* <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);
-}
-
+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
@@ -560,13 +560,13 @@ public Color getBackground() {
* <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);
-}
-
+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
@@ -581,85 +581,85 @@ public Rectangle getBounds() {
*
* @see ImageData
*/
-public ImageData getImageData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- 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 calcBpl, 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++) {
- 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 = 4;
- } 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;
-}
-
+public ImageData getImageData() {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ 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 calcBpl, 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++) {
+ 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 = 4;
+ } 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 which return <code>true</code> when passed to
@@ -670,211 +670,211 @@ public ImageData getImageData() {
*
* @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) {
- 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 = 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;
-}
-
+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) {
+ 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 = 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>
@@ -890,30 +890,30 @@ void init(Device device, ImageData i) {
*
* @private
*/
-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);
-
- data.device = device;
- data.image = this;
- return pmMC;
-}
-
+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);
+
+ data.device = device;
+ data.image = this;
+ return pmMC;
+}
+
/**
* Invokes platform specific functionality to dispose a GC handle.
* <p>
@@ -929,10 +929,10 @@ public int internal_new_GC (GCData data) {
*
* @private
*/
-public void internal_dispose_GC (int pmMC, GCData data) {
- OS.PmMemReleaseMC(pmMC);
-}
-
+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.
@@ -943,86 +943,86 @@ public void internal_dispose_GC (int pmMC, GCData data) {
*
* @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 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 = 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;
-}
-
+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 = 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 + "}";
-}
-
+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
index e0a506ba93..8b95059741 100755
--- 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
@@ -1,15 +1,15 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -20,16 +20,16 @@ import org.eclipse.swt.*;
* when those instances are no longer required.
* </p>
*/
-public final class Region {
-
- /**
- * the OS resource for the region
- * (Warning: This field is platform dependent)
+public final class Region {
+
+ /**
+ * the OS resource for the region
+ * (Warning: This field is platform dependent)
*/
- public int handle;
-
- static int EMPTY_REGION = -1;
-
+ public int handle;
+
+ static int EMPTY_REGION = -1;
+
/**
* Constructs a new empty region.
*
@@ -37,14 +37,14 @@ public final class Region {
* <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li>
* </ul>
*/
-public Region () {
- handle = EMPTY_REGION;
-}
-Region(int handle) {
- this.handle = handle;
-}
-
-
+public Region () {
+ handle = EMPTY_REGION;
+}
+Region(int handle) {
+ this.handle = handle;
+}
+
+
/**
* Adds the given rectangle to the collection of rectangles
* the receiver maintains to describe its area.
@@ -59,22 +59,22 @@ Region(int handle) {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public void add (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (handle == 0) return;
- int tile_ptr = OS.PhGetTile();
- PhTile_t tile = new PhTile_t();
- tile.rect_ul_x = (short)rect.x;
- tile.rect_ul_y = (short)rect.y;
- tile.rect_lr_x = (short)(rect.x + rect.width - 1);
- tile.rect_lr_y = (short)(rect.y + rect.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);
-}
-
+public void add (Rectangle rect) {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ if (handle == 0) return;
+ int tile_ptr = OS.PhGetTile();
+ PhTile_t tile = new PhTile_t();
+ tile.rect_ul_x = (short)rect.x;
+ tile.rect_ul_y = (short)rect.y;
+ tile.rect_lr_x = (short)(rect.x + rect.width - 1);
+ tile.rect_lr_y = (short)(rect.y + rect.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 rectangles which make up the area covered
* by the argument to the collection of rectangles the receiver
@@ -90,17 +90,17 @@ public void add (Rectangle rect) {
* <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);
-}
-
+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,
@@ -114,21 +114,21 @@ public void add (Region region) {
* <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;
-}
-
+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>
@@ -144,22 +144,22 @@ public boolean contains (int x, int y) {
* <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);
-}
-
+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 (handle != EMPTY_REGION) OS.PhFreeTiles (handle);
- handle = 0;
-}
-
+public void dispose () {
+ if (handle == 0) return;
+ if (handle != EMPTY_REGION) OS.PhFreeTiles (handle);
+ handle = 0;
+}
+
/**
* Compares the argument to the receiver, and returns true
* if they represent the <em>same</em> object using a class
@@ -170,13 +170,13 @@ public void dispose () {
*
* @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;
-}
-
+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 rectangles the receiver
@@ -190,26 +190,26 @@ public boolean equals (Object object) {
*
* @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);
-}
-
+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 which return <code>true</code> when passed to
@@ -220,10 +220,10 @@ public Rectangle getBounds() {
*
* @see #equals
*/
-public int hashCode () {
- return handle;
-}
-
+public int hashCode () {
+ return handle;
+}
+
/**
* Returns <code>true</code> if the rectangle described by the
* arguments intersects with any of the rectangles the receiver
@@ -241,23 +241,23 @@ public int hashCode () {
*
* @see Rectangle#intersects
*/
-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;
-}
-
+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 rectangles the receiver mainains to describe
@@ -275,11 +275,11 @@ public boolean intersects (int x, int y, int width, int height) {
*
* @see Rectangle#intersects
*/
-public boolean intersects (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return intersects(rect.x, rect.y, rect.width, rect.height);
-}
-
+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.
@@ -290,10 +290,10 @@ public boolean intersects (Rectangle rect) {
*
* @return <code>true</code> when the region is disposed, and <code>false</code> otherwise
*/
-public boolean isDisposed() {
- return handle == 0;
-}
-
+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
@@ -305,23 +305,23 @@ public boolean isDisposed() {
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* </ul>
*/
-public boolean isEmpty () {
- return getBounds().isEmpty();
-
-}
-
-public static Region photon_new(int handle) {
- return new Region(handle);
-}
-
+public boolean isEmpty () {
+ return getBounds().isEmpty();
+
+}
+
+public static Region photon_new(int handle) {
+ return new Region(handle);
+}
+
/**
* Returns a string containing a concise, human-readable
* description of the receiver.
*
* @return a string representation of the receiver
*/
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
+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
index aa6c11ddd1..920f0849d8 100755
--- 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
@@ -1,14 +1,14 @@
-package org.eclipse.swt.internal;
-
-import java.io.UnsupportedEncodingException;
-
-/*
+package org.eclipse.swt.internal;
+
+import java.io.UnsupportedEncodingException;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
/**
* This class implements the conversions between unicode characters
* and the <em>platform supported</em> representation for characters.
@@ -17,47 +17,47 @@ import java.io.UnsupportedEncodingException;
* 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];
+
+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;
- }
-}
-}
+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
index 9cce3f3ad4..2497daa884 100755
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -36,9 +36,9 @@ import org.eclipse.swt.events.*;
* within the SWT implementation.
* </p>
*/
-public class Button extends Control {
- Image image;
-
+public class Button extends Control {
+ Image image;
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -75,24 +75,24 @@ public class Button extends Control {
* @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) != 0) {
- return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
- }
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) {
- return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
- }
- if ((style & SWT.ARROW) != 0) {
- return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
- }
- return style;
-}
-
+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) != 0) {
+ return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
+ }
+ if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) {
+ return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
+ }
+ if ((style & SWT.ARROW) != 0) {
+ 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
@@ -117,151 +117,151 @@ static int checkStyle (int style) {
* @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 () {
- int rid = OS.PtWidgetRid (handle);
- if (rid == 0) return;
- PhEvent_t event = new PhEvent_t ();
- event.emitter_rid = rid;
- event.emitter_handle = handle;
- event.collector_rid = rid;
- event.collector_handle = handle;
- event.flags = OS.Ph_EVENT_DIRECT;
- event.processing_flags = 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 = 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 (handle, ptr);
- OS.PtFlush ();
- event.type = OS.Ph_EV_BUT_RELEASE;
- event.subtype = 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 (handle, ptr);
- OS.free (ptr);
-}
-
-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;
- Display display = getDisplay ();
- 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);
- }
-}
-
+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 () {
+ int rid = OS.PtWidgetRid (handle);
+ if (rid == 0) return;
+ PhEvent_t event = new PhEvent_t ();
+ event.emitter_rid = rid;
+ event.emitter_handle = handle;
+ event.collector_rid = rid;
+ event.collector_handle = handle;
+ event.flags = OS.Ph_EVENT_DIRECT;
+ event.processing_flags = 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 = 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 (handle, ptr);
+ OS.PtFlush ();
+ event.type = OS.Ph_EV_BUT_RELEASE;
+ event.subtype = 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 (handle, ptr);
+ OS.free (ptr);
+}
+
+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;
+ Display display = getDisplay ();
+ 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
@@ -278,28 +278,28 @@ void drawWidget (int widget, int damage) {
* <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;
-}
-
+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.
@@ -311,11 +311,11 @@ boolean getDefault () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Image getImage () {
- checkWidget();
- return image;
-}
-
+public Image getImage () {
+ checkWidget();
+ return image;
+}
+
/**
* Returns <code>true</code> if the receiver is selected,
* and false otherwise.
@@ -332,16 +332,16 @@ public Image getImage () {
* <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 ();
-}
-
+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.
@@ -353,95 +353,95 @@ String getNameText () {
* <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 "";
- int [] args = {
- OS.Pt_ARG_TEXT_STRING, 0, 0,
- OS.Pt_ARG_ACCEL_KEY, 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 [] result = Converter.mbcsToWcs (null, buffer);
- int count = 0;
- int mnemonic = 0;
- if (args [4] != 0) {
- int length2 = OS.strlen (args [4]);
- if (length2 > 0) {
- byte [] buffer2 = new byte [length2];
- OS.memmove (buffer2, args [4], length2);
- char [] result2 = Converter.mbcsToWcs (null, buffer2);
- if (result2.length > 0) mnemonic = result2 [0];
- }
- }
- if (mnemonic != 0) count++;
- for (int i=0; i<result.length-1; i++)
- if (result [i] == Mnemonic) count++;
- char [] newResult = result;
- if ((count != 0) || (mnemonic != 0)) {
- newResult = new char [result.length + count];
- int i = 0, j = 0;
- while (i < result.length) {
- if ((mnemonic != 0) && (result [i] == mnemonic)) {
- if (j < newResult.length) newResult [j++] = Mnemonic;
- mnemonic = 0;
- }
- if ((newResult [j++] = result [i++]) == Mnemonic)
- if (j < newResult.length) newResult [j++] = Mnemonic;
- }
- }
- return new String (newResult);
-}
-
-void hookEvents () {
- super.hookEvents ();
- int windowProc = getDisplay ().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;
-}
-
+public String getText () {
+ checkWidget();
+ if ((style & SWT.ARROW) != 0) return "";
+ int [] args = {
+ OS.Pt_ARG_TEXT_STRING, 0, 0,
+ OS.Pt_ARG_ACCEL_KEY, 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 [] result = Converter.mbcsToWcs (null, buffer);
+ int count = 0;
+ int mnemonic = 0;
+ if (args [4] != 0) {
+ int length2 = OS.strlen (args [4]);
+ if (length2 > 0) {
+ byte [] buffer2 = new byte [length2];
+ OS.memmove (buffer2, args [4], length2);
+ char [] result2 = Converter.mbcsToWcs (null, buffer2);
+ if (result2.length > 0) mnemonic = result2 [0];
+ }
+ }
+ if (mnemonic != 0) count++;
+ for (int i=0; i<result.length-1; i++)
+ if (result [i] == Mnemonic) count++;
+ char [] newResult = result;
+ if ((count != 0) || (mnemonic != 0)) {
+ newResult = new char [result.length + count];
+ int i = 0, j = 0;
+ while (i < result.length) {
+ if ((mnemonic != 0) && (result [i] == mnemonic)) {
+ if (j < newResult.length) newResult [j++] = Mnemonic;
+ mnemonic = 0;
+ }
+ if ((newResult [j++] = result [i++]) == Mnemonic)
+ if (j < newResult.length) newResult [j++] = Mnemonic;
+ }
+ }
+ return new String (newResult);
+}
+
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().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.
@@ -459,39 +459,39 @@ void releaseWidget () {
* @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);
-}
-
+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
@@ -508,39 +508,39 @@ void selectRadio () {
* <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;
-}
-
+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>.
@@ -557,12 +557,12 @@ boolean setRadioSelection (boolean value) {
* <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);
-}
-
+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
* null indicating that no image should be displayed.
@@ -577,23 +577,23 @@ public void setSelection (boolean selected) {
* <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);
-}
-
+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>
@@ -611,52 +611,52 @@ public void setImage (Image image) {
* <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;
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- int i=0, j=0;
- char mnemonic=0;
- while (i < text.length) {
- if ((text [j++] = text [i++]) == Mnemonic) {
- if (i == text.length) {continue;}
- if (text [i] == Mnemonic) {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
- j--;
- }
- }
- while (j < text.length) text [j++] = 0;
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, 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, ptr, 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 (ptr);
- OS.free (ptr2);
-}
-
-int traversalCode (int key_sym, PhKeyEvent_t ke) {
- int code = super.traversalCode (key_sym , ke);
- code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_MNEMONIC;
- return code;
-}
-
-int widgetClass () {
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) return OS.PtToggleButton ();
- return OS.PtButton ();
-}
-
-}
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.ARROW) != 0) return;
+ char [] text = new char [string.length ()];
+ string.getChars (0, text.length, text, 0);
+ int i=0, j=0;
+ char mnemonic=0;
+ while (i < text.length) {
+ if ((text [j++] = text [i++]) == Mnemonic) {
+ if (i == text.length) {continue;}
+ if (text [i] == Mnemonic) {i++; continue;}
+ if (mnemonic == 0) mnemonic = text [i];
+ j--;
+ }
+ }
+ while (j < text.length) text [j++] = 0;
+ byte [] buffer = Converter.wcsToMbcs (null, text, true);
+ int ptr = OS.malloc (buffer.length);
+ OS.memmove (ptr, 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, ptr, 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 (ptr);
+ OS.free (ptr2);
+}
+
+int traversalCode (int key_sym, PhKeyEvent_t ke) {
+ int code = super.traversalCode (key_sym , ke);
+ code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_MNEMONIC;
+ 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
index a79a25705e..faecdea2b4 100755
--- 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
@@ -1,15 +1,15 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
/**
* Instances of this class provide a surface for drawing
* arbitrary graphics.
@@ -29,13 +29,13 @@ import org.eclipse.swt.graphics.*;
*
* @see Composite
*/
-public class Canvas extends Composite {
- Caret caret;
-
-Canvas () {
- /* Do nothing */
-}
-
+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.
@@ -64,10 +64,10 @@ Canvas () {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Canvas (Composite parent, int style) {
- super (parent, style);
-}
-
+public Canvas (Composite parent, int style) {
+ super (parent, style);
+}
+
/**
* Returns the caret.
* <p>
@@ -86,53 +86,53 @@ public Canvas (Composite parent, int style) {
* <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;
-}
-
-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 releaseWidget () {
- if (caret != null) caret.releaseResources ();
- caret = null;
- super.releaseWidget();
-}
-
+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;
+}
+
+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 releaseWidget () {
+ if (caret != null) caret.releaseResources ();
+ caret = null;
+ super.releaseWidget();
+}
+
/**
* Scrolls a rectangular area of the receiver by first copying
* the source area to the destination and then causing the area
@@ -155,29 +155,29 @@ void releaseWidget () {
* <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 (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;
-}
-
+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 (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>
@@ -198,23 +198,23 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
* <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();
- super.setFont (font);
- if (caret != null) caret.setFont (font);
-}
-}
+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();
+ super.setFont (font);
+ if (caret != null) caret.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
index 25d5a1a2f1..42bb7fdd31 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -25,14 +25,14 @@ import org.eclipse.swt.graphics.*;
* 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;
-
+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.
@@ -61,53 +61,53 @@ public class Caret extends Widget {
* @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_DRAWMODE_XOR);
- 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;
-}
-
+// 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_DRAWMODE_XOR);
+ 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).
@@ -119,21 +119,21 @@ boolean drawCaret () {
* <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);
-}
-
-public Display getDisplay () {
- Composite parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+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);
+}
+
+public Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns the font that the receiver will use to paint textual information.
*
@@ -144,12 +144,12 @@ public Display getDisplay () {
* <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 ();
-}
-
+public Font getFont () {
+ checkWidget();
+ if (font != null) return font;
+ return parent.getFont ();
+}
+
/**
* Returns the image that the receiver will use to paint the caret.
*
@@ -160,11 +160,11 @@ public Font getFont () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Image getImage () {
- checkWidget();
- return image;
-}
-
+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).
@@ -176,11 +176,11 @@ public Image getImage () {
* <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);
-}
-
+public Point getLocation () {
+ checkWidget();
+ return new Point (x, y);
+}
+
/**
* Returns the receiver's parent, which must be a <code>Canvas</code>.
*
@@ -191,11 +191,11 @@ public Point getLocation () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Canvas getParent () {
- checkWidget();
- return parent;
-}
-
+public Canvas getParent () {
+ checkWidget();
+ return parent;
+}
+
/**
* Returns a point describing the receiver's size.
*
@@ -206,15 +206,15 @@ public Canvas getParent () {
* <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);
-}
-
+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.
@@ -232,65 +232,65 @@ public Point getSize () {
* <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 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 releaseChild () {
- super.releaseChild ();
- 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;
-}
-
+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 releaseChild () {
+ super.releaseChild ();
+ 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
@@ -307,42 +307,42 @@ void releaseWidget () {
* <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) hideCaret ();
- this.x = x; this.y = y;
- this.width = width; this.height = height;
- if (isFocus) 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 ();
-}
-
+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) hideCaret ();
+ this.x = x; this.y = y;
+ this.width = width; this.height = height;
+ if (isFocus) 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
@@ -358,14 +358,14 @@ void setFocus () {
* <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;
-}
-
+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
@@ -381,17 +381,17 @@ public void setFont (Font font) {
* <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) hideCaret ();
- this.image = image;
- if (isFocus) showCaret ();
-}
-
+public void setImage (Image image) {
+ checkWidget();
+ if (image != null && image.isDisposed ()) {
+ error (SWT.ERROR_INVALID_ARGUMENT);
+ }
+ boolean isFocus = isFocusCaret ();
+ if (isFocus) hideCaret ();
+ this.image = image;
+ if (isFocus) showCaret ();
+}
+
/**
* Sets the receiver's location to the point specified by
* the arguments which are relative to the receiver's
@@ -405,11 +405,11 @@ public void setImage (Image image) {
* <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);
-}
-
+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
@@ -422,12 +422,12 @@ public void setLocation (int x, int y) {
* <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);
-}
-
+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.
*
@@ -439,11 +439,11 @@ public void setLocation (Point location) {
* <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);
-}
-
+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.
*
@@ -458,12 +458,12 @@ public void setSize (int width, int height) {
* <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);
-}
-
+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.
@@ -480,21 +480,21 @@ public void setSize (Point size) {
* <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 ();
-}
-}
+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
index 948990b97a..53812e51b8 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -26,9 +26,9 @@ import org.eclipse.swt.graphics.*;
* within the SWT implementation.
* </p>
*/
-public class ColorDialog extends Dialog {
- RGB rgb;
-
+public class ColorDialog extends Dialog {
+ RGB rgb;
+
/**
* Constructs a new instance of this class given only its parent.
*
@@ -46,10 +46,10 @@ public class ColorDialog extends Dialog {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public ColorDialog (Shell parent) {
- this (parent, SWT.PRIMARY_MODAL);
-}
-
+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.
@@ -78,11 +78,11 @@ public ColorDialog (Shell parent) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public ColorDialog (Shell parent, int style) {
- super (parent, style);
- checkSubclass ();
-}
-
+public ColorDialog (Shell parent, int style) {
+ super (parent, style);
+ checkSubclass ();
+}
+
/**
* Returns the currently selected color in the receiver.
*
@@ -90,10 +90,10 @@ public ColorDialog (Shell parent, int style) {
*
* @see PaletteData#getRGBs
*/
-public RGB getRGB () {
- return rgb;
-}
-
+public RGB getRGB () {
+ return rgb;
+}
+
/**
* Makes the receiver visible and brings it to the front
* of the display.
@@ -107,27 +107,27 @@ public RGB getRGB () {
* <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 = 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;
-}
-
+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 = 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;
+}
+
/**
* Returns the receiver's selected color to be the argument.
*
@@ -137,8 +137,8 @@ public RGB open () {
*
* @see PaletteData#getRGBs
*/
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-}
+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
index b2d0abd4b1..3cc13465d0 100755
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -49,22 +49,22 @@ import org.eclipse.swt.events.*;
*
* @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;
- }
-
+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.
@@ -95,124 +95,124 @@ public class Combo extends Composite {
* @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;
- Display display = getDisplay ();
- 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);
-}
-
+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;
+ Display display = getDisplay ();
+ 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
@@ -225,19 +225,19 @@ void createHandle (int index) {
* <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);
- }
-}
-
+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>
@@ -252,15 +252,15 @@ public void deselect (int index) {
*
* @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);
-}
-
+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.
*
@@ -279,16 +279,16 @@ public void deselectAll () {
*
* @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);
-}
-
+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.
@@ -315,23 +315,23 @@ public void add (String string) {
*
* @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 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
@@ -351,13 +351,13 @@ public void add (String string, int index) {
* @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);
-}
-
+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
@@ -382,18 +382,18 @@ public void addModifyListener (ModifyListener listener) {
* @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 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);
+}
+
/**
* Sets the selection in the receiver's text field to an empty
* selection starting just before the first character. If the
@@ -411,92 +411,92 @@ protected void checkSubclass () {
*
* @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 IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 () {
- Display display = getDisplay ();
- 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);
-}
-
+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 IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 () {
+ Display display = getDisplay ();
+ 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
@@ -516,25 +516,25 @@ int focusHandle () {
* <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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);
-}
-
+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.
*
@@ -548,13 +548,13 @@ public String getItem (int index) {
* <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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];
-}
-
+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.
@@ -569,12 +569,12 @@ public int getItemCount () {
* <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li>
* </ul>
*/
-public int getItemHeight () {
- checkWidget();
- //NOT DONE - NOT NEEDED
- return 0;
-}
-
+public int getItemHeight () {
+ checkWidget();
+ //NOT DONE - NOT NEEDED
+ return 0;
+}
+
/**
* Returns an array of <code>String</code>s which are the items
* in the receiver's list.
@@ -594,30 +594,30 @@ public int getItemHeight () {
* <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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 ();
-}
-
+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 a <code>Point</code> whose x coordinate is the start
* of the selection in the receiver's text field, and whose y
@@ -632,28 +632,28 @@ String getNameText () {
* <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]);
-}
-
+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.
@@ -665,19 +665,19 @@ public Point getSelection () {
* <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;
-}
-
+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.
@@ -689,18 +689,18 @@ public int getSelectionIndex () {
* <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);
-}
-
+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.
*
@@ -714,19 +714,19 @@ public String getText () {
* <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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;
-}
-
+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
@@ -740,24 +740,24 @@ public int getTextHeight () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-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];
-}
-
-boolean hasFocus () {
- return OS.PtIsFocused (handle) != 0;
-}
-
-void hookEvents () {
- super.hookEvents ();
- int windowProc = getDisplay ().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);
-}
-
+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];
+}
+
+boolean hasFocus () {
+ return OS.PtIsFocused (handle) != 0;
+}
+
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().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
@@ -775,12 +775,12 @@ void hookEvents () {
* <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;
-}
-
+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
@@ -799,80 +799,80 @@ public int indexOf (String string) {
* <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);
-}
-
+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
@@ -892,21 +892,21 @@ void register () {
* <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
* </ul>
*/
-public void remove (int start, int end) {
- checkWidget();
- 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);
- }
-}
-
+public void remove (int start, int end) {
+ checkWidget();
+ 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.
@@ -924,18 +924,18 @@ public void remove (int start, int end) {
* <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</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);
- }
-}
-
+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,
@@ -955,13 +955,13 @@ public void remove (int index) {
* <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
* </ul>
*/
-public void remove (String string) {
- checkWidget();
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_ITEM_NOT_REMOVED);
- remove (index);
-}
-
+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.
* <p>
@@ -970,13 +970,13 @@ public void remove (String string) {
* <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);
-}
-
+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.
@@ -994,13 +994,13 @@ public void removeAll () {
* @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);
-}
-
+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.
@@ -1018,14 +1018,14 @@ public void removeModifyListener (ModifyListener listener) {
* @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 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
@@ -1038,18 +1038,18 @@ public void removeSelectionListener (SelectionListener listener) {
* <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);
-}
-
+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
@@ -1071,21 +1071,21 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
* <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</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);
-}
-
+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.
*
@@ -1099,25 +1099,25 @@ public void setItem (int index, String string) {
* <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
* </ul>
*/
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_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);
-}
-
+public void setItems (String [] items) {
+ checkWidget();
+ if (items == null) error (SWT.ERROR_NULL_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 selection in the receiver's text field to the
* range specified by the argument whose x coordinate is the
@@ -1134,12 +1134,12 @@ public void setItems (String [] items) {
* <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});
-}
-
+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.
@@ -1161,25 +1161,25 @@ public void setSelection (Point selection) {
* <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);
-}
-
+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.
@@ -1194,36 +1194,36 @@ public void setText (String string) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-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 (key_sym == OS.Pk_Up || key_sym == OS.Pk_Down) {
- code &= ~(SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS);
- }
- 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;
-}
-
-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 ();
-}
-
-}
+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 (key_sym == OS.Pk_Up || key_sym == OS.Pk_Down) {
+ code &= ~(SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS);
+ }
+ 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;
+}
+
+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
index b6cb8bd11b..ab5bec1586 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -34,15 +34,15 @@ import org.eclipse.swt.graphics.*;
*
* @see Canvas
*/
-public class Composite extends Scrollable {
- Layout layout;
- Control [] tabList;
- int cornerHandle;
-
-Composite () {
- /* Do nothing */
-}
-
+public class Composite extends Scrollable {
+ Layout layout;
+ Control [] tabList;
+ int cornerHandle;
+
+Composite () {
+ /* Do nothing */
+}
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -73,288 +73,288 @@ Composite () {
* @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;
-}
-
-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) {
- size = layout.computeSize (this, wHint, hHint, 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 () {
- Display display = getDisplay ();
- 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);
- Display display = getDisplay ();
- 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 drawWidget (int widget, int damage) {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_BACKGROUND) == 0) {
-
- /* Get the clipping tiles for children and siblings */
- int clip_tile = getClipping (handle, topHandle (), true, true);
-
- /* 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.PgSetMultiClip (clip_rects_count[0], clip_rects);
- OS.free (clip_rects);
-
- /* Draw the widget */
- super.drawWidget (widget, damage);
-
- /* Reset the clipping */
- OS.PgSetMultiClip (0, 0);
- }
- } else {
- super.drawWidget (widget, damage);
- }
-}
-
-
-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;
-}
-
+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;
+}
+
+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) {
+ size = layout.computeSize (this, wHint, hHint, 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 () {
+ Display display = getDisplay ();
+ 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);
+ Display display = getDisplay ();
+ 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 drawWidget (int widget, int damage) {
+ if ((state & CANVAS) != 0) {
+ if ((style & SWT.NO_BACKGROUND) == 0) {
+
+ /* Get the clipping tiles for children and siblings */
+ int clip_tile = getClipping (handle, topHandle (), true, true);
+
+ /* 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.PgSetMultiClip (clip_rects_count[0], clip_rects);
+ OS.free (clip_rects);
+
+ /* Draw the widget */
+ super.drawWidget (widget, damage);
+
+ /* Reset the clipping */
+ OS.PgSetMultiClip (0, 0);
+ }
+ } else {
+ super.drawWidget (widget, damage);
+ }
+}
+
+
+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 an array containing the receiver's children.
* <p>
@@ -370,22 +370,22 @@ int getClipping(int widget, int topWidget, boolean clipChildren, boolean clipSib
* <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;
-}
-
+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.
@@ -397,55 +397,55 @@ int getChildrenCount () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Layout getLayout () {
- checkWidget();
- return layout;
-}
-
-boolean hasBorder () {
- return (style & SWT.BORDER) != 0;
-}
-
-boolean hasFocus () {
- return OS.PtIsFocused (handle) == 2;
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
-}
-
-/**
- * Gets the last specified 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 Layout getLayout () {
+ checkWidget();
+ return layout;
+}
+
+boolean hasBorder () {
+ return (style & SWT.BORDER) != 0;
+}
+
+boolean hasFocus () {
+ return OS.PtIsFocused (handle) == 2;
+}
+
+boolean hooksKeys () {
+ return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
+}
+
+/**
+ * Gets the last specified 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;
-}
-
+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.
@@ -459,26 +459,26 @@ public Control [] getTabList () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void layout () {
- checkWidget();
- layout (true);
-}
-
-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);
-}
-
+public void layout () {
+ checkWidget();
+ layout (true);
+}
+
+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);
+}
+
/**
* 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.
@@ -496,187 +496,187 @@ void moveToBack (int child) {
* <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;
- int count = getChildrenCount ();
- if (count == 0) return;
- layout.layout (this, changed);
-}
-
-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 && 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 */
- postEvent (SWT.DragDetect);
- }
- return OS.Pt_CONTINUE;
-}
-
-void releaseChildren () {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (!child.isDisposed ()) child.releaseResources ();
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- cornerHandle = 0;
-}
-
-void releaseWidget () {
- releaseChildren ();
- super.releaseWidget ();
- layout = null;
- tabList = null;
-}
-
-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]);
-}
-
-void resizeClientArea (int width, int height) {
- 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);
- }
-}
-
-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);
- if (events) sendEvent (SWT.Resize);
- if (layout != null) layout (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 ();
-}
-
+public void layout (boolean changed) {
+ checkWidget();
+ if (layout == null) return;
+ int count = getChildrenCount ();
+ if (count == 0) return;
+ layout.layout (this, changed);
+}
+
+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 && 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 */
+ postEvent (SWT.DragDetect);
+ }
+ return OS.Pt_CONTINUE;
+}
+
+void releaseChildren () {
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (!child.isDisposed ()) child.releaseResources ();
+ }
+}
+
+void releaseHandle () {
+ super.releaseHandle ();
+ cornerHandle = 0;
+}
+
+void releaseWidget () {
+ releaseChildren ();
+ super.releaseWidget ();
+ layout = null;
+ tabList = null;
+}
+
+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]);
+}
+
+void resizeClientArea (int width, int height) {
+ 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);
+ }
+}
+
+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);
+ if (events) sendEvent (SWT.Resize);
+ if (layout != null) layout (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.
@@ -688,38 +688,38 @@ public boolean setFocus () {
* <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;
-}
-
-boolean setTabGroupFocus () {
- if (isTabItem ()) return setTabItemFocus ();
- if ((style & SWT.NO_FOCUS) == 0) {
- boolean takeFocus = true;
- 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;
-}
-
-boolean setTabItemFocus () {
- if ((style & SWT.NO_FOCUS) == 0) {
- boolean takeFocus = true;
- if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
- if (takeFocus) {
- if (!isShowing ()) return false;
- if (forceFocus ()) return true;
- }
- }
- return super.setTabItemFocus ();
-}
-
+public void setLayout (Layout layout) {
+ checkWidget();
+ this.layout = layout;
+}
+
+boolean setTabGroupFocus () {
+ if (isTabItem ()) return setTabItemFocus ();
+ if ((style & SWT.NO_FOCUS) == 0) {
+ boolean takeFocus = true;
+ 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;
+}
+
+boolean setTabItemFocus () {
+ if ((style & SWT.NO_FOCUS) == 0) {
+ boolean takeFocus = true;
+ if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
+ if (takeFocus) {
+ if (!isShowing ()) return false;
+ if (forceFocus ()) return true;
+ }
+ }
+ return super.setTabItemFocus ();
+}
+
/**
* Sets the tabbing order for the specified controls to
* match the order that they occur in the argument list.
@@ -735,29 +735,29 @@ boolean setTabItemFocus () {
* <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);
-}
-
-int widgetClass () {
- if ((state & CANVAS) != 0) return OS.PtContainer ();
- return super.widgetClass ();
-}
-
-}
+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);
+}
+
+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
index 0b5a13bdda..fc43a091c5 100755
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>
@@ -28,18 +28,18 @@ import org.eclipse.swt.accessibility.*;
* within the SWT implementation.
* </p>
*/
-public abstract class Control extends Widget implements Drawable {
- Composite parent;
- Menu menu;
- Object layoutData;
- String toolTipText;
- int toolTipHandle;
- Accessible accessible;
-
-Control () {
- /* Do nothing */
-}
-
+public abstract class Control extends Widget implements Drawable {
+ Composite parent;
+ Menu menu;
+ Object layoutData;
+ String toolTipText;
+ 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.
@@ -68,12 +68,12 @@ Control () {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Control (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (0);
-}
-
+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
@@ -93,14 +93,14 @@ public Control (Composite parent, int style) {
* @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);
-}
-
+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
@@ -120,14 +120,14 @@ public void addControlListener(ControlListener listener) {
* @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);
-}
-
+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,
@@ -147,13 +147,13 @@ public void addFocusListener (FocusListener listener) {
* @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);
-}
-
+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
@@ -173,14 +173,14 @@ public void addHelpListener (HelpListener listener) {
* @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);
-}
-
+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
@@ -200,15 +200,15 @@ public void addKeyListener (KeyListener listener) {
* @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);
-}
-
+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
@@ -228,15 +228,15 @@ public void addMouseListener (MouseListener listener) {
* @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);
-}
-
+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
@@ -256,13 +256,13 @@ public void addMouseTrackListener (MouseTrackListener listener) {
* @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);
-}
-
+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
@@ -282,13 +282,13 @@ public void addMouseMoveListener (MouseMoveListener listener) {
* @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);
-}
-
+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
@@ -308,13 +308,13 @@ public void addPaintListener (PaintListener listener) {
* @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);
-}
-
+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.
@@ -328,23 +328,23 @@ public void addTraverseListener (TraverseListener listener) {
*
* @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;
- int shellHandle = shell.shellHandle;
- OS.PtWindowToFront (shellHandle);
- OS.PtContainerGiveFocus (handle, null);
- return hasFocus ();
-}
-
+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;
+ int shellHandle = shell.shellHandle;
+ OS.PtWindowToFront (shellHandle);
+ OS.PtContainerGiveFocus (handle, null);
+ return hasFocus ();
+}
+
/**
* Returns the preferred size of the receiver.
* <p>
@@ -372,10 +372,10 @@ public boolean forceFocus () {
* @see #pack
* @see "computeTrim, getClientArea for controls that implement them"
*/
-public Point computeSize (int wHint, int hHint) {
- return computeSize (wHint, hHint, true);
-}
-
+public Point computeSize (int wHint, int hHint) {
+ return computeSize (wHint, hHint, true);
+}
+
/**
* Returns the preferred size of the receiver.
* <p>
@@ -410,133 +410,133 @@ public Point computeSize (int wHint, int hHint) {
* @see #pack
* @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);
- setZOrder ();
- realizeWidget ();
- setDefaultFont ();
-}
-
-int defaultBackground () {
- Display display = getDisplay ();
- return display.WIDGET_BACKGROUND;
-}
-
-byte [] defaultFont () {
- Display display = getDisplay ();
- return display.TEXT_FONT;
-}
-
-int defaultForeground () {
- Display display = getDisplay ();
- return display.WIDGET_FOREGROUND;
-}
-
-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;
- GC gc = event.gc = new GC (this);
- gc.setClipping (event.x, event.y, event.width, event.height);
- sendEvent (SWT.Paint, event);
- if (isDisposed ()) break;
- gc.dispose ();
- event.gc = null;
- }
- }
- } 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 (tile.next);
- GC gc = event.gc = new GC (this);
- 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);
-}
-
+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);
+ setZOrder ();
+ realizeWidget ();
+ setDefaultFont ();
+}
+
+int defaultBackground () {
+ Display display = getDisplay ();
+ return display.WIDGET_BACKGROUND;
+}
+
+byte [] defaultFont () {
+ Display display = getDisplay ();
+ return display.TEXT_FONT;
+}
+
+int defaultForeground () {
+ Display display = getDisplay ();
+ return display.WIDGET_FOREGROUND;
+}
+
+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;
+ GC gc = event.gc = new GC (this);
+ gc.setClipping (event.x, event.y, event.width, event.height);
+ sendEvent (SWT.Paint, event);
+ if (isDisposed ()) break;
+ gc.dispose ();
+ event.gc = null;
+ }
+ }
+ } 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 (tile.next);
+ GC gc = event.gc = new GC (this);
+ 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);
+}
+
/**
* Returns the accessible object for the receiver.
* If this is the first time this object is requested,
@@ -554,14 +554,14 @@ void drawWidget (int widget, int damage) {
*
* @since 2.0
*/
-public Accessible getAccessible () {
- checkWidget ();
- if (accessible == null) {
- accessible = Accessible.internal_new_Accessible (this);
- }
- return accessible;
-}
-
+public Accessible getAccessible () {
+ checkWidget ();
+ if (accessible == null) {
+ accessible = Accessible.internal_new_Accessible (this);
+ }
+ return accessible;
+}
+
/**
* Returns the receiver's background color.
*
@@ -572,13 +572,13 @@ public Accessible getAccessible () {
* <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 (getDisplay (), args [1]);
-}
-
+public Color getBackground () {
+ checkWidget();
+ int [] args = {OS.Pt_ARG_FILL_COLOR, 0, 0};
+ OS.PtGetResources (handle, args.length / 3, args);
+ return Color.photon_new (getDisplay (), args [1]);
+}
+
/**
* Returns the font that the receiver will use to paint textual information.
*
@@ -589,30 +589,30 @@ public Color getBackground () {
* <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 (getDisplay (), font);
-}
-
+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 (getDisplay (), font);
+}
+
/**
* Returns the foreground color that the receiver will use to draw.
*
@@ -623,13 +623,13 @@ public Font getFont () {
* <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 (getDisplay (), args [1]);
-}
-
+public Color getForeground () {
+ checkWidget();
+ int [] args = {OS.Pt_ARG_COLOR, 0, 0};
+ OS.PtGetResources (handle, args.length / 3, args);
+ return Color.photon_new (getDisplay (), args [1]);
+}
+
/**
* Returns the receiver's border width.
*
@@ -640,25 +640,25 @@ public Color getForeground () {
* <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;
-}
-
+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).
@@ -670,14 +670,14 @@ public int getBorderWidth () {
* <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);
-}
-
+public Rectangle getBounds () {
+ checkWidget();
+ int topHandle = topHandle ();
+ PhArea_t area = new PhArea_t ();
+ OS.PtWidgetArea (topHandle, area);
+ return new Rectangle (area.pos_x, area.pos_y, area.size_w, area.size_h);
+}
+
/**
* Returns the display that the receiver was created on.
*
@@ -688,12 +688,12 @@ public Rectangle getBounds () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Display getDisplay () {
- Composite parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+public Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> otherwise. A disabled control is typically
@@ -707,12 +707,12 @@ public Display getDisplay () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean getEnabled () {
- checkWidget ();
- int topHandle = topHandle ();
- return (OS.PtWidgetFlags (topHandle) & OS.Pt_BLOCKED) == 0;
-}
-
+public boolean getEnabled () {
+ checkWidget ();
+ int topHandle = topHandle ();
+ return (OS.PtWidgetFlags (topHandle) & OS.Pt_BLOCKED) == 0;
+}
+
/**
* Returns layout data which is associated with the receiver.
*
@@ -723,11 +723,11 @@ public boolean getEnabled () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Object getLayoutData () {
- checkWidget();
- return layoutData;
-}
-
+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).
@@ -739,14 +739,14 @@ public Object getLayoutData () {
* <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);
-}
-
+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
@@ -762,11 +762,11 @@ public Point getLocation () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Menu getMenu () {
- checkWidget();
- return menu;
-}
-
+public Menu getMenu () {
+ checkWidget();
+ return menu;
+}
+
/**
* 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
@@ -779,28 +779,28 @@ public Menu getMenu () {
* <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;
-}
-
+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.
@@ -814,14 +814,14 @@ Control [] getPath () {
* <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);
-}
-
+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.
@@ -833,11 +833,11 @@ public Point getSize () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
+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
@@ -853,11 +853,11 @@ public String getToolTipText () {
*
* @see #getParent
*/
-public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-
+public Shell getShell () {
+ checkWidget();
+ return parent.getShell ();
+}
+
/**
* Returns <code>true</code> if the receiver is visible, and
* <code>false</code> otherwise.
@@ -875,36 +875,36 @@ public Shell getShell () {
* <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 = getDisplay ().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;
-}
-
+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 = getDisplay ().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>
@@ -920,22 +920,22 @@ int focusHandle () {
*
* @private
*/
-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 [] args = {OS.Pt_ARG_COLOR, 0, 0, OS.Pt_ARG_FILL_COLOR, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- data.device = getDisplay ();
- data.widget = handle;
- data.topWidget = topHandle ();
- data.foreground = args [1];
- data.background = args [4];
- data.font = getFont ().handle;
- return phGC;
-}
-
+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 [] args = {OS.Pt_ARG_COLOR, 0, 0, OS.Pt_ARG_FILL_COLOR, 0, 0};
+ OS.PtGetResources (handle, args.length / 3, args);
+ data.device = getDisplay ();
+ 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>
@@ -951,40 +951,40 @@ public int internal_new_GC (GCData data) {
*
* @private
*/
-public void internal_dispose_GC (int phGC, GCData data) {
- checkWidget ();
- OS.PgDestroyGC(phGC);
-}
-
-/**
- * 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 ();
-}
-
-public boolean isFocusAncestor () {
- Display display = getDisplay ();
- Control control = display.getFocusControl ();
- while (control != null && control != this) {
- control = control.parent;
- }
- return control == this;
-}
-
+public void internal_dispose_GC (int phGC, GCData data) {
+ checkWidget ();
+ OS.PgDestroyGC(phGC);
+}
+
+/**
+ * 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 ();
+}
+
+public boolean isFocusAncestor () {
+ Display display = getDisplay ();
+ 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.
@@ -996,11 +996,11 @@ public boolean isFocusAncestor () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean isFocusControl () {
- checkWidget();
- return hasFocus ();
-}
-
+public boolean isFocusControl () {
+ checkWidget();
+ return hasFocus ();
+}
+
/**
* Returns <code>true</code> if the underlying operating
* system supports this reparenting, otherwise <code>false</code>
@@ -1012,83 +1012,83 @@ public boolean isFocusControl () {
* <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
- * 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);
-}
-
-Decorations menuShell () {
- return parent.menuShell ();
-}
-
+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
+ * 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);
+}
+
+Decorations menuShell () {
+ return parent.menuShell ();
+}
+
/**
* Moves the receiver above the specified control in the
* drawing order. If the argument is null, then the receiver
@@ -1106,20 +1106,20 @@ Decorations menuShell () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-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);
-}
-
+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
@@ -1137,20 +1137,20 @@ public void moveAbove (Control control) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-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);
-}
-
+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
@@ -1163,11 +1163,11 @@ public void moveBelow (Control control) {
*
* @see #computeSize
*/
-public void pack () {
- checkWidget();
- pack (true);
-}
-
+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
@@ -1187,346 +1187,346 @@ public void pack () {
*
* @see #computeSize
*/
-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);
- Event event = new Event ();
- event.time = ev.timestamp;
- setMouseState (event, pe, ev);
- switch ((int) ev.subtype) {
- case OS.Ph_EV_PTR_ENTER:
- case OS.Ph_EV_PTR_ENTER_FROM_CHILD:
- sendEvent (SWT.MouseEnter, event);
- break;
- case OS.Ph_EV_PTR_LEAVE:
- case OS.Ph_EV_PTR_LEAVE_TO_CHILD:
- sendEvent (SWT.MouseExit, event);
- break;
- case OS.Ph_EV_PTR_STEADY:
- 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, pe, ev);
- postEvent (SWT.MouseDown, event);
- if (pe.click_count == 2) {
- Event clickEvent = new Event ();
- clickEvent.time = event.time;
- clickEvent.x = event.x;
- clickEvent.y = event.y;
- clickEvent.button = event.button;
- clickEvent.stateMask = event.stateMask;
- postEvent (SWT.MouseDoubleClick, clickEvent);
- }
- if (event.button == 3) {
- if (menu != null && !menu.isDisposed ()) {
- Display display = getDisplay ();
- display.runDeferredEvents ();
- menu.setVisible (true);
- }
- }
- /*
- * 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, 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, 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_PROCESS;
- }
- }
- }
-
- Event event = new Event ();
- event.time = ev.timestamp;
- setKeyState (event, ke);
- Display display = getDisplay ();
- 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;
- }
- postEvent (type, event);
- return OS.Pt_PROCESS;
-}
-
-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, 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.getDisplay ();
- 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 releaseWidget () {
- super.releaseWidget ();
- if (toolTipHandle != 0) destroyToolTip (toolTipHandle);
- toolTipHandle = 0;
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- menu = null;
- parent = null;
- layoutData = null;
-}
-
+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);
+ Event event = new Event ();
+ event.time = ev.timestamp;
+ setMouseState (event, pe, ev);
+ switch ((int) ev.subtype) {
+ case OS.Ph_EV_PTR_ENTER:
+ case OS.Ph_EV_PTR_ENTER_FROM_CHILD:
+ sendEvent (SWT.MouseEnter, event);
+ break;
+ case OS.Ph_EV_PTR_LEAVE:
+ case OS.Ph_EV_PTR_LEAVE_TO_CHILD:
+ sendEvent (SWT.MouseExit, event);
+ break;
+ case OS.Ph_EV_PTR_STEADY:
+ 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, pe, ev);
+ postEvent (SWT.MouseDown, event);
+ if (pe.click_count == 2) {
+ Event clickEvent = new Event ();
+ clickEvent.time = event.time;
+ clickEvent.x = event.x;
+ clickEvent.y = event.y;
+ clickEvent.button = event.button;
+ clickEvent.stateMask = event.stateMask;
+ postEvent (SWT.MouseDoubleClick, clickEvent);
+ }
+ if (event.button == 3) {
+ if (menu != null && !menu.isDisposed ()) {
+ Display display = getDisplay ();
+ display.runDeferredEvents ();
+ menu.setVisible (true);
+ }
+ }
+ /*
+ * 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, 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, 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_PROCESS;
+ }
+ }
+ }
+
+ Event event = new Event ();
+ event.time = ev.timestamp;
+ setKeyState (event, ke);
+ Display display = getDisplay ();
+ 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;
+ }
+ postEvent (type, event);
+ return OS.Pt_PROCESS;
+}
+
+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, 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.getDisplay ();
+ 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 releaseWidget () {
+ super.releaseWidget ();
+ if (toolTipHandle != 0) destroyToolTip (toolTipHandle);
+ toolTipHandle = 0;
+ if (menu != null && !menu.isDisposed ()) {
+ menu.dispose ();
+ }
+ menu = null;
+ parent = null;
+ layoutData = null;
+}
+
/**
* Causes the entire bounds of the receiver to be marked
* as needing to be redrawn. The next time a paint request
@@ -1539,11 +1539,11 @@ void releaseWidget () {
*
* @see #update
*/
-public void redraw () {
- checkWidget();
- OS.PtDamageWidget (handle);
-}
-
+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.
@@ -1567,17 +1567,17 @@ public void redraw () {
*
* @see #update
*/
-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);
-}
-
+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.
@@ -1595,14 +1595,14 @@ public void redraw (int x, int y, int width, int height, boolean allChildren) {
* @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);
-}
-
+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.
@@ -1620,14 +1620,14 @@ public void removeControlListener (ControlListener listener) {
* @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);
-}
-
+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.
@@ -1645,13 +1645,13 @@ public void removeFocusListener(FocusListener listener) {
* @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);
-}
-
+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.
@@ -1669,14 +1669,14 @@ public void removeHelpListener (HelpListener listener) {
* @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);
-}
-
+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.
@@ -1694,15 +1694,15 @@ public void removeKeyListener(KeyListener listener) {
* @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);
-}
-
+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.
@@ -1720,15 +1720,15 @@ public void removeMouseTrackListener(MouseTrackListener listener) {
* @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);
-}
-
+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.
@@ -1746,13 +1746,13 @@ public void removeMouseListener (MouseListener listener) {
* @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);
-}
-
+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.
@@ -1770,13 +1770,13 @@ public void removeMouseMoveListener(MouseMoveListener listener) {
* @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);
-}
-
+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.
@@ -1794,65 +1794,65 @@ public void removePaintListener(PaintListener listener) {
* @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;
-}
-
+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
@@ -1874,11 +1874,11 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
* <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);
-}
-
+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
@@ -1897,11 +1897,11 @@ public void setBounds (int x, int y, int width, int height) {
* <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);
-}
-
+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
@@ -1914,10 +1914,10 @@ public void setBounds (Rectangle rect) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setCapture (boolean capture) {
- checkWidget();
-}
-
+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
@@ -1937,33 +1937,33 @@ public void setCapture (boolean capture) {
* <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);
- }
-}
-
+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
@@ -1977,13 +1977,13 @@ public void setCursor (Cursor cursor) {
* <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);
-}
-
+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);
+}
+
/**
* Causes the receiver to have the <em>keyboard focus</em>,
* such that all keyboard events will be delivered to it.
@@ -1997,11 +1997,11 @@ public void setEnabled (boolean enabled) {
*
* @see #forceFocus
*/
-public boolean setFocus () {
- checkWidget();
- return forceFocus ();
-}
-
+public boolean setFocus () {
+ checkWidget();
+ return forceFocus ();
+}
+
/**
* Sets the receiver's background color to the color specified
* by the argument, or to the default system color for the control
@@ -2017,27 +2017,27 @@ public boolean setFocus () {
* <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);
-}
-
-void setBackgroundPixel (int pixel) {
- OS.PtSetResource (handle, OS.Pt_ARG_FILL_COLOR, pixel, 0);
-}
-
-void setDefaultFont () {
- Display display = getDisplay ();
- if (display.defaultFont != null) setFont (defaultFont ());
-}
-
+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);
+}
+
+void setBackgroundPixel (int pixel) {
+ OS.PtSetResource (handle, OS.Pt_ARG_FILL_COLOR, pixel, 0);
+}
+
+void setDefaultFont () {
+ Display display = getDisplay ();
+ 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
@@ -2053,35 +2053,35 @@ void setDefaultFont () {
* <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);
-}
-
+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
@@ -2097,22 +2097,22 @@ void setFont (int font) {
* <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);
-}
-
+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.
*
@@ -2123,11 +2123,11 @@ void setForegroundPixel (int pixel) {
* <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;
-}
-
+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
@@ -2141,11 +2141,11 @@ public void setLayoutData (Object layoutData) {
* <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);
-}
-
+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 argument which is relative to the receiver's
@@ -2158,12 +2158,12 @@ public void setLocation (int x, int y) {
* <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);
-}
-
+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
@@ -2184,17 +2184,17 @@ public void setLocation (Point location) {
* <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;
-}
-
+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.
@@ -2211,12 +2211,12 @@ public void setMenu (Menu menu) {
* <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
* </ul>
*/
-public boolean setParent (Composite parent) {
- checkWidget();
- if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return false;
-}
-
+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>
@@ -2236,25 +2236,25 @@ public boolean setParent (Composite parent) {
* <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 setFocus ();
-}
-
-boolean setRadioSelection (boolean value) {
- return false;
-}
-
+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 setFocus ();
+}
+
+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
@@ -2277,14 +2277,14 @@ boolean setRadioSelection (boolean value) {
* @see #redraw
* @see #update
*/
-public void setRedraw (boolean redraw) {
- checkWidget();
- if (redraw) {
- OS.PtContainerRelease (handle);
- } else {
- OS.PtContainerHold (handle);
- }
-}
+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>
@@ -2301,11 +2301,11 @@ public void setRedraw (boolean redraw) {
* <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);
-}
-
+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.
@@ -2322,22 +2322,22 @@ public void setSize (int width, int height) {
* <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 flags = visible ? 0 : OS.Pt_DELAY_REALIZE;
- OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_DELAY_REALIZE);
- if (parent != null && !OS.PtWidgetIsRealized (parent.handle)) return;
- if (visible == OS.PtWidgetIsRealized (topHandle)) return;
- if (visible) {
- sendEvent (SWT.Show);
- OS.PtRealizeWidget (topHandle);
- } else {
- OS.PtUnrealizeWidget (topHandle);
- sendEvent(SWT.Hide);
- }
-}
-
+public void setVisible (boolean visible) {
+ checkWidget ();
+ int topHandle = topHandle ();
+ int flags = visible ? 0 : OS.Pt_DELAY_REALIZE;
+ OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_DELAY_REALIZE);
+ if (parent != null && !OS.PtWidgetIsRealized (parent.handle)) return;
+ if (visible == OS.PtWidgetIsRealized (topHandle)) return;
+ if (visible) {
+ sendEvent (SWT.Show);
+ OS.PtRealizeWidget (topHandle);
+ } else {
+ OS.PtUnrealizeWidget (topHandle);
+ 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.
@@ -2349,38 +2349,38 @@ public void setVisible (boolean visible) {
* <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;
- }
- }
- }
- }
-}
-
-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]);
-}
-
+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;
+ }
+ }
+ }
+ }
+}
+
+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,
@@ -2396,19 +2396,19 @@ public Point toControl (int x, int y) {
* <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);
-}
-
-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]);
-}
-
+public Point toControl (Point point) {
+ checkWidget();
+ if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
+ return toControl (point.x, point.y);
+}
+
+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
@@ -2424,103 +2424,103 @@ public Point toDisplay (int x, int y) {
* <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 || (phEvent.key_mods & OS.Pk_KM_Ctrl) != 0;
- event.detail = detail;
- setKeyState (event, phEvent);
- 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 false;
- 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;
-}
-
+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 || (phEvent.key_mods & OS.Pk_KM_Ctrl) != 0;
+ event.detail = detail;
+ setKeyState (event, phEvent);
+ 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 false;
+ 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:
@@ -2536,84 +2536,84 @@ boolean traverse (Event event) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean traverse (int traversal) {
- checkWidget ();
- if (!isFocusControl () && !setFocus ()) return false;
- 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 ()) {
- if (!isDisposed () && !isFocusControl ()) 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.
- */
- 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;
-}
-
+public boolean traverse (int traversal) {
+ checkWidget ();
+ if (!isFocusControl () && !setFocus ()) return false;
+ 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 ()) {
+ if (!isDisposed () && !isFocusControl ()) 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.
+ */
+ 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 tree
* to be processed before this method returns.
@@ -2625,13 +2625,13 @@ boolean traverseReturn () {
*
* @see #redraw
*/
-public void update () {
- checkWidget();
- OS.PtFlush ();
-}
-
-int widgetClass () {
- return 0;
-}
-
-}
+public void update () {
+ checkWidget();
+ OS.PtFlush ();
+}
+
+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
index 2f20d0b075..ad0f29dac4 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -83,17 +83,17 @@ import org.eclipse.swt.graphics.*;
* @see Shell
* @see SWT
*/
-public class Decorations extends Canvas {
- Menu menuBar;
- Menu [] menus;
- String text = "";
- Image image;
- Button defaultButton, saveDefault;
-
-Decorations () {
- /* Do nothing */
-}
-
+public class Decorations extends Canvas {
+ Menu menuBar;
+ Menu [] menus;
+ String text = "";
+ Image image;
+ 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.
@@ -132,46 +132,46 @@ Decorations () {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Decorations (Composite parent, int style) {
- super (parent, style);
-}
-
-static int checkStyle (int style) {
- 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 () {
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-Control computeTabGroup () {
- return this;
-}
-
-Control computeTabRoot () {
- return this;
-}
-
+public Decorations (Composite parent, int style) {
+ super (parent, style);
+}
+
+static int checkStyle (int style) {
+ 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 () {
+}
+
+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.
@@ -185,11 +185,11 @@ Control computeTabRoot () {
*
* @see #setDefaultButton
*/
-public Button getDefaultButton () {
- checkWidget();
- return defaultButton;
-}
-
+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
@@ -211,11 +211,11 @@ public Button getDefaultButton () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Image getImage () {
- checkWidget();
- return image;
-}
-
+public Image getImage () {
+ checkWidget();
+ return image;
+}
+
/**
* Returns <code>true</code> if the receiver is currently
* maximized, and false otherwise.
@@ -230,11 +230,11 @@ public Image getImage () {
*
* @see #setMaximized
*/
-public boolean getMaximized () {
- checkWidget();
- return false;
-}
-
+public boolean getMaximized () {
+ checkWidget();
+ return false;
+}
+
/**
* Returns <code>true</code> if the receiver is currently
* minimized, and false otherwise.
@@ -249,11 +249,11 @@ public boolean getMaximized () {
*
* @see #setMinimized
*/
-public boolean getMinimized () {
- checkWidget();
- return false;
-}
-
+public boolean getMinimized () {
+ checkWidget();
+ return false;
+}
+
/**
* Returns the receiver's menu bar if one had previously
* been set, otherwise returns null.
@@ -265,15 +265,15 @@ public boolean getMinimized () {
* <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 ();
-}
-
+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
@@ -287,76 +287,76 @@ String getNameText () {
* <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 releaseWidget () {
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) menu.releaseResources ();
- }
- }
- menuBar = null;
- menus = null;
- image = null;
- super.releaseWidget ();
- 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);
-}
-
+public String getText () {
+ checkWidget();
+ return text;
+}
+
+boolean hasBorder () {
+ return false;
+}
+
+boolean isTabGroup () {
+ return true;
+}
+
+boolean isTabItem () {
+ return false;
+}
+
+Decorations menuShell () {
+ return this;
+}
+
+void releaseWidget () {
+ if (menus != null) {
+ for (int i=0; i<menus.length; i++) {
+ Menu menu = menus [i];
+ if (menu != null && !menu.isDisposed ()) menu.releaseResources ();
+ }
+ }
+ menuBar = null;
+ menus = null;
+ image = null;
+ super.releaseWidget ();
+ 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);
+}
+
/**
* If the argument is not null, sets the receiver's default
* button to the argument, and if the argument is null, sets
@@ -377,32 +377,32 @@ void resizeBounds (int width, int height) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setDefaultButton (Button button) {
- checkWidget();
- setDefaultButton (button, true);
-}
-void setDefaultButton (Button button, boolean save) {
- if (button == null) {
- if (defaultButton == saveDefault) {
- if (save) saveDefault = null;
- return;
- }
- } else {
- if (button.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- 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;
-}
-
+public void setDefaultButton (Button button) {
+ checkWidget();
+ setDefaultButton (button, true);
+}
+void setDefaultButton (Button button, boolean save) {
+ if (button == null) {
+ if (defaultButton == saveDefault) {
+ if (save) saveDefault = null;
+ return;
+ }
+ } else {
+ if (button.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ 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
@@ -420,12 +420,12 @@ void setDefaultButton (Button button, boolean save) {
* <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;
-}
-
+public void setImage (Image image) {
+ checkWidget();
+ if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ this.image = image;
+}
+
/**
* Sets the maximized state of the receiver.
* If the argument is <code>true</code> causes the receiver
@@ -449,10 +449,10 @@ public void setImage (Image image) {
*
* @see #setMinimized
*/
-public void setMaximized (boolean maximized) {
- checkWidget();
-}
-
+public void setMaximized (boolean maximized) {
+ checkWidget();
+}
+
/**
* Sets the receiver's menu bar to the argument, which
* may be null.
@@ -468,12 +468,12 @@ public void setMaximized (boolean maximized) {
* <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
-}
-
+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
@@ -497,10 +497,10 @@ public void setMenuBar (Menu menu) {
*
* @see #setMaximized
*/
-public void setMinimized (boolean minimized) {
- checkWidget();
-}
-
+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
@@ -516,17 +516,17 @@ public void setMinimized (boolean minimized) {
* <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;
-}
-
-}
+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
index 5f085a4e02..0b38ff26e8 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -19,9 +19,9 @@ import org.eclipse.swt.*;
* within the SWT implementation.
* </p>
*/
-public class DirectoryDialog extends Dialog {
- String message = "", filterPath = "";
-
+public class DirectoryDialog extends Dialog {
+ String message = "", filterPath = "";
+
/**
* Constructs a new instance of this class given only its
* parent.
@@ -44,10 +44,10 @@ public class DirectoryDialog extends Dialog {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public DirectoryDialog (Shell parent) {
- this (parent, SWT.PRIMARY_MODAL);
-}
-
+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.
@@ -78,21 +78,21 @@ public DirectoryDialog (Shell parent) {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public DirectoryDialog (Shell parent, int style) {
- super (parent, style);
- checkSubclass ();
-}
-
+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
*/
-public String getFilterPath () {
- return filterPath;
-}
-
+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
@@ -100,10 +100,10 @@ public String getFilterPath () {
*
* @return the message
*/
-public String getMessage () {
- return message;
-}
-
+public String getMessage () {
+ return message;
+}
+
/**
* Makes the dialog visible and brings it to the front
* of the display.
@@ -116,29 +116,29 @@ public String getMessage () {
* <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 new String (Converter.mbcsToWcs (null, path));
-}
-
+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 new String (Converter.mbcsToWcs (null, path));
+}
+
/**
* Sets the path which the dialog will use to filter
* the directories it shows to the argument, which may be
@@ -146,10 +146,10 @@ public String open () {
*
* @param string the filter path
*/
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
+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
@@ -157,8 +157,8 @@ public void setFilterPath (String string) {
*
* @param string the message
*/
-public void setMessage (String string) {
- message = string;
-}
-
+public void setMessage (String string) {
+ 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
index 84f07e30f6..9dfa89d378 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -87,200 +87,200 @@ import org.eclipse.swt.graphics.*;
* @see #sleep
* @see #dispose
*/
-public class Display extends Device {
-
+public class Display extends Device {
+
/* TEMPORARY CODE FOR EMULATED TABLE */
- int textHighlightThickness = 0;
-
- /* TEMPORARY HACK FOR PHOTON */
- 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;
-
- /* 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.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_Cancel, 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},
-
-
- /* Numeric Keypad Keys */
- /*
- {OS.XK_KP_Add, SWT.KP_PLUS},
- {OS.XK_KP_Subtract, SWT.KP_MINUS},
- {OS.XK_KP_Multiply, SWT.KP_TIMES},
- {OS.XK_KP_Divide, SWT.KP_DIVIDE},
- {OS.XK_KP_Decimal, SWT.KP_PERIOD},
- {OS.XK_KP_Enter, SWT.KP_ENTER},
- {OS.XK_KP_0, SWT.KP_0},
- {OS.XK_KP_1, SWT.KP_1},
- {OS.XK_KP_2, SWT.KP_2},
- {OS.XK_KP_3, SWT.KP_3},
- {OS.XK_KP_4, SWT.KP_4},
- {OS.XK_KP_5, SWT.KP_5},
- {OS.XK_KP_6, SWT.KP_6},
- {OS.XK_KP_7, SWT.KP_7},
- {OS.XK_KP_8, SWT.KP_8},
- {OS.XK_KP_9, SWT.KP_9},
- */
- };
-
- /* Multiple Displays. */
- static Display Default;
- static Display [] Displays = new Display [4];
-
- /* Window Classes */
- int ClassesPtr;
- int PtButton;
- int PtList;
- int PtLabel;
- int PtWindow;
- int PtToggleButton;
- int PtComboBox;
- int PtText;
- int PtMultiText;
- int PtScrollbar;
- int PtScrollContainer;
- int PtScrollArea;
- int PtContainer;
- int PtProgress;
- int PtPanelGroup;
- int PtPane;
- int PtSlider;
- int PtSeparator;
- int PtToolbar;
-
- /* 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;
-
- /* 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;
-}
-
+ int textHighlightThickness = 0;
+
+ /* TEMPORARY HACK FOR PHOTON */
+ 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;
+
+ /* 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.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_Cancel, 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},
+
+
+ /* Numeric Keypad Keys */
+ /*
+ {OS.XK_KP_Add, SWT.KP_PLUS},
+ {OS.XK_KP_Subtract, SWT.KP_MINUS},
+ {OS.XK_KP_Multiply, SWT.KP_TIMES},
+ {OS.XK_KP_Divide, SWT.KP_DIVIDE},
+ {OS.XK_KP_Decimal, SWT.KP_PERIOD},
+ {OS.XK_KP_Enter, SWT.KP_ENTER},
+ {OS.XK_KP_0, SWT.KP_0},
+ {OS.XK_KP_1, SWT.KP_1},
+ {OS.XK_KP_2, SWT.KP_2},
+ {OS.XK_KP_3, SWT.KP_3},
+ {OS.XK_KP_4, SWT.KP_4},
+ {OS.XK_KP_5, SWT.KP_5},
+ {OS.XK_KP_6, SWT.KP_6},
+ {OS.XK_KP_7, SWT.KP_7},
+ {OS.XK_KP_8, SWT.KP_8},
+ {OS.XK_KP_9, SWT.KP_9},
+ */
+ };
+
+ /* Multiple Displays. */
+ static Display Default;
+ static Display [] Displays = new Display [4];
+
+ /* Window Classes */
+ int ClassesPtr;
+ int PtButton;
+ int PtList;
+ int PtLabel;
+ int PtWindow;
+ int PtToggleButton;
+ int PtComboBox;
+ int PtText;
+ int PtMultiText;
+ int PtScrollbar;
+ int PtScrollContainer;
+ int PtScrollArea;
+ int PtContainer;
+ int PtProgress;
+ int PtPanelGroup;
+ int PtPane;
+ int PtSlider;
+ int PtSeparator;
+ int PtToolbar;
+
+ /* 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;
+
+ /* 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>
@@ -300,71 +300,71 @@ static void setDevice (Device device) {
* @see Widget#checkSubclass
* @see Shell
*/
-public Display () {
- this (null);
-}
-
-public Display (DeviceData data) {
- super (data);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notifed when an event of the given type occurs anywhere
- * in SWT. When the event does occur, 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>
- * </ul>
- *
- * @see Listener
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 2.1
- */
-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 notifed when an event of the given type occurs. 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>
- * </ul>
- *
- * @see Listener
- * @see #removeListener
- *
- * @since 2.0
+public Display () {
+ this (null);
+}
+
+public Display (DeviceData data) {
+ super (data);
+}
+
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notifed when an event of the given type occurs anywhere
+ * in SWT. When the event does occur, 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>
+ * </ul>
+ *
+ * @see Listener
+ * @see #removeFilter
+ * @see #removeListener
+ *
+ * @since 2.1
+ */
+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 notifed when an event of the given type occurs. 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>
+ * </ul>
+ *
+ * @see Listener
+ * @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);
-}
-
+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
@@ -376,112 +376,112 @@ public void addListener (int eventType, Listener listener) {
*
* @see #syncExec
*/
-public void asyncExec (Runnable runnable) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer.asyncExec (runnable);
-}
-
+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).
*/
-public void beep () {
- checkDevice ();
- OS.PtBeep ();
-}
-
-protected void checkDevice () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-static synchronized void checkDisplay (Thread thread) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] != null && Displays [i].thread == thread) {
- SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
-}
-
-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>
- * </ul>
- *
- * @see #dispose
- *
- * @since 2.0
+public void beep () {
+ checkDevice ();
+ OS.PtBeep ();
+}
+
+protected void checkDevice () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+}
+
+static synchronized void checkDisplay (Thread thread) {
+ for (int i=0; i<Displays.length; i++) {
+ if (Displays [i] != null && Displays [i].thread == thread) {
+ SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ }
+ }
+}
+
+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>
+ * </ul>
+ *
+ * @see #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 ();
-}
-
-protected void create (DeviceData data) {
- checkSubclass ();
- checkDisplay (thread = Thread.currentThread ());
- 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;
- }
-}
-
-protected void destroy () {
- if (this == Default) Default = null;
- deregister ();
- destroyDisplay ();
-}
-
-void destroyDisplay () {
- // NEED to destroy app_context ???
-}
-
+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 ();
+}
+
+protected void create (DeviceData data) {
+ checkSubclass ();
+ checkDisplay (thread = Thread.currentThread ());
+ 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;
+ }
+}
+
+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
@@ -489,40 +489,40 @@ void destroyDisplay () {
*
* @param runnable code to run at dispose time.
*/
-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);
-}
-
+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
@@ -531,26 +531,26 @@ void error (int code) {
* @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);
-}
-
+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
@@ -564,11 +564,11 @@ boolean filters (int eventType) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Widget findWidget (int handle) {
- checkDevice ();
- return WidgetTable.get (handle);
-}
-
+public Widget findWidget (int handle) {
+ checkDevice ();
+ return WidgetTable.get (handle);
+}
+
/**
* Returns the currently active <code>Shell</code>, or null
* if no shell belonging to the currently running application
@@ -580,19 +580,19 @@ public Widget findWidget (int handle) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</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;
-}
-
+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
@@ -604,41 +604,41 @@ public Shell getActiveShell () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</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;
-}
-
+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 the location of the on-screen pointer relative
* to the top left corner of the screen.
@@ -649,14 +649,14 @@ public Control getCursorControl () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</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);
-}
-
+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
@@ -664,15 +664,15 @@ public Point getCursorLocation () {
*
* @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;
-}
-
+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)
@@ -680,11 +680,11 @@ public static synchronized Display getCurrent () {
*
* @return the default display
*/
-public static synchronized Display getDefault () {
- if (Default == null) Default = new Display ();
- return Default;
-}
-
+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
@@ -692,15 +692,15 @@ public static synchronized Display getDefault () {
*
* @param name the new app name
*/
-public static void setAppName (String name) {
- /* Do nothing */
-}
-
-public int getDismissalAlignment () {
- checkDevice ();
- return SWT.RIGHT;
-}
-
+public static void setAppName (String name) {
+ /* Do nothing */
+}
+
+public int getDismissalAlignment () {
+ checkDevice ();
+ return SWT.RIGHT;
+}
+
/**
* Returns the longest duration, in milliseconds, between
* two mouse button clicks that will be considered a
@@ -712,12 +712,12 @@ public int getDismissalAlignment () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public int getDoubleClickTime () {
- checkDevice ();
- //NOT DONE
- return 250;
-}
-
+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
@@ -730,27 +730,27 @@ public int getDoubleClickTime () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</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 ();
-}
-
+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 the maximum allowed depth of icons on this display.
* On some platforms, this may be different than the actual
@@ -762,10 +762,10 @@ int getLastEventTime () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public int getIconDepth () {
- return getDepth ();
-}
-
+public int getIconDepth () {
+ return getDepth ();
+}
+
/**
* Returns an array containing all shells which have not been
* disposed and have the receiver as their display.
@@ -776,34 +776,34 @@ public int getIconDepth () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</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.getDisplay ()) {
- 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.getDisplay ()) {
- result [index++] = shell;
- }
- }
- return result;
-}
-
+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.getDisplay ()) {
+ 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.getDisplay ()) {
+ result [index++] = shell;
+ }
+ }
+ return result;
+}
+
/**
* Returns the matching standard color for the given
* constant, which should be one of the color constants
@@ -822,35 +822,35 @@ public Shell [] getShells () {
*
* @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);
-}
-
+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 a reasonable font for applications to use.
* On some platforms, this will match the "default font"
@@ -871,12 +871,12 @@ public Color getSystemColor (int id) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Font getSystemFont () {
- checkDevice ();
- byte [] font = defaultFont != null ? defaultFont : TEXT_FONT;
- return Font.photon_new (this, font);
-}
-
+public Font getSystemFont () {
+ checkDevice ();
+ byte [] font = defaultFont != null ? defaultFont : TEXT_FONT;
+ return Font.photon_new (this, font);
+}
+
/**
* Returns the thread that has invoked <code>syncExec</code>
* or null if no such runnable is currently being invoked by
@@ -888,263 +888,263 @@ public Font getSystemFont () {
*
* @return the receiver's sync-interface thread
*/
-public Thread getSyncThread () {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- return synchronizer.syncThread;
-}
-
+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
*/
-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);
-}
-
-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,
- };
- 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;
-}
-
-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 ();
- runAsyncMessages ();
- }
- return OS.Pt_CONTINUE;
-}
-
+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);
+}
+
+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,
+ };
+ 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;
+}
+
+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 ();
+ runAsyncMessages ();
+ }
+ return OS.Pt_CONTINUE;
+}
+
/**
* Invokes platform specific functionality to allocate a new GC handle.
* <p>
@@ -1160,16 +1160,16 @@ int inputProc (int data, int rcvid, int message, int size) {
*
* @private
*/
-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);
-
- data.device = this;
- data.rid = OS.Ph_DEV_RID;
- return phGC;
-}
-
+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);
+
+ data.device = this;
+ data.rid = OS.Ph_DEV_RID;
+ return phGC;
+}
+
/**
* Invokes platform specific functionality to dispose a GC handle.
* <p>
@@ -1185,14 +1185,14 @@ public int internal_new_GC (GCData data) {
*
* @private
*/
-public void internal_dispose_GC (int phGC, GCData data) {
- OS.PgDestroyGC(phGC);
-}
-
-boolean isValidThread () {
- return thread == Thread.currentThread ();
-}
-
+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.
@@ -1217,16 +1217,16 @@ boolean isValidThread () {
* @see #setData
* @see #disposeExec
*/
-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;
-}
-
+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
@@ -1249,39 +1249,39 @@ public Object getData (String key) {
* @see #setData
* @see #disposeExec
*/
-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);
-}
-
-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) wake ();
-}
-
+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);
+}
+
+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) wake ();
+}
+
/**
* Reads an event from the operating system's event queue,
* dispatches it appropriately, and returns <code>true</code>
@@ -1304,244 +1304,244 @@ void postEvent (Event event) {
* @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 ();
- } 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;
-}
-
-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.getDisplay ()) shell.dispose ();
- }
- }
- 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 = OS.Ph_RELEASE_IMAGE_ALL;
- OS.memmove(nullImage, phImage, PhImage_t.sizeof);
- OS.PhReleaseImage(nullImage);
- OS.free(nullImage);
- nullImage = 0;
- }
-
- /* Release references */
- thread = null;
- data = null;
- keys = null;
- values = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notifed when an event of the given type occurs anywhere in SWT.
- *
- * @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 #addFilter
- * @see #addListener
- *
- * @since 2.1
- */
-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 notifed when an event of the given type occurs.
- *
- * @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 #addListener
- *
- * @since 2.0
+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 ();
+ } 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;
+}
+
+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.getDisplay ()) shell.dispose ();
+ }
+ }
+ 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 = OS.Ph_RELEASE_IMAGE_ALL;
+ OS.memmove(nullImage, phImage, PhImage_t.sizeof);
+ OS.PhReleaseImage(nullImage);
+ OS.free(nullImage);
+ nullImage = 0;
+ }
+
+ /* Release references */
+ thread = null;
+ data = null;
+ keys = null;
+ values = null;
+}
+
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notifed when an event of the given type occurs anywhere in SWT.
+ *
+ * @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 #addFilter
+ * @see #addListener
+ *
+ * @since 2.1
*/
-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 () {
- return synchronizer.runAsyncMessages ();
-}
-
-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);
- }
-}
-
-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
- * @since 2.0
- * @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
- * </ul>
+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 notifed when an event of the given type occurs.
+ *
+ * @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 #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 () {
+ return synchronizer.runAsyncMessages ();
+}
+
+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);
+ }
+}
+
+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
+ * @since 2.0
+ * @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
+ * </ul>
*/
-public void setCursorLocation (Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- setCursorLocation (point.x, point.y);
-}
-
+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.
@@ -1566,54 +1566,54 @@ public void setCursorLocation (Point point) {
* @see #setData
* @see #disposeExec
*/
-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;
-}
-
+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.
@@ -1636,11 +1636,11 @@ public void setData (String key, Object value) {
* @see #getData
* @see #disposeExec
*/
-public void setData (Object data) {
- checkDevice ();
- this.data = data;
-}
-
+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.
@@ -1654,15 +1654,15 @@ public void setData (Object data) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setSynchronizer (Synchronizer synchronizer) {
- checkDevice ();
- if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (this.synchronizer != null) {
- this.synchronizer.runAsyncMessages();
- }
- this.synchronizer = synchronizer;
-}
-
+public void setSynchronizer (Synchronizer synchronizer) {
+ checkDevice ();
+ if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (this.synchronizer != null) {
+ this.synchronizer.runAsyncMessages();
+ }
+ 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)
@@ -1676,15 +1676,15 @@ public void setSynchronizer (Synchronizer synchronizer) {
*
* @see #wake
*/
-public boolean sleep () {
- checkDevice ();
- OS.PtHold ();
- OS.PtAppProcessEvent (app_context);
- runDeferredEvents ();
- OS.PtRelease ();
- return true;
-}
-
+public boolean sleep () {
+ checkDevice ();
+ 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
@@ -1699,20 +1699,20 @@ public boolean sleep () {
*
* @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;
-}
-
+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
@@ -1731,91 +1731,91 @@ int textWidth (String string, byte[] font) {
*
* @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;
-}
-
+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.
*
* @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.getDisplay ()) {
- shell.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.getDisplay ()) {
+ 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
@@ -1823,78 +1823,78 @@ public void update() {
*
* @see #sleep
*/
-public void wake () {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (!embedded && thread == Thread.currentThread ()) return;
-// 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 ();
-}
-
-}
+public void wake () {
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+ if (!embedded && thread == Thread.currentThread ()) return;
+// 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
index 6aed157fae..9fa6ff6c4c 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -25,12 +25,12 @@ import org.eclipse.swt.*;
* 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 = "*";
-
+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.
@@ -53,10 +53,10 @@ public class FileDialog extends Dialog {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public FileDialog (Shell parent) {
- this (parent, SWT.PRIMARY_MODAL);
-}
-
+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.
@@ -87,11 +87,11 @@ public FileDialog (Shell parent) {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public FileDialog (Shell parent, int style) {
- super (parent, style);
- checkSubclass ();
-}
-
+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,
@@ -99,10 +99,10 @@ public FileDialog (Shell parent, int style) {
*
* @return the relative path of the file
*/
-public String getFileName () {
- return fileName;
-}
-
+public String getFileName () {
+ return fileName;
+}
+
/**
* Returns the paths of all files that were selected
* in the dialog relative to the filter path, or null
@@ -110,30 +110,30 @@ public String getFileName () {
*
* @return the relative paths of the files
*/
-public String [] getFileNames () {
- return new String [] {fileName};
-}
-
+public String [] getFileNames () {
+ 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;
-}
-
+public String [] getFilterExtensions () {
+ return filterExtensions;
+}
+
/**
* Returns the file names which the dialog will
* use to filter the files it shows.
*
* @return the file name filter
*/
-public String [] getFilterNames () {
- return filterNames;
-}
-
+public String [] getFilterNames () {
+ return filterNames;
+}
+
/**
* Returns the directory path that the dialog will use.
* File names in this path will appear in the dialog,
@@ -143,10 +143,10 @@ public String [] getFilterNames () {
*
* @see #setFilterExtensions
*/
-public String getFilterPath () {
- return filterPath;
-}
-
+public String getFilterPath () {
+ return filterPath;
+}
+
/**
* Makes the dialog visible and brings it to the front
* of the display.
@@ -159,73 +159,73 @@ public String getFilterPath () {
* <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;
-}
-
+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,
@@ -234,10 +234,10 @@ public String open () {
*
* @param string the file name
*/
-public void setFileName (String string) {
- fileName = string;
-}
-
+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,
@@ -245,10 +245,10 @@ public void setFileName (String string) {
*
* @param extensions the file extension filter
*/
-public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-
+public void setFilterExtensions (String [] extensions) {
+ filterExtensions = extensions;
+}
+
/**
* Sets the file names which the dialog will
* use to filter the files it shows to the argument,
@@ -256,10 +256,10 @@ public void setFilterExtensions (String [] extensions) {
*
* @param names the file name filter
*/
-public void setFilterNames (String [] names) {
- filterNames = names;
-}
-
+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
@@ -270,8 +270,8 @@ public void setFilterNames (String [] names) {
*
* @see #setFilterExtensions
*/
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-}
+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
index 71325916e7..91cc77e697 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -20,9 +20,9 @@ import org.eclipse.swt.graphics.*;
* within the SWT implementation.
* </p>
*/
-public class FontDialog extends Dialog {
- FontData fontData;
- RGB rgb;
+public class FontDialog extends Dialog {
+ FontData fontData;
+ RGB rgb;
/**
* Constructs a new instance of this class given only its
* parent.
@@ -45,9 +45,9 @@ public class FontDialog extends Dialog {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public FontDialog (Shell parent) {
- this (parent, SWT.PRIMARY_MODAL);
-}
+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.
@@ -78,29 +78,29 @@ public FontDialog (Shell parent) {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public FontDialog (Shell parent, int style) {
- super (parent, style);
- checkSubclass ();
-}
+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
*/
-public FontData getFontData() {
- return fontData;
-}
-/**
- * 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;
-}
+public FontData getFontData() {
+ return fontData;
+}
+/**
+ * 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 dialog visible and brings it to the front
* of the display.
@@ -113,40 +113,40 @@ public RGB getRGB () {
* <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();
- font = OS.PfGenerateFontName(description, osStyle, size, new byte[OS.MAX_FONT_TAG]);
- }
- 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;
-}
+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();
+ font = OS.PfGenerateFontName(description, osStyle, size, new byte[OS.MAX_FONT_TAG]);
+ }
+ 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
@@ -154,19 +154,19 @@ public FontData open () {
*
* @param fontData the FontData to use initially, or null
*/
-public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-/**
- * Returns 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 to select a default when
- * open() is called
- *
- * @see PaletteData#getRGBs
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-}
+public void setFontData (FontData fontData) {
+ this.fontData = fontData;
+}
+/**
+ * Returns 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 to 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/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Group.java
index 30b0acaeb4..034847dbf3 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -32,8 +32,8 @@ import org.eclipse.swt.graphics.*;
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
-public class Group extends Composite {
-
+public class Group extends Composite {
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -66,63 +66,63 @@ public class Group extends Composite {
* @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) {
- size = layout.computeSize (this, wHint, hHint, 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;
- Display display = getDisplay ();
- 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 () {
- Display display = getDisplay ();
- return display.GROUP_FONT;
-}
-
+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) {
+ size = layout.computeSize (this, wHint, hHint, 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;
+ Display display = getDisplay ();
+ 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 () {
+ Display display = getDisplay ();
+ 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
@@ -135,42 +135,42 @@ byte [] defaultFont () {
* <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_TITLE, 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);
-}
-
-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);
-}
-
+public String getText () {
+ checkWidget();
+ int [] args = {OS.Pt_ARG_TITLE, 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);
+}
+
+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,
@@ -186,23 +186,23 @@ Point getTitleSize() {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int flags = OS.Pt_SHOW_TITLE | OS.Pt_ETCH_TITLE_AREA;
- byte [] buffer = Converter.wcsToMbcs (null, stripMnemonics (string), 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 ();
-}
-
-}
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int flags = OS.Pt_SHOW_TITLE | OS.Pt_ETCH_TITLE_AREA;
+ byte [] buffer = Converter.wcsToMbcs (null, stripMnemonics (string), 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
index 8967808c6c..18c43dc3f9 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -34,10 +34,10 @@ import org.eclipse.swt.graphics.*;
* within the SWT implementation.
* </p>
*/
-public class Label extends Control {
- String text = "";
- Image image;
-
+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.
@@ -75,136 +75,136 @@ public class Label extends Control {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Label (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-static int checkStyle (int style) {
- if ((style & SWT.SEPARATOR) != 0) return style;
- 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) {
- Display display = getDisplay ();
- 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 ();
+public Label (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+static int checkStyle (int style) {
+ if ((style & SWT.SEPARATOR) != 0) return style;
+ 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) {
+ Display display = getDisplay ();
+ 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;
- Display display = getDisplay ();
- 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);
-}
-
+ 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;
+ Display display = getDisplay ();
+ 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
@@ -219,15 +219,15 @@ void createHandle (int index) {
* <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 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.
@@ -239,15 +239,15 @@ public int getAlignment () {
* <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 ();
-}
-
+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
@@ -260,36 +260,36 @@ String getNameText () {
* <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;
-}
-
+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>
@@ -303,34 +303,34 @@ void releaseWidget () {
* <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 boolean setFocus () {
- checkWidget();
- return false;
-}
-
-public void setFont (Font font) {
- super.setFont (font);
- if ((style & SWT.WRAP) != 0) setText (text);
-}
-
+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 boolean setFocus () {
+ checkWidget();
+ return false;
+}
+
+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.
@@ -345,23 +345,23 @@ public void setFont (Font font) {
* <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);
-}
-
+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>
@@ -379,71 +379,71 @@ public void setImage (Image image) {
* <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 [] unicode = new char [string.length ()];
- string.getChars (0, unicode.length, unicode, 0);
- int i=0, j=0;
- char mnemonic=0;
- while (i < unicode.length) {
- if ((unicode [j++] = unicode [i++]) == Mnemonic) {
- if (i == unicode.length) {continue;}
- if (unicode [i] == Mnemonic) {i++; continue;}
- if (mnemonic == 0) mnemonic = unicode [i];
- j--;
- }
- }
- while (j < unicode.length) unicode [j++] = 0;
- /* 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;
- Display display = getDisplay ();
- if (mnemonic != '\0') string = new String (unicode);
- string = display.wrapText (string, font, width);
- buffer = Converter.wcsToMbcs (null, string, true);
- } else {
- buffer = Converter.wcsToMbcs (null, unicode, true);
- }
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, 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, ptr, 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 (ptr);
- OS.free (ptr2);
-}
-
-int widgetClass () {
- if ((style & SWT.SEPARATOR) != 0) return OS.PtSeparator ();
- return OS.PtLabel ();
-}
-
-}
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.SEPARATOR) != 0) return;
+ text = string;
+ char [] unicode = new char [string.length ()];
+ string.getChars (0, unicode.length, unicode, 0);
+ int i=0, j=0;
+ char mnemonic=0;
+ while (i < unicode.length) {
+ if ((unicode [j++] = unicode [i++]) == Mnemonic) {
+ if (i == unicode.length) {continue;}
+ if (unicode [i] == Mnemonic) {i++; continue;}
+ if (mnemonic == 0) mnemonic = unicode [i];
+ j--;
+ }
+ }
+ while (j < unicode.length) unicode [j++] = 0;
+ /* 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;
+ Display display = getDisplay ();
+ if (mnemonic != '\0') string = new String (unicode);
+ string = display.wrapText (string, font, width);
+ buffer = Converter.wcsToMbcs (null, string, true);
+ } else {
+ buffer = Converter.wcsToMbcs (null, unicode, true);
+ }
+ int ptr = OS.malloc (buffer.length);
+ OS.memmove (ptr, 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, ptr, 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 (ptr);
+ OS.free (ptr2);
+}
+
+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/List.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/List.java
index f0a4ad9438..a47e159cfe 100755
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 notificiation
@@ -30,8 +30,8 @@ import org.eclipse.swt.events.*;
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
-public class List extends Scrollable {
-
+public class List extends Scrollable {
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -61,14 +61,14 @@ public class List extends Scrollable {
* @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);
-}
-
+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.
*
@@ -87,16 +87,16 @@ static int checkStyle (int style) {
*
* @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);
-}
-
+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
@@ -121,14 +121,14 @@ public void add (String string) {
* @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 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.
@@ -155,108 +155,108 @@ public void addSelectionListener(SelectionListener listener) {
*
* @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;
- }
+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;
- Display display = getDisplay ();
- 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 () {
- Display display = getDisplay ();
- return display.LIST_BACKGROUND;
-}
-
-byte [] defaultFont () {
- Display display = getDisplay ();
- return display.LIST_FONT;
-}
-
-int defaultForeground () {
- Display display = getDisplay ();
- return display.LIST_FOREGROUND;
-}
-
+ 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;
+ Display display = getDisplay ();
+ 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 () {
+ Display display = getDisplay ();
+ return display.LIST_BACKGROUND;
+}
+
+byte [] defaultFont () {
+ Display display = getDisplay ();
+ return display.LIST_FONT;
+}
+
+int defaultForeground () {
+ Display display = getDisplay ();
+ 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
@@ -269,12 +269,12 @@ int defaultForeground () {
* <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);
-}
-
+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
@@ -290,22 +290,22 @@ public void deselect (int index) {
* <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);
- }
-}
-
+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
@@ -323,18 +323,18 @@ public void deselect (int start, int end) {
* <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);
- }
- }
-}
-
+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.
*
@@ -343,16 +343,16 @@ public void deselect (int [] indices) {
* <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);
- }
-}
-
+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 is currently
* has the focus in the receiver, or -1 if no item is has focus.
@@ -364,10 +364,10 @@ public void deselectAll () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public int getFocusIndex () {
- return getSelectionIndex ();
-}
-
+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.
@@ -386,25 +386,25 @@ public int getFocusIndex () {
* <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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);
-}
-
+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.
*
@@ -418,13 +418,13 @@ public String getItem (int index) {
* <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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];
-}
-
+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 tree.
@@ -439,25 +439,25 @@ public int getItemCount () {
* <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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);
- 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];
-}
-
+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);
+ 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 an array of <code>String</code>s which are the items
* in the receiver.
@@ -478,27 +478,27 @@ public int getItemHeight () {
* <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</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;
-
-}
-
+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. An empty array indicates that no
@@ -519,16 +519,16 @@ public String [] getItems () {
* <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</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;
-}
-
+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.
*
@@ -542,13 +542,13 @@ public String [] getSelection () {
* <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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];
-}
-
+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.
@@ -563,19 +563,19 @@ public int getSelectionCount () {
* <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</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;
-}
-
+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 array is empty if no items are selected.
@@ -594,22 +594,22 @@ public int getSelectionIndex () {
* <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</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;
-}
-
+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
@@ -622,20 +622,20 @@ public int [] getSelectionIndices () {
* <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 = getDisplay ().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);
-}
-
+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 = getDisplay ().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>
@@ -655,12 +655,12 @@ void hookEvents () {
* <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;
-}
-
+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
@@ -683,28 +683,28 @@ public int indexOf (String string) {
* <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</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;
-}
-
+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
@@ -718,37 +718,37 @@ public int indexOf (String string, int start) {
* <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;
-}
-
+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.
@@ -766,15 +766,15 @@ int Pt_CB_SELECTION (int widget, int info) {
* <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</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);
-}
-
+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,
@@ -794,13 +794,13 @@ public void remove (int index) {
* <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
* </ul>
*/
-public void remove (String string) {
- checkWidget();
- int index = indexOf (string, 0);
- if (index == -1) error (SWT.ERROR_ITEM_NOT_REMOVED);
- remove (index);
-}
-
+public void remove (String string) {
+ checkWidget();
+ int index = indexOf (string, 0);
+ if (index == -1) error (SWT.ERROR_ITEM_NOT_REMOVED);
+ remove (index);
+}
+
/**
* Removes the items from the receiver at the given
* zero-relative indices.
@@ -818,23 +818,23 @@ public void remove (String string) {
* <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
* </ul>
*/
-public void remove (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- 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<newIndices.length; i++ ) {
- int index = newIndices [i];
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- int result = OS.PtListDeleteItemPos (handle, 1, index + 1);
- if (result != 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
-}
-
+public void remove (int [] indices) {
+ checkWidget();
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int [] newIndices = new int [indices.length];
+ System.arraycopy (indices, 0, newIndices, 0, indices.length);
+ sort (newIndices);
+ 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<newIndices.length; i++ ) {
+ int index = newIndices [i];
+ if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
+ int result = OS.PtListDeleteItemPos (handle, 1, index + 1);
+ if (result != 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
+ }
+}
+
/**
* Removes the items from the receiver which are
* between the given zero-relative start and end
@@ -854,18 +854,18 @@ public void remove (int [] indices) {
* <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
* </ul>
*/
-public void remove (int start, int end) {
- checkWidget();
- 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);
-}
-
+public void remove (int start, int end) {
+ checkWidget();
+ 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>
@@ -874,11 +874,11 @@ public void remove (int start, int end) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void removeAll () {
- checkWidget();
- OS.PtListDeleteAllItems (handle);
-}
-
+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.
@@ -896,14 +896,14 @@ public void removeAll () {
* @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 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.
* If the item at the index was already selected, it remains
@@ -918,27 +918,27 @@ public void removeSelectionListener(SelectionListener listener) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void select (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);
- int count = args [1];
- if ((style & SWT.SINGLE) != 0) {
- int index = Math.min (count - 1, end);
- if (index >= start) select (index);
- return;
- }
- int gotoIndex = -1;
- for (int index=end; index>=start; index--) {
- if (0 <= index && index < count) {
- gotoIndex = index;
- OS.PtListSelectPos (handle, index + 1);
- }
- }
- if (gotoIndex != -1) OS.PtListGotoPos (handle, gotoIndex + 1);
-}
-
+public void select (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);
+ int count = args [1];
+ if ((style & SWT.SINGLE) != 0) {
+ int index = Math.min (count - 1, end);
+ if (index >= start) select (index);
+ return;
+ }
+ int gotoIndex = -1;
+ for (int index=end; index>=start; index--) {
+ if (0 <= index && index < count) {
+ 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.
* If the item at the given zero-relative index in the receiver
@@ -956,24 +956,24 @@ public void select (int start, int end) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void select (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (indices.length == 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];
- int gotoIndex = -1;
- for (int i=0; i<indices.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);
-}
-
+public void select (int [] indices) {
+ checkWidget();
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (indices.length == 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];
+ int gotoIndex = -1;
+ for (int i=0; i<indices.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
@@ -986,17 +986,17 @@ public void select (int [] indices) {
* <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);
- }
-}
-
+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 the items in the receiver.
*
@@ -1005,17 +1005,17 @@ public void select (int index) {
* <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);
- }
-}
-
+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
@@ -1037,21 +1037,21 @@ public void selectAll () {
* <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</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);
-}
-
+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.
*
@@ -1065,23 +1065,23 @@ public void setItem (int index, String string) {
* <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
* </ul>
*/
-public void setItems (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_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]);
- }
-}
-
+public void setItems (String [] items) {
+ checkWidget();
+ if (items == null) error (SWT.ERROR_NULL_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 at the given zero-relative indices in the receiver.
* The current selected if first cleared, then the new items are selected.
@@ -1097,11 +1097,11 @@ public void setItems (String [] items) {
* @see Table#deselectAll()
* @see Table#select(int,int)
*/
-public void setSelection (int start, int end) {
- if ((style & SWT.MULTI) != 0) deselectAll ();
- select (start, end);
-}
-
+public void setSelection (int start, int end) {
+ 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.
@@ -1117,11 +1117,11 @@ public void setSelection (int start, int end) {
* @see List#deselectAll()
* @see List#select(int)
*/
-public void setSelection (int index) {
- if ((style & SWT.MULTI) != 0) deselectAll ();
- select (index);
-}
-
+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 first cleared, then the new items are selected.
@@ -1139,11 +1139,11 @@ public void setSelection (int index) {
* @see List#deselectAll()
* @see List#select(int[])
*/
-public void setSelection(int[] indices) {
- deselectAll ();
- select (indices);
-}
-
+public void setSelection(int[] indices) {
+ deselectAll ();
+ select (indices);
+}
+
/**
* Sets the receiver's selection to be the given array of items.
* The current selected is first cleared, then the new items are
@@ -1162,24 +1162,24 @@ public void setSelection(int[] indices) {
* @see List#deselectAll()
* @see List#select(int)
*/
-public void setSelection (String [] items) {
- checkWidget();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.MULTI) != 0) deselectAll ();
- for (int i=items.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) && isSelected (index)) return;
- index++;
- }
- }
- }
- if ((style & SWT.SINGLE) != 0) deselectAll ();
-}
-
+public void setSelection (String [] items) {
+ checkWidget();
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.MULTI) != 0) deselectAll ();
+ for (int i=items.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) && isSelected (index)) 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
@@ -1192,11 +1192,11 @@ public void setSelection (String [] items) {
* <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);
-}
-
+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
@@ -1210,30 +1210,30 @@ public void setTopIndex (int index) {
* <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 ();
-}
-
-}
+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
index 9cb2a5ed01..64d93e7739 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -27,12 +27,12 @@ import org.eclipse.swt.graphics.*;
* 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;
-
+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
@@ -52,10 +52,10 @@ public class Menu extends Widget {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Menu (Control parent) {
- this (checkNull (parent).getShell (), SWT.POP_UP);
-}
-
+public Menu (Control parent) {
+ this (checkNull (parent).getShell (), SWT.POP_UP);
+}
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Decorations</code>) and a style value
@@ -87,12 +87,12 @@ public Menu (Control parent) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Menu (Decorations parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
-
+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
@@ -113,10 +113,10 @@ public Menu (Decorations parent, int style) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Menu (Menu parentMenu) {
- this (checkNull (parentMenu).parent, SWT.DROP_DOWN);
-}
-
+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
@@ -137,29 +137,29 @@ public Menu (Menu parentMenu) {
* @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);
-}
-
+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,
@@ -179,13 +179,13 @@ static int checkStyle (int style) {
* @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);
-}
-
+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
@@ -205,35 +205,35 @@ public void addHelpListener (HelpListener listener) {
* @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);
-}
-
+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.
@@ -246,17 +246,17 @@ void createWidget (int index) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public MenuItem getDefaultItem () {
- checkWidget();
- return defaultItem;
-}
-
-public Display getDisplay () {
- Decorations parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+public MenuItem getDefaultItem () {
+ checkWidget();
+ return defaultItem;
+}
+
+public Display getDisplay () {
+ Decorations parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> otherwise. A disabled control is typically
@@ -270,12 +270,12 @@ public Display getDisplay () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean getEnabled () {
- checkWidget ();
- int topHandle = topHandle ();
- return (OS.PtWidgetFlags (topHandle) & OS.Pt_BLOCKED) == 0;
-}
-
+public boolean getEnabled () {
+ checkWidget ();
+ int topHandle = topHandle ();
+ return (OS.PtWidgetFlags (topHandle) & OS.Pt_BLOCKED) == 0;
+}
+
/**
* Returns the number of items contained in the receiver.
*
@@ -286,18 +286,18 @@ public boolean getEnabled () {
* <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;
-}
-
+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.
@@ -313,23 +313,23 @@ public int getItemCount () {
* <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;
-}
-
+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 an array of <code>MenuItem</code>s which are the items
* in the receiver.
@@ -346,46 +346,46 @@ public MenuItem getItem (int index) {
* <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;
-}
-
+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>.
*
@@ -396,11 +396,11 @@ String getNameText () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Decorations getParent () {
- checkWidget();
- return parent;
-}
-
+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
@@ -413,11 +413,11 @@ public Decorations getParent () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public MenuItem getParentItem () {
- checkWidget();
- return cascade;
-}
-
+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
@@ -430,12 +430,12 @@ public MenuItem getParentItem () {
* <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;
-}
-
+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
@@ -451,11 +451,11 @@ public Menu getParentMenu () {
*
* @see #getParent
*/
-public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-
+public Shell getShell () {
+ checkWidget();
+ return parent.getShell ();
+}
+
/**
* Returns <code>true</code> if the receiver is visible, and
* <code>false</code> otherwise.
@@ -473,17 +473,17 @@ public Shell getShell () {
* <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 = getDisplay ().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);
-}
-
+public boolean getVisible () {
+ checkWidget();
+ return OS.PtWidgetIsRealized (handle);
+}
+
+void hookEvents () {
+ int windowProc = getDisplay ().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
@@ -501,112 +501,112 @@ void hookEvents () {
* <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 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 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 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();
- 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 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 releaseChild () {
- super.releaseChild ();
- if (cascade != null) cascade.setMenu (null);
- if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
- parent.setMenuBar (null);
- }
-}
-
-void releaseWidget () {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (!item.isDisposed ()) item.releaseResources ();
- }
- super.releaseWidget ();
- if (parent != null) parent.remove (this);
- parent = null;
- cascade = null;
-}
-
+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 releaseChild () {
+ super.releaseChild ();
+ if (cascade != null) cascade.setMenu (null);
+ if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
+ parent.setMenuBar (null);
+ }
+}
+
+void releaseWidget () {
+ MenuItem [] items = getItems ();
+ for (int i=0; i<items.length; i++) {
+ MenuItem item = items [i];
+ if (!item.isDisposed ()) item.releaseResources ();
+ }
+ 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.
@@ -624,13 +624,13 @@ void releaseWidget () {
* @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);
-}
-
+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.
@@ -648,14 +648,14 @@ public void removeHelpListener (HelpListener listener) {
* @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);
-}
-
+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>.
@@ -670,12 +670,12 @@ public void removeMenuListener (MenuListener listener) {
* <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;
-}
-
+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 control is typically
@@ -689,13 +689,13 @@ public void setDefaultItem (MenuItem item) {
* <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);
-}
-
+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 receiver's location to the point specified by
* the arguments which are relative to the display.
@@ -712,19 +712,19 @@ public void setEnabled (boolean enabled) {
* <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;
-}
-
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-
+public void setLocation (int x, int y) {
+ checkWidget();
+ this.x = x;
+ this.y = y;
+ hasLocation = true;
+}
+
+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.
@@ -741,34 +741,34 @@ public void setLocation (Point location) {
* <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) {
- 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);
- }
-}
-
-}
+public void setVisible (boolean visible) {
+ checkWidget();
+ if ((style & SWT.POP_UP) == 0) return;
+ if (visible == OS.PtWidgetIsRealized (handle)) return;
+ if (visible) {
+ 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
index b7dbf19f85..51b27d12c5 100755
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -29,10 +29,10 @@ import org.eclipse.swt.events.*;
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
-public class MenuItem extends Item {
- Menu parent, menu;
- int accelerator;
-
+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
@@ -67,10 +67,10 @@ public class MenuItem extends Item {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public MenuItem (Menu parent, int style) {
- this (parent, style, parent.getItemCount());
-}
-
+public MenuItem (Menu parent, int style) {
+ this (parent, style, parent.getItemCount());
+}
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>Menu</code>), a style value
@@ -106,27 +106,27 @@ public MenuItem (Menu parent, int style) {
* @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));
- Display display = getDisplay ();
- 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);
-}
-
+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));
+ Display display = getDisplay ();
+ 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
@@ -146,13 +146,13 @@ void addAccelerator () {
* @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);
-}
-
+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
@@ -172,13 +172,13 @@ public void addArmListener (ArmListener listener) {
* @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);
-}
-
+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 control is selected, by sending
@@ -203,58 +203,58 @@ public void addHelpListener (HelpListener listener) {
* @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 ());
- }
-}
-
+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 ());
+ }
+}
+
/**
* Return the widget accelerator. An accelerator is the bit-wise
* OR of zero or more modifier masks and a key. Examples:
@@ -268,17 +268,17 @@ void createHandle (int index) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public int getAccelerator () {
- checkWidget();
- return accelerator;
-}
-
-public Display getDisplay () {
- Menu parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+public int getAccelerator () {
+ checkWidget();
+ return accelerator;
+}
+
+public Display getDisplay () {
+ Menu parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> otherwise. A disabled control is typically
@@ -292,19 +292,19 @@ public Display getDisplay () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-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;
-}
-
+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
@@ -319,16 +319,16 @@ public boolean getEnabled () {
* <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 ();
-}
-
+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>.
*
@@ -339,11 +339,11 @@ String getNameText () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Menu getParent () {
- checkWidget();
- return parent;
-}
-
+public Menu getParent () {
+ checkWidget();
+ return parent;
+}
+
/**
* Returns <code>true</code> if the receiver is selected,
* and false otherwise.
@@ -358,120 +358,120 @@ public Menu getParent () {
* <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 = getDisplay ().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 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 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 = getDisplay ().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 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 () {
- 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);
- setKeyState (event, ke);
- 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);
- setMouseState (event, pe, ev);
- 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) {
- postEvent (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 (handle, OS.Pt_ARG_FLAGS, flags, OS.Pt_BLOCKED | OS.Pt_GHOST);
- return OS.Pt_CONTINUE;
-}
-
-void releaseChild () {
- super.releaseChild ();
- if (menu != null) menu.dispose ();
- menu = null;
-}
-
-void releaseWidget () {
- if (menu != null && !menu.isDisposed ()) menu.releaseResources ();
- menu = null;
- super.releaseWidget ();
- if (accelerator != 0) removeAccelerator ();
- accelerator = 0;
- parent = null;
-}
-
+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);
+ setKeyState (event, ke);
+ 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);
+ setMouseState (event, pe, ev);
+ 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) {
+ postEvent (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 (handle, OS.Pt_ARG_FLAGS, flags, OS.Pt_BLOCKED | OS.Pt_GHOST);
+ return OS.Pt_CONTINUE;
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ if (menu != null) menu.dispose ();
+ menu = null;
+}
+
+void releaseWidget () {
+ if (menu != null && !menu.isDisposed ()) menu.releaseResources ();
+ menu = null;
+ 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.
@@ -489,13 +489,13 @@ void releaseWidget () {
* @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);
-}
-
+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.
@@ -513,28 +513,28 @@ public void removeArmListener (ArmListener listener) {
* @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));
- Display display = getDisplay ();
- 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);
-}
-
+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));
+ Display display = getDisplay ();
+ 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.
@@ -552,25 +552,25 @@ void removeAccelerator () {
* @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);
-}
-
+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:
@@ -584,14 +584,14 @@ void selectRadio () {
* <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 ();
-}
-
+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 control is typically
@@ -605,18 +605,18 @@ public void setAccelerator (int accelerator) {
* <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);
-}
-
+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>
@@ -630,43 +630,43 @@ public void setEnabled (boolean enabled) {
* <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.
- */
- Display display = getDisplay ();
- 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);
-}
-
+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.
+ */
+ Display display = getDisplay ();
+ 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
@@ -687,45 +687,45 @@ public void setImage (Image image) {
* <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;
-}
+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>
@@ -739,123 +739,123 @@ boolean setRadioSelection (boolean value) {
* <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);
-}
-
-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++]) == Mnemonic) {
- if (i == text.length) {continue;}
- if (text [i] == Mnemonic) {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);
- }
-}
-
-}
+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);
+}
+
+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++]) == Mnemonic) {
+ if (i == text.length) {continue;}
+ if (text [i] == Mnemonic) {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
index f4ab7480ec..08d09fadbd 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.photon.*;
+import org.eclipse.swt.*;
+
/**
* Instances of this class are used used to inform or warn the user.
* <dl>
@@ -31,8 +31,8 @@ import org.eclipse.swt.*;
* within the SWT implementation.
* </p>
*/
-public class MessageBox extends Dialog {
- String message = "";
+public class MessageBox extends Dialog {
+ String message = "";
/**
* Constructs a new instance of this class given only its
* parent.
@@ -55,9 +55,9 @@ public class MessageBox extends Dialog {
* <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);
-}
+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.
@@ -88,20 +88,20 @@ public MessageBox (Shell parent) {
* <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;
-}
+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, which is a description of
* the purpose for which it was opened. This message will be
@@ -109,9 +109,9 @@ static int checkStyle (int style) {
*
* @return the message
*/
-public String getMessage () {
- return message;
-}
+public String getMessage () {
+ return message;
+}
/**
* Makes the dialog visible and brings it to the front
* of the display.
@@ -124,81 +124,81 @@ public String getMessage () {
* <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;
- if (this.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;
-}
+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;
+ if (this.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
@@ -206,7 +206,7 @@ public int open () {
*
* @param string the message
*/
-public void setMessage (String string) {
- message = string;
-}
-}
+public void setMessage (String string) {
+ 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
index f551480d3a..7cdfb3ca94 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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,
@@ -28,8 +28,8 @@ import org.eclipse.swt.graphics.*;
* within the SWT implementation.
* </p>
*/
-public class ProgressBar extends Control {
-
+public class ProgressBar extends Control {
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -60,64 +60,64 @@ public class ProgressBar extends Control {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public ProgressBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- 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;
- Display display = getDisplay ();
- 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 () {
- Display display = getDisplay ();
- return display.GAUGE_FONT;
-}
-
+public ProgressBar (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+
+static int checkStyle (int style) {
+ 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;
+ Display display = getDisplay ();
+ 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 () {
+ Display display = getDisplay ();
+ return display.GAUGE_FONT;
+}
+
/**
* Returns the maximum value which the receiver will allow.
*
@@ -128,13 +128,13 @@ byte [] defaultFont () {
* <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];
-}
-
+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.
*
@@ -145,13 +145,13 @@ public int getMaximum () {
* <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];
-}
-
+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 <em>selection</em> that is the receiver's position.
*
@@ -162,13 +162,13 @@ public int getMinimum () {
* <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 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 which the receiver will allow
* to be the argument which must be greater than or
@@ -181,14 +181,14 @@ public int getSelection () {
* <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);
- }
-}
-
+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 which the receiver will allow
* to be the argument which must be greater than or
@@ -201,14 +201,14 @@ public void setMaximum (int value) {
* <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);
- }
-}
-
+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 <em>selection</em> that is the receiver's
* position to the argument which must be greater than or equal
@@ -221,17 +221,17 @@ public void setMinimum (int value) {
* <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 ();
-}
-
-}
+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
index 3039a4df6d..52be69a650 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -29,12 +29,12 @@ import org.eclipse.swt.events.*;
* 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;
-
+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.
@@ -64,10 +64,10 @@ public class Sash extends Control {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Sash (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
+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
@@ -93,220 +93,220 @@ public Sash (Composite parent, int style) {
* @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;
- Display display = getDisplay ();
- 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 () {
- Display display = getDisplay ();
- 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_DRAWMODE_XOR);
- 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 ();
- 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;
- }
-}
-
+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;
+ Display display = getDisplay ();
+ 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 () {
+ Display display = getDisplay ();
+ 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_DRAWMODE_XOR);
+ 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 ();
+ 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.
@@ -324,84 +324,84 @@ void processMouse (int info) {
* @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 ();
-}
-
-}
+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
index b9065e6395..8a96ccf0d6 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -30,9 +30,9 @@ import org.eclipse.swt.events.*;
* within the SWT implementation.
* </p>
*/
-public class Scale extends Control {
-
-
+public class Scale extends Control {
+
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -62,10 +62,10 @@ public class Scale extends Control {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Scale (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
+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
@@ -85,67 +85,67 @@ public Scale (Composite parent, int style) {
* @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;
- Display display = getDisplay ();
- 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 () {
- Display display = getDisplay ();
- return display.GAUGE_FONT;
-}
-
+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;
+ Display display = getDisplay ();
+ 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 () {
+ Display display = getDisplay ();
+ return display.GAUGE_FONT;
+}
+
/**
* Returns the amount that the receiver's value will be
* modified by when the up/down (or right/left) arrows
@@ -158,13 +158,13 @@ byte [] defaultFont () {
* <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];
-}
-
+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.
*
@@ -175,13 +175,13 @@ public int getIncrement () {
* <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];
-}
-
+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.
*
@@ -192,13 +192,13 @@ public int getMaximum () {
* <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];
-}
-
+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
@@ -211,13 +211,13 @@ public int getMinimum () {
* <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];
-}
-
+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 single <em>selection</em> that is the receiver's position.
*
@@ -228,25 +228,25 @@ public int getPageIncrement () {
* <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 = getDisplay ().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;
-}
-
+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 = getDisplay ().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.
@@ -264,14 +264,14 @@ int Pt_CB_SLIDER_MOVE (int widget, int info) {
* @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 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
@@ -285,11 +285,11 @@ public void removeSelectionListener(SelectionListener listener) {
* <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);
-}
-
+public void setIncrement (int value) {
+ checkWidget();
+ OS.PtSetResource (handle, OS.Pt_ARG_INCREMENT, value, 0);
+}
+
/**
* Sets the maximum value which the receiver will allow
* to be the argument which must be greater than or
@@ -302,11 +302,11 @@ public void setIncrement (int value) {
* <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 - 1, 0);
-}
-
+public void setMaximum (int value) {
+ checkWidget();
+ OS.PtSetResource (handle, OS.Pt_ARG_MAXIMUM, value - 1, 0);
+}
+
/**
* Sets the minimum value which the receiver will allow
* to be the argument which must be greater than or
@@ -319,11 +319,11 @@ public void setMaximum (int value) {
* <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);
-}
-
+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
@@ -337,11 +337,11 @@ public void setMinimum (int value) {
* <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);
-}
-
+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
@@ -354,13 +354,13 @@ public void setPageIncrement (int value) {
* <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 ();
-}
-
-}
+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
index ede7446d6f..9dcd537e80 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -75,27 +75,27 @@ import org.eclipse.swt.events.*;
* @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);
-}
-
+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
@@ -128,51 +128,51 @@ static int checkStyle (int style) {
* @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;
- Display display = getDisplay ();
- 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, 100, 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);
-}
-
-public Display getDisplay () {
- Scrollable parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+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;
+ Display display = getDisplay ();
+ 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, 100, 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);
+}
+
+public Display getDisplay () {
+ Scrollable parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> otherwise. A disabled control is typically
@@ -186,12 +186,12 @@ public Display getDisplay () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean getEnabled () {
- checkWidget ();
- int topHandle = topHandle ();
- return (OS.PtWidgetFlags (topHandle) & OS.Pt_BLOCKED) == 0;
-}
-
+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
@@ -204,13 +204,13 @@ public boolean getEnabled () {
* <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];
-}
-
+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.
*
@@ -221,13 +221,13 @@ public int getIncrement () {
* <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];
-}
-
+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.
*
@@ -238,13 +238,13 @@ public int getMinimum () {
* <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];
-}
-
+public int getMaximum () {
+ checkWidget();
+ int [] args = {OS.Pt_ARG_MAXIMUM, 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
@@ -257,13 +257,13 @@ public int getMaximum () {
* <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];
-}
-
+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 scrollable.
*
@@ -274,11 +274,11 @@ public int getPageIncrement () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Scrollable getParent () {
- checkWidget();
- return parent;
-}
-
+public Scrollable getParent () {
+ checkWidget();
+ return parent;
+}
+
/**
* Returns the single <em>selection</em> that is the receiver's value.
*
@@ -289,33 +289,33 @@ public Scrollable getParent () {
* <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 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]);
-}
-
+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]);
+}
+
/**
* Answers the size of the receiver's thumb relative to the
* difference between its maximum and minimum values.
@@ -329,13 +329,13 @@ public Point getSize () {
*
* @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];
-}
-
+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.
@@ -353,91 +353,91 @@ public int getThumb () {
* <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 = getDisplay ().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 getVisible () {
+ checkWidget ();
+ int topHandle = topHandle ();
+ return (OS.PtWidgetFlags (topHandle) & OS.Pt_DELAY_REALIZE) == 0;
+}
+
+void hookEvents () {
+ int windowProc = getDisplay ().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 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;
-}
-
+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.
@@ -455,26 +455,26 @@ int Pt_CB_SCROLL_MOVE (int widget, int info) {
* @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) {
- 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);
-}
-
+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) {
+ 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
@@ -488,12 +488,12 @@ void setBounds (int x, int y, int width, int height) {
* <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);
-}
+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
@@ -507,11 +507,11 @@ public void setEnabled (boolean enabled) {
* <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);
-}
-
+public void setIncrement (int value) {
+ checkWidget();
+ OS.PtSetResource (handle, OS.Pt_ARG_INCREMENT, value, 0);
+}
+
/**
* Sets the maximum value which the receiver will allow
* to be the argument which must be greater than or
@@ -524,11 +524,11 @@ public void setIncrement (int value) {
* <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 - 1, 0);
-}
-
+public void setMaximum (int value) {
+ checkWidget();
+ OS.PtSetResource (handle, OS.Pt_ARG_MAXIMUM, value - 1, 0);
+}
+
/**
* Sets the minimum value which the receiver will allow
* to be the argument which must be greater than or
@@ -541,11 +541,11 @@ public void setMaximum (int value) {
* <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);
-}
-
+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
@@ -559,11 +559,11 @@ public void setMinimum (int value) {
* <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);
-}
-
+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
@@ -576,11 +576,11 @@ public void setPageIncrement (int value) {
* <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);
-}
-
+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 to the
@@ -595,11 +595,11 @@ public void setSelection (int value) {
*
* @see ScrollBar
*/
-public void setThumb (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_SLIDER_SIZE, value, 0);
-}
-
+public void setThumb (int value) {
+ checkWidget();
+ 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.
@@ -621,25 +621,25 @@ public void setThumb (int value) {
* <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 (maximum - minimum - thumb < 0) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- int [] args = {
- OS.Pt_ARG_GAUGE_VALUE, selection, 0,
- OS.Pt_ARG_INCREMENT, increment, 0,
- OS.Pt_ARG_PAGE_INCREMENT, pageIncrement, 0,
- OS.Pt_ARG_SLIDER_SIZE, thumb, 0,
- OS.Pt_ARG_MINIMUM, minimum, 0,
- OS.Pt_ARG_MAXIMUM, maximum - 1, 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
-}
-
+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 (maximum - minimum - thumb < 0) return;
+ if (increment < 1) return;
+ if (pageIncrement < 1) return;
+ int [] args = {
+ OS.Pt_ARG_GAUGE_VALUE, selection, 0,
+ OS.Pt_ARG_INCREMENT, increment, 0,
+ OS.Pt_ARG_PAGE_INCREMENT, pageIncrement, 0,
+ OS.Pt_ARG_SLIDER_SIZE, thumb, 0,
+ OS.Pt_ARG_MINIMUM, minimum, 0,
+ OS.Pt_ARG_MAXIMUM, maximum - 1, 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.
@@ -656,23 +656,23 @@ public void setValues (int selection, int minimum, int maximum, int thumb, int i
* <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 flags = visible ? 0 : OS.Pt_DELAY_REALIZE;
- OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_DELAY_REALIZE);
- if (OS.PtWidgetIsRealized (parent.handle)) {
- if (visible != OS.PtWidgetIsRealized (topHandle)) {
- if (visible) {
- sendEvent (SWT.Show);
- OS.PtRealizeWidget (topHandle);
- } else {
- OS.PtUnrealizeWidget (topHandle);
- sendEvent(SWT.Hide);
- }
- }
- }
- parent.resizeClientArea ();
-}
-
-}
+public void setVisible (boolean visible) {
+ checkWidget ();
+ int topHandle = topHandle ();
+ int flags = visible ? 0 : OS.Pt_DELAY_REALIZE;
+ OS.PtSetResource (topHandle, OS.Pt_ARG_FLAGS, flags, OS.Pt_DELAY_REALIZE);
+ if (OS.PtWidgetIsRealized (parent.handle)) {
+ if (visible != OS.PtWidgetIsRealized (topHandle)) {
+ if (visible) {
+ sendEvent (SWT.Show);
+ OS.PtRealizeWidget (topHandle);
+ } else {
+ OS.PtUnrealizeWidget (topHandle);
+ sendEvent(SWT.Hide);
+ }
+ }
+ }
+ parent.resizeClientArea ();
+}
+
+}
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
index afae5b9b27..f0abe1bf35 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -25,14 +25,14 @@ import org.eclipse.swt.graphics.*;
* within the SWT implementation.
* </p>
*/
-public abstract class Scrollable extends Control {
- int scrolledHandle;
- ScrollBar horizontalBar, verticalBar;
-
-Scrollable () {
- /* Do nothing */
-}
-
+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.
@@ -62,39 +62,39 @@ Scrollable () {
* @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);
-}
-
+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
@@ -118,26 +118,26 @@ void deregister () {
*
* @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);
-}
-
+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,
@@ -152,17 +152,17 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
*
* @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);
-}
-
+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.
@@ -174,11 +174,11 @@ public Rectangle getClientArea () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public ScrollBar getHorizontalBar () {
- checkWidget();
- return horizontalBar;
-}
-
+public ScrollBar getHorizontalBar () {
+ checkWidget();
+ return horizontalBar;
+}
+
/**
* Returns the receiver's vertical scroll bar if it has
* one, and null if it does not.
@@ -190,40 +190,40 @@ public ScrollBar getHorizontalBar () {
* <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 releaseWidget () {
- if (horizontalBar != null) horizontalBar.releaseResources ();
- if (verticalBar != null) verticalBar.releaseResources ();
- horizontalBar = verticalBar = null;
- super.releaseWidget ();
-}
-
-void register () {
- super.register ();
- if (scrolledHandle != 0) WidgetTable.put (scrolledHandle, this);
-}
-
-int topHandle () {
- if (scrolledHandle == 0) return handle;
- return scrolledHandle;
-}
-
-}
+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 releaseWidget () {
+ if (horizontalBar != null) horizontalBar.releaseResources ();
+ if (verticalBar != null) verticalBar.releaseResources ();
+ horizontalBar = verticalBar = null;
+ super.releaseWidget ();
+}
+
+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
index 5c880743c9..9c5fa115f1 100755
--- 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
@@ -1,107 +1,107 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- * 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
- * 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>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE</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
+ * http://www.eclipse.org/legal/cpl-v10.html
*/
-public class Shell extends Decorations {
- int shellHandle;
- Display display;
- Menu activeMenu;
- int blockedList;
- Control lastActive;
-
+
+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>
+ * 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
+ * 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>.
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE</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;
+ Display display;
+ Menu activeMenu;
+ int blockedList;
+ Control lastActive;
+
/**
* Constructs a new instance of this class. This is equivalent
* to calling <code>Shell((Display) null)</code>.
@@ -111,10 +111,10 @@ public class Shell extends Decorations {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public Shell () {
- this ((Display) null);
-}
-
+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
@@ -150,10 +150,10 @@ public Shell () {
* @see SWT#APPLICATION_MODAL
* @see SWT#SYSTEM_MODAL
*/
-public Shell (int style) {
- this ((Display) null, style);
-}
-
+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>.
@@ -173,10 +173,10 @@ public Shell (int style) {
* <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);
-}
-
+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
@@ -220,24 +220,24 @@ public Shell (Display display) {
* @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);
- }
- this.style = checkStyle (style);
- this.parent = parent;
- this.display = display;
- this.handle = handle;
- createWidget (0);
-}
-
+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);
+ }
+ 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>.
@@ -260,10 +260,10 @@ Shell (Display display, Shell parent, int style, int handle) {
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
* </ul>
*/
-public Shell (Shell parent) {
- this (parent, SWT.TITLE | SWT.CLOSE | SWT.BORDER);
-}
-
+public Shell (Shell parent) {
+ this (parent, SWT.TITLE | SWT.CLOSE | SWT.BORDER);
+}
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -306,14 +306,14 @@ public Shell (Shell parent) {
* @see SWT#APPLICATION_MODAL
* @see SWT#SYSTEM_MODAL
*/
-public Shell (Shell parent, int style) {
- this (parent != null ? parent.getDisplay () : null, parent, style, 0);
-}
-
-public static Shell photon_new (Display display, int handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle);
-}
-
+public Shell (Shell parent, int style) {
+ this (parent != null ? parent.getDisplay () : 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,
@@ -333,38 +333,38 @@ public static Shell photon_new (Display display, int handle) {
* @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 () {
- OS.PtWidgetToFront (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 ();
-}
-
+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 () {
+ OS.PtWidgetToFront (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
@@ -379,158 +379,158 @@ void closeWidget () {
*
* @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 ();
- PhRect_t rect = new PhRect_t ();
- OS.PhWindowQueryVisible (OS.Ph_QUERY_GRAPHICS, 0, OS.PhInputGroup (0), rect);
- int width = (short) ((rect.lr_x - rect.ul_x + 1) * 5 / 8);
- int height = (short) ((rect.lr_y - rect.ul_y + 1) * 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);
- 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 [] 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]);
-}
-
-void deregister () {
- super.deregister ();
- WidgetTable.remove (shellHandle);
-}
-
-/**
- * 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) 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 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 ();
+ PhRect_t rect = new PhRect_t ();
+ OS.PhWindowQueryVisible (OS.Ph_QUERY_GRAPHICS, 0, OS.PhInputGroup (0), rect);
+ int width = (short) ((rect.lr_x - rect.ul_x + 1) * 5 / 8);
+ int height = (short) ((rect.lr_y - rect.ul_y + 1) * 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);
+ 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 [] 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]);
+}
+
+void deregister () {
+ super.deregister ();
+ WidgetTable.remove (shellHandle);
+}
+
+/**
+ * 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) 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 ();
-}
-
-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);
-}
-
-public Display getDisplay () {
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return display;
-}
-
+public void forceActive () {
+ checkWidget ();
+ bringToTop ();
+}
+
+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);
+}
+
+public Display getDisplay () {
+ if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return display;
+}
+
/**
* Returns the receiver's input method editor mode. This
* will be the result of bitwise OR'ing together one or
@@ -548,45 +548,45 @@ public Display getDisplay () {
*
* @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;
-}
-
-public Shell getShell () {
- checkWidget();
- return this;
-}
-
+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;
+}
+
+public Shell getShell () {
+ checkWidget();
+ return this;
+}
+
/**
* Returns an array containing all shells which are
* descendents of the receiver.
@@ -598,182 +598,182 @@ public Shell getShell () {
* <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 = getDisplay ().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,
- * and sets focus to its default button (if it has one)
- * 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 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 = getDisplay ().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,
+ * and sets focus to its default button (if it has one)
+ * 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 ();
- setVisible (true);
- 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) layout (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 releaseHandle () {
- super.releaseHandle ();
- shellHandle = 0;
-}
-
-void releaseShells () {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!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.releaseResources ();
- }
- }
- }
-}
-
-void releaseWidget () {
- releaseShells ();
- super.releaseWidget ();
- if (blockedList != 0) OS.PtUnblockWindows (blockedList);
- blockedList = 0;
- lastActive = null;
- display = null;
-}
-
+public void open () {
+ checkWidget();
+ bringToTop ();
+ setVisible (true);
+ 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) layout (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 releaseHandle () {
+ super.releaseHandle ();
+ shellHandle = 0;
+}
+
+void releaseShells () {
+ Shell [] shells = getShells ();
+ for (int i=0; i<shells.length; i++) {
+ Shell shell = shells [i];
+ if (!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.releaseResources ();
+ }
+ }
+ }
+}
+
+void releaseWidget () {
+ releaseShells ();
+ super.releaseWidget ();
+ if (blockedList != 0) OS.PtUnblockWindows (blockedList);
+ blockedList = 0;
+ lastActive = null;
+ display = null;
+}
+
/**
* Removes the listener from the collection of listeners who will
* be notified when operations are performed on the receiver.
@@ -791,158 +791,158 @@ void releaseWidget () {
* @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);
-}
-
-/**
- * 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) 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 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);
+}
+
+/**
+ * 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) 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 ();
-}
-
-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) layout (false);
- }
- }
-
- if (isFocus) caret.setFocus ();
-
- /* Always return 0 */
- return 0;
-}
-
+public void setActive () {
+ checkWidget ();
+ bringToTop ();
+}
+
+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) layout (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
@@ -959,152 +959,152 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
*
* @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);
- }
-}
-
-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);
- OS.PtRealizeWidget (shellHandle);
- } else {
- OS.PtUnrealizeWidget (shellHandle);
- sendEvent(SWT.Hide);
- }
-
- /*
- * 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;
-}
-
-}
+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);
+ }
+}
+
+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);
+ OS.PtRealizeWidget (shellHandle);
+ } else {
+ OS.PtUnrealizeWidget (shellHandle);
+ sendEvent(SWT.Hide);
+ }
+
+ /*
+ * 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
index 023179468e..83cb3c16d4 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -60,8 +60,8 @@ import org.eclipse.swt.events.*;
*
* @see ScrollBar
*/
-public class Slider extends Control {
-
+public class Slider extends Control {
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -91,14 +91,14 @@ public class Slider extends Control {
* @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);
-}
-
+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
@@ -131,55 +131,55 @@ static int checkStyle (int style) {
* @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();
- Display display = getDisplay ();
- 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;
- Display display = getDisplay ();
- int clazz = display.PtScrollbar;
- 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_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 () {
- Display display = getDisplay ();
- return display.GAUGE_FONT;
-}
-
+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();
+ Display display = getDisplay ();
+ 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;
+ Display display = getDisplay ();
+ int clazz = display.PtScrollbar;
+ 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_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 () {
+ Display display = getDisplay ();
+ return display.GAUGE_FONT;
+}
+
/**
* Returns the amount that the receiver's value will be
* modified by when the up/down (or right/left) arrows
@@ -192,13 +192,13 @@ byte [] defaultFont () {
* <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];
-}
-
+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.
*
@@ -209,13 +209,13 @@ public int getIncrement () {
* <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];
-}
-
+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.
*
@@ -226,13 +226,13 @@ public int getMinimum () {
* <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];
-}
-
+public int getMaximum () {
+ checkWidget();
+ int [] args = {OS.Pt_ARG_MAXIMUM, 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
@@ -245,13 +245,13 @@ public int getMaximum () {
* <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];
-}
-
+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 single <em>selection</em> that is the receiver's value.
*
@@ -262,20 +262,20 @@ public int getPageIncrement () {
* <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]);
-}
-
+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.
@@ -287,54 +287,54 @@ public Point getSize () {
* <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 = getDisplay ().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;
-}
-
+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 = getDisplay ().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.
@@ -352,14 +352,14 @@ int Pt_CB_SCROLL_MOVE (int widget, int info) {
* @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 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
@@ -373,11 +373,11 @@ public void removeSelectionListener (SelectionListener listener) {
* <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);
-}
-
+public void setIncrement (int value) {
+ checkWidget();
+ OS.PtSetResource (handle, OS.Pt_ARG_INCREMENT, value, 0);
+}
+
/**
* Sets the maximum value which the receiver will allow
* to be the argument which must be greater than or
@@ -390,11 +390,11 @@ public void setIncrement (int value) {
* <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 - 1, 0);
-}
-
+public void setMaximum (int value) {
+ checkWidget();
+ OS.PtSetResource (handle, OS.Pt_ARG_MAXIMUM, value - 1, 0);
+}
+
/**
* Sets the minimum value which the receiver will allow
* to be the argument which must be greater than or
@@ -407,11 +407,11 @@ public void setMaximum (int value) {
* <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);
-}
-
+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
@@ -425,11 +425,11 @@ public void setMinimum (int value) {
* <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);
-}
-
+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
@@ -442,11 +442,11 @@ public void setPageIncrement (int value) {
* <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);
-}
-
+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 to the
@@ -461,11 +461,11 @@ public void setSelection (int value) {
*
* @see ScrollBar
*/
-public void setThumb (int value) {
- checkWidget();
- OS.PtSetResource (handle, OS.Pt_ARG_SLIDER_SIZE, value, 0);
-}
-
+public void setThumb (int value) {
+ checkWidget();
+ 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.
@@ -487,27 +487,27 @@ public void setThumb (int value) {
* <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 (maximum - minimum - thumb < 0) return;
- if (increment < 1) return;
- if (pageIncrement < 1) return;
- int [] args = {
- OS.Pt_ARG_GAUGE_VALUE, selection, 0,
- OS.Pt_ARG_INCREMENT, increment, 0,
- OS.Pt_ARG_PAGE_INCREMENT, pageIncrement, 0,
- OS.Pt_ARG_SLIDER_SIZE, thumb, 0,
- OS.Pt_ARG_MINIMUM, minimum, 0,
- OS.Pt_ARG_MAXIMUM, maximum - 1, 0,
- };
- OS.PtSetResources (handle, args.length / 3, args);
-}
-
-int widgetClass () {
- return OS.PtScrollbar ();
-}
-
-}
+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 (maximum - minimum - thumb < 0) return;
+ if (increment < 1) return;
+ if (pageIncrement < 1) return;
+ int [] args = {
+ OS.Pt_ARG_GAUGE_VALUE, selection, 0,
+ OS.Pt_ARG_INCREMENT, increment, 0,
+ OS.Pt_ARG_PAGE_INCREMENT, pageIncrement, 0,
+ OS.Pt_ARG_SLIDER_SIZE, thumb, 0,
+ OS.Pt_ARG_MINIMUM, minimum, 0,
+ OS.Pt_ARG_MAXIMUM, maximum - 1, 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/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabFolder.java
index df244433aa..83ff2e9b8f 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.photon.*;
+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
@@ -35,11 +35,11 @@ import org.eclipse.swt.events.*;
* 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;
-
+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.
@@ -68,21 +68,21 @@ public class TabFolder extends Composite {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public TabFolder (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);
-}
-
+public TabFolder (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);
+}
+
/**
* Adds the listener to the collection of listeners who will
* be notified when the receiver's selection changes, by sending
@@ -107,169 +107,169 @@ static int checkStyle (int style) {
* @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) {
- size = layout.computeSize (this, wHint, hHint, 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 = 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;
- Display display = getDisplay ();
- 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,
- };
- 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);
- } else {
- OS.memmove (address, oldPtr + (j++ * 4), 4);
- str [0] = OS.strdup (address [0]);
- }
- if (str [0] == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.memmove (newPtr + (i * 4), str, 4);
- }
- OS.PtSetResource (handle, OS.Pt_ARG_PG_PANEL_TITLES, newPtr, count + 1);
- for (int i=0; i<=count; i++) {
- OS.memmove (address, newPtr + (i * 4), 4);
- OS.free (address [0]);
- }
- OS.free (newPtr);
- System.arraycopy (items, index, items, index + 1, count - index);
- items [index] = item;
- itemCount++;
-}
-
-void deregister () {
- super.deregister ();
- if (parentingHandle != 0) WidgetTable.remove (parentingHandle);
-}
-
-void destroyItem (TabItem item) {
- int count = itemCount;
- int index = 0;
- while (index < count) {
- if (items [index] == item) break;
- index++;
- }
- int [] args = {OS.Pt_ARG_PG_PANEL_TITLES, 0, 0};
- OS.PtGetResources (handle, args.length / 3, args);
- int oldPtr = args [1];
- int newPtr = OS.malloc ((count - 1) * 4);
- if (newPtr == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- int j = 0;
- int [] str = new int [1];
- int [] address = new int [1];
- for (int i=0; i<count; i++) {
- if (i == index) continue;
- OS.memmove (address, oldPtr + (i * 4), 4);
- str [0] = OS.strdup (address [0]);
- if (str [0] == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.memmove (newPtr + (j++ * 4), str, 4);
- }
- OS.PtSetResource (handle, OS.Pt_ARG_PG_PANEL_TITLES, newPtr, count - 1);
- for (int i=0; i<count-1; i++) {
- OS.memmove (address, newPtr + (i * 4), 4);
- OS.free (address [0]);
- }
- OS.free (newPtr);
- if (index != count) {
- System.arraycopy (items, index + 1, items, index, --count - index);
- }
- items [count] = null;
- itemCount--;
-}
-
-public Rectangle getClientArea () {
- checkWidget();
- PhArea_t area = new PhArea_t ();
- if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
- int clientHandle = OS.PtWidgetChildBack (handle);
- OS.PtWidgetArea (clientHandle, area);
- return new Rectangle (area.pos_x, area.pos_y, area.size_w, area.size_h);
-}
-
+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) {
+ size = layout.computeSize (this, wHint, hHint, 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 = 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;
+ Display display = getDisplay ();
+ 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,
+ };
+ 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);
+ } else {
+ OS.memmove (address, oldPtr + (j++ * 4), 4);
+ str [0] = OS.strdup (address [0]);
+ }
+ if (str [0] == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ OS.memmove (newPtr + (i * 4), str, 4);
+ }
+ OS.PtSetResource (handle, OS.Pt_ARG_PG_PANEL_TITLES, newPtr, count + 1);
+ for (int i=0; i<=count; i++) {
+ OS.memmove (address, newPtr + (i * 4), 4);
+ OS.free (address [0]);
+ }
+ OS.free (newPtr);
+ System.arraycopy (items, index, items, index + 1, count - index);
+ items [index] = item;
+ itemCount++;
+}
+
+void deregister () {
+ super.deregister ();
+ if (parentingHandle != 0) WidgetTable.remove (parentingHandle);
+}
+
+void destroyItem (TabItem item) {
+ int count = itemCount;
+ int index = 0;
+ while (index < count) {
+ if (items [index] == item) break;
+ index++;
+ }
+ int [] args = {OS.Pt_ARG_PG_PANEL_TITLES, 0, 0};
+ OS.PtGetResources (handle, args.length / 3, args);
+ int oldPtr = args [1];
+ int newPtr = OS.malloc ((count - 1) * 4);
+ if (newPtr == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ int j = 0;
+ int [] str = new int [1];
+ int [] address = new int [1];
+ for (int i=0; i<count; i++) {
+ if (i == index) continue;
+ OS.memmove (address, oldPtr + (i * 4), 4);
+ str [0] = OS.strdup (address [0]);
+ if (str [0] == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ OS.memmove (newPtr + (j++ * 4), str, 4);
+ }
+ OS.PtSetResource (handle, OS.Pt_ARG_PG_PANEL_TITLES, newPtr, count - 1);
+ for (int i=0; i<count-1; i++) {
+ OS.memmove (address, newPtr + (i * 4), 4);
+ OS.free (address [0]);
+ }
+ OS.free (newPtr);
+ if (index != count) {
+ System.arraycopy (items, index + 1, items, index, --count - index);
+ }
+ items [count] = null;
+ itemCount--;
+}
+
+public Rectangle getClientArea () {
+ checkWidget();
+ PhArea_t area = new PhArea_t ();
+ if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
+ int clientHandle = OS.PtWidgetChildBack (handle);
+ OS.PtWidgetArea (clientHandle, area);
+ 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.
@@ -285,12 +285,12 @@ public Rectangle getClientArea () {
* <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];
-}
-
+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.
@@ -307,13 +307,13 @@ public TabItem getItem (int index) {
* <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;
-}
-
+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.
*
@@ -324,11 +324,11 @@ public TabItem [] getItems () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-
+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
@@ -345,13 +345,13 @@ public int getItemCount () {
* <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]};
-}
-
+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.
@@ -363,26 +363,26 @@ public TabItem [] getSelection () {
* <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 = getDisplay ().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);
-}
-
+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 = getDisplay ().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
@@ -400,106 +400,106 @@ void hookEvents () {
* <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 releaseWidget () {
- for (int i=0; i<itemCount; i++) {
- TabItem item = items [i];
- if (!item.isDisposed ()) item.releaseResources ();
- }
- items = null;
- super.releaseWidget ();
-}
-
+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 releaseWidget () {
+ for (int i=0; i<itemCount; i++) {
+ TabItem item = items [i];
+ if (!item.isDisposed ()) item.releaseResources ();
+ }
+ items = null;
+ super.releaseWidget ();
+}
+
/**
* Removes the listener from the collection of listeners who will
* be notified when the receiver's selection changes.
@@ -517,32 +517,32 @@ void releaseWidget () {
* @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;
-}
-
+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.
@@ -556,50 +556,50 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setSelection (int index) {
- checkWidget();
- 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);
- }
- }
-}
-
+public void setSelection (int index) {
+ checkWidget();
+ 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 be the given array of items.
* The current selected is first cleared, then the new items are
@@ -612,39 +612,39 @@ void setSelection (int index, boolean notify) {
* <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);
- return;
- }
- for (int i=items.length-1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) setSelection (index);
- }
-}
-
-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 ();
-}
-
-}
+public void setSelection (TabItem [] items) {
+ checkWidget();
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (items.length == 0) {
+ setSelection (-1);
+ return;
+ }
+ for (int i=items.length-1; i>=0; --i) {
+ int index = indexOf (items [i]);
+ if (index != -1) setSelection (index);
+ }
+}
+
+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
index 3b4e125e97..0a9ffda9d3 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -25,11 +25,11 @@ import org.eclipse.swt.graphics.*;
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
-public class TabItem extends Item {
- TabFolder parent;
- Control control;
- String toolTipText;
-
+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
@@ -60,10 +60,10 @@ public class TabItem extends Item {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public TabItem (TabFolder parent, int style) {
- this(parent, style, parent.getItemCount ());
-}
-
+public TabItem (TabFolder parent, int style) {
+ this(parent, style, parent.getItemCount ());
+}
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>TabFolder</code>), a style value
@@ -95,16 +95,16 @@ public TabItem (TabFolder parent, int style) {
* @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);
-}
-
+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);
+}
+
/**
* Returns the control that is used to fill the client area of
* the tab folder when the user selects the tab item. If no
@@ -117,17 +117,17 @@ protected void checkSubclass () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Control getControl () {
- checkWidget();
- return control;
-}
-
-public Display getDisplay () {
- TabFolder parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+public Control getControl () {
+ checkWidget();
+ return control;
+}
+
+public Display getDisplay () {
+ TabFolder parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns the receiver's parent, which must be a <code>TabFolder</code>.
*
@@ -138,11 +138,11 @@ public Display getDisplay () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public TabFolder getParent () {
- checkWidget();
- return parent;
-}
-
+public TabFolder getParent () {
+ checkWidget();
+ return parent;
+}
+
/**
* Returns the receiver's tool tip text, or null if it has
* not been set.
@@ -154,27 +154,27 @@ public TabFolder getParent () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
-void releaseChild () {
- super.releaseChild ();
- int index = parent.indexOf (this);
- if (index == parent.getSelectionIndex ()) {
- if (control != null) control.setVisible (false);
- }
- parent.destroyItem (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- control = null;
- parent = null;
- toolTipText = null;
-}
-
+public String getToolTipText () {
+ checkWidget();
+ return toolTipText;
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ int index = parent.indexOf (this);
+ if (index == parent.getSelectionIndex ()) {
+ if (control != null) control.setVisible (false);
+ }
+ parent.destroyItem (this);
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ control = null;
+ parent = 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.
@@ -190,65 +190,65 @@ void releaseWidget () {
* <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
-}
-
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- 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];
- byte [] buffer = Converter.wcsToMbcs (null, stripMnemonics (string), true);
- 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);
-}
-
+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
+}
+
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ super.setText (string);
+ 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];
+ byte [] buffer = Converter.wcsToMbcs (null, stripMnemonics (string), true);
+ 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.
@@ -260,9 +260,9 @@ public void setText (String string) {
* <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;
-}
-
-}
+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
index e2d67ff41d..af858421d7 100755
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -29,25 +29,25 @@ import org.eclipse.swt.events.*;
* 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;
-
- public static final int LIMIT;
- 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";
- }
-
+public class Text extends Scrollable {
+ char echoCharacter;
+ boolean ignoreChange;
+ String hiddenText;
+ int tabs, lastModifiedText;
+ PtTextCallback_t textVerify;
+
+ public static final int LIMIT;
+ 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";
+ }
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -79,65 +79,65 @@ public class Text extends Scrollable {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-static int checkStyle (int style) {
- 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;
- 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);
-}
+public Text (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+
+static int checkStyle (int style) {
+ 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;
+ 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.
*
@@ -146,56 +146,56 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
* <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;
- Display display = getDisplay ();
- 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);
-}
-
+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;
+ Display display = getDisplay ();
+ 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);
+}
+
/**
* Adds the listener to the collection of listeners who will
* be notified when the receiver's text is modified, by sending
@@ -215,13 +215,13 @@ void createWidget (int index) {
* @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);
-}
-
+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
@@ -246,14 +246,14 @@ public void addModifyListener (ModifyListener listener) {
* @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 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
@@ -273,13 +273,13 @@ public void addSelectionListener (SelectionListener listener) {
* @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);
-}
-
+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>
@@ -297,13 +297,13 @@ public void addVerifyListener (VerifyListener listener) {
* <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);
-}
-
+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>
@@ -315,19 +315,19 @@ public void append (String string) {
* <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);
-}
-
+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>
@@ -343,46 +343,46 @@ public void copy () {
* <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 () {
- Display display = getDisplay ();
- return display.TEXT_BACKGROUND;
-}
-
-int defaultForeground () {
- Display display = getDisplay ();
- return display.TEXT_FOREGROUND;
-}
-
+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 () {
+ Display display = getDisplay ();
+ return display.TEXT_BACKGROUND;
+}
+
+int defaultForeground () {
+ Display display = getDisplay ();
+ return display.TEXT_FOREGROUND;
+}
+
/**
* Gets the line number of the caret.
* <p>
@@ -399,12 +399,12 @@ int defaultForeground () {
* <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;
-}
-
+public int getCaretLineNumber () {
+ checkWidget();
+ //NOT DONE - NOT NEEDED
+ return 0;
+}
+
/**
* Gets the location the caret.
* <p>
@@ -418,12 +418,12 @@ public int getCaretLineNumber () {
* <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;
-}
-
+public Point getCaretLocation () {
+ checkWidget();
+ //NOT DONE - NOT NEEDED
+ return null;
+}
+
/**
* Gets the position of the caret.
* <p>
@@ -437,13 +437,13 @@ public Point getCaretLocation () {
* <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];
-}
-
+public int getCaretPosition () {
+ checkWidget();
+ int [] args = {OS.Pt_ARG_CURSOR_POSITION, 0, 0};
+ OS.PtGetResources (handle, args.length / 3, args);
+ return args [1];
+}
+
/**
* Gets the number of characters.
*
@@ -454,14 +454,14 @@ public int getCaretPosition () {
* <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]);
-}
-
+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]);
+}
+
/**
* Gets the double click enabled flag.
* <p>
@@ -475,12 +475,12 @@ public int getCharCount () {
* <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;
-}
-
+public boolean getDoubleClickEnabled () {
+ checkWidget();
+ //NOT DONE - NOT NEEDED
+ return false;
+}
+
/**
* Gets the echo character.
* <p>
@@ -494,11 +494,11 @@ public boolean getDoubleClickEnabled () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public char getEchoChar () {
- checkWidget();
- return echoCharacter;
-}
-
+public char getEchoChar () {
+ checkWidget();
+ return echoCharacter;
+}
+
/**
* Gets the editable state.
*
@@ -507,13 +507,13 @@ public char getEchoChar () {
* <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;
-}
-
+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;
+}
+
/**
* Gets the number of lines.
*
@@ -524,14 +524,14 @@ public boolean getEditable () {
* <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];
-}
-
+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];
+}
+
/**
* Gets the line delimiter.
*
@@ -542,11 +542,11 @@ public int getLineCount () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public String getLineDelimiter () {
- checkWidget();
- return "\n";
-}
-
+public String getLineDelimiter () {
+ checkWidget();
+ return "\n";
+}
+
/**
* Gets the height of a line.
*
@@ -557,39 +557,39 @@ public String getLineDelimiter () {
* <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));
-}
-
+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));
+}
+
/**
* Gets the position of the selected text.
* <p>
@@ -605,21 +605,21 @@ String getNameText () {
* <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]);
-}
-
+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]);
+}
+
/**
* Gets the number of selected characters.
*
@@ -630,12 +630,12 @@ public Point getSelection () {
* <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;
-}
-
+public int getSelectionCount () {
+ checkWidget();
+ Point selection = getSelection ();
+ return selection.y - selection.x;
+}
+
/**
* Gets the selected text.
*
@@ -646,17 +646,17 @@ public int getSelectionCount () {
* <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);
-}
-
+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);
+}
+
/**
* Gets the number of tabs.
* <p>
@@ -672,23 +672,23 @@ public String getSelectionText () {
* <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;
-}
-
+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;
+}
+
/**
* Gets a range of text.
* <p>
@@ -706,17 +706,17 @@ int getTabWidth (int tabs) {
* <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();
- /*
- * NOTE: The current implementation uses substring ()
- * which can reference a potentially large character
- * array.
- */
- //NOT DONE - use OS in SINGLE text
- return getText ().substring (start, end + 1);
-}
-
+public String getText (int start, int end) {
+ checkWidget();
+ /*
+ * NOTE: The current implementation uses substring ()
+ * which can reference a potentially large character
+ * array.
+ */
+ //NOT DONE - use OS in SINGLE text
+ return getText ().substring (start, end + 1);
+}
+
/**
* Gets the widget text.
* <p>
@@ -730,19 +730,19 @@ public String getText (int start, int end) {
* <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);
-}
-
+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>
@@ -757,13 +757,13 @@ public String getText () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-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];
-}
-
+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.
@@ -778,14 +778,14 @@ public int getTextLimit () {
* <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;
-}
-
+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;
+}
+
/**
* Gets the top pixel.
* <p>
@@ -806,19 +806,19 @@ public int getTopIndex () {
* <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 = getDisplay ().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);
-}
-
+public int getTopPixel () {
+ checkWidget();
+ //NOT DONE - NOT NEEDED
+ return 0;
+}
+
+void hookEvents () {
+ super.hookEvents ();
+ int windowProc = getDisplay ().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>
@@ -832,20 +832,20 @@ void hookEvents () {
* <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);
-}
-
+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>
@@ -858,136 +858,136 @@ public void insert (String string) {
* <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 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, 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, 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;
-}
-
+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_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, 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, 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.
@@ -1005,13 +1005,13 @@ void releaseWidget () {
* @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);
-}
-
+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.
@@ -1029,14 +1029,14 @@ public void removeModifyListener (ModifyListener listener) {
* @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 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.
@@ -1054,13 +1054,13 @@ public void removeSelectionListener (SelectionListener listener) {
* @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);
-}
-
+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.
*
@@ -1069,11 +1069,11 @@ public void removeVerifyListener (VerifyListener listener) {
* <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});
-}
-
+public void selectAll () {
+ checkWidget();
+ OS.PtTextSetSelection (handle, new int [] {0}, new int [] {0x7FFFFFFF});
+}
+
/**
* Sets the echo character.
* <p>
@@ -1094,25 +1094,25 @@ public void selectAll () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setEchoChar (char echo) {
- checkWidget();
- if (echoCharacter == echo) return;
- String newText;
- if (echo == 0) {
- newText = hiddenText;
- hiddenText = null;
- } else {
- newText = hiddenText = getText();
- }
- echoCharacter = echo;
- Point selection = getSelection();
- boolean oldValue = ignoreChange;
- ignoreChange = true;
- setText(newText);
- setSelection(selection.x, selection.y);
- ignoreChange = oldValue;
-}
-
+public void setEchoChar (char echo) {
+ checkWidget();
+ if (echoCharacter == echo) return;
+ String newText;
+ if (echo == 0) {
+ newText = hiddenText;
+ hiddenText = null;
+ } 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>
@@ -1128,11 +1128,11 @@ public void setEchoChar (char echo) {
* <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
-}
-
+public void setDoubleClickEnabled (boolean doubleClick) {
+ checkWidget();
+ //NOT DONE - NOT NEEDED
+}
+
/**
* Sets the editable state.
*
@@ -1143,19 +1143,19 @@ public void setDoubleClickEnabled (boolean doubleClick) {
* <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);
-}
-
+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 selection.
* <p>
@@ -1179,22 +1179,22 @@ public void setFont (Font font) {
* <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);
- }
-}
-
+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.
* <p>
@@ -1221,12 +1221,12 @@ public void setSelection (int position) {
* <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);
-}
-
+public void setSelection (Point selection) {
+ checkWidget();
+ if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
+ setSelection (selection.x, selection.y);
+}
+
/**
* Sets the selection.
* <p>
@@ -1251,21 +1251,21 @@ public void setSelection (Point selection) {
* <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);
- }
-}
-
+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>
@@ -1282,21 +1282,21 @@ public void setSelection (int start, int end) {
* <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);
-}
-
+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
@@ -1312,16 +1312,16 @@ void setTabStops (int tabs) {
* <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);
-}
-
+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.
@@ -1342,12 +1342,12 @@ public void setText (String string) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-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);
-}
-
+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
@@ -1360,12 +1360,12 @@ public void setTextLimit (int limit) {
* <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);
-}
-
+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>
@@ -1382,37 +1382,37 @@ public void setTopIndex (int index) {
* <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 ();
-}
-
-}
+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
index 5ca0f9ee5a..9e2df2bba7 100755
--- 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
@@ -1,16 +1,16 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -34,12 +34,12 @@ import org.eclipse.swt.graphics.*;
* 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;
-
+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.
@@ -72,128 +72,128 @@ public class ToolBar extends Composite {
* @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);
-}
-
-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;
- Display display = getDisplay ();
- 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 ();
-}
-
+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);
+}
+
+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;
+ Display display = getDisplay ();
+ 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.
*
@@ -204,11 +204,11 @@ public boolean forceFocus () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-
+public int getItemCount () {
+ checkWidget();
+ return itemCount;
+}
+
/**
* Returns an array of <code>TabItem</code>s which are the items
* in the receiver.
@@ -225,13 +225,13 @@ public int getItemCount () {
* <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;
-}
-
+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.
@@ -247,13 +247,13 @@ public ToolItem [] getItems () {
* <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 = itemCount;
- if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
- return items [index];
-}
-
+public ToolItem getItem (int index) {
+ checkWidget();
+ int count = itemCount;
+ if (!(0 <= index && index < count)) 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
@@ -270,15 +270,15 @@ public ToolItem getItem (int index) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public ToolItem getItem (Point pt) {
- checkWidget();
- for (int i=0; i<itemCount; i++) {
- Rectangle rect = items [i].getBounds ();
- if (rect.contains (pt)) return items [i];
- }
- return null;
-}
-
+public ToolItem getItem (Point pt) {
+ checkWidget();
+ 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
@@ -292,19 +292,19 @@ public ToolItem getItem (Point pt) {
* <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();
-}
-
+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
@@ -323,130 +323,130 @@ boolean hasFocus () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public int indexOf (ToolItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- int count = itemCount;
- for (int i=0; i<count; 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 releaseWidget () {
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null && !item.isDisposed ()) item.releaseResources ();
- }
- items = null;
- super.releaseWidget ();
-}
-
-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);
+public int indexOf (ToolItem item) {
+ checkWidget();
+ if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ int count = itemCount;
+ for (int i=0; i<count; 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 releaseWidget () {
+ for (int i=0; i<items.length; i++) {
+ ToolItem item = items [i];
+ if (item != null && !item.isDisposed ()) item.releaseResources ();
+ }
+ items = null;
+ super.releaseWidget ();
+}
+
+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 ();
-}
-
-}
+ }
+}
+
+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
index f5bbacca2a..0d204e2885 100755
--- 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
@@ -1,18 +1,18 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
@@ -29,14 +29,14 @@ import org.eclipse.swt.events.*;
* 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;
-
+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
@@ -71,10 +71,10 @@ public class ToolItem extends Item {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public ToolItem (ToolBar parent, int style) {
- this(parent, style, parent.getItemCount ());
-}
-
+public ToolItem (ToolBar parent, int style) {
+ this(parent, style, parent.getItemCount ());
+}
+
/**
* Constructs a new instance of this class given its parent
* (which must be a <code>ToolBar</code>), a style value
@@ -110,12 +110,12 @@ public ToolItem (ToolBar parent, int style) {
* @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);
-}
-
+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
@@ -141,134 +141,134 @@ public ToolItem (ToolBar parent, int style, int index) {
* @see #removeSelectionListener
* @see SelectionEvent
*/
-public void addSelectionListener(SelectionListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Selection,typedListener);
- addListener (SWT.DefaultSelection,typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-int 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);
- }
-}
-
+public void addSelectionListener(SelectionListener listener) {
+ checkWidget();
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Selection,typedListener);
+ addListener (SWT.DefaultSelection,typedListener);
+}
+
+static int checkStyle (int style) {
+ return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
+}
+
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+
+int 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);
+ }
+}
+
/**
* Returns a rectangle describing the receiver's size and location
* relative to its parent.
@@ -280,14 +280,14 @@ void deregister () {
* <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);
-}
-
+public Rectangle getBounds () {
+ checkWidget();
+ int topHandle = topHandle ();
+ PhArea_t area = new PhArea_t ();
+ OS.PtWidgetArea (topHandle, area);
+ return new Rectangle (area.pos_x, area.pos_y, area.size_w, area.size_h);
+}
+
/**
* Returns the control that is used to fill the bounds of
* the item when the items is a <code>SEPARATOR</code>.
@@ -299,11 +299,11 @@ public Rectangle getBounds () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Control getControl () {
- checkWidget();
- return control;
-}
-
+public Control getControl () {
+ checkWidget();
+ return control;
+}
+
/**
* Returns the receiver's disabled image if it has one, or null
* if it does not.
@@ -318,17 +318,17 @@ public Control getControl () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Image getDisabledImage () {
- checkWidget();
- return disabledImage;
-}
-
-public Display getDisplay () {
- ToolBar parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
+public Image getDisabledImage () {
+ checkWidget();
+ return disabledImage;
+}
+
+public Display getDisplay () {
+ ToolBar parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
/**
* Returns <code>true</code> if the receiver is enabled, and
* <code>false</code> otherwise.
@@ -344,12 +344,12 @@ public Display getDisplay () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public boolean getEnabled () {
- checkWidget ();
- int topHandle = topHandle ();
- return (OS.PtWidgetFlags (topHandle) & OS.Pt_BLOCKED) == 0;
-}
-
+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.
@@ -364,11 +364,11 @@ public boolean getEnabled () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public Image getHotImage () {
- checkWidget();
- return hotImage;
-}
-
+public Image getHotImage () {
+ checkWidget();
+ return hotImage;
+}
+
/**
* Returns the receiver's parent, which must be a <code>ToolBar</code>.
*
@@ -379,11 +379,11 @@ public Image getHotImage () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public ToolBar getParent () {
- checkWidget();
- return parent;
-}
-
+public ToolBar getParent () {
+ checkWidget();
+ return parent;
+}
+
/**
* Returns <code>true</code> if the receiver is selected,
* and false otherwise.
@@ -401,12 +401,12 @@ public ToolBar getParent () {
* <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;
-}
-
+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.
*
@@ -417,11 +417,11 @@ public boolean getSelection () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-
+public String getToolTipText () {
+ checkWidget();
+ return toolTipText;
+}
+
/**
* Gets the width of the receiver.
*
@@ -432,130 +432,130 @@ public String getToolTipText () {
* <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 = getDisplay ().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);
-}
-
-/**
- * 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 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 = getDisplay ().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);
+}
+
+/**
+ * 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 releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- arrow = button = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (toolTipHandle != 0) destroyToolTip (toolTipHandle);
- if (parent.lastFocus == this) parent.lastFocus = null;
- toolTipHandle = 0;
- parent = null;
- control = null;
- hotImage = null;
- disabledImage = null;
- toolTipText = null;
-}
-
+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 releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+
+void releaseHandle () {
+ super.releaseHandle ();
+ arrow = button = 0;
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ if (toolTipHandle != 0) destroyToolTip (toolTipHandle);
+ if (parent.lastFocus == this) parent.lastFocus = null;
+ toolTipHandle = 0;
+ parent = null;
+ 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.
@@ -573,33 +573,33 @@ void releaseWidget () {
* @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);
- }
-}
-
+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 items is a <code>SEPARATOR</code>.
@@ -615,29 +615,29 @@ void setBackgroundPixel (int pixel) {
* <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 () {
- Display display = getDisplay ();
- if (display.defaultFont != null) setFont (parent.defaultFont ());
-}
-
+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 () {
+ Display display = getDisplay ();
+ 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.
@@ -655,13 +655,13 @@ void setDefaultFont () {
* <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;
-}
-
+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.
@@ -678,62 +678,62 @@ public void setDisabledImage (Image image) {
* <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);
- }
-}
-
+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.
@@ -751,62 +751,62 @@ void setForegroundPixel (int pixel) {
* <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;
-}
-
+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>
@@ -822,42 +822,42 @@ boolean setRadioSelection (boolean value) {
* <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);
-}
-
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setText (string);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int ptr = OS.malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- int type = OS.Pt_Z_STRING;
- if (image != null) type = OS.Pt_TEXT_IMAGE;
- int [] args = {
- OS.Pt_ARG_TEXT_STRING, ptr, 0,
- OS.Pt_ARG_LABEL_TYPE, type, 0,
- };
- OS.PtSetResources (button, args.length / 3, args);
- if (ptr != 0) OS.free (ptr);
-
- /*
- * 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);
- }
- }
-}
-
+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);
+}
+
+public void setText (String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.SEPARATOR) != 0) return;
+ super.setText (string);
+ byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ int ptr = OS.malloc (buffer.length);
+ OS.memmove (ptr, buffer, buffer.length);
+ int type = OS.Pt_Z_STRING;
+ if (image != null) type = OS.Pt_TEXT_IMAGE;
+ int [] args = {
+ OS.Pt_ARG_TEXT_STRING, ptr, 0,
+ OS.Pt_ARG_LABEL_TYPE, type, 0,
+ };
+ OS.PtSetResources (button, args.length / 3, args);
+ if (ptr != 0) OS.free (ptr);
+
+ /*
+ * 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.
@@ -869,11 +869,11 @@ public void setText (String string) {
* <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;
-}
-
+public void setToolTipText (String string) {
+ checkWidget();
+ toolTipText = string;
+}
+
/**
* Sets the width of the receiver.
*
@@ -884,14 +884,14 @@ public void setToolTipText (String string) {
* <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 ());
- }
-}
-}
+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
index c9d24acbf3..5778890e61 100755
--- 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
@@ -1,50 +1,50 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- Display display;
- boolean tracking, stippled;
- Rectangle [] rectangles, proportions;
- 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;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+ Display display;
+ boolean tracking, stippled;
+ Rectangle [] rectangles, proportions;
+ 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
@@ -79,16 +79,16 @@ public class Tracker extends Widget {
* @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;
-}
-
+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.
@@ -121,12 +121,12 @@ public Tracker (Display display, int style) {
* @see Widget#checkSubclass
* @see Widget#getStyle
*/
-public Tracker (Composite parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- display = parent.getDisplay ();
-}
-
+public Tracker (Composite parent, int style) {
+ super (parent, checkStyle (style));
+ this.parent = parent;
+ display = parent.getDisplay ();
+}
+
/**
* Adds the listener to the collection of listeners who will
* be notified when the control is moved or resized, by sending
@@ -146,212 +146,212 @@ public Tracker (Composite parent, int style) {
* @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.Move,typedListener);
-}
-
-Point adjustMoveCursor () {
- Rectangle bounds = computeBounds ();
- 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;
- Rectangle bounds = computeBounds ();
-
- 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];
- Rectangle bounds = computeBounds ();
- for (int i = 0; i < rects.length; i++) {
- result[i] = new Rectangle (
- (rects[i].x - bounds.x) * 100 / bounds.width,
- (rects[i].y - bounds.y) * 100 / bounds.height,
- rects[i].width * 100 / bounds.width,
- rects[i].height * 100 / bounds.height);
- }
- return result;
-}
-
-void drawRectangles (Rectangle [] rects) {
- if (parent != null) {
- if (parent.isDisposed ()) return;
- parent.getShell ().update ();
- } else {
- display.update ();
- }
- 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_DRAWMODE_XOR);
- 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);
-}
-
-public Display getDisplay () {
- return display;
-}
-
-/**
- * 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 void addControlListener(ControlListener listener) {
+ checkWidget();
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Move,typedListener);
+}
+
+Point adjustMoveCursor () {
+ Rectangle bounds = computeBounds ();
+ 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;
+ Rectangle bounds = computeBounds ();
+
+ 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];
+ Rectangle bounds = computeBounds ();
+ for (int i = 0; i < rects.length; i++) {
+ result[i] = new Rectangle (
+ (rects[i].x - bounds.x) * 100 / bounds.width,
+ (rects[i].y - bounds.y) * 100 / bounds.height,
+ rects[i].width * 100 / bounds.width,
+ rects[i].height * 100 / bounds.height);
+ }
+ return result;
+}
+
+void drawRectangles (Rectangle [] rects) {
+ if (parent != null) {
+ if (parent.isDisposed ()) return;
+ parent.getShell ().update ();
+ } else {
+ display.update ();
+ }
+ 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_DRAWMODE_XOR);
+ 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);
+}
+
+public Display getDisplay () {
+ return display;
+}
+
+/**
+ * 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();
- return rectangles;
-}
-
+public Rectangle [] getRectangles () {
+ checkWidget();
+ return rectangles;
+}
+
/**
* Returns <code>true</code> if the rectangles are drawn with a stippled line, <code>false</code> otherwise.
*
@@ -362,230 +362,230 @@ public Rectangle [] getRectangles () {
* <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)) return;
- if (xChange > 0 && ((style & SWT.RIGHT) == 0)) return;
- if (yChange < 0 && ((style & SWT.UP) == 0)) return;
- if (yChange > 0 && ((style & SWT.DOWN) == 0)) return;
- Rectangle bounds = computeBounds ();
- 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;
-
- drawRectangles (rectangles);
- 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) {
- drawRectangles (rectangles);
- event.x = newX;
- event.y = newY;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (newX - oldX, newY - oldY);
- cursorPos = adjustResizeCursor ();
- newX = cursorPos.x; newY = cursorPos.y;
- sendEvent (SWT.Resize, event);
- } 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 ()) return false;
- drawRectangles (rectangles);
- 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) {
- drawRectangles (rectangles);
- int newX = oldX + xChange;
- int newY = oldY + yChange;
- event.x = newX;
- event.y = newY;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (xChange, yChange);
- cursorPos = adjustResizeCursor ();
- sendEvent (SWT.Resize, event);
- } else {
- moveRectangles (xChange, yChange);
- cursorPos = adjustMoveCursor ();
- 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 ()) return false;
- drawRectangles (rectangles);
- 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);
- }
- drawRectangles (rectangles);
- tracking = false;
- if (region != 0) OS.PtDestroyWidget (region);
- return !cancelled;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- display = null;
- rectangles = null;
-}
-
+public boolean getStippled () {
+ checkWidget();
+ return stippled;
+}
+
+void moveRectangles (int xChange, int yChange) {
+ if (xChange < 0 && ((style & SWT.LEFT) == 0)) return;
+ if (xChange > 0 && ((style & SWT.RIGHT) == 0)) return;
+ if (yChange < 0 && ((style & SWT.UP) == 0)) return;
+ if (yChange > 0 && ((style & SWT.DOWN) == 0)) return;
+ Rectangle bounds = computeBounds ();
+ 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;
+
+ drawRectangles (rectangles);
+ 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) {
+ drawRectangles (rectangles);
+ event.x = newX;
+ event.y = newY;
+ if ((style & SWT.RESIZE) != 0) {
+ resizeRectangles (newX - oldX, newY - oldY);
+ cursorPos = adjustResizeCursor ();
+ newX = cursorPos.x; newY = cursorPos.y;
+ sendEvent (SWT.Resize, event);
+ } 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 ()) return false;
+ drawRectangles (rectangles);
+ 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) {
+ drawRectangles (rectangles);
+ int newX = oldX + xChange;
+ int newY = oldY + yChange;
+ event.x = newX;
+ event.y = newY;
+ if ((style & SWT.RESIZE) != 0) {
+ resizeRectangles (xChange, yChange);
+ cursorPos = adjustResizeCursor ();
+ sendEvent (SWT.Resize, event);
+ } else {
+ moveRectangles (xChange, yChange);
+ cursorPos = adjustMoveCursor ();
+ 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 ()) return false;
+ drawRectangles (rectangles);
+ 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);
+ }
+ drawRectangles (rectangles);
+ 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.
@@ -603,109 +603,109 @@ void releaseWidget () {
* @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);
-}
-
-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;
- } else if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
- cursorOrientation |= SWT.RIGHT;
- } else if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
- cursorOrientation |= SWT.UP;
- } else if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
- cursorOrientation |= SWT.DOWN;
- }
- Rectangle bounds = computeBounds ();
- 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;
- }
- /*
- * The following are conditions under which the resize should not be applied
- */
- if (bounds.width < 0 || bounds.height < 0) return;
-
- 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);
- }
-}
-
+public void removeControlListener (ControlListener listener) {
+ checkWidget();
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) return;
+ eventTable.unhook (SWT.Move, 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;
+ } else if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
+ cursorOrientation |= SWT.RIGHT;
+ } else if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
+ cursorOrientation |= SWT.UP;
+ } else if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
+ cursorOrientation |= SWT.DOWN;
+ }
+ Rectangle bounds = computeBounds ();
+ 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;
+ }
+ /*
+ * The following are conditions under which the resize should not be applied
+ */
+ if (bounds.width < 0 || bounds.height < 0) return;
+
+ 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.
@@ -717,13 +717,13 @@ void setCursor (int cursorHandle) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void setRectangles (Rectangle [] rectangles) {
- checkWidget();
- if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles = rectangles;
- proportions = computeProportions (rectangles);
-}
-
+public void setRectangles (Rectangle [] rectangles) {
+ checkWidget();
+ if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
+ this.rectangles = rectangles;
+ proportions = computeProportions (rectangles);
+}
+
/**
* Changes the appearance of the line used to draw the rectangles.
*
@@ -734,9 +734,9 @@ public void setRectangles (Rectangle [] rectangles) {
* <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;
-}
-
-}
+public void setStippled (boolean stippled) {
+ checkWidget();
+ this.stippled = stippled;
+}
+
+}
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
index b880163253..48e196d1d6 100755
--- 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
@@ -1,17 +1,17 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.photon.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
@@ -38,40 +38,40 @@ import org.eclipse.swt.events.*;
*
* @see #checkSubclass
*/
-public abstract class Widget {
- public int handle;
- int style, state;
- EventTable eventTable;
- Object data;
- String [] keys;
- Object [] values;
-
- /* Global state flags */
-// static final int AUTOMATIC = 1 << 0;
-// static final int ACTIVE = 1 << 1;
- static final int GRAB = 1 << 2;
-// static final int MULTIEXPOSE = 1 << 3;
-// static final int RESIZEREDRAW = 1 << 4;
-// static final int WRAP = 1 << 5;
- static final int DISABLED = 1 << 6;
-// static final int HIDDEN = 1 << 7;
-// static final int FOREGROUND = 1 << 8;
-// static final int BACKGROUND = 1 << 9;
- static final int DISPOSED = 1 << 10;
- static final int HANDLE = 1 << 11;
- static final int CANVAS = 1 << 12;
- static final int MOVED = 1 << 13;
- static final int RESIZED = 1 << 14;
-
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
- static final char Mnemonic = '&';
-
-Widget () {
- /* Do nothing */
-}
-
+public abstract class Widget {
+ public int handle;
+ int style, state;
+ EventTable eventTable;
+ Object data;
+ String [] keys;
+ Object [] values;
+
+ /* Global state flags */
+// static final int AUTOMATIC = 1 << 0;
+// static final int ACTIVE = 1 << 1;
+ static final int GRAB = 1 << 2;
+// static final int MULTIEXPOSE = 1 << 3;
+// static final int RESIZEREDRAW = 1 << 4;
+// static final int WRAP = 1 << 5;
+ static final int DISABLED = 1 << 6;
+// static final int HIDDEN = 1 << 7;
+// static final int FOREGROUND = 1 << 8;
+// static final int BACKGROUND = 1 << 9;
+ static final int DISPOSED = 1 << 10;
+ static final int HANDLE = 1 << 11;
+ static final int CANVAS = 1 << 12;
+ static final int MOVED = 1 << 13;
+ static final int RESIZED = 1 << 14;
+
+ static final int DEFAULT_WIDTH = 64;
+ static final int DEFAULT_HEIGHT = 64;
+
+ static final char Mnemonic = '&';
+
+Widget () {
+ /* Do nothing */
+}
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -100,156 +100,156 @@ Widget () {
* @see #checkSubclass
* @see #getStyle
*/
-public Widget (Widget parent, int style) {
- checkSubclass ();
- checkParent (parent);
- this.style = style;
-}
-
-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;
-}
-
-/**
- * Returns the provided string without mnemonic indicators.
- *
- * @param string the string to demangle
- */
-static String stripMnemonics (String string) {
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- int j = 0;
- for (int i = 0; i < text.length;) {
- if ((text[j++] = text[i++]) == Mnemonic) {
- if (i != text.length) {
- if (text[i] == Mnemonic) i++; else j--;
- }
- }
- }
- return new String(text, 0, j);
-}
-
-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.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (parent.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) 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;
-}
-
+public Widget (Widget parent, int style) {
+ checkSubclass ();
+ checkParent (parent);
+ this.style = style;
+}
+
+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;
+}
+
+/**
+ * Returns the provided string without mnemonic indicators.
+ *
+ * @param string the string to demangle
+ */
+static String stripMnemonics (String string) {
+ char [] text = new char [string.length ()];
+ string.getChars (0, text.length, text, 0);
+ int j = 0;
+ for (int i = 0; i < text.length;) {
+ if ((text[j++] = text[i++]) == Mnemonic) {
+ if (i != text.length) {
+ if (text[i] == Mnemonic) i++; else j--;
+ }
+ }
+ }
+ return new String(text, 0, j);
+}
+
+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.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (parent.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+}
+
+/**
+ * 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 () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (isDisposed ()) 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 notifed when an event of the given type occurs. When the
@@ -270,13 +270,13 @@ int copyPhImage(int image) {
* @see Listener
* @see #removeListener
*/
-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);
-}
-
+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 notifed when the widget is disposed. When the widget is
@@ -296,81 +296,81 @@ public void addListener (int eventType, Listener handler) {
* @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 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);
- Display display = getDisplay ();
- 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);
- }
-}
-
+public void addDisposeListener (DisposeListener listener) {
+ checkWidget();
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Dispose, typedListener);
+}
+
+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);
+ Display display = getDisplay ();
+ 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
@@ -394,31 +394,31 @@ void destroyWidget () {
* @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);
- releaseChild ();
- releaseWidget ();
- destroyWidget ();
-}
-
-int drawProc (int widget, int damage) {
- return OS.Pt_CONTINUE;
-}
-
-static void error (int code) {
- SWT.error(code);
-}
-
-boolean filters (int eventType) {
- Display display = getDisplay ();
- return display.filters (eventType);
-}
-
+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);
+ releaseChild ();
+ releaseWidget ();
+ destroyWidget ();
+}
+
+int drawProc (int widget, int damage) {
+ return OS.Pt_CONTINUE;
+}
+
+static void error (int code) {
+ SWT.error(code);
+}
+
+boolean filters (int eventType) {
+ Display display = getDisplay ();
+ return display.filters (eventType);
+}
+
/**
* Returns the application defined widget data associated
* with the receiver, or null if it has not been set. The
@@ -441,11 +441,11 @@ boolean filters (int eventType) {
*
* @see #setData
*/
-public Object getData () {
- checkWidget();
- return data;
-}
-
+public Object getData () {
+ checkWidget();
+ return data;
+}
+
/**
* Returns the application defined property of the receiver
* with the specified name, or null if it has not been set.
@@ -470,16 +470,16 @@ public Object getData () {
*
* @see #setData
*/
-public Object getData (String key) {
- checkWidget();
- 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;
-}
-
+public Object getData (String key) {
+ checkWidget();
+ 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 <code>Display</code> that is associated with
* the receiver.
@@ -496,19 +496,19 @@ public Object getData (String key) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public abstract Display getDisplay ();
-
-String getName () {
- String string = getClass ().getName ();
- int index = string.length ();
- while (--index > 0 && string.charAt (index) != '.');
- return string.substring (index + 1, string.length ());
-}
-
-String getNameText () {
- return "";
-}
-
+public abstract Display getDisplay ();
+
+String getName () {
+ 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>
@@ -529,24 +529,24 @@ String getNameText () {
* <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 */
-}
-
+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.
@@ -558,25 +558,25 @@ void hookEvents () {
*
* @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 ());
-}
-
-protected boolean isListening (int eventType) {
- checkWidget();
- return hooks (eventType);
-}
-
-boolean isValidThread () {
- return getDisplay ().isValidThread ();
-}
-
+public boolean isDisposed () {
+ if (handle != 0) return false;
+ if ((state & HANDLE) != 0) return true;
+ return (state & DISPOSED) != 0;
+}
+
+boolean isValidSubclass () {
+ return Display.isValidClass (getClass ());
+}
+
+protected 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
@@ -593,136 +593,136 @@ boolean isValidThread () {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
-public void notifyListeners (int eventType, Event event) {
- checkWidget();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- 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_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 releaseChild () {
- /* Do nothing */
-}
-
-void register () {
- if (handle == 0) return;
- WidgetTable.put (handle, this);
-}
-
-void releaseHandle () {
- handle = 0;
- state |= DISPOSED;
-}
-
-void releaseResources () {
- releaseWidget ();
- releaseHandle ();
-}
-
-void releaseWidget () {
- sendEvent (SWT.Dispose);
- deregister ();
- eventTable = null;
- data = null;
- keys = null;
- values = null;
-}
-
+public void notifyListeners (int eventType, Event event) {
+ checkWidget();
+ if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
+ 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_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 releaseChild () {
+ /* Do nothing */
+}
+
+void register () {
+ if (handle == 0) return;
+ WidgetTable.put (handle, this);
+}
+
+void releaseHandle () {
+ handle = 0;
+ state |= DISPOSED;
+}
+
+void releaseResources () {
+ releaseWidget ();
+ releaseHandle ();
+}
+
+void releaseWidget () {
+ sendEvent (SWT.Dispose);
+ deregister ();
+ eventTable = null;
+ data = null;
+ keys = null;
+ values = null;
+}
+
/**
* Removes the listener from the collection of listeners who will
* be notifed when an event of the given type occurs.
@@ -741,44 +741,44 @@ void releaseWidget () {
* @see Listener
* @see #addListener
*/
-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 notifed 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);
-}
-
+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 notifed 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 notifed when the widget is disposed.
@@ -796,80 +796,80 @@ protected void removeListener (int eventType, SWTEventListener handler) {
* @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) {
- Display display = getDisplay ();
- 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, SWT.Activate, display.windowProc);
- }
- 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) {
- Display display = getDisplay ();
- 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);
- }
-}
-
+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) {
+ Display display = getDisplay ();
+ 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, SWT.Activate, display.windowProc);
+ }
+ 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) {
+ Display display = getDisplay ();
+ 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
@@ -890,11 +890,11 @@ void sendEvent (int eventType, Event event, boolean send) {
* <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
* </ul>
*/
-public void setData (Object data) {
- checkWidget();
- this.data = data;
-}
-
+public void setData (Object data) {
+ checkWidget();
+ this.data = data;
+}
+
/**
* Sets the application defined property of the receiver
* with the specified name to the given value.
@@ -919,185 +919,185 @@ public void setData (Object data) {
*
* @see #getData
*/
-public void setData (String key, Object value) {
- checkWidget();
- 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;
-}
-
-void setInputState(Event event, 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;
-}
-
-void setKeyState(Event event, PhKeyEvent_t ke) {
- /*
- * 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 = 0;
- if ((ke.key_flags & OS.Pk_KF_Sym_Valid) != 0) {
- key = ke.key_sym;
- } else if ((ke.key_flags & OS.Pk_KF_Cap_Valid) != 0) {
- if ((ke.key_flags & (OS.Pk_KF_Key_Down | OS.Pk_KF_Key_Repeat)) != 0) {
- key = ke.key_cap;
- if ((ke.key_mods & OS.Pk_KM_Ctrl) != 0) {
- if ('a' <= key && key <= 'z') key -= 'a' - 'A';
- if (64 <= key && key <= 95) key -= 64;
- }
- }
- }
- 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_Return: event.character = '\r'; break;
- case OS.Pk_Delete: event.character = 0x7F; break;
- case OS.Pk_Cancel:
- case OS.Pk_Escape: event.character = 0x1B; break;
- case OS.Pk_KP_Tab:
- case OS.Pk_Tab: event.character = '\t'; break;
-// case OS.Pk_Clear: event.character = 0xB; break;
-// case OS.Pk_Pause: event.character = 0x13; break;
-// case OS.Pk_Scroll_Lock: event.character = 0x14; break;
- default:
- if (event.keyCode == 0) event.character = (char) key;
- }
- setInputState(event, ke.key_mods, ke.button_state);
- switch (event.type) {
- 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;
- }
-}
-
-void setMouseState(Event event, 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;
- }
- }
- setInputState(event, pe.key_mods, pe.button_state);
- switch (ev.type) {
- case OS.Ph_EV_BUT_PRESS:
- if (buttons == OS.Ph_BUTTON_SELECT) event.stateMask &= ~SWT.BUTTON1;
- if (buttons == OS.Ph_BUTTON_ADJUST) event.stateMask &= ~SWT.BUTTON2;
- if (buttons == OS.Ph_BUTTON_MENU) event.stateMask &= ~SWT.BUTTON3;
- break;
- case OS.Ph_EV_BUT_RELEASE:
- case OS.Ph_EV_DRAG:
- if (buttons == OS.Ph_BUTTON_SELECT) event.stateMask |= SWT.BUTTON1;
- if (buttons == OS.Ph_BUTTON_ADJUST) event.stateMask |= SWT.BUTTON2;
- if (buttons == OS.Ph_BUTTON_MENU) event.stateMask |= SWT.BUTTON3;
- break;
- }
-}
-
-int topHandle () {
- return handle;
-}
-
+public void setData (String key, Object value) {
+ checkWidget();
+ 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;
+}
+
+void setInputState(Event event, 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;
+}
+
+void setKeyState(Event event, PhKeyEvent_t ke) {
+ /*
+ * 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 = 0;
+ if ((ke.key_flags & OS.Pk_KF_Sym_Valid) != 0) {
+ key = ke.key_sym;
+ } else if ((ke.key_flags & OS.Pk_KF_Cap_Valid) != 0) {
+ if ((ke.key_flags & (OS.Pk_KF_Key_Down | OS.Pk_KF_Key_Repeat)) != 0) {
+ key = ke.key_cap;
+ if ((ke.key_mods & OS.Pk_KM_Ctrl) != 0) {
+ if ('a' <= key && key <= 'z') key -= 'a' - 'A';
+ if (64 <= key && key <= 95) key -= 64;
+ }
+ }
+ }
+ 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_Return: event.character = '\r'; break;
+ case OS.Pk_Delete: event.character = 0x7F; break;
+ case OS.Pk_Cancel:
+ case OS.Pk_Escape: event.character = 0x1B; break;
+ case OS.Pk_KP_Tab:
+ case OS.Pk_Tab: event.character = '\t'; break;
+// case OS.Pk_Clear: event.character = 0xB; break;
+// case OS.Pk_Pause: event.character = 0x13; break;
+// case OS.Pk_Scroll_Lock: event.character = 0x14; break;
+ default:
+ if (event.keyCode == 0) event.character = (char) key;
+ }
+ setInputState(event, ke.key_mods, ke.button_state);
+ switch (event.type) {
+ 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;
+ }
+}
+
+void setMouseState(Event event, 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;
+ }
+ }
+ setInputState(event, pe.key_mods, pe.button_state);
+ switch (ev.type) {
+ case OS.Ph_EV_BUT_PRESS:
+ if (buttons == OS.Ph_BUTTON_SELECT) event.stateMask &= ~SWT.BUTTON1;
+ if (buttons == OS.Ph_BUTTON_ADJUST) event.stateMask &= ~SWT.BUTTON2;
+ if (buttons == OS.Ph_BUTTON_MENU) event.stateMask &= ~SWT.BUTTON3;
+ break;
+ case OS.Ph_EV_BUT_RELEASE:
+ case OS.Ph_EV_DRAG:
+ if (buttons == OS.Ph_BUTTON_SELECT) event.stateMask |= SWT.BUTTON1;
+ if (buttons == OS.Ph_BUTTON_ADJUST) event.stateMask |= SWT.BUTTON2;
+ if (buttons == OS.Ph_BUTTON_MENU) event.stateMask |= SWT.BUTTON3;
+ break;
+ }
+}
+
+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_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;
-}
-
-}
+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_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
index 7fdae475d0..a370d8cbdc 100755
--- 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
@@ -1,109 +1,109 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index 738893f329..5b3b428410 100755
--- 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
@@ -1,330 +1,330 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 {
-
- /**
- * the handle to the OS color resource
- * (Warning: This field is platform dependent)
- */
- public int handle;
-
- /**
- * the device where this color was created
- */
- Device device;
-
-/**
- * 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.
- *
- * @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 which 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*}";
- return "Color {" + 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 win32_new(Device device, int handle) {
- if (device == null) device = Device.getDevice();
- Color color = new Color();
- color.handle = handle;
- color.device = device;
- return color;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 {
+
+ /**
+ * the handle to the OS color resource
+ * (Warning: This field is platform dependent)
+ */
+ public int handle;
+
+ /**
+ * the device where this color was created
+ */
+ Device device;
+
+/**
+ * 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.
+ *
+ * @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 which 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*}";
+ return "Color {" + 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 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
index 945ddbc1aa..00f4435954 100755
--- 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
@@ -1,404 +1,404 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 {
-
- /**
- * the handle to the OS cursor resource
- * (Warning: This field is platform dependent)
- */
- public int handle;
-
- /**
- * the device where this cursor was created
- */
- Device device;
-
- /**
- * 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 co-ordinates 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 either is not of depth one, 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 color depths */
- if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (source.depth != 1) 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);
- }
- /* 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, source.data, mask.data);
- 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 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));
-// }
-
- /*
- * 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 which 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
- *
- * @private
- */
-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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 {
+
+ /**
+ * the handle to the OS cursor resource
+ * (Warning: This field is platform dependent)
+ */
+ public int handle;
+
+ /**
+ * the device where this cursor was created
+ */
+ Device device;
+
+ /**
+ * 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 co-ordinates 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 either is not of depth one, 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 color depths */
+ if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ if (source.depth != 1) 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);
+ }
+ /* 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, source.data, mask.data);
+ 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 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));
+// }
+
+ /*
+ * 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 which 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
+ *
+ * @private
+ */
+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
index 81607fc0f4..9b3458c6ae 100755
--- 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
@@ -1,714 +1,714 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-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)
- */
- public int hPalette = 0;
- int [] colorRefCount;
-
- /* System Font */
- int systemFont;
-
- /* Font Enumeration */
- int nFonts = 256;
- LOGFONT [] logFonts;
-
- boolean disposed;
-
- /*
- * TEMPORARY CODE. When a graphics object is
- * created and the device parameter is null,
- * the current Display is used. This presents
- * a problem because SWT graphics does not
- * reference classes in SWT widgets. The correct
- * fix is to remove this feature. Unfortunately,
- * too many application programs rely on this
- * feature.
- *
- * 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 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>
- *
- * @param data the DeviceData which describes the receiver
- *
- * @see #create
- * @see #init
- * @see DeviceData
- */
-public Device(DeviceData data) {
- 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) {
-}
-
-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 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,
- * which in turn requires font creation.
- */
- int hFont = OS.CreateFontIndirect(logFont);
- int oldFont = OS.SelectObject(hDC, hFont);
- TEXTMETRIC lptm = new TEXTMETRIC();
- OS.GetTextMetrics(hDC, lptm);
- OS.SelectObject(hDC, oldFont);
- OS.DeleteObject(hFont);
- 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;
- if ((lParam == 1) != isScalable) return 1;
-
- /* 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;
- }
- LOGFONT logFont = logFonts [nFonts];
- if (logFont == null) logFont = new LOGFONT ();
- OS.MoveMemory (logFont, lpelfe, LOGFONT.sizeof);
- logFonts [nFonts++] = logFont;
- 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 true if scalable fonts should be 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);
- int lpEnumFontFamProc = callback.getAddress ();
-
- /* Initialize the instance variables */
- logFonts = new LOGFONT [nFonts];
- for (int i=0; i<logFonts.length; i++) {
- logFonts [i] = new LOGFONT ();
- }
- 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.
- */
- char [] buffer = new char [] {
- lf.lfFaceName0, lf.lfFaceName1, lf.lfFaceName2, lf.lfFaceName3,
- lf.lfFaceName4, lf.lfFaceName5, lf.lfFaceName6, lf.lfFaceName7,
- lf.lfFaceName8, lf.lfFaceName9, lf.lfFaceName10, lf.lfFaceName11,
- lf.lfFaceName12, lf.lfFaceName13, lf.lfFaceName14, lf.lfFaceName15,
- lf.lfFaceName16, lf.lfFaceName17, lf.lfFaceName18, lf.lfFaceName19,
- lf.lfFaceName20, lf.lfFaceName21, lf.lfFaceName22, lf.lfFaceName23,
- lf.lfFaceName24, lf.lfFaceName25, lf.lfFaceName26, lf.lfFaceName27,
- lf.lfFaceName28, lf.lfFaceName29, lf.lfFaceName30, lf.lfFaceName31,
- };
- TCHAR lpFaceName = new TCHAR (0, new String(buffer), true);
- OS.EnumFontFamilies (hDC, lpFaceName, 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);
- }
- 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++) {
- LOGFONT logFont = logFonts [i+offset];
- result [i] = FontData.win32_new (logFont, computePoints(logFont));
- }
-
- /* Clean up */
- callback.dispose ();
- logFonts = null;
- 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_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 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_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 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
- *
- * @private
- */
-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 handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
- */
-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 (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>true</code> prevents these
- * messages from being printed. If the argument is <code>false</code>
- * message printing is not blocked.
- *
- * @param warnings <code>true</code>if warnings should be handled, 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 ();
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.*;
+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)
+ */
+ public int hPalette = 0;
+ int [] colorRefCount;
+
+ /* System Font */
+ int systemFont;
+
+ /* Font Enumeration */
+ int nFonts = 256;
+ LOGFONT [] logFonts;
+
+ boolean disposed;
+
+ /*
+ * TEMPORARY CODE. When a graphics object is
+ * created and the device parameter is null,
+ * the current Display is used. This presents
+ * a problem because SWT graphics does not
+ * reference classes in SWT widgets. The correct
+ * fix is to remove this feature. Unfortunately,
+ * too many application programs rely on this
+ * feature.
+ *
+ * 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 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>
+ *
+ * @param data the DeviceData which describes the receiver
+ *
+ * @see #create
+ * @see #init
+ * @see DeviceData
+ */
+public Device(DeviceData data) {
+ 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) {
+}
+
+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 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,
+ * which in turn requires font creation.
+ */
+ int hFont = OS.CreateFontIndirect(logFont);
+ int oldFont = OS.SelectObject(hDC, hFont);
+ TEXTMETRIC lptm = new TEXTMETRIC();
+ OS.GetTextMetrics(hDC, lptm);
+ OS.SelectObject(hDC, oldFont);
+ OS.DeleteObject(hFont);
+ 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;
+ if ((lParam == 1) != isScalable) return 1;
+
+ /* 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;
+ }
+ LOGFONT logFont = logFonts [nFonts];
+ if (logFont == null) logFont = new LOGFONT ();
+ OS.MoveMemory (logFont, lpelfe, LOGFONT.sizeof);
+ logFonts [nFonts++] = logFont;
+ 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 true if scalable fonts should be 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);
+ int lpEnumFontFamProc = callback.getAddress ();
+
+ /* Initialize the instance variables */
+ logFonts = new LOGFONT [nFonts];
+ for (int i=0; i<logFonts.length; i++) {
+ logFonts [i] = new LOGFONT ();
+ }
+ 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.
+ */
+ char [] buffer = new char [] {
+ lf.lfFaceName0, lf.lfFaceName1, lf.lfFaceName2, lf.lfFaceName3,
+ lf.lfFaceName4, lf.lfFaceName5, lf.lfFaceName6, lf.lfFaceName7,
+ lf.lfFaceName8, lf.lfFaceName9, lf.lfFaceName10, lf.lfFaceName11,
+ lf.lfFaceName12, lf.lfFaceName13, lf.lfFaceName14, lf.lfFaceName15,
+ lf.lfFaceName16, lf.lfFaceName17, lf.lfFaceName18, lf.lfFaceName19,
+ lf.lfFaceName20, lf.lfFaceName21, lf.lfFaceName22, lf.lfFaceName23,
+ lf.lfFaceName24, lf.lfFaceName25, lf.lfFaceName26, lf.lfFaceName27,
+ lf.lfFaceName28, lf.lfFaceName29, lf.lfFaceName30, lf.lfFaceName31,
+ };
+ TCHAR lpFaceName = new TCHAR (0, new String(buffer), true);
+ OS.EnumFontFamilies (hDC, lpFaceName, 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);
+ }
+ 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++) {
+ LOGFONT logFont = logFonts [i+offset];
+ result [i] = FontData.win32_new (logFont, computePoints(logFont));
+ }
+
+ /* Clean up */
+ callback.dispose ();
+ logFonts = null;
+ 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_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 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_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 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
+ *
+ * @private
+ */
+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 handle the platform specific GC handle
+ * @param data the platform specific GC data
+ *
+ * @private
+ */
+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 (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>true</code> prevents these
+ * messages from being printed. If the argument is <code>false</code>
+ * message printing is not blocked.
+ *
+ * @param warnings <code>true</code>if warnings should be handled, 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
index 06e99bb30c..d36b10ff4a 100755
--- 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
@@ -1,19 +1,19 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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
index 3ce6e79c8a..1a3f410bb8 100755
--- 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
@@ -1,256 +1,256 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 {
-
- /**
- * the handle to the OS font resource
- * (Warning: This field is platform dependent)
- */
- public int handle;
-
- /**
- * the device where this font was created
- */
- Device device;
-
-/**
- * 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);
- 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 = new LOGFONT();
- OS.GetObject(handle, LOGFONT.sizeof, logFont);
- return new FontData[] {FontData.win32_new(logFont, device.computePoints(logFont))};
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects which 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
- *
- * @private
- */
-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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 {
+
+ /**
+ * the handle to the OS font resource
+ * (Warning: This field is platform dependent)
+ */
+ public int handle;
+
+ /**
+ * the device where this font was created
+ */
+ Device device;
+
+/**
+ * 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);
+ 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 = new LOGFONT();
+ OS.GetObject(handle, LOGFONT.sizeof, logFont);
+ return new FontData[] {FontData.win32_new(logFont, device.computePoints(logFont))};
+}
+
+/**
+ * Returns an integer hash code for the receiver. Any two
+ * objects which 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
+ *
+ * @private
+ */
+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
index 1a37985314..12620ee2dc 100755
--- 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
@@ -1,693 +1,693 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe operating system fonts.
- * Only the public API of this type is platform independent.
- * <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)
- */
- public LOGFONT data;
-
- /**
- * The height of the font data in points
- * (Warning: This field is platform dependent)
- */
- public int height;
-
- /**
- * The locales of the font
- * (Warning: These fields are platform dependent)
- */
- String lang, country, variant;
-
-/**
- * Constructs a new un-initialized font data.
- */
-public FontData() {
- data = new LOGFONT();
- // We set the charset field so that
- // wildcard searching will work properly
- // out of the box
- data.lfCharSet = 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 = new LOGFONT();
- data.lfCharSet = 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")) {
- LOGFONT newData = new LOGFONT();
- 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;
- }
- char[] lfFaceName = new char[32];
- string.getChars(start, string.length(), lfFaceName, 0);
- newData.lfFaceName0 = lfFaceName[0];
- newData.lfFaceName1 = lfFaceName[1];
- newData.lfFaceName2 = lfFaceName[2];
- newData.lfFaceName3 = lfFaceName[3];
- newData.lfFaceName4 = lfFaceName[4];
- newData.lfFaceName5 = lfFaceName[5];
- newData.lfFaceName6 = lfFaceName[6];
- newData.lfFaceName7 = lfFaceName[7];
- newData.lfFaceName8 = lfFaceName[8];
- newData.lfFaceName9 = lfFaceName[9];
- newData.lfFaceName10 = lfFaceName[10];
- newData.lfFaceName11 = lfFaceName[11];
- newData.lfFaceName12 = lfFaceName[12];
- newData.lfFaceName13 = lfFaceName[13];
- newData.lfFaceName14 = lfFaceName[14];
- newData.lfFaceName15 = lfFaceName[15];
- newData.lfFaceName16 = lfFaceName[16];
- newData.lfFaceName17 = lfFaceName[17];
- newData.lfFaceName18 = lfFaceName[18];
- newData.lfFaceName19 = lfFaceName[19];
- newData.lfFaceName20 = lfFaceName[20];
- newData.lfFaceName21 = lfFaceName[21];
- newData.lfFaceName22 = lfFaceName[22];
- newData.lfFaceName23 = lfFaceName[23];
- newData.lfFaceName24 = lfFaceName[24];
- newData.lfFaceName25 = lfFaceName[25];
- newData.lfFaceName26 = lfFaceName[26];
- newData.lfFaceName27 = lfFaceName[27];
- newData.lfFaceName28 = lfFaceName[28];
- newData.lfFaceName29 = lfFaceName[29];
- newData.lfFaceName30 = lfFaceName[30];
- newData.lfFaceName31 = lfFaceName[31];
- 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 = new LOGFONT();
- setName(name);
- setHeight(height);
- setStyle(style);
- // We set the charset field so that
- // wildcard searching will work properly
- // out of the box
- data.lfCharSet = 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 &&
- data.lfFaceName0 == lf.lfFaceName0 &&
- data.lfFaceName1 == lf.lfFaceName1 &&
- data.lfFaceName2 == lf.lfFaceName2 &&
- data.lfFaceName3 == lf.lfFaceName3 &&
- data.lfFaceName4 == lf.lfFaceName4 &&
- data.lfFaceName5 == lf.lfFaceName5 &&
- data.lfFaceName6 == lf.lfFaceName6 &&
- data.lfFaceName7 == lf.lfFaceName7 &&
- data.lfFaceName8 == lf.lfFaceName8 &&
- data.lfFaceName9 == lf.lfFaceName9 &&
- data.lfFaceName10 == lf.lfFaceName10 &&
- data.lfFaceName11 == lf.lfFaceName11 &&
- data.lfFaceName12 == lf.lfFaceName12 &&
- data.lfFaceName13 == lf.lfFaceName13 &&
- data.lfFaceName14 == lf.lfFaceName14 &&
- data.lfFaceName15 == lf.lfFaceName15 &&
- data.lfFaceName16 == lf.lfFaceName16 &&
- data.lfFaceName17 == lf.lfFaceName17 &&
- data.lfFaceName18 == lf.lfFaceName18 &&
- data.lfFaceName19 == lf.lfFaceName19 &&
- data.lfFaceName20 == lf.lfFaceName20 &&
- data.lfFaceName21 == lf.lfFaceName21 &&
- data.lfFaceName22 == lf.lfFaceName22 &&
- data.lfFaceName23 == lf.lfFaceName23 &&
- data.lfFaceName24 == lf.lfFaceName24 &&
- data.lfFaceName25 == lf.lfFaceName25 &&
- data.lfFaceName26 == lf.lfFaceName26 &&
- data.lfFaceName27 == lf.lfFaceName27 &&
- data.lfFaceName28 == lf.lfFaceName28 &&
- data.lfFaceName29 == lf.lfFaceName29 &&
- data.lfFaceName30 == lf.lfFaceName30 &&
- data.lfFaceName31 == lf.lfFaceName31;
-}
-
-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 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 = {
- data.lfFaceName0, data.lfFaceName1, data.lfFaceName2, data.lfFaceName3,
- data.lfFaceName4, data.lfFaceName5, data.lfFaceName6, data.lfFaceName7,
- data.lfFaceName8, data.lfFaceName9, data.lfFaceName10, data.lfFaceName11,
- data.lfFaceName12, data.lfFaceName13, data.lfFaceName14, data.lfFaceName15,
- data.lfFaceName16, data.lfFaceName17, data.lfFaceName18, data.lfFaceName19,
- data.lfFaceName20, data.lfFaceName21, data.lfFaceName22, data.lfFaceName23,
- data.lfFaceName24, data.lfFaceName25, data.lfFaceName26, data.lfFaceName27,
- data.lfFaceName28, data.lfFaceName29, data.lfFaceName30, data.lfFaceName31,
- };
- 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 which 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 ^
- data.lfFaceName0 ^ data.lfFaceName1 ^ data.lfFaceName2 ^
- data.lfFaceName3 ^ data.lfFaceName4 ^ data.lfFaceName5 ^
- data.lfFaceName6 ^ data.lfFaceName7 ^ data.lfFaceName8 ^
- data.lfFaceName9 ^ data.lfFaceName10 ^ data.lfFaceName11 ^
- data.lfFaceName12 ^ data.lfFaceName13 ^ data.lfFaceName14 ^
- data.lfFaceName15 ^ data.lfFaceName16 ^ data.lfFaceName17 ^
- data.lfFaceName18 ^ data.lfFaceName19 ^ data.lfFaceName20 ^
- data.lfFaceName21 ^ data.lfFaceName22 ^ data.lfFaceName23 ^
- data.lfFaceName24 ^ data.lfFaceName25 ^ data.lfFaceName26 ^
- data.lfFaceName27 ^ data.lfFaceName28 ^ data.lfFaceName29 ^
- data.lfFaceName30 ^ data.lfFaceName31;
-}
-
-/**
- * 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 which 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 = OS.DEFAULT_CHARSET;
- } else {
- Callback callback = new Callback (this, "EnumLocalesProc", 1);
- int lpEnumLocalesProc = callback.getAddress ();
- 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);
- char [] chars = new char [32];
-
- /* The field lfFaceName must be NULL terminated */
- int length = name.length();
- name.getChars (0, length <= 31 ? length : 31, chars, 0);
- data.lfFaceName0 = chars[0];
- data.lfFaceName1 = chars[1];
- data.lfFaceName2 = chars[2];
- data.lfFaceName3 = chars[3];
- data.lfFaceName4 = chars[4];
- data.lfFaceName5 = chars[5];
- data.lfFaceName6 = chars[6];
- data.lfFaceName7 = chars[7];
- data.lfFaceName8 = chars[8];
- data.lfFaceName9 = chars[9];
- data.lfFaceName10 = chars[10];
- data.lfFaceName11 = chars[11];
- data.lfFaceName12 = chars[12];
- data.lfFaceName13 = chars[13];
- data.lfFaceName14 = chars[14];
- data.lfFaceName15 = chars[15];
- data.lfFaceName16 = chars[16];
- data.lfFaceName17 = chars[17];
- data.lfFaceName18 = chars[18];
- data.lfFaceName19 = chars[19];
- data.lfFaceName20 = chars[20];
- data.lfFaceName21 = chars[21];
- data.lfFaceName22 = chars[22];
- data.lfFaceName23 = chars[23];
- data.lfFaceName24 = chars[24];
- data.lfFaceName25 = chars[25];
- data.lfFaceName26 = chars[26];
- data.lfFaceName27 = chars[27];
- data.lfFaceName28 = chars[28];
- data.lfFaceName29 = chars[29];
- data.lfFaceName30 = chars[30];
- data.lfFaceName31 = chars[31];
-}
-
-/**
- * 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.
- *
- * @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|");
- buffer.append(getName());
- buffer.append("|");
- buffer.append(getHeight());
- buffer.append("|");
- buffer.append(getStyle());
- buffer.append("|");
- buffer.append("WINDOWS|1|");
- buffer.append(data.lfHeight);
- buffer.append("|");
- buffer.append(data.lfWidth);
- buffer.append("|");
- buffer.append(data.lfEscapement);
- buffer.append("|");
- buffer.append(data.lfOrientation);
- buffer.append("|");
- buffer.append(data.lfWeight);
- buffer.append("|");
- buffer.append(data.lfItalic);
- buffer.append("|");
- buffer.append(data.lfUnderline);
- buffer.append("|");
- buffer.append(data.lfStrikeOut);
- buffer.append("|");
- buffer.append(data.lfCharSet);
- buffer.append("|");
- buffer.append(data.lfOutPrecision);
- buffer.append("|");
- buffer.append(data.lfClipPrecision);
- buffer.append("|");
- buffer.append(data.lfQuality);
- buffer.append("|");
- buffer.append(data.lfPitchAndFamily);
- buffer.append("|");
- char[] faceName = {
- data.lfFaceName0, data.lfFaceName1, data.lfFaceName2, data.lfFaceName3,
- data.lfFaceName4, data.lfFaceName5, data.lfFaceName6, data.lfFaceName7,
- data.lfFaceName8, data.lfFaceName9, data.lfFaceName10, data.lfFaceName11,
- data.lfFaceName12, data.lfFaceName13, data.lfFaceName14, data.lfFaceName15,
- data.lfFaceName16, data.lfFaceName17, data.lfFaceName18, data.lfFaceName19,
- data.lfFaceName20, data.lfFaceName21, data.lfFaceName22, data.lfFaceName23,
- data.lfFaceName24, data.lfFaceName25, data.lfFaceName26, data.lfFaceName27,
- data.lfFaceName28, data.lfFaceName29, data.lfFaceName30, data.lfFaceName31,
- };
- int i = 0;
- while (i < faceName.length && faceName[i] != 0) {
- buffer.append(faceName[i++]);
- }
- 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
- *
- * @private
- */
-public static FontData win32_new(LOGFONT data, int height) {
- return new FontData(data, height);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.win32.*;
+import org.eclipse.swt.*;
+
+/**
+ * Instances of this class describe operating system fonts.
+ * Only the public API of this type is platform independent.
+ * <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)
+ */
+ public LOGFONT data;
+
+ /**
+ * The height of the font data in points
+ * (Warning: This field is platform dependent)
+ */
+ public int height;
+
+ /**
+ * The locales of the font
+ * (Warning: These fields are platform dependent)
+ */
+ String lang, country, variant;
+
+/**
+ * Constructs a new un-initialized font data.
+ */
+public FontData() {
+ data = new LOGFONT();
+ // We set the charset field so that
+ // wildcard searching will work properly
+ // out of the box
+ data.lfCharSet = 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 = new LOGFONT();
+ data.lfCharSet = 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")) {
+ LOGFONT newData = new LOGFONT();
+ 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;
+ }
+ char[] lfFaceName = new char[32];
+ string.getChars(start, string.length(), lfFaceName, 0);
+ newData.lfFaceName0 = lfFaceName[0];
+ newData.lfFaceName1 = lfFaceName[1];
+ newData.lfFaceName2 = lfFaceName[2];
+ newData.lfFaceName3 = lfFaceName[3];
+ newData.lfFaceName4 = lfFaceName[4];
+ newData.lfFaceName5 = lfFaceName[5];
+ newData.lfFaceName6 = lfFaceName[6];
+ newData.lfFaceName7 = lfFaceName[7];
+ newData.lfFaceName8 = lfFaceName[8];
+ newData.lfFaceName9 = lfFaceName[9];
+ newData.lfFaceName10 = lfFaceName[10];
+ newData.lfFaceName11 = lfFaceName[11];
+ newData.lfFaceName12 = lfFaceName[12];
+ newData.lfFaceName13 = lfFaceName[13];
+ newData.lfFaceName14 = lfFaceName[14];
+ newData.lfFaceName15 = lfFaceName[15];
+ newData.lfFaceName16 = lfFaceName[16];
+ newData.lfFaceName17 = lfFaceName[17];
+ newData.lfFaceName18 = lfFaceName[18];
+ newData.lfFaceName19 = lfFaceName[19];
+ newData.lfFaceName20 = lfFaceName[20];
+ newData.lfFaceName21 = lfFaceName[21];
+ newData.lfFaceName22 = lfFaceName[22];
+ newData.lfFaceName23 = lfFaceName[23];
+ newData.lfFaceName24 = lfFaceName[24];
+ newData.lfFaceName25 = lfFaceName[25];
+ newData.lfFaceName26 = lfFaceName[26];
+ newData.lfFaceName27 = lfFaceName[27];
+ newData.lfFaceName28 = lfFaceName[28];
+ newData.lfFaceName29 = lfFaceName[29];
+ newData.lfFaceName30 = lfFaceName[30];
+ newData.lfFaceName31 = lfFaceName[31];
+ 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 = new LOGFONT();
+ setName(name);
+ setHeight(height);
+ setStyle(style);
+ // We set the charset field so that
+ // wildcard searching will work properly
+ // out of the box
+ data.lfCharSet = 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 &&
+ data.lfFaceName0 == lf.lfFaceName0 &&
+ data.lfFaceName1 == lf.lfFaceName1 &&
+ data.lfFaceName2 == lf.lfFaceName2 &&
+ data.lfFaceName3 == lf.lfFaceName3 &&
+ data.lfFaceName4 == lf.lfFaceName4 &&
+ data.lfFaceName5 == lf.lfFaceName5 &&
+ data.lfFaceName6 == lf.lfFaceName6 &&
+ data.lfFaceName7 == lf.lfFaceName7 &&
+ data.lfFaceName8 == lf.lfFaceName8 &&
+ data.lfFaceName9 == lf.lfFaceName9 &&
+ data.lfFaceName10 == lf.lfFaceName10 &&
+ data.lfFaceName11 == lf.lfFaceName11 &&
+ data.lfFaceName12 == lf.lfFaceName12 &&
+ data.lfFaceName13 == lf.lfFaceName13 &&
+ data.lfFaceName14 == lf.lfFaceName14 &&
+ data.lfFaceName15 == lf.lfFaceName15 &&
+ data.lfFaceName16 == lf.lfFaceName16 &&
+ data.lfFaceName17 == lf.lfFaceName17 &&
+ data.lfFaceName18 == lf.lfFaceName18 &&
+ data.lfFaceName19 == lf.lfFaceName19 &&
+ data.lfFaceName20 == lf.lfFaceName20 &&
+ data.lfFaceName21 == lf.lfFaceName21 &&
+ data.lfFaceName22 == lf.lfFaceName22 &&
+ data.lfFaceName23 == lf.lfFaceName23 &&
+ data.lfFaceName24 == lf.lfFaceName24 &&
+ data.lfFaceName25 == lf.lfFaceName25 &&
+ data.lfFaceName26 == lf.lfFaceName26 &&
+ data.lfFaceName27 == lf.lfFaceName27 &&
+ data.lfFaceName28 == lf.lfFaceName28 &&
+ data.lfFaceName29 == lf.lfFaceName29 &&
+ data.lfFaceName30 == lf.lfFaceName30 &&
+ data.lfFaceName31 == lf.lfFaceName31;
+}
+
+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 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 = {
+ data.lfFaceName0, data.lfFaceName1, data.lfFaceName2, data.lfFaceName3,
+ data.lfFaceName4, data.lfFaceName5, data.lfFaceName6, data.lfFaceName7,
+ data.lfFaceName8, data.lfFaceName9, data.lfFaceName10, data.lfFaceName11,
+ data.lfFaceName12, data.lfFaceName13, data.lfFaceName14, data.lfFaceName15,
+ data.lfFaceName16, data.lfFaceName17, data.lfFaceName18, data.lfFaceName19,
+ data.lfFaceName20, data.lfFaceName21, data.lfFaceName22, data.lfFaceName23,
+ data.lfFaceName24, data.lfFaceName25, data.lfFaceName26, data.lfFaceName27,
+ data.lfFaceName28, data.lfFaceName29, data.lfFaceName30, data.lfFaceName31,
+ };
+ 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 which 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 ^
+ data.lfFaceName0 ^ data.lfFaceName1 ^ data.lfFaceName2 ^
+ data.lfFaceName3 ^ data.lfFaceName4 ^ data.lfFaceName5 ^
+ data.lfFaceName6 ^ data.lfFaceName7 ^ data.lfFaceName8 ^
+ data.lfFaceName9 ^ data.lfFaceName10 ^ data.lfFaceName11 ^
+ data.lfFaceName12 ^ data.lfFaceName13 ^ data.lfFaceName14 ^
+ data.lfFaceName15 ^ data.lfFaceName16 ^ data.lfFaceName17 ^
+ data.lfFaceName18 ^ data.lfFaceName19 ^ data.lfFaceName20 ^
+ data.lfFaceName21 ^ data.lfFaceName22 ^ data.lfFaceName23 ^
+ data.lfFaceName24 ^ data.lfFaceName25 ^ data.lfFaceName26 ^
+ data.lfFaceName27 ^ data.lfFaceName28 ^ data.lfFaceName29 ^
+ data.lfFaceName30 ^ data.lfFaceName31;
+}
+
+/**
+ * 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 which 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 = OS.DEFAULT_CHARSET;
+ } else {
+ Callback callback = new Callback (this, "EnumLocalesProc", 1);
+ int lpEnumLocalesProc = callback.getAddress ();
+ 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);
+ char [] chars = new char [32];
+
+ /* The field lfFaceName must be NULL terminated */
+ int length = name.length();
+ name.getChars (0, length <= 31 ? length : 31, chars, 0);
+ data.lfFaceName0 = chars[0];
+ data.lfFaceName1 = chars[1];
+ data.lfFaceName2 = chars[2];
+ data.lfFaceName3 = chars[3];
+ data.lfFaceName4 = chars[4];
+ data.lfFaceName5 = chars[5];
+ data.lfFaceName6 = chars[6];
+ data.lfFaceName7 = chars[7];
+ data.lfFaceName8 = chars[8];
+ data.lfFaceName9 = chars[9];
+ data.lfFaceName10 = chars[10];
+ data.lfFaceName11 = chars[11];
+ data.lfFaceName12 = chars[12];
+ data.lfFaceName13 = chars[13];
+ data.lfFaceName14 = chars[14];
+ data.lfFaceName15 = chars[15];
+ data.lfFaceName16 = chars[16];
+ data.lfFaceName17 = chars[17];
+ data.lfFaceName18 = chars[18];
+ data.lfFaceName19 = chars[19];
+ data.lfFaceName20 = chars[20];
+ data.lfFaceName21 = chars[21];
+ data.lfFaceName22 = chars[22];
+ data.lfFaceName23 = chars[23];
+ data.lfFaceName24 = chars[24];
+ data.lfFaceName25 = chars[25];
+ data.lfFaceName26 = chars[26];
+ data.lfFaceName27 = chars[27];
+ data.lfFaceName28 = chars[28];
+ data.lfFaceName29 = chars[29];
+ data.lfFaceName30 = chars[30];
+ data.lfFaceName31 = chars[31];
+}
+
+/**
+ * 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.
+ *
+ * @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|");
+ buffer.append(getName());
+ buffer.append("|");
+ buffer.append(getHeight());
+ buffer.append("|");
+ buffer.append(getStyle());
+ buffer.append("|");
+ buffer.append("WINDOWS|1|");
+ buffer.append(data.lfHeight);
+ buffer.append("|");
+ buffer.append(data.lfWidth);
+ buffer.append("|");
+ buffer.append(data.lfEscapement);
+ buffer.append("|");
+ buffer.append(data.lfOrientation);
+ buffer.append("|");
+ buffer.append(data.lfWeight);
+ buffer.append("|");
+ buffer.append(data.lfItalic);
+ buffer.append("|");
+ buffer.append(data.lfUnderline);
+ buffer.append("|");
+ buffer.append(data.lfStrikeOut);
+ buffer.append("|");
+ buffer.append(data.lfCharSet);
+ buffer.append("|");
+ buffer.append(data.lfOutPrecision);
+ buffer.append("|");
+ buffer.append(data.lfClipPrecision);
+ buffer.append("|");
+ buffer.append(data.lfQuality);
+ buffer.append("|");
+ buffer.append(data.lfPitchAndFamily);
+ buffer.append("|");
+ char[] faceName = {
+ data.lfFaceName0, data.lfFaceName1, data.lfFaceName2, data.lfFaceName3,
+ data.lfFaceName4, data.lfFaceName5, data.lfFaceName6, data.lfFaceName7,
+ data.lfFaceName8, data.lfFaceName9, data.lfFaceName10, data.lfFaceName11,
+ data.lfFaceName12, data.lfFaceName13, data.lfFaceName14, data.lfFaceName15,
+ data.lfFaceName16, data.lfFaceName17, data.lfFaceName18, data.lfFaceName19,
+ data.lfFaceName20, data.lfFaceName21, data.lfFaceName22, data.lfFaceName23,
+ data.lfFaceName24, data.lfFaceName25, data.lfFaceName26, data.lfFaceName27,
+ data.lfFaceName28, data.lfFaceName29, data.lfFaceName30, data.lfFaceName31,
+ };
+ int i = 0;
+ while (i < faceName.length && faceName[i] != 0) {
+ buffer.append(faceName[i++]);
+ }
+ 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
+ *
+ * @private
+ */
+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
index 83819f050a..6ee56cbe90 100755
--- 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
@@ -1,173 +1,173 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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)
- */
- 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 which 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 tm the <code>TEXTMETRIC</code> containing information about a font
- *
- * @private
- */
-public static FontMetrics win32_new(TEXTMETRIC handle) {
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.handle = handle;
- return fontMetrics;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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)
+ */
+ 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 which 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 tm the <code>TEXTMETRIC</code> containing information about a font
+ *
+ * @private
+ */
+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
index f027948a9c..6c75124849 100755
--- 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
@@ -1,2305 +1,2305 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-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>.
- * <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>
- *
- * @see org.eclipse.swt.events.PaintEvent
- */
-
-public final class GC {
-
- /**
- * the handle to the OS device context
- * (Warning: This field is platform dependent)
- */
- public int handle;
-
- Drawable drawable;
- GCData data;
-
-/**
- * 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) {
- if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- GCData data = new GCData ();
- 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);
- data.device = device;
- init (drawable, data, hDC);
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Copies a rectangular area of the receiver at the specified
- * position into the image, which must be of type <code>SWT.BITMAP</code>.
- *
- * @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) {
- 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 res = OS.ScrollWindowEx(hwnd, destX - srcX, destY - srcY, lprcScroll, lprcClip, 0, null, OS.SW_INVALIDATE | OS.SW_ERASE);
-
- /*
- * 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);
- 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 createDIB(int width, int height) {
- short depth = 32;
-
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
- bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
- bmiHeader.biWidth = width;
- bmiHeader.biHeight = -height;
- bmiHeader.biPlanes = 1;
- bmiHeader.biBitCount = 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];
- int hDib = OS.CreateDIBSection(0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
- if (hDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- return hDib;
-}
-
-/**
- * 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;
-
- /*
- * The only way for pens and brushes to get
- * selected into the HDC is for the receiver to
- * create them. When we are destroying the
- * hDC we also destroy any pens and brushes that
- * we have allocated. This code assumes that it
- * is OK to delete stock objects. This will
- * happen when a GC is disposed and the user has
- * not caused new pens or brushes to be allocated.
- */
- int nullPen = OS.GetStockObject(OS.NULL_PEN);
- int oldPen = OS.SelectObject(handle, nullPen);
- OS.DeleteObject(oldPen);
- int nullBrush = OS.GetStockObject(OS.NULL_BRUSH);
- int oldBrush = OS.SelectObject(handle, nullBrush);
- OS.DeleteObject(oldBrush);
-
- /*
- * 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;
- 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 IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.</li>
- * </ul>
- * @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 endAngle) {
- 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 || endAngle == 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /*
- * 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 (endAngle < 0) {
- startAngle += endAngle;
- endAngle = -endAngle;
- }
- if (endAngle > 360) endAngle = 360;
- int[] points = new int[(endAngle + 1) * 2];
- int cteX = 2 * x + width;
- int cteY = 2 * y + height;
- int index = 0;
- for (int i = 0; i <= endAngle; 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 (endAngle >= 360 || endAngle <= -360) {
- x1 = x2 = x + width;
- y1 = y2 = y + height / 2;
- } else {
- isNegative = endAngle < 0;
-
- endAngle = endAngle + startAngle;
- if (isNegative) {
- // swap angles
- tmp = startAngle;
- startAngle = endAngle;
- endAngle = tmp;
- }
- x1 = Compatibility.cos(startAngle, width) + x + width/2;
- y1 = -1 * Compatibility.sin(startAngle, height) + y + height/2;
-
- x2 = Compatibility.cos(endAngle, width) + x + width/2;
- y2 = -1 * Compatibility.sin(endAngle, 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
- */
-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 SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</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 SWTError <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</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) {
- 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;
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- }
-}
-
-void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- /* Simple case: no stretching, entire icon */
- if (simple) {
- OS.DrawIconEx(handle, destX, destY, srcImage.handle, 0, 0, 0, 0, OS.DI_NORMAL);
- 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 (simple) {
- /* Simple case: no stretching, entire icon */
- OS.DrawIconEx(handle, destX, destY, srcImage.handle, 0, 0, 0, 0, OS.DI_NORMAL);
- } else {
- /* Get the HDC for the device */
- Device device = data.device;
- int hDC = device.internal_new_GC(null);
-
- /* Create the icon info and HDC's */
- ICONINFO newIconInfo = new ICONINFO();
- newIconInfo.fIcon = true;
- int srcHdc = OS.CreateCompatibleDC(hDC);
- int dstHdc = OS.CreateCompatibleDC(hDC);
-
- /* 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);
- if (!OS.IsWinCE) OS.SetStretchBltMode(dstHdc, OS.COLORONCOLOR);
- OS.StretchBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcColorY, srcWidth, srcHeight, 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);
- OS.StretchBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCCOPY);
-
- /* Select old bitmaps before creating the icon */
- OS.SelectObject(srcHdc, oldSrcBitmap);
- OS.SelectObject(dstHdc, oldDestBitmap);
-
- /* Create the new icon */
- int hIcon = OS.CreateIconIndirect(newIconInfo);
- if (hIcon == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-
- /* Draw the new icon */
- OS.DrawIconEx(handle, destX, destY, hIcon, destWidth, destHeight, 0, 0, OS.DI_NORMAL);
-
- /* Destroy the new icon and hdc's*/
- OS.DestroyIcon(hIcon);
- OS.DeleteObject(newIconInfo.hbmMask);
- OS.DeleteObject(newIconInfo.hbmColor);
- OS.DeleteDC(dstHdc);
- OS.DeleteDC(srcHdc);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
- }
- }
-
- /* 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()) {
- 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;
- }
-
- /* 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 = createDIB(Math.max(srcWidth, destWidth), Math.max(srcHeight, destHeight));
- 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 */
- if (!OS.IsWinCE) OS.SetStretchBltMode(memHdc, OS.COLORONCOLOR);
- 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 = createDIB(destWidth, destHeight);
- int oldTempBitmap = OS.SelectObject(tempHdc, tempDib);
- OS.StretchBlt(tempHdc, 0, 0, destWidth, destHeight, memHdc, 0, 0, srcWidth, srcHeight, 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 {
- OS.StretchBlt(memHdc, 0, 0, destWidth, destHeight, memHdc, 0, 0, srcWidth, srcHeight, 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 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) {
-
- /* Get the HDC for the device */
- Device device = data.device;
- int hDC = device.internal_new_GC(null);
-
- /* 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;
- 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 {
- /* 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;
- }
- }
-
- 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.
- */
- int transparentColor = transBlue << 16 | transGreen << 8 | transRed;
- OS.TransparentImage(handle, destX, destY, destWidth, destHeight,
- srcHdc, srcX, srcY, srcWidth, srcHeight, transparentColor);
- } else {
- /* Create the mask for the source image */
- int maskHdc = OS.CreateCompatibleDC(hDC);
- int maskBitmap = OS.CreateBitmap(imgWidth, imgHeight, 1, 1, null);
- int oldMaskBitmap = OS.SelectObject(maskHdc, maskBitmap);
- OS.SetBkColor(srcHdc, (transBlue << 16) | (transGreen << 8) | transRed);
- OS.BitBlt(maskHdc, 0, 0, imgWidth, imgHeight, srcHdc, 0, 0, OS.SRCCOPY);
- if (originalColors != null) OS.SetDIBColorTable(srcHdc, 0, 1 << bm.bmBitsPixel, originalColors);
-
- /* Draw the source bitmap transparently using invert/and mask/invert */
- int tempHdc = OS.CreateCompatibleDC(hDC);
- int tempBitmap = OS.CreateCompatibleBitmap(hDC, destWidth, destHeight);
- int oldTempBitmap = OS.SelectObject(tempHdc, tempBitmap);
- OS.BitBlt(tempHdc, 0, 0, destWidth, destHeight, handle, destX, destY, OS.SRCCOPY);
- 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);
- OS.BitBlt(handle, destX, destY, destWidth, destHeight, tempHdc, 0, 0, OS.SRCCOPY);
-
- /* Release resources */
- 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);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
-}
-
-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 mode = 0, rop2 = 0;
- if (!OS.IsWinCE) {
- rop2 = OS.GetROP2(handle);
- mode = OS.SetStretchBltMode(handle, OS.COLORONCOLOR);
- } else {
- rop2 = OS.SetROP2 (handle, OS.R2_COPYPEN);
- OS.SetROP2 (handle, rop2);
- }
- int dwRop = rop2 == OS.R2_XORPEN ? OS.SRCINVERT : OS.SRCCOPY;
- OS.StretchBlt(handle, destX, destY, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, dwRop);
- if (!OS.IsWinCE) {
- OS.SetStretchBltMode(handle, mode);
- }
- 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);
- 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);
- }
- 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);
- // 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 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 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);
- OS.Polyline(handle, pointArray, pointArray.length / 2);
-}
-
-/**
- * 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 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.
- *
- * @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 horizontal diameter of the arc at the four corners
- * @param arcHeight the vertical diameter of the arc at the four corners
- *
- * @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 (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-1, x+width-arcWidth/2, y+height-1);
- }
- if (arcHeight < height) {
- drawLine(x, y+arcHeight/2, x, y+height-arcHeight/2);
- drawLine(x+width-1, y+arcHeight/2, x+width-1, y+height-arcHeight/2);
- }
- if (arcWidth != 0 && arcHeight != 0) {
- drawArc(x, y, arcWidth, arcHeight, 90, 90);
- drawArc(x+width-arcWidth-1, y, arcWidth, arcHeight, 0, 90);
- drawArc(x+width-arcWidth-1, y+height-arcHeight-1, arcWidth, arcHeight, 0, -90);
- drawArc(x, y+height-arcHeight-1, 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,y+height, arcWidth, arcHeight);
- OS.SelectObject(handle,oldBrush);
- }
-}
-
-/**
- * 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();
- char[] buffer = new char [length];
- string.getChars(0, length, buffer, 0);
- int oldBkMode = OS.SetBkMode(handle, isTransparent ? OS.TRANSPARENT : OS.OPAQUE);
- OS.ExtTextOutW(handle, x, y, 0, null, buffer, length, null);
- 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);
- RECT rect = new RECT();
- OS.SetRect(rect, x, y, 0x7FFF, 0x7FFF);
- TCHAR buffer = new TCHAR(getCodePage(), string, false);
- 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 oldBkMode = OS.SetBkMode(handle, (flags & SWT.DRAW_TRANSPARENT) != 0 ? OS.TRANSPARENT : OS.OPAQUE);
- OS.DrawText(handle, buffer, buffer.length(), rect, uFormat);
- 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 IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.</li>
- * </ul>
- * @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 endAngle) {
- 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 || endAngle == 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
-
- /*
- * 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 (endAngle < 0) {
- startAngle += endAngle;
- endAngle = -endAngle;
- }
- boolean drawSegments = true;
- if (endAngle >= 360) {
- endAngle = 360;
- drawSegments = false;
- }
- int[] points = new int[(endAngle + 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 <= endAngle; 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 (endAngle >= 360 || endAngle <= -360) {
- x1 = x2 = x + width;
- y1 = y2 = y + height / 2;
- } else {
- isNegative = endAngle < 0;
-
- endAngle = endAngle + startAngle;
- if (isNegative) {
- // swap angles
- tmp = startAngle;
- startAngle = endAngle;
- endAngle = tmp;
- }
- x1 = Compatibility.cos(startAngle, width) + x + width/2;
- y1 = -1 * Compatibility.sin(startAngle, height) + y + height/2;
-
- x2 = Compatibility.cos(endAngle, width) + x + width/2;
- y2 = -1 * Compatibility.sin(endAngle, 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
- */
-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;
- }
- 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)) {
- OS.PatBlt(handle, x, y, width, height, OS.PATCOPY);
- return;
- }
-
- /* Use GradientFill if supported, only on Windows 98, 2000 and newer */
- if (!OS.IsWinCE) {
- 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);
-
- /* 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 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);
- 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
- */
-public void fillRectangle (int x, int y, int width, int height) {
- 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);
- }
- 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 rectangle 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
- */
-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 horizontal diameter of the arc at the four corners
- * @param arcHeight the vertical diameter of the arc at the four corners
- *
- * @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 nullPen = OS.GetStockObject(OS.NULL_PEN);
- int oldPen = OS.SelectObject(handle, nullPen);
- OS.RoundRect(handle, x,y,x+width,y+height,arcWidth, arcHeight);
- OS.SelectObject(handle,oldPen);
-}
-
-/**
- * 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 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 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 tm = new TEXTMETRIC();
- OS.GetTextMetricsW(handle, tm);
- SIZE size = new SIZE();
- OS.GetTextExtentPoint32W(handle, new char[]{ch}, 1, size);
- return size.cx - tm.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);
- 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>
- * </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 result = OS.GetClipRgn (handle, region.handle);
- if (result == 1) return;
- RECT rect = new RECT();
- OS.GetClipBox(handle, rect);
- OS.SetRectRgn(region.handle, rect.left, rect.top, rect.right, rect.bottom);
-}
-
-int getCodePage () {
- if (OS.IsWinCE) return OS.GetACP();
- int[] lpCs = new int[8];
- int cs = OS.GetTextCharset(handle);
- OS.TranslateCharsetInfo(cs, lpCs, OS.TCI_SRCCHARSET);
- return lpCs[1];
-}
-
-/**
- * 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 = new TEXTMETRIC();
- 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 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 hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
- LOGPEN logPen = new LOGPEN();
- OS.GetObject(hPen, LOGPEN.sizeof, logPen);
- switch (logPen.lopnStyle) {
- 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;
- 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 hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
- LOGPEN logPen = new LOGPEN();
- OS.GetObject(hPen, LOGPEN.sizeof, logPen);
- return logPen.x;
-}
-
-/**
- * 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 init(Drawable drawable, GCData data, int hDC) {
- int foreground = data.foreground;
- if (foreground != -1 && OS.GetTextColor(hDC) != foreground) {
- OS.SetTextColor(hDC, foreground);
- int hPen = OS.CreatePen(OS.PS_SOLID, 0, foreground);
- OS.SelectObject(hDC, hPen);
- }
- int background = data.background;
- if (background != -1 && OS.GetBkColor(hDC) != background) {
- OS.SetBkColor(hDC, background);
- int hBrush = OS.CreateSolidBrush(background);
- OS.SelectObject(hDC, hBrush);
- }
- 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;
- }
- this.drawable = drawable;
- this.data = data;
- handle = hDC;
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects which 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;
-}
-
-/**
- * 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 (OS.GetBkColor(handle) == color.handle) return;
- OS.SetBkColor (handle, color.handle);
- int newBrush = OS.CreateSolidBrush (color.handle);
- int oldBrush = OS.SelectObject (handle, newBrush);
- OS.DeleteObject (oldBrush);
-}
-
-/**
- * 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);
- OS.SelectClipRgn (handle, hRgn);
- OS.DeleteObject (hRgn);
-}
-
-/**
- * Sets the area of the receiver which can be changed
- * by drawing operations to the rectangular area specified
- * by the argument.
- *
- * @param rect the clipping rectangle
- *
- * @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) {
- OS.SelectClipRgn (handle, 0);
- return;
- }
- 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.
- *
- * @param rect the clipping region.
- *
- * @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);
- int hRegion = 0;
- if (region != null) hRegion = region.handle;
- OS.SelectClipRgn (handle, hRegion);
-}
-
-/**
- * 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 (OS.GetTextColor(handle) == color.handle) return;
- int hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
- LOGPEN logPen = new LOGPEN();
- OS.GetObject(hPen, LOGPEN.sizeof, logPen);
- OS.SetTextColor (handle, color.handle);
- int newPen = OS.CreatePen (logPen.lopnStyle, logPen.x, color.handle);
- int oldPen = OS.SelectObject (handle, newPen);
- OS.DeleteObject (oldPen);
-}
-
-/**
- * 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 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;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
- LOGPEN logPen = new LOGPEN();
- OS.GetObject(hPen, LOGPEN.sizeof, logPen);
- if (logPen.lopnStyle == style) return;
- OS.SetBkMode (handle, style == OS.PS_SOLID ? OS.OPAQUE : OS.TRANSPARENT);
- int newPen = OS.CreatePen(style, logPen.x, logPen.lopnColor);
- int oldPen = OS.SelectObject(handle, newPen);
- OS.DeleteObject(oldPen);
-}
-
-/**
- * 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.
- *
- * @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 hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
- LOGPEN logPen = new LOGPEN();
- OS.GetObject(hPen, LOGPEN.sizeof, logPen);
- if (logPen.x == lineWidth) return;
- int newPen = OS.CreatePen(logPen.lopnStyle, lineWidth, logPen.lopnColor);
- int oldPen = OS.SelectObject(handle, newPen);
- OS.DeleteObject(oldPen);
-}
-
-/**
- * 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.
- *
- * @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>
- */
-public void setXORMode(boolean xor) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (xor) {
- OS.SetROP2(handle, OS.R2_XORPEN);
- } else {
- OS.SetROP2(handle, OS.R2_COPYPEN);
- }
-}
-
-/**
- * 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);
- SIZE size = new SIZE();
- int length = string.length();
- 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 (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>
- *
- * @private
- */
-public static GC win32_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- int hDC = drawable.internal_new_GC(data);
- gc.init(drawable, data, hDC);
- return gc;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.*;
+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>.
+ * <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>
+ *
+ * @see org.eclipse.swt.events.PaintEvent
+ */
+
+public final class GC {
+
+ /**
+ * the handle to the OS device context
+ * (Warning: This field is platform dependent)
+ */
+ public int handle;
+
+ Drawable drawable;
+ GCData data;
+
+/**
+ * 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) {
+ if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ GCData data = new GCData ();
+ 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);
+ data.device = device;
+ init (drawable, data, hDC);
+ if (device.tracking) device.new_Object(this);
+}
+
+/**
+ * Copies a rectangular area of the receiver at the specified
+ * position into the image, which must be of type <code>SWT.BITMAP</code>.
+ *
+ * @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) {
+ 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 res = OS.ScrollWindowEx(hwnd, destX - srcX, destY - srcY, lprcScroll, lprcClip, 0, null, OS.SW_INVALIDATE | OS.SW_ERASE);
+
+ /*
+ * 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);
+ 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 createDIB(int width, int height) {
+ short depth = 32;
+
+ BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
+ bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
+ bmiHeader.biWidth = width;
+ bmiHeader.biHeight = -height;
+ bmiHeader.biPlanes = 1;
+ bmiHeader.biBitCount = 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];
+ int hDib = OS.CreateDIBSection(0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0);
+ if (hDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ return hDib;
+}
+
+/**
+ * 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;
+
+ /*
+ * The only way for pens and brushes to get
+ * selected into the HDC is for the receiver to
+ * create them. When we are destroying the
+ * hDC we also destroy any pens and brushes that
+ * we have allocated. This code assumes that it
+ * is OK to delete stock objects. This will
+ * happen when a GC is disposed and the user has
+ * not caused new pens or brushes to be allocated.
+ */
+ int nullPen = OS.GetStockObject(OS.NULL_PEN);
+ int oldPen = OS.SelectObject(handle, nullPen);
+ OS.DeleteObject(oldPen);
+ int nullBrush = OS.GetStockObject(OS.NULL_BRUSH);
+ int oldBrush = OS.SelectObject(handle, nullBrush);
+ OS.DeleteObject(oldBrush);
+
+ /*
+ * 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;
+ 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 IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.</li>
+ * </ul>
+ * @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 endAngle) {
+ 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 || endAngle == 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ /*
+ * 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 (endAngle < 0) {
+ startAngle += endAngle;
+ endAngle = -endAngle;
+ }
+ if (endAngle > 360) endAngle = 360;
+ int[] points = new int[(endAngle + 1) * 2];
+ int cteX = 2 * x + width;
+ int cteY = 2 * y + height;
+ int index = 0;
+ for (int i = 0; i <= endAngle; 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 (endAngle >= 360 || endAngle <= -360) {
+ x1 = x2 = x + width;
+ y1 = y2 = y + height / 2;
+ } else {
+ isNegative = endAngle < 0;
+
+ endAngle = endAngle + startAngle;
+ if (isNegative) {
+ // swap angles
+ tmp = startAngle;
+ startAngle = endAngle;
+ endAngle = tmp;
+ }
+ x1 = Compatibility.cos(startAngle, width) + x + width/2;
+ y1 = -1 * Compatibility.sin(startAngle, height) + y + height/2;
+
+ x2 = Compatibility.cos(endAngle, width) + x + width/2;
+ y2 = -1 * Compatibility.sin(endAngle, 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
+ */
+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 SWTError <ul>
+ * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</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 SWTError <ul>
+ * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</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) {
+ 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;
+ default:
+ SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
+ }
+}
+
+void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
+ /* Simple case: no stretching, entire icon */
+ if (simple) {
+ OS.DrawIconEx(handle, destX, destY, srcImage.handle, 0, 0, 0, 0, OS.DI_NORMAL);
+ 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 (simple) {
+ /* Simple case: no stretching, entire icon */
+ OS.DrawIconEx(handle, destX, destY, srcImage.handle, 0, 0, 0, 0, OS.DI_NORMAL);
+ } else {
+ /* Get the HDC for the device */
+ Device device = data.device;
+ int hDC = device.internal_new_GC(null);
+
+ /* Create the icon info and HDC's */
+ ICONINFO newIconInfo = new ICONINFO();
+ newIconInfo.fIcon = true;
+ int srcHdc = OS.CreateCompatibleDC(hDC);
+ int dstHdc = OS.CreateCompatibleDC(hDC);
+
+ /* 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);
+ if (!OS.IsWinCE) OS.SetStretchBltMode(dstHdc, OS.COLORONCOLOR);
+ OS.StretchBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcColorY, srcWidth, srcHeight, 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);
+ OS.StretchBlt(dstHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCCOPY);
+
+ /* Select old bitmaps before creating the icon */
+ OS.SelectObject(srcHdc, oldSrcBitmap);
+ OS.SelectObject(dstHdc, oldDestBitmap);
+
+ /* Create the new icon */
+ int hIcon = OS.CreateIconIndirect(newIconInfo);
+ if (hIcon == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+
+ /* Draw the new icon */
+ OS.DrawIconEx(handle, destX, destY, hIcon, destWidth, destHeight, 0, 0, OS.DI_NORMAL);
+
+ /* Destroy the new icon and hdc's*/
+ OS.DestroyIcon(hIcon);
+ OS.DeleteObject(newIconInfo.hbmMask);
+ OS.DeleteObject(newIconInfo.hbmColor);
+ OS.DeleteDC(dstHdc);
+ OS.DeleteDC(srcHdc);
+
+ /* Release the HDC for the device */
+ device.internal_dispose_GC(hDC, null);
+ }
+ }
+
+ /* 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()) {
+ 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;
+ }
+
+ /* 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 = createDIB(Math.max(srcWidth, destWidth), Math.max(srcHeight, destHeight));
+ 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 */
+ if (!OS.IsWinCE) OS.SetStretchBltMode(memHdc, OS.COLORONCOLOR);
+ 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 = createDIB(destWidth, destHeight);
+ int oldTempBitmap = OS.SelectObject(tempHdc, tempDib);
+ OS.StretchBlt(tempHdc, 0, 0, destWidth, destHeight, memHdc, 0, 0, srcWidth, srcHeight, 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 {
+ OS.StretchBlt(memHdc, 0, 0, destWidth, destHeight, memHdc, 0, 0, srcWidth, srcHeight, 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 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) {
+
+ /* Get the HDC for the device */
+ Device device = data.device;
+ int hDC = device.internal_new_GC(null);
+
+ /* 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;
+ 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 {
+ /* 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;
+ }
+ }
+
+ 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.
+ */
+ int transparentColor = transBlue << 16 | transGreen << 8 | transRed;
+ OS.TransparentImage(handle, destX, destY, destWidth, destHeight,
+ srcHdc, srcX, srcY, srcWidth, srcHeight, transparentColor);
+ } else {
+ /* Create the mask for the source image */
+ int maskHdc = OS.CreateCompatibleDC(hDC);
+ int maskBitmap = OS.CreateBitmap(imgWidth, imgHeight, 1, 1, null);
+ int oldMaskBitmap = OS.SelectObject(maskHdc, maskBitmap);
+ OS.SetBkColor(srcHdc, (transBlue << 16) | (transGreen << 8) | transRed);
+ OS.BitBlt(maskHdc, 0, 0, imgWidth, imgHeight, srcHdc, 0, 0, OS.SRCCOPY);
+ if (originalColors != null) OS.SetDIBColorTable(srcHdc, 0, 1 << bm.bmBitsPixel, originalColors);
+
+ /* Draw the source bitmap transparently using invert/and mask/invert */
+ int tempHdc = OS.CreateCompatibleDC(hDC);
+ int tempBitmap = OS.CreateCompatibleBitmap(hDC, destWidth, destHeight);
+ int oldTempBitmap = OS.SelectObject(tempHdc, tempBitmap);
+ OS.BitBlt(tempHdc, 0, 0, destWidth, destHeight, handle, destX, destY, OS.SRCCOPY);
+ 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);
+ OS.BitBlt(handle, destX, destY, destWidth, destHeight, tempHdc, 0, 0, OS.SRCCOPY);
+
+ /* Release resources */
+ 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);
+
+ /* Release the HDC for the device */
+ device.internal_dispose_GC(hDC, null);
+}
+
+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 mode = 0, rop2 = 0;
+ if (!OS.IsWinCE) {
+ rop2 = OS.GetROP2(handle);
+ mode = OS.SetStretchBltMode(handle, OS.COLORONCOLOR);
+ } else {
+ rop2 = OS.SetROP2 (handle, OS.R2_COPYPEN);
+ OS.SetROP2 (handle, rop2);
+ }
+ int dwRop = rop2 == OS.R2_XORPEN ? OS.SRCINVERT : OS.SRCCOPY;
+ OS.StretchBlt(handle, destX, destY, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, dwRop);
+ if (!OS.IsWinCE) {
+ OS.SetStretchBltMode(handle, mode);
+ }
+ 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);
+ 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);
+ }
+ 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);
+ // 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 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 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);
+ OS.Polyline(handle, pointArray, pointArray.length / 2);
+}
+
+/**
+ * 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 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.
+ *
+ * @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 horizontal diameter of the arc at the four corners
+ * @param arcHeight the vertical diameter of the arc at the four corners
+ *
+ * @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 (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-1, x+width-arcWidth/2, y+height-1);
+ }
+ if (arcHeight < height) {
+ drawLine(x, y+arcHeight/2, x, y+height-arcHeight/2);
+ drawLine(x+width-1, y+arcHeight/2, x+width-1, y+height-arcHeight/2);
+ }
+ if (arcWidth != 0 && arcHeight != 0) {
+ drawArc(x, y, arcWidth, arcHeight, 90, 90);
+ drawArc(x+width-arcWidth-1, y, arcWidth, arcHeight, 0, 90);
+ drawArc(x+width-arcWidth-1, y+height-arcHeight-1, arcWidth, arcHeight, 0, -90);
+ drawArc(x, y+height-arcHeight-1, 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,y+height, arcWidth, arcHeight);
+ OS.SelectObject(handle,oldBrush);
+ }
+}
+
+/**
+ * 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();
+ char[] buffer = new char [length];
+ string.getChars(0, length, buffer, 0);
+ int oldBkMode = OS.SetBkMode(handle, isTransparent ? OS.TRANSPARENT : OS.OPAQUE);
+ OS.ExtTextOutW(handle, x, y, 0, null, buffer, length, null);
+ 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);
+ RECT rect = new RECT();
+ OS.SetRect(rect, x, y, 0x7FFF, 0x7FFF);
+ TCHAR buffer = new TCHAR(getCodePage(), string, false);
+ 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 oldBkMode = OS.SetBkMode(handle, (flags & SWT.DRAW_TRANSPARENT) != 0 ? OS.TRANSPARENT : OS.OPAQUE);
+ OS.DrawText(handle, buffer, buffer.length(), rect, uFormat);
+ 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 IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.</li>
+ * </ul>
+ * @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 endAngle) {
+ 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 || endAngle == 0) {
+ SWT.error (SWT.ERROR_INVALID_ARGUMENT);
+ }
+
+ /*
+ * 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 (endAngle < 0) {
+ startAngle += endAngle;
+ endAngle = -endAngle;
+ }
+ boolean drawSegments = true;
+ if (endAngle >= 360) {
+ endAngle = 360;
+ drawSegments = false;
+ }
+ int[] points = new int[(endAngle + 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 <= endAngle; 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 (endAngle >= 360 || endAngle <= -360) {
+ x1 = x2 = x + width;
+ y1 = y2 = y + height / 2;
+ } else {
+ isNegative = endAngle < 0;
+
+ endAngle = endAngle + startAngle;
+ if (isNegative) {
+ // swap angles
+ tmp = startAngle;
+ startAngle = endAngle;
+ endAngle = tmp;
+ }
+ x1 = Compatibility.cos(startAngle, width) + x + width/2;
+ y1 = -1 * Compatibility.sin(startAngle, height) + y + height/2;
+
+ x2 = Compatibility.cos(endAngle, width) + x + width/2;
+ y2 = -1 * Compatibility.sin(endAngle, 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
+ */
+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;
+ }
+ 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)) {
+ OS.PatBlt(handle, x, y, width, height, OS.PATCOPY);
+ return;
+ }
+
+ /* Use GradientFill if supported, only on Windows 98, 2000 and newer */
+ if (!OS.IsWinCE) {
+ 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);
+
+ /* 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 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);
+ 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
+ */
+public void fillRectangle (int x, int y, int width, int height) {
+ 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);
+ }
+ 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 rectangle 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
+ */
+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 horizontal diameter of the arc at the four corners
+ * @param arcHeight the vertical diameter of the arc at the four corners
+ *
+ * @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 nullPen = OS.GetStockObject(OS.NULL_PEN);
+ int oldPen = OS.SelectObject(handle, nullPen);
+ OS.RoundRect(handle, x,y,x+width,y+height,arcWidth, arcHeight);
+ OS.SelectObject(handle,oldPen);
+}
+
+/**
+ * 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 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 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 tm = new TEXTMETRIC();
+ OS.GetTextMetricsW(handle, tm);
+ SIZE size = new SIZE();
+ OS.GetTextExtentPoint32W(handle, new char[]{ch}, 1, size);
+ return size.cx - tm.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);
+ 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>
+ * </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 result = OS.GetClipRgn (handle, region.handle);
+ if (result == 1) return;
+ RECT rect = new RECT();
+ OS.GetClipBox(handle, rect);
+ OS.SetRectRgn(region.handle, rect.left, rect.top, rect.right, rect.bottom);
+}
+
+int getCodePage () {
+ if (OS.IsWinCE) return OS.GetACP();
+ int[] lpCs = new int[8];
+ int cs = OS.GetTextCharset(handle);
+ OS.TranslateCharsetInfo(cs, lpCs, OS.TCI_SRCCHARSET);
+ return lpCs[1];
+}
+
+/**
+ * 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 = new TEXTMETRIC();
+ 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 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 hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
+ LOGPEN logPen = new LOGPEN();
+ OS.GetObject(hPen, LOGPEN.sizeof, logPen);
+ switch (logPen.lopnStyle) {
+ 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;
+ 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 hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
+ LOGPEN logPen = new LOGPEN();
+ OS.GetObject(hPen, LOGPEN.sizeof, logPen);
+ return logPen.x;
+}
+
+/**
+ * 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 init(Drawable drawable, GCData data, int hDC) {
+ int foreground = data.foreground;
+ if (foreground != -1 && OS.GetTextColor(hDC) != foreground) {
+ OS.SetTextColor(hDC, foreground);
+ int hPen = OS.CreatePen(OS.PS_SOLID, 0, foreground);
+ OS.SelectObject(hDC, hPen);
+ }
+ int background = data.background;
+ if (background != -1 && OS.GetBkColor(hDC) != background) {
+ OS.SetBkColor(hDC, background);
+ int hBrush = OS.CreateSolidBrush(background);
+ OS.SelectObject(hDC, hBrush);
+ }
+ 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;
+ }
+ this.drawable = drawable;
+ this.data = data;
+ handle = hDC;
+}
+
+/**
+ * Returns an integer hash code for the receiver. Any two
+ * objects which 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;
+}
+
+/**
+ * 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 (OS.GetBkColor(handle) == color.handle) return;
+ OS.SetBkColor (handle, color.handle);
+ int newBrush = OS.CreateSolidBrush (color.handle);
+ int oldBrush = OS.SelectObject (handle, newBrush);
+ OS.DeleteObject (oldBrush);
+}
+
+/**
+ * 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);
+ OS.SelectClipRgn (handle, hRgn);
+ OS.DeleteObject (hRgn);
+}
+
+/**
+ * Sets the area of the receiver which can be changed
+ * by drawing operations to the rectangular area specified
+ * by the argument.
+ *
+ * @param rect the clipping rectangle
+ *
+ * @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) {
+ OS.SelectClipRgn (handle, 0);
+ return;
+ }
+ 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.
+ *
+ * @param rect the clipping region.
+ *
+ * @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);
+ int hRegion = 0;
+ if (region != null) hRegion = region.handle;
+ OS.SelectClipRgn (handle, hRegion);
+}
+
+/**
+ * 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 (OS.GetTextColor(handle) == color.handle) return;
+ int hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
+ LOGPEN logPen = new LOGPEN();
+ OS.GetObject(hPen, LOGPEN.sizeof, logPen);
+ OS.SetTextColor (handle, color.handle);
+ int newPen = OS.CreatePen (logPen.lopnStyle, logPen.x, color.handle);
+ int oldPen = OS.SelectObject (handle, newPen);
+ OS.DeleteObject (oldPen);
+}
+
+/**
+ * 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 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;
+ default:
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ int hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
+ LOGPEN logPen = new LOGPEN();
+ OS.GetObject(hPen, LOGPEN.sizeof, logPen);
+ if (logPen.lopnStyle == style) return;
+ OS.SetBkMode (handle, style == OS.PS_SOLID ? OS.OPAQUE : OS.TRANSPARENT);
+ int newPen = OS.CreatePen(style, logPen.x, logPen.lopnColor);
+ int oldPen = OS.SelectObject(handle, newPen);
+ OS.DeleteObject(oldPen);
+}
+
+/**
+ * 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.
+ *
+ * @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 hPen = OS.GetCurrentObject(handle, OS.OBJ_PEN);
+ LOGPEN logPen = new LOGPEN();
+ OS.GetObject(hPen, LOGPEN.sizeof, logPen);
+ if (logPen.x == lineWidth) return;
+ int newPen = OS.CreatePen(logPen.lopnStyle, lineWidth, logPen.lopnColor);
+ int oldPen = OS.SelectObject(handle, newPen);
+ OS.DeleteObject(oldPen);
+}
+
+/**
+ * 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.
+ *
+ * @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>
+ */
+public void setXORMode(boolean xor) {
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (xor) {
+ OS.SetROP2(handle, OS.R2_XORPEN);
+ } else {
+ OS.SetROP2(handle, OS.R2_COPYPEN);
+ }
+}
+
+/**
+ * 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);
+ SIZE size = new SIZE();
+ int length = string.length();
+ 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 (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>
+ *
+ * @private
+ */
+public static GC win32_new(Drawable drawable, GCData data) {
+ GC gc = new GC();
+ int hDC = drawable.internal_new_GC(data);
+ gc.init(drawable, 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
index 82c2b4913b..2783b746d6 100755
--- 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
@@ -1,34 +1,34 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- *
- * @private
- */
-
-public final class GCData {
- public Device device;
- public Image image;
- public int foreground = -1;
- public int background = -1;
- public int hFont;
- public int hNullBitmap;
- public int hwnd;
- public PAINTSTRUCT ps;
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>
+ *
+ * @private
+ */
+
+public final class GCData {
+ public Device device;
+ public Image image;
+ public int foreground = -1;
+ public int background = -1;
+ public int hFont;
+ public int hNullBitmap;
+ public int hwnd;
+ public PAINTSTRUCT ps;
}
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
index d21dcd7a46..10e16f4dfc 100755
--- 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
@@ -1,1902 +1,1902 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 explicitely 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 implements Drawable {
-
- /**
- * specifies whether the receiver is a bitmap or an icon
- * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
- */
- public int type;
-
- /**
- * the OS resource of the image
- * (Warning: This field is platform dependent)
- */
- public int handle;
-
- /**
- * the device where this image was created
- */
- Device device;
-
- /**
- * specifies the transparent pixel
- * (Warning: This field is platform dependent)
- */
- int transparentPixel = -1;
-
- /**
- * the GC which is drawing on the image
- * (Warning: This field is platform dependent)
- */
- GC memGC;
-
- /**
- * the alpha data for the image
- * (Warning: This field is platform dependent)
- */
- byte[] alphaData;
-
- /**
- * the global alpha value to be used for every pixel
- * (Warning: This field is platform dependent)
- */
- int alpha = -1;
-
- /**
- * the image data used to create this image if it is a
- * icon. Used only in WinCE
- * (Warning: This field is platform dependent)
- */
- ImageData data;
-
- /**
- * specifies the default scanline padding
- * (Warning: This field is platform dependent)
- */
- 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>
- * </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: {
- Rectangle r = srcImage.getBounds();
- 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);
- handle = OS.CreateCompatibleBitmap(hdcSource, r.width, r.height);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int hOldDest = OS.SelectObject(hdcDest, handle);
- OS.BitBlt(hdcDest, 0, 0, r.width, r.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, r.width, r.height, 0);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- }
- break;
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- }
- if (device.tracking) device.new_Object(this);
- return;
- }
- case SWT.IMAGE_DISABLE: {
- Rectangle r = srcImage.getBounds();
- this.type = srcImage.type;
- byte[] rgbBwBitmapInfo = {
- 40,0,0,0, /* biSize */
- (byte)(r.width & 0xFF), /* biWidth */
- (byte)((r.width & 0xFF00) >> 8),
- (byte)((r.width & 0xFF0000) >> 16),
- (byte)((r.width & 0xFF000000) >> 24),
- (byte)(r.height & 0xFF), /* biHeight */
- (byte)((r.height & 0xFF00) >> 8),
- (byte)((r.height & 0xFF0000) >> 16),
- (byte)((r.height & 0xFF000000) >> 24),
- 1,0, /* biPlanes */
- 1,0, /* biBitCount */
- 0,0,0,0, /* biCompression */
- 0,0,0,0, /* biSizeImage */
- 0,0,0,0, /* biXPelsPerMeter */
- 0,0,0,0, /* biYPelsPerMeter */
- 0,0,0,0, /* biClrUsed */
- 0,0,0,0, /* biClrImportant */
- 0,0,0,0, /* First color: black */
- (byte)0xFF,(byte)0xFF,(byte)0xFF,0 /* Second color: white */
- };
-
- /* Get the HDC for the device */
- int hDC = device.internal_new_GC(null);
-
- /* Source DC */
- int hdcSource = OS.CreateCompatibleDC(hDC);
- if (hdcSource == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- /* Monochrome (Intermediate) DC */
- int bwDC = OS.CreateCompatibleDC(hdcSource);
- if (bwDC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- /* Destination DC */
- int hdcBmp = OS.CreateCompatibleDC(hDC);
- if (hdcBmp == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- /* Monochrome (Intermediate) DIB section */
- int[] pbitsBW = new int[1];
- int hbmBW = OS.CreateDIBSection(bwDC, rgbBwBitmapInfo, OS.DIB_RGB_COLORS, pbitsBW, 0, 0);
- if (hbmBW == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- switch (type) {
- case SWT.BITMAP:
- /* Attach the bitmap to the source DC */
- int hOldSrc = OS.SelectObject(hdcSource, srcImage.handle);
- /* Create the destination bitmap */
- handle = OS.CreateCompatibleBitmap(hDC, r.width, r.height);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- /* Attach the DIB section and the new bitmap to the DCs */
- int hOldBw = OS.SelectObject(bwDC, hbmBW);
- int hOldBmp = OS.SelectObject(hdcBmp, handle);
- /* BitBlt the bitmap into the monochrome DIB section */
- OS.BitBlt(bwDC, 0, 0, r.width, r.height, hdcSource, 0, 0, OS.SRCCOPY);
- /* Paint the destination rectangle in gray */
- RECT rect = new RECT();
- rect.left = 0;
- rect.top = 0;
- rect.right = r.width;
- rect.bottom = r.height;
- OS.FillRect(hdcBmp, rect, OS.GetSysColorBrush(OS.COLOR_3DFACE));
- /*
- * BitBlt the black bits in the monochrome bitmap into
- * COLOR_3DHILIGHT bits in the destination DC.
- * The magic ROP comes from Charles Petzold's book
- */
- int hb = OS.CreateSolidBrush(OS.GetSysColor(OS.COLOR_3DHILIGHT));
- int oldBrush = OS.SelectObject(hdcBmp, hb);
- OS.BitBlt(hdcBmp, 1, 1, r.width, r.height, bwDC, 0, 0, 0xB8074A);
- /*
- * BitBlt the black bits in the monochrome bitmap into
- * COLOR_3DSHADOW bits in the destination DC.
- */
- hb = OS.CreateSolidBrush(OS.GetSysColor(OS.COLOR_3DSHADOW));
- OS.DeleteObject(OS.SelectObject(hdcBmp, hb));
- OS.BitBlt(hdcBmp, 0, 0, r.width, r.height, bwDC, 0, 0, 0xB8074A);
- OS.DeleteObject(OS.SelectObject(hdcBmp, oldBrush));
- /* Free resources */
- OS.SelectObject(hdcSource, hOldSrc);
- OS.SelectObject(hdcBmp, hOldBmp);
- OS.SelectObject(bwDC, hOldBw);
- OS.DeleteDC(hdcSource);
- OS.DeleteDC(bwDC);
- OS.DeleteDC(hdcBmp);
- OS.DeleteObject(hbmBW);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
- break;
- case SWT.ICON:
- /* Get icon information */
- ICONINFO iconInfo = new ICONINFO();
- if (OS.IsWinCE) {
- GetIconInfo(srcImage, iconInfo);
- } else {
- if (!OS.GetIconInfo(srcImage.handle, iconInfo))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- int hdcMask = OS.CreateCompatibleDC(hDC);
- /* Create the destination bitmaps */
- if (iconInfo.hbmColor == 0)
- hOldSrc = OS.SelectObject(hdcSource, iconInfo.hbmMask);
- else
- hOldSrc = OS.SelectObject(hdcSource, iconInfo.hbmColor);
- int newHbmp = OS.CreateCompatibleBitmap(hdcSource, r.width, r.height);
- if (newHbmp == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int newHmask = OS.CreateBitmap(r.width, r.height, 1, 1, null);
- if (newHmask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- /* BitBlt the source mask into the destination mask */
- int hOldMask = OS.SelectObject(hdcMask, newHmask);
- if (iconInfo.hbmColor != 0)
- OS.SelectObject(hdcSource, iconInfo.hbmMask);
- OS.SelectObject(hdcSource, iconInfo.hbmMask);
- OS.BitBlt(hdcMask, 0, 0, r.width, r.height, hdcSource, 0, 0, OS.SRCCOPY);
- /* Attach the monochrome DIB section and the destination bitmap to the DCs */
- hOldBw = OS.SelectObject(bwDC, hbmBW);
- /* BitBlt the bitmap into the monochrome DIB section */
- if (iconInfo.hbmColor == 0) {
- OS.SelectObject(hdcSource, iconInfo.hbmMask);
- OS.BitBlt(bwDC, 0, 0, r.width, r.height, hdcSource, 0, r.height, OS.SRCCOPY);
- } else {
- OS.SelectObject(hdcSource, iconInfo.hbmColor);
- OS.BitBlt(bwDC, 0, 0, r.width, r.height, hdcSource, 0, 0, OS.SRCCOPY);
- }
- /* Paint the destination rectangle in grey */
- rect = new RECT();
- rect.left = 0;
- rect.top = 0;
- rect.right = r.width;
- rect.bottom = r.height;
- hOldBmp = OS.SelectObject(hdcBmp, newHbmp);
- OS.FillRect(hdcBmp, rect, OS.GetSysColorBrush(OS.COLOR_3DFACE));
- /*
- * BitBlt the black bits in the monochrome bitmap into
- * COLOR_3DHILIGHT bits in the destination DC.
- * The magic ROP comes from Charles Petzold's book
- */
- hb = OS.CreateSolidBrush(OS.GetSysColor(OS.COLOR_3DSHADOW));
- oldBrush = OS.SelectObject(hdcBmp, hb);
- OS.BitBlt(hdcBmp, 0, 0, r.width, r.height, bwDC, 0, 0, 0xB8074A);
- /* Invert mask into hdcBw */
- OS.BitBlt(bwDC, 0, 0, r.width, r.height, hdcMask, 0, 0, OS.NOTSRCCOPY);
- /* Select black brush into destination */
- hb = OS.CreateSolidBrush(0);
- OS.DeleteObject(OS.SelectObject(hdcBmp, hb));
- /*
- * Copy black bits from monochrome bitmap into black bits in the
- * destination DC.
- */
- OS.BitBlt(hdcBmp, 0, 0, r.width, r.height, bwDC, 0, 0, 0xB8074A);
- OS.DeleteObject(OS.SelectObject(hdcBmp, oldBrush));
- /* Free resources */
- OS.SelectObject(hdcSource, hOldSrc);
- OS.DeleteDC(hdcSource);
- OS.SelectObject(bwDC, hOldBw);
- OS.DeleteDC(bwDC);
- OS.SelectObject(hdcBmp, hOldBmp);
- OS.DeleteDC(hdcBmp);
- OS.SelectObject(hdcMask, hOldMask);
- OS.DeleteDC(hdcMask);
- OS.DeleteObject(hbmBW);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
-
- /* Create the new iconinfo */
- ICONINFO newIconInfo = new ICONINFO();
- newIconInfo.fIcon = iconInfo.fIcon;
- newIconInfo.hbmMask = newHmask;
- newIconInfo.hbmColor = newHbmp;
- /* Create the new icon */
- handle = OS.CreateIconIndirect(newIconInfo);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- /* Free bitmaps */
- OS.DeleteObject(newHbmp);
- OS.DeleteObject(newHmask);
- if (iconInfo.hbmColor != 0)
- OS.DeleteObject(iconInfo.hbmColor);
- OS.DeleteObject(iconInfo.hbmMask);
- break;
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- }
- 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.maskData = data.maskData;
- newData.maskPad = data.maskPad;
-
- /* 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];
- 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;
- newData.data[offset++] =
- (byte)((red+red+green+green+green+green+green+blue) >> 3);
- }
- }
- }
- 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 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, and the mask image
- * must have a color depth of 1. Pixel transparency in either image
- * will be ignored. If either image is an icon to begin with, an
- * exception is thrown.
- * <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 or
- * if the mask is not monochrome, or if either the source or mask
- * is already an icon</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);
- }
- if (mask.depth != 1) {
- /*
- * Feature in Windows. 1-bit DIB sections are buggy on Win98, so we
- * create 4-bit DIBs when given a 1-bit ImageData. In order to allow
- * users to draw on the masks, we must also support 4-bit masks in
- * icon creation by converting them into 1-bit masks.
- */
- if (mask.depth != 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- PaletteData palette = new PaletteData(new RGB[] {new RGB(0, 0, 0), new RGB(255,255,255)});
- ImageData tempMask = new ImageData(mask.width, mask.height, 1, palette);
- /* Find index of black in mask palette */
- RGB[] rgbs = mask.getRGBs();
- int blackIndex = 0;
- while (blackIndex < rgbs.length) {
- if (rgbs[blackIndex].equals(palette.colors[0])) break;
- blackIndex++;
- }
- if (blackIndex == rgbs.length) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- 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;
- }
- }
- tempMask.setPixels(0, y, mask.width, pixels, 0);
- }
- mask = tempMask;
- }
- /* Create a temporary image and locate the black pixel */
- ImageData image;
- int blackIndex = 0;
- if (source.palette.isDirect) {
- image = 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;
- image = 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;
- }
- }
- image = 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, image.data, 0, image.data.length);
- } else {
- /* Modify the source image to contain black wherever the mask is 0 */
- int[] imagePixels = new int[image.width];
- int[] maskPixels = new int[mask.width];
- for (int y = 0; y < image.height; y++) {
- source.getPixels(0, y, image.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;
- }
- image.setPixels(0, y, source.width, imagePixels, 0);
- }
- }
- /*
- * Make sure the mask is padded properly. Windows requires icon masks
- * to have a scanline pad of 2.
- */
- int bytesPerLine = (((mask.width + 7) / 8) + 1) / 2 * 2;
- byte[] newMaskData = new byte[bytesPerLine * mask.height];
- ImageData newMask = new ImageData(mask.width, mask.height, 1, mask.palette, 2, newMaskData);
- int[] maskPixels = new int[mask.width];
- for (int y = 0; y < mask.height; y++) {
- mask.getPixels(0, y, mask.width, maskPixels, 0);
- newMask.setPixels(0, y, newMask.width, maskPixels, 0);
- }
- /* Set the fields and create the icon */
- image.maskPad = newMask.scanlinePad;
- image.maskData = newMask.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.
- * <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>
- * new Image(device, clazz.getResourceAsStream("file.gif"));
- * </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_INVALID_IMAGE - if the image file contains invalid data </li>
- * <li>ERROR_IO - if an IO error occurs while reading data</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_INVALID_IMAGE - if the image file contains invalid data </li>
- * <li>ERROR_IO - if an IO error occurs while reading data</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 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;
-}
-
-/**
- * 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 (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);
- switch (type) {
- case SWT.BITMAP:
- BITMAP bm = new BITMAP();
- OS.GetObject(handle, BITMAP.sizeof, bm);
- return new Rectangle(0, 0, bm.bmWidth, bm.bmHeight);
- case SWT.ICON:
- if (OS.IsWinCE) {
- return new Rectangle(0, 0, data.width, 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, bm.bmWidth, bm.bmHeight);
- }
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- 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 desiredScanline = (width + 7) / 8;
- desiredScanline = desiredScanline + (desiredScanline % 2);
- int realScanline = imageSize / height;
- if (realScanline != desiredScanline) {
- byte[] newData = new byte[desiredScanline * height];
- int srcIndex = 0;
- int destIndex = 0;
- for (int i = 0; i < height; i++) {
- System.arraycopy(maskData, srcIndex, newData, destIndex, desiredScanline);
- destIndex += desiredScanline;
- srcIndex += realScanline;
- }
- maskData = newData;
- }
- }
- /* 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 = 4;
- 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()) {
- 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_UNSUPPORTED_FORMAT);
- return null;
- }
-}
-
-/**
- * Returns an integer hash code for the receiver. Any two
- * objects which 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;
-
- /* Get the HDC for the device */
- int hDC = device.internal_new_GC(null);
-
- /* Fill the bitmap with the current background color */
- handle = OS.CreateCompatibleBitmap(hDC, width, height);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- 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);
-
- /* Release the HDC for the device */
- device.internal_dispose_GC(hDC, null);
-}
-
-/**
- * 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 ((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)) {
- int newBpl = i.bytesPerLine + (4 - (i.bytesPerLine % 4));
- byte[] newData = new byte[i.height * newBpl];
- int srcPtr = 0;
- int destPtr = 0;
- for (int y = 0; y < i.height; y++) {
- System.arraycopy(data, srcPtr, newData, destPtr, i.bytesPerLine);
- srcPtr += i.bytesPerLine;
- destPtr += newBpl;
- }
- data = newData;
- }
- 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 */
-// int hHeap = OS.GetProcessHeap();
-// int bmBits = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, i.maskData.length);
-// OS.MoveMemory(bmBits, i.maskData, i.maskData.length);
-// BITMAP bm = new BITMAP();
-// bm.bmWidth = i.width;
-// bm.bmHeight = i.height;
-// bm.bmWidthBytes = (((i.width + 7) / 8) + 3) / 4 * 4;
-// bm.bmPlanes = 1;
-// bm.bmBitsPixel = 1;
-// bm.bmBits = bmBits;
-// int hMask = OS.CreateBitmapIndirect(bm);
-// OS.HeapFree(hHeap, 0, bmBits);
- int hMask = OS.CreateBitmap(i.width, i.height, 1, 1, i.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;
-}
-
-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
- *
- * @private
- */
-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 */
- 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 handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
- */
-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
- * @param hPalette the OS handle for the palette, or 0
- *
- * @private
- */
-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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 explicitely 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 implements Drawable {
+
+ /**
+ * specifies whether the receiver is a bitmap or an icon
+ * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
+ */
+ public int type;
+
+ /**
+ * the OS resource of the image
+ * (Warning: This field is platform dependent)
+ */
+ public int handle;
+
+ /**
+ * the device where this image was created
+ */
+ Device device;
+
+ /**
+ * specifies the transparent pixel
+ * (Warning: This field is platform dependent)
+ */
+ int transparentPixel = -1;
+
+ /**
+ * the GC which is drawing on the image
+ * (Warning: This field is platform dependent)
+ */
+ GC memGC;
+
+ /**
+ * the alpha data for the image
+ * (Warning: This field is platform dependent)
+ */
+ byte[] alphaData;
+
+ /**
+ * the global alpha value to be used for every pixel
+ * (Warning: This field is platform dependent)
+ */
+ int alpha = -1;
+
+ /**
+ * the image data used to create this image if it is a
+ * icon. Used only in WinCE
+ * (Warning: This field is platform dependent)
+ */
+ ImageData data;
+
+ /**
+ * specifies the default scanline padding
+ * (Warning: This field is platform dependent)
+ */
+ 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>
+ * </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: {
+ Rectangle r = srcImage.getBounds();
+ 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);
+ handle = OS.CreateCompatibleBitmap(hdcSource, r.width, r.height);
+ if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int hOldDest = OS.SelectObject(hdcDest, handle);
+ OS.BitBlt(hdcDest, 0, 0, r.width, r.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, r.width, r.height, 0);
+ if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ }
+ break;
+ default:
+ SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
+ }
+ if (device.tracking) device.new_Object(this);
+ return;
+ }
+ case SWT.IMAGE_DISABLE: {
+ Rectangle r = srcImage.getBounds();
+ this.type = srcImage.type;
+ byte[] rgbBwBitmapInfo = {
+ 40,0,0,0, /* biSize */
+ (byte)(r.width & 0xFF), /* biWidth */
+ (byte)((r.width & 0xFF00) >> 8),
+ (byte)((r.width & 0xFF0000) >> 16),
+ (byte)((r.width & 0xFF000000) >> 24),
+ (byte)(r.height & 0xFF), /* biHeight */
+ (byte)((r.height & 0xFF00) >> 8),
+ (byte)((r.height & 0xFF0000) >> 16),
+ (byte)((r.height & 0xFF000000) >> 24),
+ 1,0, /* biPlanes */
+ 1,0, /* biBitCount */
+ 0,0,0,0, /* biCompression */
+ 0,0,0,0, /* biSizeImage */
+ 0,0,0,0, /* biXPelsPerMeter */
+ 0,0,0,0, /* biYPelsPerMeter */
+ 0,0,0,0, /* biClrUsed */
+ 0,0,0,0, /* biClrImportant */
+ 0,0,0,0, /* First color: black */
+ (byte)0xFF,(byte)0xFF,(byte)0xFF,0 /* Second color: white */
+ };
+
+ /* Get the HDC for the device */
+ int hDC = device.internal_new_GC(null);
+
+ /* Source DC */
+ int hdcSource = OS.CreateCompatibleDC(hDC);
+ if (hdcSource == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ /* Monochrome (Intermediate) DC */
+ int bwDC = OS.CreateCompatibleDC(hdcSource);
+ if (bwDC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ /* Destination DC */
+ int hdcBmp = OS.CreateCompatibleDC(hDC);
+ if (hdcBmp == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ /* Monochrome (Intermediate) DIB section */
+ int[] pbitsBW = new int[1];
+ int hbmBW = OS.CreateDIBSection(bwDC, rgbBwBitmapInfo, OS.DIB_RGB_COLORS, pbitsBW, 0, 0);
+ if (hbmBW == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ switch (type) {
+ case SWT.BITMAP:
+ /* Attach the bitmap to the source DC */
+ int hOldSrc = OS.SelectObject(hdcSource, srcImage.handle);
+ /* Create the destination bitmap */
+ handle = OS.CreateCompatibleBitmap(hDC, r.width, r.height);
+ if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ /* Attach the DIB section and the new bitmap to the DCs */
+ int hOldBw = OS.SelectObject(bwDC, hbmBW);
+ int hOldBmp = OS.SelectObject(hdcBmp, handle);
+ /* BitBlt the bitmap into the monochrome DIB section */
+ OS.BitBlt(bwDC, 0, 0, r.width, r.height, hdcSource, 0, 0, OS.SRCCOPY);
+ /* Paint the destination rectangle in gray */
+ RECT rect = new RECT();
+ rect.left = 0;
+ rect.top = 0;
+ rect.right = r.width;
+ rect.bottom = r.height;
+ OS.FillRect(hdcBmp, rect, OS.GetSysColorBrush(OS.COLOR_3DFACE));
+ /*
+ * BitBlt the black bits in the monochrome bitmap into
+ * COLOR_3DHILIGHT bits in the destination DC.
+ * The magic ROP comes from Charles Petzold's book
+ */
+ int hb = OS.CreateSolidBrush(OS.GetSysColor(OS.COLOR_3DHILIGHT));
+ int oldBrush = OS.SelectObject(hdcBmp, hb);
+ OS.BitBlt(hdcBmp, 1, 1, r.width, r.height, bwDC, 0, 0, 0xB8074A);
+ /*
+ * BitBlt the black bits in the monochrome bitmap into
+ * COLOR_3DSHADOW bits in the destination DC.
+ */
+ hb = OS.CreateSolidBrush(OS.GetSysColor(OS.COLOR_3DSHADOW));
+ OS.DeleteObject(OS.SelectObject(hdcBmp, hb));
+ OS.BitBlt(hdcBmp, 0, 0, r.width, r.height, bwDC, 0, 0, 0xB8074A);
+ OS.DeleteObject(OS.SelectObject(hdcBmp, oldBrush));
+ /* Free resources */
+ OS.SelectObject(hdcSource, hOldSrc);
+ OS.SelectObject(hdcBmp, hOldBmp);
+ OS.SelectObject(bwDC, hOldBw);
+ OS.DeleteDC(hdcSource);
+ OS.DeleteDC(bwDC);
+ OS.DeleteDC(hdcBmp);
+ OS.DeleteObject(hbmBW);
+
+ /* Release the HDC for the device */
+ device.internal_dispose_GC(hDC, null);
+ break;
+ case SWT.ICON:
+ /* Get icon information */
+ ICONINFO iconInfo = new ICONINFO();
+ if (OS.IsWinCE) {
+ GetIconInfo(srcImage, iconInfo);
+ } else {
+ if (!OS.GetIconInfo(srcImage.handle, iconInfo))
+ SWT.error(SWT.ERROR_INVALID_IMAGE);
+ }
+ int hdcMask = OS.CreateCompatibleDC(hDC);
+ /* Create the destination bitmaps */
+ if (iconInfo.hbmColor == 0)
+ hOldSrc = OS.SelectObject(hdcSource, iconInfo.hbmMask);
+ else
+ hOldSrc = OS.SelectObject(hdcSource, iconInfo.hbmColor);
+ int newHbmp = OS.CreateCompatibleBitmap(hdcSource, r.width, r.height);
+ if (newHbmp == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ int newHmask = OS.CreateBitmap(r.width, r.height, 1, 1, null);
+ if (newHmask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ /* BitBlt the source mask into the destination mask */
+ int hOldMask = OS.SelectObject(hdcMask, newHmask);
+ if (iconInfo.hbmColor != 0)
+ OS.SelectObject(hdcSource, iconInfo.hbmMask);
+ OS.SelectObject(hdcSource, iconInfo.hbmMask);
+ OS.BitBlt(hdcMask, 0, 0, r.width, r.height, hdcSource, 0, 0, OS.SRCCOPY);
+ /* Attach the monochrome DIB section and the destination bitmap to the DCs */
+ hOldBw = OS.SelectObject(bwDC, hbmBW);
+ /* BitBlt the bitmap into the monochrome DIB section */
+ if (iconInfo.hbmColor == 0) {
+ OS.SelectObject(hdcSource, iconInfo.hbmMask);
+ OS.BitBlt(bwDC, 0, 0, r.width, r.height, hdcSource, 0, r.height, OS.SRCCOPY);
+ } else {
+ OS.SelectObject(hdcSource, iconInfo.hbmColor);
+ OS.BitBlt(bwDC, 0, 0, r.width, r.height, hdcSource, 0, 0, OS.SRCCOPY);
+ }
+ /* Paint the destination rectangle in grey */
+ rect = new RECT();
+ rect.left = 0;
+ rect.top = 0;
+ rect.right = r.width;
+ rect.bottom = r.height;
+ hOldBmp = OS.SelectObject(hdcBmp, newHbmp);
+ OS.FillRect(hdcBmp, rect, OS.GetSysColorBrush(OS.COLOR_3DFACE));
+ /*
+ * BitBlt the black bits in the monochrome bitmap into
+ * COLOR_3DHILIGHT bits in the destination DC.
+ * The magic ROP comes from Charles Petzold's book
+ */
+ hb = OS.CreateSolidBrush(OS.GetSysColor(OS.COLOR_3DSHADOW));
+ oldBrush = OS.SelectObject(hdcBmp, hb);
+ OS.BitBlt(hdcBmp, 0, 0, r.width, r.height, bwDC, 0, 0, 0xB8074A);
+ /* Invert mask into hdcBw */
+ OS.BitBlt(bwDC, 0, 0, r.width, r.height, hdcMask, 0, 0, OS.NOTSRCCOPY);
+ /* Select black brush into destination */
+ hb = OS.CreateSolidBrush(0);
+ OS.DeleteObject(OS.SelectObject(hdcBmp, hb));
+ /*
+ * Copy black bits from monochrome bitmap into black bits in the
+ * destination DC.
+ */
+ OS.BitBlt(hdcBmp, 0, 0, r.width, r.height, bwDC, 0, 0, 0xB8074A);
+ OS.DeleteObject(OS.SelectObject(hdcBmp, oldBrush));
+ /* Free resources */
+ OS.SelectObject(hdcSource, hOldSrc);
+ OS.DeleteDC(hdcSource);
+ OS.SelectObject(bwDC, hOldBw);
+ OS.DeleteDC(bwDC);
+ OS.SelectObject(hdcBmp, hOldBmp);
+ OS.DeleteDC(hdcBmp);
+ OS.SelectObject(hdcMask, hOldMask);
+ OS.DeleteDC(hdcMask);
+ OS.DeleteObject(hbmBW);
+
+ /* Release the HDC for the device */
+ device.internal_dispose_GC(hDC, null);
+
+ /* Create the new iconinfo */
+ ICONINFO newIconInfo = new ICONINFO();
+ newIconInfo.fIcon = iconInfo.fIcon;
+ newIconInfo.hbmMask = newHmask;
+ newIconInfo.hbmColor = newHbmp;
+ /* Create the new icon */
+ handle = OS.CreateIconIndirect(newIconInfo);
+ if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ /* Free bitmaps */
+ OS.DeleteObject(newHbmp);
+ OS.DeleteObject(newHmask);
+ if (iconInfo.hbmColor != 0)
+ OS.DeleteObject(iconInfo.hbmColor);
+ OS.DeleteObject(iconInfo.hbmMask);
+ break;
+ default:
+ SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
+ }
+ 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.maskData = data.maskData;
+ newData.maskPad = data.maskPad;
+
+ /* 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];
+ 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;
+ newData.data[offset++] =
+ (byte)((red+red+green+green+green+green+green+blue) >> 3);
+ }
+ }
+ }
+ 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 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, and the mask image
+ * must have a color depth of 1. Pixel transparency in either image
+ * will be ignored. If either image is an icon to begin with, an
+ * exception is thrown.
+ * <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 or
+ * if the mask is not monochrome, or if either the source or mask
+ * is already an icon</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);
+ }
+ if (mask.depth != 1) {
+ /*
+ * Feature in Windows. 1-bit DIB sections are buggy on Win98, so we
+ * create 4-bit DIBs when given a 1-bit ImageData. In order to allow
+ * users to draw on the masks, we must also support 4-bit masks in
+ * icon creation by converting them into 1-bit masks.
+ */
+ if (mask.depth != 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ PaletteData palette = new PaletteData(new RGB[] {new RGB(0, 0, 0), new RGB(255,255,255)});
+ ImageData tempMask = new ImageData(mask.width, mask.height, 1, palette);
+ /* Find index of black in mask palette */
+ RGB[] rgbs = mask.getRGBs();
+ int blackIndex = 0;
+ while (blackIndex < rgbs.length) {
+ if (rgbs[blackIndex].equals(palette.colors[0])) break;
+ blackIndex++;
+ }
+ if (blackIndex == rgbs.length) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ 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;
+ }
+ }
+ tempMask.setPixels(0, y, mask.width, pixels, 0);
+ }
+ mask = tempMask;
+ }
+ /* Create a temporary image and locate the black pixel */
+ ImageData image;
+ int blackIndex = 0;
+ if (source.palette.isDirect) {
+ image = 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;
+ image = 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;
+ }
+ }
+ image = 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, image.data, 0, image.data.length);
+ } else {
+ /* Modify the source image to contain black wherever the mask is 0 */
+ int[] imagePixels = new int[image.width];
+ int[] maskPixels = new int[mask.width];
+ for (int y = 0; y < image.height; y++) {
+ source.getPixels(0, y, image.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;
+ }
+ image.setPixels(0, y, source.width, imagePixels, 0);
+ }
+ }
+ /*
+ * Make sure the mask is padded properly. Windows requires icon masks
+ * to have a scanline pad of 2.
+ */
+ int bytesPerLine = (((mask.width + 7) / 8) + 1) / 2 * 2;
+ byte[] newMaskData = new byte[bytesPerLine * mask.height];
+ ImageData newMask = new ImageData(mask.width, mask.height, 1, mask.palette, 2, newMaskData);
+ int[] maskPixels = new int[mask.width];
+ for (int y = 0; y < mask.height; y++) {
+ mask.getPixels(0, y, mask.width, maskPixels, 0);
+ newMask.setPixels(0, y, newMask.width, maskPixels, 0);
+ }
+ /* Set the fields and create the icon */
+ image.maskPad = newMask.scanlinePad;
+ image.maskData = newMask.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.
+ * <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>
+ * new Image(device, clazz.getResourceAsStream("file.gif"));
+ * </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_INVALID_IMAGE - if the image file contains invalid data </li>
+ * <li>ERROR_IO - if an IO error occurs while reading data</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_INVALID_IMAGE - if the image file contains invalid data </li>
+ * <li>ERROR_IO - if an IO error occurs while reading data</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 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;
+}
+
+/**
+ * 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 (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);
+ switch (type) {
+ case SWT.BITMAP:
+ BITMAP bm = new BITMAP();
+ OS.GetObject(handle, BITMAP.sizeof, bm);
+ return new Rectangle(0, 0, bm.bmWidth, bm.bmHeight);
+ case SWT.ICON:
+ if (OS.IsWinCE) {
+ return new Rectangle(0, 0, data.width, 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, bm.bmWidth, bm.bmHeight);
+ }
+ default:
+ SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
+ 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 desiredScanline = (width + 7) / 8;
+ desiredScanline = desiredScanline + (desiredScanline % 2);
+ int realScanline = imageSize / height;
+ if (realScanline != desiredScanline) {
+ byte[] newData = new byte[desiredScanline * height];
+ int srcIndex = 0;
+ int destIndex = 0;
+ for (int i = 0; i < height; i++) {
+ System.arraycopy(maskData, srcIndex, newData, destIndex, desiredScanline);
+ destIndex += desiredScanline;
+ srcIndex += realScanline;
+ }
+ maskData = newData;
+ }
+ }
+ /* 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 = 4;
+ 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()) {
+ 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_UNSUPPORTED_FORMAT);
+ return null;
+ }
+}
+
+/**
+ * Returns an integer hash code for the receiver. Any two
+ * objects which 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;
+
+ /* Get the HDC for the device */
+ int hDC = device.internal_new_GC(null);
+
+ /* Fill the bitmap with the current background color */
+ handle = OS.CreateCompatibleBitmap(hDC, width, height);
+ if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ 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);
+
+ /* Release the HDC for the device */
+ device.internal_dispose_GC(hDC, null);
+}
+
+/**
+ * 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 ((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)) {
+ int newBpl = i.bytesPerLine + (4 - (i.bytesPerLine % 4));
+ byte[] newData = new byte[i.height * newBpl];
+ int srcPtr = 0;
+ int destPtr = 0;
+ for (int y = 0; y < i.height; y++) {
+ System.arraycopy(data, srcPtr, newData, destPtr, i.bytesPerLine);
+ srcPtr += i.bytesPerLine;
+ destPtr += newBpl;
+ }
+ data = newData;
+ }
+ 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 */
+// int hHeap = OS.GetProcessHeap();
+// int bmBits = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, i.maskData.length);
+// OS.MoveMemory(bmBits, i.maskData, i.maskData.length);
+// BITMAP bm = new BITMAP();
+// bm.bmWidth = i.width;
+// bm.bmHeight = i.height;
+// bm.bmWidthBytes = (((i.width + 7) / 8) + 3) / 4 * 4;
+// bm.bmPlanes = 1;
+// bm.bmBitsPixel = 1;
+// bm.bmBits = bmBits;
+// int hMask = OS.CreateBitmapIndirect(bm);
+// OS.HeapFree(hHeap, 0, bmBits);
+ int hMask = OS.CreateBitmap(i.width, i.height, 1, 1, i.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;
+}
+
+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
+ *
+ * @private
+ */
+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 */
+ 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 handle the platform specific GC handle
+ * @param data the platform specific GC data
+ *
+ * @private
+ */
+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
+ * @param hPalette the OS handle for the palette, or 0
+ *
+ * @private
+ */
+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/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java
index 620983418b..a08b88d065 100755
--- 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
@@ -1,307 +1,307 @@
-package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 rectangles.
- * <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 {
-
- /**
- * the OS resource for the region
- * (Warning: This field is platform dependent)
- */
- 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 () {
- handle = OS.CreateRectRgn (0, 0, 0, 0);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-}
-
-/**
- * Constructs a new region given a handle to the operating
- * system resources that it should represent.
- *
- * @param handle the handle for the result
- */
-Region(int handle) {
- this.handle = handle;
-}
-
-/**
- * Adds the given rectangle to the collection of rectangles
- * the receiver maintains to describe its area.
- *
- * @param rect the rectangle to merge with the receiver
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void add (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- int rectRgn = OS.CreateRectRgn (rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
- OS.CombineRgn (handle, handle, rectRgn, OS.RGN_OR);
- OS.DeleteObject (rectRgn);
-}
-
-/**
- * Adds all of the rectangles which make up the area covered
- * by the argument to the collection of rectangles 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 (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) OS.DeleteObject (handle);
- handle = 0;
-}
-
-/**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode
- */
-public boolean equals (Object object) {
- if (this == object) return true;
- if (!(object instanceof Region)) return false;
- Region rgn = (Region)object;
- return handle == rgn.handle;
-}
-
-/**
- * Returns a rectangle which represents the rectangular
- * union of the collection of rectangles 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 which 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 rectangle described by the
- * arguments intersects with any of the rectangles the receiver
- * mainains 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
- */
-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 rectangles the receiver mainains 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
- */
-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);
- 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);
-}
-
-/**
- * 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 handle the handle for the region
- *
- * @private
- */
-public static Region win32_new(int handle) {
- return new Region(handle);
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-public String toString () {
- if (isDisposed()) return "Region {*DISPOSED*}";
- return "Region {" + handle + "}";
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 rectangles.
+ * <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 {
+
+ /**
+ * the OS resource for the region
+ * (Warning: This field is platform dependent)
+ */
+ 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 () {
+ handle = OS.CreateRectRgn (0, 0, 0, 0);
+ if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+}
+
+/**
+ * Constructs a new region given a handle to the operating
+ * system resources that it should represent.
+ *
+ * @param handle the handle for the result
+ */
+Region(int handle) {
+ this.handle = handle;
+}
+
+/**
+ * Adds the given rectangle to the collection of rectangles
+ * the receiver maintains to describe its area.
+ *
+ * @param rect the rectangle to merge with the receiver
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
+ * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
+ * </ul>
+ */
+public void add (Rectangle rect) {
+ if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+
+ int rectRgn = OS.CreateRectRgn (rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
+ OS.CombineRgn (handle, handle, rectRgn, OS.RGN_OR);
+ OS.DeleteObject (rectRgn);
+}
+
+/**
+ * Adds all of the rectangles which make up the area covered
+ * by the argument to the collection of rectangles 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 (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) OS.DeleteObject (handle);
+ handle = 0;
+}
+
+/**
+ * Compares the argument to the receiver, and returns true
+ * if they represent the <em>same</em> object using a class
+ * specific comparison.
+ *
+ * @param object the object to compare with this object
+ * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
+ *
+ * @see #hashCode
+ */
+public boolean equals (Object object) {
+ if (this == object) return true;
+ if (!(object instanceof Region)) return false;
+ Region rgn = (Region)object;
+ return handle == rgn.handle;
+}
+
+/**
+ * Returns a rectangle which represents the rectangular
+ * union of the collection of rectangles 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 which 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 rectangle described by the
+ * arguments intersects with any of the rectangles the receiver
+ * mainains 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
+ */
+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 rectangles the receiver mainains 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
+ */
+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);
+ 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);
+}
+
+/**
+ * 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 handle the handle for the region
+ *
+ * @private
+ */
+public static Region win32_new(int handle) {
+ return new Region(handle);
+}
+
+/**
+ * Returns a string containing a concise, human-readable
+ * description of the receiver.
+ *
+ * @return a string representation of the receiver
+ */
+public String toString () {
+ if (isDisposed()) return "Region {*DISPOSED*}";
+ return "Region {" + handle + "}";
+}
+
+}
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
index 1b39904fbd..73c1d4cd57 100644
--- 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
@@ -1,532 +1,532 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2001, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.internal.win32.GCP_RESULTS;
-import org.eclipse.swt.internal.win32.OS;
-import org.eclipse.swt.internal.win32.RECT;
-import org.eclipse.swt.internal.win32.TCHAR;
-import java.util.Hashtable;
-/*
- * 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 map = 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";
- static Callback callback;
- static {
- try {
- callback = new Callback (Class.forName (CLASS_NAME), "windowProc", 4);
- } 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 int GCPGLYPH_LINKBEFORE = 0x8000;
- static final int GCPGLYPH_LINKAFTER = 0x4000;
- // ExtTextOut constants
- 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";
- static final String CD_PG_ARABIC = "1256";
- // 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 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 int 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) {
- map.put (new Integer (hwnd), runnable);
- int oldProc = OS.GetWindowLong (hwnd, OS.GWL_WNDPROC);
- oldProcMap.put (new Integer(hwnd), new Integer(oldProc));
- OS.SetWindowLong (hwnd, OS.GWL_WNDPROC, callback.getAddress ());
-}
-/**
- * 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) {
- RECT rect = null;
- OS.ExtTextOutW(gc.handle, x, y, ETO_GLYPH_INDEX, rect, renderBuffer, renderBuffer.length, renderDx);
-}
-/**
- * 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);
- 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);
- System.arraycopy (dx2, 0, dx, glyphCount, dx2.length);
- }
- if (order != null) {
- int [] order2 = new int [length];
- OS.MoveMemory(order2, result.lpOrder, order2.length * 4);
- for (int j=0; j<length; j++) {
- order2 [j] += glyphCount;
- }
- 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);
- 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();
-
- 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);
- for (int j=0; j<length; j++) {
- order2 [j] += glyphCount;
- }
- 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
- */
-public 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);
- 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) {
- map.remove (new Integer (hwnd));
- Integer proc = (Integer)oldProcMap.remove (new Integer (hwnd));
- if (proc == null) return;
- OS.SetWindowLong (hwnd, OS.GWL_WNDPROC, proc.intValue());
-}
-/**
- * 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;
- }
- }
- }
-
-}
-/**
- * Window proc to intercept keyboard language switch event (WS_INPUTLANGCHANGE).
- * 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) {
- switch (msg) {
- case 0x51 /*OS.WM_INPUTLANGCHANGE*/:
- Runnable runnable = (Runnable) map.get (new Integer (hwnd));
- if (runnable != null) runnable.run ();
- break;
- }
- Integer oldProc = (Integer)oldProcMap.get(new Integer(hwnd));
- return OS.CallWindowProc (oldProc.intValue(), hwnd, msg, wParam, lParam);
-}
-
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.internal.win32.GCP_RESULTS;
+import org.eclipse.swt.internal.win32.OS;
+import org.eclipse.swt.internal.win32.RECT;
+import org.eclipse.swt.internal.win32.TCHAR;
+import java.util.Hashtable;
+/*
+ * 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 map = 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";
+ static Callback callback;
+ static {
+ try {
+ callback = new Callback (Class.forName (CLASS_NAME), "windowProc", 4);
+ } 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 int GCPGLYPH_LINKBEFORE = 0x8000;
+ static final int GCPGLYPH_LINKAFTER = 0x4000;
+ // ExtTextOut constants
+ 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";
+ static final String CD_PG_ARABIC = "1256";
+ // 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 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 int 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) {
+ map.put (new Integer (hwnd), runnable);
+ int oldProc = OS.GetWindowLong (hwnd, OS.GWL_WNDPROC);
+ oldProcMap.put (new Integer(hwnd), new Integer(oldProc));
+ OS.SetWindowLong (hwnd, OS.GWL_WNDPROC, callback.getAddress ());
+}
+/**
+ * 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) {
+ RECT rect = null;
+ OS.ExtTextOutW(gc.handle, x, y, ETO_GLYPH_INDEX, rect, renderBuffer, renderBuffer.length, renderDx);
+}
+/**
+ * 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);
+ 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);
+ System.arraycopy (dx2, 0, dx, glyphCount, dx2.length);
+ }
+ if (order != null) {
+ int [] order2 = new int [length];
+ OS.MoveMemory(order2, result.lpOrder, order2.length * 4);
+ for (int j=0; j<length; j++) {
+ order2 [j] += glyphCount;
+ }
+ 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);
+ 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();
+
+ 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);
+ for (int j=0; j<length; j++) {
+ order2 [j] += glyphCount;
+ }
+ 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
+ */
+public 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);
+ 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) {
+ map.remove (new Integer (hwnd));
+ Integer proc = (Integer)oldProcMap.remove (new Integer (hwnd));
+ if (proc == null) return;
+ OS.SetWindowLong (hwnd, OS.GWL_WNDPROC, proc.intValue());
+}
+/**
+ * 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;
+ }
+ }
+ }
+
+}
+/**
+ * Window proc to intercept keyboard language switch event (WS_INPUTLANGCHANGE).
+ * 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) {
+ switch (msg) {
+ case 0x51 /*OS.WM_INPUTLANGCHANGE*/:
+ Runnable runnable = (Runnable) map.get (new Integer (hwnd));
+ if (runnable != null) runnable.run ();
+ break;
+ }
+ Integer oldProc = (Integer)oldProcMap.get(new Integer(hwnd));
+ return OS.CallWindowProc (oldProc.intValue(), hwnd, msg, wParam, lParam);
+}
+
} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Converter.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Converter.java
index 1a5c388a2b..7699a2a0b0 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Converter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Converter.java
@@ -1,186 +1,186 @@
-package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.win32.*;
-
-/**
- * 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>
- *
- * @deprecated
- */
-
-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 int CodePage;
- static {
- CodePage = OS.GetACP ();
- }
-
-/**
- * Returns the default code page for the platform where the
- * application is currently running.
- *
- * @return the default code page
- */
-public static int defaultCodePage () {
- return CodePage;
-}
-
-/**
- * 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 (int codePage, byte [] buffer) {
-
- /* Check for the simple cases */
- if (codePage < 0 || 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 [] lpWideCharStr = new char [length];
- for (int i=0; i<length; i++) {
- if ((buffer [i] & 0xFF) <= 0x7F) {
- lpWideCharStr [i] = (char) buffer [i]; // all bytes <= 0x7F, so no ((char) (buffer[i]&0xFF)) needed
- } else {
- /* Convert from DBCS to UNICODE */
- int cp = codePage != 0 ? codePage : CodePage;
- int cchWideChar = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, length, null, 0);
- if (cchWideChar == 0) return EMPTY_CHAR_ARRAY;
- lpWideCharStr = new char [cchWideChar];
- OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, length, lpWideCharStr, cchWideChar);
- return lpWideCharStr;
- }
- }
- return lpWideCharStr;
-}
-
-/**
- * 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 (int codePage, char [] buffer) {
- return wcsToMbcs (0, 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 (int codePage, char [] buffer, boolean terminate) {
-
- /* Check for the simple cases */
- if (codePage < 0 || 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 {
- /* Convert from UNICODE to DBCS */
- int cp = codePage != 0 ? codePage : CodePage;
- int cchMultiByte = OS.WideCharToMultiByte (cp, 0, buffer, length, null, 0, null, null);
- if (cchMultiByte == 0) return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY;
- byte [] lpMultiByteStr = new byte [(terminate) ? cchMultiByte + 1 : cchMultiByte];
- OS.WideCharToMultiByte (cp, 0, buffer, length, lpMultiByteStr, cchMultiByte, null, null);
- return lpMultiByteStr;
- }
- }
- 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 (int codePage, String string) {
- return wcsToMbcs (0, 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 (int 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);
- }
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.win32.*;
+
+/**
+ * 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>
+ *
+ * @deprecated
+ */
+
+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 int CodePage;
+ static {
+ CodePage = OS.GetACP ();
+ }
+
+/**
+ * Returns the default code page for the platform where the
+ * application is currently running.
+ *
+ * @return the default code page
+ */
+public static int defaultCodePage () {
+ return CodePage;
+}
+
+/**
+ * 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 (int codePage, byte [] buffer) {
+
+ /* Check for the simple cases */
+ if (codePage < 0 || 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 [] lpWideCharStr = new char [length];
+ for (int i=0; i<length; i++) {
+ if ((buffer [i] & 0xFF) <= 0x7F) {
+ lpWideCharStr [i] = (char) buffer [i]; // all bytes <= 0x7F, so no ((char) (buffer[i]&0xFF)) needed
+ } else {
+ /* Convert from DBCS to UNICODE */
+ int cp = codePage != 0 ? codePage : CodePage;
+ int cchWideChar = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, length, null, 0);
+ if (cchWideChar == 0) return EMPTY_CHAR_ARRAY;
+ lpWideCharStr = new char [cchWideChar];
+ OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, length, lpWideCharStr, cchWideChar);
+ return lpWideCharStr;
+ }
+ }
+ return lpWideCharStr;
+}
+
+/**
+ * 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 (int codePage, char [] buffer) {
+ return wcsToMbcs (0, 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 (int codePage, char [] buffer, boolean terminate) {
+
+ /* Check for the simple cases */
+ if (codePage < 0 || 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 {
+ /* Convert from UNICODE to DBCS */
+ int cp = codePage != 0 ? codePage : CodePage;
+ int cchMultiByte = OS.WideCharToMultiByte (cp, 0, buffer, length, null, 0, null, null);
+ if (cchMultiByte == 0) return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY;
+ byte [] lpMultiByteStr = new byte [(terminate) ? cchMultiByte + 1 : cchMultiByte];
+ OS.WideCharToMultiByte (cp, 0, buffer, length, lpMultiByteStr, cchMultiByte, null, null);
+ return lpMultiByteStr;
+ }
+ }
+ 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 (int codePage, String string) {
+ return wcsToMbcs (0, 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 (int 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/win32/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java
index f3038052a8..f2a42c585e 100755
--- 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
@@ -1,712 +1,712 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 {
- Image image;
- static final int ButtonProc;
- static final TCHAR ButtonClass = new TCHAR (0,"BUTTON", true);
- static final int CheckWidth, CheckHeight;
- static {
- int hBitmap = OS.LoadBitmap (0, OS.OBM_CHECKBOXES);
- if (hBitmap == 0) {
- CheckWidth = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CXSMICON : OS.SM_CXVSCROLL);
- CheckHeight = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CYSMICON : OS.SM_CYVSCROLL);
- } else {
- BITMAP bitmap = new BITMAP ();
- OS.GetObject (hBitmap, BITMAP.sizeof, bitmap);
- OS.DeleteObject (hBitmap);
- CheckWidth = bitmap.bmWidth / 4;
- CheckHeight = 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));
-}
-
-/**
- * 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 msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (ButtonProc, handle, 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) != 0) {
- return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
- }
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) {
- return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
- }
- if ((style & SWT.ARROW) != 0) {
- return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
- }
- return style;
-}
-
-void click () {
- /*
- * Note: BM_CLICK sends WM_LBUTTONDOWN and WM_LBUTTONUP.
- */
- OS.SendMessage (handle, OS.BM_CLICK, 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.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 + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
- }
- int extra = 0;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & (OS.BS_BITMAP | OS.BS_ICON)) == 0) {
- 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 = new TEXTMETRIC ();
- OS.GetTextMetrics (hDC, lptm);
- int length = OS.GetWindowTextLength (handle);
- if (length == 0) {
- height += lptm.tmHeight;
- } else {
- extra = Math.max (8, lptm.tmAveCharWidth);
- TCHAR buffer = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (handle, buffer, length + 1);
- RECT rect = new RECT ();
- int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE;
- OS.DrawText (hDC, buffer, length, rect, flags);
- width += rect.right - rect.left;
- height += rect.bottom - rect.top;
- }
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- } else {
- if (image != null) {
- Rectangle rect = image.getBounds ();
- width = rect.width;
- height = rect.height;
- extra = 8;
- }
- }
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- width += CheckWidth + extra;
- height = Math.max (height, CheckHeight + 3);
- }
- if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
- width += 12; height += 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-
-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);
-}
-
-/**
- * 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.
- *
- * @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);
-}
-
-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 ();
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- bits &= ~(OS.BS_LEFT | OS.BS_CENTER | OS.BS_RIGHT);
- 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;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- 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);
-}
-
-public boolean setFocus () {
- checkWidget();
- if ((style & SWT.ARROW) != 0) return false;
- return super.setFocus ();
-}
-
-/**
- * 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 ();
- int hImage = 0, imageBits = 0, fImageType = 0;
- if (image != null) {
- if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- hImage = image.handle;
- switch (image.type) {
- case SWT.BITMAP:
- imageBits = OS.BS_BITMAP;
- fImageType = OS.IMAGE_BITMAP;
- break;
- case SWT.ICON:
- imageBits = OS.BS_ICON;
- fImageType = OS.IMAGE_ICON;
- break;
- default:
- return;
- }
- }
- this.image = image;
- int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int 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);
-}
-
-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 disallow focus to be restored to radio button that is
- * not selected.
- */
- 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);
- int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int oldBits = newBits;
- newBits &= ~(OS.BS_BITMAP | OS.BS_ICON);
- if (newBits != oldBits) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- }
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SetWindowText (handle, buffer);
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.BS_NOTIFY;
- 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;
- return bits | OS.BS_PUSHBUTTON | OS.WS_TABSTOP;
-}
-
-TCHAR windowClass () {
- return ButtonClass;
-}
-
-int windowProc () {
- return ButtonProc;
-}
-
-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_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 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 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);
- 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;
- RECT rect = new RECT ();
- OS.SetRect (rect, struct.left, struct.top, struct.right, struct.bottom);
- OS.DrawFrameControl (struct.hDC, rect, OS.DFC_SCROLL, uState);
- return null;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 {
+ Image image;
+ static final int ButtonProc;
+ static final TCHAR ButtonClass = new TCHAR (0,"BUTTON", true);
+ static final int CheckWidth, CheckHeight;
+ static {
+ int hBitmap = OS.LoadBitmap (0, OS.OBM_CHECKBOXES);
+ if (hBitmap == 0) {
+ CheckWidth = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CXSMICON : OS.SM_CXVSCROLL);
+ CheckHeight = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CYSMICON : OS.SM_CYVSCROLL);
+ } else {
+ BITMAP bitmap = new BITMAP ();
+ OS.GetObject (hBitmap, BITMAP.sizeof, bitmap);
+ OS.DeleteObject (hBitmap);
+ CheckWidth = bitmap.bmWidth / 4;
+ CheckHeight = 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));
+}
+
+/**
+ * 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 msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (ButtonProc, handle, 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) != 0) {
+ return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
+ }
+ if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) {
+ return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
+ }
+ if ((style & SWT.ARROW) != 0) {
+ return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
+ }
+ return style;
+}
+
+void click () {
+ /*
+ * Note: BM_CLICK sends WM_LBUTTONDOWN and WM_LBUTTONUP.
+ */
+ OS.SendMessage (handle, OS.BM_CLICK, 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.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 + (border * 2);
+ if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
+ return new Point (width, height);
+ }
+ int extra = 0;
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & (OS.BS_BITMAP | OS.BS_ICON)) == 0) {
+ 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 = new TEXTMETRIC ();
+ OS.GetTextMetrics (hDC, lptm);
+ int length = OS.GetWindowTextLength (handle);
+ if (length == 0) {
+ height += lptm.tmHeight;
+ } else {
+ extra = Math.max (8, lptm.tmAveCharWidth);
+ TCHAR buffer = new TCHAR (getCodePage (), length + 1);
+ OS.GetWindowText (handle, buffer, length + 1);
+ RECT rect = new RECT ();
+ int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE;
+ OS.DrawText (hDC, buffer, length, rect, flags);
+ width += rect.right - rect.left;
+ height += rect.bottom - rect.top;
+ }
+ if (newFont != 0) OS.SelectObject (hDC, oldFont);
+ OS.ReleaseDC (handle, hDC);
+ } else {
+ if (image != null) {
+ Rectangle rect = image.getBounds ();
+ width = rect.width;
+ height = rect.height;
+ extra = 8;
+ }
+ }
+ if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
+ width += CheckWidth + extra;
+ height = Math.max (height, CheckHeight + 3);
+ }
+ if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
+ width += 12; height += 10;
+ }
+ if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
+ if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
+ return new Point (width, height);
+}
+
+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);
+}
+
+/**
+ * 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.
+ *
+ * @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);
+}
+
+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 ();
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ bits &= ~(OS.BS_LEFT | OS.BS_CENTER | OS.BS_RIGHT);
+ 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;
+ OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
+ 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);
+}
+
+public boolean setFocus () {
+ checkWidget();
+ if ((style & SWT.ARROW) != 0) return false;
+ return super.setFocus ();
+}
+
+/**
+ * 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 ();
+ int hImage = 0, imageBits = 0, fImageType = 0;
+ if (image != null) {
+ if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ hImage = image.handle;
+ switch (image.type) {
+ case SWT.BITMAP:
+ imageBits = OS.BS_BITMAP;
+ fImageType = OS.IMAGE_BITMAP;
+ break;
+ case SWT.ICON:
+ imageBits = OS.BS_ICON;
+ fImageType = OS.IMAGE_ICON;
+ break;
+ default:
+ return;
+ }
+ }
+ this.image = image;
+ int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ int 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);
+}
+
+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 disallow focus to be restored to radio button that is
+ * not selected.
+ */
+ 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);
+ int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ int oldBits = newBits;
+ newBits &= ~(OS.BS_BITMAP | OS.BS_ICON);
+ if (newBits != oldBits) {
+ OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
+ }
+ TCHAR buffer = new TCHAR (getCodePage (), string, true);
+ OS.SetWindowText (handle, buffer);
+}
+
+int widgetStyle () {
+ int bits = super.widgetStyle () | OS.BS_NOTIFY;
+ 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;
+ return bits | OS.BS_PUSHBUTTON | OS.WS_TABSTOP;
+}
+
+TCHAR windowClass () {
+ return ButtonClass;
+}
+
+int windowProc () {
+ return ButtonProc;
+}
+
+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_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 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 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);
+ 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;
+ RECT rect = new RECT ();
+ OS.SetRect (rect, struct.left, struct.top, struct.right, struct.bottom);
+ 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
index 8de1e053c6..cf1a9c1ac3 100755
--- 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
@@ -1,216 +1,216 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Canvas (Composite parent, int style) {
- super (parent, style);
-}
-
-/*
-* Not currently used.
-*/
-void clearArea (int x, int y, int width, int height) {
- checkWidget ();
- if (OS.IsWindowVisible (handle)) return;
- 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 releaseWidget () {
- if (caret != null) caret.releaseResources ();
- caret = null;
- super.releaseWidget ();
-}
-
-/**
- * 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 ();
-
- /* Remove the caret so it won't get scrolled */
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
-
- /* Flush outstanding WM_PAINT's and scroll the window */
- if (OS.IsWinCE) {
- OS.UpdateWindow (handle);
- } else {
- int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (handle, null, 0, flags);
- }
- RECT rect = new RECT ();
- OS.SetRect (rect, x, y, x + width, y + height);
- int deltaX = destX - x, deltaY = destY - y;
- int flags = OS.SW_INVALIDATE | OS.SW_ERASE;
- if (all) flags |= OS.SW_SCROLLCHILDREN;
- OS.ScrollWindowEx (handle, deltaX, deltaY, rect, null, 0, null, flags);
-
- /* Restore the caret */
- 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 (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 ();
- super.setFont (font);
- if (caret != null) caret.setFont (font);
-}
-
-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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>
+ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
+ * </ul>
+ *
+ * @see SWT
+ * @see Widget#checkSubclass
+ * @see Widget#getStyle
+ */
+public Canvas (Composite parent, int style) {
+ super (parent, style);
+}
+
+/*
+* Not currently used.
+*/
+void clearArea (int x, int y, int width, int height) {
+ checkWidget ();
+ if (OS.IsWindowVisible (handle)) return;
+ 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 releaseWidget () {
+ if (caret != null) caret.releaseResources ();
+ caret = null;
+ super.releaseWidget ();
+}
+
+/**
+ * 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 ();
+
+ /* Remove the caret so it won't get scrolled */
+ boolean isFocus = caret != null && caret.isFocusCaret ();
+ if (isFocus) caret.killFocus ();
+
+ /* Flush outstanding WM_PAINT's and scroll the window */
+ if (OS.IsWinCE) {
+ OS.UpdateWindow (handle);
+ } else {
+ int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
+ OS.RedrawWindow (handle, null, 0, flags);
+ }
+ RECT rect = new RECT ();
+ OS.SetRect (rect, x, y, x + width, y + height);
+ int deltaX = destX - x, deltaY = destY - y;
+ int flags = OS.SW_INVALIDATE | OS.SW_ERASE;
+ if (all) flags |= OS.SW_SCROLLCHILDREN;
+ OS.ScrollWindowEx (handle, deltaX, deltaY, rect, null, 0, null, flags);
+
+ /* Restore the caret */
+ 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 (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 ();
+ super.setFont (font);
+ if (caret != null) caret.setFont (font);
+}
+
+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;
+}
+
+}
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
index a10aee3686..3f979d3b10 100755
--- 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
@@ -1,555 +1,555 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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);
- if (hwndIME == 0) return parent.defaultFont ();
- int hFont = OS.SendMessage (hwndIME, 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);
-}
-
-public Display getDisplay () {
- Composite parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
-/**
- * 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 (getDisplay (), 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 ();
- if (font != null) restoreIMEFont ();
-}
-
-void move () {
- moved = false;
- if (!OS.SetCaretPos (x, y)) return;
- if (OS.IsDBLocale) {
- POINT ptCurrentPos = new POINT ();
- if (!OS.GetCaretPos (ptCurrentPos)) return;
- COMPOSITIONFORM lpCompForm = new COMPOSITIONFORM ();
- lpCompForm.dwStyle = OS.CFS_POINT;
- lpCompForm.x = ptCurrentPos.x;
- lpCompForm.y = ptCurrentPos.y;
- int hwnd = parent.handle;
- int hIMC = OS.ImmGetContext (hwnd);
- OS.ImmSetCompositionWindow (hIMC, lpCompForm);
- OS.ImmReleaseContext (hwnd, hIMC);
- }
-}
-
-void releaseChild () {
- super.releaseChild ();
- 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 = 0;
- if (image != null) hBitmap = image.handle;
- 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;
-}
-
-void saveIMEFont () {
- if (!OS.IsDBLocale) return;
- if (oldFont != null) return;
- int hwnd = parent.handle;
- int hIMC = OS.ImmGetContext (hwnd);
- oldFont = new LOGFONT ();
- if (OS.ImmGetCompositionFont (hIMC, oldFont)) oldFont = null;
- OS.ImmReleaseContext (hwnd, hIMC);
-}
-
-/**
- * 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 ();
- if (font != null) {
- int hFont = font.handle;
- saveIMEFont ();
- setIMEFont (hFont);
- }
- 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 (isVisible && hasFocus ()) {
- int hFont = 0;
- if (font != null) hFont = font.handle;
- if (hFont == 0) hFont = defaultFont ();
- saveIMEFont ();
- setIMEFont (hFont);
- }
-}
-
-/**
- * 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 font the new font (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 (int hFont) {
- if (!OS.IsDBLocale) return;
- LOGFONT logFont = new LOGFONT ();
- if (OS.GetObject (hFont, LOGFONT.sizeof, logFont) != 0) {
- int hwnd = parent.handle;
- int hIMC = OS.ImmGetContext (hwnd);
- 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
- * @param height the new height 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);
- }
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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);
+ if (hwndIME == 0) return parent.defaultFont ();
+ int hFont = OS.SendMessage (hwndIME, 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);
+}
+
+public Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
+/**
+ * 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 (getDisplay (), 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 ();
+ if (font != null) restoreIMEFont ();
+}
+
+void move () {
+ moved = false;
+ if (!OS.SetCaretPos (x, y)) return;
+ if (OS.IsDBLocale) {
+ POINT ptCurrentPos = new POINT ();
+ if (!OS.GetCaretPos (ptCurrentPos)) return;
+ COMPOSITIONFORM lpCompForm = new COMPOSITIONFORM ();
+ lpCompForm.dwStyle = OS.CFS_POINT;
+ lpCompForm.x = ptCurrentPos.x;
+ lpCompForm.y = ptCurrentPos.y;
+ int hwnd = parent.handle;
+ int hIMC = OS.ImmGetContext (hwnd);
+ OS.ImmSetCompositionWindow (hIMC, lpCompForm);
+ OS.ImmReleaseContext (hwnd, hIMC);
+ }
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ 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 = 0;
+ if (image != null) hBitmap = image.handle;
+ 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;
+}
+
+void saveIMEFont () {
+ if (!OS.IsDBLocale) return;
+ if (oldFont != null) return;
+ int hwnd = parent.handle;
+ int hIMC = OS.ImmGetContext (hwnd);
+ oldFont = new LOGFONT ();
+ if (OS.ImmGetCompositionFont (hIMC, oldFont)) oldFont = null;
+ OS.ImmReleaseContext (hwnd, hIMC);
+}
+
+/**
+ * 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 ();
+ if (font != null) {
+ int hFont = font.handle;
+ saveIMEFont ();
+ setIMEFont (hFont);
+ }
+ 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 (isVisible && hasFocus ()) {
+ int hFont = 0;
+ if (font != null) hFont = font.handle;
+ if (hFont == 0) hFont = defaultFont ();
+ saveIMEFont ();
+ setIMEFont (hFont);
+ }
+}
+
+/**
+ * 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 font the new font (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 (int hFont) {
+ if (!OS.IsDBLocale) return;
+ LOGFONT logFont = new LOGFONT ();
+ if (OS.GetObject (hFont, LOGFONT.sizeof, logFont) != 0) {
+ int hwnd = parent.handle;
+ int hIMC = OS.ImmGetContext (hwnd);
+ 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
+ * @param height the new height 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
index 6a5a3ea76e..8366153109 100755
--- 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
@@ -1,198 +1,198 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 (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
- * @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);
- 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);
- int lpfnHook = callback.getAddress ();
-
- /* Allocate the Custom Colors */
- Display display = parent.getDisplay ();
- 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;
- }
- boolean success = OS.ChooseColor (lpcc);
- 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 to select a default when
- * open() is called
- * @see PaletteData#getRGBs
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 (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
+ * @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);
+ 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);
+ int lpfnHook = callback.getAddress ();
+
+ /* Allocate the Custom Colors */
+ Display display = parent.getDisplay ();
+ 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;
+ }
+ boolean success = OS.ChooseColor (lpcc);
+ 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 to 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
index 5e1cfa4b2b..1d9ce8dcae 100755
--- 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
@@ -1,1461 +1,1461 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
-
- /**
- * 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;
- }
-
- static final int ComboProc;
- static final TCHAR ComboClass = new TCHAR (0,"COMBOBOX", true);
- /*
- * 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 {
- 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));
-}
-
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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);
-}
-
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- *
- * @see #add(String)
- */
-public void add (String string, int index) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- int result = OS.SendMessage (handle, OS.CB_INSERTSTRING, index, buffer);
- if (result == OS.CB_ERRSPACE) error (SWT.ERROR_ITEM_NOT_ADDED);
- 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_ADDED);
- } else {
- 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);
-}
-
-int callWindowProc (int msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (ComboProc, handle, msg, wParam, lParam);
-}
-
-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 count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- int itemHeight = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, 0, 0);
- int width = 0, height = 0;
- if ((style & SWT.SIMPLE) != 0) height = count * itemHeight;
- 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_NOPREFIX;
- 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);
- 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);
- }
- }
- }
- TEXTMETRIC tm = new TEXTMETRIC ();
- OS.GetTextMetrics (hDC, tm);
- 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;
- int border = OS.GetSystemMetrics (OS.SM_CXEDGE);
- width += OS.GetSystemMetrics (OS.SM_CXVSCROLL) + (tm.tmInternalLeading + 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;
- }
- 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;
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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.SendMessage (handle, OS.WM_CUT, 0, 0);
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_WINDOW);
-}
-
-/**
- * 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
-}
-
-boolean getEditable () {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- return (bits & 0x0F) == OS.CBS_DROPDOWNLIST;
-}
-
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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 null;
-}
-
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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 an 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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 a <code>Point</code> whose x coordinate is the start
- * of the selection in the receiver's text field, and whose y
- * coordinate is the end of the selection. The returned values
- * are zero-relative. An "empty" selection as indicated by
- * the the x and y coordinates having the same value.
- *
- * @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);
- 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.
- *
- * @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);
-}
-
-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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public int getTextHeight () {
- checkWidget ();
- int result = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0);
- if (result == OS.CB_ERR) error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT);
- return result + 6;
-}
-
-/**
- * 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>
- */
-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);
-}
-
-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
- * @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;
-}
-
-/**
- * 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.SendMessage (handle, OS.WM_PASTE, 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- 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 (length != OS.GetWindowTextLength (handle)) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the modify
- * event. If this happens, just return.
- */
- 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, 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget ();
- if (start > end) return;
- int length = OS.GetWindowTextLength (handle);
- for (int i=start; i<=end; i++) {
- int result = OS.SendMessage (handle, OS.CB_DELETESTRING, start, 0);
- if (result == OS.CB_ERR) {
- int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
- if (0 <= i && i < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- if (length != OS.GetWindowTextLength (handle)) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the modify
- * event. If this happens, just return.
- */
- 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, 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove (String string) {
- 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.
- * <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);
- // widget could be disposed at this point
-}
-
-/**
- * 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);
-}
-
-/**
- * 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 setBackgroundPixel (int pixel) {
- if (background == pixel) return;
- 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) {
- int textHeight = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0);
- int itemHeight = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, 0, 0);
- height = textHeight + 6 + (itemHeight * 5) + 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;
- }
- }
- OS.SetWindowPos (handle, 0, x, y, width, height, flags);
- return;
- }
-
- /*
- * 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 (parent.lpwp != null || (flags & OS.SWP_NOSIZE) != 0 || !OS.IsWindowVisible (handle)) {
- super.setBounds (x, y, width, height, flags);
- return;
- }
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- super.setBounds (x, y, width, height, flags);
- int oldWidth = rect.right - rect.left, oldHeight = rect.bottom - rect.top;
- if (oldWidth != width || oldHeight != height) {
- 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);
- }
- }
-}
-
-void setEditable (boolean editable) {
- error (SWT.ERROR_NOT_IMPLEMENTED);
-}
-
-void setForegroundPixel (int pixel) {
- if (foreground == pixel) return;
- 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 <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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
- * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</li>
- * </ul>
- */
-public void setItem (int index, String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- remove (index);
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the modify
- * event that might be sent when the index is removed.
- * If this happens, just exit.
- */
- if (isDisposed ()) return;
- add (string, index);
-}
-
-/**
- * Sets the receiver's list to be the given array of items.
- *
- * @param items the array 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- 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);
- }
- // widget could be disposed at this point
- sendEvent (SWT.Modify);
-}
-
-/**
- * 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 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 bits = selection.x | (selection.y << 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 text 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.
- *
- * @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>
- */
-public void setTextLimit (int limit) {
- checkWidget ();
- if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
- OS.SendMessage (handle, OS.CB_LIMITTEXT, limit, 0);
-}
-
-boolean translateAccelerator (MSG msg) {
- if (super.translateAccelerator (msg)) return true;
-
- /*
- * In order to see key events for the text widget in a combo box,
- * filter the key events before they are dispatched to the text
- * widget and invoke the cooresponding key handler for the combo
- * box as if the key was sent directly to the combo box, not the
- * text field. The key is still dispatched to the text widget,
- * in the normal fashion. Note that we must call TranslateMessage
- * in order to process accented keys properly.
- */
- int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0 && msg.hwnd == hwndText) {
- switch (msg.message) {
- case OS.WM_CHAR:
- case OS.WM_SYSCHAR:
- case OS.WM_KEYDOWN: {
- Display display = getDisplay ();
- if (msg.message == OS.WM_KEYDOWN) {
- if (display.translateTraversal (msg, this)) return true;
- } else {
- if (display.translateMnemonic (msg, this)) return true;
- }
- }
- }
- OS.TranslateMessage (msg);
- switch (msg.message) {
- case OS.WM_CHAR: WM_CHAR (msg.wParam, msg.lParam); break;
- case OS.WM_IME_CHAR: WM_IME_CHAR (msg.wParam, msg.lParam); break;
- case OS.WM_KEYDOWN: WM_KEYDOWN (msg.wParam, msg.lParam); break;
- case OS.WM_KEYUP: WM_KEYUP (msg.wParam, msg.lParam); break;
- case OS.WM_SYSCHAR: WM_SYSCHAR (msg.wParam, msg.lParam); break;
- case OS.WM_SYSKEYDOWN: WM_SYSKEYDOWN (msg.wParam, msg.lParam); break;
- case OS.WM_SYSKEYUP: WM_SYSKEYUP (msg.wParam, msg.lParam); break;
- }
- OS.DispatchMessage (msg);
- return true;
- }
- return false;
-}
-
-boolean translateTraversal (MSG msg) {
- /*
- * Feature in Windows. For some reason, when the
- * user presses tab, return or escape, Windows beeps.
- * The fix is to look for these keys and not call
- * the window proc.
- */
- int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
- if (hwndText != 0 && msg.hwnd == hwndText) {
- switch (msg.wParam) {
- case OS.VK_ESCAPE:
- /* Allow the escape key to close the combo box */
- if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) != 0) {
- return false;
- }
- // FALL THROUGH
- case OS.VK_TAB:
- case OS.VK_RETURN:
- boolean translated = super.translateTraversal (msg);
- if (!translated) {
- if (sendKeyEvent (SWT.KeyDown, msg.message, msg.wParam, msg.lParam)) {
- if (msg.wParam == OS.VK_RETURN) {
- sendEvent (SWT.DefaultSelection);
- // widget could be disposed at this point
- }
- }
- }
- return true;
- }
- }
- return super.translateTraversal (msg);
-}
-
-boolean traverseEscape () {
- if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) != 0) {
- OS.SendMessage (handle, OS.CB_SHOWDROPDOWN, 0, 0);
- return true;
- }
- return super.traverseEscape ();
-}
-
-int widgetExtStyle () {
- return super.widgetExtStyle () & ~OS.WS_EX_NOINHERITLAYOUT;
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.CBS_AUTOHSCROLL | OS.CBS_NOINTEGRALHEIGHT | 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;
-}
-
-LRESULT WM_CHAR (int wParam, int lParam) {
- LRESULT result = super.WM_CHAR (wParam, lParam);
- if (result != null) return result;
- if (wParam == OS.VK_RETURN) {
- postEvent (SWT.DefaultSelection);
- }
- return result;
-}
-
-LRESULT WM_CTLCOLOR (int wParam, int lParam) {
- return wmColorChild (wParam, lParam);
-}
-
-LRESULT WM_GETDLGCODE (int wParam, int lParam) {
- int code = callWindowProc (OS.WM_GETDLGCODE, wParam, lParam);
- return new LRESULT (code | OS.DLGC_WANTARROWS);
-}
-
-LRESULT WM_KILLFOCUS (int wParam, int lParam) {
- /*
- * Return NULL - Focus notification is
- * done in WM_COMMAND by CBN_KILLFOCUS.
- */
- return null;
-}
-
-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) {
- /*
- * 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.
- */
- if ((style & SWT.READ_ONLY) != 0 || (style & SWT.DROP_DOWN) == 0) {
- return super.WM_SIZE (wParam, lParam);
- }
- 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);
- }
- }
- 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 (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);
- }
- return result;
-}
-
-LRESULT wmCommandChild (int wParam, int lParam) {
- int code = wParam >> 16;
- switch (code) {
- case OS.CBN_EDITCHANGE:
- /*
- * Feature in Windows. If the combo box list selection is
- * queried using CB_GETCURSEL before the WM_COMMAND (with
- * CBM_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;
- /*
- * 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;
- 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 CBM_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:
- case OS.CBN_KILLFOCUS:
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the focus
- * event. If this happens, end the processing of the
- * Windows message by returning zero as the result of
- * the window proc.
- */
- sendEvent (code == OS.CBN_SETFOCUS ? SWT.FocusIn : SWT.FocusOut);
- if (isDisposed ()) return LRESULT.ZERO;
- break;
- }
- return super.wmCommandChild (wParam, lParam);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+
+ /**
+ * 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;
+ }
+
+ static final int ComboProc;
+ static final TCHAR ComboClass = new TCHAR (0,"COMBOBOX", true);
+ /*
+ * 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 {
+ 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));
+}
+
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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);
+}
+
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ *
+ * @see #add(String)
+ */
+public void add (String string, int index) {
+ checkWidget ();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ TCHAR buffer = new TCHAR (getCodePage (), string, true);
+ int result = OS.SendMessage (handle, OS.CB_INSERTSTRING, index, buffer);
+ if (result == OS.CB_ERRSPACE) error (SWT.ERROR_ITEM_NOT_ADDED);
+ 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_ADDED);
+ } else {
+ 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);
+}
+
+int callWindowProc (int msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (ComboProc, handle, msg, wParam, lParam);
+}
+
+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 count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
+ int itemHeight = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, 0, 0);
+ int width = 0, height = 0;
+ if ((style & SWT.SIMPLE) != 0) height = count * itemHeight;
+ 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_NOPREFIX;
+ 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);
+ 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);
+ }
+ }
+ }
+ TEXTMETRIC tm = new TEXTMETRIC ();
+ OS.GetTextMetrics (hDC, tm);
+ 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;
+ int border = OS.GetSystemMetrics (OS.SM_CXEDGE);
+ width += OS.GetSystemMetrics (OS.SM_CXVSCROLL) + (tm.tmInternalLeading + 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;
+ }
+ 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;
+}
+
+/**
+ * Cuts the selected text.
+ * <p>
+ * The current selection is first copied to the
+ * clipboard and then deleted from the widget.
+ * </p>
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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.SendMessage (handle, OS.WM_CUT, 0, 0);
+}
+
+int defaultBackground () {
+ return OS.GetSysColor (OS.COLOR_WINDOW);
+}
+
+/**
+ * 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
+}
+
+boolean getEditable () {
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ return (bits & 0x0F) == OS.CBS_DROPDOWNLIST;
+}
+
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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 null;
+}
+
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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 an 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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 a <code>Point</code> whose x coordinate is the start
+ * of the selection in the receiver's text field, and whose y
+ * coordinate is the end of the selection. The returned values
+ * are zero-relative. An "empty" selection as indicated by
+ * the the x and y coordinates having the same value.
+ *
+ * @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);
+ 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.
+ *
+ * @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);
+}
+
+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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public int getTextHeight () {
+ checkWidget ();
+ int result = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0);
+ if (result == OS.CB_ERR) error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT);
+ return result + 6;
+}
+
+/**
+ * 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>
+ */
+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);
+}
+
+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
+ * @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;
+}
+
+/**
+ * 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.SendMessage (handle, OS.WM_PASTE, 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove (int index) {
+ checkWidget ();
+ 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 (length != OS.GetWindowTextLength (handle)) {
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the modify
+ * event. If this happens, just return.
+ */
+ 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, 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove (int start, int end) {
+ checkWidget ();
+ if (start > end) return;
+ int length = OS.GetWindowTextLength (handle);
+ for (int i=start; i<=end; i++) {
+ int result = OS.SendMessage (handle, OS.CB_DELETESTRING, start, 0);
+ if (result == OS.CB_ERR) {
+ int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
+ if (0 <= i && i < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ }
+ if (length != OS.GetWindowTextLength (handle)) {
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the modify
+ * event. If this happens, just return.
+ */
+ 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, 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove (String string) {
+ 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.
+ * <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);
+ // widget could be disposed at this point
+}
+
+/**
+ * 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);
+}
+
+/**
+ * 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 setBackgroundPixel (int pixel) {
+ if (background == pixel) return;
+ 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) {
+ int textHeight = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0);
+ int itemHeight = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, 0, 0);
+ height = textHeight + 6 + (itemHeight * 5) + 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;
+ }
+ }
+ OS.SetWindowPos (handle, 0, x, y, width, height, flags);
+ return;
+ }
+
+ /*
+ * 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 (parent.lpwp != null || (flags & OS.SWP_NOSIZE) != 0 || !OS.IsWindowVisible (handle)) {
+ super.setBounds (x, y, width, height, flags);
+ return;
+ }
+ RECT rect = new RECT ();
+ OS.GetWindowRect (handle, rect);
+ super.setBounds (x, y, width, height, flags);
+ int oldWidth = rect.right - rect.left, oldHeight = rect.bottom - rect.top;
+ if (oldWidth != width || oldHeight != height) {
+ 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);
+ }
+ }
+}
+
+void setEditable (boolean editable) {
+ error (SWT.ERROR_NOT_IMPLEMENTED);
+}
+
+void setForegroundPixel (int pixel) {
+ if (foreground == pixel) return;
+ 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 <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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
+ * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void setItem (int index, String string) {
+ checkWidget ();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ remove (index);
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the modify
+ * event that might be sent when the index is removed.
+ * If this happens, just exit.
+ */
+ if (isDisposed ()) return;
+ add (string, index);
+}
+
+/**
+ * Sets the receiver's list to be the given array of items.
+ *
+ * @param items the array 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void setItems (String [] items) {
+ checkWidget ();
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+ 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);
+ }
+ // widget could be disposed at this point
+ sendEvent (SWT.Modify);
+}
+
+/**
+ * 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 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 bits = selection.x | (selection.y << 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 text 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.
+ *
+ * @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>
+ */
+public void setTextLimit (int limit) {
+ checkWidget ();
+ if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
+ OS.SendMessage (handle, OS.CB_LIMITTEXT, limit, 0);
+}
+
+boolean translateAccelerator (MSG msg) {
+ if (super.translateAccelerator (msg)) return true;
+
+ /*
+ * In order to see key events for the text widget in a combo box,
+ * filter the key events before they are dispatched to the text
+ * widget and invoke the cooresponding key handler for the combo
+ * box as if the key was sent directly to the combo box, not the
+ * text field. The key is still dispatched to the text widget,
+ * in the normal fashion. Note that we must call TranslateMessage
+ * in order to process accented keys properly.
+ */
+ int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
+ if (hwndText != 0 && msg.hwnd == hwndText) {
+ switch (msg.message) {
+ case OS.WM_CHAR:
+ case OS.WM_SYSCHAR:
+ case OS.WM_KEYDOWN: {
+ Display display = getDisplay ();
+ if (msg.message == OS.WM_KEYDOWN) {
+ if (display.translateTraversal (msg, this)) return true;
+ } else {
+ if (display.translateMnemonic (msg, this)) return true;
+ }
+ }
+ }
+ OS.TranslateMessage (msg);
+ switch (msg.message) {
+ case OS.WM_CHAR: WM_CHAR (msg.wParam, msg.lParam); break;
+ case OS.WM_IME_CHAR: WM_IME_CHAR (msg.wParam, msg.lParam); break;
+ case OS.WM_KEYDOWN: WM_KEYDOWN (msg.wParam, msg.lParam); break;
+ case OS.WM_KEYUP: WM_KEYUP (msg.wParam, msg.lParam); break;
+ case OS.WM_SYSCHAR: WM_SYSCHAR (msg.wParam, msg.lParam); break;
+ case OS.WM_SYSKEYDOWN: WM_SYSKEYDOWN (msg.wParam, msg.lParam); break;
+ case OS.WM_SYSKEYUP: WM_SYSKEYUP (msg.wParam, msg.lParam); break;
+ }
+ OS.DispatchMessage (msg);
+ return true;
+ }
+ return false;
+}
+
+boolean translateTraversal (MSG msg) {
+ /*
+ * Feature in Windows. For some reason, when the
+ * user presses tab, return or escape, Windows beeps.
+ * The fix is to look for these keys and not call
+ * the window proc.
+ */
+ int hwndText = OS.GetDlgItem (handle, CBID_EDIT);
+ if (hwndText != 0 && msg.hwnd == hwndText) {
+ switch (msg.wParam) {
+ case OS.VK_ESCAPE:
+ /* Allow the escape key to close the combo box */
+ if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) != 0) {
+ return false;
+ }
+ // FALL THROUGH
+ case OS.VK_TAB:
+ case OS.VK_RETURN:
+ boolean translated = super.translateTraversal (msg);
+ if (!translated) {
+ if (sendKeyEvent (SWT.KeyDown, msg.message, msg.wParam, msg.lParam)) {
+ if (msg.wParam == OS.VK_RETURN) {
+ sendEvent (SWT.DefaultSelection);
+ // widget could be disposed at this point
+ }
+ }
+ }
+ return true;
+ }
+ }
+ return super.translateTraversal (msg);
+}
+
+boolean traverseEscape () {
+ if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) != 0) {
+ OS.SendMessage (handle, OS.CB_SHOWDROPDOWN, 0, 0);
+ return true;
+ }
+ return super.traverseEscape ();
+}
+
+int widgetExtStyle () {
+ return super.widgetExtStyle () & ~OS.WS_EX_NOINHERITLAYOUT;
+}
+
+int widgetStyle () {
+ int bits = super.widgetStyle () | OS.CBS_AUTOHSCROLL | OS.CBS_NOINTEGRALHEIGHT | 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;
+}
+
+LRESULT WM_CHAR (int wParam, int lParam) {
+ LRESULT result = super.WM_CHAR (wParam, lParam);
+ if (result != null) return result;
+ if (wParam == OS.VK_RETURN) {
+ postEvent (SWT.DefaultSelection);
+ }
+ return result;
+}
+
+LRESULT WM_CTLCOLOR (int wParam, int lParam) {
+ return wmColorChild (wParam, lParam);
+}
+
+LRESULT WM_GETDLGCODE (int wParam, int lParam) {
+ int code = callWindowProc (OS.WM_GETDLGCODE, wParam, lParam);
+ return new LRESULT (code | OS.DLGC_WANTARROWS);
+}
+
+LRESULT WM_KILLFOCUS (int wParam, int lParam) {
+ /*
+ * Return NULL - Focus notification is
+ * done in WM_COMMAND by CBN_KILLFOCUS.
+ */
+ return null;
+}
+
+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) {
+ /*
+ * 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.
+ */
+ if ((style & SWT.READ_ONLY) != 0 || (style & SWT.DROP_DOWN) == 0) {
+ return super.WM_SIZE (wParam, lParam);
+ }
+ 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);
+ }
+ }
+ 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 (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);
+ }
+ return result;
+}
+
+LRESULT wmCommandChild (int wParam, int lParam) {
+ int code = wParam >> 16;
+ switch (code) {
+ case OS.CBN_EDITCHANGE:
+ /*
+ * Feature in Windows. If the combo box list selection is
+ * queried using CB_GETCURSEL before the WM_COMMAND (with
+ * CBM_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;
+ /*
+ * 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;
+ 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 CBM_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:
+ case OS.CBN_KILLFOCUS:
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the focus
+ * event. If this happens, end the processing of the
+ * Windows message by returning zero as the result of
+ * the window proc.
+ */
+ sendEvent (code == OS.CBN_SETFOCUS ? SWT.FocusIn : SWT.FocusOut);
+ if (isDisposed ()) return LRESULT.ZERO;
+ break;
+ }
+ return super.wmCommandChild (wParam, lParam);
+}
+
+}
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
index 96548af04a..770516cbd0 100755
--- 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
@@ -1,830 +1,830 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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</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>
- * 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;
-
-/**
- * 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 = WidgetTable.get (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;
-}
-
-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) {
- size = layout.computeSize (this, wHint, hHint, 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 () {
- super.createHandle ();
- state |= CANVAS;
-}
-
-/**
- * Returns an array containing the receiver's children.
- * <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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 last specified 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);
-}
-
-/**
- * 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 the argument is <code>true</code> the layout must not rely
- * on any cached information it is keeping about the children. If it
- * is <code>false</code> the layout may (potentially) simplify the
- * work it is doing by assuming that the state of the none of the
- * receiver's children has changed since the last layout.
- * If the receiver does not have a layout, do nothing.
- *
- * @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;
- setResizeChildren (false);
- layout.layout (this, changed);
- setResizeChildren (true);
-}
-
-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 releaseChildren () {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (!child.isDisposed ()) child.releaseResources ();
- }
-}
-
-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 = OS.DeferWindowPos (hdwp, wp.hwnd, 0, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
- if (hdwp == 0) return false;
- } else {
- OS.SetWindowPos (wp.hwnd, 0, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
- }
- }
- }
- if (defer) return OS.EndDeferWindowPos (hdwp);
- return true;
-}
-
-void releaseWidget () {
- releaseChildren ();
- super.releaseWidget ();
- layout = null;
- tabList = null;
- lpwp = null;
-}
-
-public boolean setFocus () {
- checkWidget ();
- if ((style & SWT.NO_FOCUS) != 0) return false;
- 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;
-}
-
-/**
- * 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);
- /*
- * This code is intentionally commented.
- * Tab lists are currently only supported
- * for the direct children of a composite.
- */
-// Shell shell = control.getShell ();
-// while (control != shell && control != this) {
-// control = control.parent;
-// }
-// if (control != this) error (SWT.ERROR_INVALID_PARENT);
- 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 ();
- if ((style & SWT.NO_FOCUS) == 0) {
- boolean takeFocus = true;
- 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.setRadioFocus ()) return true;
- }
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.isTabItem () && child.setTabItemFocus ()) return true;
- }
- return false;
-}
-
-boolean setTabItemFocus () {
- if ((style & SWT.NO_FOCUS) == 0) {
- boolean takeFocus = true;
- if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
- if (takeFocus) {
- if (!isShowing ()) return false;
- if (forceFocus ()) return true;
- }
- }
- return super.setTabItemFocus ();
-}
-
-String toolTipText (NMTTDISPINFO hdr) {
- if ((hdr.uFlags & OS.TTF_IDISHWND) == 0) {
- return null;
- }
- int hwnd = hdr.idFrom;
- if (hwnd == 0) return null;
- Control control = WidgetTable.get (hwnd);
- if (control == null) return null;
- return control.toolTipText;
-}
-
-boolean translateMnemonic (char key) {
- if (super.translateMnemonic (key)) return true;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.translateMnemonic (key)) return true;
- }
- return false;
-}
-
-void updateFont (Font oldFont, Font newFont) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control control = children [i];
- if (!control.isDisposed ()) {
- control.updateFont (oldFont, newFont);
- }
- }
- super.updateFont (oldFont, newFont);
- layout (true);
-}
-
-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) {
- if ((style & SWT.NO_BACKGROUND) != 0) 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 ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) return new LRESULT (OS.DLGC_STATIC);
- if (hooksKeys ()) {
- int flags = OS.DLGC_WANTALLKEYS | OS.DLGC_WANTARROWS | OS.DLGC_WANTTAB;
- return new LRESULT (flags);
- }
- int count = getChildrenCount ();
- if (count != 0) return new LRESULT (OS.DLGC_STATIC);
- }
- return result;
-}
-
-LRESULT WM_GETFONT (int wParam, int lParam) {
- LRESULT result = super.WM_GETFONT (wParam, lParam);
- if (result != null) return result;
- int code = callWindowProc (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);
-
- /* Set focus for a canvas with no children */
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) return result;
- if (OS.GetWindow (handle, OS.GW_CHILD) == 0) setFocus ();
- }
- 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.
- */
- Display display = getDisplay ();
- 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;
- OS.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 = new NMTTDISPINFO ();
- if (hdr.code == OS.TTN_GETDISPINFOA) {
- OS.MoveMemoryA (lpnmtdi, lParam, NMTTDISPINFO.sizeofA);
- } else {
- OS.MoveMemoryW (lpnmtdi, lParam, NMTTDISPINFO.sizeofW);
- }
- 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);
- 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.MoveMemoryA (lParam, lpnmtdi, NMTTDISPINFO.sizeofA);
- } else {
- shell.setToolTipText (lpnmtdi, chars);
- OS.MoveMemoryW (lParam, lpnmtdi, NMTTDISPINFO.sizeofW);
- }
- return LRESULT.ZERO;
- }
- break;
- }
- }
- }
- return super.WM_NOTIFY (wParam, lParam);
-}
-
-LRESULT WM_PAINT (int wParam, int lParam) {
- if ((state & CANVAS) == 0) {
- return super.WM_PAINT (wParam, lParam);
- }
-
- /*
- * This code is intentionally commented. Don't exit
- * early because the background must still be painted,
- * even though no application code will be painting
- * the widget.
- *
- * Do not uncomment this code.
- */
-// if (!hooks (SWT.Paint)) return null;
-
- /* Get the damage */
- int [] lpRgnData = null;
- boolean isComplex = false;
- boolean exposeRegion = false;
- if ((style & SWT.NO_MERGE_PAINTS) != 0) {
- int rgn = OS.CreateRectRgn (0, 0, 0, 0);
- isComplex = OS.GetUpdateRgn (handle, rgn, false) == OS.COMPLEXREGION;
- if (isComplex) {
- int nBytes = OS.GetRegionData (rgn, 0, null);
- lpRgnData = new int [nBytes / 4];
- exposeRegion = OS.GetRegionData (rgn, nBytes, lpRgnData) != 0;
- }
- OS.DeleteObject (rgn);
- }
-
- /* Set the clipping bits */
- int oldBits = 0;
- if (!OS.IsWinCE) {
- oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int newBits = oldBits | OS.WS_CLIPSIBLINGS | OS.WS_CLIPCHILDREN;
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- }
-
- /* Create the paint GC */
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- GCData data = new GCData ();
- data.ps = ps;
- GC gc = GC.win32_new (this, data);
- int hDC = gc.handle;
-
- /* Send the paint event */
- Event event = new Event ();
- event.gc = gc;
- if (isComplex && exposeRegion) {
- RECT rect = new RECT ();
- int count = lpRgnData [2];
- for (int i=0; i<count; i++) {
- OS.SetRect (rect,
- lpRgnData [8 + (i << 2)],
- lpRgnData [8 + (i << 2) + 1],
- lpRgnData [8 + (i << 2) + 2],
- lpRgnData [8 + (i << 2) + 3]);
- if ((style & SWT.NO_BACKGROUND) == 0) {
- drawBackground (hDC, 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;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the paint
- * event. If this happens, attempt to give back the
- * paint GC anyways because this is a scarce Windows
- * resource.
- */
- sendEvent (SWT.Paint, event);
- if (isDisposed ()) break;
- }
- } else {
- if ((style & SWT.NO_BACKGROUND) == 0) {
- RECT rect = new RECT ();
- OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
- drawBackground (hDC, rect);
- }
- 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
-
- /* Dispose the paint GC */
- event.gc = null;
- gc.dispose ();
-
- if (!OS.IsWinCE) {
- /*
- * 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_SETFONT (int wParam, int lParam) {
- 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) layout.layout (this, false);
-
- /* End deferred window positioning */
- setResizeChildren (true);
-
- /* Damage the widget to cause a repaint */
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_REDRAW_RESIZE) == 0) {
- if (hooks (SWT.Paint)) {
- OS.InvalidateRect (handle, null, true);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_SYSCOLORCHANGE (int wParam, int lParam) {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- int hwndChild = children [i].handle;
- OS.SendMessage (hwndChild, OS.WM_SYSCOLORCHANGE, 0, 0);
- }
- return null;
-}
-
-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 (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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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</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>
+ * 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;
+
+/**
+ * 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 = WidgetTable.get (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;
+}
+
+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) {
+ size = layout.computeSize (this, wHint, hHint, 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 () {
+ super.createHandle ();
+ state |= CANVAS;
+}
+
+/**
+ * Returns an array containing the receiver's children.
+ * <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
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 last specified 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);
+}
+
+/**
+ * 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 the argument is <code>true</code> the layout must not rely
+ * on any cached information it is keeping about the children. If it
+ * is <code>false</code> the layout may (potentially) simplify the
+ * work it is doing by assuming that the state of the none of the
+ * receiver's children has changed since the last layout.
+ * If the receiver does not have a layout, do nothing.
+ *
+ * @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;
+ setResizeChildren (false);
+ layout.layout (this, changed);
+ setResizeChildren (true);
+}
+
+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 releaseChildren () {
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (!child.isDisposed ()) child.releaseResources ();
+ }
+}
+
+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 = OS.DeferWindowPos (hdwp, wp.hwnd, 0, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
+ if (hdwp == 0) return false;
+ } else {
+ OS.SetWindowPos (wp.hwnd, 0, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
+ }
+ }
+ }
+ if (defer) return OS.EndDeferWindowPos (hdwp);
+ return true;
+}
+
+void releaseWidget () {
+ releaseChildren ();
+ super.releaseWidget ();
+ layout = null;
+ tabList = null;
+ lpwp = null;
+}
+
+public boolean setFocus () {
+ checkWidget ();
+ if ((style & SWT.NO_FOCUS) != 0) return false;
+ 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;
+}
+
+/**
+ * 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);
+ /*
+ * This code is intentionally commented.
+ * Tab lists are currently only supported
+ * for the direct children of a composite.
+ */
+// Shell shell = control.getShell ();
+// while (control != shell && control != this) {
+// control = control.parent;
+// }
+// if (control != this) error (SWT.ERROR_INVALID_PARENT);
+ 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 ();
+ if ((style & SWT.NO_FOCUS) == 0) {
+ boolean takeFocus = true;
+ 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.setRadioFocus ()) return true;
+ }
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (child.isTabItem () && child.setTabItemFocus ()) return true;
+ }
+ return false;
+}
+
+boolean setTabItemFocus () {
+ if ((style & SWT.NO_FOCUS) == 0) {
+ boolean takeFocus = true;
+ if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
+ if (takeFocus) {
+ if (!isShowing ()) return false;
+ if (forceFocus ()) return true;
+ }
+ }
+ return super.setTabItemFocus ();
+}
+
+String toolTipText (NMTTDISPINFO hdr) {
+ if ((hdr.uFlags & OS.TTF_IDISHWND) == 0) {
+ return null;
+ }
+ int hwnd = hdr.idFrom;
+ if (hwnd == 0) return null;
+ Control control = WidgetTable.get (hwnd);
+ if (control == null) return null;
+ return control.toolTipText;
+}
+
+boolean translateMnemonic (char key) {
+ if (super.translateMnemonic (key)) return true;
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control child = children [i];
+ if (child.translateMnemonic (key)) return true;
+ }
+ return false;
+}
+
+void updateFont (Font oldFont, Font newFont) {
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ Control control = children [i];
+ if (!control.isDisposed ()) {
+ control.updateFont (oldFont, newFont);
+ }
+ }
+ super.updateFont (oldFont, newFont);
+ layout (true);
+}
+
+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) {
+ if ((style & SWT.NO_BACKGROUND) != 0) 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 ((state & CANVAS) != 0) {
+ if ((style & SWT.NO_FOCUS) != 0) return new LRESULT (OS.DLGC_STATIC);
+ if (hooksKeys ()) {
+ int flags = OS.DLGC_WANTALLKEYS | OS.DLGC_WANTARROWS | OS.DLGC_WANTTAB;
+ return new LRESULT (flags);
+ }
+ int count = getChildrenCount ();
+ if (count != 0) return new LRESULT (OS.DLGC_STATIC);
+ }
+ return result;
+}
+
+LRESULT WM_GETFONT (int wParam, int lParam) {
+ LRESULT result = super.WM_GETFONT (wParam, lParam);
+ if (result != null) return result;
+ int code = callWindowProc (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);
+
+ /* Set focus for a canvas with no children */
+ if ((state & CANVAS) != 0) {
+ if ((style & SWT.NO_FOCUS) != 0) return result;
+ if (OS.GetWindow (handle, OS.GW_CHILD) == 0) setFocus ();
+ }
+ 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.
+ */
+ Display display = getDisplay ();
+ 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;
+ OS.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 = new NMTTDISPINFO ();
+ if (hdr.code == OS.TTN_GETDISPINFOA) {
+ OS.MoveMemoryA (lpnmtdi, lParam, NMTTDISPINFO.sizeofA);
+ } else {
+ OS.MoveMemoryW (lpnmtdi, lParam, NMTTDISPINFO.sizeofW);
+ }
+ 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);
+ 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.MoveMemoryA (lParam, lpnmtdi, NMTTDISPINFO.sizeofA);
+ } else {
+ shell.setToolTipText (lpnmtdi, chars);
+ OS.MoveMemoryW (lParam, lpnmtdi, NMTTDISPINFO.sizeofW);
+ }
+ return LRESULT.ZERO;
+ }
+ break;
+ }
+ }
+ }
+ return super.WM_NOTIFY (wParam, lParam);
+}
+
+LRESULT WM_PAINT (int wParam, int lParam) {
+ if ((state & CANVAS) == 0) {
+ return super.WM_PAINT (wParam, lParam);
+ }
+
+ /*
+ * This code is intentionally commented. Don't exit
+ * early because the background must still be painted,
+ * even though no application code will be painting
+ * the widget.
+ *
+ * Do not uncomment this code.
+ */
+// if (!hooks (SWT.Paint)) return null;
+
+ /* Get the damage */
+ int [] lpRgnData = null;
+ boolean isComplex = false;
+ boolean exposeRegion = false;
+ if ((style & SWT.NO_MERGE_PAINTS) != 0) {
+ int rgn = OS.CreateRectRgn (0, 0, 0, 0);
+ isComplex = OS.GetUpdateRgn (handle, rgn, false) == OS.COMPLEXREGION;
+ if (isComplex) {
+ int nBytes = OS.GetRegionData (rgn, 0, null);
+ lpRgnData = new int [nBytes / 4];
+ exposeRegion = OS.GetRegionData (rgn, nBytes, lpRgnData) != 0;
+ }
+ OS.DeleteObject (rgn);
+ }
+
+ /* Set the clipping bits */
+ int oldBits = 0;
+ if (!OS.IsWinCE) {
+ oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ int newBits = oldBits | OS.WS_CLIPSIBLINGS | OS.WS_CLIPCHILDREN;
+ OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
+ }
+
+ /* Create the paint GC */
+ PAINTSTRUCT ps = new PAINTSTRUCT ();
+ GCData data = new GCData ();
+ data.ps = ps;
+ GC gc = GC.win32_new (this, data);
+ int hDC = gc.handle;
+
+ /* Send the paint event */
+ Event event = new Event ();
+ event.gc = gc;
+ if (isComplex && exposeRegion) {
+ RECT rect = new RECT ();
+ int count = lpRgnData [2];
+ for (int i=0; i<count; i++) {
+ OS.SetRect (rect,
+ lpRgnData [8 + (i << 2)],
+ lpRgnData [8 + (i << 2) + 1],
+ lpRgnData [8 + (i << 2) + 2],
+ lpRgnData [8 + (i << 2) + 3]);
+ if ((style & SWT.NO_BACKGROUND) == 0) {
+ drawBackground (hDC, 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;
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the paint
+ * event. If this happens, attempt to give back the
+ * paint GC anyways because this is a scarce Windows
+ * resource.
+ */
+ sendEvent (SWT.Paint, event);
+ if (isDisposed ()) break;
+ }
+ } else {
+ if ((style & SWT.NO_BACKGROUND) == 0) {
+ RECT rect = new RECT ();
+ OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
+ drawBackground (hDC, rect);
+ }
+ 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
+
+ /* Dispose the paint GC */
+ event.gc = null;
+ gc.dispose ();
+
+ if (!OS.IsWinCE) {
+ /*
+ * 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_SETFONT (int wParam, int lParam) {
+ 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) layout.layout (this, false);
+
+ /* End deferred window positioning */
+ setResizeChildren (true);
+
+ /* Damage the widget to cause a repaint */
+ if ((state & CANVAS) != 0) {
+ if ((style & SWT.NO_REDRAW_RESIZE) == 0) {
+ if (hooks (SWT.Paint)) {
+ OS.InvalidateRect (handle, null, true);
+ }
+ }
+ }
+ return result;
+}
+
+LRESULT WM_SYSCOLORCHANGE (int wParam, int lParam) {
+ Control [] children = _getChildren ();
+ for (int i=0; i<children.length; i++) {
+ int hwndChild = children [i].handle;
+ OS.SendMessage (hwndChild, OS.WM_SYSCOLORCHANGE, 0, 0);
+ }
+ return null;
+}
+
+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 (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;
+}
+
+}
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
index 12d66dd630..c601004f37 100755
--- 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
@@ -1,4224 +1,4224 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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</dd>
- * </dl>
- * <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>
- *
- * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
- */
-
-public abstract class Control extends Widget implements Drawable {
- /**
- * the handle to the OS resource
- * (Warning: This field is platform dependent)
- */
- public int handle;
-
- Composite parent;
- int drawCount, hCursor;
- int foreground, background;
- Menu menu;
- String toolTipText;
- Object layoutData;
- Accessible accessible;
-
- static final short [] ACCENTS = new short [] {'~', '`', '\'', '^', '"'};
-
-/**
- * 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);
-}
-
-abstract int callWindowProc (int msg, int wParam, int lParam);
-
-void checkOrientation (Widget parent) {
- super.checkOrientation (parent);
- if ((style & SWT.RIGHT_TO_LEFT) != 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
- * @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
- * @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 = 0;
- if (handle != 0) {
- hwndParent = handle;
- } else {
- if (parent != null) hwndParent = parent.handle;
- }
- handle = OS.CreateWindowEx (
- widgetExtStyle (),
- windowClass (),
- null,
- widgetStyle (),
- OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
- hwndParent,
- 0,
- OS.GetModuleHandle (null),
- null);
- 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 && parent != null) {
- int hIMC = OS.ImmGetContext (hwndParent);
- OS.ImmAssociateContext (handle, hIMC);
- OS.ImmReleaseContext (hwndParent, hIMC);
- }
-}
-
-void createWidget () {
- foreground = background = -1;
- checkOrientation (parent);
- createHandle ();
- register ();
- subclass ();
- setDefaultFont ();
-}
-
-int defaultBackground () {
- if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOW);
- return OS.GetSysColor (OS.COLOR_BTNFACE);
-}
-
-int defaultFont () {
- Display display = getDisplay ();
- return display.systemFont ();
-}
-
-int defaultForeground () {
- return OS.GetSysColor (OS.COLOR_WINDOWTEXT);
-}
-
-void deregister () {
- WidgetTable.remove (handle);
-}
-
-void destroyWidget () {
- int hwnd = handle;
- 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) {
- Display display = getDisplay ();
- int hPalette = display.hPalette;
- if (hPalette != 0) {
- OS.SelectPalette (hDC, hPalette, false);
- OS.RealizePalette (hDC);
- }
- int pixel = getBackgroundPixel ();
- int hBrush = findBrush (pixel);
- OS.FillRect (hDC, rect, hBrush);
-}
-
-int findBrush (int pixel) {
- return parent.findBrush (pixel);
-}
-
-int findCursor () {
- if (hCursor != 0) return hCursor;
- return parent.findCursor ();
-}
-
-char findMnemonic (String string) {
- int index = 0;
- int length = string.length ();
- do {
- while (index < length && string.charAt (index) != Mnemonic) index++;
- if (++index >= length) return '\0';
- if (string.charAt (index) != Mnemonic) return string.charAt (index);
- index++;
- } while (index < length);
- return '\0';
-}
-
-void fixFocus () {
- Shell shell = getShell ();
- Control control = this;
- while ((control = control.parent) != null) {
- if (control.setFocus () || control == shell) return;
- }
- 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 ();
- Decorations shell = menuShell ();
- shell.setSavedFocus (this);
- if (!isEnabled () || !isVisible () || !isActive ()) return false;
- if (isFocusControl ()) return true;
- shell.bringToTop ();
- /*
- * 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);
- 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;
-// }
- OS.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 ();
- return Color.win32_new (getDisplay (), getBackgroundPixel ());
-}
-
-int getBackgroundPixel () {
- if (background == -1) return defaultBackground ();
- return background;
-}
-
-/**
- * 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 bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
- if ((bits & OS.WS_EX_CLIENTEDGE) != 0) return OS.GetSystemMetrics (OS.SM_CXEDGE);
- if ((bits & OS.WS_EX_STATICEDGE) != 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).
- *
- * @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 (handle, 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 () {
- int hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- LOGFONT logFont = new LOGFONT ();
- 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 ();
-}
-
-/**
- * Returns the display that the receiver was created on.
- *
- * @return the receiver's 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 Display getDisplay () {
- Composite parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
-/**
- * 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 (getDisplay (), 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 (getDisplay (), getForegroundPixel ());
-}
-
-int getForegroundPixel () {
- if (foreground == -1) return defaultForeground ();
- return foreground;
-}
-
-/**
- * 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).
- *
- * @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 (handle, 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 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 (handle, 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 ();
- 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;
- if (OS.MapWindowPoints (handle, 0, rect, 2) == 0) return false;
- 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 (WidgetTable.get (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
- *
- * @private
- */
-public int internal_new_GC (GCData data) {
- checkWidget();
- int hDC;
- if (data == null || data.ps == null) {
- hDC = OS.GetDC (handle);
- } else {
- hDC = OS.BeginPaint (handle, data.ps);
- }
- if (hDC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (data != null) {
- data.device = getDisplay ();
- data.foreground = getForegroundPixel ();
- data.background = getBackgroundPixel ();
- data.hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- data.hwnd = handle;
- }
- 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 handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
- */
-public void internal_dispose_GC (int hDC, GCData data) {
- checkWidget ();
- if (data == null || data.ps == null) {
- OS.ReleaseDC (handle, hDC);
- } else {
- OS.EndPaint (handle, data.ps);
- }
-}
-
-boolean isActive () {
- Display display = getDisplay ();
- Shell modal = display.getModalShell ();
- if (modal != null && modal != this) {
- if ((modal.style & SWT.PRIMARY_MODAL) != 0) {
- Shell shell = getShell ();
- if (modal.parent == shell) {
- return false;
- }
- }
- int bits = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
- if ((modal.style & bits) != 0) {
- Control control = this;
- while (control != null) {
- if (control == modal) break;
- control = control.parent;
- }
- if (control != modal) return false;
- }
- }
- return getShell ().getEnabled ();
-}
-
-public boolean isDisposed () {
- return handle == 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 ();
-}
-
-/**
- * Returns <code>true</code> if the receiver has the user-interface
- * focus, and <code>false</code> otherwise.
- *
- * @return the receiver's focus state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean isFocusControl () {
- checkWidget ();
- return hasFocus ();
-}
-
-boolean isFocusAncestor () {
- Display display = getDisplay ();
- Control control = display.getFocusControl ();
- 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
- * 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.IsWindowVisible (handle);
-}
-
-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 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>
- */
-public void moveAbove (Control control) {
- checkWidget ();
- int hwndAbove = OS.HWND_TOP;
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- int hwnd = control.handle;
- if (hwnd == 0 || hwnd == handle) 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;
- OS.SetWindowPos (handle, 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 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>
- */
-public void moveBelow (Control control) {
- checkWidget ();
- int hwndAbove = OS.HWND_BOTTOM;
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- hwndAbove = control.handle;
- }
- if (hwndAbove == 0 || hwndAbove == handle) return;
- int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
- OS.SetWindowPos (handle, hwndAbove, 0, 0, 0, 0, flags);
-}
-
-Accessible new_Accessible (Control control) {
- return Accessible.internal_new_Accessible (this);
-}
-
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize
- */
-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>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
- */
-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.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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
- */
-public void redraw () {
- 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;
- 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. 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
- */
-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);
- }
-}
-
-void register () {
- WidgetTable.put (handle, this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- if (OS.IsDBLocale) {
- OS.ImmAssociateContext (handle, 0);
- }
- if (toolTipText != null) {
- Shell shell = getShell ();
- shell.setToolTipText (handle, null);
- }
- toolTipText = null;
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- menu = null;
- deregister ();
- unsubclass ();
- parent = null;
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 sendKeyEvent (int type, int msg, int wParam, int lParam) {
- Event event = new Event ();
- if (!setKeyState (event, type)) return true;
- return sendKeyEvent (type, msg, wParam, lParam, event);
-}
-
-boolean sendKeyEvent (int type, int msg, int wParam, int lParam, Event event) {
- postEvent (type, event);
- return true;
-}
-
-boolean sendMouseEvent (int type, int button, int msg, int wParam, int lParam) {
- Event event = new Event ();
- event.button = button;
- event.x = (short) (lParam & 0xFFFF);
- event.y = (short) (lParam >> 16);
- setInputState (event, type);
- return sendMouseEvent (type, msg, wParam, lParam, event);
-}
-
-boolean sendMouseEvent (int type, int msg, int wParam, int lParam, Event event) {
- postEvent (type, event);
- return true;
-}
-
-/**
- * Sets the receiver's background color to the color specified
- * by the argument, or to the default system color for the control
- * if the argument is null.
- *
- * @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;
- }
- setBackgroundPixel (pixel);
-}
-
-void setBackgroundPixel (int pixel) {
- if (background == pixel) return;
- background = pixel;
- OS.InvalidateRect (handle, null, 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).
- * <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) {
- if (parent == null) {
- OS.SetWindowPos (handle, 0, x, y, width, height, flags);
- return;
- }
- if (parent.lpwp == 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) flags |= OS.SWP_NOCOPYBITS;
-// }
- OS.SetWindowPos (handle, 0, x, y, width, height, flags);
- return;
- }
- forceResize ();
- WINDOWPOS [] lpwp = parent.lpwp;
- 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 = handle;
- wp.x = x;
- wp.y = y;
- wp.cx = width;
- wp.cy = height;
- wp.flags = flags;
- lpwp [index] = wp;
-}
-
-/**
- * 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 ();
- }
- }
-}
-
-/**
- * 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 ();
- hCursor = 0;
- if (cursor != null) {
- if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- hCursor = cursor.handle;
- }
- if (OS.IsWinCE) {
- 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;
- }
- int lParam = OS.HTCLIENT | (OS.WM_MOUSEMOVE << 16);
- OS.SendMessage (hwndCursor, OS.WM_SETCURSOR, hwndCursor, lParam);
-}
-
-void setDefaultFont () {
- Display display = getDisplay ();
- int hFont = display.systemFont ();
- 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.
- */
- boolean fixFocus = false;
- if (!enabled) fixFocus = isFocusAncestor ();
- OS.EnableWindow (handle, enabled);
- if (fixFocus) fixFocus ();
-}
-
-/**
- * Causes the receiver to have the <em>keyboard focus</em>,
- * such that all keyboard events will 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 #forceFocus
- */
-public boolean setFocus () {
- checkWidget ();
- 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;
- }
- setForegroundPixel (pixel);
-}
-
-void setForegroundPixel (int pixel) {
- if (foreground == pixel) return;
- foreground = 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).
- *
- * @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 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 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.
- *
- * @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.
- * <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
- * @see #update
- */
-public void setRedraw (boolean redraw) {
- checkWidget ();
- /*
- * This code is intentionally commented.
- *
- * 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.
- *
- * There is no fix at this time.
- */
-// if (drawCount == 0) {
-// int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
-// if ((bits & OS.WS_VISIBLE) == 0) return;
-// }
-
- if (redraw) {
- if (--drawCount == 0) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- 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
- * @param height the new height 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 setFocus ();
-}
-
-/**
- * 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 ();
- Shell shell = getShell ();
- shell.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 bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if (((bits & OS.WS_VISIBLE) != 0) == 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;
- }
-
- /*
- * 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.
- */
- boolean fixFocus = false;
- if (!visible) fixFocus = isFocusAncestor ();
- OS.ShowWindow (handle, visible ? OS.SW_SHOW : OS.SW_HIDE);
- if (!visible) {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the show
- * event. If this happens, just return.
- */
- sendEvent (SWT.Hide);
- if (isDisposed ()) return;
- }
- if (fixFocus) fixFocus ();
-}
-
-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 = getDisplay ().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);
-}
-
-boolean translateAccelerator (MSG msg) {
- return menuShell ().translateAccelerator (msg);
-}
-
-boolean translateMnemonic (char key) {
- if (!isVisible () || !isEnabled ()) return false;
- Event event = new Event ();
- event.doit = mnemonicMatch (key);
- event.detail = SWT.TRAVERSE_MNEMONIC;
- Display display = getDisplay ();
- display.lastKey = 0;
- display.lastAscii = key;
- display.lastVirtual = display.lastNull = false;
- if (!setKeyState (event, SWT.Traverse)) {
- return false;
- }
- return traverse (event);
-}
-
-boolean translateMnemonic (MSG msg) {
- 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 ()) {
- char ch = mbcsToWcs ((char) msg.wParam);
- return ch != 0 && shell.translateMnemonic (ch);
- }
- return false;
-}
-
-boolean translateTraversal (MSG msg) {
- int key = msg.wParam;
- if (key == OS.VK_MENU) {
- Shell shell = getShell ();
- int hwndShell = shell.handle;
- OS.SendMessage (hwndShell, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
- return false;
- }
- int hwnd = msg.hwnd;
- 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: {
- /*
- * NOTE: This code causes Shift+Tab and Ctrl+Tab to
- * always attempt traversal which is not correct.
- * The default should be the same as a plain Tab key.
- * This behavior is currently relied on by StyledText.
- *
- * The correct behavior is to give every key to a
- * control that answers DLGC_WANTALLKEYS.
- */
- 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) {
- if (next && OS.GetKeyState (OS.VK_CONTROL) >= 0) doit = false;
- }
- detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
- break;
- }
- case OS.VK_UP:
- case OS.VK_LEFT:
- case OS.VK_DOWN:
- case OS.VK_RIGHT: {
- /*
- * On WinCE SP there is no tab key. Focus is assigned
- * using only 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;
- /*
- * The fact that this code is commented causes Ctrl+PgUp
- * and Ctrl+PgDn to always attempt traversal which is not
- * correct. This behavior is relied on by StyledText.
- *
- * The correct behavior is to give every key to a control
- * that answers DLGC_WANTALLKEYS.
- */
-// int code = OS.SendMessage (hwnd, OS., 0, 0);
-// if ((code & OS.DLGC_WANTALLKEYS) != 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 display = getDisplay ();
- display.lastKey = lastKey;
- display.lastAscii = lastAscii;
- display.lastVirtual = lastVirtual;
- display.lastNull = false;
- if (!setKeyState (event, SWT.Traverse)) {
- return false;
- }
- Shell shell = getShell ();
- Control control = this;
- do {
- if (control.traverse (event)) {
- int hwndShell = shell.handle;
- OS.SendMessage (hwndShell, 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 false;
- 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 ();
- if (!isFocusControl () && !setFocus ()) return false;
- 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 ()) {
- if (!isDisposed () && !isFocusControl ()) 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.
- */
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- Control child = children [index];
- if (!child.isDisposed () && child.isTabItem ()) {
- if (child.setTabItemFocus ()) return true;
- }
- }
- return false;
-}
-
-boolean traverseMnemonic (char key) {
- return mnemonicHit (key);
-}
-
-boolean traversePage (boolean next) {
- return false;
-}
-
-boolean traverseReturn () {
- return false;
-}
-
-void unsubclass () {
- int newProc = windowProc ();
- int oldProc = getDisplay ().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
- */
-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 updateFont (Font oldFont, Font newFont) {
- Font font = getFont ();
- if (font.equals (oldFont)) setFont (newFont);
-}
-
-int widgetExtStyle () {
- int bits = 0;
- if ((style & SWT.BORDER) != 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_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {
- return bits;
- }
- bits |= OS.WS_EX_NOINHERITLAYOUT;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) bits |= OS.WS_EX_LAYOUTRTL;
- return bits;
-}
-
-int widgetStyle () {
- /* Force clipping of siblings by setting WS_CLIPSIBLINGS */
- return OS.WS_CHILD | OS.WS_VISIBLE | OS.WS_CLIPSIBLINGS;
-
- /*
- * 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.
- * Answers <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>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
- * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</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 (OS.SetParent (handle, parent.handle) == 0) {
- return false;
- }
- this.parent = parent;
- return true;
-}
-
-abstract TCHAR windowClass ();
-
-abstract int windowProc ();
-
-int windowProc (int msg, int wParam, int lParam) {
- LRESULT result = null;
- switch (msg) {
- case OS.WM_ACTIVATE: result = WM_ACTIVATE (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_ERASEBKGND: result = WM_ERASEBKGND (wParam, lParam); break;
- case OS.WM_GETDLGCODE: result = WM_GETDLGCODE (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_GETFONT: result = WM_GETFONT (wParam, lParam); break;
- case OS.WM_GETOBJECT: result = WM_GETOBJECT (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_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_PASTE: result = WM_PASTE (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_VSCROLL: result = WM_VSCROLL (wParam, lParam); break;
- case OS.WM_WINDOWPOSCHANGING: result = WM_WINDOWPOSCHANGING (wParam, lParam); break;
- }
- if (result != null) return result.value;
- return callWindowProc (msg, wParam, lParam);
-}
-
-LRESULT WM_ACTIVATE (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_CHAR (int wParam, int lParam) {
-
- /*
- * Do not report a lead byte as a key pressed.
- */
- Display display = getDisplay ();
- if (!OS.IsUnicode && OS.IsDBLocale) {
- byte lead = (byte) (wParam & 0xFF);
- if (OS.IsDBCSLeadByte (lead)) return null;
- }
-
- /*
- * Use VkKeyScan () to tell us if the character is a control
- * or a numeric key pad character with Num Lock down. On
- * international keyboards, the control key may be down when
- * the character is not a control character. In this case
- * use the last key (computed in WM_KEYDOWN) instead of wParam
- * as the keycode because there is not enough information to
- * compute the keycode in WPARAM.
- */
- display.lastAscii = wParam;
- display.lastNull = false;
- if (display.lastKey == 0) {
- display.lastKey = wParam;
- display.lastVirtual = display.isVirtualKey (wParam);
- } else {
- int result = OS.IsWinCE ? 0 : OS.VkKeyScan ((short) wParam);
- if (!OS.IsWinCE && (result == -1 || (result >> 8) <= 2)) {
- if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
- display.lastVirtual = display.isVirtualKey (display.lastKey);
- }
- } else {
- display.lastKey = wParam;
- display.lastVirtual = false;
- }
- }
- if (!sendKeyEvent (SWT.KeyDown, OS.WM_CHAR, wParam, lParam)) {
- return LRESULT.ZERO;
- }
- return null;
-}
-
-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 = shell.findMenuItem (id);
- if (item != null && item.isEnabled ()) {
- return item.wmCommandChild (wParam, lParam);
- }
- }
- return null;
- }
- Control control = WidgetTable.get (lParam);
- if (control == null) return null;
- return control.wmCommandChild (wParam, lParam);
-}
-
-LRESULT WM_CONTEXTMENU (int wParam, int lParam) {
- if (wParam != handle) 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.
- */
- POINT pt = new POINT ();
- pt.x = (short) (lParam & 0xFFFF);
- pt.y = (short) (lParam >> 16);
- if (pt.x != -1 || pt.y != -1) {
- RECT rect = new RECT ();
- OS.GetClientRect (handle, rect);
- OS.ScreenToClient (handle, pt);
- if (!OS.PtInRect (rect, pt)) return null;
- }
-
- /*
- * Because context menus can be shared between controls
- * and the parent of all menus is the shell, the menu may
- * have been destroyed.
- */
- if (menu != null && !menu.isDisposed ()) {
-// menu.setLocation (x, y);
- menu.setVisible (true);
- return LRESULT.ZERO;
- }
- return null;
-}
-
-LRESULT WM_CTLCOLOR (int wParam, int lParam) {
- Display display = getDisplay ();
- int hPalette = display.hPalette;
- if (hPalette != 0) {
- OS.SelectPalette (wParam, hPalette, false);
- OS.RealizePalette (wParam);
- }
- Control control = WidgetTable.get (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) {
- Decorations shell = menuShell ();
- MenuItem item = shell.findMenuItem (struct.itemID);
- if (item == null) return null;
- return item.wmDrawChild (wParam, lParam);
- }
- Control control = WidgetTable.get (struct.hwndItem);
- if (control == null) return null;
- return control.wmDrawChild (wParam, lParam);
-}
-
-LRESULT WM_ENDSESSION (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_ERASEBKGND (int wParam, int lParam) {
- 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_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 = shell.findMenuItem (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 = WidgetTable.get (lParam);
- if (control == null) return null;
- return control.wmScrollChild (wParam, lParam);
-}
-
-LRESULT WM_IME_CHAR (int wParam, int lParam) {
- Display display = getDisplay ();
- display.lastKey = 0;
- display.lastAscii = wParam;
- display.lastVirtual = display.lastNull = false;
- sendKeyEvent (SWT.KeyDown, OS.WM_IME_CHAR, wParam, lParam);
- sendKeyEvent (SWT.KeyUp, OS.WM_IME_CHAR, wParam, lParam);
- display.lastKey = display.lastAscii = 0;
- return LRESULT.ZERO;
-}
-
-LRESULT WM_IME_COMPOSITION (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_INITMENUPOPUP (int wParam, int lParam) {
-
- /* Ignore WM_INITMENUPOPUP for an accelerator */
- Display display = getDisplay ();
- 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);
- }
- 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) {
- /*
- * SWT.Selection events are posted to allow stepping
- * in the VA/Java debugger. SWT.Show events are
- * sent to ensure that application event handler
- * code runs before the menu is displayed. This
- * means that SWT.Show events would normally occur
- * before SWT.Selection events. While this is not
- * strictly incorrect, applications often use the
- * SWT.Selection event to update the state of menu
- * items and would like the ordering of events to
- * be the other way around.
- *
- * The fix is to run the deferred events before
- * the menu is shown. This means that stepping
- * through a selection event that was caused by
- * a popup menu will fail in VA/Java.
- */
- display.runDeferredEvents ();
- newMenu.sendEvent (SWT.Show);
- // widget could be disposed at this point
- }
- return null;
-}
-
-LRESULT WM_KEYDOWN (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 display = getDisplay ();
- display.lastAscii = display.lastKey = 0;
- display.lastVirtual = display.lastNull = 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 on 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.
- */
- int mapKey = OS.IsWinCE ? 0 : 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. On Windows 95 and NT, a call to ToAscii (), clears the
- * accented state such that the next WM_CHAR loses the accent. 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.
- *
- * NOTE: This code is used to avoid a call to ToAscii ().
- */
- if (OS.IsWinNT) {
- if ((mapKey & 0x80000000) != 0) return null;
- } else {
- if ((mapKey & 0x8000) != 0) return null;
- }
-
- /*
- * Bug in Windows. When the accent key is generated on an international
- * keyboard using Ctrl+Alt or the special key, MapVirtualKey () does not
- * have the high bit set indicating that this is an accent key stroke.
- * The fix is to iterate through all known accent, mapping them back to
- * their corresponding virtual key and key state. If the virtual key
- * and key state match the current key, then this is an accent that has
- * been generated using an international keyboard and calling ToAscii ()
- * will clear the accent state.
- *
- * NOTE: This code is used to avoid a call to ToAscii ().
- */
- if (!OS.IsWinCE) {
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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</dd>
+ * </dl>
+ * <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>
+ *
+ * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
+ */
+
+public abstract class Control extends Widget implements Drawable {
+ /**
+ * the handle to the OS resource
+ * (Warning: This field is platform dependent)
+ */
+ public int handle;
+
+ Composite parent;
+ int drawCount, hCursor;
+ int foreground, background;
+ Menu menu;
+ String toolTipText;
+ Object layoutData;
+ Accessible accessible;
+
+ static final short [] ACCENTS = new short [] {'~', '`', '\'', '^', '"'};
+
+/**
+ * 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);
+}
+
+abstract int callWindowProc (int msg, int wParam, int lParam);
+
+void checkOrientation (Widget parent) {
+ super.checkOrientation (parent);
+ if ((style & SWT.RIGHT_TO_LEFT) != 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
+ * @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
+ * @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 = 0;
+ if (handle != 0) {
+ hwndParent = handle;
+ } else {
+ if (parent != null) hwndParent = parent.handle;
+ }
+ handle = OS.CreateWindowEx (
+ widgetExtStyle (),
+ windowClass (),
+ null,
+ widgetStyle (),
+ OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
+ hwndParent,
+ 0,
+ OS.GetModuleHandle (null),
+ null);
+ 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 && parent != null) {
+ int hIMC = OS.ImmGetContext (hwndParent);
+ OS.ImmAssociateContext (handle, hIMC);
+ OS.ImmReleaseContext (hwndParent, hIMC);
+ }
+}
+
+void createWidget () {
+ foreground = background = -1;
+ checkOrientation (parent);
+ createHandle ();
+ register ();
+ subclass ();
+ setDefaultFont ();
+}
+
+int defaultBackground () {
+ if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOW);
+ return OS.GetSysColor (OS.COLOR_BTNFACE);
+}
+
+int defaultFont () {
+ Display display = getDisplay ();
+ return display.systemFont ();
+}
+
+int defaultForeground () {
+ return OS.GetSysColor (OS.COLOR_WINDOWTEXT);
+}
+
+void deregister () {
+ WidgetTable.remove (handle);
+}
+
+void destroyWidget () {
+ int hwnd = handle;
+ 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) {
+ Display display = getDisplay ();
+ int hPalette = display.hPalette;
+ if (hPalette != 0) {
+ OS.SelectPalette (hDC, hPalette, false);
+ OS.RealizePalette (hDC);
+ }
+ int pixel = getBackgroundPixel ();
+ int hBrush = findBrush (pixel);
+ OS.FillRect (hDC, rect, hBrush);
+}
+
+int findBrush (int pixel) {
+ return parent.findBrush (pixel);
+}
+
+int findCursor () {
+ if (hCursor != 0) return hCursor;
+ return parent.findCursor ();
+}
+
+char findMnemonic (String string) {
+ int index = 0;
+ int length = string.length ();
+ do {
+ while (index < length && string.charAt (index) != Mnemonic) index++;
+ if (++index >= length) return '\0';
+ if (string.charAt (index) != Mnemonic) return string.charAt (index);
+ index++;
+ } while (index < length);
+ return '\0';
+}
+
+void fixFocus () {
+ Shell shell = getShell ();
+ Control control = this;
+ while ((control = control.parent) != null) {
+ if (control.setFocus () || control == shell) return;
+ }
+ 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 ();
+ Decorations shell = menuShell ();
+ shell.setSavedFocus (this);
+ if (!isEnabled () || !isVisible () || !isActive ()) return false;
+ if (isFocusControl ()) return true;
+ shell.bringToTop ();
+ /*
+ * 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);
+ 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;
+// }
+ OS.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 ();
+ return Color.win32_new (getDisplay (), getBackgroundPixel ());
+}
+
+int getBackgroundPixel () {
+ if (background == -1) return defaultBackground ();
+ return background;
+}
+
+/**
+ * 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 bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
+ if ((bits & OS.WS_EX_CLIENTEDGE) != 0) return OS.GetSystemMetrics (OS.SM_CXEDGE);
+ if ((bits & OS.WS_EX_STATICEDGE) != 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).
+ *
+ * @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 (handle, 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 () {
+ int hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
+ LOGFONT logFont = new LOGFONT ();
+ 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 ();
+}
+
+/**
+ * Returns the display that the receiver was created on.
+ *
+ * @return the receiver's 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 Display getDisplay () {
+ Composite parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
+/**
+ * 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 (getDisplay (), 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 (getDisplay (), getForegroundPixel ());
+}
+
+int getForegroundPixel () {
+ if (foreground == -1) return defaultForeground ();
+ return foreground;
+}
+
+/**
+ * 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).
+ *
+ * @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 (handle, 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 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 (handle, 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 ();
+ 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;
+ if (OS.MapWindowPoints (handle, 0, rect, 2) == 0) return false;
+ 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 (WidgetTable.get (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
+ *
+ * @private
+ */
+public int internal_new_GC (GCData data) {
+ checkWidget();
+ int hDC;
+ if (data == null || data.ps == null) {
+ hDC = OS.GetDC (handle);
+ } else {
+ hDC = OS.BeginPaint (handle, data.ps);
+ }
+ if (hDC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+ if (data != null) {
+ data.device = getDisplay ();
+ data.foreground = getForegroundPixel ();
+ data.background = getBackgroundPixel ();
+ data.hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
+ data.hwnd = handle;
+ }
+ 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 handle the platform specific GC handle
+ * @param data the platform specific GC data
+ *
+ * @private
+ */
+public void internal_dispose_GC (int hDC, GCData data) {
+ checkWidget ();
+ if (data == null || data.ps == null) {
+ OS.ReleaseDC (handle, hDC);
+ } else {
+ OS.EndPaint (handle, data.ps);
+ }
+}
+
+boolean isActive () {
+ Display display = getDisplay ();
+ Shell modal = display.getModalShell ();
+ if (modal != null && modal != this) {
+ if ((modal.style & SWT.PRIMARY_MODAL) != 0) {
+ Shell shell = getShell ();
+ if (modal.parent == shell) {
+ return false;
+ }
+ }
+ int bits = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL;
+ if ((modal.style & bits) != 0) {
+ Control control = this;
+ while (control != null) {
+ if (control == modal) break;
+ control = control.parent;
+ }
+ if (control != modal) return false;
+ }
+ }
+ return getShell ().getEnabled ();
+}
+
+public boolean isDisposed () {
+ return handle == 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 ();
+}
+
+/**
+ * Returns <code>true</code> if the receiver has the user-interface
+ * focus, and <code>false</code> otherwise.
+ *
+ * @return the receiver's focus state
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public boolean isFocusControl () {
+ checkWidget ();
+ return hasFocus ();
+}
+
+boolean isFocusAncestor () {
+ Display display = getDisplay ();
+ Control control = display.getFocusControl ();
+ 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
+ * 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.IsWindowVisible (handle);
+}
+
+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 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>
+ */
+public void moveAbove (Control control) {
+ checkWidget ();
+ int hwndAbove = OS.HWND_TOP;
+ if (control != null) {
+ if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
+ if (parent != control.parent) return;
+ int hwnd = control.handle;
+ if (hwnd == 0 || hwnd == handle) 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;
+ OS.SetWindowPos (handle, 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 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>
+ */
+public void moveBelow (Control control) {
+ checkWidget ();
+ int hwndAbove = OS.HWND_BOTTOM;
+ if (control != null) {
+ if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
+ if (parent != control.parent) return;
+ hwndAbove = control.handle;
+ }
+ if (hwndAbove == 0 || hwndAbove == handle) return;
+ int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
+ OS.SetWindowPos (handle, hwndAbove, 0, 0, 0, 0, flags);
+}
+
+Accessible new_Accessible (Control control) {
+ return Accessible.internal_new_Accessible (this);
+}
+
+/**
+ * Causes the receiver to be resized to its preferred size.
+ * For a composite, this involves computing the preferred size
+ * from its layout, if there is one.
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @see #computeSize
+ */
+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>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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
+ */
+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.
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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
+ */
+public void redraw () {
+ 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;
+ 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. 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
+ */
+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);
+ }
+}
+
+void register () {
+ WidgetTable.put (handle, this);
+}
+
+void releaseHandle () {
+ super.releaseHandle ();
+ handle = 0;
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ if (OS.IsDBLocale) {
+ OS.ImmAssociateContext (handle, 0);
+ }
+ if (toolTipText != null) {
+ Shell shell = getShell ();
+ shell.setToolTipText (handle, null);
+ }
+ toolTipText = null;
+ if (menu != null && !menu.isDisposed ()) {
+ menu.dispose ();
+ }
+ menu = null;
+ deregister ();
+ unsubclass ();
+ parent = null;
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 sendKeyEvent (int type, int msg, int wParam, int lParam) {
+ Event event = new Event ();
+ if (!setKeyState (event, type)) return true;
+ return sendKeyEvent (type, msg, wParam, lParam, event);
+}
+
+boolean sendKeyEvent (int type, int msg, int wParam, int lParam, Event event) {
+ postEvent (type, event);
+ return true;
+}
+
+boolean sendMouseEvent (int type, int button, int msg, int wParam, int lParam) {
+ Event event = new Event ();
+ event.button = button;
+ event.x = (short) (lParam & 0xFFFF);
+ event.y = (short) (lParam >> 16);
+ setInputState (event, type);
+ return sendMouseEvent (type, msg, wParam, lParam, event);
+}
+
+boolean sendMouseEvent (int type, int msg, int wParam, int lParam, Event event) {
+ postEvent (type, event);
+ return true;
+}
+
+/**
+ * Sets the receiver's background color to the color specified
+ * by the argument, or to the default system color for the control
+ * if the argument is null.
+ *
+ * @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;
+ }
+ setBackgroundPixel (pixel);
+}
+
+void setBackgroundPixel (int pixel) {
+ if (background == pixel) return;
+ background = pixel;
+ OS.InvalidateRect (handle, null, 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).
+ * <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) {
+ if (parent == null) {
+ OS.SetWindowPos (handle, 0, x, y, width, height, flags);
+ return;
+ }
+ if (parent.lpwp == 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) flags |= OS.SWP_NOCOPYBITS;
+// }
+ OS.SetWindowPos (handle, 0, x, y, width, height, flags);
+ return;
+ }
+ forceResize ();
+ WINDOWPOS [] lpwp = parent.lpwp;
+ 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 = handle;
+ wp.x = x;
+ wp.y = y;
+ wp.cx = width;
+ wp.cy = height;
+ wp.flags = flags;
+ lpwp [index] = wp;
+}
+
+/**
+ * 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 ();
+ }
+ }
+}
+
+/**
+ * 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 ();
+ hCursor = 0;
+ if (cursor != null) {
+ if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ hCursor = cursor.handle;
+ }
+ if (OS.IsWinCE) {
+ 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;
+ }
+ int lParam = OS.HTCLIENT | (OS.WM_MOUSEMOVE << 16);
+ OS.SendMessage (hwndCursor, OS.WM_SETCURSOR, hwndCursor, lParam);
+}
+
+void setDefaultFont () {
+ Display display = getDisplay ();
+ int hFont = display.systemFont ();
+ 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.
+ */
+ boolean fixFocus = false;
+ if (!enabled) fixFocus = isFocusAncestor ();
+ OS.EnableWindow (handle, enabled);
+ if (fixFocus) fixFocus ();
+}
+
+/**
+ * Causes the receiver to have the <em>keyboard focus</em>,
+ * such that all keyboard events will 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 #forceFocus
+ */
+public boolean setFocus () {
+ checkWidget ();
+ 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;
+ }
+ setForegroundPixel (pixel);
+}
+
+void setForegroundPixel (int pixel) {
+ if (foreground == pixel) return;
+ foreground = 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).
+ *
+ * @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 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 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.
+ *
+ * @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.
+ * <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
+ * @see #update
+ */
+public void setRedraw (boolean redraw) {
+ checkWidget ();
+ /*
+ * This code is intentionally commented.
+ *
+ * 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.
+ *
+ * There is no fix at this time.
+ */
+// if (drawCount == 0) {
+// int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+// if ((bits & OS.WS_VISIBLE) == 0) return;
+// }
+
+ if (redraw) {
+ if (--drawCount == 0) {
+ OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
+ 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
+ * @param height the new height 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 setFocus ();
+}
+
+/**
+ * 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 ();
+ Shell shell = getShell ();
+ shell.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 bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if (((bits & OS.WS_VISIBLE) != 0) == 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;
+ }
+
+ /*
+ * 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.
+ */
+ boolean fixFocus = false;
+ if (!visible) fixFocus = isFocusAncestor ();
+ OS.ShowWindow (handle, visible ? OS.SW_SHOW : OS.SW_HIDE);
+ if (!visible) {
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the show
+ * event. If this happens, just return.
+ */
+ sendEvent (SWT.Hide);
+ if (isDisposed ()) return;
+ }
+ if (fixFocus) fixFocus ();
+}
+
+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 = getDisplay ().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);
+}
+
+boolean translateAccelerator (MSG msg) {
+ return menuShell ().translateAccelerator (msg);
+}
+
+boolean translateMnemonic (char key) {
+ if (!isVisible () || !isEnabled ()) return false;
+ Event event = new Event ();
+ event.doit = mnemonicMatch (key);
+ event.detail = SWT.TRAVERSE_MNEMONIC;
+ Display display = getDisplay ();
+ display.lastKey = 0;
+ display.lastAscii = key;
+ display.lastVirtual = display.lastNull = false;
+ if (!setKeyState (event, SWT.Traverse)) {
+ return false;
+ }
+ return traverse (event);
+}
+
+boolean translateMnemonic (MSG msg) {
+ 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 ()) {
+ char ch = mbcsToWcs ((char) msg.wParam);
+ return ch != 0 && shell.translateMnemonic (ch);
+ }
+ return false;
+}
+
+boolean translateTraversal (MSG msg) {
+ int key = msg.wParam;
+ if (key == OS.VK_MENU) {
+ Shell shell = getShell ();
+ int hwndShell = shell.handle;
+ OS.SendMessage (hwndShell, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0);
+ return false;
+ }
+ int hwnd = msg.hwnd;
+ 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: {
+ /*
+ * NOTE: This code causes Shift+Tab and Ctrl+Tab to
+ * always attempt traversal which is not correct.
+ * The default should be the same as a plain Tab key.
+ * This behavior is currently relied on by StyledText.
+ *
+ * The correct behavior is to give every key to a
+ * control that answers DLGC_WANTALLKEYS.
+ */
+ 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) {
+ if (next && OS.GetKeyState (OS.VK_CONTROL) >= 0) doit = false;
+ }
+ detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
+ break;
+ }
+ case OS.VK_UP:
+ case OS.VK_LEFT:
+ case OS.VK_DOWN:
+ case OS.VK_RIGHT: {
+ /*
+ * On WinCE SP there is no tab key. Focus is assigned
+ * using only 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;
+ /*
+ * The fact that this code is commented causes Ctrl+PgUp
+ * and Ctrl+PgDn to always attempt traversal which is not
+ * correct. This behavior is relied on by StyledText.
+ *
+ * The correct behavior is to give every key to a control
+ * that answers DLGC_WANTALLKEYS.
+ */
+// int code = OS.SendMessage (hwnd, OS., 0, 0);
+// if ((code & OS.DLGC_WANTALLKEYS) != 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 display = getDisplay ();
+ display.lastKey = lastKey;
+ display.lastAscii = lastAscii;
+ display.lastVirtual = lastVirtual;
+ display.lastNull = false;
+ if (!setKeyState (event, SWT.Traverse)) {
+ return false;
+ }
+ Shell shell = getShell ();
+ Control control = this;
+ do {
+ if (control.traverse (event)) {
+ int hwndShell = shell.handle;
+ OS.SendMessage (hwndShell, 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 false;
+ 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 ();
+ if (!isFocusControl () && !setFocus ()) return false;
+ 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 ()) {
+ if (!isDisposed () && !isFocusControl ()) 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.
+ */
+ int start = index, offset = (next) ? 1 : -1;
+ while ((index = (index + offset + length) % length) != start) {
+ Control child = children [index];
+ if (!child.isDisposed () && child.isTabItem ()) {
+ if (child.setTabItemFocus ()) return true;
+ }
+ }
+ return false;
+}
+
+boolean traverseMnemonic (char key) {
+ return mnemonicHit (key);
+}
+
+boolean traversePage (boolean next) {
+ return false;
+}
+
+boolean traverseReturn () {
+ return false;
+}
+
+void unsubclass () {
+ int newProc = windowProc ();
+ int oldProc = getDisplay ().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
+ */
+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 updateFont (Font oldFont, Font newFont) {
+ Font font = getFont ();
+ if (font.equals (oldFont)) setFont (newFont);
+}
+
+int widgetExtStyle () {
+ int bits = 0;
+ if ((style & SWT.BORDER) != 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_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {
+ return bits;
+ }
+ bits |= OS.WS_EX_NOINHERITLAYOUT;
+ if ((style & SWT.RIGHT_TO_LEFT) != 0) bits |= OS.WS_EX_LAYOUTRTL;
+ return bits;
+}
+
+int widgetStyle () {
+ /* Force clipping of siblings by setting WS_CLIPSIBLINGS */
+ return OS.WS_CHILD | OS.WS_VISIBLE | OS.WS_CLIPSIBLINGS;
+
+ /*
+ * 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.
+ * Answers <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>
+ * </ul>
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</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 (OS.SetParent (handle, parent.handle) == 0) {
+ return false;
+ }
+ this.parent = parent;
+ return true;
+}
+
+abstract TCHAR windowClass ();
+
+abstract int windowProc ();
+
+int windowProc (int msg, int wParam, int lParam) {
+ LRESULT result = null;
+ switch (msg) {
+ case OS.WM_ACTIVATE: result = WM_ACTIVATE (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_ERASEBKGND: result = WM_ERASEBKGND (wParam, lParam); break;
+ case OS.WM_GETDLGCODE: result = WM_GETDLGCODE (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_GETFONT: result = WM_GETFONT (wParam, lParam); break;
+ case OS.WM_GETOBJECT: result = WM_GETOBJECT (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_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_PASTE: result = WM_PASTE (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_VSCROLL: result = WM_VSCROLL (wParam, lParam); break;
+ case OS.WM_WINDOWPOSCHANGING: result = WM_WINDOWPOSCHANGING (wParam, lParam); break;
+ }
+ if (result != null) return result.value;
+ return callWindowProc (msg, wParam, lParam);
+}
+
+LRESULT WM_ACTIVATE (int wParam, int lParam) {
+ return null;
+}
+
+LRESULT WM_CHAR (int wParam, int lParam) {
+
+ /*
+ * Do not report a lead byte as a key pressed.
+ */
+ Display display = getDisplay ();
+ if (!OS.IsUnicode && OS.IsDBLocale) {
+ byte lead = (byte) (wParam & 0xFF);
+ if (OS.IsDBCSLeadByte (lead)) return null;
+ }
+
+ /*
+ * Use VkKeyScan () to tell us if the character is a control
+ * or a numeric key pad character with Num Lock down. On
+ * international keyboards, the control key may be down when
+ * the character is not a control character. In this case
+ * use the last key (computed in WM_KEYDOWN) instead of wParam
+ * as the keycode because there is not enough information to
+ * compute the keycode in WPARAM.
+ */
+ display.lastAscii = wParam;
+ display.lastNull = false;
+ if (display.lastKey == 0) {
+ display.lastKey = wParam;
+ display.lastVirtual = display.isVirtualKey (wParam);
+ } else {
+ int result = OS.IsWinCE ? 0 : OS.VkKeyScan ((short) wParam);
+ if (!OS.IsWinCE && (result == -1 || (result >> 8) <= 2)) {
+ if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
+ display.lastVirtual = display.isVirtualKey (display.lastKey);
+ }
+ } else {
+ display.lastKey = wParam;
+ display.lastVirtual = false;
+ }
+ }
+ if (!sendKeyEvent (SWT.KeyDown, OS.WM_CHAR, wParam, lParam)) {
+ return LRESULT.ZERO;
+ }
+ return null;
+}
+
+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 = shell.findMenuItem (id);
+ if (item != null && item.isEnabled ()) {
+ return item.wmCommandChild (wParam, lParam);
+ }
+ }
+ return null;
+ }
+ Control control = WidgetTable.get (lParam);
+ if (control == null) return null;
+ return control.wmCommandChild (wParam, lParam);
+}
+
+LRESULT WM_CONTEXTMENU (int wParam, int lParam) {
+ if (wParam != handle) 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.
+ */
+ POINT pt = new POINT ();
+ pt.x = (short) (lParam & 0xFFFF);
+ pt.y = (short) (lParam >> 16);
+ if (pt.x != -1 || pt.y != -1) {
+ RECT rect = new RECT ();
+ OS.GetClientRect (handle, rect);
+ OS.ScreenToClient (handle, pt);
+ if (!OS.PtInRect (rect, pt)) return null;
+ }
+
+ /*
+ * Because context menus can be shared between controls
+ * and the parent of all menus is the shell, the menu may
+ * have been destroyed.
+ */
+ if (menu != null && !menu.isDisposed ()) {
+// menu.setLocation (x, y);
+ menu.setVisible (true);
+ return LRESULT.ZERO;
+ }
+ return null;
+}
+
+LRESULT WM_CTLCOLOR (int wParam, int lParam) {
+ Display display = getDisplay ();
+ int hPalette = display.hPalette;
+ if (hPalette != 0) {
+ OS.SelectPalette (wParam, hPalette, false);
+ OS.RealizePalette (wParam);
+ }
+ Control control = WidgetTable.get (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) {
+ Decorations shell = menuShell ();
+ MenuItem item = shell.findMenuItem (struct.itemID);
+ if (item == null) return null;
+ return item.wmDrawChild (wParam, lParam);
+ }
+ Control control = WidgetTable.get (struct.hwndItem);
+ if (control == null) return null;
+ return control.wmDrawChild (wParam, lParam);
+}
+
+LRESULT WM_ENDSESSION (int wParam, int lParam) {
+ return null;
+}
+
+LRESULT WM_ERASEBKGND (int wParam, int lParam) {
+ 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_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 = shell.findMenuItem (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 = WidgetTable.get (lParam);
+ if (control == null) return null;
+ return control.wmScrollChild (wParam, lParam);
+}
+
+LRESULT WM_IME_CHAR (int wParam, int lParam) {
+ Display display = getDisplay ();
+ display.lastKey = 0;
+ display.lastAscii = wParam;
+ display.lastVirtual = display.lastNull = false;
+ sendKeyEvent (SWT.KeyDown, OS.WM_IME_CHAR, wParam, lParam);
+ sendKeyEvent (SWT.KeyUp, OS.WM_IME_CHAR, wParam, lParam);
+ display.lastKey = display.lastAscii = 0;
+ return LRESULT.ZERO;
+}
+
+LRESULT WM_IME_COMPOSITION (int wParam, int lParam) {
+ return null;
+}
+
+LRESULT WM_INITMENUPOPUP (int wParam, int lParam) {
+
+ /* Ignore WM_INITMENUPOPUP for an accelerator */
+ Display display = getDisplay ();
+ 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);
+ }
+ 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) {
+ /*
+ * SWT.Selection events are posted to allow stepping
+ * in the VA/Java debugger. SWT.Show events are
+ * sent to ensure that application event handler
+ * code runs before the menu is displayed. This
+ * means that SWT.Show events would normally occur
+ * before SWT.Selection events. While this is not
+ * strictly incorrect, applications often use the
+ * SWT.Selection event to update the state of menu
+ * items and would like the ordering of events to
+ * be the other way around.
+ *
+ * The fix is to run the deferred events before
+ * the menu is shown. This means that stepping
+ * through a selection event that was caused by
+ * a popup menu will fail in VA/Java.
+ */
+ display.runDeferredEvents ();
+ newMenu.sendEvent (SWT.Show);
+ // widget could be disposed at this point
+ }
+ return null;
+}
+
+LRESULT WM_KEYDOWN (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 display = getDisplay ();
+ display.lastAscii = display.lastKey = 0;
+ display.lastVirtual = display.lastNull = 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 on 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.
+ */
+ int mapKey = OS.IsWinCE ? 0 : 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. On Windows 95 and NT, a call to ToAscii (), clears the
+ * accented state such that the next WM_CHAR loses the accent. 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.
+ *
+ * NOTE: This code is used to avoid a call to ToAscii ().
+ */
+ if (OS.IsWinNT) {
+ if ((mapKey & 0x80000000) != 0) return null;
+ } else {
+ if ((mapKey & 0x8000) != 0) return null;
+ }
+
+ /*
+ * Bug in Windows. When the accent key is generated on an international
+ * keyboard using Ctrl+Alt or the special key, MapVirtualKey () does not
+ * have the high bit set indicating that this is an accent key stroke.
+ * The fix is to iterate through all known accent, mapping them back to
+ * their corresponding virtual key and key state. If the virtual key
+ * and key state match the current key, then this is an accent that has
+ * been generated using an international keyboard and calling ToAscii ()
+ * will clear the accent state.
+ *
+ * NOTE: This code is used to avoid a call to ToAscii ().
+ */
+ if (!OS.IsWinCE) {
for (int i=0; i<ACCENTS.length; i++) {
- int value = OS.VkKeyScan (ACCENTS [i]);
- if ((value & 0xFF) == wParam && (value & 0x600) == 0x600) {
- return null;
- }
- }
- }
-
- /*
- * 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.
- */
- display.lastKey = wParam;
- display.lastVirtual = (mapKey == 0);
- 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;
- /*
- * 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) {
- if (display.asciiKey (display.lastKey) != 0) return null;
- display.lastAscii = display.numpadKey (display.lastKey);
- }
- } else {
- /*
- * Get the shifted state or convert to lower case if necessary.
- * If the user types Ctrl+A, LastKey should be 'a', not 'A'. If
- * the user types Ctrl+Shift+A, LastKey should be 'A'. If the user
- * types Ctrl+Shift+6, the value of LastKey will depend on the
- * international keyboard.
- */
- if (OS.GetKeyState (OS.VK_SHIFT) < 0) {
- display.lastKey = display.shiftedKey (display.lastKey);
- if (display.lastKey == 0) display.lastKey = wParam;
- } else {
- display.lastKey = OS.CharLower ((short) mapKey);
- }
- /*
- * 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 VK_SPACE and
- * issue the event from WM_CHAR.
- */
- if (asciiKey == OS.VK_SPACE) {
- display.lastVirtual = true;
- return null;
- }
- if (asciiKey != wParam) return null;
- }
-
- /*
- * If the control key is not down at this point, then
- * the key that was pressed was an accent key. In that
- * case, do not issue the key down event.
- */
- if (OS.GetKeyState (OS.VK_CONTROL) >= 0) {
- display.lastKey = 0;
- return null;
- }
-
- /*
- * Virtual keys such as VK_RETURN are both virtual and ASCII keys.
- * Normally, these are marked virtual in WM_CHAR. Since we will not
- * be getting a WM_CHAR for the key at this point, we need to test
- * LastKey to see if it is virtual. This happens when the user types
- * Ctrl+Tab.
- */
- display.lastVirtual = display.isVirtualKey (wParam);
- display.lastAscii = display.controlKey (display.lastKey);
- display.lastNull = display.lastAscii == 0 && display.lastKey == '@';
- }
- if (!sendKeyEvent (SWT.KeyDown, OS.WM_KEYDOWN, wParam, lParam)) {
- return LRESULT.ZERO;
- }
- return null;
-}
-
-LRESULT WM_KEYUP (int wParam, int lParam) {
- Display display = getDisplay ();
-
- /* 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 = 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);
- 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 = false;
- return null;
- }
-
- /* Map the virtual key. */
- /*
- * Bug on 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.
- */
- int mapKey = OS.IsWinCE ? 0 : 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. On Windows 95 and NT, a call to ToAscii (), clears the
- * accented state such that the next WM_CHAR loses the accent. 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.
- *
- * NOTE: This code is used to avoid a call to ToAscii ().
- *
- */
- if (OS.IsWinNT) {
- if ((mapKey & 0x80000000) != 0) return null;
- } else {
- if ((mapKey & 0x8000) != 0) return null;
- }
-
- /*
- * Bug in Windows. When the accent key is generated on an international
- * keyboard using Ctrl+Alt or the special key, MapVirtualKey () does not
- * have the high bit set indicating that this is an accent key stroke.
- * The fix is to iterate through all known accent, mapping them back to
- * their corresponding virtual key and key state. If the virtual key
- * and key state match the current key, then this is an accent that has
- * been generated using an international keyboard.
- *
- * NOTE: This code is used to avoid a call to ToAscii ().
- */
- if (!OS.IsWinCE) {
- for (int i=0; i<ACCENTS.length; i++) {
- int value = OS.VkKeyScan (ACCENTS [i]);
- if ((value & 0xFF) == wParam && (value & 0x600) == 0x600) {
- display.lastKey = display.lastAscii = 0;
- display.lastVirtual = display.lastNull = false;
- return null;
- }
- }
- }
-
- display.lastVirtual = (mapKey == 0);
- if (display.lastVirtual) {
- display.lastKey = wParam;
- } else {
- if (display.lastKey == 0) {
- display.lastAscii = 0;
- display.lastNull = false;
- return null;
- }
- display.lastVirtual = display.isVirtualKey (display.lastKey);
- }
-
- LRESULT result = null;
- if (!sendKeyEvent (SWT.KeyUp, OS.WM_KEYUP, wParam, lParam)) {
- result = LRESULT.ZERO;
- }
- display.lastKey = display.lastAscii = 0;
- display.lastVirtual = display.lastNull = false;
- return result;
-}
-
-LRESULT WM_KILLFOCUS (int wParam, int lParam) {
- int code = callWindowProc (OS.WM_KILLFOCUS, wParam, lParam);
- Display display = getDisplay ();
- Shell shell = getShell ();
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the focus
- * out event. If this happens keep going to send
- * the deactivate events.
- */
- sendEvent (SWT.FocusOut);
- // 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 ()) {
- Control control = display.findControl (wParam);
- if (control == null || shell != control.getShell ()) {
- shell.setActiveControl (null);
- }
- }
-
- /*
- * 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 WM_LBUTTONDBLCLK (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.
- */
- sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
- sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_LBUTTONDBLCLK, wParam, lParam);
- int result = callWindowProc (OS.WM_LBUTTONDBLCLK, wParam, lParam);
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- return new LRESULT (result);
-}
-
-LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
- boolean dragging = false, mouseDown = true;
- boolean dragDetect = hooks (SWT.DragDetect);
- 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 = (short) (lParam & 0xFFFF);
- pt.y = (short) (lParam >> 16);
- OS.ClientToScreen(handle, pt);
- dragging = OS.DragDetect (handle, pt);
- mouseDown = OS.GetKeyState (OS.VK_LBUTTON) < 0;
- }
- }
- sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
- int result = callWindowProc (OS.WM_LBUTTONDOWN, wParam, lParam);
- if (OS.IsPPC) {
- if (menu != null && !menu.isDisposed ()) {
- 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) {
- menu.setVisible (true);
- }
- }
- }
- if (mouseDown) {
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- }
- if (dragging) {
- postEvent (SWT.DragDetect);
- } 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 these 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 (handle, OS.WM_LBUTTONUP, wParam, lParam);
- }
- }
- }
- return new LRESULT (result);
-}
-
-LRESULT WM_LBUTTONUP (int wParam, int lParam) {
- sendMouseEvent (SWT.MouseUp, 1, OS.WM_LBUTTONUP, wParam, lParam);
- int result = callWindowProc (OS.WM_LBUTTONUP, wParam, lParam);
- if ((wParam & (OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON)) == 0) {
- if (OS.GetCapture () == handle) OS.ReleaseCapture ();
- }
- return new LRESULT (result);
-}
-
-LRESULT WM_MBUTTONDBLCLK (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.
- */
- sendMouseEvent (SWT.MouseDown, 2, OS.WM_MBUTTONDOWN, wParam, lParam);
- sendMouseEvent (SWT.MouseDoubleClick, 2, OS.WM_MBUTTONDBLCLK, wParam, lParam);
- int result = callWindowProc (OS.WM_MBUTTONDBLCLK, wParam, lParam);
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- return new LRESULT (result);
-}
-
-LRESULT WM_MBUTTONDOWN (int wParam, int lParam) {
- sendMouseEvent (SWT.MouseDown, 2, OS.WM_MBUTTONDOWN, wParam, lParam);
- int result = callWindowProc (OS.WM_MBUTTONDOWN, wParam, lParam);
- if (OS.GetCapture () != handle) OS.SetCapture(handle);
- return new LRESULT (result);
-}
-
-LRESULT WM_MBUTTONUP (int wParam, int lParam) {
- sendMouseEvent (SWT.MouseUp, 2, OS.WM_MBUTTONUP, wParam, lParam);
- int result = callWindowProc (OS.WM_MBUTTONUP, wParam, lParam);
- if ((wParam & (OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON)) == 0) {
- if (OS.GetCapture () == handle) OS.ReleaseCapture ();
- }
- return new LRESULT (result);
-}
-
-LRESULT WM_MEASUREITEM (int wParam, int lParam) {
- MEASUREITEMSTRUCT struct = new MEASUREITEMSTRUCT ();
- OS.MoveMemory (struct, lParam, MEASUREITEMSTRUCT.sizeof);
- if (struct.CtlType == OS.ODT_MENU) {
- Decorations shell = menuShell ();
- MenuItem item = shell.findMenuItem (struct.itemID);
- if (item == null) return null;
- return item.wmMeasureChild (wParam, lParam);
- }
- int hwnd = OS.GetDlgItem (handle, struct.CtlID);
- Control control = WidgetTable.get (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 display = getDisplay ();
- 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) {
- Display display = getDisplay ();
- display.mnemonicKeyHit = true;
- Menu 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
- * 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 = menuShell.findMenuItem (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) {
- sendMouseEvent (SWT.MouseHover, 0, OS.WM_MOUSEHOVER, wParam, lParam);
- return null;
-}
-
-LRESULT WM_MOUSELEAVE (int wParam, int lParam) {
- int pos = OS.GetMessagePos ();
- POINT pt = new POINT ();
- pt.x = (short) (pos & 0xFFFF);
- pt.y = (short) (pos >> 16);
- OS.ScreenToClient (handle, pt);
- lParam = pt.x | (pt.y << 16);
- sendMouseEvent (SWT.MouseExit, 0, OS.WM_MOUSELEAVE, wParam, lParam);
- return null;
-}
-
-LRESULT WM_MOUSEMOVE (int wParam, int lParam) {
- if (!OS.IsWinCE) {
- Display display = getDisplay ();
- 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 (mouseEnter || mouseExit || mouseHover) {
- TRACKMOUSEEVENT lpEventTrack = new TRACKMOUSEEVENT ();
- lpEventTrack.cbSize = TRACKMOUSEEVENT.sizeof;
- lpEventTrack.dwFlags = OS.TME_QUERY;
- lpEventTrack.hwndTrack = handle;
- OS.TrackMouseEvent (lpEventTrack);
- if (lpEventTrack.dwFlags == 0) {
- lpEventTrack.dwFlags = OS.TME_LEAVE | OS.TME_HOVER;
- lpEventTrack.hwndTrack = handle;
- OS.TrackMouseEvent (lpEventTrack);
- if (mouseEnter) {
- sendMouseEvent (SWT.MouseEnter, 0, OS.WM_MOUSEMOVE, wParam, lParam);
- }
- } else {
- lpEventTrack.dwFlags = OS.TME_HOVER;
- OS.TrackMouseEvent (lpEventTrack);
- }
- }
- }
- Display display = getDisplay ();
- int pos = OS.GetMessagePos ();
- if (pos != display.lastMouse) {
- display.lastMouse = pos;
- sendMouseEvent (SWT.MouseMove, 0, OS.WM_MOUSEMOVE, wParam, lParam);
- }
- return null;
-}
-
-LRESULT WM_MOUSEWHEEL (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_MOVE (int wParam, int lParam) {
- 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_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 = WidgetTable.get (hwnd);
- if (control == null) return null;
- return control.wmNotifyChild (wParam, lParam);
-}
-
-LRESULT WM_PAINT (int wParam, int lParam) {
-
- /* Exit early - don't draw the background */
- if (!hooks (SWT.Paint) && !filters (SWT.Paint)) {
- return null;
- }
-
- /* Get the damage */
- int result = 0;
- if (OS.IsWinCE) {
- RECT rect = new RECT ();
- OS.GetUpdateRect (handle, rect, false);
- result = callWindowProc (OS.WM_PAINT, wParam, lParam);
- OS.InvalidateRect (handle, rect, false);
- } else {
- int rgn = OS.CreateRectRgn (0, 0, 0, 0);
- OS.GetUpdateRgn (handle, rgn, false);
- result = callWindowProc (OS.WM_PAINT, wParam, lParam);
- OS.InvalidateRgn (handle, rgn, false);
- OS.DeleteObject (rgn);
- }
-
- /* Create the paint GC */
- PAINTSTRUCT ps = new PAINTSTRUCT ();
- GCData data = new GCData ();
- data.ps = ps;
- GC gc = GC.win32_new (this, data);
-
- /* Send the paint event */
- 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;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the paint
- * event. If this happens, attempt to give back the
- * paint GC anyways because this is a scarce Windows
- * resource.
- */
- sendEvent (SWT.Paint, event);
- // widget could be disposed at this point
-
- /* Dispose the paint GC */
- event.gc = null;
- gc.dispose ();
-
- if (result == 0) return LRESULT.ZERO;
- return new LRESULT (result);
-}
-
-LRESULT WM_PALETTECHANGED (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_PASTE (int wParam, int lParam) {
- return null;
-}
-
-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) {
- /*
- * 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.
- */
- sendMouseEvent (SWT.MouseDown, 3, OS.WM_RBUTTONDOWN, wParam, lParam);
- sendMouseEvent (SWT.MouseDoubleClick, 3, OS.WM_RBUTTONDBLCLK, wParam, lParam);
- int result = callWindowProc (OS.WM_RBUTTONDBLCLK, wParam, lParam);
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- return new LRESULT (result);
-}
-
-LRESULT WM_RBUTTONDOWN (int wParam, int lParam) {
- sendMouseEvent (SWT.MouseDown, 3, OS.WM_RBUTTONDOWN, wParam, lParam);
- int result = callWindowProc (OS.WM_RBUTTONDOWN, wParam, lParam);
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- return new LRESULT (result);
-}
-
-LRESULT WM_RBUTTONUP (int wParam, int lParam) {
- sendMouseEvent (SWT.MouseUp, 3, OS.WM_RBUTTONUP, wParam, lParam);
- int result = callWindowProc (OS.WM_RBUTTONUP, wParam, lParam);
- if ((wParam & (OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON)) == 0) {
- if (OS.GetCapture () == handle) OS.ReleaseCapture ();
- }
- return new LRESULT (result);
-}
-
-LRESULT WM_SETCURSOR (int wParam, int lParam) {
- int hitTest = lParam & 0xFFFF;
- if (hitTest == OS.HTCLIENT) {
- Control control = WidgetTable.get (wParam);
- if (control == null) return null;
- int hCursor = control.findCursor ();
- if (hCursor != 0) {
- OS.SetCursor (hCursor);
- return LRESULT.ONE;
- }
- }
- return null;
-}
-
-LRESULT WM_SETFOCUS (int wParam, int lParam) {
- int code = callWindowProc (OS.WM_SETFOCUS, wParam, lParam);
- Shell shell = getShell ();
-
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the focus
- * in event. If this happens keep going to send
- * the activate events.
- */
- sendEvent (SWT.FocusIn);
- // 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);
- }
-
- /*
- * 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 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) {
- Display display = getDisplay ();
-
- /* Set last key and last ascii because a new key has been typed */
- display.lastAscii = display.lastKey = wParam;
- display.lastVirtual = display.isVirtualKey (wParam);
- display.lastNull = false;
-
- /* Do not issue a key down if a menu bar mnemonic was invoked */
- if (!hooks (SWT.KeyDown) && !display.filters (SWT.KeyDown)) {
- return null;
- }
- display.mnemonicKeyHit = true;
- int result = callWindowProc (OS.WM_SYSCHAR, wParam, lParam);
- if (!display.mnemonicKeyHit) {
- sendKeyEvent (SWT.KeyDown, OS.WM_SYSCHAR, wParam, lParam);
- }
- display.mnemonicKeyHit = false;
- return new LRESULT (result);
-}
-
-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 = shell.findMenuItem (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:
- if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
- Decorations shell = menuShell ();
- Menu menu = shell.getMenuBar ();
- if (menu != null) {
- char key = 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 display = getDisplay ();
- display.mnemonicKeyHit = false;
- return LRESULT.ZERO;
- }
- }
- }
- }
- }
- }
- // 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) {
- /*
- * Feature in Windows. WM_SYSKEYDOWN is sent when
- * the user presses ALT-<aKey> or F10 without the ALT key.
- * In order to issue events for F10 (without the ALT key)
- * but ignore all other key presses without the ALT key,
- * make F10 a special case.
- */
- if (wParam != OS.VK_F10) {
- /* Make sure WM_SYSKEYDOWN was sent by ALT-<aKey>. */
- if ((lParam & 0x20000000) == 0) 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 display = getDisplay ();
- display.lastAscii = display.lastKey = 0;
- display.lastVirtual = display.lastNull = false;
-
- /* If are going to get a WM_SYSCHAR, ignore this message. */
- /*
- * Bug on 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_SYSCHAR
- * event will follow.
- */
- if (!OS.IsWinCE) {
- if (OS.MapVirtualKey (wParam, 2) != 0) {
- /*
- * Feature in Windows. 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 (wParam != OS.VK_RETURN) return null;
- display.lastAscii = '\r';
- }
- }
- display.lastKey = wParam;
- display.lastVirtual = true;
-
- /*
- * 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) {
- if (display.asciiKey (display.lastKey) != 0) return null;
- }
-
- if (!sendKeyEvent (SWT.KeyDown, OS.WM_SYSKEYDOWN, wParam, lParam)) {
- return LRESULT.ZERO;
- }
- return null;
-}
-
-LRESULT WM_SYSKEYUP (int wParam, int lParam) {
- return WM_KEYUP (wParam, lParam);
-}
-
-LRESULT WM_TIMER (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_UNDO (int wParam, int lParam) {
- return null;
-}
-
-LRESULT WM_VSCROLL (int wParam, int lParam) {
- if (lParam == 0) return null;
- Control control = WidgetTable.get (lParam);
- if (control == null) return null;
- return control.wmScrollChild (wParam, lParam);
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) {
- return null;
-}
-
-LRESULT wmColorChild (int wParam, int lParam) {
- if (background == -1 && foreground == -1) return null;
- int forePixel = foreground, backPixel = background;
- if (forePixel == -1) forePixel = defaultForeground ();
- if (backPixel == -1) backPixel = defaultBackground ();
- OS.SetTextColor (wParam, forePixel);
- OS.SetBkColor (wParam, backPixel);
- return new LRESULT (findBrush (backPixel));
-}
-
-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;
-}
-
-}
-
+ int value = OS.VkKeyScan (ACCENTS [i]);
+ if ((value & 0xFF) == wParam && (value & 0x600) == 0x600) {
+ return null;
+ }
+ }
+ }
+
+ /*
+ * 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.
+ */
+ display.lastKey = wParam;
+ display.lastVirtual = (mapKey == 0);
+ 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;
+ /*
+ * 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) {
+ if (display.asciiKey (display.lastKey) != 0) return null;
+ display.lastAscii = display.numpadKey (display.lastKey);
+ }
+ } else {
+ /*
+ * Get the shifted state or convert to lower case if necessary.
+ * If the user types Ctrl+A, LastKey should be 'a', not 'A'. If
+ * the user types Ctrl+Shift+A, LastKey should be 'A'. If the user
+ * types Ctrl+Shift+6, the value of LastKey will depend on the
+ * international keyboard.
+ */
+ if (OS.GetKeyState (OS.VK_SHIFT) < 0) {
+ display.lastKey = display.shiftedKey (display.lastKey);
+ if (display.lastKey == 0) display.lastKey = wParam;
+ } else {
+ display.lastKey = OS.CharLower ((short) mapKey);
+ }
+ /*
+ * 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 VK_SPACE and
+ * issue the event from WM_CHAR.
+ */
+ if (asciiKey == OS.VK_SPACE) {
+ display.lastVirtual = true;
+ return null;
+ }
+ if (asciiKey != wParam) return null;
+ }
+
+ /*
+ * If the control key is not down at this point, then
+ * the key that was pressed was an accent key. In that
+ * case, do not issue the key down event.
+ */
+ if (OS.GetKeyState (OS.VK_CONTROL) >= 0) {
+ display.lastKey = 0;
+ return null;
+ }
+
+ /*
+ * Virtual keys such as VK_RETURN are both virtual and ASCII keys.
+ * Normally, these are marked virtual in WM_CHAR. Since we will not
+ * be getting a WM_CHAR for the key at this point, we need to test
+ * LastKey to see if it is virtual. This happens when the user types
+ * Ctrl+Tab.
+ */
+ display.lastVirtual = display.isVirtualKey (wParam);
+ display.lastAscii = display.controlKey (display.lastKey);
+ display.lastNull = display.lastAscii == 0 && display.lastKey == '@';
+ }
+ if (!sendKeyEvent (SWT.KeyDown, OS.WM_KEYDOWN, wParam, lParam)) {
+ return LRESULT.ZERO;
+ }
+ return null;
+}
+
+LRESULT WM_KEYUP (int wParam, int lParam) {
+ Display display = getDisplay ();
+
+ /* 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 = 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);
+ 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 = false;
+ return null;
+ }
+
+ /* Map the virtual key. */
+ /*
+ * Bug on 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.
+ */
+ int mapKey = OS.IsWinCE ? 0 : 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. On Windows 95 and NT, a call to ToAscii (), clears the
+ * accented state such that the next WM_CHAR loses the accent. 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.
+ *
+ * NOTE: This code is used to avoid a call to ToAscii ().
+ *
+ */
+ if (OS.IsWinNT) {
+ if ((mapKey & 0x80000000) != 0) return null;
+ } else {
+ if ((mapKey & 0x8000) != 0) return null;
+ }
+
+ /*
+ * Bug in Windows. When the accent key is generated on an international
+ * keyboard using Ctrl+Alt or the special key, MapVirtualKey () does not
+ * have the high bit set indicating that this is an accent key stroke.
+ * The fix is to iterate through all known accent, mapping them back to
+ * their corresponding virtual key and key state. If the virtual key
+ * and key state match the current key, then this is an accent that has
+ * been generated using an international keyboard.
+ *
+ * NOTE: This code is used to avoid a call to ToAscii ().
+ */
+ if (!OS.IsWinCE) {
+ for (int i=0; i<ACCENTS.length; i++) {
+ int value = OS.VkKeyScan (ACCENTS [i]);
+ if ((value & 0xFF) == wParam && (value & 0x600) == 0x600) {
+ display.lastKey = display.lastAscii = 0;
+ display.lastVirtual = display.lastNull = false;
+ return null;
+ }
+ }
+ }
+
+ display.lastVirtual = (mapKey == 0);
+ if (display.lastVirtual) {
+ display.lastKey = wParam;
+ } else {
+ if (display.lastKey == 0) {
+ display.lastAscii = 0;
+ display.lastNull = false;
+ return null;
+ }
+ display.lastVirtual = display.isVirtualKey (display.lastKey);
+ }
+
+ LRESULT result = null;
+ if (!sendKeyEvent (SWT.KeyUp, OS.WM_KEYUP, wParam, lParam)) {
+ result = LRESULT.ZERO;
+ }
+ display.lastKey = display.lastAscii = 0;
+ display.lastVirtual = display.lastNull = false;
+ return result;
+}
+
+LRESULT WM_KILLFOCUS (int wParam, int lParam) {
+ int code = callWindowProc (OS.WM_KILLFOCUS, wParam, lParam);
+ Display display = getDisplay ();
+ Shell shell = getShell ();
+
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the focus
+ * out event. If this happens keep going to send
+ * the deactivate events.
+ */
+ sendEvent (SWT.FocusOut);
+ // 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 ()) {
+ Control control = display.findControl (wParam);
+ if (control == null || shell != control.getShell ()) {
+ shell.setActiveControl (null);
+ }
+ }
+
+ /*
+ * 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 WM_LBUTTONDBLCLK (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.
+ */
+ sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
+ sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_LBUTTONDBLCLK, wParam, lParam);
+ int result = callWindowProc (OS.WM_LBUTTONDBLCLK, wParam, lParam);
+ if (OS.GetCapture () != handle) OS.SetCapture (handle);
+ return new LRESULT (result);
+}
+
+LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
+ boolean dragging = false, mouseDown = true;
+ boolean dragDetect = hooks (SWT.DragDetect);
+ 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 = (short) (lParam & 0xFFFF);
+ pt.y = (short) (lParam >> 16);
+ OS.ClientToScreen(handle, pt);
+ dragging = OS.DragDetect (handle, pt);
+ mouseDown = OS.GetKeyState (OS.VK_LBUTTON) < 0;
+ }
+ }
+ sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
+ int result = callWindowProc (OS.WM_LBUTTONDOWN, wParam, lParam);
+ if (OS.IsPPC) {
+ if (menu != null && !menu.isDisposed ()) {
+ 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) {
+ menu.setVisible (true);
+ }
+ }
+ }
+ if (mouseDown) {
+ if (OS.GetCapture () != handle) OS.SetCapture (handle);
+ }
+ if (dragging) {
+ postEvent (SWT.DragDetect);
+ } 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 these 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 (handle, OS.WM_LBUTTONUP, wParam, lParam);
+ }
+ }
+ }
+ return new LRESULT (result);
+}
+
+LRESULT WM_LBUTTONUP (int wParam, int lParam) {
+ sendMouseEvent (SWT.MouseUp, 1, OS.WM_LBUTTONUP, wParam, lParam);
+ int result = callWindowProc (OS.WM_LBUTTONUP, wParam, lParam);
+ if ((wParam & (OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON)) == 0) {
+ if (OS.GetCapture () == handle) OS.ReleaseCapture ();
+ }
+ return new LRESULT (result);
+}
+
+LRESULT WM_MBUTTONDBLCLK (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.
+ */
+ sendMouseEvent (SWT.MouseDown, 2, OS.WM_MBUTTONDOWN, wParam, lParam);
+ sendMouseEvent (SWT.MouseDoubleClick, 2, OS.WM_MBUTTONDBLCLK, wParam, lParam);
+ int result = callWindowProc (OS.WM_MBUTTONDBLCLK, wParam, lParam);
+ if (OS.GetCapture () != handle) OS.SetCapture (handle);
+ return new LRESULT (result);
+}
+
+LRESULT WM_MBUTTONDOWN (int wParam, int lParam) {
+ sendMouseEvent (SWT.MouseDown, 2, OS.WM_MBUTTONDOWN, wParam, lParam);
+ int result = callWindowProc (OS.WM_MBUTTONDOWN, wParam, lParam);
+ if (OS.GetCapture () != handle) OS.SetCapture(handle);
+ return new LRESULT (result);
+}
+
+LRESULT WM_MBUTTONUP (int wParam, int lParam) {
+ sendMouseEvent (SWT.MouseUp, 2, OS.WM_MBUTTONUP, wParam, lParam);
+ int result = callWindowProc (OS.WM_MBUTTONUP, wParam, lParam);
+ if ((wParam & (OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON)) == 0) {
+ if (OS.GetCapture () == handle) OS.ReleaseCapture ();
+ }
+ return new LRESULT (result);
+}
+
+LRESULT WM_MEASUREITEM (int wParam, int lParam) {
+ MEASUREITEMSTRUCT struct = new MEASUREITEMSTRUCT ();
+ OS.MoveMemory (struct, lParam, MEASUREITEMSTRUCT.sizeof);
+ if (struct.CtlType == OS.ODT_MENU) {
+ Decorations shell = menuShell ();
+ MenuItem item = shell.findMenuItem (struct.itemID);
+ if (item == null) return null;
+ return item.wmMeasureChild (wParam, lParam);
+ }
+ int hwnd = OS.GetDlgItem (handle, struct.CtlID);
+ Control control = WidgetTable.get (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 display = getDisplay ();
+ 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) {
+ Display display = getDisplay ();
+ display.mnemonicKeyHit = true;
+ Menu 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
+ * 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 = menuShell.findMenuItem (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) {
+ sendMouseEvent (SWT.MouseHover, 0, OS.WM_MOUSEHOVER, wParam, lParam);
+ return null;
+}
+
+LRESULT WM_MOUSELEAVE (int wParam, int lParam) {
+ int pos = OS.GetMessagePos ();
+ POINT pt = new POINT ();
+ pt.x = (short) (pos & 0xFFFF);
+ pt.y = (short) (pos >> 16);
+ OS.ScreenToClient (handle, pt);
+ lParam = pt.x | (pt.y << 16);
+ sendMouseEvent (SWT.MouseExit, 0, OS.WM_MOUSELEAVE, wParam, lParam);
+ return null;
+}
+
+LRESULT WM_MOUSEMOVE (int wParam, int lParam) {
+ if (!OS.IsWinCE) {
+ Display display = getDisplay ();
+ 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 (mouseEnter || mouseExit || mouseHover) {
+ TRACKMOUSEEVENT lpEventTrack = new TRACKMOUSEEVENT ();
+ lpEventTrack.cbSize = TRACKMOUSEEVENT.sizeof;
+ lpEventTrack.dwFlags = OS.TME_QUERY;
+ lpEventTrack.hwndTrack = handle;
+ OS.TrackMouseEvent (lpEventTrack);
+ if (lpEventTrack.dwFlags == 0) {
+ lpEventTrack.dwFlags = OS.TME_LEAVE | OS.TME_HOVER;
+ lpEventTrack.hwndTrack = handle;
+ OS.TrackMouseEvent (lpEventTrack);
+ if (mouseEnter) {
+ sendMouseEvent (SWT.MouseEnter, 0, OS.WM_MOUSEMOVE, wParam, lParam);
+ }
+ } else {
+ lpEventTrack.dwFlags = OS.TME_HOVER;
+ OS.TrackMouseEvent (lpEventTrack);
+ }
+ }
+ }
+ Display display = getDisplay ();
+ int pos = OS.GetMessagePos ();
+ if (pos != display.lastMouse) {
+ display.lastMouse = pos;
+ sendMouseEvent (SWT.MouseMove, 0, OS.WM_MOUSEMOVE, wParam, lParam);
+ }
+ return null;
+}
+
+LRESULT WM_MOUSEWHEEL (int wParam, int lParam) {
+ return null;
+}
+
+LRESULT WM_MOVE (int wParam, int lParam) {
+ 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_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 = WidgetTable.get (hwnd);
+ if (control == null) return null;
+ return control.wmNotifyChild (wParam, lParam);
+}
+
+LRESULT WM_PAINT (int wParam, int lParam) {
+
+ /* Exit early - don't draw the background */
+ if (!hooks (SWT.Paint) && !filters (SWT.Paint)) {
+ return null;
+ }
+
+ /* Get the damage */
+ int result = 0;
+ if (OS.IsWinCE) {
+ RECT rect = new RECT ();
+ OS.GetUpdateRect (handle, rect, false);
+ result = callWindowProc (OS.WM_PAINT, wParam, lParam);
+ OS.InvalidateRect (handle, rect, false);
+ } else {
+ int rgn = OS.CreateRectRgn (0, 0, 0, 0);
+ OS.GetUpdateRgn (handle, rgn, false);
+ result = callWindowProc (OS.WM_PAINT, wParam, lParam);
+ OS.InvalidateRgn (handle, rgn, false);
+ OS.DeleteObject (rgn);
+ }
+
+ /* Create the paint GC */
+ PAINTSTRUCT ps = new PAINTSTRUCT ();
+ GCData data = new GCData ();
+ data.ps = ps;
+ GC gc = GC.win32_new (this, data);
+
+ /* Send the paint event */
+ 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;
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the paint
+ * event. If this happens, attempt to give back the
+ * paint GC anyways because this is a scarce Windows
+ * resource.
+ */
+ sendEvent (SWT.Paint, event);
+ // widget could be disposed at this point
+
+ /* Dispose the paint GC */
+ event.gc = null;
+ gc.dispose ();
+
+ if (result == 0) return LRESULT.ZERO;
+ return new LRESULT (result);
+}
+
+LRESULT WM_PALETTECHANGED (int wParam, int lParam) {
+ return null;
+}
+
+LRESULT WM_PASTE (int wParam, int lParam) {
+ return null;
+}
+
+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) {
+ /*
+ * 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.
+ */
+ sendMouseEvent (SWT.MouseDown, 3, OS.WM_RBUTTONDOWN, wParam, lParam);
+ sendMouseEvent (SWT.MouseDoubleClick, 3, OS.WM_RBUTTONDBLCLK, wParam, lParam);
+ int result = callWindowProc (OS.WM_RBUTTONDBLCLK, wParam, lParam);
+ if (OS.GetCapture () != handle) OS.SetCapture (handle);
+ return new LRESULT (result);
+}
+
+LRESULT WM_RBUTTONDOWN (int wParam, int lParam) {
+ sendMouseEvent (SWT.MouseDown, 3, OS.WM_RBUTTONDOWN, wParam, lParam);
+ int result = callWindowProc (OS.WM_RBUTTONDOWN, wParam, lParam);
+ if (OS.GetCapture () != handle) OS.SetCapture (handle);
+ return new LRESULT (result);
+}
+
+LRESULT WM_RBUTTONUP (int wParam, int lParam) {
+ sendMouseEvent (SWT.MouseUp, 3, OS.WM_RBUTTONUP, wParam, lParam);
+ int result = callWindowProc (OS.WM_RBUTTONUP, wParam, lParam);
+ if ((wParam & (OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON)) == 0) {
+ if (OS.GetCapture () == handle) OS.ReleaseCapture ();
+ }
+ return new LRESULT (result);
+}
+
+LRESULT WM_SETCURSOR (int wParam, int lParam) {
+ int hitTest = lParam & 0xFFFF;
+ if (hitTest == OS.HTCLIENT) {
+ Control control = WidgetTable.get (wParam);
+ if (control == null) return null;
+ int hCursor = control.findCursor ();
+ if (hCursor != 0) {
+ OS.SetCursor (hCursor);
+ return LRESULT.ONE;
+ }
+ }
+ return null;
+}
+
+LRESULT WM_SETFOCUS (int wParam, int lParam) {
+ int code = callWindowProc (OS.WM_SETFOCUS, wParam, lParam);
+ Shell shell = getShell ();
+
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the focus
+ * in event. If this happens keep going to send
+ * the activate events.
+ */
+ sendEvent (SWT.FocusIn);
+ // 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);
+ }
+
+ /*
+ * 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 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) {
+ Display display = getDisplay ();
+
+ /* Set last key and last ascii because a new key has been typed */
+ display.lastAscii = display.lastKey = wParam;
+ display.lastVirtual = display.isVirtualKey (wParam);
+ display.lastNull = false;
+
+ /* Do not issue a key down if a menu bar mnemonic was invoked */
+ if (!hooks (SWT.KeyDown) && !display.filters (SWT.KeyDown)) {
+ return null;
+ }
+ display.mnemonicKeyHit = true;
+ int result = callWindowProc (OS.WM_SYSCHAR, wParam, lParam);
+ if (!display.mnemonicKeyHit) {
+ sendKeyEvent (SWT.KeyDown, OS.WM_SYSCHAR, wParam, lParam);
+ }
+ display.mnemonicKeyHit = false;
+ return new LRESULT (result);
+}
+
+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 = shell.findMenuItem (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:
+ if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
+ Decorations shell = menuShell ();
+ Menu menu = shell.getMenuBar ();
+ if (menu != null) {
+ char key = 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 display = getDisplay ();
+ display.mnemonicKeyHit = false;
+ return LRESULT.ZERO;
+ }
+ }
+ }
+ }
+ }
+ }
+ // 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) {
+ /*
+ * Feature in Windows. WM_SYSKEYDOWN is sent when
+ * the user presses ALT-<aKey> or F10 without the ALT key.
+ * In order to issue events for F10 (without the ALT key)
+ * but ignore all other key presses without the ALT key,
+ * make F10 a special case.
+ */
+ if (wParam != OS.VK_F10) {
+ /* Make sure WM_SYSKEYDOWN was sent by ALT-<aKey>. */
+ if ((lParam & 0x20000000) == 0) 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 display = getDisplay ();
+ display.lastAscii = display.lastKey = 0;
+ display.lastVirtual = display.lastNull = false;
+
+ /* If are going to get a WM_SYSCHAR, ignore this message. */
+ /*
+ * Bug on 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_SYSCHAR
+ * event will follow.
+ */
+ if (!OS.IsWinCE) {
+ if (OS.MapVirtualKey (wParam, 2) != 0) {
+ /*
+ * Feature in Windows. 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 (wParam != OS.VK_RETURN) return null;
+ display.lastAscii = '\r';
+ }
+ }
+ display.lastKey = wParam;
+ display.lastVirtual = true;
+
+ /*
+ * 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) {
+ if (display.asciiKey (display.lastKey) != 0) return null;
+ }
+
+ if (!sendKeyEvent (SWT.KeyDown, OS.WM_SYSKEYDOWN, wParam, lParam)) {
+ return LRESULT.ZERO;
+ }
+ return null;
+}
+
+LRESULT WM_SYSKEYUP (int wParam, int lParam) {
+ return WM_KEYUP (wParam, lParam);
+}
+
+LRESULT WM_TIMER (int wParam, int lParam) {
+ return null;
+}
+
+LRESULT WM_UNDO (int wParam, int lParam) {
+ return null;
+}
+
+LRESULT WM_VSCROLL (int wParam, int lParam) {
+ if (lParam == 0) return null;
+ Control control = WidgetTable.get (lParam);
+ if (control == null) return null;
+ return control.wmScrollChild (wParam, lParam);
+}
+
+LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) {
+ return null;
+}
+
+LRESULT wmColorChild (int wParam, int lParam) {
+ if (background == -1 && foreground == -1) return null;
+ int forePixel = foreground, backPixel = background;
+ if (forePixel == -1) forePixel = defaultForeground ();
+ if (backPixel == -1) backPixel = defaultBackground ();
+ OS.SetTextColor (wParam, forePixel);
+ OS.SetBkColor (wParam, backPixel);
+ return new LRESULT (findBrush (backPixel));
+}
+
+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
index c9b8985e70..c194db22df 100755
--- 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
@@ -1,1001 +1,1001 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>(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 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 MAX_WIDTH = 0x7FFF;
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see SWT
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public CoolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-int callWindowProc (int msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (ReBarProc, handle, 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 (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;
- OS.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);
- OS.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);
- OS.SendMessage(handle, OS.RB_GETBANDBORDERS, i, rect);
- if ((rbBand.fStyle & OS.RBBS_BREAK) != 0) {
- width = Math.max(width, rowWidth);
- rowWidth = 0;
- }
- rowWidth += rbBand.cxIdeal + rect.left + rect.right + 2;
- }
- width = Math.max(width, rowWidth);
- if (redraw) {
- if (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_WIDTH;
- if (height == 0) height = DEFAULT_HEIGHT;
- 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;
-
- /*
- * 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;
-}
-
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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;
- 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);
- sizes [i] = new Point (rect.right - rect.left + 2, 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;
-}
-
-/**
- * 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 + 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 releaseWidget () {
- for (int i=0; i<items.length; i++) {
- CoolItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.releaseResources ();
- }
- }
- items = null;
- super.releaseWidget();
-}
-
-void setBackgroundPixel (int pixel) {
- if (background == pixel) return;
- background = pixel;
- if (pixel == -1) pixel = defaultBackground ();
- OS.SendMessage (handle, OS.RB_SETBKCOLOR, 0, pixel);
- setItemColors (OS.SendMessage (handle, OS.RB_GETTEXTCOLOR, 0, 0), pixel);
-}
-
-void setForegroundPixel (int pixel) {
- if (foreground == pixel) return;
- foreground = 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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_BANDBORDERS | OS.RBS_DBLCLKTOGGLE;
- 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);
- if (result != null) return result;
-
- /*
- * 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.
- */
- drawBackground (wParam);
-
- /*
- * NOTE: The cool bar draws separators in WM_ERASEBKGND
- * so it is essential to run the cool bar window proc
- * after the background has been erased.
- */
- return null;
-}
-
-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
- * by not running the default window proc or the rebar window
- * proc.
- */
- if (COMCTL32_MAJOR >= 6) return LRESULT.ZERO;
- Rectangle rect = getBounds ();
- int code = callWindowProc (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 (OS.WM_SIZE, wParam, lParam);
- if (code == 0) return LRESULT.ZERO;
- return new LRESULT (code);
- }
- 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_HEIGHTCHANGE:
- if (!ignoreResize) {
- Point size = getSize ();
- int border = getBorderWidth ();
- int height = OS.SendMessage (handle, OS.RB_GETBARHEIGHT, 0, 0);
- setSize (size.x, height + (border * 2));
- }
- break;
- case OS.RBN_CHEVRONPUSHED:
- NMREBARCHEVRON lpnm = new NMREBARCHEVRON ();
- OS.MoveMemory (lpnm, lParam, NMREBARCHEVRON.sizeof);
- CoolItem child = items [lpnm.wID];
- if (child != null) {
- Event event = new Event();
- event.detail = SWT.ARROW;
- event.x = lpnm.left;
- event.y = lpnm.bottom;
- child.postEvent (SWT.Selection, event);
- }
- break;
- }
- return super.wmNotifyChild (wParam, lParam);
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>(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 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 MAX_WIDTH = 0x7FFF;
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
+ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
+ * </ul>
+ *
+ * @see SWT
+ * @see Widget#checkSubclass
+ * @see Widget#getStyle
+ */
+public CoolBar (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+
+int callWindowProc (int msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (ReBarProc, handle, 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 (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;
+ OS.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);
+ OS.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);
+ OS.SendMessage(handle, OS.RB_GETBANDBORDERS, i, rect);
+ if ((rbBand.fStyle & OS.RBBS_BREAK) != 0) {
+ width = Math.max(width, rowWidth);
+ rowWidth = 0;
+ }
+ rowWidth += rbBand.cxIdeal + rect.left + rect.right + 2;
+ }
+ width = Math.max(width, rowWidth);
+ if (redraw) {
+ if (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_WIDTH;
+ if (height == 0) height = DEFAULT_HEIGHT;
+ 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;
+
+ /*
+ * 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;
+}
+
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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;
+ 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);
+ sizes [i] = new Point (rect.right - rect.left + 2, 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;
+}
+
+/**
+ * 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 + 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 releaseWidget () {
+ for (int i=0; i<items.length; i++) {
+ CoolItem item = items [i];
+ if (item != null && !item.isDisposed ()) {
+ item.releaseResources ();
+ }
+ }
+ items = null;
+ super.releaseWidget();
+}
+
+void setBackgroundPixel (int pixel) {
+ if (background == pixel) return;
+ background = pixel;
+ if (pixel == -1) pixel = defaultBackground ();
+ OS.SendMessage (handle, OS.RB_SETBKCOLOR, 0, pixel);
+ setItemColors (OS.SendMessage (handle, OS.RB_GETTEXTCOLOR, 0, 0), pixel);
+}
+
+void setForegroundPixel (int pixel) {
+ if (foreground == pixel) return;
+ foreground = 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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_BANDBORDERS | OS.RBS_DBLCLKTOGGLE;
+ 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);
+ if (result != null) return result;
+
+ /*
+ * 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.
+ */
+ drawBackground (wParam);
+
+ /*
+ * NOTE: The cool bar draws separators in WM_ERASEBKGND
+ * so it is essential to run the cool bar window proc
+ * after the background has been erased.
+ */
+ return null;
+}
+
+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
+ * by not running the default window proc or the rebar window
+ * proc.
+ */
+ if (COMCTL32_MAJOR >= 6) return LRESULT.ZERO;
+ Rectangle rect = getBounds ();
+ int code = callWindowProc (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 (OS.WM_SIZE, wParam, lParam);
+ if (code == 0) return LRESULT.ZERO;
+ return new LRESULT (code);
+ }
+ 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_HEIGHTCHANGE:
+ if (!ignoreResize) {
+ Point size = getSize ();
+ int border = getBorderWidth ();
+ int height = OS.SendMessage (handle, OS.RB_GETBARHEIGHT, 0, 0);
+ setSize (size.x, height + (border * 2));
+ }
+ break;
+ case OS.RBN_CHEVRONPUSHED:
+ NMREBARCHEVRON lpnm = new NMREBARCHEVRON ();
+ OS.MoveMemory (lpnm, lParam, NMREBARCHEVRON.sizeof);
+ CoolItem child = items [lpnm.wID];
+ if (child != null) {
+ Event event = new Event();
+ event.detail = SWT.ARROW;
+ event.x = lpnm.left;
+ event.y = lpnm.bottom;
+ child.postEvent (SWT.Selection, event);
+ }
+ 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
index 46445eb1bf..867f632234 100755
--- 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
@@ -1,665 +1,665 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 index at which to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 CoolBar#getBorderWidth
- * @see CoolBar#computeTrim
- * @see CoolBar#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;
- int hwnd = parent.handle;
- RECT rect = new RECT ();
- OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect);
- width += rect.left + rect.right + 2;
- return new Point (width, height);
-}
-
-/**
- * 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);
- int width = rect.right - rect.left + 2;
- int height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-/*
-* Not currently used.
-*/
-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 + insetRect.top;
- int width = rect.right - rect.left - (insetRect.left + insetRect.right);
- int height = rect.bottom - rect.top - (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, width, height);
-}
-
-/**
- * Returns the control that is associated with the receiver.
- *
- * @return the control that is contained by the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Control getControl () {
- checkWidget ();
- return control;
-}
-
-public Display getDisplay () {
- CoolBar parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
-/**
- * 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 releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- control = null;
- parent = 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 = 0;
- if (newControl != null) hwndChild = control.handle;
- 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;
- OS.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);
- RECT rect = new RECT ();
- OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect);
- int width = rbBand.cxIdeal + rect.left + rect.right + 2;
- return new Point (width, rbBand.cyMinChild);
-}
-
-/**
- * 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;
- ideal = true;
- int hwnd = parent.handle;
- RECT rect = new RECT ();
- OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect);
- 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 = width - rect.left - rect.right - 2;
- rbBand.cyMaxChild = height;
- if (!minimum) rbBand.cyMinChild = height;
- 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
- * @param height the new ideal height 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);
- int width = rect.right - rect.left + 2;
- int height = rect.bottom - rect.top;
- 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;
- int hwnd = parent.handle;
- REBARBANDINFO rbBand = new REBARBANDINFO ();
- rbBand.cbSize = REBARBANDINFO.sizeof;
-
- /*
- * Do not set the size for the last item on the row.
- */
- int count = OS.SendMessage (hwnd, OS.RB_GETBANDCOUNT, 0, 0);
- boolean isLastItem;
- if (index + 1 == count) {
- isLastItem = true;
- } else {
- rbBand.fMask = OS.RBBIM_STYLE;
- OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index + 1, rbBand);
- isLastItem = (rbBand.fStyle & OS.RBBS_BREAK) != 0;
- rbBand.fMask = 0;
- }
-
- /* 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. */
- rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE;
- if (!ideal) {
- RECT rect = new RECT ();
- OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect);
- rbBand.cxIdeal = width - rect.left - rect.right - 2;
- }
- if (!minimum) rbBand.cyMinChild = height;
- rbBand.cyChild = rbBand.cyMaxChild = height;
- if (!isLastItem) {
- rbBand.cx = width - 2;
- 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
- * @param height the new height 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);
- 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;
- minimum = true;
- int hwnd = parent.handle;
- 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 = width;
- rbBand.cyMinChild = height;
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 index at which to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 CoolBar#getBorderWidth
+ * @see CoolBar#computeTrim
+ * @see CoolBar#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;
+ int hwnd = parent.handle;
+ RECT rect = new RECT ();
+ OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect);
+ width += rect.left + rect.right + 2;
+ return new Point (width, height);
+}
+
+/**
+ * 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);
+ int width = rect.right - rect.left + 2;
+ int height = rect.bottom - rect.top;
+ return new Rectangle (rect.left, rect.top, width, height);
+}
+
+/*
+* Not currently used.
+*/
+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 + insetRect.top;
+ int width = rect.right - rect.left - (insetRect.left + insetRect.right);
+ int height = rect.bottom - rect.top - (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, width, height);
+}
+
+/**
+ * Returns the control that is associated with the receiver.
+ *
+ * @return the control that is contained by the receiver
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public Control getControl () {
+ checkWidget ();
+ return control;
+}
+
+public Display getDisplay () {
+ CoolBar parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
+/**
+ * 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 releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ control = null;
+ parent = 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 = 0;
+ if (newControl != null) hwndChild = control.handle;
+ 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;
+ OS.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);
+ RECT rect = new RECT ();
+ OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect);
+ int width = rbBand.cxIdeal + rect.left + rect.right + 2;
+ return new Point (width, rbBand.cyMinChild);
+}
+
+/**
+ * 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;
+ ideal = true;
+ int hwnd = parent.handle;
+ RECT rect = new RECT ();
+ OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect);
+ 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 = width - rect.left - rect.right - 2;
+ rbBand.cyMaxChild = height;
+ if (!minimum) rbBand.cyMinChild = height;
+ 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
+ * @param height the new ideal height 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);
+ int width = rect.right - rect.left + 2;
+ int height = rect.bottom - rect.top;
+ 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;
+ int hwnd = parent.handle;
+ REBARBANDINFO rbBand = new REBARBANDINFO ();
+ rbBand.cbSize = REBARBANDINFO.sizeof;
+
+ /*
+ * Do not set the size for the last item on the row.
+ */
+ int count = OS.SendMessage (hwnd, OS.RB_GETBANDCOUNT, 0, 0);
+ boolean isLastItem;
+ if (index + 1 == count) {
+ isLastItem = true;
+ } else {
+ rbBand.fMask = OS.RBBIM_STYLE;
+ OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index + 1, rbBand);
+ isLastItem = (rbBand.fStyle & OS.RBBS_BREAK) != 0;
+ rbBand.fMask = 0;
+ }
+
+ /* 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. */
+ rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE;
+ if (!ideal) {
+ RECT rect = new RECT ();
+ OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, rect);
+ rbBand.cxIdeal = width - rect.left - rect.right - 2;
+ }
+ if (!minimum) rbBand.cyMinChild = height;
+ rbBand.cyChild = rbBand.cyMaxChild = height;
+ if (!isLastItem) {
+ rbBand.cx = width - 2;
+ 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
+ * @param height the new height 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);
+ 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;
+ minimum = true;
+ int hwnd = parent.handle;
+ 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 = width;
+ rbBand.cyMinChild = height;
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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
index 0e05b7bf9a..b634682a12 100755
--- 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
@@ -1,1364 +1,1364 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- * 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;
- Menu menuBar;
- Menu [] menus;
- MenuItem [] items;
- Control savedFocus;
- Button defaultButton, saveDefault;
- int swFlags, hAccel, nAccel, hIcon;
-
- /*
- * 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;
-
-/**
- * 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 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 add (MenuItem item) {
- if (items == null) items = new MenuItem [12];
- 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 + 12];
- newItems [items.length] = item;
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
-}
-
-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 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);
-// }
-}
-
-static int checkStyle (int style) {
- 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 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;
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-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 bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- boolean hasMenu = OS.IsWinCE ? false : OS.GetMenu (handle) != 0;
- OS.AdjustWindowRectEx (rect, bits, hasMenu, OS.GetWindowLong (handle, OS.GWL_EXSTYLE));
-
- /* 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);
-
- /* Get 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) {
- 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;
- if (menuBar == null || items == null) {
- if (!OS.IsPPC) return;
- maxAccel = 1;
- } else {
- maxAccel = OS.IsPPC ? items.length + 1 : items.length;
- }
- int size = ACCEL.sizeof;
- ACCEL accel = new ACCEL ();
- byte [] buffer1 = new byte [size];
- byte [] buffer2 = new byte [maxAccel * size];
- if (menuBar != null && items != null) {
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item != null && item.accelerator != 0) {
- Menu parent = item.parent;
- while (parent != null && parent != menuBar) {
- parent = parent.getParentMenu ();
- }
- if (parent == menuBar) {
- item.fillAccel (accel);
- OS.MoveMemory (buffer1, accel, size);
- System.arraycopy (buffer1, 0, buffer2, nAccel * size, size);
- 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 = OS.FVIRTKEY | OS.FCONTROL;
- accel.key = 'Q';
- accel.cmd = OS.IDOK;
- OS.MoveMemory (buffer1, accel, size);
- System.arraycopy (buffer1, 0, buffer2, nAccel * size, size);
- nAccel++;
- }
- if (nAccel != 0) hAccel = OS.CreateAcceleratorTable (buffer2, nAccel);
-}
-
-void createHandle () {
- super.createHandle ();
- if (parent == null) return;
- 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;
-}
-
-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;
-}
-
-MenuItem findMenuItem (int id) {
- if (items == null) return null;
- id = id - ID_START;
- if (0 <= id && id < items.length) return items [id];
- return null;
-}
-
-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 -= height;
- }
- return rect;
- }
- if (!OS.IsWinCE) {
- if (OS.IsIconic (handle)) {
- RECT rect = new RECT ();
- WINDOWPLACEMENT lpwndpl = new WINDOWPLACEMENT ();
- lpwndpl.length = WINDOWPLACEMENT.sizeof;
- OS.GetWindowPlacement (handle, lpwndpl);
- int width = lpwndpl.right - lpwndpl.left;
- int height = lpwndpl.bottom - lpwndpl.top;
- OS.SetRect (rect, 0, 0, width, height);
- OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, rect);
- return new Rectangle (0, 0, rect.right, rect.bottom);
- }
- }
- 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;
-}
-
-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);
- }
- }
- 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 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);
-}
-
-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 releaseWidget () {
- if (menuBar != null) menuBar.releaseResources ();
- menuBar = null;
- if (menus != null) {
- do {
- int index = 0;
- while (index < menus.length) {
- Menu menu = menus [index];
- if (menu != null && !menu.isDisposed ()) {
- while (menu.getParentMenu () != null) {
- menu = menu.getParentMenu ();
- }
- menu.dispose ();
- break;
- }
- index++;
- }
- if (index == menus.length) break;
- } while (true);
- }
- menus = null;
- super.releaseWidget ();
- if (hIcon != 0) OS.DestroyIcon (hIcon);
- hIcon = 0;
- items = null;
- image = null;
- savedFocus = null;
- defaultButton = saveDefault = null;
- if (hAccel != 0 && hAccel != -1) OS.DestroyAcceleratorTable (hAccel);
- hAccel = -1;
-}
-
-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 remove (MenuItem item) {
- if (items == null) return;
- items [item.id - ID_START] = null;
- item.id = -1;
-}
-
-boolean restoreFocus () {
- 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 = getDisplay ().getFocusControl ();
- if (control != null) setSavedFocus (control);
-}
-
-void setBounds (int x, int y, int width, int height, int flags) {
- if (OS.IsWinCE) {
- super.setBounds (x, y, width, height, flags);
- }
- if (OS.IsIconic (handle) || OS.IsZoomed (handle)) {
- setPlacement (x, y, width, height, flags);
- return;
- }
- super.setBounds (x, y, width, height, flags);
-}
-
-/**
- * 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.
- *
- * @param the new default button
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 ();
- setDefaultButton (button, true);
-}
-
-void setDefaultButton (Button button, boolean save) {
- if (button == null) {
- if (defaultButton == saveDefault) {
- if (save) saveDefault = null;
- return;
- }
- } else {
- if (button.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- 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;
-}
-
-public boolean setFocus () {
- checkWidget ();
- if (this instanceof Shell) return super.setFocus ();
- /*
- * Bug in Windows. Setting the focus to a child of the
- * receiver interferes with moving and resizing of the
- * parent shell. The fix (for now) is to always set the
- * focus to the shell.
- */
- int hwndFocus = OS.SetFocus (getShell ().handle);
- return hwndFocus == OS.GetFocus ();
-}
-/**
- * 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);
- /*
- * 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 anyways.
- */
- if (OS.IsWinCE) {
- this.image = image;
- return;
- }
- int hImage = 0;
- if (image != null) {
- if (hIcon != 0) OS.DestroyIcon (hIcon);
- hIcon = 0;
- switch (image.type) {
- case SWT.BITMAP:
- /* Copy the bitmap in case it's a DIB */
- int hBitmap = image.handle;
- BITMAP bm = new BITMAP ();
- OS.GetObject (hBitmap, BITMAP.sizeof, bm);
- byte [] lpvBits = new byte [(bm.bmWidth + 15) / 16 * 2 * bm.bmHeight];
- int hMask = OS.CreateBitmap (bm.bmWidth, bm.bmHeight, 1, 1, lpvBits);
- int hDC = OS.GetDC (handle);
- int hdcMem = OS.CreateCompatibleDC (hDC);
- int hColor = OS.CreateCompatibleBitmap (hDC, bm.bmWidth, bm.bmHeight);
- OS.SelectObject (hdcMem, hColor);
- int hdcBmp = OS.CreateCompatibleDC (hDC);
- OS.SelectObject (hdcBmp, hBitmap);
- OS.BitBlt (hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcBmp, 0, 0, OS.SRCCOPY);
- ICONINFO info = new ICONINFO ();
- info.fIcon = true;
- info.hbmMask = hMask;
- info.hbmColor = hColor;
- hImage = hIcon = OS.CreateIconIndirect (info);
- OS.DeleteObject (hMask);
- OS.DeleteObject(hColor);
- OS.DeleteDC (hdcBmp);
- OS.DeleteDC (hdcMem);
- OS.ReleaseDC (handle, hDC);
- break;
- case SWT.ICON:
- hImage = image.handle;
- break;
- default:
- return;
- }
- }
- this.image = image;
- OS.SendMessage (handle, OS.WM_SETICON, OS.ICON_BIG, hImage);
-
- /*
- * 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 (hIcon == 0 && (style & SWT.BORDER) != 0) {
- int flags = OS.RDW_FRAME | OS.RDW_INVALIDATE;
- OS.RedrawWindow (handle, null, 0, flags);
- }
- }
-}
-
-/**
- * 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 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.
- * PocketPC windows typically don't have a caption when they are
- * maximized. They usually have one when they are not occupying all the
- * space. We implement this behavior by default - it can be overriden by
- * setting SWT.TITLE or SWT.NO_TRIM.
- */
- if (maximized) {
- if ((style & SWT.TITLE) == 0) {
- /* Remove caption when maximized */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- bits &= ~OS.WS_CAPTION;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- 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;
- OS.SetWindowPos (handle, 0, rect.left, rect.top, width, height, flags);
- } else {
- if ((style & SWT.NO_TRIM) == 0) {
- /* Insert caption when no longer maximized */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- bits |= OS.WS_CAPTION;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- int flags = OS.SWP_NOMOVE | OS.SWP_NOSIZE | OS.SWP_NOZORDER | OS.SWP_DRAWFRAME;
- OS.SetWindowPos (handle, 0, 0, 0, 0, 0, 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);
- layout (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 display = getDisplay ();
- 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 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 = OS.SW_RESTORE;
- if (minimized) swFlags = OS.SW_SHOWMINNOACTIVE;
- if (!OS.IsWindowVisible (handle)) return;
- if (minimized == OS.IsIconic (handle)) return;
- OS.ShowWindow (handle, swFlags);
- 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.
- */
- Display display = getDisplay ();
- int hwndParent = parent.handle;
- display.lockActiveWindow = true;
- OS.SetParent (handle, hwndParent);
- if (!OS.IsWindowVisible (hwndParent)) {
- OS.ShowWindow (handle, OS.SW_SHOWNA);
- }
- 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;
- }
- }
- if ((flags & OS.SWP_NOMOVE) == 0) {
- lpwndpl.left = x;
- lpwndpl.top = y;
- }
- if ((flags & OS.SWP_NOSIZE) == 0) {
- lpwndpl.right = x + width;
- lpwndpl.bottom = y + height;
- }
- OS.SetWindowPlacement (handle, lpwndpl);
-}
-
-void setSavedFocus (Control control) {
- if (this == control) {
- savedFocus = null;
- return;
- }
- if (this != control.menuShell ()) return;
- 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 may not be null.
- *
- * @param text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 (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 (OS.IsWinCE) {
- OS.ShowWindow (handle, OS.SW_SHOW);
- } else {
- if (menuBar != null) {
- Display display = getDisplay ();
- display.removeBar (menuBar);
- OS.DrawMenuBar (handle);
- }
- OS.ShowWindow (handle, swFlags);
- }
- 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;
- }
- }
- }
- }
- OS.ShowWindow (handle, OS.SW_HIDE);
- sendEvent (SWT.Hide);
- }
-}
-
-boolean translateAccelerator (MSG msg) {
- if (!isEnabled () || !isActive ()) return false;
- if (menuBar != null && !menuBar.isEnabled ()) return false;
- if (hAccel == -1) createAccelerators ();
- if (hAccel == 0) return false;
- return OS.TranslateAccelerator (handle, hAccel, msg) != 0;
-}
-
-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;
-}
-
-int widgetExtStyle () {
- int bits = super.widgetExtStyle () & ~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.TOOL) != 0) bits |= OS.WS_EX_TOOLWINDOW;
- if ((style & SWT.RESIZE) != 0) return bits;
- if ((style & SWT.BORDER) != 0) bits |= OS.WS_EX_DLGMODALFRAME;
- return bits;
-}
-
-int widgetStyle () {
- /*
- * Set WS_POPUP and clear WS_VISIBLE and WS_TABSTOP.
- * NOTE: WS_TABSTOP is the same as WS_MAXIMIZEBOX so
- * it cannot be used to do tabbing with decorations.
- */
- int bits = super.widgetStyle () | OS.WS_POPUP;
- bits &= ~(OS.WS_VISIBLE | OS.WS_TABSTOP);
-
- /* 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 msg, int wParam, int lParam) {
- switch (msg) {
- case OS.WM_APP:
- case OS.WM_APP+1:
- if (hAccel == -1) createAccelerators ();
- return msg == OS.WM_APP ? nAccel : hAccel;
- }
- return super.windowProc (msg, wParam, lParam);
-}
-
-LRESULT WM_ACTIVATE (int wParam, int lParam) {
- LRESULT result = super.WM_ACTIVATE (wParam, lParam);
- if (result != null) return result;
- 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;
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the activate
- * event. If this happens, end the processing of the
- * Windows message by returning zero as the result of
- * the window proc.
- */
- sendEvent (SWT.Activate);
- if (isDisposed ()) return LRESULT.ZERO;
- if (restoreFocus ()) return LRESULT.ZERO;
- if (traverseGroup (true)) return LRESULT.ZERO;
-
- } else {
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the deactivate
- * event. If this happens, end the processing of the
- * Windows message by returning zero as the result of
- * the window proc.
- */
- Shell shell = getShell ();
- shell.setActiveControl (null);
- if (isDisposed ()) return LRESULT.ZERO;
- sendEvent (SWT.Deactivate);
- 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;
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- // the widget could be disposed at this point
- if (event.doit && !isDisposed ()) dispose ();
- 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_NCACTIVATE (int wParam, int lParam) {
- LRESULT result = super.WM_NCACTIVATE (wParam, lParam);
- if (result != null) return result;
- if (wParam == 0) {
- Display display = getDisplay ();
- if (display.lockActiveWindow) return LRESULT.ZERO;
- }
- 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 (!restoreFocus ()) traverseGroup (true);
- 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;
- if (wParam == OS.SIZE_MINIMIZED) {
- sendEvent (SWT.Iconify);
- // widget could be disposed at this point
- }
- return result;
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) {
- LRESULT result = super.WM_WINDOWPOSCHANGING (wParam,lParam);
- if (result != null) return result;
- Display display = getDisplay ();
- 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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>
+ * 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;
+ Menu menuBar;
+ Menu [] menus;
+ MenuItem [] items;
+ Control savedFocus;
+ Button defaultButton, saveDefault;
+ int swFlags, hAccel, nAccel, hIcon;
+
+ /*
+ * 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;
+
+/**
+ * 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 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 add (MenuItem item) {
+ if (items == null) items = new MenuItem [12];
+ 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 + 12];
+ newItems [items.length] = item;
+ System.arraycopy (items, 0, newItems, 0, items.length);
+ items = newItems;
+}
+
+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 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);
+// }
+}
+
+static int checkStyle (int style) {
+ 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 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;
+}
+
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+
+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 bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ boolean hasMenu = OS.IsWinCE ? false : OS.GetMenu (handle) != 0;
+ OS.AdjustWindowRectEx (rect, bits, hasMenu, OS.GetWindowLong (handle, OS.GWL_EXSTYLE));
+
+ /* 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);
+
+ /* Get 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) {
+ 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;
+ if (menuBar == null || items == null) {
+ if (!OS.IsPPC) return;
+ maxAccel = 1;
+ } else {
+ maxAccel = OS.IsPPC ? items.length + 1 : items.length;
+ }
+ int size = ACCEL.sizeof;
+ ACCEL accel = new ACCEL ();
+ byte [] buffer1 = new byte [size];
+ byte [] buffer2 = new byte [maxAccel * size];
+ if (menuBar != null && items != null) {
+ for (int i=0; i<items.length; i++) {
+ MenuItem item = items [i];
+ if (item != null && item.accelerator != 0) {
+ Menu parent = item.parent;
+ while (parent != null && parent != menuBar) {
+ parent = parent.getParentMenu ();
+ }
+ if (parent == menuBar) {
+ item.fillAccel (accel);
+ OS.MoveMemory (buffer1, accel, size);
+ System.arraycopy (buffer1, 0, buffer2, nAccel * size, size);
+ 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 = OS.FVIRTKEY | OS.FCONTROL;
+ accel.key = 'Q';
+ accel.cmd = OS.IDOK;
+ OS.MoveMemory (buffer1, accel, size);
+ System.arraycopy (buffer1, 0, buffer2, nAccel * size, size);
+ nAccel++;
+ }
+ if (nAccel != 0) hAccel = OS.CreateAcceleratorTable (buffer2, nAccel);
+}
+
+void createHandle () {
+ super.createHandle ();
+ if (parent == null) return;
+ 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;
+}
+
+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;
+}
+
+MenuItem findMenuItem (int id) {
+ if (items == null) return null;
+ id = id - ID_START;
+ if (0 <= id && id < items.length) return items [id];
+ return null;
+}
+
+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 -= height;
+ }
+ return rect;
+ }
+ if (!OS.IsWinCE) {
+ if (OS.IsIconic (handle)) {
+ RECT rect = new RECT ();
+ WINDOWPLACEMENT lpwndpl = new WINDOWPLACEMENT ();
+ lpwndpl.length = WINDOWPLACEMENT.sizeof;
+ OS.GetWindowPlacement (handle, lpwndpl);
+ int width = lpwndpl.right - lpwndpl.left;
+ int height = lpwndpl.bottom - lpwndpl.top;
+ OS.SetRect (rect, 0, 0, width, height);
+ OS.SendMessage (handle, OS.WM_NCCALCSIZE, 0, rect);
+ return new Rectangle (0, 0, rect.right, rect.bottom);
+ }
+ }
+ 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;
+}
+
+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);
+ }
+ }
+ 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 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);
+}
+
+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 releaseWidget () {
+ if (menuBar != null) menuBar.releaseResources ();
+ menuBar = null;
+ if (menus != null) {
+ do {
+ int index = 0;
+ while (index < menus.length) {
+ Menu menu = menus [index];
+ if (menu != null && !menu.isDisposed ()) {
+ while (menu.getParentMenu () != null) {
+ menu = menu.getParentMenu ();
+ }
+ menu.dispose ();
+ break;
+ }
+ index++;
+ }
+ if (index == menus.length) break;
+ } while (true);
+ }
+ menus = null;
+ super.releaseWidget ();
+ if (hIcon != 0) OS.DestroyIcon (hIcon);
+ hIcon = 0;
+ items = null;
+ image = null;
+ savedFocus = null;
+ defaultButton = saveDefault = null;
+ if (hAccel != 0 && hAccel != -1) OS.DestroyAcceleratorTable (hAccel);
+ hAccel = -1;
+}
+
+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 remove (MenuItem item) {
+ if (items == null) return;
+ items [item.id - ID_START] = null;
+ item.id = -1;
+}
+
+boolean restoreFocus () {
+ 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 = getDisplay ().getFocusControl ();
+ if (control != null) setSavedFocus (control);
+}
+
+void setBounds (int x, int y, int width, int height, int flags) {
+ if (OS.IsWinCE) {
+ super.setBounds (x, y, width, height, flags);
+ }
+ if (OS.IsIconic (handle) || OS.IsZoomed (handle)) {
+ setPlacement (x, y, width, height, flags);
+ return;
+ }
+ super.setBounds (x, y, width, height, flags);
+}
+
+/**
+ * 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.
+ *
+ * @param the new default button
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 ();
+ setDefaultButton (button, true);
+}
+
+void setDefaultButton (Button button, boolean save) {
+ if (button == null) {
+ if (defaultButton == saveDefault) {
+ if (save) saveDefault = null;
+ return;
+ }
+ } else {
+ if (button.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ 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;
+}
+
+public boolean setFocus () {
+ checkWidget ();
+ if (this instanceof Shell) return super.setFocus ();
+ /*
+ * Bug in Windows. Setting the focus to a child of the
+ * receiver interferes with moving and resizing of the
+ * parent shell. The fix (for now) is to always set the
+ * focus to the shell.
+ */
+ int hwndFocus = OS.SetFocus (getShell ().handle);
+ return hwndFocus == OS.GetFocus ();
+}
+/**
+ * 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);
+ /*
+ * 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 anyways.
+ */
+ if (OS.IsWinCE) {
+ this.image = image;
+ return;
+ }
+ int hImage = 0;
+ if (image != null) {
+ if (hIcon != 0) OS.DestroyIcon (hIcon);
+ hIcon = 0;
+ switch (image.type) {
+ case SWT.BITMAP:
+ /* Copy the bitmap in case it's a DIB */
+ int hBitmap = image.handle;
+ BITMAP bm = new BITMAP ();
+ OS.GetObject (hBitmap, BITMAP.sizeof, bm);
+ byte [] lpvBits = new byte [(bm.bmWidth + 15) / 16 * 2 * bm.bmHeight];
+ int hMask = OS.CreateBitmap (bm.bmWidth, bm.bmHeight, 1, 1, lpvBits);
+ int hDC = OS.GetDC (handle);
+ int hdcMem = OS.CreateCompatibleDC (hDC);
+ int hColor = OS.CreateCompatibleBitmap (hDC, bm.bmWidth, bm.bmHeight);
+ OS.SelectObject (hdcMem, hColor);
+ int hdcBmp = OS.CreateCompatibleDC (hDC);
+ OS.SelectObject (hdcBmp, hBitmap);
+ OS.BitBlt (hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcBmp, 0, 0, OS.SRCCOPY);
+ ICONINFO info = new ICONINFO ();
+ info.fIcon = true;
+ info.hbmMask = hMask;
+ info.hbmColor = hColor;
+ hImage = hIcon = OS.CreateIconIndirect (info);
+ OS.DeleteObject (hMask);
+ OS.DeleteObject(hColor);
+ OS.DeleteDC (hdcBmp);
+ OS.DeleteDC (hdcMem);
+ OS.ReleaseDC (handle, hDC);
+ break;
+ case SWT.ICON:
+ hImage = image.handle;
+ break;
+ default:
+ return;
+ }
+ }
+ this.image = image;
+ OS.SendMessage (handle, OS.WM_SETICON, OS.ICON_BIG, hImage);
+
+ /*
+ * 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 (hIcon == 0 && (style & SWT.BORDER) != 0) {
+ int flags = OS.RDW_FRAME | OS.RDW_INVALIDATE;
+ OS.RedrawWindow (handle, null, 0, flags);
+ }
+ }
+}
+
+/**
+ * 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 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.
+ * PocketPC windows typically don't have a caption when they are
+ * maximized. They usually have one when they are not occupying all the
+ * space. We implement this behavior by default - it can be overriden by
+ * setting SWT.TITLE or SWT.NO_TRIM.
+ */
+ if (maximized) {
+ if ((style & SWT.TITLE) == 0) {
+ /* Remove caption when maximized */
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ bits &= ~OS.WS_CAPTION;
+ OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
+ }
+ 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;
+ OS.SetWindowPos (handle, 0, rect.left, rect.top, width, height, flags);
+ } else {
+ if ((style & SWT.NO_TRIM) == 0) {
+ /* Insert caption when no longer maximized */
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ bits |= OS.WS_CAPTION;
+ OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
+ int flags = OS.SWP_NOMOVE | OS.SWP_NOSIZE | OS.SWP_NOZORDER | OS.SWP_DRAWFRAME;
+ OS.SetWindowPos (handle, 0, 0, 0, 0, 0, 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);
+ layout (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 display = getDisplay ();
+ 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 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 = OS.SW_RESTORE;
+ if (minimized) swFlags = OS.SW_SHOWMINNOACTIVE;
+ if (!OS.IsWindowVisible (handle)) return;
+ if (minimized == OS.IsIconic (handle)) return;
+ OS.ShowWindow (handle, swFlags);
+ 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.
+ */
+ Display display = getDisplay ();
+ int hwndParent = parent.handle;
+ display.lockActiveWindow = true;
+ OS.SetParent (handle, hwndParent);
+ if (!OS.IsWindowVisible (hwndParent)) {
+ OS.ShowWindow (handle, OS.SW_SHOWNA);
+ }
+ 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;
+ }
+ }
+ if ((flags & OS.SWP_NOMOVE) == 0) {
+ lpwndpl.left = x;
+ lpwndpl.top = y;
+ }
+ if ((flags & OS.SWP_NOSIZE) == 0) {
+ lpwndpl.right = x + width;
+ lpwndpl.bottom = y + height;
+ }
+ OS.SetWindowPlacement (handle, lpwndpl);
+}
+
+void setSavedFocus (Control control) {
+ if (this == control) {
+ savedFocus = null;
+ return;
+ }
+ if (this != control.menuShell ()) return;
+ 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 may not be null.
+ *
+ * @param text the new text
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 (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 (OS.IsWinCE) {
+ OS.ShowWindow (handle, OS.SW_SHOW);
+ } else {
+ if (menuBar != null) {
+ Display display = getDisplay ();
+ display.removeBar (menuBar);
+ OS.DrawMenuBar (handle);
+ }
+ OS.ShowWindow (handle, swFlags);
+ }
+ 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;
+ }
+ }
+ }
+ }
+ OS.ShowWindow (handle, OS.SW_HIDE);
+ sendEvent (SWT.Hide);
+ }
+}
+
+boolean translateAccelerator (MSG msg) {
+ if (!isEnabled () || !isActive ()) return false;
+ if (menuBar != null && !menuBar.isEnabled ()) return false;
+ if (hAccel == -1) createAccelerators ();
+ if (hAccel == 0) return false;
+ return OS.TranslateAccelerator (handle, hAccel, msg) != 0;
+}
+
+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;
+}
+
+int widgetExtStyle () {
+ int bits = super.widgetExtStyle () & ~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.TOOL) != 0) bits |= OS.WS_EX_TOOLWINDOW;
+ if ((style & SWT.RESIZE) != 0) return bits;
+ if ((style & SWT.BORDER) != 0) bits |= OS.WS_EX_DLGMODALFRAME;
+ return bits;
+}
+
+int widgetStyle () {
+ /*
+ * Set WS_POPUP and clear WS_VISIBLE and WS_TABSTOP.
+ * NOTE: WS_TABSTOP is the same as WS_MAXIMIZEBOX so
+ * it cannot be used to do tabbing with decorations.
+ */
+ int bits = super.widgetStyle () | OS.WS_POPUP;
+ bits &= ~(OS.WS_VISIBLE | OS.WS_TABSTOP);
+
+ /* 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 msg, int wParam, int lParam) {
+ switch (msg) {
+ case OS.WM_APP:
+ case OS.WM_APP+1:
+ if (hAccel == -1) createAccelerators ();
+ return msg == OS.WM_APP ? nAccel : hAccel;
+ }
+ return super.windowProc (msg, wParam, lParam);
+}
+
+LRESULT WM_ACTIVATE (int wParam, int lParam) {
+ LRESULT result = super.WM_ACTIVATE (wParam, lParam);
+ if (result != null) return result;
+ 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;
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the activate
+ * event. If this happens, end the processing of the
+ * Windows message by returning zero as the result of
+ * the window proc.
+ */
+ sendEvent (SWT.Activate);
+ if (isDisposed ()) return LRESULT.ZERO;
+ if (restoreFocus ()) return LRESULT.ZERO;
+ if (traverseGroup (true)) return LRESULT.ZERO;
+
+ } else {
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the deactivate
+ * event. If this happens, end the processing of the
+ * Windows message by returning zero as the result of
+ * the window proc.
+ */
+ Shell shell = getShell ();
+ shell.setActiveControl (null);
+ if (isDisposed ()) return LRESULT.ZERO;
+ sendEvent (SWT.Deactivate);
+ 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;
+ Event event = new Event ();
+ sendEvent (SWT.Close, event);
+ // the widget could be disposed at this point
+ if (event.doit && !isDisposed ()) dispose ();
+ 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_NCACTIVATE (int wParam, int lParam) {
+ LRESULT result = super.WM_NCACTIVATE (wParam, lParam);
+ if (result != null) return result;
+ if (wParam == 0) {
+ Display display = getDisplay ();
+ if (display.lockActiveWindow) return LRESULT.ZERO;
+ }
+ 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 (!restoreFocus ()) traverseGroup (true);
+ 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;
+ if (wParam == OS.SIZE_MINIMIZED) {
+ sendEvent (SWT.Iconify);
+ // widget could be disposed at this point
+ }
+ return result;
+}
+
+LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) {
+ LRESULT result = super.WM_WINDOWPOSCHANGING (wParam,lParam);
+ if (result != null) return result;
+ Display display = getDisplay ();
+ 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
index b97e76ef34..f4fdc01bf0 100755
--- 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
@@ -1,242 +1,242 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.
- * <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 = "";
- String directoryPath;
-
-/**
- * Constructs a new instance of this class given only its
- * parent.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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 */
- TCHAR buffer = new TCHAR (0, 256);
- int byteCount = buffer.length () * TCHAR.sizeof;
- OS.MoveMemory (buffer, lParam, byteCount);
- directoryPath = buffer.toString (0, buffer.strlen ());
- break;
- }
- return 0;
-}
-
-/**
- * Returns the path which the dialog will use to filter
- * the directories it shows.
- *
- * @return the filter path
- */
-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);
-
- /* Initialize OLE */
- OS.OleInitialize (0);
-
- 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 != null && message.length () != 0) {
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, message, 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);
- int address = callback.getAddress ();
-
- /* Open the dialog */
- 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;
- int lpItemIdList = OS.SHBrowseForFolder (lpbi);
- boolean success = lpItemIdList != 0;
- if (success) {
- /* Use the character encoding for the default locale */
- TCHAR buffer = new TCHAR (0, 256);
- 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);
- }
-
- /* Uninitialize OLE */
- OS.OleUninitialize ();
-
- /*
- * 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 which the dialog will use to filter
- * the directories it shows to the argument, which may be
- * null.
- *
- * @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
- */
-public void setMessage (String string) {
- message = string;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
+ * <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 = "";
+ String directoryPath;
+
+/**
+ * Constructs a new instance of this class given only its
+ * parent.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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 */
+ TCHAR buffer = new TCHAR (0, 256);
+ int byteCount = buffer.length () * TCHAR.sizeof;
+ OS.MoveMemory (buffer, lParam, byteCount);
+ directoryPath = buffer.toString (0, buffer.strlen ());
+ break;
+ }
+ return 0;
+}
+
+/**
+ * Returns the path which the dialog will use to filter
+ * the directories it shows.
+ *
+ * @return the filter path
+ */
+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);
+
+ /* Initialize OLE */
+ OS.OleInitialize (0);
+
+ 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 != null && message.length () != 0) {
+ /* Use the character encoding for the default locale */
+ TCHAR buffer = new TCHAR (0, message, 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);
+ int address = callback.getAddress ();
+
+ /* Open the dialog */
+ 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;
+ int lpItemIdList = OS.SHBrowseForFolder (lpbi);
+ boolean success = lpItemIdList != 0;
+ if (success) {
+ /* Use the character encoding for the default locale */
+ TCHAR buffer = new TCHAR (0, 256);
+ 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);
+ }
+
+ /* Uninitialize OLE */
+ OS.OleUninitialize ();
+
+ /*
+ * 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 which the dialog will use to filter
+ * the directories it shows to the argument, which may be
+ * null.
+ *
+ * @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
+ */
+public void setMessage (String string) {
+ 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
index 322fce35d9..37b27ba529 100755
--- 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
@@ -1,2333 +1,2333 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 #dispose
- */
-
-public class Display extends Device {
-
- /**
- * the handle to the OS message queue
- * (Warning: This field is platform dependent)
- */
- public MSG msg = new MSG ();
-
- /* Windows and Events */
- Event [] eventQueue;
- Callback windowCallback;
- int windowProc, threadId, processId;
- TCHAR windowClass;
- static int WindowClassCount = 0;
- static final String WindowName = "SWT_Window";
- EventTable eventTable, filterTable;
-
- /* Message Filter */
- Callback msgFilterCallback;
- int msgFilterProc, hHook;
- MSG hookMsg = new MSG ();
-
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer = new Synchronizer (this);
- Thread thread;
-
- /* Display Shutdown */
- Runnable [] disposeList;
-
- /* Timers */
- int timerCount;
- int [] timerIds;
- Runnable [] timerList;
-
- /* Keyboard and Mouse State */
- boolean lockActiveWindow;
- boolean lastVirtual, lastNull;
- int lastKey, lastAscii, lastMouse;
- byte [] keyboard = new byte [256];
- boolean accelKeyHit, mnemonicKeyHit;
-
- /* Message Only Window */
- int hwndMessage, messageProc;
- Callback messageCallback;
- int [] systemFonts;
-
- /* Image list cache */
- ImageList[] imageList, toolImageList, toolHotImageList, toolDisabledImageList;
-
- /* Custom Colors for ChooseColor */
- int lpCustColors;
-
- /* Display Data */
- Object data;
- String [] keys;
- Object [] values;
-
- /* Bar and Popup Menus */
- Menu [] bars, popups;
-
- /* 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},
-
- /* 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},
-
- /* Numeric Keypad Keys */
-// {OS.VK_ADD, SWT.KP_PLUS},
-// {OS.VK_SUBTRACT, SWT.KP_MINUS},
-// {OS.VK_MULTIPLY, SWT.KP_TIMES},
-// {OS.VK_DIVIDE, SWT.KP_DIVIDE},
-// {OS.VK_DECIMAL, SWT.KP_DECIMAL},
-// {OS.VK_RETURN, SWT.KP_CR},
-// {OS.VK_NUMPAD0, SWT.KP_0},
-// {OS.VK_NUMPAD1, SWT.KP_1},
-// {OS.VK_NUMPAD2, SWT.KP_2},
-// {OS.VK_NUMPAD3, SWT.KP_3},
-// {OS.VK_NUMPAD4, SWT.KP_4},
-// {OS.VK_NUMPAD5, SWT.KP_5},
-// {OS.VK_NUMPAD6, SWT.KP_6},
-// {OS.VK_NUMPAD7, SWT.KP_7},
-// {OS.VK_NUMPAD8, SWT.KP_8},
-// {OS.VK_NUMPAD9, SWT.KP_9},
-
- };
-
- /* Multiple Displays */
- static Display Default;
- static Display [] Displays = new Display [4];
-
- /* Modality */
- Shell [] modalWidgets;
- static boolean TrimEnabled = false;
-
- /* 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);
-// }
-
- /*
- * 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 not called from the thread that created the parent</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);
-}
-
-public Display (DeviceData data) {
- super (data);
-}
-
-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;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notifed when an event of the given type occurs anywhere
- * in SWT. When the event does occur, 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>
- * </ul>
- *
- * @see Listener
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 2.1
- */
-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 notifed when an event of the given type occurs. 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>
- * </ul>
- *
- * @see Listener
- * @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 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 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.
- *
- * @param runnable code to run on the user-interface thread.
- *
- * @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).
- */
-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 (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-static synchronized void checkDisplay (Thread thread) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] != null && Displays [i].thread == thread) {
- SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- }
-}
-
-void clearModal (Shell shell) {
- if (modalWidgets == null) return;
- int index = 0, length = modalWidgets.length;
- while (index < length) {
- if (modalWidgets [index] == shell) break;
- if (modalWidgets [index] == null) return;
- index++;
- }
- if (index == length) return;
- System.arraycopy (modalWidgets, index + 1, modalWidgets, index, --length - index);
- modalWidgets [length] = null;
- if (index == 0 && modalWidgets [0] == null) modalWidgets = 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>
- * </ul>
- *
- * @see #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 ());
- createDisplay (data);
- register (this);
- if (Default == null) Default = this;
-}
-
-void createDisplay (DeviceData data) {
-}
-
-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 #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.
- *
- * @param runnable code to run at dispose time.
- */
-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;
-}
-
-/**
- * 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);
-}
-
-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 = false;
- return true;
- }
- }
- }
- 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.
- *
- * @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>
- * </ul>
- */
-public Widget findWidget (int handle) {
- checkDevice ();
- return WidgetTable.get (handle);
-}
-
-Control findControl(int handle) {
- if (handle == 0) return null;
- /*
- * This code is intentionally commented. It is possible
- * find the SWT control that is associated with a handle
- * that belongs to another process when the handle was
- * created by an in-proc OLE client. In this case, the
- * handle comes from another process, but it is a child
- * of an SWT control. For now, it is necessary to look
- * at handles that do not belong to the SWT process.
- */
-// int [] hwndProcessId = new int [1];
-// OS.GetWindowThreadProcessId (handle, hwndProcessId);
-// if (hwndProcessId [0] != processId) return null;
- do {
- Control control = WidgetTable.get (handle);
- if (control != null && control.handle == handle) {
- return control;
- }
- } while ((handle = OS.GetParent (handle)) != 0);
- return null;
-}
-
-
-/**
- * Returns the display which the given thread is the
- * user-interface thread for, or null if the given thread
- * is not a user-interface thread for any display.
- *
- * @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>
- * </ul>
- */
-public Shell getActiveShell () {
- checkDevice ();
- Control control = findControl (OS.GetActiveWindow ());
- if (control instanceof Shell) return (Shell) control;
- return 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>
- * </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 ());
-}
-
-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);
-}
-
-/**
- * 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>
- * </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>
- * </ul>
- */
-public Point getCursorLocation () {
- checkDevice ();
- POINT pt = new POINT ();
- OS.GetCursorPos (pt);
- return new Point (pt.x, pt.y);
-}
-
-/**
- * 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 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>
- * </ul>
- *
- * @see #setData
- * @see #disposeExec
- */
-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 provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @return the display specific data
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
- * </ul>
- *
- * @see #setData
- * @see #disposeExec
- */
-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>
- * </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>
- * </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>
- * </ul>
- */
-public Control getFocusControl () {
- checkDevice ();
- return findControl (OS.GetFocus ());
-}
-
-/**
- * Returns the maximum allowed depth of icons on this display.
- * 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>
- * </ul>
- */
-public int getIconDepth () {
- checkDevice ();
-
- /* Use the character encoding for the default locale */
- TCHAR buffer1 = new TCHAR (0, "Control Panel\\Desktop\\WindowMetrics", true);
-
- 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);
-
- 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;
-}
-
-ImageList getImageList (Point size) {
- 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;
- if (list.getImageSize().equals(size)) {
- 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();
- imageList [i] = list;
- list.addRef();
- return list;
-}
-
-ImageList getToolImageList (Point size) {
- 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;
- if (list.getImageSize().equals(size)) {
- 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();
- toolImageList [i] = list;
- list.addRef();
- return list;
-}
-
-ImageList getToolHotImageList (Point size) {
- 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;
- if (list.getImageSize().equals(size)) {
- 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();
- toolHotImageList [i] = list;
- list.addRef();
- return list;
-}
-
-ImageList getToolDisabledImageList (Point size) {
- 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;
- if (list.getImageSize().equals(size)) {
- 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();
- toolDisabledImageList [i] = list;
- list.addRef();
- return list;
-}
-
-Shell getModalShell () {
- if (modalWidgets == null) return null;
- int index = modalWidgets.length;
- while (--index >= 0) {
- Shell shell = modalWidgets [index];
- if (shell != null) return shell;
- }
- return null;
-}
-
-int getLastEventTime () {
- return OS.IsWinCE ? OS.GetTickCount () : OS.GetMessageTime ();
-}
-
-/**
- * Returns an 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>
- * </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.getDisplay ()) {
- 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.getDisplay ()) {
- result [index++] = shell;
- }
- }
- 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
- */
-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>
- * </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 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>
- * </ul>
- */
-public Font getSystemFont () {
- checkDevice ();
- int hFont = systemFont ();
- return Font.win32_new (this, hFont);
-}
-
-/**
- * Returns the user-interface thread for the receiver.
- *
- * @return the receiver's user-interface thread
- */
-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
- *
- * @private
- */
-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) {
- data.device = this;
- data.hFont = systemFont ();
- }
- 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);
- windowProc = windowCallback.getAddress ();
- if (windowProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Remember the current procsss and thread */
- threadId = OS.GetCurrentThreadId ();
- processId = OS.GetCurrentProcessId ();
-
- /* Use the character encoding for the default locale */
- windowClass = new TCHAR (0, WindowName + WindowClassCount++, true);
-
- /* 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;
- int lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- lpWndClass.lpszClassName = lpszClassName;
- OS.MoveMemory (lpszClassName, windowClass, byteCount);
- OS.RegisterClass (lpWndClass);
-
- /* Initialize the system font */
- int systemFont = 0;
- if (!OS.IsWinCE) {
- NONCLIENTMETRICS info = new NONCLIENTMETRICS ();
- info.cbSize = NONCLIENTMETRICS.sizeof;
- if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
- systemFont = OS.CreateFontIndirect (info.lfMessageFont);
- }
- }
- if (systemFont == 0) systemFont = OS.GetStockObject (OS.DEFAULT_GUI_FONT);
- if (systemFont == 0) systemFont = OS.GetStockObject (OS.SYSTEM_FONT);
- if (systemFont != 0) systemFonts = new int [] {systemFont};
-
- /* 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);
- messageProc = messageCallback.getAddress ();
- if (messageProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.SetWindowLong (hwndMessage, OS.GWL_WNDPROC, messageProc);
-
- /* Create the message filter hook */
- if (!OS.IsWinCE) {
- msgFilterCallback = new Callback (this, "msgFilterProc", 3);
- msgFilterProc = msgFilterCallback.getAddress ();
- if (msgFilterProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- hHook = OS.SetWindowsHookEx (OS.WH_MSGFILTER, msgFilterProc, 0, threadId);
- }
-}
-
-/**
- * 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 handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
- */
-public void internal_dispose_GC (int hDC, GCData data) {
- OS.ReleaseDC (0, hDC);
-}
-
-boolean isWakeMessage (MSG msg) {
- return msg.hwnd == hwndMessage && msg.message == OS.WM_NULL;
-}
-
-boolean isValidThread () {
- return thread == Thread.currentThread ();
-}
-
-boolean isVirtualKey (int key) {
- switch (key) {
- case OS.VK_TAB:
- case OS.VK_RETURN:
- case OS.VK_BACK:
- case OS.VK_ESCAPE:
-// case OS.VK_DELETE:
- case OS.VK_SPACE:
- case OS.VK_MENU:
- case OS.VK_SHIFT:
- case OS.VK_CONTROL: return true;
- }
- return false;
-}
-
-int messageProc (int hwnd, int msg, int wParam, int lParam) {
- switch (msg) {
- 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.
- */
- if (wParam != 0) {
- Shell shell = getModalShell ();
- if (shell != null) shell.bringToTop ();
- }
- break;
- case OS.WM_ENDSESSION:
- if (wParam != 0) dispose ();
- break;
- case OS.WM_NULL:
- runAsyncMessages ();
- break;
- case OS.WM_QUERYENDSESSION:
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (!event.doit) return 0;
- break;
- case OS.WM_SETTINGCHANGE:
- updateFont ();
- break;
- case OS.WM_TIMER:
- runTimer (wParam);
- break;
- }
- return OS.DefWindowProc (hwnd, msg, wParam, lParam);
-}
-
-int msgFilterProc (int code, int wParam, int lParam) {
- if (code >= 0) {
- OS.MoveMemory (hookMsg, lParam, MSG.sizeof);
- if (hookMsg.message == OS.WM_NULL) runAsyncMessages ();
- }
- return OS.CallNextHookEx (hHook, 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;
-}
-
-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>
- * </ul>
- *
- * @see #sleep
- * @see #wake
- */
-public boolean readAndDispatch () {
- checkDevice ();
- drawMenuBars ();
- runPopups ();
- if (OS.PeekMessage (msg, 0, 0, 0, OS.PM_REMOVE)) {
- if (!isWakeMessage (msg)) {
- if (!filterMessage (msg)) {
- OS.TranslateMessage (msg);
- OS.DispatchMessage (msg);
- }
- runDeferredEvents ();
- return true;
- }
- }
- return runAsyncMessages ();
-}
-
-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 #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.getDisplay ()) shell.dispose ();
- }
- }
- 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 () {
-
- /* Unhook the message hook */
- if (!OS.IsWinCE) {
- if (hHook != 0) OS.UnhookWindowsHookEx (hHook);
- hHook = 0;
- msgFilterCallback.dispose ();
- msgFilterCallback = null;
- msgFilterProc = 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);
- windowClass = null;
- windowCallback.dispose ();
- windowCallback = null;
- windowProc = 0;
-
- /* Release the system fonts */
- if (systemFonts != null) {
- for (int i=0; i<systemFonts.length; i++) {
- if (systemFonts [i] != 0) OS.DeleteObject (systemFonts [i]);
- }
- }
- systemFonts = null;
-
- /* Release Custom Colors for ChooseColor */
- if (lpCustColors != 0) OS.HeapFree (hHeap, 0, lpCustColors);
- lpCustColors = 0;
-
- /* Release references */
- thread = null;
- msg = null;
- keyboard = null;
- modalWidgets = null;
- data = null;
- keys = null;
- values = 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 notifed when an event of the given type occurs anywhere in SWT.
- *
- * @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 #addFilter
- * @see #addListener
- *
- * @since 2.1
- */
-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 notifed when an event of the given type occurs.
- *
- * @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 #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;
- }
- }
-}
-
-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 () {
- return synchronizer.runAsyncMessages ();
-}
-
-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;
- menu._setVisible (true);
- result = true;
- }
- popups = null;
- return result;
-}
-
-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 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>
- * </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
- * </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>
- * </ul>
- *
- * @see #setData
- * @see #disposeExec
- */
-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 - when called from the wrong thread</li>
- * </ul>
- *
- * @see #getData
- * @see #disposeExec
- */
-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.
- *
- * @param name the new app name
- */
-public static void setAppName (String name) {
- /* Do nothing */
-}
-
-void setModalShell (Shell shell) {
- if (modalWidgets == null) modalWidgets = new Shell [4];
- int index = 0, length = modalWidgets.length;
- while (index < length) {
- if (modalWidgets [index] == shell) return;
- if (modalWidgets [index] == null) break;
- index++;
- }
- if (index == length) {
- Shell [] newModalWidgets = new Shell [length + 4];
- System.arraycopy (modalWidgets, 0, newModalWidgets, 0, length);
- modalWidgets = newModalWidgets;
- }
- modalWidgets [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>
- * </ul>
- */
-public void setSynchronizer (Synchronizer synchronizer) {
- checkDevice ();
- if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (this.synchronizer != null) {
- this.synchronizer.runAsyncMessages();
- }
- 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>
- * </ul>
- *
- * @see #wake
- */
-public boolean sleep () {
- checkDevice ();
- 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.
- *
- * @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
- */
-public void syncExec (Runnable runnable) {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- synchronizer.syncExec (runnable);
-}
-
-int systemFont () {
- int hFont = 0;
- if (systemFonts != null) {
- int length = systemFonts.length;
- if (length != 0) hFont = systemFonts [length - 1];
- }
- if (hFont == 0) hFont = OS.GetStockObject (OS.DEFAULT_GUI_FONT);
- if (hFont == 0) hFont = OS.GetStockObject (OS.SYSTEM_FONT);
- return hFont;
-}
-
-/**
- * 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.
- *
- * @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>
- * </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++;
- }
- timerCount++;
- timerId = timerCount;
- 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.
- *
- * @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.getDisplay ()) {
- shell.update (true);
- }
- }
-}
-
-void updateFont () {
- if (OS.IsWinCE) return;
- Font oldFont = getSystemFont ();
- int systemFont = 0;
- NONCLIENTMETRICS info = new NONCLIENTMETRICS ();
- info.cbSize = NONCLIENTMETRICS.sizeof;
- if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
- systemFont = OS.CreateFontIndirect (info.lfMessageFont);
- }
- if (systemFont == 0) systemFont = OS.GetStockObject (OS.DEFAULT_GUI_FONT);
- if (systemFont == 0) systemFont = OS.GetStockObject (OS.SYSTEM_FONT);
- if (systemFont == 0) return;
- int length = systemFonts == null ? 0 : systemFonts.length;
- int [] newFonts = new int [length + 1];
- if (systemFonts != null) {
- System.arraycopy (systemFonts, 0, newFonts, 0, length);
- }
- newFonts [length] = systemFont;
- systemFonts = newFonts;
- Font newFont = getSystemFont ();
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) {
- shell.updateFont (oldFont, newFont);
- }
- }
-}
-
-/**
- * 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.
- *
- * @see #sleep
- */
-public void wake () {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (thread == Thread.currentThread ()) return;
- if (OS.IsWinCE) {
- OS.PostMessage (hwndMessage, OS.WM_NULL, 0, 0);
- } else {
- OS.PostThreadMessage (threadId, OS.WM_NULL, 0, 0);
- }
-}
-
-int windowProc (int hwnd, int msg, int wParam, int lParam) {
- Control control = WidgetTable.get (hwnd);
- if (control != null) {
- return control.windowProc (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");
- i++;
- }
- }
- return result.toString ();
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 #dispose
+ */
+
+public class Display extends Device {
+
+ /**
+ * the handle to the OS message queue
+ * (Warning: This field is platform dependent)
+ */
+ public MSG msg = new MSG ();
+
+ /* Windows and Events */
+ Event [] eventQueue;
+ Callback windowCallback;
+ int windowProc, threadId, processId;
+ TCHAR windowClass;
+ static int WindowClassCount = 0;
+ static final String WindowName = "SWT_Window";
+ EventTable eventTable, filterTable;
+
+ /* Message Filter */
+ Callback msgFilterCallback;
+ int msgFilterProc, hHook;
+ MSG hookMsg = new MSG ();
+
+ /* Sync/Async Widget Communication */
+ Synchronizer synchronizer = new Synchronizer (this);
+ Thread thread;
+
+ /* Display Shutdown */
+ Runnable [] disposeList;
+
+ /* Timers */
+ int timerCount;
+ int [] timerIds;
+ Runnable [] timerList;
+
+ /* Keyboard and Mouse State */
+ boolean lockActiveWindow;
+ boolean lastVirtual, lastNull;
+ int lastKey, lastAscii, lastMouse;
+ byte [] keyboard = new byte [256];
+ boolean accelKeyHit, mnemonicKeyHit;
+
+ /* Message Only Window */
+ int hwndMessage, messageProc;
+ Callback messageCallback;
+ int [] systemFonts;
+
+ /* Image list cache */
+ ImageList[] imageList, toolImageList, toolHotImageList, toolDisabledImageList;
+
+ /* Custom Colors for ChooseColor */
+ int lpCustColors;
+
+ /* Display Data */
+ Object data;
+ String [] keys;
+ Object [] values;
+
+ /* Bar and Popup Menus */
+ Menu [] bars, popups;
+
+ /* 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},
+
+ /* 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},
+
+ /* Numeric Keypad Keys */
+// {OS.VK_ADD, SWT.KP_PLUS},
+// {OS.VK_SUBTRACT, SWT.KP_MINUS},
+// {OS.VK_MULTIPLY, SWT.KP_TIMES},
+// {OS.VK_DIVIDE, SWT.KP_DIVIDE},
+// {OS.VK_DECIMAL, SWT.KP_DECIMAL},
+// {OS.VK_RETURN, SWT.KP_CR},
+// {OS.VK_NUMPAD0, SWT.KP_0},
+// {OS.VK_NUMPAD1, SWT.KP_1},
+// {OS.VK_NUMPAD2, SWT.KP_2},
+// {OS.VK_NUMPAD3, SWT.KP_3},
+// {OS.VK_NUMPAD4, SWT.KP_4},
+// {OS.VK_NUMPAD5, SWT.KP_5},
+// {OS.VK_NUMPAD6, SWT.KP_6},
+// {OS.VK_NUMPAD7, SWT.KP_7},
+// {OS.VK_NUMPAD8, SWT.KP_8},
+// {OS.VK_NUMPAD9, SWT.KP_9},
+
+ };
+
+ /* Multiple Displays */
+ static Display Default;
+ static Display [] Displays = new Display [4];
+
+ /* Modality */
+ Shell [] modalWidgets;
+ static boolean TrimEnabled = false;
+
+ /* 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);
+// }
+
+ /*
+ * 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 not called from the thread that created the parent</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);
+}
+
+public Display (DeviceData data) {
+ super (data);
+}
+
+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;
+}
+
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notifed when an event of the given type occurs anywhere
+ * in SWT. When the event does occur, 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>
+ * </ul>
+ *
+ * @see Listener
+ * @see #removeFilter
+ * @see #removeListener
+ *
+ * @since 2.1
+ */
+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 notifed when an event of the given type occurs. 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>
+ * </ul>
+ *
+ * @see Listener
+ * @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 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 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.
+ *
+ * @param runnable code to run on the user-interface thread.
+ *
+ * @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).
+ */
+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 (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+}
+
+static synchronized void checkDisplay (Thread thread) {
+ for (int i=0; i<Displays.length; i++) {
+ if (Displays [i] != null && Displays [i].thread == thread) {
+ SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ }
+ }
+}
+
+void clearModal (Shell shell) {
+ if (modalWidgets == null) return;
+ int index = 0, length = modalWidgets.length;
+ while (index < length) {
+ if (modalWidgets [index] == shell) break;
+ if (modalWidgets [index] == null) return;
+ index++;
+ }
+ if (index == length) return;
+ System.arraycopy (modalWidgets, index + 1, modalWidgets, index, --length - index);
+ modalWidgets [length] = null;
+ if (index == 0 && modalWidgets [0] == null) modalWidgets = 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>
+ * </ul>
+ *
+ * @see #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 ());
+ createDisplay (data);
+ register (this);
+ if (Default == null) Default = this;
+}
+
+void createDisplay (DeviceData data) {
+}
+
+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 #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.
+ *
+ * @param runnable code to run at dispose time.
+ */
+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;
+}
+
+/**
+ * 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);
+}
+
+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 = false;
+ return true;
+ }
+ }
+ }
+ 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.
+ *
+ * @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>
+ * </ul>
+ */
+public Widget findWidget (int handle) {
+ checkDevice ();
+ return WidgetTable.get (handle);
+}
+
+Control findControl(int handle) {
+ if (handle == 0) return null;
+ /*
+ * This code is intentionally commented. It is possible
+ * find the SWT control that is associated with a handle
+ * that belongs to another process when the handle was
+ * created by an in-proc OLE client. In this case, the
+ * handle comes from another process, but it is a child
+ * of an SWT control. For now, it is necessary to look
+ * at handles that do not belong to the SWT process.
+ */
+// int [] hwndProcessId = new int [1];
+// OS.GetWindowThreadProcessId (handle, hwndProcessId);
+// if (hwndProcessId [0] != processId) return null;
+ do {
+ Control control = WidgetTable.get (handle);
+ if (control != null && control.handle == handle) {
+ return control;
+ }
+ } while ((handle = OS.GetParent (handle)) != 0);
+ return null;
+}
+
+
+/**
+ * Returns the display which the given thread is the
+ * user-interface thread for, or null if the given thread
+ * is not a user-interface thread for any display.
+ *
+ * @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>
+ * </ul>
+ */
+public Shell getActiveShell () {
+ checkDevice ();
+ Control control = findControl (OS.GetActiveWindow ());
+ if (control instanceof Shell) return (Shell) control;
+ return 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>
+ * </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 ());
+}
+
+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);
+}
+
+/**
+ * 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>
+ * </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>
+ * </ul>
+ */
+public Point getCursorLocation () {
+ checkDevice ();
+ POINT pt = new POINT ();
+ OS.GetCursorPos (pt);
+ return new Point (pt.x, pt.y);
+}
+
+/**
+ * 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 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>
+ * </ul>
+ *
+ * @see #setData
+ * @see #disposeExec
+ */
+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 provide a
+ * <code>disposeExec()</code> handler which does so.
+ * </p>
+ *
+ * @return the display specific data
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li>
+ * </ul>
+ *
+ * @see #setData
+ * @see #disposeExec
+ */
+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>
+ * </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>
+ * </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>
+ * </ul>
+ */
+public Control getFocusControl () {
+ checkDevice ();
+ return findControl (OS.GetFocus ());
+}
+
+/**
+ * Returns the maximum allowed depth of icons on this display.
+ * 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>
+ * </ul>
+ */
+public int getIconDepth () {
+ checkDevice ();
+
+ /* Use the character encoding for the default locale */
+ TCHAR buffer1 = new TCHAR (0, "Control Panel\\Desktop\\WindowMetrics", true);
+
+ 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);
+
+ 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;
+}
+
+ImageList getImageList (Point size) {
+ 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;
+ if (list.getImageSize().equals(size)) {
+ 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();
+ imageList [i] = list;
+ list.addRef();
+ return list;
+}
+
+ImageList getToolImageList (Point size) {
+ 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;
+ if (list.getImageSize().equals(size)) {
+ 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();
+ toolImageList [i] = list;
+ list.addRef();
+ return list;
+}
+
+ImageList getToolHotImageList (Point size) {
+ 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;
+ if (list.getImageSize().equals(size)) {
+ 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();
+ toolHotImageList [i] = list;
+ list.addRef();
+ return list;
+}
+
+ImageList getToolDisabledImageList (Point size) {
+ 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;
+ if (list.getImageSize().equals(size)) {
+ 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();
+ toolDisabledImageList [i] = list;
+ list.addRef();
+ return list;
+}
+
+Shell getModalShell () {
+ if (modalWidgets == null) return null;
+ int index = modalWidgets.length;
+ while (--index >= 0) {
+ Shell shell = modalWidgets [index];
+ if (shell != null) return shell;
+ }
+ return null;
+}
+
+int getLastEventTime () {
+ return OS.IsWinCE ? OS.GetTickCount () : OS.GetMessageTime ();
+}
+
+/**
+ * Returns an 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>
+ * </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.getDisplay ()) {
+ 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.getDisplay ()) {
+ result [index++] = shell;
+ }
+ }
+ 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
+ */
+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>
+ * </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 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>
+ * </ul>
+ */
+public Font getSystemFont () {
+ checkDevice ();
+ int hFont = systemFont ();
+ return Font.win32_new (this, hFont);
+}
+
+/**
+ * Returns the user-interface thread for the receiver.
+ *
+ * @return the receiver's user-interface thread
+ */
+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
+ *
+ * @private
+ */
+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) {
+ data.device = this;
+ data.hFont = systemFont ();
+ }
+ 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);
+ windowProc = windowCallback.getAddress ();
+ if (windowProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+
+ /* Remember the current procsss and thread */
+ threadId = OS.GetCurrentThreadId ();
+ processId = OS.GetCurrentProcessId ();
+
+ /* Use the character encoding for the default locale */
+ windowClass = new TCHAR (0, WindowName + WindowClassCount++, true);
+
+ /* 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;
+ int lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
+ lpWndClass.lpszClassName = lpszClassName;
+ OS.MoveMemory (lpszClassName, windowClass, byteCount);
+ OS.RegisterClass (lpWndClass);
+
+ /* Initialize the system font */
+ int systemFont = 0;
+ if (!OS.IsWinCE) {
+ NONCLIENTMETRICS info = new NONCLIENTMETRICS ();
+ info.cbSize = NONCLIENTMETRICS.sizeof;
+ if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
+ systemFont = OS.CreateFontIndirect (info.lfMessageFont);
+ }
+ }
+ if (systemFont == 0) systemFont = OS.GetStockObject (OS.DEFAULT_GUI_FONT);
+ if (systemFont == 0) systemFont = OS.GetStockObject (OS.SYSTEM_FONT);
+ if (systemFont != 0) systemFonts = new int [] {systemFont};
+
+ /* 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);
+ messageProc = messageCallback.getAddress ();
+ if (messageProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+ OS.SetWindowLong (hwndMessage, OS.GWL_WNDPROC, messageProc);
+
+ /* Create the message filter hook */
+ if (!OS.IsWinCE) {
+ msgFilterCallback = new Callback (this, "msgFilterProc", 3);
+ msgFilterProc = msgFilterCallback.getAddress ();
+ if (msgFilterProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
+ hHook = OS.SetWindowsHookEx (OS.WH_MSGFILTER, msgFilterProc, 0, threadId);
+ }
+}
+
+/**
+ * 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 handle the platform specific GC handle
+ * @param data the platform specific GC data
+ *
+ * @private
+ */
+public void internal_dispose_GC (int hDC, GCData data) {
+ OS.ReleaseDC (0, hDC);
+}
+
+boolean isWakeMessage (MSG msg) {
+ return msg.hwnd == hwndMessage && msg.message == OS.WM_NULL;
+}
+
+boolean isValidThread () {
+ return thread == Thread.currentThread ();
+}
+
+boolean isVirtualKey (int key) {
+ switch (key) {
+ case OS.VK_TAB:
+ case OS.VK_RETURN:
+ case OS.VK_BACK:
+ case OS.VK_ESCAPE:
+// case OS.VK_DELETE:
+ case OS.VK_SPACE:
+ case OS.VK_MENU:
+ case OS.VK_SHIFT:
+ case OS.VK_CONTROL: return true;
+ }
+ return false;
+}
+
+int messageProc (int hwnd, int msg, int wParam, int lParam) {
+ switch (msg) {
+ 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.
+ */
+ if (wParam != 0) {
+ Shell shell = getModalShell ();
+ if (shell != null) shell.bringToTop ();
+ }
+ break;
+ case OS.WM_ENDSESSION:
+ if (wParam != 0) dispose ();
+ break;
+ case OS.WM_NULL:
+ runAsyncMessages ();
+ break;
+ case OS.WM_QUERYENDSESSION:
+ Event event = new Event ();
+ sendEvent (SWT.Close, event);
+ if (!event.doit) return 0;
+ break;
+ case OS.WM_SETTINGCHANGE:
+ updateFont ();
+ break;
+ case OS.WM_TIMER:
+ runTimer (wParam);
+ break;
+ }
+ return OS.DefWindowProc (hwnd, msg, wParam, lParam);
+}
+
+int msgFilterProc (int code, int wParam, int lParam) {
+ if (code >= 0) {
+ OS.MoveMemory (hookMsg, lParam, MSG.sizeof);
+ if (hookMsg.message == OS.WM_NULL) runAsyncMessages ();
+ }
+ return OS.CallNextHookEx (hHook, 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;
+}
+
+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>
+ * </ul>
+ *
+ * @see #sleep
+ * @see #wake
+ */
+public boolean readAndDispatch () {
+ checkDevice ();
+ drawMenuBars ();
+ runPopups ();
+ if (OS.PeekMessage (msg, 0, 0, 0, OS.PM_REMOVE)) {
+ if (!isWakeMessage (msg)) {
+ if (!filterMessage (msg)) {
+ OS.TranslateMessage (msg);
+ OS.DispatchMessage (msg);
+ }
+ runDeferredEvents ();
+ return true;
+ }
+ }
+ return runAsyncMessages ();
+}
+
+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 #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.getDisplay ()) shell.dispose ();
+ }
+ }
+ 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 () {
+
+ /* Unhook the message hook */
+ if (!OS.IsWinCE) {
+ if (hHook != 0) OS.UnhookWindowsHookEx (hHook);
+ hHook = 0;
+ msgFilterCallback.dispose ();
+ msgFilterCallback = null;
+ msgFilterProc = 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);
+ windowClass = null;
+ windowCallback.dispose ();
+ windowCallback = null;
+ windowProc = 0;
+
+ /* Release the system fonts */
+ if (systemFonts != null) {
+ for (int i=0; i<systemFonts.length; i++) {
+ if (systemFonts [i] != 0) OS.DeleteObject (systemFonts [i]);
+ }
+ }
+ systemFonts = null;
+
+ /* Release Custom Colors for ChooseColor */
+ if (lpCustColors != 0) OS.HeapFree (hHeap, 0, lpCustColors);
+ lpCustColors = 0;
+
+ /* Release references */
+ thread = null;
+ msg = null;
+ keyboard = null;
+ modalWidgets = null;
+ data = null;
+ keys = null;
+ values = 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 notifed when an event of the given type occurs anywhere in SWT.
+ *
+ * @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 #addFilter
+ * @see #addListener
+ *
+ * @since 2.1
+ */
+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 notifed when an event of the given type occurs.
+ *
+ * @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 #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;
+ }
+ }
+}
+
+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 () {
+ return synchronizer.runAsyncMessages ();
+}
+
+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;
+ menu._setVisible (true);
+ result = true;
+ }
+ popups = null;
+ return result;
+}
+
+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 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>
+ * </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
+ * </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>
+ * </ul>
+ *
+ * @see #setData
+ * @see #disposeExec
+ */
+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 - when called from the wrong thread</li>
+ * </ul>
+ *
+ * @see #getData
+ * @see #disposeExec
+ */
+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.
+ *
+ * @param name the new app name
+ */
+public static void setAppName (String name) {
+ /* Do nothing */
+}
+
+void setModalShell (Shell shell) {
+ if (modalWidgets == null) modalWidgets = new Shell [4];
+ int index = 0, length = modalWidgets.length;
+ while (index < length) {
+ if (modalWidgets [index] == shell) return;
+ if (modalWidgets [index] == null) break;
+ index++;
+ }
+ if (index == length) {
+ Shell [] newModalWidgets = new Shell [length + 4];
+ System.arraycopy (modalWidgets, 0, newModalWidgets, 0, length);
+ modalWidgets = newModalWidgets;
+ }
+ modalWidgets [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>
+ * </ul>
+ */
+public void setSynchronizer (Synchronizer synchronizer) {
+ checkDevice ();
+ if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (this.synchronizer != null) {
+ this.synchronizer.runAsyncMessages();
+ }
+ 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>
+ * </ul>
+ *
+ * @see #wake
+ */
+public boolean sleep () {
+ checkDevice ();
+ 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.
+ *
+ * @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
+ */
+public void syncExec (Runnable runnable) {
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+ synchronizer.syncExec (runnable);
+}
+
+int systemFont () {
+ int hFont = 0;
+ if (systemFonts != null) {
+ int length = systemFonts.length;
+ if (length != 0) hFont = systemFonts [length - 1];
+ }
+ if (hFont == 0) hFont = OS.GetStockObject (OS.DEFAULT_GUI_FONT);
+ if (hFont == 0) hFont = OS.GetStockObject (OS.SYSTEM_FONT);
+ return hFont;
+}
+
+/**
+ * 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.
+ *
+ * @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>
+ * </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++;
+ }
+ timerCount++;
+ timerId = timerCount;
+ 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.
+ *
+ * @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.getDisplay ()) {
+ shell.update (true);
+ }
+ }
+}
+
+void updateFont () {
+ if (OS.IsWinCE) return;
+ Font oldFont = getSystemFont ();
+ int systemFont = 0;
+ NONCLIENTMETRICS info = new NONCLIENTMETRICS ();
+ info.cbSize = NONCLIENTMETRICS.sizeof;
+ if (OS.SystemParametersInfo (OS.SPI_GETNONCLIENTMETRICS, 0, info, 0)) {
+ systemFont = OS.CreateFontIndirect (info.lfMessageFont);
+ }
+ if (systemFont == 0) systemFont = OS.GetStockObject (OS.DEFAULT_GUI_FONT);
+ if (systemFont == 0) systemFont = OS.GetStockObject (OS.SYSTEM_FONT);
+ if (systemFont == 0) return;
+ int length = systemFonts == null ? 0 : systemFonts.length;
+ int [] newFonts = new int [length + 1];
+ if (systemFonts != null) {
+ System.arraycopy (systemFonts, 0, newFonts, 0, length);
+ }
+ newFonts [length] = systemFont;
+ systemFonts = newFonts;
+ Font newFont = getSystemFont ();
+ Shell [] shells = getShells ();
+ for (int i=0; i<shells.length; i++) {
+ Shell shell = shells [i];
+ if (!shell.isDisposed ()) {
+ shell.updateFont (oldFont, newFont);
+ }
+ }
+}
+
+/**
+ * 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.
+ *
+ * @see #sleep
+ */
+public void wake () {
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+ if (thread == Thread.currentThread ()) return;
+ if (OS.IsWinCE) {
+ OS.PostMessage (hwndMessage, OS.WM_NULL, 0, 0);
+ } else {
+ OS.PostThreadMessage (threadId, OS.WM_NULL, 0, 0);
+ }
+}
+
+int windowProc (int hwnd, int msg, int wParam, int lParam) {
+ Control control = WidgetTable.get (hwnd);
+ if (control != null) {
+ return control.windowProc (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");
+ i++;
+ }
+ }
+ return result.toString ();
+}
+
+}
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
index 1a299ff7ca..9cb6dfa5d5 100755
--- 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
@@ -1,411 +1,411 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- * 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 * 10;
-
-/**
- * Constructs a new instance of this class given only its
- * parent.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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
- *
- * @return the relative path of the file
- */
-public String getFileName () {
- return fileName;
-}
-
-/**
- * Returns the paths of all files that were selected
- * in the dialog relative to the filter path, or null
- * if none are available.
- *
- * @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 file names which the dialog will
- * use to filter the files it shows.
- *
- * @return the file name filter
- */
-public String [] getFilterNames () {
- return filterNames;
-}
-
-/**
- * Returns the directory path that the dialog will use.
- * 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.
- * Note that the longest that a single path name can
- * be on Windows is 256.
- */
- int nMaxFile = 256;
- 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 lpstrInitialDir = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- int byteCountDir = Math.min (path.length () * TCHAR.sizeof, byteCount - 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;
-
- /*
- * Feature in Windows. The focus window is not saved and
- * and restored automatically by the call to GetOpenFileName ().
- * The fix is to save and restore the focus window.
- */
- int hwndFocus = OS.GetFocus ();
-
- /*
- * Bug/Feature in Windows. When Windows opens the standard
- * file dialog, it changes the cursor to the hourglass and
- * does not put it back. The fix is to save the current
- * cursor and restore it when the dialog closes.
- */
- int hCursor = OS.GetCursor ();
-
- /*
- * Open the dialog. If the open fails due to an invalid
- * file name, use an empty file name and open it again.
- */
- boolean save = (style & SWT.SAVE) != 0;
- 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);
- }
-
- /* Set the new path, file name and filter */
- fileNames = null;
- 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);
-
- /* Restore the old cursor */
- OS.SetCursor (hCursor);
-
- /* Restore the old focus */
- OS.SetFocus (hwndFocus);
-
- /*
- * 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.
- *
- * @param extensions the file extension filter
- */
-public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-
-/**
- * Sets the file names which the dialog will
- * use to filter the files it shows to the argument,
- * which may be null.
- *
- * @param names the file name filter
- */
-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.
- *
- * @param string the directory path
- *
- * @see #setFilterExtensions
- */
-public void setFilterPath (String string) {
- filterPath = string;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>
+ * 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 * 10;
+
+/**
+ * Constructs a new instance of this class given only its
+ * parent.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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
+ *
+ * @return the relative path of the file
+ */
+public String getFileName () {
+ return fileName;
+}
+
+/**
+ * Returns the paths of all files that were selected
+ * in the dialog relative to the filter path, or null
+ * if none are available.
+ *
+ * @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 file names which the dialog will
+ * use to filter the files it shows.
+ *
+ * @return the file name filter
+ */
+public String [] getFilterNames () {
+ return filterNames;
+}
+
+/**
+ * Returns the directory path that the dialog will use.
+ * 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.
+ * Note that the longest that a single path name can
+ * be on Windows is 256.
+ */
+ int nMaxFile = 256;
+ 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 lpstrInitialDir = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
+ int byteCountDir = Math.min (path.length () * TCHAR.sizeof, byteCount - 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;
+
+ /*
+ * Feature in Windows. The focus window is not saved and
+ * and restored automatically by the call to GetOpenFileName ().
+ * The fix is to save and restore the focus window.
+ */
+ int hwndFocus = OS.GetFocus ();
+
+ /*
+ * Bug/Feature in Windows. When Windows opens the standard
+ * file dialog, it changes the cursor to the hourglass and
+ * does not put it back. The fix is to save the current
+ * cursor and restore it when the dialog closes.
+ */
+ int hCursor = OS.GetCursor ();
+
+ /*
+ * Open the dialog. If the open fails due to an invalid
+ * file name, use an empty file name and open it again.
+ */
+ boolean save = (style & SWT.SAVE) != 0;
+ 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);
+ }
+
+ /* Set the new path, file name and filter */
+ fileNames = null;
+ 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);
+
+ /* Restore the old cursor */
+ OS.SetCursor (hCursor);
+
+ /* Restore the old focus */
+ OS.SetFocus (hwndFocus);
+
+ /*
+ * 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.
+ *
+ * @param extensions the file extension filter
+ */
+public void setFilterExtensions (String [] extensions) {
+ filterExtensions = extensions;
+}
+
+/**
+ * Sets the file names which the dialog will
+ * use to filter the files it shows to the argument,
+ * which may be null.
+ *
+ * @param names the file name filter
+ */
+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.
+ *
+ * @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
index 494dc309ee..229cb2442e 100755
--- 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
@@ -1,237 +1,237 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.
- * <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.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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
- */
-public FontData getFontData() {
- return fontData;
-}
-
-/**
- * Returns the currently selected color in the receiver.
- *
- * @return the RGB value for the selected color, may be 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;
- }
- boolean success = OS.ChooseFont (lpcf);
- if (success) {
- LOGFONT logFont = new LOGFONT ();
- 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 = new TEXTMETRIC();
- 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
- */
-public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-
-/**
- * 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 to select a default when
- * open() is called
- *
- * @see PaletteData#getRGBs
- *
- * @since 2.1
- */
-public void setRGB (RGB rgb) {
- this.rgb = rgb;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
+ * <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.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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
+ */
+public FontData getFontData() {
+ return fontData;
+}
+
+/**
+ * Returns the currently selected color in the receiver.
+ *
+ * @return the RGB value for the selected color, may be 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;
+ }
+ boolean success = OS.ChooseFont (lpcf);
+ if (success) {
+ LOGFONT logFont = new LOGFONT ();
+ 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 = new TEXTMETRIC();
+ 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
+ */
+public void setFontData (FontData fontData) {
+ this.fontData = fontData;
+}
+
+/**
+ * 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 to 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
index a82ca8070c..89c1e85d23 100755
--- 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
@@ -1,373 +1,373 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 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 exposed
- * area.
- *
- * 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 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 (handle, msg, wParam, lParam);
- }
- return OS.CallWindowProc (GroupProc, handle, 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;
- 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 length = OS.GetWindowTextLength (handle);
- TCHAR buffer1 = new TCHAR (getCodePage (), length + 1);
- OS.GetWindowText (handle, buffer1, length + 1);
- 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);
- Point size;
- if (layout != null) {
- size = layout.computeSize (this, wHint, hHint, changed);
- } else {
- size = minimumSize ();
- }
- width = size.x; 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, rect.right - rect.left + 6);
- 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 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 = new TEXTMETRIC ();
- OS.GetTextMetrics (hDC, tm);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- int inset = 3;
- trim.x -= inset; trim.y -= tm.tmHeight;
- trim.width += (inset * 2); trim.height += tm.tmHeight + inset;
- return trim;
-}
-
-void createHandle () {
- super.createHandle ();
- 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 = new TEXTMETRIC ();
- OS.GetTextMetrics (hDC, tm);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- int inset = 3, x = inset, y = tm.tmHeight;
- return new Rectangle (x, y, rect.right - (inset * 2), rect.bottom - y - inset);
-}
-
-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);
-}
-
-/**
- * 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 assgned
- * 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 text the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 (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 (COMCTL32_MAJOR >= 6) {
- int hFont = OS.GetCurrentObject (wParam, OS.OBJ_FONT);
- int code = callWindowProc (OS.WM_PRINTCLIENT, wParam, lParam);
- OS.SelectObject (wParam, hFont);
- 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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 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 exposed
+ * area.
+ *
+ * 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 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 (handle, msg, wParam, lParam);
+ }
+ return OS.CallWindowProc (GroupProc, handle, 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;
+ 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 length = OS.GetWindowTextLength (handle);
+ TCHAR buffer1 = new TCHAR (getCodePage (), length + 1);
+ OS.GetWindowText (handle, buffer1, length + 1);
+ 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);
+ Point size;
+ if (layout != null) {
+ size = layout.computeSize (this, wHint, hHint, changed);
+ } else {
+ size = minimumSize ();
+ }
+ width = size.x; 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, rect.right - rect.left + 6);
+ 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 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 = new TEXTMETRIC ();
+ OS.GetTextMetrics (hDC, tm);
+ if (newFont != 0) OS.SelectObject (hDC, oldFont);
+ OS.ReleaseDC (handle, hDC);
+ int inset = 3;
+ trim.x -= inset; trim.y -= tm.tmHeight;
+ trim.width += (inset * 2); trim.height += tm.tmHeight + inset;
+ return trim;
+}
+
+void createHandle () {
+ super.createHandle ();
+ 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 = new TEXTMETRIC ();
+ OS.GetTextMetrics (hDC, tm);
+ if (newFont != 0) OS.SelectObject (hDC, oldFont);
+ OS.ReleaseDC (handle, hDC);
+ int inset = 3, x = inset, y = tm.tmHeight;
+ return new Rectangle (x, y, rect.right - (inset * 2), rect.bottom - y - inset);
+}
+
+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);
+}
+
+/**
+ * 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 assgned
+ * 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 text the new text
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 (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 (COMCTL32_MAJOR >= 6) {
+ int hFont = OS.GetCurrentObject (wParam, OS.OBJ_FONT);
+ int code = callWindowProc (OS.WM_PRINTCLIENT, wParam, lParam);
+ OS.SelectObject (wParam, hFont);
+ 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;
+}
+
+}
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
index e5c1275f7d..1cac1c7058 100755
--- 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
@@ -1,254 +1,254 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-class ImageList {
- int handle, refCount;
- Image [] images;
- static final int CREATE_FLAGS;
- static {
- if (OS.IsWinCE) {
- CREATE_FLAGS = OS.ILC_MASK | OS.ILC_COLOR;
- } else {
- int flags = OS.ILC_MASK;
- 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;
- }
- CREATE_FLAGS = flags;
- }
- }
-
-public ImageList () {
- handle = OS.ImageList_Create (32, 32, CREATE_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++;
- }
- int [] cx = new int [1], cy = new int [1];
- if (count == 0) {
- Rectangle rect = image.getBounds();
- cx [0] = rect.width;
- cy [0] = rect.height;
- OS.ImageList_SetIconSize (handle, cx [0], cy [0]);
- }
- int hImage = image.handle;
- OS.ImageList_GetIconSize (handle, cx, cy);
- switch (image.type) {
- case SWT.BITMAP: {
- int hBitmap = copyBitmap (hImage, cx [0], cy [0]);
- int background = -1;
- Color color = image.getBackground ();
- if (color != null) background = color.handle;
- if (index == count) {
- if (background != -1) {
- OS.ImageList_AddMasked (handle, hBitmap, background);
- } else {
- int hMask = createMask (hBitmap, cx [0], cy [0], background);
- OS.ImageList_Add (handle, hBitmap, hMask);
- OS.DeleteObject (hMask);
- }
- } else {
- int hMask = createMask (hBitmap, cx [0], cy [0], background);
- OS.ImageList_Replace (handle, index, hBitmap, hMask);
- OS.DeleteObject (hMask);
- }
- 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;
- }
- }
- 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);
- int hBitmap = OS.CreateCompatibleBitmap (hDC, width, height);
- OS.SelectObject (hdc2, hBitmap);
- if (!OS.IsWinCE) OS.SetStretchBltMode(hdc2, OS.COLORONCOLOR);
- OS.StretchBlt (hdc2, 0, 0, width, height, hdc1, 0, 0, bm.bmWidth, bm.bmHeight, 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, OS.LR_DEFAULTCOLOR);
- return hIcon != 0 ? hIcon : hImage;
-}
-
-int createMask (int hBitmap, int width, int height, int background) {
- int hMask = OS.CreateBitmap (width, height, 1, 1, null);
- int hDC = OS.GetDC (0);
- int hdc1 = OS.CreateCompatibleDC (hDC);
- if (background != -1) {
- OS.SelectObject (hdc1, hBitmap);
- int hdc2 = OS.CreateCompatibleDC (hDC);
- OS.SelectObject (hdc2, hMask);
- OS.SetBkColor (hdc1, background);
- OS.BitBlt (hdc2, 0, 0, width, height, hdc1, 0, 0, OS.SRCCOPY);
- OS.DeleteDC (hdc2);
- } else {
- int hOldBitmap = OS.SelectObject (hdc1, hMask);
- OS.PatBlt (hdc1, 0, 0, width, height, 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 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) {
- int [] cx = new int [1], cy = new int [1];
- OS.ImageList_GetIconSize (handle, cx, cy);
- int hImage = image.handle;
- switch (image.type) {
- case SWT.BITMAP: {
- int background = -1;
- Color color = image.getBackground ();
- if (color != null) background = color.handle;
- int hBitmap = copyBitmap (hImage, cx [0], cy [0]);
- int hMask = createMask (hBitmap, cx [0], cy [0], background);
- OS.ImageList_Replace (handle, index, hBitmap, hMask);
- OS.DeleteObject (hBitmap);
- OS.DeleteObject (hMask);
- break;
- }
- case SWT.ICON: {
- if (OS.IsWinCE) {
- OS.ImageList_ReplaceIcon (handle, index, hImage);
- } else {
- int hIcon = copyIcon (hImage, cx [0], cy [0]);
- OS.ImageList_ReplaceIcon (handle, index, hIcon);
- OS.DestroyIcon (hIcon);
- }
- break;
- }
- }
- }
- 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;
-}
-
-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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.win32.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+class ImageList {
+ int handle, refCount;
+ Image [] images;
+ static final int CREATE_FLAGS;
+ static {
+ if (OS.IsWinCE) {
+ CREATE_FLAGS = OS.ILC_MASK | OS.ILC_COLOR;
+ } else {
+ int flags = OS.ILC_MASK;
+ 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;
+ }
+ CREATE_FLAGS = flags;
+ }
+ }
+
+public ImageList () {
+ handle = OS.ImageList_Create (32, 32, CREATE_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++;
+ }
+ int [] cx = new int [1], cy = new int [1];
+ if (count == 0) {
+ Rectangle rect = image.getBounds();
+ cx [0] = rect.width;
+ cy [0] = rect.height;
+ OS.ImageList_SetIconSize (handle, cx [0], cy [0]);
+ }
+ int hImage = image.handle;
+ OS.ImageList_GetIconSize (handle, cx, cy);
+ switch (image.type) {
+ case SWT.BITMAP: {
+ int hBitmap = copyBitmap (hImage, cx [0], cy [0]);
+ int background = -1;
+ Color color = image.getBackground ();
+ if (color != null) background = color.handle;
+ if (index == count) {
+ if (background != -1) {
+ OS.ImageList_AddMasked (handle, hBitmap, background);
+ } else {
+ int hMask = createMask (hBitmap, cx [0], cy [0], background);
+ OS.ImageList_Add (handle, hBitmap, hMask);
+ OS.DeleteObject (hMask);
+ }
+ } else {
+ int hMask = createMask (hBitmap, cx [0], cy [0], background);
+ OS.ImageList_Replace (handle, index, hBitmap, hMask);
+ OS.DeleteObject (hMask);
+ }
+ 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;
+ }
+ }
+ 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);
+ int hBitmap = OS.CreateCompatibleBitmap (hDC, width, height);
+ OS.SelectObject (hdc2, hBitmap);
+ if (!OS.IsWinCE) OS.SetStretchBltMode(hdc2, OS.COLORONCOLOR);
+ OS.StretchBlt (hdc2, 0, 0, width, height, hdc1, 0, 0, bm.bmWidth, bm.bmHeight, 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, OS.LR_DEFAULTCOLOR);
+ return hIcon != 0 ? hIcon : hImage;
+}
+
+int createMask (int hBitmap, int width, int height, int background) {
+ int hMask = OS.CreateBitmap (width, height, 1, 1, null);
+ int hDC = OS.GetDC (0);
+ int hdc1 = OS.CreateCompatibleDC (hDC);
+ if (background != -1) {
+ OS.SelectObject (hdc1, hBitmap);
+ int hdc2 = OS.CreateCompatibleDC (hDC);
+ OS.SelectObject (hdc2, hMask);
+ OS.SetBkColor (hdc1, background);
+ OS.BitBlt (hdc2, 0, 0, width, height, hdc1, 0, 0, OS.SRCCOPY);
+ OS.DeleteDC (hdc2);
+ } else {
+ int hOldBitmap = OS.SelectObject (hdc1, hMask);
+ OS.PatBlt (hdc1, 0, 0, width, height, 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 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) {
+ int [] cx = new int [1], cy = new int [1];
+ OS.ImageList_GetIconSize (handle, cx, cy);
+ int hImage = image.handle;
+ switch (image.type) {
+ case SWT.BITMAP: {
+ int background = -1;
+ Color color = image.getBackground ();
+ if (color != null) background = color.handle;
+ int hBitmap = copyBitmap (hImage, cx [0], cy [0]);
+ int hMask = createMask (hBitmap, cx [0], cy [0], background);
+ OS.ImageList_Replace (handle, index, hBitmap, hMask);
+ OS.DeleteObject (hBitmap);
+ OS.DeleteObject (hMask);
+ break;
+ }
+ case SWT.ICON: {
+ if (OS.IsWinCE) {
+ OS.ImageList_ReplaceIcon (handle, index, hImage);
+ } else {
+ int hIcon = copyIcon (hImage, cx [0], cy [0]);
+ OS.ImageList_ReplaceIcon (handle, index, hIcon);
+ OS.DestroyIcon (hIcon);
+ }
+ break;
+ }
+ }
+ }
+ 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;
+}
+
+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
index e8efcd2b0d..8be690c27c 100755
--- 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
@@ -1,583 +1,583 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 {
- Image image;
- int font;
- 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 msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (LabelProc, handle, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- if ((style & SWT.SEPARATOR) != 0) return style;
- 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;
- int 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);
- }
- /*
- * NOTE: SS_BITMAP and SS_ICON are not single bit
- * masks so it is necessary to test for all of the
- * bits in these masks.
- */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- boolean isBitmap = (bits & OS.SS_BITMAP) == OS.SS_BITMAP;
- boolean isIcon = (bits & OS.SS_ICON) == OS.SS_ICON;
- if (isBitmap || isIcon) {
- if (image != null) {
- Rectangle rect = image.getBounds();
- width = rect.width;
- height = rect.height;
- }
- } else {
- int hDC = OS.GetDC (handle);
- int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- int oldFont = OS.SelectObject (hDC, newFont);
- 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 = wHint;
- }
- int length = OS.GetWindowTextLength (handle);
- 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 = rect.bottom - rect.top;
- if (height == 0) {
- TEXTMETRIC tm = new TEXTMETRIC ();
- OS.GetTextMetrics (hDC, tm);
- height = tm.tmHeight;
- }
- 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 size.
- */
- if (OS.IsWinCE) {
- if (!isBitmap && !isIcon) width += 2;
- }
- return new Point (width, height);
-}
-
-/**
- * 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 "";
- 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);
-}
-
-/*
-* Not currently used.
-*/
-boolean getWrap () {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & (OS.SS_RIGHT | OS.SS_CENTER)) != 0) return true;
- if ((bits & OS.SS_LEFTNOWORDWRAP) != 0) return false;
- return 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 releaseWidget () {
- super.releaseWidget ();
- 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);
- /*
- * Feature in Windows. The windows label does not align
- * the bitmap or icon. Any attempt to set alignment bits
- * such as SS_CENTER cause the label to display text. The
- * fix is to disallow alignment.
- *
- * NOTE: SS_BITMAP and SS_ICON are not single bit
- * masks so it is necessary to test for all of the
- * bits in these masks.
- */
- if ((bits & OS.SS_BITMAP) == OS.SS_BITMAP) return;
- if ((bits & OS.SS_ICON) == OS.SS_ICON) return;
- bits &= ~(OS.SS_LEFTNOWORDWRAP | OS.SS_CENTER | OS.SS_RIGHT);
- if ((style & SWT.LEFT) != 0 && (style & SWT.WRAP) == 0) {
- 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);
-}
-
-public boolean setFocus () {
- checkWidget();
- return false;
-}
-
-/**
- * Sets the receiver's image to the argument, which may be
- * null indicating that no image should be displayed.
- *
- * @param image the image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image image) {
- checkWidget ();
- if ((style & SWT.SEPARATOR) != 0) return;
- int hImage = 0, imageBits = 0, fImageType = 0;
- if (image != null) {
- if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- hImage = image.handle;
- switch (image.type) {
- case SWT.BITMAP:
- imageBits = OS.SS_BITMAP;
- fImageType = OS.IMAGE_BITMAP;
- break;
- case SWT.ICON:
- imageBits = OS.SS_ICON;
- fImageType = OS.IMAGE_ICON;
- break;
- default:
- return;
- }
- }
- this.image = image;
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- int oldBits = newBits;
- newBits &= ~(OS.SS_BITMAP | OS.SS_ICON);
- newBits |= imageBits | OS.SS_REALSIZEIMAGE | OS.SS_CENTERIMAGE;
- if (newBits != oldBits) {
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- }
- OS.SendMessage (handle, OS.STM_SETIMAGE, fImageType, hImage);
- /*
- * Feature in Windows. When STM_SETIMAGE is used to set the
- * image for a static control, Windows either streches the image
- * to fit the control or shrinks the control to fit the image.
- * While not stricly wrong, neither of these is desirable.
- * The fix is to stop Windows from stretching the image by
- * using SS_REALSIZEIMAGE and SS_CENTERIMAGE, allow Windows
- * to shrink the control, and then restore the control to the
- * original size.
- */
- int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE | OS.SWP_NOMOVE;
- OS.SetWindowPos (handle, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, flags);
- 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;
- int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE), oldBits = newBits;
- newBits &= ~(OS.SS_BITMAP | OS.SS_ICON | OS.SS_REALSIZEIMAGE | OS.SS_CENTERIMAGE);
- if ((style & SWT.LEFT) != 0 && (style & SWT.WRAP) == 0) newBits |= OS.SS_LEFTNOWORDWRAP;
- if ((style & SWT.CENTER) != 0) newBits |= OS.SS_CENTER;
- if ((style & SWT.RIGHT) != 0) newBits |= OS.SS_RIGHT;
- if (newBits != oldBits) {
- /*
- * Bug in Windows. When the style of a label is SS_BITMAP
- * or SS_ICON, the label does not remember the font that is
- * set in WM_SETFONT. The fix is to remember the font and
- * return the font in WM_GETFONT and to reset the font when
- * the style is changed from SS_BITMAP or SS_ICON to a style
- * that displays text.
- */
- int hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- if (hFont != 0) OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
- }
- string = Display.withCrLf (string);
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SetWindowText (handle, buffer);
-}
-
-/*
-* Not currently used.
-*/
-void setWrap (boolean wrap) {
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & (OS.SS_RIGHT | OS.SS_CENTER)) != 0) return;
- bits &= ~OS.SS_LEFTNOWORDWRAP;
- if (!wrap) bits |= OS.SS_LEFTNOWORDWRAP;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- 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 ((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;
- if ((style & SWT.SEPARATOR) != 0) return LRESULT.ONE;
- /*
- * Bug in Windows. When a label has the SS_BITMAP
- * or SS_ICON style, the label does not draw the
- * background. The fix is to draw the background
- * when the label is showing a bitmap or icon.
- *
- * NOTE: SS_BITMAP and SS_ICON are not single bit
- * masks so it is necessary to test for all of the
- * bits in these masks.
- */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- boolean isBitmap = (bits & OS.SS_BITMAP) == OS.SS_BITMAP;
- boolean isIcon = (bits & OS.SS_ICON) == OS.SS_ICON;
- if (isBitmap || isIcon) {
- drawBackground (wParam);
- return LRESULT.ONE;
- }
- return result;
-}
-
-LRESULT WM_GETFONT (int wParam, int lParam) {
- LRESULT result = super.WM_GETFONT (wParam, lParam);
- if (result != null) return result;
- /*
- * Bug in Windows. When the style of a label is SS_BITMAP
- * or SS_ICON, the label does not remember the font that is
- * set in WM_SETFONT. The fix is to remember the font and
- * return the font in WM_GETFONT.
- */
- if (font == 0) font = defaultFont ();
- return new LRESULT (font);
-}
-
-LRESULT WM_SETFONT (int wParam, int lParam) {
- /*
- * Bug in Windows. When the style of a label is SS_BITMAP
- * or SS_ICON, the label does not remember the font that is
- * set in WM_SETFONT. The fix is to remember the font and
- * return the font in WM_GETFONT.
- */
- return super.WM_SETFONT (font = wParam, lParam);
-}
-
-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;
- if ((style & SWT.SEPARATOR) != 0) {
- OS.InvalidateRect (handle, null, true);
- return result;
- }
-
- /*
- * Bug in Windows. For some reason, a label with
- * SS_BITMAP or SS_ICON and SS_CENTER does not redraw
- * properly when resized. Only the new area is drawn
- * and the old area is not cleared. The fix is to
- * force the redraw.
- *
- * NOTE: SS_BITMAP and SS_ICON are not single bit
- * masks so it is necessary to test for all of the
- * bits in these masks.
- */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- boolean isBitmap = (bits & OS.SS_BITMAP) == OS.SS_BITMAP;
- boolean isIcon = (bits & OS.SS_ICON) == OS.SS_ICON;
- if (isBitmap || isIcon) {
- 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 ((style & (SWT.WRAP | SWT.CENTER | SWT.RIGHT)) != 0) {
- OS.InvalidateRect (handle, null, true);
- return result;
- }
-
- return result;
-}
-
-LRESULT wmDrawChild (int wParam, int lParam) {
- DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT ();
- OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof);
- drawBackground (struct.hDC);
- if ((style & SWT.SHADOW_NONE) != 0) return null;
- RECT rect = new RECT ();
- int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER);
- int flags = OS.EDGE_ETCHED;
- if ((style & SWT.SHADOW_IN) != 0) flags = OS.EDGE_SUNKEN;
- 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);
- }
- return null;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 {
+ Image image;
+ int font;
+ 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 msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (LabelProc, handle, msg, wParam, lParam);
+}
+
+static int checkStyle (int style) {
+ if ((style & SWT.SEPARATOR) != 0) return style;
+ 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;
+ int 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);
+ }
+ /*
+ * NOTE: SS_BITMAP and SS_ICON are not single bit
+ * masks so it is necessary to test for all of the
+ * bits in these masks.
+ */
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ boolean isBitmap = (bits & OS.SS_BITMAP) == OS.SS_BITMAP;
+ boolean isIcon = (bits & OS.SS_ICON) == OS.SS_ICON;
+ if (isBitmap || isIcon) {
+ if (image != null) {
+ Rectangle rect = image.getBounds();
+ width = rect.width;
+ height = rect.height;
+ }
+ } else {
+ int hDC = OS.GetDC (handle);
+ int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
+ int oldFont = OS.SelectObject (hDC, newFont);
+ 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 = wHint;
+ }
+ int length = OS.GetWindowTextLength (handle);
+ 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 = rect.bottom - rect.top;
+ if (height == 0) {
+ TEXTMETRIC tm = new TEXTMETRIC ();
+ OS.GetTextMetrics (hDC, tm);
+ height = tm.tmHeight;
+ }
+ 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 size.
+ */
+ if (OS.IsWinCE) {
+ if (!isBitmap && !isIcon) width += 2;
+ }
+ return new Point (width, height);
+}
+
+/**
+ * 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 "";
+ 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);
+}
+
+/*
+* Not currently used.
+*/
+boolean getWrap () {
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & (OS.SS_RIGHT | OS.SS_CENTER)) != 0) return true;
+ if ((bits & OS.SS_LEFTNOWORDWRAP) != 0) return false;
+ return 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 releaseWidget () {
+ super.releaseWidget ();
+ 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);
+ /*
+ * Feature in Windows. The windows label does not align
+ * the bitmap or icon. Any attempt to set alignment bits
+ * such as SS_CENTER cause the label to display text. The
+ * fix is to disallow alignment.
+ *
+ * NOTE: SS_BITMAP and SS_ICON are not single bit
+ * masks so it is necessary to test for all of the
+ * bits in these masks.
+ */
+ if ((bits & OS.SS_BITMAP) == OS.SS_BITMAP) return;
+ if ((bits & OS.SS_ICON) == OS.SS_ICON) return;
+ bits &= ~(OS.SS_LEFTNOWORDWRAP | OS.SS_CENTER | OS.SS_RIGHT);
+ if ((style & SWT.LEFT) != 0 && (style & SWT.WRAP) == 0) {
+ 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);
+}
+
+public boolean setFocus () {
+ checkWidget();
+ return false;
+}
+
+/**
+ * Sets the receiver's image to the argument, which may be
+ * null indicating that no image should be displayed.
+ *
+ * @param image the image to display on the receiver (may be null)
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setImage (Image image) {
+ checkWidget ();
+ if ((style & SWT.SEPARATOR) != 0) return;
+ int hImage = 0, imageBits = 0, fImageType = 0;
+ if (image != null) {
+ if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ hImage = image.handle;
+ switch (image.type) {
+ case SWT.BITMAP:
+ imageBits = OS.SS_BITMAP;
+ fImageType = OS.IMAGE_BITMAP;
+ break;
+ case SWT.ICON:
+ imageBits = OS.SS_ICON;
+ fImageType = OS.IMAGE_ICON;
+ break;
+ default:
+ return;
+ }
+ }
+ this.image = image;
+ RECT rect = new RECT ();
+ OS.GetWindowRect (handle, rect);
+ int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ int oldBits = newBits;
+ newBits &= ~(OS.SS_BITMAP | OS.SS_ICON);
+ newBits |= imageBits | OS.SS_REALSIZEIMAGE | OS.SS_CENTERIMAGE;
+ if (newBits != oldBits) {
+ OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
+ }
+ OS.SendMessage (handle, OS.STM_SETIMAGE, fImageType, hImage);
+ /*
+ * Feature in Windows. When STM_SETIMAGE is used to set the
+ * image for a static control, Windows either streches the image
+ * to fit the control or shrinks the control to fit the image.
+ * While not stricly wrong, neither of these is desirable.
+ * The fix is to stop Windows from stretching the image by
+ * using SS_REALSIZEIMAGE and SS_CENTERIMAGE, allow Windows
+ * to shrink the control, and then restore the control to the
+ * original size.
+ */
+ int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE | OS.SWP_NOMOVE;
+ OS.SetWindowPos (handle, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, flags);
+ 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;
+ int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE), oldBits = newBits;
+ newBits &= ~(OS.SS_BITMAP | OS.SS_ICON | OS.SS_REALSIZEIMAGE | OS.SS_CENTERIMAGE);
+ if ((style & SWT.LEFT) != 0 && (style & SWT.WRAP) == 0) newBits |= OS.SS_LEFTNOWORDWRAP;
+ if ((style & SWT.CENTER) != 0) newBits |= OS.SS_CENTER;
+ if ((style & SWT.RIGHT) != 0) newBits |= OS.SS_RIGHT;
+ if (newBits != oldBits) {
+ /*
+ * Bug in Windows. When the style of a label is SS_BITMAP
+ * or SS_ICON, the label does not remember the font that is
+ * set in WM_SETFONT. The fix is to remember the font and
+ * return the font in WM_GETFONT and to reset the font when
+ * the style is changed from SS_BITMAP or SS_ICON to a style
+ * that displays text.
+ */
+ int hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
+ OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
+ if (hFont != 0) OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
+ }
+ string = Display.withCrLf (string);
+ TCHAR buffer = new TCHAR (getCodePage (), string, true);
+ OS.SetWindowText (handle, buffer);
+}
+
+/*
+* Not currently used.
+*/
+void setWrap (boolean wrap) {
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & (OS.SS_RIGHT | OS.SS_CENTER)) != 0) return;
+ bits &= ~OS.SS_LEFTNOWORDWRAP;
+ if (!wrap) bits |= OS.SS_LEFTNOWORDWRAP;
+ OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
+ 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 ((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;
+ if ((style & SWT.SEPARATOR) != 0) return LRESULT.ONE;
+ /*
+ * Bug in Windows. When a label has the SS_BITMAP
+ * or SS_ICON style, the label does not draw the
+ * background. The fix is to draw the background
+ * when the label is showing a bitmap or icon.
+ *
+ * NOTE: SS_BITMAP and SS_ICON are not single bit
+ * masks so it is necessary to test for all of the
+ * bits in these masks.
+ */
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ boolean isBitmap = (bits & OS.SS_BITMAP) == OS.SS_BITMAP;
+ boolean isIcon = (bits & OS.SS_ICON) == OS.SS_ICON;
+ if (isBitmap || isIcon) {
+ drawBackground (wParam);
+ return LRESULT.ONE;
+ }
+ return result;
+}
+
+LRESULT WM_GETFONT (int wParam, int lParam) {
+ LRESULT result = super.WM_GETFONT (wParam, lParam);
+ if (result != null) return result;
+ /*
+ * Bug in Windows. When the style of a label is SS_BITMAP
+ * or SS_ICON, the label does not remember the font that is
+ * set in WM_SETFONT. The fix is to remember the font and
+ * return the font in WM_GETFONT.
+ */
+ if (font == 0) font = defaultFont ();
+ return new LRESULT (font);
+}
+
+LRESULT WM_SETFONT (int wParam, int lParam) {
+ /*
+ * Bug in Windows. When the style of a label is SS_BITMAP
+ * or SS_ICON, the label does not remember the font that is
+ * set in WM_SETFONT. The fix is to remember the font and
+ * return the font in WM_GETFONT.
+ */
+ return super.WM_SETFONT (font = wParam, lParam);
+}
+
+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;
+ if ((style & SWT.SEPARATOR) != 0) {
+ OS.InvalidateRect (handle, null, true);
+ return result;
+ }
+
+ /*
+ * Bug in Windows. For some reason, a label with
+ * SS_BITMAP or SS_ICON and SS_CENTER does not redraw
+ * properly when resized. Only the new area is drawn
+ * and the old area is not cleared. The fix is to
+ * force the redraw.
+ *
+ * NOTE: SS_BITMAP and SS_ICON are not single bit
+ * masks so it is necessary to test for all of the
+ * bits in these masks.
+ */
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ boolean isBitmap = (bits & OS.SS_BITMAP) == OS.SS_BITMAP;
+ boolean isIcon = (bits & OS.SS_ICON) == OS.SS_ICON;
+ if (isBitmap || isIcon) {
+ 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 ((style & (SWT.WRAP | SWT.CENTER | SWT.RIGHT)) != 0) {
+ OS.InvalidateRect (handle, null, true);
+ return result;
+ }
+
+ return result;
+}
+
+LRESULT wmDrawChild (int wParam, int lParam) {
+ DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT ();
+ OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof);
+ drawBackground (struct.hDC);
+ if ((style & SWT.SHADOW_NONE) != 0) return null;
+ RECT rect = new RECT ();
+ int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER);
+ int flags = OS.EDGE_ETCHED;
+ if ((style & SWT.SHADOW_IN) != 0) flags = OS.EDGE_SUNKEN;
+ 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);
+ }
+ return null;
+}
+
+}
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
index 7414305ee5..77b53091d6 100755
--- 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
@@ -1,1540 +1,1540 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 notificiation
- * when a string 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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 msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (ListProc, handle, 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 count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- int itemHeight = OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0);
- int width = 0, height = count * itemHeight;
- if ((style & SWT.H_SCROLL) != 0) {
- width = OS.SendMessage (handle, OS.LB_GETHORIZONTALEXTENT, 0, 0);
- } else {
- 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 (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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 is currently
- * has the focus in the receiver, or -1 if no item is 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.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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);
- } else {
- 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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 an 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</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. 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure while getting the selection</li>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</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 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</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
- * @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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- 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 || i == 0) {
- 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) {
- int index = newIndices [i];
- if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- error (SWT.ERROR_INVALID_RANGE);
- }
-}
-
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</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) error (SWT.ERROR_ITEM_NOT_REMOVED);
- buffer = new TCHAR (getCodePage (), length + 1);
- int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer);
- if (result == OS.LB_ERR) error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget ();
- if (start > end) return;
- int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- 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) {
- if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
- error (SWT.ERROR_INVALID_RANGE);
- }
-}
-
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove (String string) {
- checkWidget ();
- 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.
- * If the item at the given zero-relative index in the receiver
- * is not selected, it is selected. If the item at the index
- * was selected, it remains selected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- 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);
- if ((style & SWT.SINGLE) != 0) {
- int count = getItemCount ();
- if (0 <= index && index < count) {
- break;
- }
- }
- }
- 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 == -1) return;
- if (scroll) {
- if ((style & SWT.SINGLE) != 0) {
- OS.SendMessage (handle, OS.LB_SETCURSEL, index, 0);
- } else {
- int focusIndex = OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
- OS.SendMessage (handle, OS.LB_SETSEL, 1, index);
- if (focusIndex != -1) {
- OS.SendMessage (handle, OS.LB_SETCARETINDEX, index, 0);
- }
- }
- 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, index, 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 at the given zero-relative indices in the receiver.
- * If the item at the index was already selected, it remains
- * selected. The range of the indices is inclusive. Indices that are
- * out of range are ignored and no items will be selected if start is
- * greater than end.
- *
- * @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 select (int start, int end) {
- checkWidget ();
- select (start, end, false);
-}
-
-void select (int start, int end, boolean scroll) {
- if (start > end) return;
- if ((style & SWT.SINGLE) != 0) {
- int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
- int index = Math.min (count - 1, end);
- if (index >= start) select (index, scroll);
- 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));
- if (start == end) {
- select (start, scroll);
- return;
- }
- OS.SendMessage (handle, OS.LB_SELITEMRANGEEX, start, end);
- if (scroll) showSelection ();
-}
-
-/**
- * Selects all 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 void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- OS.SendMessage (handle, OS.LB_SETSEL, 1, -1);
-}
-
-void setBounds (int x, int y, int width, int height, int flags) {
- /*
- * 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 resizing is not deferred and
- * the new size is different from the previous size.
- */
- if (parent.lpwp != null || (flags & OS.SWP_NOSIZE) != 0) {
- super.setBounds (x, y, width, height, flags);
- return;
- }
- RECT rect = new RECT ();
- OS.GetWindowRect (handle, rect);
- int oldWidth = rect.right - rect.left;
- int oldHeight = rect.bottom - rect.top;
- super.setBounds (x, y, width, height, flags);
- if (oldWidth == width && oldHeight == height) return;
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- info.fMask = OS.SIF_POS;
- if (!OS.GetScrollInfo (handle, OS.SB_HORZ, info)) return;
- if (info.nPos != 0) OS.InvalidateRect (handle, null, true);
-}
-
-void setFocusIndex (int index) {
- 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
- * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void setItems (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_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];
- if (string == null) break;
- 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, buffer.length (), 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 first cleared, then the new items are selected.
- *
- * @param indices the indices of the items to select
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 ();
- select (indices, true);
- if ((style & SWT.MULTI) != 0) {
- if (indices.length != 0) {
- int focusIndex = indices [0];
- if (focusIndex != -1) setFocusIndex (focusIndex);
- }
- }
-}
-
-/**
- * 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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 (String [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.MULTI) != 0) deselectAll ();
- int focusIndex = -1;
- for (int i=items.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)) {
- /*
- * Return and rely on the fact that select ()
- * for single-select lists clears the previous
- * selection.
- */
- showSelection ();
- return;
- }
- index++;
- }
- if (localFocus != -1) focusIndex = localFocus;
- }
- }
- if ((style & SWT.SINGLE) != 0) deselectAll ();
- if ((style & SWT.MULTI) != 0) {
- if (focusIndex != -1) 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 selected 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>
- * @see List#deselectAll()
- * @see List#select(int)
- */
-public void setSelection (int index) {
- checkWidget ();
- if ((style & SWT.MULTI) != 0) deselectAll ();
- select (index, true);
- if ((style & SWT.MULTI) != 0) {
- if (index != -1) setFocusIndex (index);
- }
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selection is first cleared, then the new items are selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- *
- * @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 ();
- if ((style & SWT.MULTI) != 0) deselectAll ();
- select (start, end, true);
- if ((style & SWT.MULTI) != 0) {
- if (start != -1) 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);
- 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 + 1, 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 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);
-}
-
-
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 notificiation
+ * when a string 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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 msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (ListProc, handle, 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 count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
+ int itemHeight = OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0);
+ int width = 0, height = count * itemHeight;
+ if ((style & SWT.H_SCROLL) != 0) {
+ width = OS.SendMessage (handle, OS.LB_GETHORIZONTALEXTENT, 0, 0);
+ } else {
+ 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 (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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 is currently
+ * has the focus in the receiver, or -1 if no item is 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.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</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);
+ } else {
+ 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</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 an 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</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. 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure while getting the selection</li>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</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
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</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 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</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
+ * @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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove (int [] indices) {
+ checkWidget ();
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int [] newIndices = new int [indices.length];
+ System.arraycopy (indices, 0, newIndices, 0, indices.length);
+ sort (newIndices);
+ int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
+ 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 || i == 0) {
+ 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) {
+ int index = newIndices [i];
+ if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+}
+
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</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) error (SWT.ERROR_ITEM_NOT_REMOVED);
+ buffer = new TCHAR (getCodePage (), length + 1);
+ int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer);
+ if (result == OS.LB_ERR) error (SWT.ERROR_ITEM_NOT_REMOVED);
+ }
+ 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove (int start, int end) {
+ checkWidget ();
+ if (start > end) return;
+ int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
+ 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) {
+ if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+}
+
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove (String string) {
+ checkWidget ();
+ 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.
+ * If the item at the given zero-relative index in the receiver
+ * is not selected, it is selected. If the item at the index
+ * was selected, it remains selected. Indices that are out
+ * of range and duplicate indices are ignored.
+ *
+ * @param indices the array of indices for the items to select
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 [] indices) {
+ checkWidget ();
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
+ 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);
+ if ((style & SWT.SINGLE) != 0) {
+ int count = getItemCount ();
+ if (0 <= index && index < count) {
+ break;
+ }
+ }
+ }
+ 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 == -1) return;
+ if (scroll) {
+ if ((style & SWT.SINGLE) != 0) {
+ OS.SendMessage (handle, OS.LB_SETCURSEL, index, 0);
+ } else {
+ int focusIndex = OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0);
+ OS.SendMessage (handle, OS.LB_SETSEL, 1, index);
+ if (focusIndex != -1) {
+ OS.SendMessage (handle, OS.LB_SETCARETINDEX, index, 0);
+ }
+ }
+ 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, index, 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 at the given zero-relative indices in the receiver.
+ * If the item at the index was already selected, it remains
+ * selected. The range of the indices is inclusive. Indices that are
+ * out of range are ignored and no items will be selected if start is
+ * greater than end.
+ *
+ * @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 select (int start, int end) {
+ checkWidget ();
+ select (start, end, false);
+}
+
+void select (int start, int end, boolean scroll) {
+ if (start > end) return;
+ if ((style & SWT.SINGLE) != 0) {
+ int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
+ int index = Math.min (count - 1, end);
+ if (index >= start) select (index, scroll);
+ 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));
+ if (start == end) {
+ select (start, scroll);
+ return;
+ }
+ OS.SendMessage (handle, OS.LB_SELITEMRANGEEX, start, end);
+ if (scroll) showSelection ();
+}
+
+/**
+ * Selects all 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 void selectAll () {
+ checkWidget ();
+ if ((style & SWT.SINGLE) != 0) return;
+ OS.SendMessage (handle, OS.LB_SETSEL, 1, -1);
+}
+
+void setBounds (int x, int y, int width, int height, int flags) {
+ /*
+ * 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 resizing is not deferred and
+ * the new size is different from the previous size.
+ */
+ if (parent.lpwp != null || (flags & OS.SWP_NOSIZE) != 0) {
+ super.setBounds (x, y, width, height, flags);
+ return;
+ }
+ RECT rect = new RECT ();
+ OS.GetWindowRect (handle, rect);
+ int oldWidth = rect.right - rect.left;
+ int oldHeight = rect.bottom - rect.top;
+ super.setBounds (x, y, width, height, flags);
+ if (oldWidth == width && oldHeight == height) return;
+ SCROLLINFO info = new SCROLLINFO ();
+ info.cbSize = SCROLLINFO.sizeof;
+ info.fMask = OS.SIF_POS;
+ if (!OS.GetScrollInfo (handle, OS.SB_HORZ, info)) return;
+ if (info.nPos != 0) OS.InvalidateRect (handle, null, true);
+}
+
+void setFocusIndex (int index) {
+ 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li>
+ * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul>
+ * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void setItems (String [] items) {
+ checkWidget ();
+ if (items == null) error (SWT.ERROR_NULL_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];
+ if (string == null) break;
+ 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, buffer.length (), 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 first cleared, then the new items are selected.
+ *
+ * @param indices the indices of the items to select
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 ();
+ select (indices, true);
+ if ((style & SWT.MULTI) != 0) {
+ if (indices.length != 0) {
+ int focusIndex = indices [0];
+ if (focusIndex != -1) setFocusIndex (focusIndex);
+ }
+ }
+}
+
+/**
+ * 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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 (String [] items) {
+ checkWidget ();
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if ((style & SWT.MULTI) != 0) deselectAll ();
+ int focusIndex = -1;
+ for (int i=items.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)) {
+ /*
+ * Return and rely on the fact that select ()
+ * for single-select lists clears the previous
+ * selection.
+ */
+ showSelection ();
+ return;
+ }
+ index++;
+ }
+ if (localFocus != -1) focusIndex = localFocus;
+ }
+ }
+ if ((style & SWT.SINGLE) != 0) deselectAll ();
+ if ((style & SWT.MULTI) != 0) {
+ if (focusIndex != -1) 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 selected 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>
+ * @see List#deselectAll()
+ * @see List#select(int)
+ */
+public void setSelection (int index) {
+ checkWidget ();
+ if ((style & SWT.MULTI) != 0) deselectAll ();
+ select (index, true);
+ if ((style & SWT.MULTI) != 0) {
+ if (index != -1) setFocusIndex (index);
+ }
+}
+
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * The current selection is first cleared, then the new items are selected.
+ * Indices that are out of range are ignored and no items will be selected
+ * if start is greater than end.
+ *
+ * @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 ();
+ if ((style & SWT.MULTI) != 0) deselectAll ();
+ select (start, end, true);
+ if ((style & SWT.MULTI) != 0) {
+ if (start != -1) 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);
+ 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 + 1, 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 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
index 21339f817a..c0c411558a 100755
--- 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
@@ -1,1200 +1,1200 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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)
- */
- public int handle;
-
- int x, y, hwndCB, id0, id1;
- boolean hasLocation;
- MenuItem cascade;
- Decorations parent;
- 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).getShell (), 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 parent 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 parent 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) {
- OS.SendMessage (hwndParent, OS.WM_CANCELMODE, 0, 0);
- return;
- }
- int flags = OS.TPM_LEFTBUTTON | 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);
- }
-}
-
-/**
- * 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);
- parent.add (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_DROPDOWN | OS.TBSTYLE_AUTOSIZE | 0x80);
- lpButton.fsState = (byte) OS.TBSTATE_ENABLED;
- lpButton.iBitmap = OS.I_IMAGENONE;
- if ((item.style & SWT.SEPARATOR) != 0) lpButton.fsStyle = (byte) OS.BTNS_SEP;
- 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 an empty string.
- */
- int hHeap = OS.GetProcessHeap ();
- int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
- 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) {
- parent.remove (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.add (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);
- }
- } 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.RemoveMenu (handle, index, OS.MF_BYPOSITION)) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- }
- }
- } else {
- if (!OS.RemoveMenu (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);
- }
-}
-
-/**
- * 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 parent.findMenuItem (info.wID);
- }
- return null;
-}
-
-public Display getDisplay () {
- Decorations parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
-/**
- * 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 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 parent.findMenuItem (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 an 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] = parent.findMenuItem (id0);
- result[1] = parent.findMenuItem (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] = parent.findMenuItem (lpButton.idCommand);
- }
- return result;
- }
- int index = 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 (index == items.length) {
- MenuItem [] newItems = new MenuItem [index + 4];
- System.arraycopy (items, 0, newItems, 0, index);
- items = newItems;
- }
- items [index++] = parent.findMenuItem (info.dwItemData);
- }
- if (index == items.length) return items;
- MenuItem [] result = new MenuItem [index];
- System.arraycopy (items, 0, result, 0, index);
- return result;
-}
-
-int GetMenuItemCount (int handle) {
- checkWidget ();
- 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) {
- Display display = getDisplay ();
- Menu [] popups = display.popups;
- if (popups == null) return false;
- for (int i=0; i<popups.length; i++) {
- if (popups [i] == this) return true;
- }
- }
- return this == getShell ().activeMenu;
-}
-
-/**
- * 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 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 ();
- 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 ((style & SWT.BAR) != 0) {
- Display display = getDisplay ();
- display.addBar (this);
- } else {
- update ();
- }
-}
-
-void releaseChild () {
- super.releaseChild ();
- if (cascade != null) cascade.releaseMenu ();
- if ((style & SWT.BAR) != 0) {
- Display display = getDisplay ();
- display.removeBar (this);
- if (this == parent.menuBar) {
- parent.setMenuBar (null);
- }
- } else {
- if ((style & SWT.POP_UP) != 0) {
- Display display = getDisplay ();
- display.removePopup (this);
- }
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = hwndCB = 0;
-}
-
-void releaseWidget () {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (!item.isDisposed ()) {
- if (OS.IsPPC && hwndCB != 0) {
- item.dispose ();
- } else {
- item.releaseResources ();
- }
- }
- }
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 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 ();
- state &= ~DISABLED;
- if (!enabled) state |= DISABLED;
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the display.
- * <p>
- * Note: 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 ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- this.x = x;
- this.y = y;
- hasLocation = true;
-}
-
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the display.
- * <p>
- * Note: This is different from most widgets where the
- * location of the widget is relative to the parent.
- * </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;
- Display display = getDisplay ();
- 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 ((style & SWT.BAR) != 0) {
- if (this == parent.menuBar) OS.DrawMenuBar (parent.handle);
- return;
- }
- if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {
- return;
- }
- boolean hasCheck = false, hasImage = false;
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (item.getImage () != null) {
- if ((hasImage = true) && hasCheck) break;
- }
- if ((item.getStyle () & (SWT.CHECK | SWT.RADIO)) != 0) {
- if ((hasCheck = true) && hasImage) break;
- }
- }
- 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);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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)
+ */
+ public int handle;
+
+ int x, y, hwndCB, id0, id1;
+ boolean hasLocation;
+ MenuItem cascade;
+ Decorations parent;
+ 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).getShell (), 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 parent 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 parent 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) {
+ OS.SendMessage (hwndParent, OS.WM_CANCELMODE, 0, 0);
+ return;
+ }
+ int flags = OS.TPM_LEFTBUTTON | 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);
+ }
+}
+
+/**
+ * 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);
+ parent.add (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_DROPDOWN | OS.TBSTYLE_AUTOSIZE | 0x80);
+ lpButton.fsState = (byte) OS.TBSTATE_ENABLED;
+ lpButton.iBitmap = OS.I_IMAGENONE;
+ if ((item.style & SWT.SEPARATOR) != 0) lpButton.fsStyle = (byte) OS.BTNS_SEP;
+ 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 an empty string.
+ */
+ int hHeap = OS.GetProcessHeap ();
+ int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
+ 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) {
+ parent.remove (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.add (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);
+ }
+ } 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.RemoveMenu (handle, index, OS.MF_BYPOSITION)) {
+ error (SWT.ERROR_ITEM_NOT_REMOVED);
+ }
+ }
+ } else {
+ if (!OS.RemoveMenu (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);
+ }
+}
+
+/**
+ * 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 parent.findMenuItem (info.wID);
+ }
+ return null;
+}
+
+public Display getDisplay () {
+ Decorations parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
+/**
+ * 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 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 parent.findMenuItem (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 an 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] = parent.findMenuItem (id0);
+ result[1] = parent.findMenuItem (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] = parent.findMenuItem (lpButton.idCommand);
+ }
+ return result;
+ }
+ int index = 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 (index == items.length) {
+ MenuItem [] newItems = new MenuItem [index + 4];
+ System.arraycopy (items, 0, newItems, 0, index);
+ items = newItems;
+ }
+ items [index++] = parent.findMenuItem (info.dwItemData);
+ }
+ if (index == items.length) return items;
+ MenuItem [] result = new MenuItem [index];
+ System.arraycopy (items, 0, result, 0, index);
+ return result;
+}
+
+int GetMenuItemCount (int handle) {
+ checkWidget ();
+ 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) {
+ Display display = getDisplay ();
+ Menu [] popups = display.popups;
+ if (popups == null) return false;
+ for (int i=0; i<popups.length; i++) {
+ if (popups [i] == this) return true;
+ }
+ }
+ return this == getShell ().activeMenu;
+}
+
+/**
+ * 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 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 ();
+ 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 ((style & SWT.BAR) != 0) {
+ Display display = getDisplay ();
+ display.addBar (this);
+ } else {
+ update ();
+ }
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ if (cascade != null) cascade.releaseMenu ();
+ if ((style & SWT.BAR) != 0) {
+ Display display = getDisplay ();
+ display.removeBar (this);
+ if (this == parent.menuBar) {
+ parent.setMenuBar (null);
+ }
+ } else {
+ if ((style & SWT.POP_UP) != 0) {
+ Display display = getDisplay ();
+ display.removePopup (this);
+ }
+ }
+}
+
+void releaseHandle () {
+ super.releaseHandle ();
+ handle = hwndCB = 0;
+}
+
+void releaseWidget () {
+ MenuItem [] items = getItems ();
+ for (int i=0; i<items.length; i++) {
+ MenuItem item = items [i];
+ if (!item.isDisposed ()) {
+ if (OS.IsPPC && hwndCB != 0) {
+ item.dispose ();
+ } else {
+ item.releaseResources ();
+ }
+ }
+ }
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 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 ();
+ state &= ~DISABLED;
+ if (!enabled) state |= DISABLED;
+}
+
+/**
+ * Sets the receiver's location to the point specified by
+ * the arguments which are relative to the display.
+ * <p>
+ * Note: 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 ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
+ this.x = x;
+ this.y = y;
+ hasLocation = true;
+}
+
+/**
+ * Sets the receiver's location to the point specified by
+ * the arguments which are relative to the display.
+ * <p>
+ * Note: This is different from most widgets where the
+ * location of the widget is relative to the parent.
+ * </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;
+ Display display = getDisplay ();
+ 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 ((style & SWT.BAR) != 0) {
+ if (this == parent.menuBar) OS.DrawMenuBar (parent.handle);
+ return;
+ }
+ if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {
+ return;
+ }
+ boolean hasCheck = false, hasImage = false;
+ MenuItem [] items = getItems ();
+ for (int i=0; i<items.length; i++) {
+ MenuItem item = items [i];
+ if (item.getImage () != null) {
+ if ((hasImage = true) && hasCheck) break;
+ }
+ if ((item.getStyle () & (SWT.CHECK | SWT.RADIO)) != 0) {
+ if ((hasCheck = true) && hasImage) break;
+ }
+ }
+ 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
index 6833f5561c..5a59689728 100755
--- 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
@@ -1,976 +1,976 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
-
-/**
- * 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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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;
- Decorations shell = parent.parent;
- shell.add (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 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 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 fillAccel (ACCEL accel) {
- accel.fVirt = 0;
- accel.cmd = accel.key = 0;
- if (accelerator == 0) 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 = 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;
-}
-
-/**
- * Return 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>.
- *
- * @return the accelerator
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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 Display getDisplay () {
- Menu parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
-/**
- * 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 ((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 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 () {
- return getEnabled () && parent.isEnabled ();
-}
-
-void releaseChild () {
- super.releaseChild ();
- if (menu != null) menu.dispose ();
- menu = null;
- parent.destroyItem (this);
-}
-
-void releaseMenu () {
- if (!OS.IsSP) setMenu (null);
- menu = null;
-}
-
-void releaseWidget () {
- if (menu != null) menu.releaseResources ();
- menu = null;
- super.releaseWidget ();
- if (accelerator != 0) {
- parent.destroyAccelerators ();
- }
- accelerator = 0;
- Decorations shell = parent.parent;
- shell.remove (this);
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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>.
- *
- * @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 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 ((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) error (SWT.ERROR_CANNOT_SET_ENABLED);
- }
- }
- parent.redraw ();
-}
-
-/**
- * Sets the image the receiver will display to the argument.
- * <p>
- * Note: This feature is not available on all window systems (for example, Window NT),
- * in which case, calling this method will silently do nothing.
- *
- * @param menu 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) return;
- if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {
- return;
- }
- int hMenu = parent.handle;
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_BITMAP;
- if (image != null) info.hbmpItem = OS.HBMMENU_CALLBACK;
- 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.
- *
- * @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;
- 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;
- boolean 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. SetMenuItemInfo
- * does not set the menu item state and submenu use InsertMenu
- * to set these fields and SetMenuItemInfo to set the menu item
- * data. NOTE: SetMenuItemInfo is also used to set the string
- * that was queried from the original menu item.
- */
- 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);
- }
- 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) 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;
- 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 {
- /* 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 hMenu = parent.handle;
- MENUITEMINFO info = new MENUITEMINFO ();
- info.cbSize = MENUITEMINFO.sizeof;
- info.fMask = OS.MIIM_TYPE;
- info.fType = widgetStyle ();
- info.dwTypeData = pszText;
- success = OS.SetMenuItemInfo (hMenu, id, false, info);
- /*
- * 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.
- */
- if (!OS.IsWinCE) {
- if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) >= (4 << 16 | 10)) {
- if (image != null) {
- 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) {
- /*
- * This code intentionally commented.
- */
-// GC gc = GC.win32_new (struct.hDC, null);
-// gc.drawImage (image, struct.left, struct.top);
- int hImage = image.handle;
- switch (image.type) {
- case SWT.BITMAP:
- BITMAP bm = new BITMAP ();
- OS.GetObject (hImage, BITMAP.sizeof, bm);
- int hDC = OS.CreateCompatibleDC (struct.hDC);
- int oldBitmap = OS.SelectObject (hDC, hImage);
- OS.BitBlt (struct.hDC, struct.left, struct.top + 2, bm.bmWidth, bm.bmHeight, hDC, 0, 0, OS.SRCCOPY);
- OS.SelectObject (hDC, oldBitmap);
- OS.DeleteDC (hDC);
- break;
- case SWT.ICON:
- OS.DrawIconEx (struct.hDC, struct.left, struct.top + 2, hImage, 0, 0, 0, 0, OS.DI_NORMAL);
- break;
- }
- }
- return null;
-}
-
-LRESULT wmMeasureChild (int wParam, int lParam) {
- MEASUREITEMSTRUCT struct = new MEASUREITEMSTRUCT ();
- OS.MoveMemory (struct, lParam, MEASUREITEMSTRUCT.sizeof);
- if (image != null) {
- /*
- * 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 add only 2 pixels in
- * this case.
- */
- Rectangle rect = image.getBounds ();
- struct.itemWidth = rect.width + (OS.IsWin95 ? 4 : 2);
- struct.itemHeight = rect.height + 4;
- }
- OS.MoveMemory (lParam, struct, MEASUREITEMSTRUCT.sizeof);
- return null;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+
+/**
+ * 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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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;
+ Decorations shell = parent.parent;
+ shell.add (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 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 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 fillAccel (ACCEL accel) {
+ accel.fVirt = 0;
+ accel.cmd = accel.key = 0;
+ if (accelerator == 0) 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 = 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;
+}
+
+/**
+ * Return 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>.
+ *
+ * @return the accelerator
+ *
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 Display getDisplay () {
+ Menu parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
+/**
+ * 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 ((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 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 () {
+ return getEnabled () && parent.isEnabled ();
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ if (menu != null) menu.dispose ();
+ menu = null;
+ parent.destroyItem (this);
+}
+
+void releaseMenu () {
+ if (!OS.IsSP) setMenu (null);
+ menu = null;
+}
+
+void releaseWidget () {
+ if (menu != null) menu.releaseResources ();
+ menu = null;
+ super.releaseWidget ();
+ if (accelerator != 0) {
+ parent.destroyAccelerators ();
+ }
+ accelerator = 0;
+ Decorations shell = parent.parent;
+ shell.remove (this);
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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>.
+ *
+ * @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 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 ((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) error (SWT.ERROR_CANNOT_SET_ENABLED);
+ }
+ }
+ parent.redraw ();
+}
+
+/**
+ * Sets the image the receiver will display to the argument.
+ * <p>
+ * Note: This feature is not available on all window systems (for example, Window NT),
+ * in which case, calling this method will silently do nothing.
+ *
+ * @param menu 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) return;
+ if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {
+ return;
+ }
+ int hMenu = parent.handle;
+ MENUITEMINFO info = new MENUITEMINFO ();
+ info.cbSize = MENUITEMINFO.sizeof;
+ info.fMask = OS.MIIM_BITMAP;
+ if (image != null) info.hbmpItem = OS.HBMMENU_CALLBACK;
+ 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.
+ *
+ * @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;
+ 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;
+ boolean 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. SetMenuItemInfo
+ * does not set the menu item state and submenu use InsertMenu
+ * to set these fields and SetMenuItemInfo to set the menu item
+ * data. NOTE: SetMenuItemInfo is also used to set the string
+ * that was queried from the original menu item.
+ */
+ 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);
+ }
+ 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) 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;
+ 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 {
+ /* 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 hMenu = parent.handle;
+ MENUITEMINFO info = new MENUITEMINFO ();
+ info.cbSize = MENUITEMINFO.sizeof;
+ info.fMask = OS.MIIM_TYPE;
+ info.fType = widgetStyle ();
+ info.dwTypeData = pszText;
+ success = OS.SetMenuItemInfo (hMenu, id, false, info);
+ /*
+ * 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.
+ */
+ if (!OS.IsWinCE) {
+ if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) >= (4 << 16 | 10)) {
+ if (image != null) {
+ 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) {
+ /*
+ * This code intentionally commented.
+ */
+// GC gc = GC.win32_new (struct.hDC, null);
+// gc.drawImage (image, struct.left, struct.top);
+ int hImage = image.handle;
+ switch (image.type) {
+ case SWT.BITMAP:
+ BITMAP bm = new BITMAP ();
+ OS.GetObject (hImage, BITMAP.sizeof, bm);
+ int hDC = OS.CreateCompatibleDC (struct.hDC);
+ int oldBitmap = OS.SelectObject (hDC, hImage);
+ OS.BitBlt (struct.hDC, struct.left, struct.top + 2, bm.bmWidth, bm.bmHeight, hDC, 0, 0, OS.SRCCOPY);
+ OS.SelectObject (hDC, oldBitmap);
+ OS.DeleteDC (hDC);
+ break;
+ case SWT.ICON:
+ OS.DrawIconEx (struct.hDC, struct.left, struct.top + 2, hImage, 0, 0, 0, 0, OS.DI_NORMAL);
+ break;
+ }
+ }
+ return null;
+}
+
+LRESULT wmMeasureChild (int wParam, int lParam) {
+ MEASUREITEMSTRUCT struct = new MEASUREITEMSTRUCT ();
+ OS.MoveMemory (struct, lParam, MEASUREITEMSTRUCT.sizeof);
+ if (image != null) {
+ /*
+ * 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 add only 2 pixels in
+ * this case.
+ */
+ Rectangle rect = image.getBounds ();
+ struct.itemWidth = rect.width + (OS.IsWin95 ? 4 : 2);
+ struct.itemHeight = rect.height + 4;
+ }
+ 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
index e1716155e8..0b8b1e180e 100755
--- 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
@@ -1,252 +1,252 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class are used 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.
- * <p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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.
- * </p>
- * Note: Currently, null can be passed in for the parent.
- * This has the effect of creating the dialog on the currently active
- * display if there is one. If there is no current display, the
- * dialog 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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, 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 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 (parent != null && (parent.style & SWT.RIGHT_TO_LEFT) != 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 is to force the parent
- * to be NULL when this style is set.
- */
- int hwndOwner = 0;
- if (parent != null && (bits & OS.MB_TASKMODAL) == 0) {
- hwndOwner = parent.handle;
- }
-
- /*
- * Feature in Windows. The focus window is not saved and
- * and restored automatically by the call to MessageBox().
- * The fix is to save and restore the focus window.
- */
- int hwndFocus = OS.GetFocus ();
-
- /* 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);
-
- /* Restore focus */
- OS.SetFocus (hwndFocus);
-
- /*
- * 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
- */
-public void setMessage (String string) {
- message = string;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.win32.*;
+import org.eclipse.swt.*;
+
+/**
+ * Instances of this class are used 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.
+ * <p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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.
+ * </p>
+ * Note: Currently, null can be passed in for the parent.
+ * This has the effect of creating the dialog on the currently active
+ * display if there is one. If there is no current display, the
+ * dialog 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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, 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 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 (parent != null && (parent.style & SWT.RIGHT_TO_LEFT) != 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 is to force the parent
+ * to be NULL when this style is set.
+ */
+ int hwndOwner = 0;
+ if (parent != null && (bits & OS.MB_TASKMODAL) == 0) {
+ hwndOwner = parent.handle;
+ }
+
+ /*
+ * Feature in Windows. The focus window is not saved and
+ * and restored automatically by the call to MessageBox().
+ * The fix is to save and restore the focus window.
+ */
+ int hwndFocus = OS.GetFocus ();
+
+ /* 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);
+
+ /* Restore focus */
+ OS.SetFocus (hwndFocus);
+
+ /*
+ * 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
+ */
+public void setMessage (String string) {
+ 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
index e2b5996604..14a37795ee 100755
--- 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
@@ -1,279 +1,279 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 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;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (ProgressBarProc, handle, 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 createHandle () {
- super.createHandle ();
- if ((style & SWT.INDETERMINATE) != 0) {
- OS.SetTimer (handle, TIMER_ID, DELAY, 0);
- }
-}
-
-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 <em>selection</em> 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 ();
- if ((style & SWT.INDETERMINATE) != 0) {
- OS.KillTimer (handle, TIMER_ID);
- }
-}
-
-void setBackgroundPixel (int pixel) {
- if (background == pixel) return;
- background = pixel;
- if (pixel == -1) pixel = OS.CLR_DEFAULT;
- OS.SendMessage (handle, OS.PBM_SETBKCOLOR, 0, pixel);
-}
-
-public boolean setFocus () {
- checkWidget();
- return false;
-}
-
-void setForegroundPixel (int pixel) {
- if (foreground == pixel) return;
- foreground = pixel;
- if (pixel == -1) pixel = OS.CLR_DEFAULT;
- OS.SendMessage (handle, OS.PBM_SETBARCOLOR, 0, pixel);
-}
-
-/**
- * Sets the maximum value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new maximum (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 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 which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new minimum (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 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 <em>selection</em> 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;
- 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_TIMER (int wParam, int lParam) {
- LRESULT result = super.WM_TIMER (wParam, lParam);
- if (result != null) return result;
- if (wParam == TIMER_ID) {
- OS.SendMessage (handle, OS.PBM_STEPIT, 0, 0);
- }
- return null;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 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;
+ }
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (ProgressBarProc, handle, 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 createHandle () {
+ super.createHandle ();
+ if ((style & SWT.INDETERMINATE) != 0) {
+ OS.SetTimer (handle, TIMER_ID, DELAY, 0);
+ }
+}
+
+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 <em>selection</em> 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 ();
+ if ((style & SWT.INDETERMINATE) != 0) {
+ OS.KillTimer (handle, TIMER_ID);
+ }
+}
+
+void setBackgroundPixel (int pixel) {
+ if (background == pixel) return;
+ background = pixel;
+ if (pixel == -1) pixel = OS.CLR_DEFAULT;
+ OS.SendMessage (handle, OS.PBM_SETBKCOLOR, 0, pixel);
+}
+
+public boolean setFocus () {
+ checkWidget();
+ return false;
+}
+
+void setForegroundPixel (int pixel) {
+ if (foreground == pixel) return;
+ foreground = pixel;
+ if (pixel == -1) pixel = OS.CLR_DEFAULT;
+ OS.SendMessage (handle, OS.PBM_SETBARCOLOR, 0, pixel);
+}
+
+/**
+ * Sets the maximum value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new maximum (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 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 which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new minimum (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 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 <em>selection</em> 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;
+ 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_TIMER (int wParam, int lParam) {
+ LRESULT result = super.WM_TIMER (wParam, lParam);
+ if (result != null) return result;
+ if (wParam == TIMER_ID) {
+ OS.SendMessage (handle, OS.PBM_STEPIT, 0, 0);
+ }
+ return null;
+}
+
+}
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
index 3d744daf42..ad7f3cd6c8 100755
--- 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
@@ -1,404 +1,404 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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</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 reciever 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 msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.DefWindowProc (handle, 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 += 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) {
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 getDisplay ().windowClass;
-}
-
-int windowProc () {
- return getDisplay ().windowProc;
-}
-
-LRESULT WM_ERASEBKGND (int wParam, int lParam) {
- LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
- if (result != null) return result;
- 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 (parent.handle, cursorPt);
- if ((style & SWT.VERTICAL) != 0) {
- cursorPt.y += height / 2;
- }
- else {
- cursorPt.x += width / 2;
- }
- OS.SetCursorPos (cursorPt.x, cursorPt.y);
-
- /* 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 LRESULT.ZERO;
- 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);
-
- /* 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;
- 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 LRESULT.ZERO;
-
- /* Draw the banding rectangle */
- if (event.doit) {
- dragging = true;
- menuShell ().bringToTop ();
- if (OS.IsWinCE) {
- OS.UpdateWindow (hwndTrack);
- } else {
- int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
- OS.RedrawWindow (hwndTrack, null, 0, flags);
- }
- drawBand (lastX = event.x, lastY = event.y, width, height);
- }
- return result;
-}
-
-LRESULT WM_LBUTTONUP (int wParam, int lParam) {
- LRESULT result = super.WM_LBUTTONUP (wParam, lParam);
-
- /* 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 (lastX, lastY, width, height);
- sendEvent (SWT.Selection, event);
- // 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;
- 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 LRESULT.ZERO;
-
- /* Draw the banding rectangle */
- 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);
- }
- 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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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</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 reciever 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 msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.DefWindowProc (handle, 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 += 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) {
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 getDisplay ().windowClass;
+}
+
+int windowProc () {
+ return getDisplay ().windowProc;
+}
+
+LRESULT WM_ERASEBKGND (int wParam, int lParam) {
+ LRESULT result = super.WM_ERASEBKGND (wParam, lParam);
+ if (result != null) return result;
+ 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 (parent.handle, cursorPt);
+ if ((style & SWT.VERTICAL) != 0) {
+ cursorPt.y += height / 2;
+ }
+ else {
+ cursorPt.x += width / 2;
+ }
+ OS.SetCursorPos (cursorPt.x, cursorPt.y);
+
+ /* 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 LRESULT.ZERO;
+ 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);
+
+ /* 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;
+ 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 LRESULT.ZERO;
+
+ /* Draw the banding rectangle */
+ if (event.doit) {
+ dragging = true;
+ menuShell ().bringToTop ();
+ if (OS.IsWinCE) {
+ OS.UpdateWindow (hwndTrack);
+ } else {
+ int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
+ OS.RedrawWindow (hwndTrack, null, 0, flags);
+ }
+ drawBand (lastX = event.x, lastY = event.y, width, height);
+ }
+ return result;
+}
+
+LRESULT WM_LBUTTONUP (int wParam, int lParam) {
+ LRESULT result = super.WM_LBUTTONUP (wParam, lParam);
+
+ /* 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 (lastX, lastY, width, height);
+ sendEvent (SWT.Selection, event);
+ // 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;
+ 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 LRESULT.ZERO;
+
+ /* Draw the banding rectangle */
+ 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);
+ }
+ 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
index 09b770cead..e3efc29250 100755
--- 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
@@ -1,416 +1,416 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 {
- 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;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (TrackBarProc, handle, 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 ();
- 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 single <em>selection</em> 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.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 setBackgroundPixel (int pixel) {
- if (background == pixel) return;
- 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 post a fake WM_SETFOCUS event to cause it to redraw
- * with the new background color.
- *
- * Note. This WM_SETFOCUS message causes recursion when
- * setBackground is called from within the focus event listener.
- */
- OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0);
-}
-
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setIncrement (int 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 which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new maximum (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 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 which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new minimum (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 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.
- *
- * @return 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 single <em>selection</em> that 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;
- return bits | OS.TBS_VERT;
-}
-
-TCHAR windowClass () {
- return TrackBarClass;
-}
-
-int windowProc () {
- return TrackBarProc;
-}
-
-LRESULT wmScrollChild (int wParam, int lParam) {
-
- /* Do nothing when scrolling is ending */
- int code = wParam & 0xFFFF;
- if (code == OS.TB_ENDTRACK) return null;
-
- /*
- * This code is intentionally commented. The event
- * detail field is not currently supported on all
- * platforms.
- */
- Event event = new Event ();
-// switch (code) {
-// /*
-// * This line is intentionally commented. Do not set the detail
-// * field to DRAG to indicate that the dragging has ended when the
-// * scroll bar is finally positioned in TB_THUMBPOSITION.
-// */
-//// case OS.TB_THUMBPOSITION: break;
-// case OS.TB_THUMBTRACK: event.detail = SWT.DRAG; break;
-// 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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 {
+ 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;
+ }
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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.
+ *
+ * @param listener the listener which should be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (TrackBarProc, handle, 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 ();
+ 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 single <em>selection</em> 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.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 setBackgroundPixel (int pixel) {
+ if (background == pixel) return;
+ 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 post a fake WM_SETFOCUS event to cause it to redraw
+ * with the new background color.
+ *
+ * Note. This WM_SETFOCUS message causes recursion when
+ * setBackground is called from within the focus event listener.
+ */
+ OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0);
+}
+
+/**
+ * Sets the amount that the receiver's value will be
+ * modified by when the up/down (or right/left) arrows
+ * are pressed to the argument, which must be at least
+ * one.
+ *
+ * @param value the new increment (must be greater than zero)
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setIncrement (int 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 which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new maximum (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 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 which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new minimum (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 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.
+ *
+ * @return 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 single <em>selection</em> that 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;
+ return bits | OS.TBS_VERT;
+}
+
+TCHAR windowClass () {
+ return TrackBarClass;
+}
+
+int windowProc () {
+ return TrackBarProc;
+}
+
+LRESULT wmScrollChild (int wParam, int lParam) {
+
+ /* Do nothing when scrolling is ending */
+ int code = wParam & 0xFFFF;
+ if (code == OS.TB_ENDTRACK) return null;
+
+ /*
+ * This code is intentionally commented. The event
+ * detail field is not currently supported on all
+ * platforms.
+ */
+ Event event = new Event ();
+// switch (code) {
+// /*
+// * This line is intentionally commented. Do not set the detail
+// * field to DRAG to indicate that the dragging has ended when the
+// * scroll bar is finally positioned in TB_THUMBPOSITION.
+// */
+//// case OS.TB_THUMBPOSITION: break;
+// case OS.TB_THUMBTRACK: event.detail = SWT.DRAG; break;
+// 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
index a5baa1a81b..aa6e1b0dad 100755
--- 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
@@ -1,1004 +1,1004 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 <em>selection</em> 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>0</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.
- */
-}
-
-public void dispose () {
- int hwnd = hwndScrollBar (), type = scrollBarType ();
- super.dispose ();
- 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);
- }
-}
-
-/*
-* Not currently used.
-*/
-Rectangle getBounds () {
- RECT rect = new RECT ();
- OS.GetClientRect (parent.handle, 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);
-}
-
-public Display getDisplay () {
- Scrollable parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
-/**
- * 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 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 <em>selection</em> 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();
- RECT rect = new RECT ();
- OS.GetClientRect (parent.handle, 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);
-}
-
-/**
- * Answers 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.handle;
-}
-
-/**
- * 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 releaseChild () {
- super.releaseChild ();
- 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);
-}
-
-int scrollBarType () {
- if ((style & SWT.VERTICAL) != 0) return OS.SB_VERT;
- /*
- * This line is intentionally commented. There should
- * only ever be HORIZONTAL and VERTICAL scroll bars.
- * The commented code reminds us that this is the case
- * and that the default style is HORIZONTAL.
- */
-// if ((style & SWT.HORIZONTAL) != 0) return OS.SB_HORZ;
- return 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);
- state &= ~DISABLED;
- if (!enabled) 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 value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new maximum (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 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;
- OS.SetScrollInfo (hwnd, type, info, (state & DISABLED) == 0);
-
- /*
- * 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
- * widget 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) {
- OS.ShowScrollBar (hwnd, type, 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, type, OS.ESB_DISABLE_BOTH);
- }
- }
-}
-
-/**
- * Sets the minimum value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new minimum (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 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;
- OS.SetScrollInfo (hwnd, type, info, true);
-
- /*
- * 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
- * widget 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) {
- OS.ShowScrollBar (hwnd, type, 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, type, OS.ESB_DISABLE_BOTH);
- }
- }
-}
-
-/**
- * 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.
- *
- * @return the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the single <em>selection</em> that is the receiver's
- * value to the argument which must be greater than or equal
- * to zero.
- *
- * @param 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();
- SCROLLINFO info = new SCROLLINFO ();
- info.cbSize = SCROLLINFO.sizeof;
- int hwnd = hwndScrollBar (), type = scrollBarType ();
- info.fMask = OS.SIF_POS;
- info.nPos = selection;
- OS.SetScrollInfo (hwnd, type, info, true);
-}
-
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values to the
- * argument which must be at least one.
- *
- * @param value the new thumb value (must be at least 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 ScrollBar
- */
-public void setThumb (int value) {
- checkWidget();
-
- /* Position the thumb */
- 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);
- if (info.nMax - info.nMin - value < 0) return;
- info.nPage = value;
- if (info.nPage != 0) info.nPage++;
- OS.SetScrollInfo (hwnd, type, info, true);
-
- /*
- * 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
- * widget 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) {
- OS.ShowScrollBar (hwnd, type, 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, type, OS.ESB_DISABLE_BOTH);
- }
- }
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is equivalent 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 (maximum - minimum - thumb < 0) 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 ();
- OS.SetScrollInfo (hwnd, type, info, true);
-
- /*
- * 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
- * widget 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) {
- OS.ShowScrollBar (hwnd, type, 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, type, OS.ESB_DISABLE_BOTH);
- }
- }
-}
-
-/**
- * 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) {
- 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 &= ~HIDDEN;
- if (!visible) 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) {
- /*
- * This line is intentionally commented. Do not set the detail
- * field to DRAG to indicate that the dragging has ended when the
- * scroll bar is finally positioned in SB_THUMBPOSITION.
- */
-// case OS.SB_THUMBPOSITION: 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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 <em>selection</em> 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>0</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.
+ */
+}
+
+public void dispose () {
+ int hwnd = hwndScrollBar (), type = scrollBarType ();
+ super.dispose ();
+ 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);
+ }
+}
+
+/*
+* Not currently used.
+*/
+Rectangle getBounds () {
+ RECT rect = new RECT ();
+ OS.GetClientRect (parent.handle, 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);
+}
+
+public Display getDisplay () {
+ Scrollable parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
+/**
+ * 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 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 <em>selection</em> 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();
+ RECT rect = new RECT ();
+ OS.GetClientRect (parent.handle, 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);
+}
+
+/**
+ * Answers 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.handle;
+}
+
+/**
+ * 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 releaseChild () {
+ super.releaseChild ();
+ 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);
+}
+
+int scrollBarType () {
+ if ((style & SWT.VERTICAL) != 0) return OS.SB_VERT;
+ /*
+ * This line is intentionally commented. There should
+ * only ever be HORIZONTAL and VERTICAL scroll bars.
+ * The commented code reminds us that this is the case
+ * and that the default style is HORIZONTAL.
+ */
+// if ((style & SWT.HORIZONTAL) != 0) return OS.SB_HORZ;
+ return 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);
+ state &= ~DISABLED;
+ if (!enabled) 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 value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new maximum (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 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;
+ OS.SetScrollInfo (hwnd, type, info, (state & DISABLED) == 0);
+
+ /*
+ * 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
+ * widget 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) {
+ OS.ShowScrollBar (hwnd, type, 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, type, OS.ESB_DISABLE_BOTH);
+ }
+ }
+}
+
+/**
+ * Sets the minimum value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new minimum (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 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;
+ OS.SetScrollInfo (hwnd, type, info, true);
+
+ /*
+ * 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
+ * widget 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) {
+ OS.ShowScrollBar (hwnd, type, 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, type, OS.ESB_DISABLE_BOTH);
+ }
+ }
+}
+
+/**
+ * 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.
+ *
+ * @return the page increment (must be greater than zero)
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setPageIncrement (int value) {
+ checkWidget();
+ if (value < 1) return;
+ pageIncrement = value;
+}
+
+/**
+ * Sets the single <em>selection</em> that is the receiver's
+ * value to the argument which must be greater than or equal
+ * to zero.
+ *
+ * @param 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();
+ SCROLLINFO info = new SCROLLINFO ();
+ info.cbSize = SCROLLINFO.sizeof;
+ int hwnd = hwndScrollBar (), type = scrollBarType ();
+ info.fMask = OS.SIF_POS;
+ info.nPos = selection;
+ OS.SetScrollInfo (hwnd, type, info, true);
+}
+
+/**
+ * Sets the size of the receiver's thumb relative to the
+ * difference between its maximum and minimum values to the
+ * argument which must be at least one.
+ *
+ * @param value the new thumb value (must be at least 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 ScrollBar
+ */
+public void setThumb (int value) {
+ checkWidget();
+
+ /* Position the thumb */
+ 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);
+ if (info.nMax - info.nMin - value < 0) return;
+ info.nPage = value;
+ if (info.nPage != 0) info.nPage++;
+ OS.SetScrollInfo (hwnd, type, info, true);
+
+ /*
+ * 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
+ * widget 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) {
+ OS.ShowScrollBar (hwnd, type, 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, type, OS.ESB_DISABLE_BOTH);
+ }
+ }
+}
+
+/**
+ * Sets the receiver's selection, minimum value, maximum
+ * value, thumb, increment and page increment all at once.
+ * <p>
+ * Note: This is equivalent 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 (maximum - minimum - thumb < 0) 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 ();
+ OS.SetScrollInfo (hwnd, type, info, true);
+
+ /*
+ * 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
+ * widget 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) {
+ OS.ShowScrollBar (hwnd, type, 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, type, OS.ESB_DISABLE_BOTH);
+ }
+ }
+}
+
+/**
+ * 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) {
+ 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 &= ~HIDDEN;
+ if (!visible) 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) {
+ /*
+ * This line is intentionally commented. Do not set the detail
+ * field to DRAG to indicate that the dragging has ended when the
+ * scroll bar is finally positioned in SB_THUMBPOSITION.
+ */
+// case OS.SB_THUMBPOSITION: 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
index 00aff6bc5e..b6b542001a 100755
--- 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
@@ -1,379 +1,379 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.DefWindowProc (handle, 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>
- *
- * @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 ();
- RECT rect = new RECT ();
- OS.SetRect (rect, x, y, x + width, y + height);
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- OS.AdjustWindowRectEx (rect, bits, false, OS.GetWindowLong (handle, OS.GWL_EXSTYLE));
- 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 ();
- OS.GetClientRect (handle, rect);
- return new Rectangle (0, 0, rect.right, rect.bottom);
-}
-
-/**
- * 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 releaseWidget () {
- if (horizontalBar != null) horizontalBar.releaseResources ();
- if (verticalBar != null) verticalBar.releaseResources ();
- horizontalBar = verticalBar = null;
- super.releaseWidget ();
-}
-
-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 getDisplay ().windowClass;
-}
-
-int windowProc () {
- return getDisplay ().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 ((lParam == 0 || lParam == handle) && horizontalBar != null) {
- return wmScroll (horizontalBar, 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 = 1;
- } 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 (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 (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 ((lParam == 0 || lParam == handle) && verticalBar != null) {
- return wmScroll (verticalBar, OS.WM_VSCROLL, wParam, lParam);
- }
- return result;
-}
-
-LRESULT wmScroll (ScrollBar bar, int msg, int wParam, int lParam) {
- LRESULT result = null;
- if ((state & CANVAS) != 0) {
- 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 (handle, type, info);
- info.fMask = OS.SIF_POS;
- int code = wParam & 0xFFFF;
- switch (code) {
- case OS.SB_ENDSCROLL: return null;
- case OS.SB_THUMBTRACK:
- case OS.SB_THUMBPOSITION:
- /*
- * 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 (handle, type, info, true);
- } else {
- int code = callWindowProc (msg, wParam, lParam);
- result = code == 0 ? LRESULT.ZERO : new LRESULT (code);
- }
- bar.wmScrollChild (wParam, lParam);
- return result;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.DefWindowProc (handle, 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>
+ *
+ * @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 ();
+ RECT rect = new RECT ();
+ OS.SetRect (rect, x, y, x + width, y + height);
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ OS.AdjustWindowRectEx (rect, bits, false, OS.GetWindowLong (handle, OS.GWL_EXSTYLE));
+ 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 ();
+ OS.GetClientRect (handle, rect);
+ return new Rectangle (0, 0, rect.right, rect.bottom);
+}
+
+/**
+ * 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 releaseWidget () {
+ if (horizontalBar != null) horizontalBar.releaseResources ();
+ if (verticalBar != null) verticalBar.releaseResources ();
+ horizontalBar = verticalBar = null;
+ super.releaseWidget ();
+}
+
+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 getDisplay ().windowClass;
+}
+
+int windowProc () {
+ return getDisplay ().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 ((lParam == 0 || lParam == handle) && horizontalBar != null) {
+ return wmScroll (horizontalBar, 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 = 1;
+ } 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 (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 (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 ((lParam == 0 || lParam == handle) && verticalBar != null) {
+ return wmScroll (verticalBar, OS.WM_VSCROLL, wParam, lParam);
+ }
+ return result;
+}
+
+LRESULT wmScroll (ScrollBar bar, int msg, int wParam, int lParam) {
+ LRESULT result = null;
+ if ((state & CANVAS) != 0) {
+ 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 (handle, type, info);
+ info.fMask = OS.SIF_POS;
+ int code = wParam & 0xFFFF;
+ switch (code) {
+ case OS.SB_ENDSCROLL: return null;
+ case OS.SB_THUMBTRACK:
+ case OS.SB_THUMBPOSITION:
+ /*
+ * 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 (handle, type, info, true);
+ } else {
+ int code = callWindowProc (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
index 358a1e033c..6341d5eeb6 100755
--- 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
@@ -1,1362 +1,1362 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>
- * 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
- * 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>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE</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 {
- Display display;
- Menu activeMenu;
- int hIMC;
- int [] brushes;
- boolean showWithParent;
- int toolTipHandle, lpstrTip;
- Control lastActive;
- SHACTIVATEINFO psai;
- static final int DialogProc;
- static final TCHAR DialogClass = new TCHAR (0, OS.IsWinCE ? "Dialog" : "#32770", true);
- 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);
- }
- 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_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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 SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 (Shell parent, int style) {
- this (parent != null ? parent.getDisplay () : 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
- *
- * @private
- */
-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 callWindowProc (int msg, int wParam, int lParam) {
- if (parent != null) {
- if (handle == 0) return 0;
- switch (msg) {
- case OS.WM_KILLFOCUS:
- case OS.WM_SETFOCUS:
- return OS.DefWindowProc (handle, msg, wParam, lParam);
- }
- return OS.CallWindowProc (DialogProc, handle, msg, wParam, lParam);
- }
- return super.callWindowProc (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 #dispose
- */
-public void close () {
- checkWidget ();
- OS.PostMessage (handle, OS.WM_CLOSE, 0, 0);
-}
-
-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;
- }
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- 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);
- }
-}
-
-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 ();
-}
-
-int findBrush (int pixel) {
- if (pixel == OS.GetSysColor (OS.COLOR_BTNFACE)) {
- return OS.GetSysColorBrush (OS.COLOR_BTNFACE);
- }
- if (pixel == OS.GetSysColor (OS.COLOR_WINDOW)) {
- return OS.GetSysColorBrush (OS.COLOR_WINDOW);
- }
- if (brushes == null) brushes = new int [4];
- 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);
- if (logBrush.lbColor == pixel) return hBrush;
- }
- int length = brushes.length;
- int hBrush = brushes [--length];
- if (hBrush != 0) OS.DeleteObject (hBrush);
- System.arraycopy (brushes, 0, brushes, 1, length);
- brushes [0] = hBrush = OS.CreateSolidBrush (pixel);
- return hBrush;
-}
-
-int findCursor () {
- return hCursor;
-}
-
-/**
- * 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) 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 ();
- 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);
-}
-
-public Display getDisplay () {
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return display;
-}
-
-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);
-}
-
-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 boolean isEnabled () {
- checkWidget ();
- return getEnabled ();
-}
-
-/**
- * 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,
- * and sets focus to its default button (if it has one)
- * 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 ();
- /*
- * 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);
- /*
- * 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 until a new icon is set into the
- * window or the window text is changed. The fix is to call
- * PeekMessage() with the flag PM_NOREMOVE to touch the event
- * queue but not dispatch events.
- */
- MSG msg = new MSG ();
- OS.PeekMessage (msg, 0, 0, 0, OS.PM_NOREMOVE);
- if (!restoreFocus ()) traverseGroup (true);
-}
-
-void releaseShells () {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.releaseResources ();
- }
-}
-
-void releaseWidget () {
- releaseShells ();
- super.releaseWidget ();
- activeMenu = null;
- display.clearModal (this);
- display = null;
- if (lpstrTip != 0) {
- int hHeap = OS.GetProcessHeap ();
- OS.HeapFree (hHeap, 0, lpstrTip);
- }
- lpstrTip = 0;
- toolTipHandle = 0;
- if (brushes != null) {
- for (int i=0; i<brushes.length; i++) {
- int hBrush = brushes [i];
- if (hBrush != 0) OS.DeleteObject (hBrush);
- }
- }
- brushes = null;
- if (OS.IsDBLocale) {
- if (hIMC != 0) OS.ImmDestroyContext (hIMC);
- }
- lastActive = null;
-}
-
-void remove (Menu menu) {
- super.remove (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;
-}
-
-/**
- * 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) 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 ();
-}
-
-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) {
- if (OS.IsWinCE) {
- swFlags = OS.SW_RESTORE;
- if ((style & SWT.NO_TRIM) == 0) {
- /* Set the WS_CAPTION bits when no longer maximized */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.WS_CAPTION) != OS.WS_CAPTION) {
- bits |= OS.WS_CAPTION;
- OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
- }
- }
- } else {
- if (OS.IsIconic (handle) || OS.IsZoomed (handle)) {
- setPlacement (x, y, width, height, flags);
- return;
- }
- }
- OS.SetWindowPos (handle, 0, x, y, width, height, flags);
-}
-
-public void setEnabled (boolean enabled) {
- checkWidget ();
- state &= ~DISABLED;
- if (!enabled) state |= DISABLED;
- if (!Display.TrimEnabled) {
- super.setEnabled (enabled);
- } else {
- if (isActive ()) setItemEnabled (OS.SC_CLOSE, enabled);
- }
-}
-
-/**
- * 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);
-}
-
-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 */
-}
-
-void setToolTipText (int hwnd, String text) {
- if (OS.IsWinCE) return;
- if (toolTipHandle == 0) {
- 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);
- /*
- * 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);
- }
- TOOLINFO lpti = new TOOLINFO ();
- lpti.cbSize = TOOLINFO.sizeof;
- lpti.uId = hwnd;
- lpti.hwnd = handle;
- if (text == null) {
- OS.SendMessage (toolTipHandle, OS.TTM_DELTOOL, 0, lpti);
- } else {
- lpti.uFlags = OS.TTF_IDISHWND | OS.TTF_SUBCLASS;
- lpti.lpszText = OS.LPSTR_TEXTCALLBACK;
- OS.SendMessage (toolTipHandle, OS.TTM_ADDTOOL, 0, lpti);
- }
- OS.SendMessage (toolTipHandle, OS.TTM_UPDATE, 0, 0);
-}
-
-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 ();
- super.setVisible (visible);
- if (showWithParent == visible) return;
- showWithParent = visible;
- if (!OS.IsWinCE) OS.ShowOwnedPopups (handle, visible);
- 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 ();
- 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 ();
- }
-}
-
-boolean traverseEscape () {
- if (parent == null) return false;
- if (!isVisible () || !isEnabled ()) return false;
- close ();
- return true;
-}
-
-void updateModal () {
- if (!Display.TrimEnabled) {
- super.setEnabled (isActive ());
- } else {
- setItemEnabled (OS.SC_CLOSE, isActive ());
- }
-}
-
-int widgetExtStyle () {
- int bits = super.widgetExtStyle ();
- /*
- * Bug in Windows 98 and NT. Creating a window with the
- * WS_EX_TOPMOST extendes 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 dialog 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 (OS.IsWin95) return bits;
- if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {
- return bits;
- }
- if ((style & SWT.ON_TOP) != 0) bits |= OS.WS_EX_TOPMOST;
- return bits;
-}
-
-TCHAR windowClass () {
- if (OS.IsSP) return DialogClass;
- return parent != null ? DialogClass : super.windowClass ();
-}
-
-int windowProc () {
- if (OS.IsSP) return DialogProc;
- return parent != null ? DialogProc : super.windowProc ();
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () & ~OS.WS_POPUP;
- 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 ourselves
- * when the Shell is deactivated.
- *
- * Note. When the Shell is reactivated, the text in the
- * composition window has been lost.
- */
- if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) >= (5 << 16 | 1)) {
- if ((wParam & 0xFFFF) == 0 && OS.IsDBLocale && hIMC != 0) {
- OS.ImmSetOpenStatus (hIMC, false);
- }
- }
-
- LRESULT result = super.WM_ACTIVATE (wParam, lParam);
- if (parent != null) return LRESULT.ZERO;
- return result;
-}
-
-LRESULT WM_CLOSE (int wParam, int lParam) {
- if ((Display.TrimEnabled && !isEnabled ()) || !isActive ()) {
- return LRESULT.ZERO;
- }
- return super.WM_CLOSE (wParam, lParam);
-}
-
-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;
- }
- }
- /*
- * Note in WinCE PPC. Menu events originate from the command bar.
- */
- if (OS.IsPPC || OS.IsSP) {
- if (menuBar != null) {
- int hwndCB = menuBar.hwndCB;
- if (hwndCB != 0 && lParam == hwndCB) {
- 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) {
- releaseChild ();
- releaseResources ();
- }
- return result;
-}
-
-LRESULT WM_MOUSEACTIVATE (int wParam, int lParam) {
- LRESULT result = super.WM_MOUSEACTIVATE (wParam, lParam);
- if (result != null) return result;
- int hittest = lParam & 0xFFFF;
- 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);
- setActiveControl (control);
- /*
- * This code is intentionally commented. On some platforms,
- * shells that are created with SWT.NO_TRIM won't take focus
- * when the user clicks in the client area or on the border.
- * This behavior is usedful when emulating tool tip shells
- * Until this behavior is specified, this code will remain
- * commented.
- */
-// if ((style & SWT.NO_TRIM) != 0) {
-// if (hittest == OS.HTBORDER || hittest == OS.HTCLIENT) {
-// return new LRESULT (OS.MA_NOACTIVATE);
-// }
-// }
- return null;
-}
-
-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 (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 (OS.WM_NCHITTEST, wParam, lParam);
- if (hittest == OS.HTMENU) hittest = OS.HTBORDER;
- return new LRESULT (hittest);
- }
- return null;
-}
-
-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 = 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 (WidgetTable.get (hwndPopup) == null) {
- if (OS.IsWindowEnabled (hwndPopup)) {
- OS.SetActiveWindow (hwndPopup);
- }
- }
- }
- }
- }
- }
- 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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>
+ * 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
+ * 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>.
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE</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 {
+ Display display;
+ Menu activeMenu;
+ int hIMC;
+ int [] brushes;
+ boolean showWithParent;
+ int toolTipHandle, lpstrTip;
+ Control lastActive;
+ SHACTIVATEINFO psai;
+ static final int DialogProc;
+ static final TCHAR DialogClass = new TCHAR (0, OS.IsWinCE ? "Dialog" : "#32770", true);
+ 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);
+ }
+ 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_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if 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 SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 (Shell parent, int style) {
+ this (parent != null ? parent.getDisplay () : 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
+ *
+ * @private
+ */
+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 callWindowProc (int msg, int wParam, int lParam) {
+ if (parent != null) {
+ if (handle == 0) return 0;
+ switch (msg) {
+ case OS.WM_KILLFOCUS:
+ case OS.WM_SETFOCUS:
+ return OS.DefWindowProc (handle, msg, wParam, lParam);
+ }
+ return OS.CallWindowProc (DialogProc, handle, msg, wParam, lParam);
+ }
+ return super.callWindowProc (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 #dispose
+ */
+public void close () {
+ checkWidget ();
+ OS.PostMessage (handle, OS.WM_CLOSE, 0, 0);
+}
+
+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;
+ }
+ OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
+ 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);
+ }
+}
+
+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 ();
+}
+
+int findBrush (int pixel) {
+ if (pixel == OS.GetSysColor (OS.COLOR_BTNFACE)) {
+ return OS.GetSysColorBrush (OS.COLOR_BTNFACE);
+ }
+ if (pixel == OS.GetSysColor (OS.COLOR_WINDOW)) {
+ return OS.GetSysColorBrush (OS.COLOR_WINDOW);
+ }
+ if (brushes == null) brushes = new int [4];
+ 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);
+ if (logBrush.lbColor == pixel) return hBrush;
+ }
+ int length = brushes.length;
+ int hBrush = brushes [--length];
+ if (hBrush != 0) OS.DeleteObject (hBrush);
+ System.arraycopy (brushes, 0, brushes, 1, length);
+ brushes [0] = hBrush = OS.CreateSolidBrush (pixel);
+ return hBrush;
+}
+
+int findCursor () {
+ return hCursor;
+}
+
+/**
+ * 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) 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 ();
+ 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);
+}
+
+public Display getDisplay () {
+ if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return display;
+}
+
+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);
+}
+
+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 boolean isEnabled () {
+ checkWidget ();
+ return getEnabled ();
+}
+
+/**
+ * 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,
+ * and sets focus to its default button (if it has one)
+ * 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 ();
+ /*
+ * 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);
+ /*
+ * 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 until a new icon is set into the
+ * window or the window text is changed. The fix is to call
+ * PeekMessage() with the flag PM_NOREMOVE to touch the event
+ * queue but not dispatch events.
+ */
+ MSG msg = new MSG ();
+ OS.PeekMessage (msg, 0, 0, 0, OS.PM_NOREMOVE);
+ if (!restoreFocus ()) traverseGroup (true);
+}
+
+void releaseShells () {
+ Shell [] shells = getShells ();
+ for (int i=0; i<shells.length; i++) {
+ Shell shell = shells [i];
+ if (!shell.isDisposed ()) shell.releaseResources ();
+ }
+}
+
+void releaseWidget () {
+ releaseShells ();
+ super.releaseWidget ();
+ activeMenu = null;
+ display.clearModal (this);
+ display = null;
+ if (lpstrTip != 0) {
+ int hHeap = OS.GetProcessHeap ();
+ OS.HeapFree (hHeap, 0, lpstrTip);
+ }
+ lpstrTip = 0;
+ toolTipHandle = 0;
+ if (brushes != null) {
+ for (int i=0; i<brushes.length; i++) {
+ int hBrush = brushes [i];
+ if (hBrush != 0) OS.DeleteObject (hBrush);
+ }
+ }
+ brushes = null;
+ if (OS.IsDBLocale) {
+ if (hIMC != 0) OS.ImmDestroyContext (hIMC);
+ }
+ lastActive = null;
+}
+
+void remove (Menu menu) {
+ super.remove (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;
+}
+
+/**
+ * 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) 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 ();
+}
+
+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) {
+ if (OS.IsWinCE) {
+ swFlags = OS.SW_RESTORE;
+ if ((style & SWT.NO_TRIM) == 0) {
+ /* Set the WS_CAPTION bits when no longer maximized */
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & OS.WS_CAPTION) != OS.WS_CAPTION) {
+ bits |= OS.WS_CAPTION;
+ OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
+ }
+ }
+ } else {
+ if (OS.IsIconic (handle) || OS.IsZoomed (handle)) {
+ setPlacement (x, y, width, height, flags);
+ return;
+ }
+ }
+ OS.SetWindowPos (handle, 0, x, y, width, height, flags);
+}
+
+public void setEnabled (boolean enabled) {
+ checkWidget ();
+ state &= ~DISABLED;
+ if (!enabled) state |= DISABLED;
+ if (!Display.TrimEnabled) {
+ super.setEnabled (enabled);
+ } else {
+ if (isActive ()) setItemEnabled (OS.SC_CLOSE, enabled);
+ }
+}
+
+/**
+ * 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);
+}
+
+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 */
+}
+
+void setToolTipText (int hwnd, String text) {
+ if (OS.IsWinCE) return;
+ if (toolTipHandle == 0) {
+ 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);
+ /*
+ * 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);
+ }
+ TOOLINFO lpti = new TOOLINFO ();
+ lpti.cbSize = TOOLINFO.sizeof;
+ lpti.uId = hwnd;
+ lpti.hwnd = handle;
+ if (text == null) {
+ OS.SendMessage (toolTipHandle, OS.TTM_DELTOOL, 0, lpti);
+ } else {
+ lpti.uFlags = OS.TTF_IDISHWND | OS.TTF_SUBCLASS;
+ lpti.lpszText = OS.LPSTR_TEXTCALLBACK;
+ OS.SendMessage (toolTipHandle, OS.TTM_ADDTOOL, 0, lpti);
+ }
+ OS.SendMessage (toolTipHandle, OS.TTM_UPDATE, 0, 0);
+}
+
+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 ();
+ super.setVisible (visible);
+ if (showWithParent == visible) return;
+ showWithParent = visible;
+ if (!OS.IsWinCE) OS.ShowOwnedPopups (handle, visible);
+ 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 ();
+ 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 ();
+ }
+}
+
+boolean traverseEscape () {
+ if (parent == null) return false;
+ if (!isVisible () || !isEnabled ()) return false;
+ close ();
+ return true;
+}
+
+void updateModal () {
+ if (!Display.TrimEnabled) {
+ super.setEnabled (isActive ());
+ } else {
+ setItemEnabled (OS.SC_CLOSE, isActive ());
+ }
+}
+
+int widgetExtStyle () {
+ int bits = super.widgetExtStyle ();
+ /*
+ * Bug in Windows 98 and NT. Creating a window with the
+ * WS_EX_TOPMOST extendes 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 dialog 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 (OS.IsWin95) return bits;
+ if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {
+ return bits;
+ }
+ if ((style & SWT.ON_TOP) != 0) bits |= OS.WS_EX_TOPMOST;
+ return bits;
+}
+
+TCHAR windowClass () {
+ if (OS.IsSP) return DialogClass;
+ return parent != null ? DialogClass : super.windowClass ();
+}
+
+int windowProc () {
+ if (OS.IsSP) return DialogProc;
+ return parent != null ? DialogProc : super.windowProc ();
+}
+
+int widgetStyle () {
+ int bits = super.widgetStyle () & ~OS.WS_POPUP;
+ 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 ourselves
+ * when the Shell is deactivated.
+ *
+ * Note. When the Shell is reactivated, the text in the
+ * composition window has been lost.
+ */
+ if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) >= (5 << 16 | 1)) {
+ if ((wParam & 0xFFFF) == 0 && OS.IsDBLocale && hIMC != 0) {
+ OS.ImmSetOpenStatus (hIMC, false);
+ }
+ }
+
+ LRESULT result = super.WM_ACTIVATE (wParam, lParam);
+ if (parent != null) return LRESULT.ZERO;
+ return result;
+}
+
+LRESULT WM_CLOSE (int wParam, int lParam) {
+ if ((Display.TrimEnabled && !isEnabled ()) || !isActive ()) {
+ return LRESULT.ZERO;
+ }
+ return super.WM_CLOSE (wParam, lParam);
+}
+
+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;
+ }
+ }
+ /*
+ * Note in WinCE PPC. Menu events originate from the command bar.
+ */
+ if (OS.IsPPC || OS.IsSP) {
+ if (menuBar != null) {
+ int hwndCB = menuBar.hwndCB;
+ if (hwndCB != 0 && lParam == hwndCB) {
+ 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) {
+ releaseChild ();
+ releaseResources ();
+ }
+ return result;
+}
+
+LRESULT WM_MOUSEACTIVATE (int wParam, int lParam) {
+ LRESULT result = super.WM_MOUSEACTIVATE (wParam, lParam);
+ if (result != null) return result;
+ int hittest = lParam & 0xFFFF;
+ 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);
+ setActiveControl (control);
+ /*
+ * This code is intentionally commented. On some platforms,
+ * shells that are created with SWT.NO_TRIM won't take focus
+ * when the user clicks in the client area or on the border.
+ * This behavior is usedful when emulating tool tip shells
+ * Until this behavior is specified, this code will remain
+ * commented.
+ */
+// if ((style & SWT.NO_TRIM) != 0) {
+// if (hittest == OS.HTBORDER || hittest == OS.HTCLIENT) {
+// return new LRESULT (OS.MA_NOACTIVATE);
+// }
+// }
+ return null;
+}
+
+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 (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 (OS.WM_NCHITTEST, wParam, lParam);
+ if (hittest == OS.HTMENU) hittest = OS.HTBORDER;
+ return new LRESULT (hittest);
+ }
+ return null;
+}
+
+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 = 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 (WidgetTable.get (hwndPopup) == null) {
+ if (OS.IsWindowEnabled (hwndPopup)) {
+ OS.SetActiveWindow (hwndPopup);
+ }
+ }
+ }
+ }
+ }
+ }
+ 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;
+}
+
+}
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
index c1c0bf52d2..8406073f3f 100755
--- 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
@@ -1,799 +1,799 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 <em>selection</em> 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;
- 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>0</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 msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (ScrollBarProc, handle, 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);
-}
-
-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 single <em>selection</em> 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;
- 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 post a fake WM_SETFOCUS to
- * get the scroll bar to recompute the size of the flashing cursor.
- */
- if (OS.GetFocus () == handle) {
- OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0);
- }
-}
-
-public void setEnabled (boolean enabled) {
- checkWidget ();
- if (OS.IsWinCE) {
- super.setEnabled (enabled);
- } else {
- int flags = enabled ? OS.ESB_ENABLE_BOTH : OS.ESB_DISABLE_BOTH;
- OS.EnableScrollBar (handle, OS.SB_CTL, flags);
- }
- state &= ~DISABLED;
- if (!enabled) 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 value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new maximum (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 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;
- OS.SetScrollInfo (handle, OS.SB_CTL, info, (state & DISABLED) == 0);
-
- /*
- * 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) {
- if (OS.IsWinCE) {
- OS.EnableWindow (handle, false);
- } else {
- 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 post a fake WM_SETFOCUS to
- * get the scroll bar to recompute the size of the flashing cursor.
- */
- if (OS.GetFocus () == handle) {
- OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0);
- }
-}
-
-/**
- * Sets the minimum value which the receiver will allow
- * to be the argument which must be greater than or
- * equal to zero.
- *
- * @param value the new minimum (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 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;
- OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
-
- /*
- * 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) {
- if (OS.IsWinCE) {
- OS.EnableWindow (handle, false);
- } else {
- 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 post a fake WM_SETFOCUS to
- * get the scroll bar to recompute the size of the flashing cursor.
- */
- if (OS.GetFocus () == handle) {
- OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 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.
- *
- * @return the page increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setPageIncrement (int value) {
- checkWidget ();
- if (value < 1) return;
- pageIncrement = value;
-}
-
-/**
- * Sets the single <em>selection</em> that is the receiver's
- * value to the argument which must be greater than or equal
- * to zero.
- *
- * @param 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;
- OS.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 to the
- * argument which must be at least one.
- *
- * @param value the new thumb value (must be at least 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 ScrollBar
- */
-public void setThumb (int value) {
- checkWidget ();
-
- /* Position the thumb */
- 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);
- if (info.nMax - info.nMin - value < 0) return;
- info.nPage = value;
- if (info.nPage != 0) info.nPage++;
- OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
-
- /*
- * 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) {
- if (OS.IsWinCE) {
- OS.EnableWindow (handle, false);
- } else {
- 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 post a fake WM_SETFOCUS to
- * get the scroll bar to recompute the size of the flashing cursor.
- */
- if (OS.GetFocus () == handle) {
- OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0);
- }
-}
-
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is equivalent 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 (maximum - minimum - thumb < 0) 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++;
- OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
-
- /*
- * 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) {
- if (OS.IsWinCE) {
- OS.EnableWindow (handle, false);
- } else {
- 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 post a fake WM_SETFOCUS to
- * get the scroll bar to recompute the size of the flashing cursor.
- */
- if (OS.GetFocus () == handle) {
- OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0);
- }
-}
-
-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_LBUTTONDBLCLK (int wParam, int lParam) {
-
- /*
- * Feature in Windows. For some reason, capturing
- * the mouse after processing WM_LBUTTONDBLCLK for the
- * widget interferes with the normal mouse processing
- * for the widget. The fix is to avoid the automatic
- * mouse capture.
- */
-
- /*
- * 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 hwndCapture = OS.GetCapture ();
- 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);
- OS.SetWindowLong (handle, OS.GWL_STYLE, oldBits);
- if (OS.GetCapture () != hwndCapture) OS.SetCapture (hwndCapture);
- return result;
-}
-
-LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
-
- /*
- * Feature in Windows. For some reason, capturing
- * the mouse after processing WM_LBUTTONDOWN for the
- * widget interferes with the normal mouse processing
- * for the widget. The fix is to avoid the automatic
- * mouse capture.
- */
-
- /*
- * 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 hwndCapture = OS.GetCapture ();
- 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);
- OS.SetWindowLong (handle, OS.GWL_STYLE, oldBits);
- if (OS.GetCapture () != hwndCapture) OS.SetCapture (hwndCapture);
- return result;
-}
-
-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:
- /*
- * Do not set the detail field to DRAG to
- * indicate that the dragging has ended.
- */
- 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);
-
- /*
- * 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);
- // the widget could be destroyed at this point
- return null;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 <em>selection</em> 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;
+ 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>0</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 msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (ScrollBarProc, handle, 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);
+}
+
+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 single <em>selection</em> 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;
+ 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 post a fake WM_SETFOCUS to
+ * get the scroll bar to recompute the size of the flashing cursor.
+ */
+ if (OS.GetFocus () == handle) {
+ OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0);
+ }
+}
+
+public void setEnabled (boolean enabled) {
+ checkWidget ();
+ if (OS.IsWinCE) {
+ super.setEnabled (enabled);
+ } else {
+ int flags = enabled ? OS.ESB_ENABLE_BOTH : OS.ESB_DISABLE_BOTH;
+ OS.EnableScrollBar (handle, OS.SB_CTL, flags);
+ }
+ state &= ~DISABLED;
+ if (!enabled) 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 value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new maximum (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 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;
+ OS.SetScrollInfo (handle, OS.SB_CTL, info, (state & DISABLED) == 0);
+
+ /*
+ * 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) {
+ if (OS.IsWinCE) {
+ OS.EnableWindow (handle, false);
+ } else {
+ 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 post a fake WM_SETFOCUS to
+ * get the scroll bar to recompute the size of the flashing cursor.
+ */
+ if (OS.GetFocus () == handle) {
+ OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0);
+ }
+}
+
+/**
+ * Sets the minimum value which the receiver will allow
+ * to be the argument which must be greater than or
+ * equal to zero.
+ *
+ * @param value the new minimum (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 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;
+ OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
+
+ /*
+ * 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) {
+ if (OS.IsWinCE) {
+ OS.EnableWindow (handle, false);
+ } else {
+ 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 post a fake WM_SETFOCUS to
+ * get the scroll bar to recompute the size of the flashing cursor.
+ */
+ if (OS.GetFocus () == handle) {
+ OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 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.
+ *
+ * @return the page increment (must be greater than zero)
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setPageIncrement (int value) {
+ checkWidget ();
+ if (value < 1) return;
+ pageIncrement = value;
+}
+
+/**
+ * Sets the single <em>selection</em> that is the receiver's
+ * value to the argument which must be greater than or equal
+ * to zero.
+ *
+ * @param 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;
+ OS.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 to the
+ * argument which must be at least one.
+ *
+ * @param value the new thumb value (must be at least 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 ScrollBar
+ */
+public void setThumb (int value) {
+ checkWidget ();
+
+ /* Position the thumb */
+ 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);
+ if (info.nMax - info.nMin - value < 0) return;
+ info.nPage = value;
+ if (info.nPage != 0) info.nPage++;
+ OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
+
+ /*
+ * 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) {
+ if (OS.IsWinCE) {
+ OS.EnableWindow (handle, false);
+ } else {
+ 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 post a fake WM_SETFOCUS to
+ * get the scroll bar to recompute the size of the flashing cursor.
+ */
+ if (OS.GetFocus () == handle) {
+ OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0);
+ }
+}
+
+/**
+ * Sets the receiver's selection, minimum value, maximum
+ * value, thumb, increment and page increment all at once.
+ * <p>
+ * Note: This is equivalent 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 (maximum - minimum - thumb < 0) 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++;
+ OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
+
+ /*
+ * 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) {
+ if (OS.IsWinCE) {
+ OS.EnableWindow (handle, false);
+ } else {
+ 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 post a fake WM_SETFOCUS to
+ * get the scroll bar to recompute the size of the flashing cursor.
+ */
+ if (OS.GetFocus () == handle) {
+ OS.PostMessage (handle, OS.WM_SETFOCUS, 0, 0);
+ }
+}
+
+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_LBUTTONDBLCLK (int wParam, int lParam) {
+
+ /*
+ * Feature in Windows. For some reason, capturing
+ * the mouse after processing WM_LBUTTONDBLCLK for the
+ * widget interferes with the normal mouse processing
+ * for the widget. The fix is to avoid the automatic
+ * mouse capture.
+ */
+
+ /*
+ * 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 hwndCapture = OS.GetCapture ();
+ 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);
+ OS.SetWindowLong (handle, OS.GWL_STYLE, oldBits);
+ if (OS.GetCapture () != hwndCapture) OS.SetCapture (hwndCapture);
+ return result;
+}
+
+LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
+
+ /*
+ * Feature in Windows. For some reason, capturing
+ * the mouse after processing WM_LBUTTONDOWN for the
+ * widget interferes with the normal mouse processing
+ * for the widget. The fix is to avoid the automatic
+ * mouse capture.
+ */
+
+ /*
+ * 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 hwndCapture = OS.GetCapture ();
+ 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);
+ OS.SetWindowLong (handle, OS.GWL_STYLE, oldBits);
+ if (OS.GetCapture () != hwndCapture) OS.SetCapture (hwndCapture);
+ return result;
+}
+
+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:
+ /*
+ * Do not set the detail field to DRAG to
+ * indicate that the dragging has ended.
+ */
+ 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);
+
+ /*
+ * 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);
+ // the widget could be destroyed at this point
+ return null;
+}
+
+}
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
index 2bc870aabc..976e89f79f 100755
--- 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
@@ -1,792 +1,792 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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>(none)</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 TabFolder extends Composite {
- TabItem [] items;
- ImageList imageList;
- static final int TabFolderProc;
- static final TCHAR TabFolderClass = new TCHAR (0, "SWT_" + OS.WC_TABCONTROL, true);
- static {
- /*
- * 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.
- */
- WNDCLASS lpWndClass = new WNDCLASS ();
- TCHAR WC_TABCONTROL = new TCHAR (0, OS.WC_TABCONTROL, true);
- OS.GetClassInfo (0, WC_TABCONTROL, lpWndClass);
- TabFolderProc = lpWndClass.lpfnWndProc;
- int hInstance = OS.GetModuleHandle (null);
- if (!OS.GetClassInfo (hInstance, TabFolderClass, lpWndClass)) {
- int hHeap = OS.GetProcessHeap ();
- lpWndClass.hInstance = hInstance;
- lpWndClass.style &= ~(OS.CS_HREDRAW | OS.CS_VREDRAW);
- 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 msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (TabFolderProc, 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);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- RECT insetRect = new RECT (), itemRect = new RECT ();
- OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 0, insetRect);
- int width = insetRect.left - insetRect.right, height = 0;
- 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);
- }
- Point size = null;
- if (layout != null) {
- size = layout.computeSize (this, wHint, hHint, 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 ();
- 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;
- /*
- * 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 display = getDisplay ();
- display.releaseImageList (imageList);
- }
- imageList = null;
- items = new TabItem [4];
- }
- if (count > 0 && index == selectionIndex) {
- setSelection (Math.max (0, selectionIndex - 1));
- selectionIndex = getSelectionIndex ();
- if (selectionIndex != -1) {
- Event event = new Event ();
- event.item = items [selectionIndex];
- sendEvent (SWT.Selection, event);
- // the widget could be destroyed at this point
- }
- }
-}
-
-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 = getDisplay ().getImageList (new Point (bounds.width, bounds.height));
- int index = imageList.indexOf (image);
- if (index == -1) 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) return index;
- return imageList.add (image);
-}
-
-/**
- * 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 (setFocus ()) {
- 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 releaseWidget () {
- int count = OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<count; i++) {
- TabItem item = items [i];
- if (!item.isDisposed ()) item.releaseResources ();
- }
- items = null;
- if (imageList != null) {
- OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, 0);
- Display display = getDisplay ();
- display.releaseImageList (imageList);
- }
- imageList = null;
- super.releaseWidget ();
-}
-
-/**
- * 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 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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);
- return;
- }
- for (int i=items.length-1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) setSelection (index);
- }
-}
-
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current selected 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 ();
- 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 == 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 index == getSelectionIndex ();
-}
-
-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;
- 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_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;
- }
- 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);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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>(none)</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 TabFolder extends Composite {
+ TabItem [] items;
+ ImageList imageList;
+ static final int TabFolderProc;
+ static final TCHAR TabFolderClass = new TCHAR (0, "SWT_" + OS.WC_TABCONTROL, true);
+ static {
+ /*
+ * 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.
+ */
+ WNDCLASS lpWndClass = new WNDCLASS ();
+ TCHAR WC_TABCONTROL = new TCHAR (0, OS.WC_TABCONTROL, true);
+ OS.GetClassInfo (0, WC_TABCONTROL, lpWndClass);
+ TabFolderProc = lpWndClass.lpfnWndProc;
+ int hInstance = OS.GetModuleHandle (null);
+ if (!OS.GetClassInfo (hInstance, TabFolderClass, lpWndClass)) {
+ int hHeap = OS.GetProcessHeap ();
+ lpWndClass.hInstance = hInstance;
+ lpWndClass.style &= ~(OS.CS_HREDRAW | OS.CS_VREDRAW);
+ 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 msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (TabFolderProc, 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);
+}
+
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ checkWidget ();
+ RECT insetRect = new RECT (), itemRect = new RECT ();
+ OS.SendMessage (handle, OS.TCM_ADJUSTRECT, 0, insetRect);
+ int width = insetRect.left - insetRect.right, height = 0;
+ 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);
+ }
+ Point size = null;
+ if (layout != null) {
+ size = layout.computeSize (this, wHint, hHint, 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 ();
+ 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;
+ /*
+ * 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 display = getDisplay ();
+ display.releaseImageList (imageList);
+ }
+ imageList = null;
+ items = new TabItem [4];
+ }
+ if (count > 0 && index == selectionIndex) {
+ setSelection (Math.max (0, selectionIndex - 1));
+ selectionIndex = getSelectionIndex ();
+ if (selectionIndex != -1) {
+ Event event = new Event ();
+ event.item = items [selectionIndex];
+ sendEvent (SWT.Selection, event);
+ // the widget could be destroyed at this point
+ }
+ }
+}
+
+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 = getDisplay ().getImageList (new Point (bounds.width, bounds.height));
+ int index = imageList.indexOf (image);
+ if (index == -1) 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) return index;
+ return imageList.add (image);
+}
+
+/**
+ * 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 (setFocus ()) {
+ 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 releaseWidget () {
+ int count = OS.SendMessage (handle, OS.TCM_GETITEMCOUNT, 0, 0);
+ for (int i=0; i<count; i++) {
+ TabItem item = items [i];
+ if (!item.isDisposed ()) item.releaseResources ();
+ }
+ items = null;
+ if (imageList != null) {
+ OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, 0);
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
+ }
+ imageList = null;
+ super.releaseWidget ();
+}
+
+/**
+ * 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 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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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);
+ return;
+ }
+ for (int i=items.length-1; i>=0; --i) {
+ int index = indexOf (items [i]);
+ if (index != -1) setSelection (index);
+ }
+}
+
+/**
+ * Selects the item at the given zero-relative index in the receiver.
+ * If the item at the index was already selected, it remains selected.
+ * The current selected 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 ();
+ 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 == 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 index == getSelectionIndex ();
+}
+
+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;
+ 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_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;
+ }
+ 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
index aed5113e03..0897a591e4 100755
--- 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
@@ -1,317 +1,317 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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);
-}
-
-/**
- * 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;
-}
-
-public Display getDisplay () {
- TabFolder parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/**
- * 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 releaseChild () {
- super.releaseChild ();
- int index = parent.indexOf (this);
- if (index == parent.getSelectionIndex ()) {
- if (control != null) control.setVisible (false);
- }
- parent.destroyItem (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- control = null;
- parent = 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.
- */
- if (COMCTL32_MAJOR >= 6) {
- if (text.indexOf ('&') != -1) setText (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);
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setText (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 (COMCTL32_MAJOR >= 6 && image != null) {
- if (text.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);
-}
-
-/**
- * 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;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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);
+}
+
+/**
+ * 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;
+}
+
+public Display getDisplay () {
+ TabFolder parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+/**
+ * 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 releaseChild () {
+ super.releaseChild ();
+ int index = parent.indexOf (this);
+ if (index == parent.getSelectionIndex ()) {
+ if (control != null) control.setVisible (false);
+ }
+ parent.destroyItem (this);
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ control = null;
+ parent = 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.
+ */
+ if (COMCTL32_MAJOR >= 6) {
+ if (text.indexOf ('&') != -1) setText (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);
+ int index = parent.indexOf (this);
+ if (index == -1) return;
+ super.setText (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 (COMCTL32_MAJOR >= 6 && image != null) {
+ if (text.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);
+}
+
+/**
+ * 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
index 2d2672afb6..9107f61958 100755
--- 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
@@ -1,2512 +1,2512 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 issue
- * notificiation when selected.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>TableItem</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</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection</dd>
- * </dl>
- * <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;
- ImageList imageList;
- boolean ignoreSelect, dragStarted, ignoreResize, mouseDown, customDraw;
- 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 Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Table (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the 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 reciever 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 msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (TableProc, handle, msg, wParam, lParam);
-}
-
-static int checkStyle (int style) {
- /*
- * 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);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int bits = 0;
- if (wHint != SWT.DEFAULT) {
- bits |= wHint & 0xFFFF;
- } else {
- int width = 0;
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 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;
- }
- if (hHint != SWT.DEFAULT) bits |= hHint << 16;
- int result = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, -1, bits);
- int width = result & 0xFFFF, height = result >> 16;
- 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;
- /*
- * Feature in Windows. For some reason, LVM_APPROXIMATEVIEWRECT
- * does not include the space for the vertical scroll bar but does
- * take into account the horizontal scroll bar when calculating the
- * space needed to show the items. The fix is to add in this space.
- */
- if ((style & SWT.V_SCROLL) != 0) {
- width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- }
- if (((style & SWT.H_SCROLL) != 0) && (hHint != SWT.DEFAULT)) {
- height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- }
- return new Point (width, height);
-}
-
-void createHandle () {
- super.createHandle ();
- state &= ~CANVAS;
-
- /*
- * 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);
- }
-
- /*
- * 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;
- 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 bits = OS.LVS_EX_SUBITEMIMAGES | OS.LVS_EX_LABELTIP;
- if ((style & SWT.FULL_SELECTION) != 0) bits |= OS.LVS_EX_FULLROWSELECT;
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, bits);
-
- /*
- * 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_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) return;
- if ((style & SWT.RIGHT_TO_LEFT) != 0) {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int extStyle = OS.GetWindowLong (hwndHeader, OS.GWL_EXSTYLE);
- OS.SetWindowLong (hwndHeader, OS.GWL_EXSTYLE, extStyle | OS.WS_EX_LAYOUTRTL);
- }
-}
-
-void createItem (TableColumn column, int index) {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (count == 1 && columns [0] == null) count = 0;
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- if (count == columns.length) {
- TableColumn [] newColumns = new TableColumn [columns.length + 4];
- System.arraycopy (columns, 0, newColumns, 0, columns.length);
- columns = newColumns;
- }
- /*
- * 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, count - index);
- columns [index] = column;
- if (index == 0) {
- if (count > 0) {
- 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);
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE | OS.LVIF_STATE;
- int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<itemCount; i++) {
- lvItem.iItem = i;
- lvItem.iSubItem = 0;
- lvItem.pszText = pszText;
- lvItem.cchTextMax = cchTextMax;
- OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- lvItem.iSubItem = 1;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- lvItem.iSubItem = 0;
- lvItem.pszText = lvItem.cchTextMax = 0;
- lvItem.iImage = OS.I_IMAGENONE;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- items [i].text = "";
- items [i].image = null;
- }
- 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 {
- 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);
- }
-}
-
-void createItem (TableItem item, int index) {
- item.foreground = item.background = -1;
- int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
- if (count == items.length) {
- TableItem [] newItems = new TableItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- LVITEM lvItem = new LVITEM ();
- lvItem.iItem = index;
-
- /*
- * 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 image is created.
- */
- lvItem.iImage = OS.I_IMAGENONE;
- lvItem.mask = OS.LVIF_IMAGE;
-
- /* Set the initial unchecked state */
- if ((style & SWT.CHECK) != 0) {
- lvItem.mask = lvItem.mask | OS.TVIF_STATE;
- lvItem.state = 1 << 12;
- lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
- }
-
- /* Insert the item */
- 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;
-}
-
-void createWidget () {
- super.createWidget ();
- items = new TableItem [4];
- columns = new TableColumn [4];
-}
-
-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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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);
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_SELECTED;
- for (int i=0; i<indices.length; i++) {
- lvItem.iItem = indices [i];
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, 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 ();
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_SELECTED;
- lvItem.iItem = index;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, 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 ();
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_SELECTED;
- for (int i=start; i<=end; i++) {
- lvItem.iItem = i;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, 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;
- OS.SendMessage (handle, OS.LVM_SETITEMSTATE, -1, lvItem);
-}
-
-void destroyItem (TableColumn column) {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- int index = 0;
- while (index < count) {
- if (columns [index] == column) break;
- index++;
- }
- if (index == count) return;
- boolean first = false;
- if (index == 0) {
- first = true;
- if (count > 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_WIDTH;
- lvColumn.pszText = pszText;
- lvColumn.cchTextMax = cchTextMax;
- OS.SendMessage (handle, OS.LVM_GETCOLUMN, 1, lvColumn);
- lvColumn.mask |= OS.LVCF_FMT;
- lvColumn.fmt = OS.LVCFMT_LEFT;
- OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE | OS.LVIF_STATE;
- lvItem.pszText = pszText;
- lvItem.cchTextMax = cchTextMax;
- int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<itemCount; i++) {
- lvItem.iItem = i;
- lvItem.iSubItem = 1;
- OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- lvItem.iSubItem = 0;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- TCHAR buffer = new TCHAR (getCodePage (), cchTextMax);
- OS.MoveMemory (buffer, pszText, byteCount);
- items [i].text = buffer.toString (0, buffer.strlen ());
- if (imageList != null) {
- items [i].image = imageList.get (lvItem.iImage);
- }
- }
- 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;
- lvColumn.pszText = pszText;
- OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
- if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
- OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, OS.LVSCW_AUTOSIZE);
- }
- }
- if (count > 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, --count - index);
- columns [count] = null;
-}
-
-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;
- ignoreSelect = true;
- int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
- ignoreSelect = 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) {
- if (imageList != null) {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (columnCount == 1 && columns [0] == null) columnCount = 0;
- int i = 0;
- while (i < columnCount) {
- TableColumn column = columns [i];
- if (column.getImage () != null) break;
- i++;
- }
- if (i == columnCount) {
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
- Display display = getDisplay ();
- display.releaseImageList (imageList);
- imageList = null;
- }
- }
- customDraw = false;
- items = new TableItem [4];
- }
-}
-
-void fixCheckboxImageList () {
- /*
- * 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 hOldStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
- if (hOldStateList == 0) return;
- int [] stateCx = new int [1], stateCy = new int [1];
- OS.ImageList_GetIconSize (hOldStateList, stateCx, stateCy);
- if (cx [0] == stateCx [0] && cy [0] == stateCy [0]) return;
- setCheckboxImageList (cx [0], cy [0]);
-}
-
-int getBackgroundPixel () {
- return OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0);
-}
-
-/**
- * Returns the column at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- * 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>
- */
-public TableColumn getColumn (int index) {
- checkWidget ();
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (count == 1 && columns [0] == null) count = 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>TableColumn</code>s were created by the programmer,
- * this value is zero, despite the fact that visually, one column
- * of items is 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public int getColumnCount () {
- checkWidget ();
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (count == 1 && columns [0] == null) count = 0;
- return count;
-}
-
-/**
- * Returns an array of <code>TableColumn</code>s which are the
- * columns in the receiver. 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>
- */
-public TableColumn [] getColumns () {
- checkWidget ();
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (count == 1 && columns [0] == null) count = 0;
- TableColumn [] result = new TableColumn [count];
- System.arraycopy (columns, 0, result, 0, count);
- return result;
-}
-
-int getFocusIndex () {
- return OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
-}
-
-int getForegroundPixel () {
- return OS.SendMessage (handle, OS.LVM_GETTEXTCOLOR, 0, 0);
-}
-
-/**
- * Returns the width in pixels of a grid 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 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 ();
- 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 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 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 items [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 an 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];
- 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. 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++] = items [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 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 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.LVM_GETTOPINDEX, 0, 0);
-}
-
-int imageIndex (Image image) {
- if (image == null) return OS.I_IMAGENONE;
- if (imageList == null) {
- Rectangle bounds = image.getBounds ();
- imageList = getDisplay ().getImageList (new Point (bounds.width, bounds.height));
- int index = imageList.indexOf (image);
- if (index == -1) index = imageList.add (image);
- int hImageList = imageList.getHandle ();
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList);
- return index;
- }
- int index = imageList.indexOf (image);
- if (index != -1) return index;
- return imageList.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);
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- 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 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);
- for (int i=0; i<count; i++) {
- if (items [i] == item) 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 ();
- 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 releaseWidget () {
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (columnCount == 1 && columns [0] == null) columnCount = 0;
- for (int i=0; i<columnCount; i++) {
- TableColumn column = columns [i];
- if (!column.isDisposed ()) column.releaseResources ();
- }
- columns = null;
- int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
-
- /*
- * Feature in Windows. 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.
- *
- * NOTE: LVM_DELETEALLITEMS is also sent by the table
- * when the table is destroyed.
- */
- if (columnCount > 1) {
- /* Turn off redraw and leave it off */
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- for (int i=itemCount-1; i>=0; --i) {
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_DELETEITEM, i, 0);
- ignoreSelect = false;
- TableItem item = items [i];
- if (!item.isDisposed ()) item.releaseResources ();
- }
- } else {
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (!item.isDisposed ()) item.releaseResources ();
- }
- }
- customDraw = false;
- items = null;
- if (imageList != null) {
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
- Display display = getDisplay ();
- display.releaseImageList (imageList);
- }
- imageList = null;
- int hOldList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_STATE, 0);
- if (hOldList != 0) OS.ImageList_Destroy (hOldList);
- super.releaseWidget ();
-}
-
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] newIndices = new int [indices.length];
- System.arraycopy (indices, 0, newIndices, 0, indices.length);
- sort (newIndices);
- int last = -1;
- int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- for (int i=0; i<newIndices.length; i++) {
- int index = newIndices [i];
- if (index != last || i == 0) {
- ignoreSelect = true;
- int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
- ignoreSelect = false;
- if (code == 0) {
- if (0 <= index && index < count) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- } else {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
-
- // BUG - disposed callback could remove an item
- items [index].releaseResources ();
- System.arraycopy (items, index + 1, items, index, --count - index);
- items [count] = null;
- last = index;
- }
- }
-}
-
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove (int index) {
- checkWidget ();
- int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- ignoreSelect = true;
- int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
- ignoreSelect = false;
- if (code == 0) {
- if (0 <= index && index < count) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- } else {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
- TableItem item = items [index];
- System.arraycopy (items, index + 1, items, index, --count - index);
- items [count] = null;
- item.releaseResources ();
-}
-
-/**
- * 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>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
- */
-public void remove (int start, int end) {
- checkWidget ();
- int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
- int index = start;
- while (index <= end) {
- ignoreSelect = true;
- int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, start, 0);
- ignoreSelect = false;
- if (code == 0) break;
-
- // BUG - disposed callback could remove an item
- items [index].releaseResources ();
- index++;
- }
- System.arraycopy (items, index, items, start, count - index);
- for (int i=count-(index-start); i<count; i++) items [i] = null;
- if (index <= end) {
- if (0 <= index && index < count) {
- error (SWT.ERROR_ITEM_NOT_REMOVED);
- } else {
- error (SWT.ERROR_INVALID_RANGE);
- }
- }
-}
-
-/**
- * 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 hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (columnCount == 1 && columns [0] == null) columnCount = 0;
- int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
-
- /*
- * Feature in Windows. 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.
- *
- * NOTE: LVM_DELETEALLITEMS is also sent by the table
- * when the table is destroyed.
- */
- if (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 = true;
- int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
- ignoreSelect = false;
- if (code == 0) break;
-
- // BUG - disposed callback could remove an item
- items [index].releaseResources ();
- --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 = true;
- int code = OS.SendMessage (handle, OS.LVM_DELETEALLITEMS, 0, 0);
- ignoreSelect = false;
- if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- for (int i=0; i<itemCount; i++) {
- TableItem item = items [i];
- if (!item.isDisposed ()) item.releaseResources ();
- }
- }
-
- if (imageList != null) {
- int i = 0;
- while (i < columnCount) {
- TableColumn column = columns [i];
- if (column.getImage () != null) break;
- i++;
- }
- if (i == columnCount) {
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
- Display display = getDisplay ();
- display.releaseImageList (imageList);
- imageList = null;
- }
- }
- customDraw = false;
- items = new TableItem [4];
-}
-
-/**
- * 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.
- * If the item at the given zero-relative index in the receiver
- * is not selected, it is selected. If the item at the index
- * was selected, it remains selected. Indices that are out
- * of range and duplicate 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>
- */
-public void select (int [] indices) {
- checkWidget ();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- int length = indices.length;
- if (length == 0) return;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.state = OS.LVIS_SELECTED;
- lvItem.stateMask = OS.LVIS_SELECTED;
- for (int i=indices.length-1; i>=0; --i) {
- lvItem.iItem = indices [i];
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, 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 ();
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.state = OS.LVIS_SELECTED;
- lvItem.stateMask = OS.LVIS_SELECTED;
- lvItem.iItem = index;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- ignoreSelect = false;
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * If the item at the index was already selected, it remains
- * selected. The range of the indices is inclusive. Indices that are
- * out of range are ignored and no items will be selected if start is
- * greater than end.
- *
- * @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 select (int start, int end) {
- checkWidget ();
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.state = OS.LVIS_SELECTED;
- lvItem.stateMask = OS.LVIS_SELECTED;
- for (int i=start; i<=end; i++) {
- lvItem.iItem = i;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- ignoreSelect = false;
- }
-}
-
-/**
- * Selects all 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 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;
-}
-
-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);
- sendMouseEvent (type, button, msg, wParam, lParam);
-
- /*
- * 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. These bits are used when
- * the table is multi-select to issue the selection
- * event. 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 (OS.GetCapture () != handle) OS.SetCapture (handle);
- return LRESULT.ZERO;
- }
-
- /*
- * Feature in Windows. When a table item is reselected,
- * the table does not issue a WM_NOTIFY when the item
- * state has not changed. This is inconsistent with
- * the list widget and other widgets in Windows. The
- * fix is to detect the case when an item is reselected
- * and issue the notification.
- */
- boolean wasSelected = 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);
- wasSelected = (lvItem.state & OS.LVIS_SELECTED) != 0;
- if (wasSelected) ignoreSelect = true;
- }
- dragStarted = false;
- int code = callWindowProc (msg, wParam, lParam);
- if (wasSelected) {
- ignoreSelect = false;
- Event event = new Event ();
- event.item = items [pinfo.iItem];
- postEvent (SWT.Selection, event);
- }
- if (dragStarted) {
- 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) {
- mouseDown = false;
- sendMouseEvent (SWT.MouseUp, button, msg, wParam, lParam);
- }
- }
- dragStarted = false;
- return new LRESULT (code);
-}
-
-void setBackgroundPixel (int pixel) {
- if (background == pixel) return;
- background = pixel;
-
- /*
- * Feature in Windows. Setting the color to be
- * the current default is not correct because the
- * widget will not change colors when the colors
- * are changed from the control panel. There is
- * no fix at this time.
- */
- if (pixel == -1) pixel = defaultBackground ();
- OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, pixel);
- OS.SendMessage (handle, OS.LVM_SETTEXTBKCOLOR, 0, pixel);
- if ((style & SWT.CHECK) != 0) setCheckboxImageListColor ();
-
- /*
- * 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 setCheckboxImageListColor () {
- if ((style & SWT.CHECK) == 0) return;
- int hOldStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
- if (hOldStateList == 0) return;
- int [] cx = new int [1], cy = new int [1];
- OS.ImageList_GetIconSize (hOldStateList, cx, cy);
- setCheckboxImageList (cx [0], cy [0]);
-}
-
-void setCheckboxImageList (int width, int height) {
- if ((style & SWT.CHECK) == 0) return;
- int count = 4;
- int hStateList = OS.ImageList_Create (width, height, OS.ILC_COLOR, 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 hBrush = OS.CreateSolidBrush (getBackgroundPixel ());
- OS.FillRect (memDC, rect, hBrush);
- OS.DeleteObject (hBrush);
- int oldFont = OS.SelectObject (hDC, defaultFont ());
- TEXTMETRIC tm = new TEXTMETRIC ();
- 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);
- 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);
- OS.ImageList_AddMasked (hStateList, hBitmap, 0);
- OS.DeleteObject (hBitmap);
- 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);
-}
-
-void setFocusIndex (int index) {
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.state = OS.LVIS_FOCUSED;
- lvItem.stateMask = OS.LVIS_FOCUSED;
- lvItem.iItem = index;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- ignoreSelect = false;
-}
-
-public void setFont (Font font) {
- checkWidget ();
- super.setFont (font);
- setScrollWidth ();
- /*
- * Bug in Windows. Setting the font will cause the
- * table area to be redrawn but not the column headers.
- * Fix is to force a redraw on the column headers.
- */
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- OS.InvalidateRect (hwndHeader, null, true);
- 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;
- setRowHeight ();
-}
-
-void setForegroundPixel (int pixel) {
- if (foreground == pixel) return;
- foreground = pixel;
-
- /*
- * Feature in Windows. Setting the color to be
- * the current default is not correct because the
- * table will not change colors when the colors
- * are changed from the control panel. There is
- * no fix at this time.
- */
- if (pixel == -1) pixel = defaultForeground ();
- 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 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 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.
- */
- int topIndex = getTopIndex ();
- OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
- if (topIndex != 0) setTopIndex (topIndex);
- if (show) {
- int bits = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
- if ((bits & OS.LVS_EX_GRIDLINES) != 0) setRowHeight ();
- }
-}
-
-/**
- * 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 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 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) setRowHeight ();
- }
- OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_GRIDLINES, newBits);
-}
-
-public void setRedraw (boolean redraw) {
- checkWidget ();
- if (redraw) {
- if (--drawCount == 0) {
- setScrollWidth ();
- /*
- * This code is intentionally commented. When many items
- * are added to a table, it is slightly faster to temporarily
- * unsubclass the window proc so that messages are dispatched
- * directly to the table. This is optimization is 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.
- * For now, don't attempt it.
- */
-// subclass ();
-
- /*
- * 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 ignore any resize generated by WM_SETREDRAW and
- * defer the work until the WM_SETREDRAW has returned.
- */
- ignoreResize = true;
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- if (!ignoreResize) {
- setResizeChildren (false);
- sendEvent (SWT.Resize);
- // widget may be disposed at this point
- if (isDisposed ()) return;
- if (layout != null) layout.layout (this, false);
- setResizeChildren (true);
- }
- ignoreResize = false;
-
- /*
- * This code is intentionally commented. The window proc
- * for the table implements WM_SETREDRAW to invalidate
- * and erase the table and the header. This is undocumented
- * behavior. The commented code below shows what is actually
- * happening and reminds us that we are relying on this
- * undocumented behavior.
- *
- * NOTE: The window proc for the table does not redraw the
- * non-client area (ie. the border and scroll bars). This
- * must be explicitly redrawn. This code can be removed
- * if we stop relying on the undocuemented behavior.
- */
- if (OS.IsWinCE) {
- OS.InvalidateRect (handle, null, false);
- } else {
- OS.RedrawWindow (handle, null, 0, OS.RDW_FRAME | OS.RDW_INVALIDATE);
- }
-// int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
-// if (hwndHeader != 0) OS.SendMessage (hwndHeader, OS.WM_SETREDRAW, 1, 0);
-// int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
-// OS.RedrawWindow (handle, null, 0, flags);
-// if (hwndHeader != 0) OS.RedrawWindow (hwndHeader, null, 0, flags);
- }
- } 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);
- /*
- * This code is intentionally commented. When many items
- * are added to a table, it is slightly faster to temporarily
- * unsubclass the window proc so that messages are dispatched
- * directly to the table. This is optimization is 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.
- * For now, don't attempt it.
- */
-// unsubclass ();
- }
- }
-}
-
-void setRowHeight () {
- /*
- * 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 ((COMCTL32_MAJOR << 16 | COMCTL32_MINOR) >= (5 << 16 | 80)) return;
- 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);
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
- OS.ImageList_Destroy (hImageList);
-}
-
-void setScrollWidth () {
- if (drawCount != 0) return;
- int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (count == 1 && columns [0] == null) {
- OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, OS.LVSCW_AUTOSIZE);
- }
-}
-
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selected is first cleared, then the new items are selected.
- *
- * @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 ();
- select (indices);
- if (indices.length != 0) {
- int focusIndex = indices [0];
- if (focusIndex != -1) setFocusIndex (focusIndex);
- }
- showSelection ();
-}
-
-/**
- * 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 array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of 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#deselectAll()
- * @see Table#select(int)
- */
-public void setSelection (TableItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- deselectAll ();
- int length = items.length;
- if (length == 0) return;
- int focusIndex = -1;
- if ((style & SWT.SINGLE) != 0) length = 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 selected 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 at the given zero-relative indices in the receiver.
- * The current selection is first cleared, then the new items are selected.
- * Indices that are out of range are ignored and no items will be selected
- * if start is greater than end.
- *
- * @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 ();
- select (start, end);
- /*
- * NOTE: This code relies on the select (int, int)
- * selecting the last item in the range for a single
- * selection table.
- */
- int focusIndex = (style & SWT.SINGLE) != 0 ? end : start;
- if (focusIndex != -1) setFocusIndex (focusIndex);
- 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 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 the author is seeing are width=68 and height=6
- * but there is no guarantee that these values are absolute.
- * They may depend on the font and any number of other
- * factors. In fact, the author has observed that setting
- * the font to anything but the default seems to sometimes
- * fix 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;
- OS.SendMessage (handle, OS.LVM_GETITEMRECT, 0, rect);
- int dy = (index - topIndex) * (rect.bottom - rect.top);
- OS.SendMessage (handle, OS.LVM_SCROLL, 0, dy);
-}
-
-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 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);
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.LVS_SHAREIMAGELISTS | OS.WS_CLIPCHILDREN;
- 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;
- return bits;
-}
-
-TCHAR windowClass () {
- return TableClass;
-}
-
-int windowProc () {
- return TableProc;
-}
-
-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;
- if ((style & SWT.CHECK) != 0 && wParam == OS.VK_SPACE) {
- int index = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
- if (index != -1) {
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
- lvItem.iItem = index;
- OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- int state = lvItem.state >> 12;
- if ((state & 0x1) != 0) {
- state++;
- } else {
- --state;
- }
- lvItem.state = state << 12;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- }
- }
- 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);
- OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
- sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
- sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_LBUTTONDBLCLK, wParam, lParam);
- if (pinfo.iItem != -1) callWindowProc (OS.WM_LBUTTONDBLCLK, wParam, lParam);
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- return LRESULT.ZERO;
-}
-
-LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
- mouseDown = true;
-
- /*
- * 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);
-
- /* 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.
- */
- int index = OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
- if (index != -1 && pinfo.flags == OS.LVHT_ONITEMSTATEICON) {
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
- lvItem.iItem = index;
- OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
- int state = lvItem.state >> 12;
- if ((state & 0x1) != 0) {
- state++;
- } else {
- --state;
- }
- lvItem.state = state << 12;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- }
- }
-
- return result;
-}
-
-LRESULT WM_LBUTTONUP (int wParam, int lParam) {
- mouseDown = false;
- return super.WM_LBUTTONUP (wParam, lParam);
-}
-
-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_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:{
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- TableColumn column = columns [phdn.iItem];
- if (column != null && !column.getResizable ()) {
- return LRESULT.ONE;
- }
- break;
- }
- case OS.HDN_ITEMCHANGEDW:
- case OS.HDN_ITEMCHANGEDA: {
- NMHEADER phdn = new NMHEADER ();
- OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
- Event event = new Event ();
- 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.sendEvent (SWT.Resize, event);
- /*
- * 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 zero as the result of
- * the window proc.
- */
- if (isDisposed ()) return LRESULT.ZERO;
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (count == 1 && columns [0] == null) count = 0;
- /*
- * 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 [count];
- System.arraycopy (columns, 0, newColumns, 0, count);
- for (int i=phdn.iItem+1; i<count; i++) {
- if (!newColumns [i].isDisposed ()) {
- newColumns [i].sendEvent (SWT.Move, event);
- }
- }
- }
- }
- }
- break;
- }
- }
- }
- return super.WM_NOTIFY (wParam, lParam);
-}
-
-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);
- sendMouseEvent (SWT.MouseDown, 1, OS.WM_RBUTTONDOWN, wParam, lParam);
- sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_RBUTTONDBLCLK, wParam, lParam);
- if (pinfo.iItem != -1) callWindowProc (OS.WM_RBUTTONDBLCLK, wParam, lParam);
- 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.mask = OS.LVIF_STATE;
- lvItem.state = OS.LVIS_FOCUSED;
- lvItem.stateMask = OS.LVIS_FOCUSED;
- ignoreSelect = true;
- OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
- ignoreSelect = false;
- }
- return result;
-}
-
-LRESULT WM_SIZE (int wParam, int lParam) {
- if (ignoreResize) {
- ignoreResize = false;
- int code = callWindowProc (OS.WM_SIZE, wParam, lParam);
- return new LRESULT (code);
- }
- 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) setCheckboxImageListColor ();
- return result;
-}
-
-LRESULT wmNotifyChild (int wParam, int lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- switch (hdr.code) {
- case OS.NM_CUSTOMDRAW: {
- if (!customDraw) break;
- NMLVCUSTOMDRAW nmcd = new NMLVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMLVCUSTOMDRAW.sizeof);
- switch (nmcd.dwDrawStage) {
- case OS.CDDS_PREPAINT: return new LRESULT (OS.CDRF_NOTIFYITEMDRAW);
- case OS.CDDS_ITEMPREPAINT: return new LRESULT (OS.CDRF_NOTIFYSUBITEMDRAW);
- case OS.CDDS_ITEMPREPAINT | OS.CDDS_SUBITEM: {
- TableItem item = items [nmcd.dwItemSpec];
- int clrText = item.foreground, clrTextBk = item.background;
- if (clrText == -1 && clrTextBk == -1) break;
- nmcd.clrText = clrText == -1 ? getForegroundPixel () : clrText;
- nmcd.clrTextBk = clrTextBk == -1 ? getBackgroundPixel () : clrTextBk;
- OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
- return new LRESULT (OS.CDRF_NEWFONT);
- }
- }
- break;
- }
- case OS.LVN_MARQUEEBEGIN: return LRESULT.ONE;
- case OS.LVN_BEGINDRAG:
- case OS.LVN_BEGINRDRAG: {
- dragStarted = true;
- if (hdr.code == OS.LVN_BEGINDRAG) {
- postEvent (SWT.DragDetect);
- }
- 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: {
- NMLISTVIEW pnmlv = new NMLISTVIEW ();
- OS.MoveMemory(pnmlv, lParam, NMLISTVIEW.sizeof);
- if (pnmlv.iItem != -1) {
- Event event = new Event ();
- event.item = items [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.iItem != -1 && (pnmlv.uChanged & OS.LVIF_STATE) != 0) {
- int oldBits = pnmlv.uOldState & OS.LVIS_STATEIMAGEMASK;
- int newBits = pnmlv.uNewState & OS.LVIS_STATEIMAGEMASK;
- if (oldBits != newBits) {
- Event event = new Event();
- event.item = items [pnmlv.iItem];
- event.detail = SWT.CHECK;
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, pnmlv.iItem, 0);
- postEvent (SWT.Selection, event);
- } else {
- boolean isFocus = (pnmlv.uNewState & OS.LVIS_FOCUSED) != 0;
- int index = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
- if ((style & SWT.MULTI) != 0) {
- if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
- if (!isFocus) {
- if (index == pnmlv.iItem) {
- boolean isSelected = (pnmlv.uNewState & OS.LVIS_SELECTED) != 0;
- boolean wasSelected = (pnmlv.uOldState & OS.LVIS_SELECTED) != 0;
- isFocus = isSelected != wasSelected;
- }
- } else {
- isFocus = mouseDown;
- }
- }
- }
- if (OS.GetKeyState (OS.VK_SPACE) < 0) isFocus = true;
- if (isFocus) {
- Event event = new Event();
- if (index != -1) {
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 0);
- event.item = items [index];
- }
- postEvent (SWT.Selection, event);
- }
- }
- }
- }
- break;
- }
- }
- return super.wmNotifyChild (wParam, lParam);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 issue
+ * notificiation when selected.
+ * <p>
+ * The item children that may be added to instances of this class
+ * must be of type <code>TableItem</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</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>Selection, DefaultSelection</dd>
+ * </dl>
+ * <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;
+ ImageList imageList;
+ boolean ignoreSelect, dragStarted, ignoreResize, mouseDown, customDraw;
+ 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 Widget#checkSubclass
+ * @see Widget#getStyle
+ */
+public Table (Composite parent, int style) {
+ super (parent, checkStyle (style));
+}
+
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notified when the 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 reciever 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 msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (TableProc, handle, msg, wParam, lParam);
+}
+
+static int checkStyle (int style) {
+ /*
+ * 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);
+}
+
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ checkWidget ();
+ int bits = 0;
+ if (wHint != SWT.DEFAULT) {
+ bits |= wHint & 0xFFFF;
+ } else {
+ int width = 0;
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 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;
+ }
+ if (hHint != SWT.DEFAULT) bits |= hHint << 16;
+ int result = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, -1, bits);
+ int width = result & 0xFFFF, height = result >> 16;
+ 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;
+ /*
+ * Feature in Windows. For some reason, LVM_APPROXIMATEVIEWRECT
+ * does not include the space for the vertical scroll bar but does
+ * take into account the horizontal scroll bar when calculating the
+ * space needed to show the items. The fix is to add in this space.
+ */
+ if ((style & SWT.V_SCROLL) != 0) {
+ width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
+ }
+ if (((style & SWT.H_SCROLL) != 0) && (hHint != SWT.DEFAULT)) {
+ height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
+ }
+ return new Point (width, height);
+}
+
+void createHandle () {
+ super.createHandle ();
+ state &= ~CANVAS;
+
+ /*
+ * 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);
+ }
+
+ /*
+ * 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;
+ 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 bits = OS.LVS_EX_SUBITEMIMAGES | OS.LVS_EX_LABELTIP;
+ if ((style & SWT.FULL_SELECTION) != 0) bits |= OS.LVS_EX_FULLROWSELECT;
+ OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, bits);
+
+ /*
+ * 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_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) return;
+ if ((style & SWT.RIGHT_TO_LEFT) != 0) {
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ int extStyle = OS.GetWindowLong (hwndHeader, OS.GWL_EXSTYLE);
+ OS.SetWindowLong (hwndHeader, OS.GWL_EXSTYLE, extStyle | OS.WS_EX_LAYOUTRTL);
+ }
+}
+
+void createItem (TableColumn column, int index) {
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ if (count == 1 && columns [0] == null) count = 0;
+ if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
+ if (count == columns.length) {
+ TableColumn [] newColumns = new TableColumn [columns.length + 4];
+ System.arraycopy (columns, 0, newColumns, 0, columns.length);
+ columns = newColumns;
+ }
+ /*
+ * 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, count - index);
+ columns [index] = column;
+ if (index == 0) {
+ if (count > 0) {
+ 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);
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE | OS.LVIF_STATE;
+ int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
+ for (int i=0; i<itemCount; i++) {
+ lvItem.iItem = i;
+ lvItem.iSubItem = 0;
+ lvItem.pszText = pszText;
+ lvItem.cchTextMax = cchTextMax;
+ OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
+ lvItem.iSubItem = 1;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
+ lvItem.iSubItem = 0;
+ lvItem.pszText = lvItem.cchTextMax = 0;
+ lvItem.iImage = OS.I_IMAGENONE;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
+ items [i].text = "";
+ items [i].image = null;
+ }
+ 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 {
+ 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);
+ }
+}
+
+void createItem (TableItem item, int index) {
+ item.foreground = item.background = -1;
+ int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
+ if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
+ if (count == items.length) {
+ TableItem [] newItems = new TableItem [items.length + 4];
+ System.arraycopy (items, 0, newItems, 0, items.length);
+ items = newItems;
+ }
+ LVITEM lvItem = new LVITEM ();
+ lvItem.iItem = index;
+
+ /*
+ * 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 image is created.
+ */
+ lvItem.iImage = OS.I_IMAGENONE;
+ lvItem.mask = OS.LVIF_IMAGE;
+
+ /* Set the initial unchecked state */
+ if ((style & SWT.CHECK) != 0) {
+ lvItem.mask = lvItem.mask | OS.TVIF_STATE;
+ lvItem.state = 1 << 12;
+ lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
+ }
+
+ /* Insert the item */
+ 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;
+}
+
+void createWidget () {
+ super.createWidget ();
+ items = new TableItem [4];
+ columns = new TableColumn [4];
+}
+
+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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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);
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.stateMask = OS.LVIS_SELECTED;
+ for (int i=0; i<indices.length; i++) {
+ lvItem.iItem = indices [i];
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, 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 ();
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.stateMask = OS.LVIS_SELECTED;
+ lvItem.iItem = index;
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, 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 ();
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.stateMask = OS.LVIS_SELECTED;
+ for (int i=start; i<=end; i++) {
+ lvItem.iItem = i;
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, 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;
+ OS.SendMessage (handle, OS.LVM_SETITEMSTATE, -1, lvItem);
+}
+
+void destroyItem (TableColumn column) {
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ int index = 0;
+ while (index < count) {
+ if (columns [index] == column) break;
+ index++;
+ }
+ if (index == count) return;
+ boolean first = false;
+ if (index == 0) {
+ first = true;
+ if (count > 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_WIDTH;
+ lvColumn.pszText = pszText;
+ lvColumn.cchTextMax = cchTextMax;
+ OS.SendMessage (handle, OS.LVM_GETCOLUMN, 1, lvColumn);
+ lvColumn.mask |= OS.LVCF_FMT;
+ lvColumn.fmt = OS.LVCFMT_LEFT;
+ OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE | OS.LVIF_STATE;
+ lvItem.pszText = pszText;
+ lvItem.cchTextMax = cchTextMax;
+ int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
+ for (int i=0; i<itemCount; i++) {
+ lvItem.iItem = i;
+ lvItem.iSubItem = 1;
+ OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
+ lvItem.iSubItem = 0;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
+ TCHAR buffer = new TCHAR (getCodePage (), cchTextMax);
+ OS.MoveMemory (buffer, pszText, byteCount);
+ items [i].text = buffer.toString (0, buffer.strlen ());
+ if (imageList != null) {
+ items [i].image = imageList.get (lvItem.iImage);
+ }
+ }
+ 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;
+ lvColumn.pszText = pszText;
+ OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);
+ if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);
+ OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, OS.LVSCW_AUTOSIZE);
+ }
+ }
+ if (count > 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, --count - index);
+ columns [count] = null;
+}
+
+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;
+ ignoreSelect = true;
+ int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
+ ignoreSelect = 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) {
+ if (imageList != null) {
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ if (columnCount == 1 && columns [0] == null) columnCount = 0;
+ int i = 0;
+ while (i < columnCount) {
+ TableColumn column = columns [i];
+ if (column.getImage () != null) break;
+ i++;
+ }
+ if (i == columnCount) {
+ OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
+ imageList = null;
+ }
+ }
+ customDraw = false;
+ items = new TableItem [4];
+ }
+}
+
+void fixCheckboxImageList () {
+ /*
+ * 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 hOldStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
+ if (hOldStateList == 0) return;
+ int [] stateCx = new int [1], stateCy = new int [1];
+ OS.ImageList_GetIconSize (hOldStateList, stateCx, stateCy);
+ if (cx [0] == stateCx [0] && cy [0] == stateCy [0]) return;
+ setCheckboxImageList (cx [0], cy [0]);
+}
+
+int getBackgroundPixel () {
+ return OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0);
+}
+
+/**
+ * Returns the column at the given, zero-relative index in the
+ * receiver. Throws an exception if the index is out of range.
+ * 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>
+ */
+public TableColumn getColumn (int index) {
+ checkWidget ();
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ if (count == 1 && columns [0] == null) count = 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>TableColumn</code>s were created by the programmer,
+ * this value is zero, despite the fact that visually, one column
+ * of items is 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public int getColumnCount () {
+ checkWidget ();
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ if (count == 1 && columns [0] == null) count = 0;
+ return count;
+}
+
+/**
+ * Returns an array of <code>TableColumn</code>s which are the
+ * columns in the receiver. 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>
+ */
+public TableColumn [] getColumns () {
+ checkWidget ();
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ if (count == 1 && columns [0] == null) count = 0;
+ TableColumn [] result = new TableColumn [count];
+ System.arraycopy (columns, 0, result, 0, count);
+ return result;
+}
+
+int getFocusIndex () {
+ return OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
+}
+
+int getForegroundPixel () {
+ return OS.SendMessage (handle, OS.LVM_GETTEXTCOLOR, 0, 0);
+}
+
+/**
+ * Returns the width in pixels of a grid 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 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 ();
+ 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 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 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 items [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 an 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];
+ 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. 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++] = items [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 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 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.LVM_GETTOPINDEX, 0, 0);
+}
+
+int imageIndex (Image image) {
+ if (image == null) return OS.I_IMAGENONE;
+ if (imageList == null) {
+ Rectangle bounds = image.getBounds ();
+ imageList = getDisplay ().getImageList (new Point (bounds.width, bounds.height));
+ int index = imageList.indexOf (image);
+ if (index == -1) index = imageList.add (image);
+ int hImageList = imageList.getHandle ();
+ OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList);
+ return index;
+ }
+ int index = imageList.indexOf (image);
+ if (index != -1) return index;
+ return imageList.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);
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ 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 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);
+ for (int i=0; i<count; i++) {
+ if (items [i] == item) 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 ();
+ 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 releaseWidget () {
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ if (columnCount == 1 && columns [0] == null) columnCount = 0;
+ for (int i=0; i<columnCount; i++) {
+ TableColumn column = columns [i];
+ if (!column.isDisposed ()) column.releaseResources ();
+ }
+ columns = null;
+ int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
+
+ /*
+ * Feature in Windows. 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.
+ *
+ * NOTE: LVM_DELETEALLITEMS is also sent by the table
+ * when the table is destroyed.
+ */
+ if (columnCount > 1) {
+ /* Turn off redraw and leave it off */
+ OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
+ for (int i=itemCount-1; i>=0; --i) {
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.LVM_DELETEITEM, i, 0);
+ ignoreSelect = false;
+ TableItem item = items [i];
+ if (!item.isDisposed ()) item.releaseResources ();
+ }
+ } else {
+ for (int i=0; i<itemCount; i++) {
+ TableItem item = items [i];
+ if (!item.isDisposed ()) item.releaseResources ();
+ }
+ }
+ customDraw = false;
+ items = null;
+ if (imageList != null) {
+ OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
+ }
+ imageList = null;
+ int hOldList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
+ OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_STATE, 0);
+ if (hOldList != 0) OS.ImageList_Destroy (hOldList);
+ super.releaseWidget ();
+}
+
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove (int [] indices) {
+ checkWidget ();
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int [] newIndices = new int [indices.length];
+ System.arraycopy (indices, 0, newIndices, 0, indices.length);
+ sort (newIndices);
+ int last = -1;
+ int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
+ for (int i=0; i<newIndices.length; i++) {
+ int index = newIndices [i];
+ if (index != last || i == 0) {
+ ignoreSelect = true;
+ int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
+ ignoreSelect = false;
+ if (code == 0) {
+ if (0 <= index && index < count) {
+ error (SWT.ERROR_ITEM_NOT_REMOVED);
+ } else {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ }
+
+ // BUG - disposed callback could remove an item
+ items [index].releaseResources ();
+ System.arraycopy (items, index + 1, items, index, --count - index);
+ items [count] = null;
+ last = index;
+ }
+ }
+}
+
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove (int index) {
+ checkWidget ();
+ int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
+ ignoreSelect = true;
+ int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
+ ignoreSelect = false;
+ if (code == 0) {
+ if (0 <= index && index < count) {
+ error (SWT.ERROR_ITEM_NOT_REMOVED);
+ } else {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ }
+ TableItem item = items [index];
+ System.arraycopy (items, index + 1, items, index, --count - index);
+ items [count] = null;
+ item.releaseResources ();
+}
+
+/**
+ * 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
+public void remove (int start, int end) {
+ checkWidget ();
+ int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
+ int index = start;
+ while (index <= end) {
+ ignoreSelect = true;
+ int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, start, 0);
+ ignoreSelect = false;
+ if (code == 0) break;
+
+ // BUG - disposed callback could remove an item
+ items [index].releaseResources ();
+ index++;
+ }
+ System.arraycopy (items, index, items, start, count - index);
+ for (int i=count-(index-start); i<count; i++) items [i] = null;
+ if (index <= end) {
+ if (0 <= index && index < count) {
+ error (SWT.ERROR_ITEM_NOT_REMOVED);
+ } else {
+ error (SWT.ERROR_INVALID_RANGE);
+ }
+ }
+}
+
+/**
+ * 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 hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ if (columnCount == 1 && columns [0] == null) columnCount = 0;
+ int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);
+
+ /*
+ * Feature in Windows. 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.
+ *
+ * NOTE: LVM_DELETEALLITEMS is also sent by the table
+ * when the table is destroyed.
+ */
+ if (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 = true;
+ int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);
+ ignoreSelect = false;
+ if (code == 0) break;
+
+ // BUG - disposed callback could remove an item
+ items [index].releaseResources ();
+ --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 = true;
+ int code = OS.SendMessage (handle, OS.LVM_DELETEALLITEMS, 0, 0);
+ ignoreSelect = false;
+ if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
+ for (int i=0; i<itemCount; i++) {
+ TableItem item = items [i];
+ if (!item.isDisposed ()) item.releaseResources ();
+ }
+ }
+
+ if (imageList != null) {
+ int i = 0;
+ while (i < columnCount) {
+ TableColumn column = columns [i];
+ if (column.getImage () != null) break;
+ i++;
+ }
+ if (i == columnCount) {
+ OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
+ imageList = null;
+ }
+ }
+ customDraw = false;
+ items = new TableItem [4];
+}
+
+/**
+ * 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.
+ * If the item at the given zero-relative index in the receiver
+ * is not selected, it is selected. If the item at the index
+ * was selected, it remains selected. Indices that are out
+ * of range and duplicate 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>
+ */
+public void select (int [] indices) {
+ checkWidget ();
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int length = indices.length;
+ if (length == 0) return;
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.state = OS.LVIS_SELECTED;
+ lvItem.stateMask = OS.LVIS_SELECTED;
+ for (int i=indices.length-1; i>=0; --i) {
+ lvItem.iItem = indices [i];
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, 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 ();
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.state = OS.LVIS_SELECTED;
+ lvItem.stateMask = OS.LVIS_SELECTED;
+ lvItem.iItem = index;
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
+ ignoreSelect = false;
+}
+
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * If the item at the index was already selected, it remains
+ * selected. The range of the indices is inclusive. Indices that are
+ * out of range are ignored and no items will be selected if start is
+ * greater than end.
+ *
+ * @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 select (int start, int end) {
+ checkWidget ();
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.state = OS.LVIS_SELECTED;
+ lvItem.stateMask = OS.LVIS_SELECTED;
+ for (int i=start; i<=end; i++) {
+ lvItem.iItem = i;
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
+ ignoreSelect = false;
+ }
+}
+
+/**
+ * Selects all 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 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;
+}
+
+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);
+ sendMouseEvent (type, button, msg, wParam, lParam);
+
+ /*
+ * 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. These bits are used when
+ * the table is multi-select to issue the selection
+ * event. 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 (OS.GetCapture () != handle) OS.SetCapture (handle);
+ return LRESULT.ZERO;
+ }
+
+ /*
+ * Feature in Windows. When a table item is reselected,
+ * the table does not issue a WM_NOTIFY when the item
+ * state has not changed. This is inconsistent with
+ * the list widget and other widgets in Windows. The
+ * fix is to detect the case when an item is reselected
+ * and issue the notification.
+ */
+ boolean wasSelected = 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);
+ wasSelected = (lvItem.state & OS.LVIS_SELECTED) != 0;
+ if (wasSelected) ignoreSelect = true;
+ }
+ dragStarted = false;
+ int code = callWindowProc (msg, wParam, lParam);
+ if (wasSelected) {
+ ignoreSelect = false;
+ Event event = new Event ();
+ event.item = items [pinfo.iItem];
+ postEvent (SWT.Selection, event);
+ }
+ if (dragStarted) {
+ 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) {
+ mouseDown = false;
+ sendMouseEvent (SWT.MouseUp, button, msg, wParam, lParam);
+ }
+ }
+ dragStarted = false;
+ return new LRESULT (code);
+}
+
+void setBackgroundPixel (int pixel) {
+ if (background == pixel) return;
+ background = pixel;
+
+ /*
+ * Feature in Windows. Setting the color to be
+ * the current default is not correct because the
+ * widget will not change colors when the colors
+ * are changed from the control panel. There is
+ * no fix at this time.
+ */
+ if (pixel == -1) pixel = defaultBackground ();
+ OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, pixel);
+ OS.SendMessage (handle, OS.LVM_SETTEXTBKCOLOR, 0, pixel);
+ if ((style & SWT.CHECK) != 0) setCheckboxImageListColor ();
+
+ /*
+ * 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 setCheckboxImageListColor () {
+ if ((style & SWT.CHECK) == 0) return;
+ int hOldStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);
+ if (hOldStateList == 0) return;
+ int [] cx = new int [1], cy = new int [1];
+ OS.ImageList_GetIconSize (hOldStateList, cx, cy);
+ setCheckboxImageList (cx [0], cy [0]);
+}
+
+void setCheckboxImageList (int width, int height) {
+ if ((style & SWT.CHECK) == 0) return;
+ int count = 4;
+ int hStateList = OS.ImageList_Create (width, height, OS.ILC_COLOR, 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 hBrush = OS.CreateSolidBrush (getBackgroundPixel ());
+ OS.FillRect (memDC, rect, hBrush);
+ OS.DeleteObject (hBrush);
+ int oldFont = OS.SelectObject (hDC, defaultFont ());
+ TEXTMETRIC tm = new TEXTMETRIC ();
+ 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);
+ 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);
+ OS.ImageList_AddMasked (hStateList, hBitmap, 0);
+ OS.DeleteObject (hBitmap);
+ 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);
+}
+
+void setFocusIndex (int index) {
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.state = OS.LVIS_FOCUSED;
+ lvItem.stateMask = OS.LVIS_FOCUSED;
+ lvItem.iItem = index;
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
+ ignoreSelect = false;
+}
+
+public void setFont (Font font) {
+ checkWidget ();
+ super.setFont (font);
+ setScrollWidth ();
+ /*
+ * Bug in Windows. Setting the font will cause the
+ * table area to be redrawn but not the column headers.
+ * Fix is to force a redraw on the column headers.
+ */
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ OS.InvalidateRect (hwndHeader, null, true);
+ 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;
+ setRowHeight ();
+}
+
+void setForegroundPixel (int pixel) {
+ if (foreground == pixel) return;
+ foreground = pixel;
+
+ /*
+ * Feature in Windows. Setting the color to be
+ * the current default is not correct because the
+ * table will not change colors when the colors
+ * are changed from the control panel. There is
+ * no fix at this time.
+ */
+ if (pixel == -1) pixel = defaultForeground ();
+ 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 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 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.
+ */
+ int topIndex = getTopIndex ();
+ OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
+ if (topIndex != 0) setTopIndex (topIndex);
+ if (show) {
+ int bits = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
+ if ((bits & OS.LVS_EX_GRIDLINES) != 0) setRowHeight ();
+ }
+}
+
+/**
+ * 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 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 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) setRowHeight ();
+ }
+ OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, OS.LVS_EX_GRIDLINES, newBits);
+}
+
+public void setRedraw (boolean redraw) {
+ checkWidget ();
+ if (redraw) {
+ if (--drawCount == 0) {
+ setScrollWidth ();
+ /*
+ * This code is intentionally commented. When many items
+ * are added to a table, it is slightly faster to temporarily
+ * unsubclass the window proc so that messages are dispatched
+ * directly to the table. This is optimization is 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.
+ * For now, don't attempt it.
+ */
+// subclass ();
+
+ /*
+ * 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 ignore any resize generated by WM_SETREDRAW and
+ * defer the work until the WM_SETREDRAW has returned.
+ */
+ ignoreResize = true;
+ OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
+ if (!ignoreResize) {
+ setResizeChildren (false);
+ sendEvent (SWT.Resize);
+ // widget may be disposed at this point
+ if (isDisposed ()) return;
+ if (layout != null) layout.layout (this, false);
+ setResizeChildren (true);
+ }
+ ignoreResize = false;
+
+ /*
+ * This code is intentionally commented. The window proc
+ * for the table implements WM_SETREDRAW to invalidate
+ * and erase the table and the header. This is undocumented
+ * behavior. The commented code below shows what is actually
+ * happening and reminds us that we are relying on this
+ * undocumented behavior.
+ *
+ * NOTE: The window proc for the table does not redraw the
+ * non-client area (ie. the border and scroll bars). This
+ * must be explicitly redrawn. This code can be removed
+ * if we stop relying on the undocuemented behavior.
+ */
+ if (OS.IsWinCE) {
+ OS.InvalidateRect (handle, null, false);
+ } else {
+ OS.RedrawWindow (handle, null, 0, OS.RDW_FRAME | OS.RDW_INVALIDATE);
+ }
+// int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+// if (hwndHeader != 0) OS.SendMessage (hwndHeader, OS.WM_SETREDRAW, 1, 0);
+// int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;
+// OS.RedrawWindow (handle, null, 0, flags);
+// if (hwndHeader != 0) OS.RedrawWindow (hwndHeader, null, 0, flags);
+ }
+ } 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);
+ /*
+ * This code is intentionally commented. When many items
+ * are added to a table, it is slightly faster to temporarily
+ * unsubclass the window proc so that messages are dispatched
+ * directly to the table. This is optimization is 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.
+ * For now, don't attempt it.
+ */
+// unsubclass ();
+ }
+ }
+}
+
+void setRowHeight () {
+ /*
+ * 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 ((COMCTL32_MAJOR << 16 | COMCTL32_MINOR) >= (5 << 16 | 80)) return;
+ 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);
+ OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
+ OS.ImageList_Destroy (hImageList);
+}
+
+void setScrollWidth () {
+ if (drawCount != 0) return;
+ int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);
+ int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ if (count == 1 && columns [0] == null) {
+ OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, OS.LVSCW_AUTOSIZE);
+ }
+}
+
+/**
+ * Selects the items at the given zero-relative indices in the receiver.
+ * The current selected is first cleared, then the new items are selected.
+ *
+ * @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 ();
+ select (indices);
+ if (indices.length != 0) {
+ int focusIndex = indices [0];
+ if (focusIndex != -1) setFocusIndex (focusIndex);
+ }
+ showSelection ();
+}
+
+/**
+ * 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 array of items is null</li>
+ * <li>ERROR_INVALID_ARGUMENT - if one of 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#deselectAll()
+ * @see Table#select(int)
+ */
+public void setSelection (TableItem [] items) {
+ checkWidget ();
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+ deselectAll ();
+ int length = items.length;
+ if (length == 0) return;
+ int focusIndex = -1;
+ if ((style & SWT.SINGLE) != 0) length = 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 selected 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 at the given zero-relative indices in the receiver.
+ * The current selection is first cleared, then the new items are selected.
+ * Indices that are out of range are ignored and no items will be selected
+ * if start is greater than end.
+ *
+ * @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 ();
+ select (start, end);
+ /*
+ * NOTE: This code relies on the select (int, int)
+ * selecting the last item in the range for a single
+ * selection table.
+ */
+ int focusIndex = (style & SWT.SINGLE) != 0 ? end : start;
+ if (focusIndex != -1) setFocusIndex (focusIndex);
+ 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 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 the author is seeing are width=68 and height=6
+ * but there is no guarantee that these values are absolute.
+ * They may depend on the font and any number of other
+ * factors. In fact, the author has observed that setting
+ * the font to anything but the default seems to sometimes
+ * fix 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;
+ OS.SendMessage (handle, OS.LVM_GETITEMRECT, 0, rect);
+ int dy = (index - topIndex) * (rect.bottom - rect.top);
+ OS.SendMessage (handle, OS.LVM_SCROLL, 0, dy);
+}
+
+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 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);
+}
+
+int widgetStyle () {
+ int bits = super.widgetStyle () | OS.LVS_SHAREIMAGELISTS | OS.WS_CLIPCHILDREN;
+ 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;
+ return bits;
+}
+
+TCHAR windowClass () {
+ return TableClass;
+}
+
+int windowProc () {
+ return TableProc;
+}
+
+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;
+ if ((style & SWT.CHECK) != 0 && wParam == OS.VK_SPACE) {
+ int index = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
+ if (index != -1) {
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
+ lvItem.iItem = index;
+ OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
+ int state = lvItem.state >> 12;
+ if ((state & 0x1) != 0) {
+ state++;
+ } else {
+ --state;
+ }
+ lvItem.state = state << 12;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
+ }
+ }
+ 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);
+ OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
+ sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
+ sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_LBUTTONDBLCLK, wParam, lParam);
+ if (pinfo.iItem != -1) callWindowProc (OS.WM_LBUTTONDBLCLK, wParam, lParam);
+ if (OS.GetCapture () != handle) OS.SetCapture (handle);
+ return LRESULT.ZERO;
+}
+
+LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
+ mouseDown = true;
+
+ /*
+ * 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);
+
+ /* 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.
+ */
+ int index = OS.SendMessage (handle, OS.LVM_HITTEST, 0, pinfo);
+ if (index != -1 && pinfo.flags == OS.LVHT_ONITEMSTATEICON) {
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
+ lvItem.iItem = index;
+ OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem);
+ int state = lvItem.state >> 12;
+ if ((state & 0x1) != 0) {
+ state++;
+ } else {
+ --state;
+ }
+ lvItem.state = state << 12;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
+ }
+ }
+
+ return result;
+}
+
+LRESULT WM_LBUTTONUP (int wParam, int lParam) {
+ mouseDown = false;
+ return super.WM_LBUTTONUP (wParam, lParam);
+}
+
+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_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:{
+ NMHEADER phdn = new NMHEADER ();
+ OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
+ TableColumn column = columns [phdn.iItem];
+ if (column != null && !column.getResizable ()) {
+ return LRESULT.ONE;
+ }
+ break;
+ }
+ case OS.HDN_ITEMCHANGEDW:
+ case OS.HDN_ITEMCHANGEDA: {
+ NMHEADER phdn = new NMHEADER ();
+ OS.MoveMemory (phdn, lParam, NMHEADER.sizeof);
+ Event event = new Event ();
+ 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.sendEvent (SWT.Resize, event);
+ /*
+ * 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 zero as the result of
+ * the window proc.
+ */
+ if (isDisposed ()) return LRESULT.ZERO;
+ int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ if (count == 1 && columns [0] == null) count = 0;
+ /*
+ * 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 [count];
+ System.arraycopy (columns, 0, newColumns, 0, count);
+ for (int i=phdn.iItem+1; i<count; i++) {
+ if (!newColumns [i].isDisposed ()) {
+ newColumns [i].sendEvent (SWT.Move, event);
+ }
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ return super.WM_NOTIFY (wParam, lParam);
+}
+
+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);
+ sendMouseEvent (SWT.MouseDown, 1, OS.WM_RBUTTONDOWN, wParam, lParam);
+ sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_RBUTTONDBLCLK, wParam, lParam);
+ if (pinfo.iItem != -1) callWindowProc (OS.WM_RBUTTONDBLCLK, wParam, lParam);
+ 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.mask = OS.LVIF_STATE;
+ lvItem.state = OS.LVIS_FOCUSED;
+ lvItem.stateMask = OS.LVIS_FOCUSED;
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
+ ignoreSelect = false;
+ }
+ return result;
+}
+
+LRESULT WM_SIZE (int wParam, int lParam) {
+ if (ignoreResize) {
+ ignoreResize = false;
+ int code = callWindowProc (OS.WM_SIZE, wParam, lParam);
+ return new LRESULT (code);
+ }
+ 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) setCheckboxImageListColor ();
+ return result;
+}
+
+LRESULT wmNotifyChild (int wParam, int lParam) {
+ NMHDR hdr = new NMHDR ();
+ OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
+ switch (hdr.code) {
+ case OS.NM_CUSTOMDRAW: {
+ if (!customDraw) break;
+ NMLVCUSTOMDRAW nmcd = new NMLVCUSTOMDRAW ();
+ OS.MoveMemory (nmcd, lParam, NMLVCUSTOMDRAW.sizeof);
+ switch (nmcd.dwDrawStage) {
+ case OS.CDDS_PREPAINT: return new LRESULT (OS.CDRF_NOTIFYITEMDRAW);
+ case OS.CDDS_ITEMPREPAINT: return new LRESULT (OS.CDRF_NOTIFYSUBITEMDRAW);
+ case OS.CDDS_ITEMPREPAINT | OS.CDDS_SUBITEM: {
+ TableItem item = items [nmcd.dwItemSpec];
+ int clrText = item.foreground, clrTextBk = item.background;
+ if (clrText == -1 && clrTextBk == -1) break;
+ nmcd.clrText = clrText == -1 ? getForegroundPixel () : clrText;
+ nmcd.clrTextBk = clrTextBk == -1 ? getBackgroundPixel () : clrTextBk;
+ OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof);
+ return new LRESULT (OS.CDRF_NEWFONT);
+ }
+ }
+ break;
+ }
+ case OS.LVN_MARQUEEBEGIN: return LRESULT.ONE;
+ case OS.LVN_BEGINDRAG:
+ case OS.LVN_BEGINRDRAG: {
+ dragStarted = true;
+ if (hdr.code == OS.LVN_BEGINDRAG) {
+ postEvent (SWT.DragDetect);
+ }
+ 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: {
+ NMLISTVIEW pnmlv = new NMLISTVIEW ();
+ OS.MoveMemory(pnmlv, lParam, NMLISTVIEW.sizeof);
+ if (pnmlv.iItem != -1) {
+ Event event = new Event ();
+ event.item = items [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.iItem != -1 && (pnmlv.uChanged & OS.LVIF_STATE) != 0) {
+ int oldBits = pnmlv.uOldState & OS.LVIS_STATEIMAGEMASK;
+ int newBits = pnmlv.uNewState & OS.LVIS_STATEIMAGEMASK;
+ if (oldBits != newBits) {
+ Event event = new Event();
+ event.item = items [pnmlv.iItem];
+ event.detail = SWT.CHECK;
+ /*
+ * This code is intentionally commented.
+ */
+// OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, pnmlv.iItem, 0);
+ postEvent (SWT.Selection, event);
+ } else {
+ boolean isFocus = (pnmlv.uNewState & OS.LVIS_FOCUSED) != 0;
+ int index = OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);
+ if ((style & SWT.MULTI) != 0) {
+ if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
+ if (!isFocus) {
+ if (index == pnmlv.iItem) {
+ boolean isSelected = (pnmlv.uNewState & OS.LVIS_SELECTED) != 0;
+ boolean wasSelected = (pnmlv.uOldState & OS.LVIS_SELECTED) != 0;
+ isFocus = isSelected != wasSelected;
+ }
+ } else {
+ isFocus = mouseDown;
+ }
+ }
+ }
+ if (OS.GetKeyState (OS.VK_SPACE) < 0) isFocus = true;
+ if (isFocus) {
+ Event event = new Event();
+ if (index != -1) {
+ /*
+ * This code is intentionally commented.
+ */
+// OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 0);
+ event.item = items [index];
+ }
+ postEvent (SWT.Selection, event);
+ }
+ }
+ }
+ }
+ 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
index 1d3f175d5c..f040329484 100755
--- 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
@@ -1,479 +1,479 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd> Move, Resize, Selection</dd>
- * </dl>
- * <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;
-
-/**
- * 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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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);
-}
-
-/**
- * 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;
-}
-
-public Display getDisplay () {
- Table parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
-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 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;
-}
-
-/**
- * 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;
- TCHAR buffer = new TCHAR (parent.getCodePage (), text, true);
- int headerWidth = OS.SendMessage (hwnd, OS.LVM_GETSTRINGWIDTH, 0, buffer) + 10;
- if (image != null) {
- int margin = 0;
- if ((COMCTL32_MAJOR << 16 | COMCTL32_MINOR) >= (5 << 16 | 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;
- }
- Rectangle rect = image.getBounds ();
- headerWidth += rect.width + margin * 2;
- }
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, OS.LVSCW_AUTOSIZE);
- int columnWidth = OS.SendMessage (hwnd, OS.LVM_GETCOLUMNWIDTH, index, 0);
- if (headerWidth > columnWidth) {
- if (image == null) {
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, OS.LVSCW_AUTOSIZE_USEHEADER);
- } else {
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, headerWidth);
- }
- }
-}
-
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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;
- int hwnd = parent.handle;
- LVCOLUMN lvColumn = new LVCOLUMN ();
- lvColumn.mask = OS.LVCF_FMT;
- lvColumn.fmt = fmt;
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMN, index, lvColumn);
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setImage (image);
- int hwnd = parent.handle;
- LVCOLUMN lvColumn = new LVCOLUMN ();
- lvColumn.mask = OS.LVCF_FMT | OS.LVCF_IMAGE;
- lvColumn.fmt = OS.LVCFMT_IMAGE;
- lvColumn.iImage = parent.imageIndex (image);
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMN, index, lvColumn);
- if (image == null) {
- lvColumn.mask = OS.LVCF_FMT;
- if ((style & SWT.LEFT) == SWT.LEFT) lvColumn.fmt = OS.LVCFMT_LEFT;
- if ((style & SWT.CENTER) == SWT.CENTER) lvColumn.fmt = OS.LVCFMT_CENTER;
- if ((style & SWT.RIGHT) == SWT.RIGHT) lvColumn.fmt = OS.LVCFMT_RIGHT;
- OS.SendMessage (hwnd, OS.LVM_SETCOLUMN, index, lvColumn);
- }
-}
-
-/**
- * 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;
-}
-
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int index = parent.indexOf (this);
- if (index == -1) return;
- super.setText (string);
-
- /*
- * 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);
-
- /* Set the column title */
- 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);
- 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 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);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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.
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>LEFT, RIGHT, CENTER</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd> Move, Resize, Selection</dd>
+ * </dl>
+ * <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;
+
+/**
+ * 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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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);
+}
+
+/**
+ * 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;
+}
+
+public Display getDisplay () {
+ Table parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
+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 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;
+}
+
+/**
+ * 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;
+ TCHAR buffer = new TCHAR (parent.getCodePage (), text, true);
+ int headerWidth = OS.SendMessage (hwnd, OS.LVM_GETSTRINGWIDTH, 0, buffer) + 10;
+ if (image != null) {
+ int margin = 0;
+ if ((COMCTL32_MAJOR << 16 | COMCTL32_MINOR) >= (5 << 16 | 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;
+ }
+ Rectangle rect = image.getBounds ();
+ headerWidth += rect.width + margin * 2;
+ }
+ OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, OS.LVSCW_AUTOSIZE);
+ int columnWidth = OS.SendMessage (hwnd, OS.LVM_GETCOLUMNWIDTH, index, 0);
+ if (headerWidth > columnWidth) {
+ if (image == null) {
+ OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, OS.LVSCW_AUTOSIZE_USEHEADER);
+ } else {
+ OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, headerWidth);
+ }
+ }
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ parent = 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 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;
+ int hwnd = parent.handle;
+ LVCOLUMN lvColumn = new LVCOLUMN ();
+ lvColumn.mask = OS.LVCF_FMT;
+ lvColumn.fmt = fmt;
+ OS.SendMessage (hwnd, OS.LVM_SETCOLUMN, index, lvColumn);
+}
+
+public void setImage (Image image) {
+ checkWidget();
+ if (image != null && image.isDisposed ()) {
+ error (SWT.ERROR_INVALID_ARGUMENT);
+ }
+ int index = parent.indexOf (this);
+ if (index == -1) return;
+ super.setImage (image);
+ int hwnd = parent.handle;
+ LVCOLUMN lvColumn = new LVCOLUMN ();
+ lvColumn.mask = OS.LVCF_FMT | OS.LVCF_IMAGE;
+ lvColumn.fmt = OS.LVCFMT_IMAGE;
+ lvColumn.iImage = parent.imageIndex (image);
+ OS.SendMessage (hwnd, OS.LVM_SETCOLUMN, index, lvColumn);
+ if (image == null) {
+ lvColumn.mask = OS.LVCF_FMT;
+ if ((style & SWT.LEFT) == SWT.LEFT) lvColumn.fmt = OS.LVCFMT_LEFT;
+ if ((style & SWT.CENTER) == SWT.CENTER) lvColumn.fmt = OS.LVCFMT_CENTER;
+ if ((style & SWT.RIGHT) == SWT.RIGHT) lvColumn.fmt = OS.LVCFMT_RIGHT;
+ OS.SendMessage (hwnd, OS.LVM_SETCOLUMN, index, lvColumn);
+ }
+}
+
+/**
+ * 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;
+}
+
+public void setText (String string) {
+ checkWidget ();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int index = parent.indexOf (this);
+ if (index == -1) return;
+ super.setText (string);
+
+ /*
+ * 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);
+
+ /* Set the column title */
+ 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);
+ 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 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);
+}
+
+}
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
index 517c27465e..310f064d2a 100755
--- 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
@@ -1,711 +1,711 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- int background, foreground;
-
-/**
- * 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) {
- 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>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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
-}
-
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-/**
- * 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 ();
- int pixel = (background == -1) ? parent.getBackgroundPixel() : background;
- return Color.win32_new (getDisplay (), pixel);
-}
-
-/**
- * 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();
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
- int hwnd = parent.handle;
- int hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index < count)) return new Rectangle (0, 0, 0, 0);
- int gridWidth = 0;
- if (parent.getLinesVisible ()) gridWidth = parent.getGridLineWidth ();
- RECT rect = new RECT ();
- rect.top = index;
- rect.left = OS.LVIR_LABEL;
- OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, itemIndex, rect);
- if (index == 0) {
- RECT iconRect = new RECT ();
- iconRect.left = OS.LVIR_ICON;
- OS.SendMessage (hwnd, OS.LVM_GETSUBITEMRECT, itemIndex, iconRect);
- rect.left = iconRect.left - gridWidth;
- }
- int width = rect.right - rect.left - gridWidth;
- int height = rect.bottom - rect.top - gridWidth;
- /*
- * 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.
- */
- if ((COMCTL32_MAJOR << 16 | COMCTL32_MINOR) >= (5 << 16 | 80)) {
- rect.top -= gridWidth;
- }
- return new Rectangle (rect.left + gridWidth, rect.top + gridWidth, width, height);
-}
-
-/**
- * Returns <code>true</code> if the receiver is checked,
- * and false otherwise. When the parent does not have
- * the <code>CHECK style, return false.
- *
- * @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.style & SWT.CHECK) == 0) return false;
- int index = parent.indexOf (this);
- if (index == -1) return false;
- int hwnd = parent.handle;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
- lvItem.iItem = index;
- int result = OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
- return (result != 0) && (((lvItem.state >> 12) & 1) == 0);
-}
-
-public Display getDisplay () {
- Table parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
-/**
- * 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 ();
- int pixel = (foreground == -1) ? parent.getForegroundPixel() : foreground;
- return Color.win32_new (getDisplay (), 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.style & SWT.CHECK) == 0) return false;
- int index = parent.indexOf (this);
- if (index == -1) return false;
- int hwnd = parent.handle;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
- lvItem.iItem = index;
- int result = OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
- return (result != 0) && ((lvItem.state >> 12) > 2);
-}
-
-/**
- * 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 (index == 0) return super.getImage ();
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return null;
- int hwnd = parent.handle;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_IMAGE;
- lvItem.iItem = itemIndex;
- lvItem.iSubItem = index;
- if (OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem) == 0) return null;
- if (lvItem.iImage >= 0) {
- ImageList imageList = parent.imageList;
- if (imageList != null) return imageList.get (lvItem.iImage);
- }
- return null;
-}
-
-/**
- * Returns a rectangle describing the size and location
- * relative to its parent of an image at a column in the
- * table.
- *
- * @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();
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
- int hwnd = parent.handle;
- int hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
- int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
- if (!(0 <= index && index < count)) return new Rectangle (0, 0, 0, 0);
- int gridWidth = 0;
- if (parent.getLinesVisible ()) gridWidth = parent.getGridLineWidth ();
- RECT rect = new RECT ();
- rect.top = index;
- rect.left = OS.LVIR_ICON;
- OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, itemIndex, rect);
- if (index == 0) {
- RECT iconRect = new RECT ();
- iconRect.left = OS.LVIR_ICON;
- OS.SendMessage (hwnd, OS.LVM_GETSUBITEMRECT, itemIndex, iconRect);
- rect.left = iconRect.left - gridWidth;
- }
- int width = rect.right - rect.left - gridWidth;
- int height = rect.bottom - rect.top - gridWidth;
- /*
- * 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.
- */
- if ((COMCTL32_MAJOR << 16 | COMCTL32_MINOR) >= (5 << 16 | 80)) {
- rect.top -= gridWidth;
- }
- return new Rectangle (rect.left + gridWidth, rect.top + gridWidth, 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();
- int index = parent.indexOf (this);
- if (index == -1) return 0;
- int hwnd = parent.handle;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_INDENT;
- lvItem.iItem = index;
- OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
- return lvItem.iIndent;
-}
-
-/**
- * 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 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>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_TEXT - if the column at index does not exist</li>
- * </ul>
- */
-public String getText (int index) {
- checkWidget();
- if (index == 0) return super.getText ();
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) error (SWT.ERROR_CANNOT_GET_TEXT);
- int cchTextMax = 1024;
- int hwnd = parent.handle;
- int hHeap = OS.GetProcessHeap ();
- int byteCount = cchTextMax * TCHAR.sizeof;
- int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT;
- lvItem.iItem = itemIndex;
- lvItem.iSubItem = index;
- lvItem.pszText = pszText;
- lvItem.cchTextMax = cchTextMax;
- int result = OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
- TCHAR buffer = new TCHAR (parent.getCodePage (), cchTextMax);
- OS.MoveMemory (buffer, pszText, byteCount);
- OS.HeapFree (hHeap, 0, pszText);
- if (result == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
- return buffer.toString (0, buffer.strlen ());
-}
-
-void redraw () {
- if (parent.drawCount > 0) return;
- int hwnd = parent.handle;
- if (!OS.IsWindowVisible (hwnd)) return;
- int index = parent.indexOf (this);
- RECT rect = new RECT ();
- rect.left = OS.LVIR_BOUNDS;
- if (OS.SendMessage (hwnd, OS.LVM_GETITEMRECT, index, rect) != 0) {
- OS.InvalidateRect (hwnd, rect, true);
- }
-}
-
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = 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;
- }
- background = pixel;
- redraw ();
-}
-
-/**
- * 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;
- int index = parent.indexOf (this);
- if (index == -1) return;
- int hwnd = parent.handle;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
- lvItem.iItem = index;
- OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
- int state = lvItem.state >> 12;
- if (checked) {
- if ((state & 0x1) != 0) state++;
- } else {
- if ((state & 0x1) == 0) --state;
- }
- lvItem.state = state << 12;
- parent.ignoreSelect = true;
- OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
- parent.ignoreSelect = 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;
- }
- foreground = pixel;
- redraw ();
-}
-
-/**
- * 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;
- int index = parent.indexOf (this);
- if (index == -1) return;
- int hwnd = parent.handle;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_STATE;
- lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
- lvItem.iItem = index;
- OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
- int state = lvItem.state >> 12;
- if (grayed) {
- if (state <= 2) state +=2;
- } else {
- if (state > 2) state -=2;
- }
- lvItem.state = state << 12;
- parent.ignoreSelect = true;
- OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
- parent.ignoreSelect = false;
-}
-
-/**
- * Sets the image for multiple columns in the Table.
- *
- * @param images the array of new images
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (Image [] images) {
- checkWidget();
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-
-/**
- * Sets the receiver's image at a column.
- *
- * @param index the column index
- * @param image the new image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setImage (int index, Image image) {
- checkWidget();
- if (image != null && image.isDisposed ()) {
- error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return;
- if (index == 0) {
- super.setImage (image);
- }
- int hwnd = parent.handle;
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_IMAGE;
- lvItem.iItem = itemIndex;
- lvItem.iSubItem = index;
- lvItem.iImage = parent.imageIndex (image);
- if (OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem) != 0) {
- if (index == 0) parent.setScrollWidth ();
- parent.fixCheckboxImageList ();
- }
-}
-
-public void setImage (Image image) {
- checkWidget ();
- setImage (0, image);
-}
-
-/**
- * Sets the image indent.
- *
- * @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>
- */
-public void setImageIndent (int indent) {
- checkWidget();
- if (indent < 0) return;
- int index = parent.indexOf (this);
- if (index == -1) return;
- 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);
-}
-
-/**
- * Sets the text for multiple columns in the table.
- *
- * @param strings the array of new strings
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (String [] strings) {
- checkWidget();
- if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<strings.length; i++) {
- String string = strings [i];
- if (string != null) setText (i, string);
- }
-}
-
-/**
- * Sets the receiver's text at a column
- *
- * @param index the column index
- * @param string the new text
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setText (int index, String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int itemIndex = parent.indexOf (this);
- if (itemIndex == -1) return;
- if (index == 0) {
- super.setText (string);
- }
- 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);
- LVITEM lvItem = new LVITEM ();
- lvItem.mask = OS.LVIF_TEXT;
- lvItem.iItem = itemIndex;
- lvItem.pszText = pszText;
- lvItem.iSubItem = index;
- if (OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem) != 0) {
- if (index == 0) parent.setScrollWidth ();
- }
- OS.HeapFree (hHeap, 0, pszText);
-}
-
-public void setText (String string) {
- checkWidget();
- setText (0, string);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+ int background, foreground;
+
+/**
+ * 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) {
+ 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>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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
+ super (parent, style);
+ this.parent = parent;
+ parent.createItem (this, index);
+}
+
+protected void checkSubclass () {
+ if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
+}
+
+/**
+ * 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 ();
+ int pixel = (background == -1) ? parent.getBackgroundPixel() : background;
+ return Color.win32_new (getDisplay (), pixel);
+}
+
+/**
+ * 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();
+ int itemIndex = parent.indexOf (this);
+ if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
+ int hwnd = parent.handle;
+ int hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
+ int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ if (!(0 <= index && index < count)) return new Rectangle (0, 0, 0, 0);
+ int gridWidth = 0;
+ if (parent.getLinesVisible ()) gridWidth = parent.getGridLineWidth ();
+ RECT rect = new RECT ();
+ rect.top = index;
+ rect.left = OS.LVIR_LABEL;
+ OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, itemIndex, rect);
+ if (index == 0) {
+ RECT iconRect = new RECT ();
+ iconRect.left = OS.LVIR_ICON;
+ OS.SendMessage (hwnd, OS.LVM_GETSUBITEMRECT, itemIndex, iconRect);
+ rect.left = iconRect.left - gridWidth;
+ }
+ int width = rect.right - rect.left - gridWidth;
+ int height = rect.bottom - rect.top - gridWidth;
+ /*
+ * 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.
+ */
+ if ((COMCTL32_MAJOR << 16 | COMCTL32_MINOR) >= (5 << 16 | 80)) {
+ rect.top -= gridWidth;
+ }
+ return new Rectangle (rect.left + gridWidth, rect.top + gridWidth, width, height);
+}
+
+/**
+ * Returns <code>true</code> if the receiver is checked,
+ * and false otherwise. When the parent does not have
+ * the <code>CHECK style, return false.
+ *
+ * @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.style & SWT.CHECK) == 0) return false;
+ int index = parent.indexOf (this);
+ if (index == -1) return false;
+ int hwnd = parent.handle;
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
+ lvItem.iItem = index;
+ int result = OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
+ return (result != 0) && (((lvItem.state >> 12) & 1) == 0);
+}
+
+public Display getDisplay () {
+ Table parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
+/**
+ * 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 ();
+ int pixel = (foreground == -1) ? parent.getForegroundPixel() : foreground;
+ return Color.win32_new (getDisplay (), 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.style & SWT.CHECK) == 0) return false;
+ int index = parent.indexOf (this);
+ if (index == -1) return false;
+ int hwnd = parent.handle;
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
+ lvItem.iItem = index;
+ int result = OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
+ return (result != 0) && ((lvItem.state >> 12) > 2);
+}
+
+/**
+ * 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 (index == 0) return super.getImage ();
+ int itemIndex = parent.indexOf (this);
+ if (itemIndex == -1) return null;
+ int hwnd = parent.handle;
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_IMAGE;
+ lvItem.iItem = itemIndex;
+ lvItem.iSubItem = index;
+ if (OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem) == 0) return null;
+ if (lvItem.iImage >= 0) {
+ ImageList imageList = parent.imageList;
+ if (imageList != null) return imageList.get (lvItem.iImage);
+ }
+ return null;
+}
+
+/**
+ * Returns a rectangle describing the size and location
+ * relative to its parent of an image at a column in the
+ * table.
+ *
+ * @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();
+ int itemIndex = parent.indexOf (this);
+ if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);
+ int hwnd = parent.handle;
+ int hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);
+ int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);
+ if (!(0 <= index && index < count)) return new Rectangle (0, 0, 0, 0);
+ int gridWidth = 0;
+ if (parent.getLinesVisible ()) gridWidth = parent.getGridLineWidth ();
+ RECT rect = new RECT ();
+ rect.top = index;
+ rect.left = OS.LVIR_ICON;
+ OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, itemIndex, rect);
+ if (index == 0) {
+ RECT iconRect = new RECT ();
+ iconRect.left = OS.LVIR_ICON;
+ OS.SendMessage (hwnd, OS.LVM_GETSUBITEMRECT, itemIndex, iconRect);
+ rect.left = iconRect.left - gridWidth;
+ }
+ int width = rect.right - rect.left - gridWidth;
+ int height = rect.bottom - rect.top - gridWidth;
+ /*
+ * 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.
+ */
+ if ((COMCTL32_MAJOR << 16 | COMCTL32_MINOR) >= (5 << 16 | 80)) {
+ rect.top -= gridWidth;
+ }
+ return new Rectangle (rect.left + gridWidth, rect.top + gridWidth, 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();
+ int index = parent.indexOf (this);
+ if (index == -1) return 0;
+ int hwnd = parent.handle;
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_INDENT;
+ lvItem.iItem = index;
+ OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
+ return lvItem.iIndent;
+}
+
+/**
+ * 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 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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_TEXT - if the column at index does not exist</li>
+ * </ul>
+ */
+public String getText (int index) {
+ checkWidget();
+ if (index == 0) return super.getText ();
+ int itemIndex = parent.indexOf (this);
+ if (itemIndex == -1) error (SWT.ERROR_CANNOT_GET_TEXT);
+ int cchTextMax = 1024;
+ int hwnd = parent.handle;
+ int hHeap = OS.GetProcessHeap ();
+ int byteCount = cchTextMax * TCHAR.sizeof;
+ int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_TEXT;
+ lvItem.iItem = itemIndex;
+ lvItem.iSubItem = index;
+ lvItem.pszText = pszText;
+ lvItem.cchTextMax = cchTextMax;
+ int result = OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
+ TCHAR buffer = new TCHAR (parent.getCodePage (), cchTextMax);
+ OS.MoveMemory (buffer, pszText, byteCount);
+ OS.HeapFree (hHeap, 0, pszText);
+ if (result == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
+ return buffer.toString (0, buffer.strlen ());
+}
+
+void redraw () {
+ if (parent.drawCount > 0) return;
+ int hwnd = parent.handle;
+ if (!OS.IsWindowVisible (hwnd)) return;
+ int index = parent.indexOf (this);
+ RECT rect = new RECT ();
+ rect.left = OS.LVIR_BOUNDS;
+ if (OS.SendMessage (hwnd, OS.LVM_GETITEMRECT, index, rect) != 0) {
+ OS.InvalidateRect (hwnd, rect, true);
+ }
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ parent = 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;
+ }
+ background = pixel;
+ redraw ();
+}
+
+/**
+ * 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;
+ int index = parent.indexOf (this);
+ if (index == -1) return;
+ int hwnd = parent.handle;
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
+ lvItem.iItem = index;
+ OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
+ int state = lvItem.state >> 12;
+ if (checked) {
+ if ((state & 0x1) != 0) state++;
+ } else {
+ if ((state & 0x1) == 0) --state;
+ }
+ lvItem.state = state << 12;
+ parent.ignoreSelect = true;
+ OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
+ parent.ignoreSelect = 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;
+ }
+ foreground = pixel;
+ redraw ();
+}
+
+/**
+ * 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;
+ int index = parent.indexOf (this);
+ if (index == -1) return;
+ int hwnd = parent.handle;
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_STATE;
+ lvItem.stateMask = OS.LVIS_STATEIMAGEMASK;
+ lvItem.iItem = index;
+ OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);
+ int state = lvItem.state >> 12;
+ if (grayed) {
+ if (state <= 2) state +=2;
+ } else {
+ if (state > 2) state -=2;
+ }
+ lvItem.state = state << 12;
+ parent.ignoreSelect = true;
+ OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
+ parent.ignoreSelect = false;
+}
+
+/**
+ * Sets the image for multiple columns in the Table.
+ *
+ * @param images the array of new images
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
+ * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setImage (Image [] images) {
+ checkWidget();
+ if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
+ for (int i=0; i<images.length; i++) {
+ setImage (i, images [i]);
+ }
+}
+
+/**
+ * Sets the receiver's image at a column.
+ *
+ * @param index the column index
+ * @param image the new image
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setImage (int index, Image image) {
+ checkWidget();
+ if (image != null && image.isDisposed ()) {
+ error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ int itemIndex = parent.indexOf (this);
+ if (itemIndex == -1) return;
+ if (index == 0) {
+ super.setImage (image);
+ }
+ int hwnd = parent.handle;
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_IMAGE;
+ lvItem.iItem = itemIndex;
+ lvItem.iSubItem = index;
+ lvItem.iImage = parent.imageIndex (image);
+ if (OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem) != 0) {
+ if (index == 0) parent.setScrollWidth ();
+ parent.fixCheckboxImageList ();
+ }
+}
+
+public void setImage (Image image) {
+ checkWidget ();
+ setImage (0, image);
+}
+
+/**
+ * Sets the image indent.
+ *
+ * @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>
+ */
+public void setImageIndent (int indent) {
+ checkWidget();
+ if (indent < 0) return;
+ int index = parent.indexOf (this);
+ if (index == -1) return;
+ 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);
+}
+
+/**
+ * Sets the text for multiple columns in the table.
+ *
+ * @param strings the array of new strings
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setText (String [] strings) {
+ checkWidget();
+ if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
+ for (int i=0; i<strings.length; i++) {
+ String string = strings [i];
+ if (string != null) setText (i, string);
+ }
+}
+
+/**
+ * Sets the receiver's text at a column
+ *
+ * @param index the column index
+ * @param string the new text
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setText (int index, String string) {
+ checkWidget();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ int itemIndex = parent.indexOf (this);
+ if (itemIndex == -1) return;
+ if (index == 0) {
+ super.setText (string);
+ }
+ 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);
+ LVITEM lvItem = new LVITEM ();
+ lvItem.mask = OS.LVIF_TEXT;
+ lvItem.iItem = itemIndex;
+ lvItem.pszText = pszText;
+ lvItem.iSubItem = index;
+ if (OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem) != 0) {
+ if (index == 0) parent.setScrollWidth ();
+ }
+ OS.HeapFree (hHeap, 0, pszText);
+}
+
+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
index 1583861902..970e070155 100755
--- 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
@@ -1,1755 +1,1755 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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, 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, ignoreVerify, ignoreCharacter;
-
- public static final int LIMIT;
- 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 = 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;
- }
-
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * lists the style constants that are applicable to the class.
- * Style bits are also inherited from superclasses.
- * </p>
- *
- * @param parent a composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (EditProc, handle, 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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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);
- if (string == null) return;
- }
- OS.SendMessage (handle, OS.EM_SETSEL, length, length);
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
- OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
-}
-
-static int checkStyle (int style) {
- 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;
- 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 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 = new TEXTMETRIC ();
- OS.GetTextMetrics (hDC, tm);
- int count = OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0);
- int height = count * tm.tmHeight, width = 0;
- 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;
- }
- String text = getText ();
- TCHAR buffer = new TCHAR (getCodePage (), text, false);
- OS.DrawText (hDC, buffer, 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;
-
- /* Calculate the margin width */
- int margins = OS.SendMessage(handle, OS.EM_GETMARGINS, 0, 0);
- int marginWidth = (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF);
- width += marginWidth;
-
- /*
- * 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.
- */
- if ((style & SWT.V_SCROLL) != 0) {
- width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- }
- if ((style & SWT.H_SCROLL) != 0) {
- height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- if ((style & SWT.BORDER) == 0) width++;
- }
- if ((style & SWT.BORDER) != 0) {
- int border = getBorderWidth ();
- width += (border * 2) + 3;
- height += (border * 2) + 3;
- }
- 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>
- */
-public void copy () {
- checkWidget ();
- OS.SendMessage (handle, OS.WM_COPY, 0, 0);
-}
-
-void createWidget () {
- super.createWidget ();
- doubleClick = true;
- setTabStops (tabs = 8);
-}
-
-/**
- * Cuts the selected text.
- * <p>
- * The current selection is first copied to the
- * clipboard and then deleted from the widget.
- * </p>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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.SendMessage (handle, OS.WM_CUT, 0, 0);
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_WINDOW);
-}
-
-/**
- * Gets the line number of the caret.
- * <p>
- * The line number of the caret is returned.
- * </p>
- *
- * @return the line number
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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);
-}
-
-/**
- * Gets the location the caret.
- * <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 [] start = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, (int []) null);
- int pos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0);
- if (pos == -1) {
- pos = 0;
- if (start [0] >= OS.GetWindowTextLength (handle)) {
- int cp = getCodePage ();
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, " ", true));
- pos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0);
- OS.SendMessage (handle, OS.EM_SETSEL, start [0], start [0] + 1);
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, "", true));
- }
- }
- return new Point ((short) (pos & 0xFFFF), (short) (pos >> 16));
-}
-
-/**
- * Gets the position of the caret.
- * <p>
- * The character position of the caret is returned.
- * </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);
- int startLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, start [0], 0);
- int caretPos = OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0);
- int caretLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, caretPos, 0);
- int caret = end [0];
- if (caretLine == startLine) caret = start [0];
- if (OS.IsDBLocale) caret = mbcsToWcsPos (caret);
- return caret;
-}
-
-/**
- * Gets 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.IsDBLocale) length = mbcsToWcsPos (length);
- return length;
-}
-
-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;
-}
-
-/**
- * Gets 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>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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;
-}
-
-/**
- * Gets 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>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public char getEchoChar () {
- checkWidget ();
- char echo = (char) OS.SendMessage (handle, OS.EM_GETPASSWORDCHAR, 0, 0);
- if (echo != 0 && (echo = mbcsToWcs (echo, getCodePage ())) == 0) echo = '*';
- return echo;
-}
-
-/**
- * Gets the 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 boolean getEditable () {
- checkWidget ();
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- return (bits & OS.ES_READONLY) == 0;
-}
-
-/**
- * Gets 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);
-}
-
-/**
- * Gets 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>
- */
-public String getLineDelimiter () {
- checkWidget ();
- return DELIMITER;
-}
-
-/**
- * Gets 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 = new TEXTMETRIC ();
- OS.GetTextMetrics (hDC, tm);
- if (newFont != 0) OS.SelectObject (hDC, oldFont);
- OS.ReleaseDC (handle, hDC);
- return tm.tmHeight;
-}
-
-/**
- * Gets the position of the selected text.
- * <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 the start and end of 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 Point getSelection () {
- checkWidget ();
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (OS.IsDBLocale) {
- start [0] = mbcsToWcsPos (start [0]);
- end [0] = mbcsToWcsPos (end [0]);
- }
- return new Point (start [0], end [0]);
-}
-
-/**
- * Gets 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.
- *
- * @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);
-}
-
-/**
- * Gets 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;
-}
-
-/**
- * Gets the widget text.
- * <p>
- * The text for a text widget is the characters in the widget.
- * </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);
-}
-
-/**
- * Gets a range of text.
- * <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 ();
- /*
- * 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>
- */
-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 ();
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_MULTILINE) == 0) return 0;
- return OS.SendMessage (handle, OS.EM_GETFIRSTVISIBLELINE, 0, 0);
-}
-
-/**
- * Gets 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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]);
- if (string == null) return;
- }
- TCHAR buffer = new TCHAR (getCodePage (), string, true);
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
-}
-
-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];
- }
- 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 ();
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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
- */
-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 (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 */
- switch (msg) {
- case OS.WM_CHAR:
- if (key != 0x08 && key != 0x7F && key != '\r' && key != '\t' && key != '\n') break;
- // FALL THROUGH
- case OS.WM_KEYDOWN:
- int modifiers = SWT.ALT | SWT.SHIFT | SWT.CONTROL;
- if ((stateMask & modifiers) != 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 (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.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.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 */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_MULTILINE) == 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]);
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
- 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);
- if (rect.right - rect.left == 0) {
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (start [0] != 0 || end [0] != 0) {
- OS.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>
- *
- * @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,
- * 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 (echo != 0) {
- if ((echo = (char) 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 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.IsDBLocale) start = wcsToMbcsPos (start);
- OS.SendMessage (handle, OS.EM_SETSEL, start, start);
- OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
-}
-
-/**
- * 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
- * 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.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 text 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];
- return;
- }
- if (oldStart == start [0] && oldEnd == end [0]) return;
- OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
-}
-
-/**
- * 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
- * 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 text 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);
- 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>.
- * </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>
- */
-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 ();
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_MULTILINE) == 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 IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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) {
- return verifyText (string, start, end, null);
-}
-
-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.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 ();
- 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 | OS.ES_AUTOHSCROLL;
- bits |= OS.ES_MULTILINE | OS.ES_AUTOHSCROLL | OS.ES_NOHIDESEL;
- if ((style & SWT.WRAP) != 0) bits &= ~(OS.WS_HSCROLL | OS.ES_AUTOHSCROLL);
- return bits;
-}
-
-TCHAR windowClass () {
- return EditClass;
-}
-
-int windowProc () {
- return EditProc;
-}
-
-LRESULT WM_CHAR (int wParam, int lParam) {
- if (ignoreCharacter) return null;
- LRESULT result = super.WM_CHAR (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.
- */
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_MULTILINE) == 0) {
- switch (wParam) {
- case OS.VK_RETURN:
- postEvent (SWT.DefaultSelection);
- // FALL THROUGH
- case OS.VK_TAB:
- case OS.VK_ESCAPE: return LRESULT.ZERO;
- }
- }
- return result;
-}
-
-LRESULT WM_CLEAR (int wParam, int lParam) {
- LRESULT result = super.WM_CLEAR (wParam, lParam);
- if (result != null) return result;
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return result;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_READONLY) != 0) return result;
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (start [0] == end [0]) return result;
- String newText = verifyText ("", start [0], end [0]);
- if (newText == null) return LRESULT.ZERO;
- if (newText.length () != 0) {
- result = new LRESULT (callWindowProc (OS.WM_CLEAR, 0, 0));
- newText = Display.withCrLf (newText);
- TCHAR buffer = new TCHAR (getCodePage (), newText, true);
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
- }
- return result;
-}
-
-LRESULT WM_CUT (int wParam, int lParam) {
- LRESULT result = super.WM_CUT (wParam, lParam);
- if (result != null) return result;
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return result;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_READONLY) != 0) return result;
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- if (start [0] == end [0]) return result;
- String newText = verifyText ("", start [0], end [0]);
- if (newText == null) return LRESULT.ZERO;
- if (newText.length () != 0) {
- result = new LRESULT (callWindowProc (OS.WM_CUT, 0, 0));
- newText = Display.withCrLf (newText);
- TCHAR buffer = new TCHAR (getCodePage (), newText, true);
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
- }
- return result;
-}
-
-LRESULT WM_GETDLGCODE (int wParam, int lParam) {
- LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. Despite the fact that the
- * text control is read only, it still returns a
- * dialog code indicating that it wants keys. The
- * fix is to detect this case and clear the bits.
- */
- if ((style & SWT.READ_ONLY) != 0) {
- int code = callWindowProc (OS.WM_GETDLGCODE, wParam, lParam);
- code &= ~(OS.DLGC_WANTALLKEYS | OS.DLGC_WANTTAB | OS.DLGC_WANTARROWS);
- return new LRESULT (code);
- }
- return null;
-}
-
-LRESULT WM_IME_CHAR (int wParam, int lParam) {
-
- /* Process a DBCS character */
- Display display = getDisplay ();
- display.lastKey = 0;
- display.lastAscii = wParam;
- display.lastVirtual = display.lastNull = false;
- if (!sendKeyEvent (SWT.KeyDown, OS.WM_IME_CHAR, wParam, lParam)) {
- return LRESULT.ZERO;
- }
- sendKeyEvent (SWT.KeyUp, OS.WM_IME_CHAR, wParam, lParam);
- display.lastKey = display.lastAscii = 0;
-
- /*
- * 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 (OS.WM_IME_CHAR, wParam, lParam);
- MSG msg = new MSG ();
- while (OS.PeekMessage (msg, handle, OS.WM_CHAR, OS.WM_CHAR, OS.PM_REMOVE)) {
- OS.TranslateMessage (msg);
- OS.DispatchMessage (msg);
- }
- ignoreCharacter = false;
- 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.
- */
- sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
- sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_LBUTTONDBLCLK, wParam, lParam);
- 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 result = OS.SendMessage (handle, OS.EM_LINELENGTH, length, 0);
- if (result == 0) return LRESULT.ZERO;
- }
- }
- return null;
-}
-
-LRESULT WM_PASTE (int wParam, int lParam) {
- LRESULT result = super.WM_PASTE (wParam, lParam);
- if (result != null) return result;
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return result;
- int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
- if ((bits & OS.ES_READONLY) != 0) return result;
- String oldText = getClipboardText ();
- if (oldText == null) return result;
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- String newText = verifyText (oldText, start [0], end [0]);
- if (newText == null) return LRESULT.ZERO;
- if (newText != oldText) {
- newText = Display.withCrLf (newText);
- TCHAR buffer = new TCHAR (getCodePage (), newText, true);
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
- return LRESULT.ZERO;
- }
- return result;
-}
-
-LRESULT WM_UNDO (int wParam, int lParam) {
- LRESULT result = super.WM_UNDO (wParam, lParam);
- if (result != null) return result;
- if (!hooks (SWT.Verify) && !filters (SWT.Verify)) {
- return result;
- }
-
- /* Undo and then Redo to get the Undo text */
- if (OS.SendMessage (handle, OS.EM_CANUNDO, 0, 0) == 0) {
- return result;
- }
- ignoreVerify = true;
- callWindowProc (OS.WM_UNDO, wParam, lParam);
- String oldText = getSelectionText ();
- callWindowProc (OS.WM_UNDO, wParam, lParam);
- ignoreVerify = false;
-
- /* Verify the Undo operation */
- int [] start = new int [1], end = new int [1];
- OS.SendMessage (handle, OS.EM_GETSEL, start, end);
- String newText = verifyText (oldText, start [0], end [0]);
- if (newText == null) return LRESULT.ZERO;
- if (newText != oldText) {
- newText = Display.withCrLf (newText);
- TCHAR buffer = new TCHAR (getCodePage (), newText, true);
- OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
- return LRESULT.ZERO;
- }
-
- /* Do the original Undo */
- ignoreVerify = true;
- callWindowProc (OS.WM_UNDO, wParam, lParam);
- ignoreVerify = false;
- return LRESULT.ONE;
-}
-
-LRESULT wmCommandChild (int wParam, int lParam) {
- int code = wParam >> 16;
- switch (code) {
- case OS.EN_CHANGE:
- /*
- * 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;
- }
- return super.wmCommandChild (wParam, lParam);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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, 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, ignoreVerify, ignoreCharacter;
+
+ public static final int LIMIT;
+ 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 = 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;
+ }
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * lists the style constants that are applicable to the class.
+ * Style bits are also inherited from superclasses.
+ * </p>
+ *
+ * @param parent a composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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 msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (EditProc, handle, 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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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);
+ if (string == null) return;
+ }
+ OS.SendMessage (handle, OS.EM_SETSEL, length, length);
+ TCHAR buffer = new TCHAR (getCodePage (), string, true);
+ OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
+ OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
+}
+
+static int checkStyle (int style) {
+ 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;
+ 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 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 = new TEXTMETRIC ();
+ OS.GetTextMetrics (hDC, tm);
+ int count = OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0);
+ int height = count * tm.tmHeight, width = 0;
+ 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;
+ }
+ String text = getText ();
+ TCHAR buffer = new TCHAR (getCodePage (), text, false);
+ OS.DrawText (hDC, buffer, 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;
+
+ /* Calculate the margin width */
+ int margins = OS.SendMessage(handle, OS.EM_GETMARGINS, 0, 0);
+ int marginWidth = (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF);
+ width += marginWidth;
+
+ /*
+ * 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.
+ */
+ if ((style & SWT.V_SCROLL) != 0) {
+ width += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
+ }
+ if ((style & SWT.H_SCROLL) != 0) {
+ height += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
+ if ((style & SWT.BORDER) == 0) width++;
+ }
+ if ((style & SWT.BORDER) != 0) {
+ int border = getBorderWidth ();
+ width += (border * 2) + 3;
+ height += (border * 2) + 3;
+ }
+ 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>
+ */
+public void copy () {
+ checkWidget ();
+ OS.SendMessage (handle, OS.WM_COPY, 0, 0);
+}
+
+void createWidget () {
+ super.createWidget ();
+ doubleClick = true;
+ setTabStops (tabs = 8);
+}
+
+/**
+ * Cuts the selected text.
+ * <p>
+ * The current selection is first copied to the
+ * clipboard and then deleted from the widget.
+ * </p>
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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.SendMessage (handle, OS.WM_CUT, 0, 0);
+}
+
+int defaultBackground () {
+ return OS.GetSysColor (OS.COLOR_WINDOW);
+}
+
+/**
+ * Gets the line number of the caret.
+ * <p>
+ * The line number of the caret is returned.
+ * </p>
+ *
+ * @return the line number
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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);
+}
+
+/**
+ * Gets the location the caret.
+ * <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 [] start = new int [1];
+ OS.SendMessage (handle, OS.EM_GETSEL, start, (int []) null);
+ int pos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0);
+ if (pos == -1) {
+ pos = 0;
+ if (start [0] >= OS.GetWindowTextLength (handle)) {
+ int cp = getCodePage ();
+ OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, " ", true));
+ pos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0);
+ OS.SendMessage (handle, OS.EM_SETSEL, start [0], start [0] + 1);
+ OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, "", true));
+ }
+ }
+ return new Point ((short) (pos & 0xFFFF), (short) (pos >> 16));
+}
+
+/**
+ * Gets the position of the caret.
+ * <p>
+ * The character position of the caret is returned.
+ * </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);
+ int startLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, start [0], 0);
+ int caretPos = OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0);
+ int caretLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, caretPos, 0);
+ int caret = end [0];
+ if (caretLine == startLine) caret = start [0];
+ if (OS.IsDBLocale) caret = mbcsToWcsPos (caret);
+ return caret;
+}
+
+/**
+ * Gets 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.IsDBLocale) length = mbcsToWcsPos (length);
+ return length;
+}
+
+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;
+}
+
+/**
+ * Gets 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>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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;
+}
+
+/**
+ * Gets 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>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public char getEchoChar () {
+ checkWidget ();
+ char echo = (char) OS.SendMessage (handle, OS.EM_GETPASSWORDCHAR, 0, 0);
+ if (echo != 0 && (echo = mbcsToWcs (echo, getCodePage ())) == 0) echo = '*';
+ return echo;
+}
+
+/**
+ * Gets the 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 boolean getEditable () {
+ checkWidget ();
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ return (bits & OS.ES_READONLY) == 0;
+}
+
+/**
+ * Gets 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);
+}
+
+/**
+ * Gets 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>
+ */
+public String getLineDelimiter () {
+ checkWidget ();
+ return DELIMITER;
+}
+
+/**
+ * Gets 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 = new TEXTMETRIC ();
+ OS.GetTextMetrics (hDC, tm);
+ if (newFont != 0) OS.SelectObject (hDC, oldFont);
+ OS.ReleaseDC (handle, hDC);
+ return tm.tmHeight;
+}
+
+/**
+ * Gets the position of the selected text.
+ * <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 the start and end of 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 Point getSelection () {
+ checkWidget ();
+ int [] start = new int [1], end = new int [1];
+ OS.SendMessage (handle, OS.EM_GETSEL, start, end);
+ if (OS.IsDBLocale) {
+ start [0] = mbcsToWcsPos (start [0]);
+ end [0] = mbcsToWcsPos (end [0]);
+ }
+ return new Point (start [0], end [0]);
+}
+
+/**
+ * Gets 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.
+ *
+ * @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);
+}
+
+/**
+ * Gets 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;
+}
+
+/**
+ * Gets the widget text.
+ * <p>
+ * The text for a text widget is the characters in the widget.
+ * </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);
+}
+
+/**
+ * Gets a range of text.
+ * <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 ();
+ /*
+ * 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>
+ */
+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 ();
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & OS.ES_MULTILINE) == 0) return 0;
+ return OS.SendMessage (handle, OS.EM_GETFIRSTVISIBLELINE, 0, 0);
+}
+
+/**
+ * Gets 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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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]);
+ if (string == null) return;
+ }
+ TCHAR buffer = new TCHAR (getCodePage (), string, true);
+ OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
+}
+
+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];
+ }
+ 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 ();
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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
+ */
+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 (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 */
+ switch (msg) {
+ case OS.WM_CHAR:
+ if (key != 0x08 && key != 0x7F && key != '\r' && key != '\t' && key != '\n') break;
+ // FALL THROUGH
+ case OS.WM_KEYDOWN:
+ int modifiers = SWT.ALT | SWT.SHIFT | SWT.CONTROL;
+ if ((stateMask & modifiers) != 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 (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.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.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 */
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & OS.ES_MULTILINE) == 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]);
+ OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
+ 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);
+ if (rect.right - rect.left == 0) {
+ int [] start = new int [1], end = new int [1];
+ OS.SendMessage (handle, OS.EM_GETSEL, start, end);
+ if (start [0] != 0 || end [0] != 0) {
+ OS.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>
+ *
+ * @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,
+ * 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 (echo != 0) {
+ if ((echo = (char) 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 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.IsDBLocale) start = wcsToMbcsPos (start);
+ OS.SendMessage (handle, OS.EM_SETSEL, start, start);
+ OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
+}
+
+/**
+ * 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
+ * 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.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 text 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];
+ return;
+ }
+ if (oldStart == start [0] && oldEnd == end [0]) return;
+ OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
+}
+
+/**
+ * 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
+ * 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 text 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);
+ 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>.
+ * </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>
+ */
+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 ();
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & OS.ES_MULTILINE) == 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 IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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) {
+ return verifyText (string, start, end, null);
+}
+
+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.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 ();
+ 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 | OS.ES_AUTOHSCROLL;
+ bits |= OS.ES_MULTILINE | OS.ES_AUTOHSCROLL | OS.ES_NOHIDESEL;
+ if ((style & SWT.WRAP) != 0) bits &= ~(OS.WS_HSCROLL | OS.ES_AUTOHSCROLL);
+ return bits;
+}
+
+TCHAR windowClass () {
+ return EditClass;
+}
+
+int windowProc () {
+ return EditProc;
+}
+
+LRESULT WM_CHAR (int wParam, int lParam) {
+ if (ignoreCharacter) return null;
+ LRESULT result = super.WM_CHAR (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.
+ */
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & OS.ES_MULTILINE) == 0) {
+ switch (wParam) {
+ case OS.VK_RETURN:
+ postEvent (SWT.DefaultSelection);
+ // FALL THROUGH
+ case OS.VK_TAB:
+ case OS.VK_ESCAPE: return LRESULT.ZERO;
+ }
+ }
+ return result;
+}
+
+LRESULT WM_CLEAR (int wParam, int lParam) {
+ LRESULT result = super.WM_CLEAR (wParam, lParam);
+ if (result != null) return result;
+ if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return result;
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & OS.ES_READONLY) != 0) return result;
+ int [] start = new int [1], end = new int [1];
+ OS.SendMessage (handle, OS.EM_GETSEL, start, end);
+ if (start [0] == end [0]) return result;
+ String newText = verifyText ("", start [0], end [0]);
+ if (newText == null) return LRESULT.ZERO;
+ if (newText.length () != 0) {
+ result = new LRESULT (callWindowProc (OS.WM_CLEAR, 0, 0));
+ newText = Display.withCrLf (newText);
+ TCHAR buffer = new TCHAR (getCodePage (), newText, true);
+ OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
+ }
+ return result;
+}
+
+LRESULT WM_CUT (int wParam, int lParam) {
+ LRESULT result = super.WM_CUT (wParam, lParam);
+ if (result != null) return result;
+ if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return result;
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & OS.ES_READONLY) != 0) return result;
+ int [] start = new int [1], end = new int [1];
+ OS.SendMessage (handle, OS.EM_GETSEL, start, end);
+ if (start [0] == end [0]) return result;
+ String newText = verifyText ("", start [0], end [0]);
+ if (newText == null) return LRESULT.ZERO;
+ if (newText.length () != 0) {
+ result = new LRESULT (callWindowProc (OS.WM_CUT, 0, 0));
+ newText = Display.withCrLf (newText);
+ TCHAR buffer = new TCHAR (getCodePage (), newText, true);
+ OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
+ }
+ return result;
+}
+
+LRESULT WM_GETDLGCODE (int wParam, int lParam) {
+ LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
+ if (result != null) return result;
+ /*
+ * Feature in Windows. Despite the fact that the
+ * text control is read only, it still returns a
+ * dialog code indicating that it wants keys. The
+ * fix is to detect this case and clear the bits.
+ */
+ if ((style & SWT.READ_ONLY) != 0) {
+ int code = callWindowProc (OS.WM_GETDLGCODE, wParam, lParam);
+ code &= ~(OS.DLGC_WANTALLKEYS | OS.DLGC_WANTTAB | OS.DLGC_WANTARROWS);
+ return new LRESULT (code);
+ }
+ return null;
+}
+
+LRESULT WM_IME_CHAR (int wParam, int lParam) {
+
+ /* Process a DBCS character */
+ Display display = getDisplay ();
+ display.lastKey = 0;
+ display.lastAscii = wParam;
+ display.lastVirtual = display.lastNull = false;
+ if (!sendKeyEvent (SWT.KeyDown, OS.WM_IME_CHAR, wParam, lParam)) {
+ return LRESULT.ZERO;
+ }
+ sendKeyEvent (SWT.KeyUp, OS.WM_IME_CHAR, wParam, lParam);
+ display.lastKey = display.lastAscii = 0;
+
+ /*
+ * 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 (OS.WM_IME_CHAR, wParam, lParam);
+ MSG msg = new MSG ();
+ while (OS.PeekMessage (msg, handle, OS.WM_CHAR, OS.WM_CHAR, OS.PM_REMOVE)) {
+ OS.TranslateMessage (msg);
+ OS.DispatchMessage (msg);
+ }
+ ignoreCharacter = false;
+ 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.
+ */
+ sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
+ sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_LBUTTONDBLCLK, wParam, lParam);
+ 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 result = OS.SendMessage (handle, OS.EM_LINELENGTH, length, 0);
+ if (result == 0) return LRESULT.ZERO;
+ }
+ }
+ return null;
+}
+
+LRESULT WM_PASTE (int wParam, int lParam) {
+ LRESULT result = super.WM_PASTE (wParam, lParam);
+ if (result != null) return result;
+ if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return result;
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & OS.ES_READONLY) != 0) return result;
+ String oldText = getClipboardText ();
+ if (oldText == null) return result;
+ int [] start = new int [1], end = new int [1];
+ OS.SendMessage (handle, OS.EM_GETSEL, start, end);
+ String newText = verifyText (oldText, start [0], end [0]);
+ if (newText == null) return LRESULT.ZERO;
+ if (newText != oldText) {
+ newText = Display.withCrLf (newText);
+ TCHAR buffer = new TCHAR (getCodePage (), newText, true);
+ OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
+ return LRESULT.ZERO;
+ }
+ return result;
+}
+
+LRESULT WM_UNDO (int wParam, int lParam) {
+ LRESULT result = super.WM_UNDO (wParam, lParam);
+ if (result != null) return result;
+ if (!hooks (SWT.Verify) && !filters (SWT.Verify)) {
+ return result;
+ }
+
+ /* Undo and then Redo to get the Undo text */
+ if (OS.SendMessage (handle, OS.EM_CANUNDO, 0, 0) == 0) {
+ return result;
+ }
+ ignoreVerify = true;
+ callWindowProc (OS.WM_UNDO, wParam, lParam);
+ String oldText = getSelectionText ();
+ callWindowProc (OS.WM_UNDO, wParam, lParam);
+ ignoreVerify = false;
+
+ /* Verify the Undo operation */
+ int [] start = new int [1], end = new int [1];
+ OS.SendMessage (handle, OS.EM_GETSEL, start, end);
+ String newText = verifyText (oldText, start [0], end [0]);
+ if (newText == null) return LRESULT.ZERO;
+ if (newText != oldText) {
+ newText = Display.withCrLf (newText);
+ TCHAR buffer = new TCHAR (getCodePage (), newText, true);
+ OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
+ return LRESULT.ZERO;
+ }
+
+ /* Do the original Undo */
+ ignoreVerify = true;
+ callWindowProc (OS.WM_UNDO, wParam, lParam);
+ ignoreVerify = false;
+ return LRESULT.ONE;
+}
+
+LRESULT wmCommandChild (int wParam, int lParam) {
+ int code = wParam >> 16;
+ switch (code) {
+ case OS.EN_CHANGE:
+ /*
+ * 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;
+ }
+ 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
index 2abda90e58..5d431f6bc0 100755
--- 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
@@ -1,928 +1,928 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- 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.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- }
-}
-
-int callWindowProc (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 (handle, msg, wParam, lParam);
- }
- return OS.CallWindowProc (ToolBarProc, handle, 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.
- */
- /*
- * This code is intentionally commented.
- */
- //if ((style & SWT.VERTICAL) != 0) style &= ~SWT.WRAP;
-
- /*
- * The TB_SETROWS calls are currently commented, so force
- * the wrap style if this bar is vertical.
- */
- 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);
-}
-
-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);
- }
- int width = 0, height = 0;
- 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;
- OS.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);
- }
- OS.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 (COMCTL32_MAJOR < 6) {
- 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 */
- OS.SendMessage (handle, OS.TB_SETEXTENDEDSTYLE, 0, OS.TBSTYLE_EX_DRAWDDARROWS);
-}
-
-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;
- /*
- * This code is intentionally commented.
- */
-// if ((style & SWT.VERTICAL) != 0) {
-// OS.SendMessage (handle, OS.TB_SETROWS, count+1, 0);
-// }
- 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) {
- Display display = getDisplay ();
- 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];
- }
- /*
- * This code is intentionally commented.
- */
-// if ((style & SWT.VERTICAL) != 0) {
-// OS.SendMessage (handle, OS.TB_SETROWS, count-1, 0);
-// }
- layoutItems ();
-}
-
-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 listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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>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 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 ();
- 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 () {
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null) item.resizeControl ();
- }
-}
-
-boolean mnemonicHit (char ch) {
- int key = wcsToMbcs (ch);
- int [] id = new int [1];
- if (OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, id) == 0) {
- return false;
- }
- if (!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 = wcsToMbcs (ch);
- int [] id = new int [1];
- return OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, id) != 0;
-}
-
-void releaseWidget () {
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.releaseImages ();
- item.releaseResources ();
- }
- }
- items = null;
- Display display = getDisplay ();
- 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;
- super.releaseWidget ();
-}
-
-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 setDisabledImageList (ImageList imageList) {
- if (disabledImageList == imageList) return;
- int hImageList = 0;
- if ((disabledImageList = imageList) != null) {
- hImageList = disabledImageList.getHandle ();
- }
- OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, hImageList);
-}
-
-void setHotImageList (ImageList imageList) {
- if (hotImageList == imageList) return;
- int hImageList = 0;
- if ((hotImageList = imageList) != null) {
- hImageList = hotImageList.getHandle ();
- }
- OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, hImageList);
-}
-
-void setImageList (ImageList imageList) {
- if (this.imageList == imageList) return;
- int hImageList = 0;
- if ((this.imageList = imageList) != null) {
- hImageList = imageList.getHandle ();
- }
- OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, hImageList);
-}
-
-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;
- }
- int index = hdr.idFrom;
- int hwndToolTip = OS.SendMessage (handle, OS.TB_GETTOOLTIPS, 0, 0);
- if (hwndToolTip == hdr.hwndFrom) {
- if (toolTipText != null) return "";
- 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;
- 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;
- if ((style & SWT.RIGHT) != 0) bits |= OS.TBSTYLE_LIST;
- return bits;
-}
-
-TCHAR windowClass () {
- return ToolBarClass;
-}
-
-int windowProc () {
- return ToolBarProc;
-}
-
-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_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_KEYDOWN (int wParam, int lParam) {
- LRESULT result = super.WM_KEYDOWN (wParam, lParam);
- if (result != null) return result;
- switch (wParam) {
- case OS.VK_RETURN:
- case OS.VK_SPACE:
- 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 (wParam == OS.VK_RETURN);
- 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_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 (OS.WM_SIZE, wParam, lParam);
- if (code == 0) return LRESULT.ZERO;
- return new LRESULT (code);
- }
- /*
- * Feature in Windows. When a tool bar that contains
- * separators is wrapped, under certain circumstances,
- * Windows redraws the entire tool bar unnecessarily
- * when resized no item is moves. Whether the entire
- * toolbar is damaged or not seems to depend on the
- * size of the tool bar and the position of the separators.
- * The fix is to ensure that the newly exposed areas are
- * always damaged, and avoid the redraw when no tool item
- * moves.
- */
- RECT [] rects = null;
- int rgn = 0, oldCount = 0;
- boolean fixRedraw = drawCount == 0 &&
- (style & SWT.WRAP) != 0 &&
- OS.IsWindowVisible (handle) &&
- OS.SendMessage (handle, OS.TB_GETROWS, 0, 0) != 1;
- if (fixRedraw) {
- rgn = OS.CreateRectRgn (0, 0, 0, 0);
- OS.GetUpdateRgn (handle, rgn, false);
- oldCount = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- rects = new RECT [oldCount];
- for (int i=0; i<oldCount; i++) {
- rects [i] = new RECT ();
- OS.SendMessage (handle, OS.TB_GETITEMRECT, i, rects [i]);
- }
- }
-
- 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 (fixRedraw) {
- int newCount = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
- if (newCount == oldCount) {
- int index = 0;
- RECT rect = new RECT ();
- while (index < newCount) {
- OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect);
- if (!OS.EqualRect (rects [index], rect)) break;
- index++;
- }
- if (index == newCount) {
- OS.ValidateRect (handle, null);
- OS.InvalidateRgn (handle, rgn, false);
- }
- }
- OS.DeleteObject (rgn);
- }
-
- layoutItems ();
- return result;
-}
-
-LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) {
- LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam);
- if (result != null) return result;
- /*
- * Feature in Windows. When a tool bar that contains
- * separators is wrapped, under certain circumstances,
- * Windows redraws the entire tool bar unnecessarily
- * when resized no item is moves. Whether the entire
- * toolbar is damaged or not seems to depend on the
- * size of the tool bar and the position of the separators.
- * The fix is to ensure that the newly exposed areas are
- * always damaged, and avoid the redraw when no tool item
- * moves.
- */
- 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 oldHeight = oldRect.bottom - oldRect.top;
- int newWidth = newRect.right - newRect.left;
- int newHeight = newRect.bottom - newRect.top;
- if (newWidth > oldWidth) {
- /*
- * 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.
- */
- RECT rect = new RECT ();
- OS.SetRect (rect, oldWidth - 2, 0, oldWidth, newHeight);
- OS.InvalidateRect (handle, rect, false);
- OS.SetRect (rect, oldRect.right, newRect.top, newRect.right, newRect.bottom);
- OS.InvalidateRect (handle, rect, true);
- }
- if (newHeight > oldHeight) {
- RECT rect = new RECT ();
- OS.SetRect (rect, newRect.left, oldRect.bottom, newRect.right, newRect.bottom);
- OS.InvalidateRect (handle, rect, true);
- }
- 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);
- return null;
- }
- break;
- }
- return super.wmNotifyChild (wParam, lParam);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+ 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.
+ */
+ if ((style & SWT.VERTICAL) != 0) {
+ this.style |= SWT.VERTICAL;
+ } else {
+ this.style |= SWT.HORIZONTAL;
+ }
+}
+
+int callWindowProc (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 (handle, msg, wParam, lParam);
+ }
+ return OS.CallWindowProc (ToolBarProc, handle, 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.
+ */
+ /*
+ * This code is intentionally commented.
+ */
+ //if ((style & SWT.VERTICAL) != 0) style &= ~SWT.WRAP;
+
+ /*
+ * The TB_SETROWS calls are currently commented, so force
+ * the wrap style if this bar is vertical.
+ */
+ 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);
+}
+
+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);
+ }
+ int width = 0, height = 0;
+ 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;
+ OS.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);
+ }
+ OS.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 (COMCTL32_MAJOR < 6) {
+ 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 */
+ OS.SendMessage (handle, OS.TB_SETEXTENDEDSTYLE, 0, OS.TBSTYLE_EX_DRAWDDARROWS);
+}
+
+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;
+ /*
+ * This code is intentionally commented.
+ */
+// if ((style & SWT.VERTICAL) != 0) {
+// OS.SendMessage (handle, OS.TB_SETROWS, count+1, 0);
+// }
+ 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) {
+ Display display = getDisplay ();
+ 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];
+ }
+ /*
+ * This code is intentionally commented.
+ */
+// if ((style & SWT.VERTICAL) != 0) {
+// OS.SendMessage (handle, OS.TB_SETROWS, count-1, 0);
+// }
+ layoutItems ();
+}
+
+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 listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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>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 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 ();
+ 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 () {
+ for (int i=0; i<items.length; i++) {
+ ToolItem item = items [i];
+ if (item != null) item.resizeControl ();
+ }
+}
+
+boolean mnemonicHit (char ch) {
+ int key = wcsToMbcs (ch);
+ int [] id = new int [1];
+ if (OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, id) == 0) {
+ return false;
+ }
+ if (!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 = wcsToMbcs (ch);
+ int [] id = new int [1];
+ return OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, id) != 0;
+}
+
+void releaseWidget () {
+ for (int i=0; i<items.length; i++) {
+ ToolItem item = items [i];
+ if (item != null && !item.isDisposed ()) {
+ item.releaseImages ();
+ item.releaseResources ();
+ }
+ }
+ items = null;
+ Display display = getDisplay ();
+ 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;
+ super.releaseWidget ();
+}
+
+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 setDisabledImageList (ImageList imageList) {
+ if (disabledImageList == imageList) return;
+ int hImageList = 0;
+ if ((disabledImageList = imageList) != null) {
+ hImageList = disabledImageList.getHandle ();
+ }
+ OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, hImageList);
+}
+
+void setHotImageList (ImageList imageList) {
+ if (hotImageList == imageList) return;
+ int hImageList = 0;
+ if ((hotImageList = imageList) != null) {
+ hImageList = hotImageList.getHandle ();
+ }
+ OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, hImageList);
+}
+
+void setImageList (ImageList imageList) {
+ if (this.imageList == imageList) return;
+ int hImageList = 0;
+ if ((this.imageList = imageList) != null) {
+ hImageList = imageList.getHandle ();
+ }
+ OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, hImageList);
+}
+
+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;
+ }
+ int index = hdr.idFrom;
+ int hwndToolTip = OS.SendMessage (handle, OS.TB_GETTOOLTIPS, 0, 0);
+ if (hwndToolTip == hdr.hwndFrom) {
+ if (toolTipText != null) return "";
+ 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;
+ 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;
+ if ((style & SWT.RIGHT) != 0) bits |= OS.TBSTYLE_LIST;
+ return bits;
+}
+
+TCHAR windowClass () {
+ return ToolBarClass;
+}
+
+int windowProc () {
+ return ToolBarProc;
+}
+
+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_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_KEYDOWN (int wParam, int lParam) {
+ LRESULT result = super.WM_KEYDOWN (wParam, lParam);
+ if (result != null) return result;
+ switch (wParam) {
+ case OS.VK_RETURN:
+ case OS.VK_SPACE:
+ 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 (wParam == OS.VK_RETURN);
+ 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_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 (OS.WM_SIZE, wParam, lParam);
+ if (code == 0) return LRESULT.ZERO;
+ return new LRESULT (code);
+ }
+ /*
+ * Feature in Windows. When a tool bar that contains
+ * separators is wrapped, under certain circumstances,
+ * Windows redraws the entire tool bar unnecessarily
+ * when resized no item is moves. Whether the entire
+ * toolbar is damaged or not seems to depend on the
+ * size of the tool bar and the position of the separators.
+ * The fix is to ensure that the newly exposed areas are
+ * always damaged, and avoid the redraw when no tool item
+ * moves.
+ */
+ RECT [] rects = null;
+ int rgn = 0, oldCount = 0;
+ boolean fixRedraw = drawCount == 0 &&
+ (style & SWT.WRAP) != 0 &&
+ OS.IsWindowVisible (handle) &&
+ OS.SendMessage (handle, OS.TB_GETROWS, 0, 0) != 1;
+ if (fixRedraw) {
+ rgn = OS.CreateRectRgn (0, 0, 0, 0);
+ OS.GetUpdateRgn (handle, rgn, false);
+ oldCount = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
+ rects = new RECT [oldCount];
+ for (int i=0; i<oldCount; i++) {
+ rects [i] = new RECT ();
+ OS.SendMessage (handle, OS.TB_GETITEMRECT, i, rects [i]);
+ }
+ }
+
+ 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 (fixRedraw) {
+ int newCount = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);
+ if (newCount == oldCount) {
+ int index = 0;
+ RECT rect = new RECT ();
+ while (index < newCount) {
+ OS.SendMessage (handle, OS.TB_GETITEMRECT, index, rect);
+ if (!OS.EqualRect (rects [index], rect)) break;
+ index++;
+ }
+ if (index == newCount) {
+ OS.ValidateRect (handle, null);
+ OS.InvalidateRgn (handle, rgn, false);
+ }
+ }
+ OS.DeleteObject (rgn);
+ }
+
+ layoutItems ();
+ return result;
+}
+
+LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) {
+ LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam);
+ if (result != null) return result;
+ /*
+ * Feature in Windows. When a tool bar that contains
+ * separators is wrapped, under certain circumstances,
+ * Windows redraws the entire tool bar unnecessarily
+ * when resized no item is moves. Whether the entire
+ * toolbar is damaged or not seems to depend on the
+ * size of the tool bar and the position of the separators.
+ * The fix is to ensure that the newly exposed areas are
+ * always damaged, and avoid the redraw when no tool item
+ * moves.
+ */
+ 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 oldHeight = oldRect.bottom - oldRect.top;
+ int newWidth = newRect.right - newRect.left;
+ int newHeight = newRect.bottom - newRect.top;
+ if (newWidth > oldWidth) {
+ /*
+ * 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.
+ */
+ RECT rect = new RECT ();
+ OS.SetRect (rect, oldWidth - 2, 0, oldWidth, newHeight);
+ OS.InvalidateRect (handle, rect, false);
+ OS.SetRect (rect, oldRect.right, newRect.top, newRect.right, newRect.bottom);
+ OS.InvalidateRect (handle, rect, true);
+ }
+ if (newHeight > oldHeight) {
+ RECT rect = new RECT ();
+ OS.SetRect (rect, newRect.left, oldRect.bottom, newRect.right, newRect.bottom);
+ OS.InvalidateRect (handle, rect, true);
+ }
+ 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);
+ return null;
+ }
+ 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
index 38602b3a35..be3712770d 100755
--- 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
@@ -1,831 +1,831 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
- /*
- * 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 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 lParam = (dropDown ? rect.right - 1 : rect.left) | (rect.top << 16);
- int hotIndex = OS.SendMessage (hwnd, OS.TB_GETHOTITEM, 0, 0);
- OS.SendMessage (hwnd, OS.WM_LBUTTONDOWN, 0, lParam);
- OS.SendMessage (hwnd, OS.WM_LBUTTONUP, 0, lParam);
- if (hotIndex != -1) {
- OS.SendMessage (hwnd, OS.TB_SETHOTITEM, hotIndex, 0);
- }
-}
-
-Image createDisabledImage (Image image, Color color) {
- Display display = getDisplay ();
- if (OS.IsWinCE) {
- return new Image (display, image, SWT.IMAGE_DISABLE);
- }
- Rectangle rect = image.getBounds ();
- Image disabled = new Image (display, rect);
- GC gc = new GC (disabled);
- gc.setBackground (color);
- gc.fillRectangle (rect);
- int hDC = gc.handle;
- int hImage = image.handle;
- int fuFlags = OS.DSS_DISABLED;
- switch (image.type) {
- case SWT.BITMAP: fuFlags |= OS.DST_BITMAP; break;
- case SWT.ICON: fuFlags |= OS.DST_ICON; break;
- }
- OS.DrawState (hDC, 0, 0, hImage, 0, 0, 0, rect.width, rect.height, fuFlags);
- gc.dispose ();
- return disabled;
-}
-
-/**
- * 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 items 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;
-}
-
-public Display getDisplay () {
- ToolBar parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
-/**
- * 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 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 releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
- control = null;
- toolTipText = null;
- disabledImage = hotImage = null;
- if (disabledImage2 != null) disabledImage2.dispose ();
- disabledImage2 = null;
-}
-
-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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 items 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;
- 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);
- fsState &= ~OS.TBSTATE_ENABLED;
- if (enabled) fsState |= OS.TBSTATE_ENABLED;
- OS.SendMessage (hwnd, OS.TB_SETSTATE, id, fsState);
- if (image != null) updateImages ();
-}
-
-/**
- * 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 ();
-}
-
-/**
- * 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 ();
-}
-
-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 ();
-}
-
-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);
- fsState &= ~OS.TBSTATE_CHECKED;
- if (selected) fsState |= OS.TBSTATE_CHECKED;
- OS.SendMessage (hwnd, OS.TB_SETSTATE, id, fsState);
-}
-/**
- * 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);
- 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);
- TBBUTTONINFO info = new TBBUTTONINFO ();
- info.cbSize = TBBUTTONINFO.sizeof;
- info.dwMask = OS.TBIF_TEXT | OS.TBIF_STYLE;
- info.pszText = pszText;
- info.fsStyle = (byte) (widgetStyle () | OS.BTNS_AUTOSIZE);
- OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, info);
- 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. [1G0G7TV, 1G0FUJ5]
- */
- int hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
- OS.SendMessage (hwnd, OS.WM_SETFONT, hFont, 0);
-
- 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.
- *
- * @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 () {
- 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) {
- Display display = getDisplay ();
- Rectangle bounds = image.getBounds ();
- Point size = new Point (bounds.width, bounds.height);
- if (imageList == null) imageList = display.getToolImageList (size);
- info.iImage = imageList.add (image);
- parent.setImageList (imageList);
- if (disabledImageList == null) disabledImageList = display.getToolDisabledImageList (size);
- Image disabled = disabledImage;
- if (disabledImage == null) {
- if (disabledImage2 != null) disabledImage2.dispose ();
- disabledImage2 = null;
- disabled = image;
- if (!getEnabled ()) {
- Color color = parent.getBackground ();
- disabled = disabledImage2 = createDisabledImage (image, color);
- }
- }
- disabledImageList.add (disabled);
- parent.setDisabledImageList (disabledImageList);
-// if ((parent.style & SWT.FLAT) != 0) {
- if (hotImageList == null) hotImageList = display.getToolHotImageList (size);
- hotImageList.add (hotImage != null ? hotImage : image);
- parent.setHotImageList (hotImageList);
-// }
- } else {
- if (imageList != null) imageList.put (info.iImage, image);
- if (disabledImageList != null) {
- Image disabled = null;
- if (image != null) {
- if (disabledImage2 != null) disabledImage2.dispose ();
- disabledImage2 = null;
- disabled = disabledImage;
- if (disabledImage == null) {
- disabled = image;
- if (!getEnabled ()) {
- Color color = parent.getBackground ();
- disabled = disabledImage2 = createDisabledImage (image, color);
- }
- }
- }
- disabledImageList.put (info.iImage, disabled);
- }
- if (hotImageList != null) {
- Image hot = null;
- if (image != null) hot = hotImage != null ? hotImage : image;
- hotImageList.put (info.iImage, hot);
- }
- if (image == null) info.iImage = OS.I_IMAGENONE;
- }
- 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 ();
- }
- }
- Event event = new Event ();
- setInputState (event, SWT.Selection);
- postEvent (SWT.Selection, event);
- return null;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
+ /*
+ * 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 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 lParam = (dropDown ? rect.right - 1 : rect.left) | (rect.top << 16);
+ int hotIndex = OS.SendMessage (hwnd, OS.TB_GETHOTITEM, 0, 0);
+ OS.SendMessage (hwnd, OS.WM_LBUTTONDOWN, 0, lParam);
+ OS.SendMessage (hwnd, OS.WM_LBUTTONUP, 0, lParam);
+ if (hotIndex != -1) {
+ OS.SendMessage (hwnd, OS.TB_SETHOTITEM, hotIndex, 0);
+ }
+}
+
+Image createDisabledImage (Image image, Color color) {
+ Display display = getDisplay ();
+ if (OS.IsWinCE) {
+ return new Image (display, image, SWT.IMAGE_DISABLE);
+ }
+ Rectangle rect = image.getBounds ();
+ Image disabled = new Image (display, rect);
+ GC gc = new GC (disabled);
+ gc.setBackground (color);
+ gc.fillRectangle (rect);
+ int hDC = gc.handle;
+ int hImage = image.handle;
+ int fuFlags = OS.DSS_DISABLED;
+ switch (image.type) {
+ case SWT.BITMAP: fuFlags |= OS.DST_BITMAP; break;
+ case SWT.ICON: fuFlags |= OS.DST_ICON; break;
+ }
+ OS.DrawState (hDC, 0, 0, hImage, 0, 0, 0, rect.width, rect.height, fuFlags);
+ gc.dispose ();
+ return disabled;
+}
+
+/**
+ * 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 items 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;
+}
+
+public Display getDisplay () {
+ ToolBar parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
+/**
+ * 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 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 releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ parent = null;
+ control = null;
+ toolTipText = null;
+ disabledImage = hotImage = null;
+ if (disabledImage2 != null) disabledImage2.dispose ();
+ disabledImage2 = null;
+}
+
+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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver 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 items 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;
+ 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);
+ fsState &= ~OS.TBSTATE_ENABLED;
+ if (enabled) fsState |= OS.TBSTATE_ENABLED;
+ OS.SendMessage (hwnd, OS.TB_SETSTATE, id, fsState);
+ if (image != null) updateImages ();
+}
+
+/**
+ * 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 ();
+}
+
+/**
+ * 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 ();
+}
+
+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 ();
+}
+
+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);
+ fsState &= ~OS.TBSTATE_CHECKED;
+ if (selected) fsState |= OS.TBSTATE_CHECKED;
+ OS.SendMessage (hwnd, OS.TB_SETSTATE, id, fsState);
+}
+/**
+ * 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);
+ 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);
+ TBBUTTONINFO info = new TBBUTTONINFO ();
+ info.cbSize = TBBUTTONINFO.sizeof;
+ info.dwMask = OS.TBIF_TEXT | OS.TBIF_STYLE;
+ info.pszText = pszText;
+ info.fsStyle = (byte) (widgetStyle () | OS.BTNS_AUTOSIZE);
+ OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, info);
+ 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. [1G0G7TV, 1G0FUJ5]
+ */
+ int hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
+ OS.SendMessage (hwnd, OS.WM_SETFONT, hFont, 0);
+
+ 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.
+ *
+ * @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 () {
+ 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) {
+ Display display = getDisplay ();
+ Rectangle bounds = image.getBounds ();
+ Point size = new Point (bounds.width, bounds.height);
+ if (imageList == null) imageList = display.getToolImageList (size);
+ info.iImage = imageList.add (image);
+ parent.setImageList (imageList);
+ if (disabledImageList == null) disabledImageList = display.getToolDisabledImageList (size);
+ Image disabled = disabledImage;
+ if (disabledImage == null) {
+ if (disabledImage2 != null) disabledImage2.dispose ();
+ disabledImage2 = null;
+ disabled = image;
+ if (!getEnabled ()) {
+ Color color = parent.getBackground ();
+ disabled = disabledImage2 = createDisabledImage (image, color);
+ }
+ }
+ disabledImageList.add (disabled);
+ parent.setDisabledImageList (disabledImageList);
+// if ((parent.style & SWT.FLAT) != 0) {
+ if (hotImageList == null) hotImageList = display.getToolHotImageList (size);
+ hotImageList.add (hotImage != null ? hotImage : image);
+ parent.setHotImageList (hotImageList);
+// }
+ } else {
+ if (imageList != null) imageList.put (info.iImage, image);
+ if (disabledImageList != null) {
+ Image disabled = null;
+ if (image != null) {
+ if (disabledImage2 != null) disabledImage2.dispose ();
+ disabledImage2 = null;
+ disabled = disabledImage;
+ if (disabledImage == null) {
+ disabled = image;
+ if (!getEnabled ()) {
+ Color color = parent.getBackground ();
+ disabled = disabledImage2 = createDisabledImage (image, color);
+ }
+ }
+ }
+ disabledImageList.put (info.iImage, disabled);
+ }
+ if (hotImageList != null) {
+ Image hot = null;
+ if (image != null) hot = hotImage != null ? hotImage : image;
+ hotImageList.put (info.iImage, hot);
+ }
+ if (image == null) info.iImage = OS.I_IMAGENONE;
+ }
+ 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 ();
+ }
+ }
+ Event event = new Event ();
+ setInputState (event, SWT.Selection);
+ postEvent (SWT.Selection, event);
+ return null;
+}
+
+}
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
index fec620169c..aab5fef74b 100755
--- 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
@@ -1,726 +1,726 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
- Display display;
- boolean tracking, stippled;
- Rectangle [] rectangles, proportions;
- int resizeCursor, clientCursor, cursorOrientation = SWT.NONE;
- boolean inEvent = false;
-
- /*
- * 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;
- display = parent.getDisplay ();
-}
-
-/**
- * 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.Move,typedListener);
-}
-
-Point adjustMoveCursor () {
- Rectangle bounds = computeBounds ();
- 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;
- Rectangle bounds = computeBounds ();
-
- 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];
- Rectangle bounds = computeBounds ();
- for (int i = 0; i < rects.length; i++) {
- result[i] = new Rectangle (
- (rects[i].x - bounds.x) * 100 / bounds.width,
- (rects[i].y - bounds.y) * 100 / bounds.height,
- rects[i].width * 100 / bounds.width,
- rects[i].height * 100 / bounds.height);
- }
- return result;
-}
-/**
- * Draw the rectangles displayed by the tracker.
- */
-void drawRectangles (Rectangle [] rects) {
- if (parent != null) {
- if (parent.isDisposed ()) return;
- Shell shell = parent.getShell ();
- shell.update (true);
- } else {
- display.update ();
- }
- 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);
-}
-
-public Display getDisplay () {
- return display;
-}
-
-/**
- * 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 ();
- return rectangles;
-}
-
-/**
- * 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)) return;
- if (xChange > 0 && ((style & SWT.RIGHT) == 0)) return;
- if (yChange < 0 && ((style & SWT.UP) == 0)) return;
- if (yChange > 0 && ((style & SWT.DOWN) == 0)) return;
- Rectangle bounds = computeBounds ();
- 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;
- boolean cancelled = false;
- tracking = true;
- Event event = new Event ();
- MSG msg = new MSG ();
- /*
- * 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);
- final int oldProc = OS.GetWindowLong (hwndTransparent, OS.GWL_WNDPROC);
- Object windowProc = new Object () {
- public int windowProc (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);
- }
- };
- newProc = new Callback (windowProc, "windowProc", 4);
- OS.SetWindowLong (hwndTransparent, OS.GWL_WNDPROC, newProc.getAddress ());
- }
-
- drawRectangles (rectangles);
- 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 ();
- }
- }
-
- int oldX = cursorPos.x, oldY = cursorPos.y;
- /*
- * Tracker behaves like a Dialog with its own OS event loop.
- */
- while (tracking && !cancelled) {
- if (parent != null && parent.isDisposed ()) break;
- OS.GetMessage (msg, 0, 0, 0);
- int message = msg.message;
- switch (message) {
- case OS.WM_LBUTTONUP:
- case OS.WM_MOUSEMOVE:
- int newPos = OS.GetMessagePos ();
- int newX = (short) (newPos & 0xFFFF);
- int newY = (short) (newPos >> 16);
- if (newX != oldX || newY != oldY) {
- drawRectangles (rectangles);
- event.x = newX;
- event.y = newY;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (newX - oldX, newY - oldY);
- cursorPos = adjustResizeCursor ();
- newX = cursorPos.x; newY = cursorPos.y;
- inEvent = true;
- sendEvent (SWT.Resize, event);
- } 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 ()) return false;
- drawRectangles (rectangles);
- oldX = newX; oldY = newY;
- }
- tracking = msg.message != OS.WM_LBUTTONUP;
- break;
- case OS.WM_SYSKEYDOWN:
- cancelled = true;
- tracking = false;
- break;
- case OS.WM_KEYDOWN:
- int stepSize = OS.GetKeyState (OS.VK_CONTROL) < 0 ? STEPSIZE_SMALL : STEPSIZE_LARGE;
- int xChange = 0, yChange = 0;
- switch (msg.wParam) {
- case OS.VK_ESCAPE:
- cancelled = true;
- tracking = false;
- break;
- case OS.VK_RETURN:
- tracking = false;
- break;
- case OS.VK_LEFT:
- xChange = -stepSize;
- break;
- case OS.VK_RIGHT:
- xChange = stepSize;
- break;
- case OS.VK_UP:
- yChange = -stepSize;
- break;
- case OS.VK_DOWN:
- yChange = stepSize;
- break;
- }
- if (xChange != 0 || yChange != 0) {
- drawRectangles (rectangles);
- newX = oldX + xChange;
- newY = oldY + yChange;
- event.x = newX;
- event.y = newY;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (xChange, yChange);
- cursorPos = adjustResizeCursor ();
- inEvent = true;
- sendEvent (SWT.Resize, event);
- } else {
- moveRectangles (xChange, yChange);
- cursorPos = adjustMoveCursor ();
- 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 ()) return false;
- drawRectangles (rectangles);
- oldX = cursorPos.x; oldY = cursorPos.y;
- }
- break;
- }
- /*
- * Don't dispatch mouse and key events in general, EXCEPT once this
- * tracker has finished its work.
- */
- if (tracking && !cancelled) {
- if (OS.WM_KEYFIRST <= message && message <= OS.WM_KEYLAST) continue;
- if (OS.WM_MOUSEFIRST <= message && message <= OS.WM_MOUSELAST) continue;
- }
- OS.DispatchMessage (msg);
- }
- drawRectangles (rectangles);
- /*
- * 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();
- }
- /*
- * Cleanup: If this tracker was resizing then the last cursor that it created
- * needs to be destroyed.
- */
- if (resizeCursor != 0) {
- OS.DestroyCursor (resizeCursor);
- }
- 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 be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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);
-}
-
-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;
- } else if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
- cursorOrientation |= SWT.RIGHT;
- } else if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
- cursorOrientation |= SWT.UP;
- } else if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
- cursorOrientation |= SWT.DOWN;
- }
- Rectangle bounds = computeBounds ();
- 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;
- }
- /*
- * The following are conditions under which the resize should not be applied
- */
- if (bounds.width < 0 || bounds.height < 0) return;
-
- 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setRectangles (Rectangle [] rectangles) {
- checkWidget ();
- if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
- this.rectangles = rectangles;
- 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;
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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;
+ Display display;
+ boolean tracking, stippled;
+ Rectangle [] rectangles, proportions;
+ int resizeCursor, clientCursor, cursorOrientation = SWT.NONE;
+ boolean inEvent = false;
+
+ /*
+ * 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;
+ display = parent.getDisplay ();
+}
+
+/**
+ * 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.Move,typedListener);
+}
+
+Point adjustMoveCursor () {
+ Rectangle bounds = computeBounds ();
+ 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;
+ Rectangle bounds = computeBounds ();
+
+ 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];
+ Rectangle bounds = computeBounds ();
+ for (int i = 0; i < rects.length; i++) {
+ result[i] = new Rectangle (
+ (rects[i].x - bounds.x) * 100 / bounds.width,
+ (rects[i].y - bounds.y) * 100 / bounds.height,
+ rects[i].width * 100 / bounds.width,
+ rects[i].height * 100 / bounds.height);
+ }
+ return result;
+}
+/**
+ * Draw the rectangles displayed by the tracker.
+ */
+void drawRectangles (Rectangle [] rects) {
+ if (parent != null) {
+ if (parent.isDisposed ()) return;
+ Shell shell = parent.getShell ();
+ shell.update (true);
+ } else {
+ display.update ();
+ }
+ 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);
+}
+
+public Display getDisplay () {
+ return display;
+}
+
+/**
+ * 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 ();
+ return rectangles;
+}
+
+/**
+ * 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)) return;
+ if (xChange > 0 && ((style & SWT.RIGHT) == 0)) return;
+ if (yChange < 0 && ((style & SWT.UP) == 0)) return;
+ if (yChange > 0 && ((style & SWT.DOWN) == 0)) return;
+ Rectangle bounds = computeBounds ();
+ 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;
+ boolean cancelled = false;
+ tracking = true;
+ Event event = new Event ();
+ MSG msg = new MSG ();
+ /*
+ * 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);
+ final int oldProc = OS.GetWindowLong (hwndTransparent, OS.GWL_WNDPROC);
+ Object windowProc = new Object () {
+ public int windowProc (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);
+ }
+ };
+ newProc = new Callback (windowProc, "windowProc", 4);
+ OS.SetWindowLong (hwndTransparent, OS.GWL_WNDPROC, newProc.getAddress ());
+ }
+
+ drawRectangles (rectangles);
+ 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 ();
+ }
+ }
+
+ int oldX = cursorPos.x, oldY = cursorPos.y;
+ /*
+ * Tracker behaves like a Dialog with its own OS event loop.
+ */
+ while (tracking && !cancelled) {
+ if (parent != null && parent.isDisposed ()) break;
+ OS.GetMessage (msg, 0, 0, 0);
+ int message = msg.message;
+ switch (message) {
+ case OS.WM_LBUTTONUP:
+ case OS.WM_MOUSEMOVE:
+ int newPos = OS.GetMessagePos ();
+ int newX = (short) (newPos & 0xFFFF);
+ int newY = (short) (newPos >> 16);
+ if (newX != oldX || newY != oldY) {
+ drawRectangles (rectangles);
+ event.x = newX;
+ event.y = newY;
+ if ((style & SWT.RESIZE) != 0) {
+ resizeRectangles (newX - oldX, newY - oldY);
+ cursorPos = adjustResizeCursor ();
+ newX = cursorPos.x; newY = cursorPos.y;
+ inEvent = true;
+ sendEvent (SWT.Resize, event);
+ } 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 ()) return false;
+ drawRectangles (rectangles);
+ oldX = newX; oldY = newY;
+ }
+ tracking = msg.message != OS.WM_LBUTTONUP;
+ break;
+ case OS.WM_SYSKEYDOWN:
+ cancelled = true;
+ tracking = false;
+ break;
+ case OS.WM_KEYDOWN:
+ int stepSize = OS.GetKeyState (OS.VK_CONTROL) < 0 ? STEPSIZE_SMALL : STEPSIZE_LARGE;
+ int xChange = 0, yChange = 0;
+ switch (msg.wParam) {
+ case OS.VK_ESCAPE:
+ cancelled = true;
+ tracking = false;
+ break;
+ case OS.VK_RETURN:
+ tracking = false;
+ break;
+ case OS.VK_LEFT:
+ xChange = -stepSize;
+ break;
+ case OS.VK_RIGHT:
+ xChange = stepSize;
+ break;
+ case OS.VK_UP:
+ yChange = -stepSize;
+ break;
+ case OS.VK_DOWN:
+ yChange = stepSize;
+ break;
+ }
+ if (xChange != 0 || yChange != 0) {
+ drawRectangles (rectangles);
+ newX = oldX + xChange;
+ newY = oldY + yChange;
+ event.x = newX;
+ event.y = newY;
+ if ((style & SWT.RESIZE) != 0) {
+ resizeRectangles (xChange, yChange);
+ cursorPos = adjustResizeCursor ();
+ inEvent = true;
+ sendEvent (SWT.Resize, event);
+ } else {
+ moveRectangles (xChange, yChange);
+ cursorPos = adjustMoveCursor ();
+ 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 ()) return false;
+ drawRectangles (rectangles);
+ oldX = cursorPos.x; oldY = cursorPos.y;
+ }
+ break;
+ }
+ /*
+ * Don't dispatch mouse and key events in general, EXCEPT once this
+ * tracker has finished its work.
+ */
+ if (tracking && !cancelled) {
+ if (OS.WM_KEYFIRST <= message && message <= OS.WM_KEYLAST) continue;
+ if (OS.WM_MOUSEFIRST <= message && message <= OS.WM_MOUSELAST) continue;
+ }
+ OS.DispatchMessage (msg);
+ }
+ drawRectangles (rectangles);
+ /*
+ * 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();
+ }
+ /*
+ * Cleanup: If this tracker was resizing then the last cursor that it created
+ * needs to be destroyed.
+ */
+ if (resizeCursor != 0) {
+ OS.DestroyCursor (resizeCursor);
+ }
+ 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 be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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);
+}
+
+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;
+ } else if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
+ cursorOrientation |= SWT.RIGHT;
+ } else if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
+ cursorOrientation |= SWT.UP;
+ } else if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
+ cursorOrientation |= SWT.DOWN;
+ }
+ Rectangle bounds = computeBounds ();
+ 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;
+ }
+ /*
+ * The following are conditions under which the resize should not be applied
+ */
+ if (bounds.width < 0 || bounds.height < 0) return;
+
+ 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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setRectangles (Rectangle [] rectangles) {
+ checkWidget ();
+ if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
+ this.rectangles = rectangles;
+ proportions = computeProportions (rectangles);
+}
+
+/**
+ * Changes the appearance of the line used to draw the rectangles.
+ *
+ * @param stippled <code>true</code> if rectangle should appear stippled
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setStippled (boolean stippled) {
+ checkWidget ();
+ this.stippled = stippled;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java
index c55e81d651..c08db437da 100755
--- 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
@@ -1,1907 +1,1907 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 issue notificiation 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>
- * 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</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection, DefaultSelection, Collapse, Expand</dd>
- * </dl>
- * <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 hAnchor;
- TreeItem [] items;
- ImageList imageList;
- boolean dragStarted;
- boolean ignoreSelect, ignoreExpand, ignoreDeselect;
- boolean customDraw;
- static final int TreeProc;
- static final TCHAR TreeClass = new TCHAR (0, OS.WC_TREEVIEW, true);
- static {
- WNDCLASS lpWndClass = new WNDCLASS ();
- OS.GetClassInfo (0, TreeClass, lpWndClass);
- TreeProc = 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));
-}
-
-/**
- * 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 reciever 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 callWindowProc (int msg, int wParam, int lParam) {
- if (handle == 0) return 0;
- return OS.CallWindowProc (TreeProc, handle, msg, wParam, lParam);
-}
-
-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);
-}
-
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- int width = 0, height = 0;
- RECT rect = new RECT ();
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- while (hItem != 0) {
- rect.left = hItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect) != 0) {
- width = Math.max (width, rect.right - rect.left);
- height += rect.bottom - rect.top;
- }
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- }
- width = width * 2;
- 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;
-
- /* 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 createItem (TreeItem item, int hParent, int hInsertAfter) {
- item.foreground = item.background = -1;
- 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;
- }
- TVINSERTSTRUCT tvInsert = new TVINSERTSTRUCT ();
- tvInsert.hParent = hParent;
- tvInsert.hInsertAfter = hInsertAfter;
- tvInsert.lParam = id;
- tvInsert.iImage = OS.I_IMAGENONE;
- tvInsert.iSelectedImage = tvInsert.iImage;
- tvInsert.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM | OS.TVIF_IMAGE | OS.TVIF_SELECTEDIMAGE;
-
- /* Set the initial unchecked state */
- if ((style & SWT.CHECK) != 0) {
- tvInsert.mask = tvInsert.mask | OS.TVIF_STATE;
- tvInsert.state = 1 << 12;
- tvInsert.stateMask = OS.TVIS_STATEIMAGEMASK;
- }
-
- /* Insert the item */
- int hItem = OS.SendMessage (handle, OS.TVM_INSERTITEM, 0, tvInsert);
- if (hItem == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- item.handle = hItem;
- items [id] = item;
-
- /*
- * 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);
-// }
-
- /*
- * 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 this case and force a redraw.
- */
- if (!OS.IsWindowVisible (handle) || drawCount > 0) return;
- int hChild = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hParent);
- if (hChild == 0 || OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hChild) != 0) {
- return;
- }
- RECT rect = new RECT ();
- rect.left = hParent;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect) != 0) {
- OS.InvalidateRect (handle, rect, false);
- }
-}
-
-void createWidget () {
- super.createWidget ();
- items = new TreeItem [4];
-}
-
-int defaultBackground () {
- return OS.GetSysColor (OS.COLOR_WINDOW);
-}
-
-/**
- * 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_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);
- }
- return;
- }
- int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- 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 (TreeItem item) {
- int hItem = item.handle;
- boolean fixRedraw = false;
- 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) {
- OS.UpdateWindow (handle);
- OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- releaseItems (item.getItems (), tvItem);
- releaseItem (item, tvItem);
- OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, hItem);
- if (fixRedraw) {
- OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- OS.ValidateRect (handle, null);
- }
- 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 display = getDisplay ();
- display.releaseImageList (imageList);
- }
- imageList = null;
- customDraw = false;
- items = new TreeItem [4];
- }
-}
-
-int getBackgroundPixel () {
- if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOW);
- int pixel = OS.SendMessage (handle, OS.TVM_GETBKCOLOR, 0, 0);
- if (pixel == -1) return OS.GetSysColor (OS.COLOR_WINDOW);
- return pixel;
-}
-
-int getForegroundPixel () {
- if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOWTEXT);
- int pixel = OS.SendMessage (handle, OS.TVM_GETTEXTCOLOR, 0, 0);
- if (pixel == -1) return OS.GetSysColor (OS.COLOR_WINDOWTEXT);
- return pixel;
-}
-
-/**
- * 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 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 && (lpht.flags & OS.TVHT_ONITEM) != 0) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- tvItem.hItem = lpht.hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- return items [tvItem.lParam];
- }
- 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 count = 0;
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- while (hItem != 0) {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- 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 the number 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 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 TreeItem [] getItems () {
- checkWidget ();
- int count = 0;
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- 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 = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- while (tvItem.hItem != 0) {
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- result [index++] = items [tvItem.lParam];
- tvItem.hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, tvItem.hItem);
- }
- return result;
-}
-
-/**
- * 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. 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_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 [] {items [tvItem.lParam]};
- }
- int count = 0;
- TreeItem [] guess = new TreeItem [8];
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_PARAM | OS.TVIF_STATE;
- int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- 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) {
- 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;
- }
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- 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;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_STATE;
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) == 0) return 0;
- return 1;
- }
- int count = 0;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_STATE;
- int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- 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) count++;
- }
- }
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
- return count;
-}
-
-/**
- * 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);
- if (hItem == 0) return null;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_PARAM;
- tvItem.hItem = hItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem) == 0) return null;
- return items [tvItem.lParam];
-}
-
-int imageIndex (Image image) {
- if (image == null) return OS.I_IMAGENONE;
- if (imageList == null) {
- int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0);
- if (hOldList != 0) OS.ImageList_Destroy (hOldList);
- Rectangle bounds = image.getBounds ();
- imageList = getDisplay ().getImageList (new Point (bounds.width, bounds.height));
- int index = imageList.indexOf (image);
- if (index == -1) index = imageList.add (image);
- int hImageList = imageList.getHandle ();
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, hImageList);
- return index;
- }
- int index = imageList.indexOf (image);
- if (index != -1) return index;
- return imageList.add (image);
-}
-
-boolean releaseItem (TreeItem item, TVITEM tvItem) {
- int hItem = item.handle;
- if (hItem == hAnchor) hAnchor = 0;
- if (item.isDisposed ()) return false;
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- items [tvItem.lParam] = null;
- return true;
-}
-
-void releaseItems (TreeItem [] nodes, TVITEM tvItem) {
- for (int i=0; i<nodes.length; i++) {
- TreeItem item = nodes [i];
- TreeItem [] sons = item.getItems ();
- if (sons.length != 0) {
- releaseItems (sons, tvItem);
- }
- if (releaseItem (item, tvItem)) {
- item.releaseResources ();
- }
- }
-}
-
-void releaseWidget () {
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.releaseResources ();
- }
- }
- /*
- * 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 usnig the custom draw flag.
- *
- * NOTE: This only happens on Windows XP.
- */
- customDraw = false;
- items = null;
- if (imageList != null) {
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, 0);
- Display display = getDisplay ();
- display.releaseImageList (imageList);
- } else {
- int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0);
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, 0);
- if (hOldList != 0) OS.ImageList_Destroy (hOldList);
- }
- imageList = null;
- int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_STATE, 0);
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_STATE, 0);
- if (hOldList != 0) OS.ImageList_Destroy (hOldList);
- super.releaseWidget ();
-}
-
-
-/**
- * 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 ();
- ignoreDeselect = ignoreSelect = true;
- if (drawCount == 0) {
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- int result = OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, OS.TVI_ROOT);
- if (drawCount == 0) {
- 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);
- for (int i=0; i<items.length; i++) {
- TreeItem item = items [i];
- if (item != null && !item.isDisposed ()) {
- item.releaseResources ();
- }
- }
- if (imageList != null) {
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, 0, 0);
- Display display = getDisplay ();
- display.releaseImageList (imageList);
- }
- imageList = null;
- customDraw = false;
- items = new TreeItem [4];
- hAnchor = 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 after 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;
- }
- OS.SendMessage (handle, OS.TVM_SETINSERTMARK, (before) ? 0 : 1, hItem);
-}
-
-/**
- * Selects all 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 void selectAll () {
- checkWidget ();
- if ((style & SWT.SINGLE) != 0) return;
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem == 0) {
- hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- if (hItem != 0) {
- ignoreSelect = true;
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hItem);
- ignoreSelect = false;
- }
- }
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = 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);
- 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 setBackgroundPixel (int pixel) {
- if (background == pixel) return;
- background = pixel;
- /*
- * Bug in Windows. When TVM_GETBKCOLOR 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.
- */
- int oldPixel = OS.SendMessage (handle, OS.TVM_GETBKCOLOR, 0, 0);
- if (oldPixel != -1) OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, -1);
- OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, pixel);
- if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
-}
-
-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 setCheckboxImageList () {
- if ((style & SWT.CHECK) == 0) return;
- int count = 5;
- int height = OS.SendMessage (handle, OS.TVM_GETITEMHEIGHT, 0, 0), width = height;
- int hImageList = OS.ImageList_Create (width, height, OS.ILC_COLOR, 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 hBrush = OS.CreateSolidBrush (getBackgroundPixel ());
- OS.FillRect (memDC, rect, hBrush);
- OS.DeleteObject (hBrush);
- int oldFont = OS.SelectObject (hDC, defaultFont ());
- TEXTMETRIC tm = new TEXTMETRIC ();
- 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);
- 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);
- OS.ImageList_AddMasked (hImageList, hBitmap, 0);
- OS.DeleteObject (hBitmap);
- int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_STATE, 0);
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_STATE, hImageList);
- if (hOldList != 0) OS.ImageList_Destroy (hOldList);
-}
-
-void setForegroundPixel (int pixel) {
- if (foreground == pixel) return;
- foreground = pixel;
- OS.SendMessage (handle, OS.TVM_SETTEXTCOLOR, 0, pixel);
-}
-
-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) {
- 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) {
- OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, hItem);
- }
-}
-
-/**
- * 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 array of items is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if one of 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#deselectAll()
- */
-public void setSelection (TreeItem [] items) {
- checkWidget ();
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- /* Select/deselect the first item */
- int hOldItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (items.length == 0) {
- if (hOldItem != 0) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- tvItem.hItem = hOldItem;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- } else {
- int hNewItem = 0;
- TreeItem item = items [0];
- if (item != null) {
- if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- hAnchor = hNewItem = item.handle;
- }
- ignoreSelect = true;
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hNewItem);
- ignoreSelect = false;
- /*
- * 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.
- */
- if (hOldItem == hNewItem) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = 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_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- for (int i=0; i<this.items.length; i++) {
- TreeItem item = this.items [i];
- if (item != null) {
- int index = 0;
- while (index < items.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 == items.length) {
- tvItem.state = 0;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- } else {
- if (index != items.length) {
- tvItem.state = OS.TVIS_SELECTED;
- OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
- }
- }
- }
- }
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
-}
-
-/**
- * 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);
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, item.handle);
-}
-
-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) {
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, hItem);
- OS.SendMessage (handle, OS.WM_HSCROLL, OS.SB_TOP ,0);
- } else {
- boolean scroll = true;
- RECT itemRect = new RECT ();
- itemRect.left = hItem;
- if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, itemRect) != 0) {
- 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) OS.SendMessage (handle, OS.TVM_ENSUREVISIBLE, 0, hItem);
- }
-}
-
-/**
- * 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;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_STATE;
- tvItem.hItem = hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) == 0) return;
- } else {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_STATE;
- int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
- int index = 0;
- while (index <items.length) {
- TreeItem item = items [index];
- if (item != null) {
- tvItem.hItem = item.handle;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) != 0) {
- hItem = tvItem.hItem;
- break;
- }
- }
- index++;
- }
- OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
- }
- if (hItem != 0) showItem (hItem);
-}
-
-String toolTipText (NMTTDISPINFO hdr) {
- int hwndToolTip = OS.SendMessage (handle, OS.TVM_GETTOOLTIPS, 0, 0);
- if (hwndToolTip == hdr.hwndFrom && toolTipText != null) return "";
- return super.toolTipText (hdr);
-}
-
-int widgetStyle () {
- int bits = super.widgetStyle () | OS.TVS_SHOWSELALWAYS;
- bits |= OS.TVS_LINESATROOT | OS.TVS_HASLINES | OS.TVS_HASBUTTONS;
- /*
- * This code is intentionally commented. In future,
- * FULL_SELECTION may be implemented for trees.
- */
-// if ((style & SWT.FULL_SELECTION) != 0) {
-// bits |= OS.TVS_FULLROWSELECT;
-// } else {
-// bits |= OS.TVS_HASLINES | OS.TVS_HASBUTTONS;
-// }
-// bits |= OS.TVS_NOTOOLTIPS;
- return bits;
-}
-
-TCHAR windowClass () {
- return TreeClass;
-}
-
-int windowProc () {
- return TreeProc;
-}
-
-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 OS.VK_ESCAPE:
- case OS.VK_RETURN:
- case OS.VK_SPACE: return LRESULT.ZERO;
- }
- 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: {
- 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_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);
- }
- 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);
- Event event = new Event ();
- event.item = items [tvItem.lParam];
- postEvent (SWT.Selection, event);
- if ((style & SWT.CHECK) != 0) {
- event = new Event ();
- event.item = items [tvItem.lParam];
- event.detail = SWT.CHECK;
- postEvent (SWT.Selection, event);
- }
- return LRESULT.ZERO;
- }
- 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: {
- 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 (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_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- int hDeselectItem = hItem;
- RECT rect1 = new RECT ();
- rect1.left = hAnchor;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1);
- RECT rect2 = rect2 = new RECT ();
- rect2.left = hDeselectItem;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, 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, 1, rect1);
- rect2.left = hSelectItem;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, 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_PARAM;
- tvItem.hItem = hNewItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- Event event = new Event ();
- event.item = items [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_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, 1, 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;
- if (!newSelected && drawCount == 0) {
- OS.UpdateWindow (handle);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
- }
- ignoreSelect = true;
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hNewItem);
- ignoreSelect = false;
- 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 (!newSelected && drawCount == 0) {
- RECT rect1 = new RECT (), rect2 = new RECT ();
- rect1.left = hItem; rect2.left = hNewItem;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1);
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect2);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- if (OS.IsWinCE) {
- OS.InvalidateRect (handle, rect1, false);
- OS.InvalidateRect (handle, rect2, false);
- OS.UpdateWindow (handle);
- } else {
- int flags = OS.RDW_UPDATENOW | OS.RDW_INVALIDATE;
- OS.RedrawWindow (handle, rect1, 0, flags);
- OS.RedrawWindow (handle, rect2, 0, flags);
- }
- }
- return LRESULT.ZERO;
- }
- }
- }
- int code = callWindowProc (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_LBUTTONDOWN (int wParam, int lParam) {
-
- /*
- * Feature in Windows. When a tree item is
- * reselected, Windows does not issue a WM_NOTIFY.
- * This is inconsistent with the list widget and
- * other widgets in Windows. The fix is to detect
- * the case when an item is reselected and issue
- * the notification. The first part of this work
- * around is to ensure that the user has selected
- * an item.
- */
- 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_ONITEM) == 0) {
- sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
- int code = callWindowProc (OS.WM_LBUTTONDOWN, wParam, lParam);
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- return new LRESULT (code);
- }
-
- /* Look for check/uncheck */
- if ((style & SWT.CHECK) != 0) {
- if ((lpht.flags & OS.TVHT_ONITEMSTATEICON) != 0) {
- TVITEM tvItem = new TVITEM ();
- tvItem.hItem = lpht.hItem;
- tvItem.mask = 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);
- Event event = new Event ();
- event.item = items [tvItem.lParam];
- event.detail = SWT.CHECK;
- postEvent (SWT.Selection, event);
- sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
- if (OS.GetCapture () != handle) OS.SetCapture (handle);
- return LRESULT.ZERO;
- }
- }
-
- /* Get the selected state of the item under the mouse */
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_STATE;
- tvItem.stateMask = OS.TVIS_SELECTED;
- boolean hittestSelected = false;
- if ((style & SWT.MULTI) != 0) {
- tvItem.hItem = lpht.hItem;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- hittestSelected = (tvItem.state & OS.TVIS_SELECTED) != 0;
- }
-
- /* Get the selected state of the last selected item */
- int 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) {
- if (drawCount == 0) {
- 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 */
- sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
- dragStarted = false;
- ignoreDeselect = ignoreSelect = true;
- int code = callWindowProc (OS.WM_LBUTTONDOWN, wParam, lParam);
- ignoreDeselect = ignoreSelect = false;
- if (dragStarted && OS.GetCapture () != handle) OS.SetCapture (handle);
- int hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 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. This is only necessary when the tree
- * is single select.
- */
- if ((style & SWT.SINGLE) != 0) {
- if (hOldItem == hNewItem) {
- tvItem.mask = 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 (drawCount == 0) {
- RECT rect1 = new RECT (), rect2 = new RECT ();
- rect1.left = hOldItem; rect2.left = hNewItem;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1);
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect2);
- /*
- * This code is intentionally commented.
- */
-// OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
- OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
- if (OS.IsWinCE) {
- OS.InvalidateRect (handle, rect1, false);
- OS.InvalidateRect (handle, rect2, false);
- OS.UpdateWindow (handle);
- } else {
- int flags = OS.RDW_UPDATENOW | OS.RDW_INVALIDATE;
- OS.RedrawWindow (handle, rect1, 0, flags);
- OS.RedrawWindow (handle, rect2, 0, flags);
- }
- }
- }
-
- /* 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);
- 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, 1, rect1) != 0) {
- RECT rect2 = rect2 = new RECT ();
- rect2.left = hNewItem;
- OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, 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 */
- tvItem.hItem = hNewItem;
- tvItem.mask = OS.TVIF_PARAM;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- Event event = new Event ();
- event.item = items [tvItem.lParam];
- postEvent (SWT.Selection, event);
-
- /*
- * 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) {
- postEvent (SWT.DragDetect);
- } else {
- sendMouseEvent (SWT.MouseUp, 1, OS.WM_LBUTTONUP, wParam, lParam);
- }
- dragStarted = false;
- return new LRESULT (code);
-}
-
-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.
- */
- sendMouseEvent (SWT.MouseDown, 3, OS.WM_RBUTTONDOWN, wParam, lParam);
- /*
- * 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 && (lpht.flags & (OS.TVHT_ONITEMICON | OS.TVHT_ONITEMLABEL)) != 0) {
- if ((wParam & (OS.MK_CONTROL | OS.MK_SHIFT)) == 0) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = 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_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_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 wmNotifyChild (int wParam, int lParam) {
- NMHDR hdr = new NMHDR ();
- OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
- int code = hdr.code;
- switch (code) {
- case OS.NM_CUSTOMDRAW: {
- if (!customDraw) break;
- NMTVCUSTOMDRAW nmcd = new NMTVCUSTOMDRAW ();
- OS.MoveMemory (nmcd, lParam, NMTVCUSTOMDRAW.sizeof);
- switch (nmcd.dwDrawStage) {
- case OS.CDDS_PREPAINT: return new LRESULT (OS.CDRF_NOTIFYITEMDRAW);
- case OS.CDDS_ITEMPREPAINT:
- TreeItem item = items [nmcd.lItemlParam];
- /*
- * Feature on 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) break;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_STATE;
- tvItem.hItem = item.handle;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- if ((tvItem.state & OS.TVIS_SELECTED) != 0) break;
- int clrText = item.foreground, clrTextBk = item.background;
- if (clrText == -1 && clrTextBk == -1) break;
- nmcd.clrText = clrText == -1 ? getForegroundPixel () : clrText;
- nmcd.clrTextBk = clrTextBk == -1 ? getBackgroundPixel () : clrTextBk;
- OS.MoveMemory (lParam, nmcd, NMTVCUSTOMDRAW.sizeof);
- return new LRESULT (OS.CDRF_NEWFONT);
- }
- break;
- }
- case OS.NM_DBLCLK:
- int pos = OS.GetMessagePos ();
- TVHITTESTINFO lpht = new TVHITTESTINFO ();
- POINT pt = new POINT ();
- pt.x = (short) (pos & 0xFFFF);
- pt.y = (short) (pos >> 16);
- OS.ScreenToClient (handle, pt);
- lpht.x = pt.x; lpht.y = pt.y;
- OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht);
- if ((lpht.flags & OS.TVHT_ONITEM) == 0) break;
- // FALL THROUGH
- case OS.NM_RETURN:
- case OS.TVN_SELCHANGEDA:
- case OS.TVN_SELCHANGEDW:
- if (!ignoreSelect) {
- TVITEM tvItem = null;
- if (code == OS.TVN_SELCHANGED) {
- tvItem = new TVITEM ();
- int offset = NMHDR.sizeof + 4 + TVITEM.sizeof;
- OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof);
- hAnchor = tvItem.hItem;
- } else {
- int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
- if (hItem != 0) {
- tvItem = new TVITEM ();
- tvItem.hItem = hItem;
- tvItem.mask = OS.TVIF_PARAM;
- OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
- }
- }
- Event event = new Event ();
- if (tvItem != null) {
- event.item = items [tvItem.lParam];
- }
- if (code == OS.TVN_SELCHANGED) {
- postEvent (SWT.Selection, event);
- } else {
- postEvent (SWT.DefaultSelection, event);
- }
- }
- if (code == OS.NM_DBLCLK && hooks (SWT.DefaultSelection)) {
- return LRESULT.ONE;
- }
- break;
- case OS.TVN_SELCHANGINGA:
- case OS.TVN_SELCHANGINGW:
- if (!ignoreSelect && !ignoreDeselect) {
- hAnchor = 0;
- if ((style & SWT.MULTI) != 0) deselectAll ();
- }
- break;
- case OS.TVN_ITEMEXPANDINGA:
- case OS.TVN_ITEMEXPANDINGW:
- if (!ignoreExpand) {
- TVITEM tvItem = new TVITEM ();
- int offset = NMHDR.sizeof + 4 + TVITEM.sizeof;
- OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof);
- int [] action = new int [1];
- OS.MoveMemory (action, lParam + NMHDR.sizeof, 4);
- Event event = new Event ();
- event.item = items [tvItem.lParam];
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in the expand
- * or collapse event. If this happens, end the
- * processing of the Windows message by returning
- * zero as the result of the window proc.
- */
- if (action [0] == OS.TVE_EXPAND) {
- sendEvent (SWT.Expand, event);
- if (isDisposed ()) return LRESULT.ZERO;
- }
- if (action [0] == OS.TVE_COLLAPSE) {
- sendEvent (SWT.Collapse, event);
- if (isDisposed ()) return LRESULT.ZERO;
- }
- }
- 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) {
- ignoreSelect = ignoreDeselect = true;
- OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, tvItem.hItem);
- ignoreSelect = ignoreDeselect = false;
- }
- dragStarted = true;
- break;
- }
- return super.wmNotifyChild (wParam, lParam);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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 issue notificiation 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>
+ * 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</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>Selection, DefaultSelection, Collapse, Expand</dd>
+ * </dl>
+ * <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 hAnchor;
+ TreeItem [] items;
+ ImageList imageList;
+ boolean dragStarted;
+ boolean ignoreSelect, ignoreExpand, ignoreDeselect;
+ boolean customDraw;
+ static final int TreeProc;
+ static final TCHAR TreeClass = new TCHAR (0, OS.WC_TREEVIEW, true);
+ static {
+ WNDCLASS lpWndClass = new WNDCLASS ();
+ OS.GetClassInfo (0, TreeClass, lpWndClass);
+ TreeProc = 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));
+}
+
+/**
+ * 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 reciever 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 callWindowProc (int msg, int wParam, int lParam) {
+ if (handle == 0) return 0;
+ return OS.CallWindowProc (TreeProc, handle, msg, wParam, lParam);
+}
+
+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);
+}
+
+
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ checkWidget ();
+ int width = 0, height = 0;
+ RECT rect = new RECT ();
+ int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
+ while (hItem != 0) {
+ rect.left = hItem;
+ if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect) != 0) {
+ width = Math.max (width, rect.right - rect.left);
+ height += rect.bottom - rect.top;
+ }
+ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
+ }
+ width = width * 2;
+ 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;
+
+ /* 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 createItem (TreeItem item, int hParent, int hInsertAfter) {
+ item.foreground = item.background = -1;
+ 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;
+ }
+ TVINSERTSTRUCT tvInsert = new TVINSERTSTRUCT ();
+ tvInsert.hParent = hParent;
+ tvInsert.hInsertAfter = hInsertAfter;
+ tvInsert.lParam = id;
+ tvInsert.iImage = OS.I_IMAGENONE;
+ tvInsert.iSelectedImage = tvInsert.iImage;
+ tvInsert.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM | OS.TVIF_IMAGE | OS.TVIF_SELECTEDIMAGE;
+
+ /* Set the initial unchecked state */
+ if ((style & SWT.CHECK) != 0) {
+ tvInsert.mask = tvInsert.mask | OS.TVIF_STATE;
+ tvInsert.state = 1 << 12;
+ tvInsert.stateMask = OS.TVIS_STATEIMAGEMASK;
+ }
+
+ /* Insert the item */
+ int hItem = OS.SendMessage (handle, OS.TVM_INSERTITEM, 0, tvInsert);
+ if (hItem == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
+ item.handle = hItem;
+ items [id] = item;
+
+ /*
+ * 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);
+// }
+
+ /*
+ * 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 this case and force a redraw.
+ */
+ if (!OS.IsWindowVisible (handle) || drawCount > 0) return;
+ int hChild = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hParent);
+ if (hChild == 0 || OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hChild) != 0) {
+ return;
+ }
+ RECT rect = new RECT ();
+ rect.left = hParent;
+ if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 0, rect) != 0) {
+ OS.InvalidateRect (handle, rect, false);
+ }
+}
+
+void createWidget () {
+ super.createWidget ();
+ items = new TreeItem [4];
+}
+
+int defaultBackground () {
+ return OS.GetSysColor (OS.COLOR_WINDOW);
+}
+
+/**
+ * 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_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);
+ }
+ return;
+ }
+ int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
+ OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
+ 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 (TreeItem item) {
+ int hItem = item.handle;
+ boolean fixRedraw = false;
+ 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) {
+ OS.UpdateWindow (handle);
+ OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
+ }
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
+ releaseItems (item.getItems (), tvItem);
+ releaseItem (item, tvItem);
+ OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, hItem);
+ if (fixRedraw) {
+ OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
+ OS.ValidateRect (handle, null);
+ }
+ 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 display = getDisplay ();
+ display.releaseImageList (imageList);
+ }
+ imageList = null;
+ customDraw = false;
+ items = new TreeItem [4];
+ }
+}
+
+int getBackgroundPixel () {
+ if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOW);
+ int pixel = OS.SendMessage (handle, OS.TVM_GETBKCOLOR, 0, 0);
+ if (pixel == -1) return OS.GetSysColor (OS.COLOR_WINDOW);
+ return pixel;
+}
+
+int getForegroundPixel () {
+ if (OS.IsWinCE) return OS.GetSysColor (OS.COLOR_WINDOWTEXT);
+ int pixel = OS.SendMessage (handle, OS.TVM_GETTEXTCOLOR, 0, 0);
+ if (pixel == -1) return OS.GetSysColor (OS.COLOR_WINDOWTEXT);
+ return pixel;
+}
+
+/**
+ * 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 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 && (lpht.flags & OS.TVHT_ONITEM) != 0) {
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
+ tvItem.hItem = lpht.hItem;
+ OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
+ return items [tvItem.lParam];
+ }
+ 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 count = 0;
+ int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
+ while (hItem != 0) {
+ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
+ 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 the number 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 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 TreeItem [] getItems () {
+ checkWidget ();
+ int count = 0;
+ int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
+ 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 = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
+ while (tvItem.hItem != 0) {
+ OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
+ result [index++] = items [tvItem.lParam];
+ tvItem.hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, tvItem.hItem);
+ }
+ return result;
+}
+
+/**
+ * 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. 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_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 [] {items [tvItem.lParam]};
+ }
+ int count = 0;
+ TreeItem [] guess = new TreeItem [8];
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_PARAM | OS.TVIF_STATE;
+ int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
+ OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
+ 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) {
+ 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;
+ }
+ OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
+ 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;
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_STATE;
+ tvItem.hItem = hItem;
+ OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
+ if ((tvItem.state & OS.TVIS_SELECTED) == 0) return 0;
+ return 1;
+ }
+ int count = 0;
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_STATE;
+ int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
+ OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
+ 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) count++;
+ }
+ }
+ OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
+ return count;
+}
+
+/**
+ * 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);
+ if (hItem == 0) return null;
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_PARAM;
+ tvItem.hItem = hItem;
+ if (OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem) == 0) return null;
+ return items [tvItem.lParam];
+}
+
+int imageIndex (Image image) {
+ if (image == null) return OS.I_IMAGENONE;
+ if (imageList == null) {
+ int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0);
+ if (hOldList != 0) OS.ImageList_Destroy (hOldList);
+ Rectangle bounds = image.getBounds ();
+ imageList = getDisplay ().getImageList (new Point (bounds.width, bounds.height));
+ int index = imageList.indexOf (image);
+ if (index == -1) index = imageList.add (image);
+ int hImageList = imageList.getHandle ();
+ OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, hImageList);
+ return index;
+ }
+ int index = imageList.indexOf (image);
+ if (index != -1) return index;
+ return imageList.add (image);
+}
+
+boolean releaseItem (TreeItem item, TVITEM tvItem) {
+ int hItem = item.handle;
+ if (hItem == hAnchor) hAnchor = 0;
+ if (item.isDisposed ()) return false;
+ tvItem.hItem = hItem;
+ OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
+ items [tvItem.lParam] = null;
+ return true;
+}
+
+void releaseItems (TreeItem [] nodes, TVITEM tvItem) {
+ for (int i=0; i<nodes.length; i++) {
+ TreeItem item = nodes [i];
+ TreeItem [] sons = item.getItems ();
+ if (sons.length != 0) {
+ releaseItems (sons, tvItem);
+ }
+ if (releaseItem (item, tvItem)) {
+ item.releaseResources ();
+ }
+ }
+}
+
+void releaseWidget () {
+ for (int i=0; i<items.length; i++) {
+ TreeItem item = items [i];
+ if (item != null && !item.isDisposed ()) {
+ item.releaseResources ();
+ }
+ }
+ /*
+ * 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 usnig the custom draw flag.
+ *
+ * NOTE: This only happens on Windows XP.
+ */
+ customDraw = false;
+ items = null;
+ if (imageList != null) {
+ OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, 0);
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
+ } else {
+ int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0);
+ OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, 0);
+ if (hOldList != 0) OS.ImageList_Destroy (hOldList);
+ }
+ imageList = null;
+ int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_STATE, 0);
+ OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_STATE, 0);
+ if (hOldList != 0) OS.ImageList_Destroy (hOldList);
+ super.releaseWidget ();
+}
+
+
+/**
+ * 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 ();
+ ignoreDeselect = ignoreSelect = true;
+ if (drawCount == 0) {
+ OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
+ /*
+ * This code is intentionally commented.
+ */
+// OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
+ }
+ int result = OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, OS.TVI_ROOT);
+ if (drawCount == 0) {
+ 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);
+ for (int i=0; i<items.length; i++) {
+ TreeItem item = items [i];
+ if (item != null && !item.isDisposed ()) {
+ item.releaseResources ();
+ }
+ }
+ if (imageList != null) {
+ OS.SendMessage (handle, OS.TVM_SETIMAGELIST, 0, 0);
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
+ }
+ imageList = null;
+ customDraw = false;
+ items = new TreeItem [4];
+ hAnchor = 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 after 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;
+ }
+ OS.SendMessage (handle, OS.TVM_SETINSERTMARK, (before) ? 0 : 1, hItem);
+}
+
+/**
+ * Selects all 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 void selectAll () {
+ checkWidget ();
+ if ((style & SWT.SINGLE) != 0) return;
+ int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
+ if (hItem == 0) {
+ hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
+ if (hItem != 0) {
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hItem);
+ ignoreSelect = false;
+ }
+ }
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = 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);
+ 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 setBackgroundPixel (int pixel) {
+ if (background == pixel) return;
+ background = pixel;
+ /*
+ * Bug in Windows. When TVM_GETBKCOLOR 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.
+ */
+ int oldPixel = OS.SendMessage (handle, OS.TVM_GETBKCOLOR, 0, 0);
+ if (oldPixel != -1) OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, -1);
+ OS.SendMessage (handle, OS.TVM_SETBKCOLOR, 0, pixel);
+ if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
+}
+
+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 setCheckboxImageList () {
+ if ((style & SWT.CHECK) == 0) return;
+ int count = 5;
+ int height = OS.SendMessage (handle, OS.TVM_GETITEMHEIGHT, 0, 0), width = height;
+ int hImageList = OS.ImageList_Create (width, height, OS.ILC_COLOR, 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 hBrush = OS.CreateSolidBrush (getBackgroundPixel ());
+ OS.FillRect (memDC, rect, hBrush);
+ OS.DeleteObject (hBrush);
+ int oldFont = OS.SelectObject (hDC, defaultFont ());
+ TEXTMETRIC tm = new TEXTMETRIC ();
+ 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);
+ 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);
+ OS.ImageList_AddMasked (hImageList, hBitmap, 0);
+ OS.DeleteObject (hBitmap);
+ int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_STATE, 0);
+ OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_STATE, hImageList);
+ if (hOldList != 0) OS.ImageList_Destroy (hOldList);
+}
+
+void setForegroundPixel (int pixel) {
+ if (foreground == pixel) return;
+ foreground = pixel;
+ OS.SendMessage (handle, OS.TVM_SETTEXTCOLOR, 0, pixel);
+}
+
+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) {
+ 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) {
+ OS.SendMessage (handle, OS.TVM_DELETEITEM, 0, hItem);
+ }
+}
+
+/**
+ * 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 array of items is null</li>
+ * <li>ERROR_INVALID_ARGUMENT - if one of 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#deselectAll()
+ */
+public void setSelection (TreeItem [] items) {
+ checkWidget ();
+ if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
+
+ /* Select/deselect the first item */
+ int hOldItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
+ if (items.length == 0) {
+ if (hOldItem != 0) {
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_STATE;
+ tvItem.stateMask = OS.TVIS_SELECTED;
+ tvItem.hItem = hOldItem;
+ OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
+ }
+ } else {
+ int hNewItem = 0;
+ TreeItem item = items [0];
+ if (item != null) {
+ if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
+ hAnchor = hNewItem = item.handle;
+ }
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hNewItem);
+ ignoreSelect = false;
+ /*
+ * 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.
+ */
+ if (hOldItem == hNewItem) {
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = 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_STATE;
+ tvItem.stateMask = OS.TVIS_SELECTED;
+ int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
+ OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
+ for (int i=0; i<this.items.length; i++) {
+ TreeItem item = this.items [i];
+ if (item != null) {
+ int index = 0;
+ while (index < items.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 == items.length) {
+ tvItem.state = 0;
+ OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
+ }
+ } else {
+ if (index != items.length) {
+ tvItem.state = OS.TVIS_SELECTED;
+ OS.SendMessage (handle, OS.TVM_SETITEM, 0, tvItem);
+ }
+ }
+ }
+ }
+ OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
+}
+
+/**
+ * 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);
+ OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, item.handle);
+}
+
+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) {
+ OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, hItem);
+ OS.SendMessage (handle, OS.WM_HSCROLL, OS.SB_TOP ,0);
+ } else {
+ boolean scroll = true;
+ RECT itemRect = new RECT ();
+ itemRect.left = hItem;
+ if (OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, itemRect) != 0) {
+ 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) OS.SendMessage (handle, OS.TVM_ENSUREVISIBLE, 0, hItem);
+ }
+}
+
+/**
+ * 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;
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_STATE;
+ tvItem.hItem = hItem;
+ OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
+ if ((tvItem.state & OS.TVIS_SELECTED) == 0) return;
+ } else {
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_STATE;
+ int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
+ OS.SetWindowLong (handle, OS.GWL_WNDPROC, TreeProc);
+ int index = 0;
+ while (index <items.length) {
+ TreeItem item = items [index];
+ if (item != null) {
+ tvItem.hItem = item.handle;
+ OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
+ if ((tvItem.state & OS.TVIS_SELECTED) != 0) {
+ hItem = tvItem.hItem;
+ break;
+ }
+ }
+ index++;
+ }
+ OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
+ }
+ if (hItem != 0) showItem (hItem);
+}
+
+String toolTipText (NMTTDISPINFO hdr) {
+ int hwndToolTip = OS.SendMessage (handle, OS.TVM_GETTOOLTIPS, 0, 0);
+ if (hwndToolTip == hdr.hwndFrom && toolTipText != null) return "";
+ return super.toolTipText (hdr);
+}
+
+int widgetStyle () {
+ int bits = super.widgetStyle () | OS.TVS_SHOWSELALWAYS;
+ bits |= OS.TVS_LINESATROOT | OS.TVS_HASLINES | OS.TVS_HASBUTTONS;
+ /*
+ * This code is intentionally commented. In future,
+ * FULL_SELECTION may be implemented for trees.
+ */
+// if ((style & SWT.FULL_SELECTION) != 0) {
+// bits |= OS.TVS_FULLROWSELECT;
+// } else {
+// bits |= OS.TVS_HASLINES | OS.TVS_HASBUTTONS;
+// }
+// bits |= OS.TVS_NOTOOLTIPS;
+ return bits;
+}
+
+TCHAR windowClass () {
+ return TreeClass;
+}
+
+int windowProc () {
+ return TreeProc;
+}
+
+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 OS.VK_ESCAPE:
+ case OS.VK_RETURN:
+ case OS.VK_SPACE: return LRESULT.ZERO;
+ }
+ 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: {
+ 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_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);
+ }
+ 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);
+ Event event = new Event ();
+ event.item = items [tvItem.lParam];
+ postEvent (SWT.Selection, event);
+ if ((style & SWT.CHECK) != 0) {
+ event = new Event ();
+ event.item = items [tvItem.lParam];
+ event.detail = SWT.CHECK;
+ postEvent (SWT.Selection, event);
+ }
+ return LRESULT.ZERO;
+ }
+ 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: {
+ 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 (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_STATE;
+ tvItem.stateMask = OS.TVIS_SELECTED;
+ int hDeselectItem = hItem;
+ RECT rect1 = new RECT ();
+ rect1.left = hAnchor;
+ OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1);
+ RECT rect2 = rect2 = new RECT ();
+ rect2.left = hDeselectItem;
+ OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, 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, 1, rect1);
+ rect2.left = hSelectItem;
+ OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, 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_PARAM;
+ tvItem.hItem = hNewItem;
+ OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
+ Event event = new Event ();
+ event.item = items [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_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, 1, 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;
+ if (!newSelected && drawCount == 0) {
+ OS.UpdateWindow (handle);
+ OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0);
+ /*
+ * This code is intentionally commented.
+ */
+// OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0);
+ }
+ ignoreSelect = true;
+ OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hNewItem);
+ ignoreSelect = false;
+ 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 (!newSelected && drawCount == 0) {
+ RECT rect1 = new RECT (), rect2 = new RECT ();
+ rect1.left = hItem; rect2.left = hNewItem;
+ OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1);
+ OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect2);
+ /*
+ * This code is intentionally commented.
+ */
+// OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
+ OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
+ if (OS.IsWinCE) {
+ OS.InvalidateRect (handle, rect1, false);
+ OS.InvalidateRect (handle, rect2, false);
+ OS.UpdateWindow (handle);
+ } else {
+ int flags = OS.RDW_UPDATENOW | OS.RDW_INVALIDATE;
+ OS.RedrawWindow (handle, rect1, 0, flags);
+ OS.RedrawWindow (handle, rect2, 0, flags);
+ }
+ }
+ return LRESULT.ZERO;
+ }
+ }
+ }
+ int code = callWindowProc (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_LBUTTONDOWN (int wParam, int lParam) {
+
+ /*
+ * Feature in Windows. When a tree item is
+ * reselected, Windows does not issue a WM_NOTIFY.
+ * This is inconsistent with the list widget and
+ * other widgets in Windows. The fix is to detect
+ * the case when an item is reselected and issue
+ * the notification. The first part of this work
+ * around is to ensure that the user has selected
+ * an item.
+ */
+ 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_ONITEM) == 0) {
+ sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
+ int code = callWindowProc (OS.WM_LBUTTONDOWN, wParam, lParam);
+ if (OS.GetCapture () != handle) OS.SetCapture (handle);
+ return new LRESULT (code);
+ }
+
+ /* Look for check/uncheck */
+ if ((style & SWT.CHECK) != 0) {
+ if ((lpht.flags & OS.TVHT_ONITEMSTATEICON) != 0) {
+ TVITEM tvItem = new TVITEM ();
+ tvItem.hItem = lpht.hItem;
+ tvItem.mask = 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);
+ Event event = new Event ();
+ event.item = items [tvItem.lParam];
+ event.detail = SWT.CHECK;
+ postEvent (SWT.Selection, event);
+ sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
+ if (OS.GetCapture () != handle) OS.SetCapture (handle);
+ return LRESULT.ZERO;
+ }
+ }
+
+ /* Get the selected state of the item under the mouse */
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_STATE;
+ tvItem.stateMask = OS.TVIS_SELECTED;
+ boolean hittestSelected = false;
+ if ((style & SWT.MULTI) != 0) {
+ tvItem.hItem = lpht.hItem;
+ OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
+ hittestSelected = (tvItem.state & OS.TVIS_SELECTED) != 0;
+ }
+
+ /* Get the selected state of the last selected item */
+ int 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) {
+ if (drawCount == 0) {
+ 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 */
+ sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
+ dragStarted = false;
+ ignoreDeselect = ignoreSelect = true;
+ int code = callWindowProc (OS.WM_LBUTTONDOWN, wParam, lParam);
+ ignoreDeselect = ignoreSelect = false;
+ if (dragStarted && OS.GetCapture () != handle) OS.SetCapture (handle);
+ int hNewItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 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. This is only necessary when the tree
+ * is single select.
+ */
+ if ((style & SWT.SINGLE) != 0) {
+ if (hOldItem == hNewItem) {
+ tvItem.mask = 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 (drawCount == 0) {
+ RECT rect1 = new RECT (), rect2 = new RECT ();
+ rect1.left = hOldItem; rect2.left = hNewItem;
+ OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect1);
+ OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, rect2);
+ /*
+ * This code is intentionally commented.
+ */
+// OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0);
+ OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0);
+ if (OS.IsWinCE) {
+ OS.InvalidateRect (handle, rect1, false);
+ OS.InvalidateRect (handle, rect2, false);
+ OS.UpdateWindow (handle);
+ } else {
+ int flags = OS.RDW_UPDATENOW | OS.RDW_INVALIDATE;
+ OS.RedrawWindow (handle, rect1, 0, flags);
+ OS.RedrawWindow (handle, rect2, 0, flags);
+ }
+ }
+ }
+
+ /* 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);
+ 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, 1, rect1) != 0) {
+ RECT rect2 = rect2 = new RECT ();
+ rect2.left = hNewItem;
+ OS.SendMessage (handle, OS.TVM_GETITEMRECT, 1, 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 */
+ tvItem.hItem = hNewItem;
+ tvItem.mask = OS.TVIF_PARAM;
+ OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
+ Event event = new Event ();
+ event.item = items [tvItem.lParam];
+ postEvent (SWT.Selection, event);
+
+ /*
+ * 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) {
+ postEvent (SWT.DragDetect);
+ } else {
+ sendMouseEvent (SWT.MouseUp, 1, OS.WM_LBUTTONUP, wParam, lParam);
+ }
+ dragStarted = false;
+ return new LRESULT (code);
+}
+
+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.
+ */
+ sendMouseEvent (SWT.MouseDown, 3, OS.WM_RBUTTONDOWN, wParam, lParam);
+ /*
+ * 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 && (lpht.flags & (OS.TVHT_ONITEMICON | OS.TVHT_ONITEMLABEL)) != 0) {
+ if ((wParam & (OS.MK_CONTROL | OS.MK_SHIFT)) == 0) {
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = 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_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_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 wmNotifyChild (int wParam, int lParam) {
+ NMHDR hdr = new NMHDR ();
+ OS.MoveMemory (hdr, lParam, NMHDR.sizeof);
+ int code = hdr.code;
+ switch (code) {
+ case OS.NM_CUSTOMDRAW: {
+ if (!customDraw) break;
+ NMTVCUSTOMDRAW nmcd = new NMTVCUSTOMDRAW ();
+ OS.MoveMemory (nmcd, lParam, NMTVCUSTOMDRAW.sizeof);
+ switch (nmcd.dwDrawStage) {
+ case OS.CDDS_PREPAINT: return new LRESULT (OS.CDRF_NOTIFYITEMDRAW);
+ case OS.CDDS_ITEMPREPAINT:
+ TreeItem item = items [nmcd.lItemlParam];
+ /*
+ * Feature on 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) break;
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_STATE;
+ tvItem.hItem = item.handle;
+ OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
+ if ((tvItem.state & OS.TVIS_SELECTED) != 0) break;
+ int clrText = item.foreground, clrTextBk = item.background;
+ if (clrText == -1 && clrTextBk == -1) break;
+ nmcd.clrText = clrText == -1 ? getForegroundPixel () : clrText;
+ nmcd.clrTextBk = clrTextBk == -1 ? getBackgroundPixel () : clrTextBk;
+ OS.MoveMemory (lParam, nmcd, NMTVCUSTOMDRAW.sizeof);
+ return new LRESULT (OS.CDRF_NEWFONT);
+ }
+ break;
+ }
+ case OS.NM_DBLCLK:
+ int pos = OS.GetMessagePos ();
+ TVHITTESTINFO lpht = new TVHITTESTINFO ();
+ POINT pt = new POINT ();
+ pt.x = (short) (pos & 0xFFFF);
+ pt.y = (short) (pos >> 16);
+ OS.ScreenToClient (handle, pt);
+ lpht.x = pt.x; lpht.y = pt.y;
+ OS.SendMessage (handle, OS.TVM_HITTEST, 0, lpht);
+ if ((lpht.flags & OS.TVHT_ONITEM) == 0) break;
+ // FALL THROUGH
+ case OS.NM_RETURN:
+ case OS.TVN_SELCHANGEDA:
+ case OS.TVN_SELCHANGEDW:
+ if (!ignoreSelect) {
+ TVITEM tvItem = null;
+ if (code == OS.TVN_SELCHANGED) {
+ tvItem = new TVITEM ();
+ int offset = NMHDR.sizeof + 4 + TVITEM.sizeof;
+ OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof);
+ hAnchor = tvItem.hItem;
+ } else {
+ int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0);
+ if (hItem != 0) {
+ tvItem = new TVITEM ();
+ tvItem.hItem = hItem;
+ tvItem.mask = OS.TVIF_PARAM;
+ OS.SendMessage (handle, OS.TVM_GETITEM, 0, tvItem);
+ }
+ }
+ Event event = new Event ();
+ if (tvItem != null) {
+ event.item = items [tvItem.lParam];
+ }
+ if (code == OS.TVN_SELCHANGED) {
+ postEvent (SWT.Selection, event);
+ } else {
+ postEvent (SWT.DefaultSelection, event);
+ }
+ }
+ if (code == OS.NM_DBLCLK && hooks (SWT.DefaultSelection)) {
+ return LRESULT.ONE;
+ }
+ break;
+ case OS.TVN_SELCHANGINGA:
+ case OS.TVN_SELCHANGINGW:
+ if (!ignoreSelect && !ignoreDeselect) {
+ hAnchor = 0;
+ if ((style & SWT.MULTI) != 0) deselectAll ();
+ }
+ break;
+ case OS.TVN_ITEMEXPANDINGA:
+ case OS.TVN_ITEMEXPANDINGW:
+ if (!ignoreExpand) {
+ TVITEM tvItem = new TVITEM ();
+ int offset = NMHDR.sizeof + 4 + TVITEM.sizeof;
+ OS.MoveMemory (tvItem, lParam + offset, TVITEM.sizeof);
+ int [] action = new int [1];
+ OS.MoveMemory (action, lParam + NMHDR.sizeof, 4);
+ Event event = new Event ();
+ event.item = items [tvItem.lParam];
+ /*
+ * It is possible (but unlikely), that application
+ * code could have disposed the widget in the expand
+ * or collapse event. If this happens, end the
+ * processing of the Windows message by returning
+ * zero as the result of the window proc.
+ */
+ if (action [0] == OS.TVE_EXPAND) {
+ sendEvent (SWT.Expand, event);
+ if (isDisposed ()) return LRESULT.ZERO;
+ }
+ if (action [0] == OS.TVE_COLLAPSE) {
+ sendEvent (SWT.Collapse, event);
+ if (isDisposed ()) return LRESULT.ZERO;
+ }
+ }
+ 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) {
+ ignoreSelect = ignoreDeselect = true;
+ OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, tvItem.hItem);
+ ignoreSelect = ignoreDeselect = false;
+ }
+ dragStarted = true;
+ break;
+ }
+ return super.wmNotifyChild (wParam, lParam);
+}
+
+}
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
index 2178d69ed8..cdcd8df0d0 100755
--- 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
@@ -1,684 +1,684 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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)
- */
- public int handle;
-
- Tree parent;
- int background, foreground;
-
-/**
- * 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 composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, 0, OS.TVI_LAST);
-}
-
-/**
- * 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 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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
- super (parent, style);
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- this.parent = parent;
- int hItem = OS.TVI_FIRST;
- if (index != 0) {
- int count = 1, hwnd = parent.handle;
- hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- while (hItem != 0 && count < index) {
- hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- count++;
- }
- if (hItem == 0) error (SWT.ERROR_INVALID_RANGE);
- };
- parent.createItem (this, 0, hItem);
-}
-
-/**
- * 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 composite control which will be the parent of the new instance (cannot be null)
- * @param style the style of control to construct
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
- super (checkNull (parentItem).parent, style);
- parent = parentItem.parent;
- int hItem = parentItem.handle;
- parent.createItem (this, hItem, OS.TVI_LAST);
-}
-
-/**
- * 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 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 index to store the receiver in its parent
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
- super (checkNull (parentItem).parent, style);
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- parent = parentItem.parent;
- int hItem = OS.TVI_FIRST;
- int hParent = parentItem.handle;
- if (index != 0) {
- int count = 1, hwnd = parent.handle;
- hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hParent);
- while (hItem != 0 && count < index) {
- hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- count++;
- }
- if (hItem == 0) error (SWT.ERROR_INVALID_RANGE);
- }
- parent.createItem (this, hParent, hItem);
-}
-
-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);
-}
-
-/**
- * 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 ();
- int pixel = (background == -1) ? parent.getBackgroundPixel() : background;
- return Color.win32_new (getDisplay (), 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 ();
- int hwnd = parent.handle;
- RECT rect = new RECT ();
- rect.left = handle;
- if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 1, rect) == 0) {
- return new Rectangle (0, 0, 0, 0);
- }
- int width = rect.right - rect.left;
- int height = rect.bottom - rect.top;
- return new Rectangle (rect.left, rect.top, width, height);
-}
-
-/**
- * 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.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);
-}
-
-public Display getDisplay () {
- Tree parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
-/**
- * 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 hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.hItem = handle;
- tvItem.mask = OS.TVIF_STATE;
- OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
- return (tvItem.state & OS.TVIS_EXPANDED) != 0;
-}
-
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- *
- */
-public Color getForeground () {
- checkWidget ();
- int pixel = (foreground == -1) ? parent.getForegroundPixel() : foreground;
- return Color.win32_new (getDisplay (), 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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the 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.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 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 ();
- int count = 0;
- int hwnd = parent.handle;
- int hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- while (hItem != 0) {
- hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
- count++;
- }
- return count;
-}
-
-/**
- * Returns an 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 ();
- int count = 0;
- int hwnd = parent.handle;
- int hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- while (hItem != 0) {
- hItem = OS.SendMessage (hwnd, 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 = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
- while (tvItem.hItem != 0) {
- OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
- result [index++] = parent.items [tvItem.lParam];
- tvItem.hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, tvItem.hItem);
- }
- 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 ();
- 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_PARENT, handle);
- if (tvItem.hItem == 0) return null;
- OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
- return parent.items [tvItem.lParam];
-}
-
-void redraw () {
- if (parent.drawCount > 0) return;
- int hwnd = parent.handle;
- if (!OS.IsWindowVisible (hwnd)) return;
- RECT rect = new RECT ();
- rect.left = handle;
- if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 1, rect) != 0) {
- OS.InvalidateRect (hwnd, rect, true);
- }
-}
-
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- handle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = 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;
- }
- background = pixel;
- redraw ();
-}
-
-/**
- * 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;
- }
- tvItem.state = state << 12;
- 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 ();
- int hwnd = parent.handle;
- /*
- * 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
- * stricly wrong but is inconsistent. The fix is to notice
- * that the selection has changed and issue the event.
- */
- 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) {
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
- tvItem.hItem = hNewItem;
- if (OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem) != 0) {
- event.item = parent.items [tvItem.lParam];
- }
- parent.hAnchor = hNewItem;
- }
- parent.sendEvent (SWT.Selection, event);
- }
-}
-
-/**
- * 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;
- }
- foreground = pixel;
- redraw ();
-}
-
-/**
- * Sets the grayed state of the receiver.
- * <p>
- *
- * @param checked the new grayed state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-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;
- }
- tvItem.state = state << 12;
- OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
-}
-
-public void setImage (Image image) {
- checkWidget ();
- super.setImage (image);
- int hwnd = parent.handle;
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_IMAGE | OS.TVIF_SELECTEDIMAGE;
- tvItem.iImage = parent.imageIndex (image);
- tvItem.iSelectedImage = tvItem.iImage;
- tvItem.hItem = handle;
- OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
-}
-
-public void setText (String string) {
- checkWidget ();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- 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);
- TVITEM tvItem = new TVITEM ();
- tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_TEXT;
- tvItem.hItem = handle;
- tvItem.pszText = pszText;
- OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
- OS.HeapFree (hHeap, 0, pszText);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+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)
+ */
+ public int handle;
+
+ Tree parent;
+ int background, foreground;
+
+/**
+ * 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 composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
+ super (parent, style);
+ this.parent = parent;
+ parent.createItem (this, 0, OS.TVI_LAST);
+}
+
+/**
+ * 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 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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
+ super (parent, style);
+ if (index < 0) error (SWT.ERROR_INVALID_RANGE);
+ this.parent = parent;
+ int hItem = OS.TVI_FIRST;
+ if (index != 0) {
+ int count = 1, hwnd = parent.handle;
+ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
+ while (hItem != 0 && count < index) {
+ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
+ count++;
+ }
+ if (hItem == 0) error (SWT.ERROR_INVALID_RANGE);
+ };
+ parent.createItem (this, 0, hItem);
+}
+
+/**
+ * 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 composite control which will be the parent of the new instance (cannot be null)
+ * @param style the style of control to construct
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
+ super (checkNull (parentItem).parent, style);
+ parent = parentItem.parent;
+ int hItem = parentItem.handle;
+ parent.createItem (this, hItem, OS.TVI_LAST);
+}
+
+/**
+ * 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 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 index to store the receiver in its parent
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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) {
+ super (checkNull (parentItem).parent, style);
+ if (index < 0) error (SWT.ERROR_INVALID_RANGE);
+ parent = parentItem.parent;
+ int hItem = OS.TVI_FIRST;
+ int hParent = parentItem.handle;
+ if (index != 0) {
+ int count = 1, hwnd = parent.handle;
+ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hParent);
+ while (hItem != 0 && count < index) {
+ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
+ count++;
+ }
+ if (hItem == 0) error (SWT.ERROR_INVALID_RANGE);
+ }
+ parent.createItem (this, hParent, hItem);
+}
+
+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);
+}
+
+/**
+ * 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 ();
+ int pixel = (background == -1) ? parent.getBackgroundPixel() : background;
+ return Color.win32_new (getDisplay (), 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 ();
+ int hwnd = parent.handle;
+ RECT rect = new RECT ();
+ rect.left = handle;
+ if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 1, rect) == 0) {
+ return new Rectangle (0, 0, 0, 0);
+ }
+ int width = rect.right - rect.left;
+ int height = rect.bottom - rect.top;
+ return new Rectangle (rect.left, rect.top, width, height);
+}
+
+/**
+ * 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.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);
+}
+
+public Display getDisplay () {
+ Tree parent = this.parent;
+ if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
+/**
+ * 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 hwnd = parent.handle;
+ TVITEM tvItem = new TVITEM ();
+ tvItem.hItem = handle;
+ tvItem.mask = OS.TVIF_STATE;
+ OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
+ return (tvItem.state & OS.TVIS_EXPANDED) != 0;
+}
+
+/**
+ * Returns the foreground color that the receiver will use to draw.
+ *
+ * @return the receiver's foreground color
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @since 2.0
+ *
+ */
+public Color getForeground () {
+ checkWidget ();
+ int pixel = (foreground == -1) ? parent.getForegroundPixel() : foreground;
+ return Color.win32_new (getDisplay (), 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
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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.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 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 ();
+ int count = 0;
+ int hwnd = parent.handle;
+ int hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
+ while (hItem != 0) {
+ hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
+ count++;
+ }
+ return count;
+}
+
+/**
+ * Returns an 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 ();
+ int count = 0;
+ int hwnd = parent.handle;
+ int hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
+ while (hItem != 0) {
+ hItem = OS.SendMessage (hwnd, 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 = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, handle);
+ while (tvItem.hItem != 0) {
+ OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
+ result [index++] = parent.items [tvItem.lParam];
+ tvItem.hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, tvItem.hItem);
+ }
+ 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 ();
+ 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_PARENT, handle);
+ if (tvItem.hItem == 0) return null;
+ OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem);
+ return parent.items [tvItem.lParam];
+}
+
+void redraw () {
+ if (parent.drawCount > 0) return;
+ int hwnd = parent.handle;
+ if (!OS.IsWindowVisible (hwnd)) return;
+ RECT rect = new RECT ();
+ rect.left = handle;
+ if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 1, rect) != 0) {
+ OS.InvalidateRect (hwnd, rect, true);
+ }
+}
+
+void releaseChild () {
+ super.releaseChild ();
+ parent.destroyItem (this);
+}
+
+void releaseHandle () {
+ super.releaseHandle ();
+ handle = 0;
+}
+
+void releaseWidget () {
+ super.releaseWidget ();
+ parent = 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;
+ }
+ background = pixel;
+ redraw ();
+}
+
+/**
+ * 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;
+ }
+ tvItem.state = state << 12;
+ 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 ();
+ int hwnd = parent.handle;
+ /*
+ * 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
+ * stricly wrong but is inconsistent. The fix is to notice
+ * that the selection has changed and issue the event.
+ */
+ 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) {
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM;
+ tvItem.hItem = hNewItem;
+ if (OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem) != 0) {
+ event.item = parent.items [tvItem.lParam];
+ }
+ parent.hAnchor = hNewItem;
+ }
+ parent.sendEvent (SWT.Selection, event);
+ }
+}
+
+/**
+ * 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;
+ }
+ foreground = pixel;
+ redraw ();
+}
+
+/**
+ * Sets the grayed state of the receiver.
+ * <p>
+ *
+ * @param checked the new grayed state
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+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;
+ }
+ tvItem.state = state << 12;
+ OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
+}
+
+public void setImage (Image image) {
+ checkWidget ();
+ super.setImage (image);
+ int hwnd = parent.handle;
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_IMAGE | OS.TVIF_SELECTEDIMAGE;
+ tvItem.iImage = parent.imageIndex (image);
+ tvItem.iSelectedImage = tvItem.iImage;
+ tvItem.hItem = handle;
+ OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
+}
+
+public void setText (String string) {
+ checkWidget ();
+ if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ super.setText (string);
+ 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);
+ TVITEM tvItem = new TVITEM ();
+ tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_TEXT;
+ tvItem.hItem = handle;
+ tvItem.pszText = pszText;
+ OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, tvItem);
+ OS.HeapFree (hHeap, 0, pszText);
+}
+
+}
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
index d4cc41bae2..109a3b552c 100755
--- 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
@@ -1,1057 +1,1057 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.win32.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * This class is the abstract superclass of all user interface objects.
- * Widgets are created, disposed and issue notification to listeners
- * when events occur which affect them.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Dispose</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation. However, it has not been marked
- * final to allow those outside of the SWT development team to implement
- * patched versions of the class in order to get around specific
- * limitations in advance of when those limitations can be addressed
- * by the team. Any class built using subclassing to access the internals
- * of this class will likely fail to compile or run between releases and
- * may be strongly platform specific. Subclassing should not be attempted
- * without an intimate and detailed understanding of the workings of the
- * hierarchy. No support is provided for user-written classes which are
- * implemented as subclasses of this class.
- * </p>
- *
- * @see #checkSubclass
- */
-
-public abstract class Widget {
- int style, state;
- EventTable eventTable;
- Object data;
- String [] keys;
- Object [] values;
-
- /* Global state flags */
-// static final int AUTOMATIC = 1<<0;
-// static final int ACTIVE = 1<<1;
-// static final int GRAB = 1<<2;
-// static final int MULTIEXPOSE = 1<<3;
-// static final int RESIZEREDRAW = 1<<4;
-// static final int WRAP = 1<<5;
- static final int DISABLED = 1<<6;
- static final int HIDDEN = 1<<7;
-// static final int FOREGROUND = 1<<8;
-// static final int BACKGROUND = 1<<9;
- static final int DISPOSED = 1<<10;
-// static final int HANDLE = 1<<11;
- static final int CANVAS = 1<<12;
-
- /* Default widths for widgets */
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
- static final char Mnemonic = '&';
-
- /* COMCTL32.DLL flags */
- static final int MAJOR = 4, MINOR = 71;
- static final int COMCTL32_MAJOR, COMCTL32_MINOR;
- static {
-
- /* Get the COMCTL32.DLL version */
- DLLVERSIONINFO dvi = new DLLVERSIONINFO ();
- dvi.cbSize = DLLVERSIONINFO.sizeof;
- dvi.dwMajorVersion = 4;
- dvi.dwMinorVersion = 0;
- TCHAR lpLibFileName = new TCHAR (0, "comctl32.dll", true);
- int hModule = OS.LoadLibrary (lpLibFileName);
- if (hModule != 0) {
- String name = "DllGetVersion\0";
- byte [] lpProcName = new byte [name.length ()];
- for (int i=0; i<lpProcName.length; i++) {
- lpProcName [i] = (byte) name.charAt (i);
- }
- int DllGetVersion = OS.GetProcAddress (hModule, lpProcName);
- if (DllGetVersion != 0) OS.Call (DllGetVersion, dvi);
- OS.FreeLibrary (hModule);
- }
- COMCTL32_MAJOR = dvi.dwMajorVersion;
- COMCTL32_MINOR = dvi.dwMinorVersion;
- if (!OS.IsWinCE) {
- if ((COMCTL32_MAJOR << 16 | COMCTL32_MINOR) < (MAJOR << 16 | MINOR)) {
- System.out.println ("***WARNING: SWT requires comctl32.dll version " + MAJOR + "." + MINOR + " or greater");
- System.out.println ("***WARNING: Detected: " + COMCTL32_MAJOR + "." + COMCTL32_MINOR);
- }
- }
-
- /* Initialize the Common Controls DLL */
- 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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notifed 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.
- *
- * @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 #removeListener
- */
-public void addListener (int eventType, Listener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notifed 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);
-}
-
-/**
- * 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);
-}
-
-/**
- * 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.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (parent.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
-}
-
-/**
- * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) 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>
- * @see #dispose
- * @see #releaseChild
- * @see #releaseWidget
- * @see #releaseHandle
- */
-void destroyWidget () {
- releaseHandle ();
-}
-
-/**
- * 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);
- releaseChild ();
- releaseWidget ();
- destroyWidget ();
-}
-
-/**
- * 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 SWTError#error
- */
-void error (int code) {
- SWT.error(code);
-}
-
-boolean filters (int eventType) {
- Display display = getDisplay ();
- return display.filters (eventType);
-}
-
-/**
- * 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
- */
-public Object getData () {
- checkWidget();
- return 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
- */
-public Object getData (String key) {
- checkWidget();
- 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 <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>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public abstract Display getDisplay ();
-
-/**
- * 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 "";
-}
-
-/**
- * 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.
- *
- * @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>
- */
-protected 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 ();
-}
-
-/*
- * 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
- */
-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
- */
-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];
-}
-
-/**
- * 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.
- *
- * @param eventType the type of event which has occurred
- * @param event the event data
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void notifyListeners (int eventType, Event event) {
- checkWidget();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- sendEvent (eventType, event);
-}
-
-void postEvent (int eventType) {
- sendEvent (eventType, null, false);
-}
-
-void postEvent (int eventType, Event event) {
- sendEvent (eventType, event, false);
-}
-
-/*
- * 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. This could not be done
- * in <code>destroyWidget</code> for the menu bar because the
- * parent shell as well as other fields have been null'd out
- * already by <code>releaseWidget</code>.
- * </p>
- * This method is called first when a widget is disposed.
- *
- * @see #dispose
- * @see #releaseChild
- * @see #releaseWidget
- * @see #releaseHandle
- */
-void releaseChild () {
-}
-
-/*
- * 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 #releaseChild
- * @see #releaseWidget
- * @see #releaseHandle
- */
-void releaseHandle () {
- state |= DISPOSED;
-}
-
-void releaseResources () {
- releaseWidget ();
- releaseHandle ();
-}
-
-/*
- * 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>
- * <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>
- * This method is called after <code>releaseChild</code>.
- *
- * @see #dispose
- * @see #releaseChild
- * @see #releaseWidget
- * @see #releaseHandle
- */
-void releaseWidget () {
- sendEvent (SWT.Dispose);
- eventTable = null;
- data = null;
- keys = null;
- values = null;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notifed when an event of the given type occurs.
- *
- * @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
- */
-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 notifed 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 notifed 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) {
- Display display = getDisplay ();
- 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>
- */
-public void setData (Object data) {
- checkWidget();
- 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
- */
-public void setData (String key, Object value) {
- checkWidget();
- 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;
-}
-
-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;
- 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) {
- Display display = getDisplay ();
- if (display.lastAscii != 0) {
- event.character = mbcsToWcs ((char) display.lastAscii);
- }
- if (display.lastVirtual) {
- event.keyCode = Display.translateKey (display.lastKey);
- }
- if (event.keyCode == 0 && event.character == 0) {
- if (!display.lastNull) return false;
- }
- return setInputState (event, type);
-}
-
-/**
- * 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 + "}";
-}
-
-/*
- * 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
- */
-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
- */
-int wcsToMbcs (char ch) {
- return wcsToMbcs (ch, 0);
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.win32.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+
+/**
+ * This class is the abstract superclass of all user interface objects.
+ * Widgets are created, disposed and issue notification to listeners
+ * when events occur which affect them.
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>(none)</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>Dispose</dd>
+ * </dl>
+ * <p>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation. However, it has not been marked
+ * final to allow those outside of the SWT development team to implement
+ * patched versions of the class in order to get around specific
+ * limitations in advance of when those limitations can be addressed
+ * by the team. Any class built using subclassing to access the internals
+ * of this class will likely fail to compile or run between releases and
+ * may be strongly platform specific. Subclassing should not be attempted
+ * without an intimate and detailed understanding of the workings of the
+ * hierarchy. No support is provided for user-written classes which are
+ * implemented as subclasses of this class.
+ * </p>
+ *
+ * @see #checkSubclass
+ */
+
+public abstract class Widget {
+ int style, state;
+ EventTable eventTable;
+ Object data;
+ String [] keys;
+ Object [] values;
+
+ /* Global state flags */
+// static final int AUTOMATIC = 1<<0;
+// static final int ACTIVE = 1<<1;
+// static final int GRAB = 1<<2;
+// static final int MULTIEXPOSE = 1<<3;
+// static final int RESIZEREDRAW = 1<<4;
+// static final int WRAP = 1<<5;
+ static final int DISABLED = 1<<6;
+ static final int HIDDEN = 1<<7;
+// static final int FOREGROUND = 1<<8;
+// static final int BACKGROUND = 1<<9;
+ static final int DISPOSED = 1<<10;
+// static final int HANDLE = 1<<11;
+ static final int CANVAS = 1<<12;
+
+ /* Default widths for widgets */
+ static final int DEFAULT_WIDTH = 64;
+ static final int DEFAULT_HEIGHT = 64;
+ static final char Mnemonic = '&';
+
+ /* COMCTL32.DLL flags */
+ static final int MAJOR = 4, MINOR = 71;
+ static final int COMCTL32_MAJOR, COMCTL32_MINOR;
+ static {
+
+ /* Get the COMCTL32.DLL version */
+ DLLVERSIONINFO dvi = new DLLVERSIONINFO ();
+ dvi.cbSize = DLLVERSIONINFO.sizeof;
+ dvi.dwMajorVersion = 4;
+ dvi.dwMinorVersion = 0;
+ TCHAR lpLibFileName = new TCHAR (0, "comctl32.dll", true);
+ int hModule = OS.LoadLibrary (lpLibFileName);
+ if (hModule != 0) {
+ String name = "DllGetVersion\0";
+ byte [] lpProcName = new byte [name.length ()];
+ for (int i=0; i<lpProcName.length; i++) {
+ lpProcName [i] = (byte) name.charAt (i);
+ }
+ int DllGetVersion = OS.GetProcAddress (hModule, lpProcName);
+ if (DllGetVersion != 0) OS.Call (DllGetVersion, dvi);
+ OS.FreeLibrary (hModule);
+ }
+ COMCTL32_MAJOR = dvi.dwMajorVersion;
+ COMCTL32_MINOR = dvi.dwMinorVersion;
+ if (!OS.IsWinCE) {
+ if ((COMCTL32_MAJOR << 16 | COMCTL32_MINOR) < (MAJOR << 16 | MINOR)) {
+ System.out.println ("***WARNING: SWT requires comctl32.dll version " + MAJOR + "." + MINOR + " or greater");
+ System.out.println ("***WARNING: Detected: " + COMCTL32_MAJOR + "." + COMCTL32_MINOR);
+ }
+ }
+
+ /* Initialize the Common Controls DLL */
+ 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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called 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;
+}
+
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notifed 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.
+ *
+ * @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 #removeListener
+ */
+public void addListener (int eventType, Listener listener) {
+ checkWidget();
+ if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (eventTable == null) eventTable = new EventTable ();
+ eventTable.hook (eventType, listener);
+}
+
+/**
+ * Adds the listener to the collection of listeners who will
+ * be notifed 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);
+}
+
+/**
+ * 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);
+}
+
+/**
+ * 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.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (parent.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+}
+
+/**
+ * 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 () {
+ if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ if (isDisposed ()) 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>
+ * @see #dispose
+ * @see #releaseChild
+ * @see #releaseWidget
+ * @see #releaseHandle
+ */
+void destroyWidget () {
+ releaseHandle ();
+}
+
+/**
+ * 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);
+ releaseChild ();
+ releaseWidget ();
+ destroyWidget ();
+}
+
+/**
+ * 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 SWTError#error
+ */
+void error (int code) {
+ SWT.error(code);
+}
+
+boolean filters (int eventType) {
+ Display display = getDisplay ();
+ return display.filters (eventType);
+}
+
+/**
+ * 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
+ */
+public Object getData () {
+ checkWidget();
+ return 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
+ */
+public Object getData (String key) {
+ checkWidget();
+ 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 <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>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public abstract Display getDisplay ();
+
+/**
+ * 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 "";
+}
+
+/**
+ * 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.
+ *
+ * @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>
+ */
+protected 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 ();
+}
+
+/*
+ * 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
+ */
+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
+ */
+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];
+}
+
+/**
+ * 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.
+ *
+ * @param eventType the type of event which has occurred
+ * @param event the event data
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the event is null</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void notifyListeners (int eventType, Event event) {
+ checkWidget();
+ if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
+ sendEvent (eventType, event);
+}
+
+void postEvent (int eventType) {
+ sendEvent (eventType, null, false);
+}
+
+void postEvent (int eventType, Event event) {
+ sendEvent (eventType, event, false);
+}
+
+/*
+ * 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. This could not be done
+ * in <code>destroyWidget</code> for the menu bar because the
+ * parent shell as well as other fields have been null'd out
+ * already by <code>releaseWidget</code>.
+ * </p>
+ * This method is called first when a widget is disposed.
+ *
+ * @see #dispose
+ * @see #releaseChild
+ * @see #releaseWidget
+ * @see #releaseHandle
+ */
+void releaseChild () {
+}
+
+/*
+ * 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 #releaseChild
+ * @see #releaseWidget
+ * @see #releaseHandle
+ */
+void releaseHandle () {
+ state |= DISPOSED;
+}
+
+void releaseResources () {
+ releaseWidget ();
+ releaseHandle ();
+}
+
+/*
+ * 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>
+ * <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>
+ * This method is called after <code>releaseChild</code>.
+ *
+ * @see #dispose
+ * @see #releaseChild
+ * @see #releaseWidget
+ * @see #releaseHandle
+ */
+void releaseWidget () {
+ sendEvent (SWT.Dispose);
+ eventTable = null;
+ data = null;
+ keys = null;
+ values = null;
+}
+
+/**
+ * Removes the listener from the collection of listeners who will
+ * be notifed when an event of the given type occurs.
+ *
+ * @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
+ */
+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 notifed 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 notifed 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) {
+ Display display = getDisplay ();
+ 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>
+ */
+public void setData (Object data) {
+ checkWidget();
+ 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
+ */
+public void setData (String key, Object value) {
+ checkWidget();
+ 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;
+}
+
+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;
+ 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) {
+ Display display = getDisplay ();
+ if (display.lastAscii != 0) {
+ event.character = mbcsToWcs ((char) display.lastAscii);
+ }
+ if (display.lastVirtual) {
+ event.keyCode = Display.translateKey (display.lastKey);
+ }
+ if (event.keyCode == 0 && event.character == 0) {
+ if (!display.lastNull) return false;
+ }
+ return setInputState (event, type);
+}
+
+/**
+ * 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 + "}";
+}
+
+/*
+ * 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
+ */
+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
+ */
+int wcsToMbcs (char ch) {
+ return wcsToMbcs (ch, 0);
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/WidgetTable.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/WidgetTable.java
index 3e4590df35..5398addd49 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/WidgetTable.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/WidgetTable.java
@@ -1,115 +1,115 @@
-package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets;
+
+/*
* Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
* This file is made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.win32.*;
-
-/**
- * This class contains static methods which provide a map from the
- * platform representation of a widget to the SWT control.
- */
-
-class WidgetTable {
- static int FreeSlot = 0;
- static int GrowSize = 1024;
- static int [] IndexTable = new int [GrowSize];
- static Control [] ControlTable = new Control [GrowSize];
- static {
- for (int i=0; i<GrowSize-1; i++) IndexTable [i] = i + 1;
- IndexTable [GrowSize - 1] = -1;
- }
-
-public static synchronized Control get (int handle) {
- if (handle == 0) return null;
- int index = OS.GetWindowLong (handle, OS.GWL_USERDATA) - 1;
- if (0 <= index && index < ControlTable.length) return ControlTable [index];
- return null;
-}
-
-public synchronized static void put (int handle, Control control) {
- if (handle == 0) return;
- if (FreeSlot == -1) {
- int length = (FreeSlot = IndexTable.length) + GrowSize;
- 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;
- }
- OS.SetWindowLong (handle, OS.GWL_USERDATA, FreeSlot + 1);
- int oldSlot = FreeSlot;
- FreeSlot = IndexTable [oldSlot];
- IndexTable [oldSlot] = -2;
- ControlTable [oldSlot] = control;
-}
-
-public static synchronized Control remove (int handle) {
- if (handle == 0) return null;
- Control control = null;
- int 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;
- OS.SetWindowLong (handle, OS.GWL_USERDATA, 0);
- }
- return control;
-}
-
-public static synchronized Shell [] shells () {
- /*
- * This code is intentionally commented.
- * Bug in JVM 1.2. For some reason, when the following code
- * is inlined in this method, the JVM issues this error error:
- *
- * A nonfatal internal JIT (3.00.072b(x)) error 'GetRegisterA' has occurred in :
- * 'org/eclipse/swt/widgets/WidgetTable.shells ()[Lorg/eclipse/swt/widgets/Shell;': Interpreting method.
- * Please report this error in detail to http://java.sun.com/cgi-bin/bugreport.cgi
- *
- * The fix is to move the code that would be inlined into another method.
- */
-// int size = 0;
-// for (int i=0; i<WidgetTable.length; i++) {
-// Control control = WidgetTable [i];
-// if (control != null && control instanceof Shell) size++;
-// }
-
- int size = shellSize ();
- int index = 0;
- Shell [] result = new Shell [size];
- for (int i=0; i<ControlTable.length; i++) {
- Control control = ControlTable [i];
- if (control != null && control instanceof Shell) {
- result [index++] = (Shell) control;
- }
- }
- return result;
-}
-
-static int shellSize () {
- int length = 0;
- for (int i=0; i<ControlTable.length; i++) {
- Control control = ControlTable [i];
- if (control != null && control instanceof Shell) length++;
- }
- return length;
-}
-
-public static synchronized int size () {
- int length = 0;
- for (int i=0; i<ControlTable.length; i++) {
- if (ControlTable [i] != null) length++;
- }
- return length;
-}
-
-}
+ * http://www.eclipse.org/legal/cpl-v10.html
+ */
+
+import org.eclipse.swt.internal.win32.*;
+
+/**
+ * This class contains static methods which provide a map from the
+ * platform representation of a widget to the SWT control.
+ */
+
+class WidgetTable {
+ static int FreeSlot = 0;
+ static int GrowSize = 1024;
+ static int [] IndexTable = new int [GrowSize];
+ static Control [] ControlTable = new Control [GrowSize];
+ static {
+ for (int i=0; i<GrowSize-1; i++) IndexTable [i] = i + 1;
+ IndexTable [GrowSize - 1] = -1;
+ }
+
+public static synchronized Control get (int handle) {
+ if (handle == 0) return null;
+ int index = OS.GetWindowLong (handle, OS.GWL_USERDATA) - 1;
+ if (0 <= index && index < ControlTable.length) return ControlTable [index];
+ return null;
+}
+
+public synchronized static void put (int handle, Control control) {
+ if (handle == 0) return;
+ if (FreeSlot == -1) {
+ int length = (FreeSlot = IndexTable.length) + GrowSize;
+ 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;
+ }
+ OS.SetWindowLong (handle, OS.GWL_USERDATA, FreeSlot + 1);
+ int oldSlot = FreeSlot;
+ FreeSlot = IndexTable [oldSlot];
+ IndexTable [oldSlot] = -2;
+ ControlTable [oldSlot] = control;
+}
+
+public static synchronized Control remove (int handle) {
+ if (handle == 0) return null;
+ Control control = null;
+ int 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;
+ OS.SetWindowLong (handle, OS.GWL_USERDATA, 0);
+ }
+ return control;
+}
+
+public static synchronized Shell [] shells () {
+ /*
+ * This code is intentionally commented.
+ * Bug in JVM 1.2. For some reason, when the following code
+ * is inlined in this method, the JVM issues this error error:
+ *
+ * A nonfatal internal JIT (3.00.072b(x)) error 'GetRegisterA' has occurred in :
+ * 'org/eclipse/swt/widgets/WidgetTable.shells ()[Lorg/eclipse/swt/widgets/Shell;': Interpreting method.
+ * Please report this error in detail to http://java.sun.com/cgi-bin/bugreport.cgi
+ *
+ * The fix is to move the code that would be inlined into another method.
+ */
+// int size = 0;
+// for (int i=0; i<WidgetTable.length; i++) {
+// Control control = WidgetTable [i];
+// if (control != null && control instanceof Shell) size++;
+// }
+
+ int size = shellSize ();
+ int index = 0;
+ Shell [] result = new Shell [size];
+ for (int i=0; i<ControlTable.length; i++) {
+ Control control = ControlTable [i];
+ if (control != null && control instanceof Shell) {
+ result [index++] = (Shell) control;
+ }
+ }
+ return result;
+}
+
+static int shellSize () {
+ int length = 0;
+ for (int i=0; i<ControlTable.length; i++) {
+ Control control = ControlTable [i];
+ if (control != null && control instanceof Shell) length++;
+ }
+ return length;
+}
+
+public static synchronized int size () {
+ int length = 0;
+ for (int i=0; i<ControlTable.length; i++) {
+ if (ControlTable [i] != null) length++;
+ }
+ return length;
+}
+
+}