Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbundles/org.eclipse.swt/.classpath_motif1
-rwxr-xr-xbundles/org.eclipse.swt/.classpath_photon1
-rwxr-xr-xbundles/org.eclipse.swt/.cvsignore1
-rwxr-xr-xbundles/org.eclipse.swt/.vcm_meta1
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/internal/awt/win32/SWT_AWT.java19
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/AnimatedProgress.java168
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/BusyIndicator.java71
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CCombo.java1067
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CLabel.java448
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolder.java1517
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderAdapter.java10
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderEvent.java18
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderListener.java12
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabItem.java436
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ControlEditor.java237
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/DefaultContent.java878
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/DefaultLineStyler.java625
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ExtendedModifyEvent.java23
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ExtendedModifyListener.java21
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineBackgroundEvent.java25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineBackgroundListener.java23
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineStyleEvent.java24
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineStyleListener.java20
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/PopupList.java248
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ST.java56
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/SashForm.java397
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ScrolledComposite.java378
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StackLayout.java74
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyleRange.java146
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledText.java6418
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextBidi.java719
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextContent.java187
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextEvent.java30
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextListener.java65
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextPrinter.java352
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableEditor.java179
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTree.java708
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTreeEditor.java100
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTreeItem.java558
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangeListener.java43
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangedEvent.java23
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangingEvent.java41
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TreeEditor.java163
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/VerifyKeyListener.java18
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ViewForm.java491
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/close.gifbin0 -> 839 bytes
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/left.gifbin0 -> 828 bytes
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/leftDisabled.gifbin0 -> 828 bytes
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/package.html14
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/right.gifbin0 -> 828 bytes
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/rightDisabled.gifbin0 -> 828 bytes
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Clipboard.java2
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Transfer.java1
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/ByteArrayTransfer.java12
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/Clipboard.java143
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/FileTransfer.java43
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/RTFTransfer.java23
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/TextTransfer.java23
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/Transfer.java3
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/TransferData.java5
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OLE.java2
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java2
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleFrame.java3
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Printing/common/org/eclipse/swt/printing/PrinterData.java4
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Printing/motif/org/eclipse/swt/printing/Printer.java41
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Printing/photon/org/eclipse/swt/printing/Printer.java6
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java2
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/Printer.java29
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Program/motif/org/eclipse/swt/program/Program.java1757
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Program/photon/org/eclipse/swt/program/Program.java41
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java48
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c109
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java9
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageData.java3827
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageLoader.java9
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java4
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/RGB.java4
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java9
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/Callback.java21
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Dialog.java3
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java4
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/RunnableLock.java3
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Synchronizer.java16
-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/Compatability.java26
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/EventObjectCompatability.java43
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SerializableCompatability.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/Compatability.java21
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/EventObjectCompatability.java5
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SerializableCompatability.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/AbstractTreeItem.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Header.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/SelectableItemWidget.java11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/TreeRoots.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/motif/java/util/EventListener.java5
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/build.csh52
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/kde.cc461
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/make_linux.mak17
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/library/swt.c679
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java2
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java96
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java26
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java241
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java179
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java7
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java438
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/KDE.java64
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/OS.java111
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java367
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java244
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java538
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java250
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java1147
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java243
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java2798
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolBar.java422
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolItem.java342
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java625
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java206
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java1147
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java308
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java157
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java139
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java280
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java1305
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java667
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java616
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java129
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java258
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java71
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java348
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java741
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java224
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java749
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java468
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java1399
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java309
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java2
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java651
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java286
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java756
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/library/makefile.mak7
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/library/structs.c166
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/library/structs.h43
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/library/swt.c390
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Device.java18
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/FontData.java12
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/GC.java265
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Image.java68
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/graphics/Region.java4
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/photon/OS.java54
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/photon/PhKeyEvent_t.java5
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Button.java75
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Canvas.java21
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Caret.java75
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ColorDialog.java2
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Combo.java110
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Composite.java163
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Control.java305
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Decorations.java66
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Display.java24
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FileDialog.java2
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/FontDialog.java2
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Group.java11
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Label.java33
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/List.java105
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Menu.java65
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/MenuItem.java163
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ProgressBar.java23
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Sash.java11
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scale.java40
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ScrollBar.java69
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scrollable.java12
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Shell.java168
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Slider.java51
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabFolder.java38
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/TabItem.java28
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Text.java179
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolBar.java35
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ToolItem.java86
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Tracker.java28
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Widget.java114
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/library/makefile.mak7
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/library/structs.c104
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/library/structs.h48
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/library/swt.c353
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/library/swt.rc6
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java19
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java1
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontData.java70
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java186
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java42
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java5
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/win32/OS.java230
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java9
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java10
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java51
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java11
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java19
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java8
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java255
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolBar.java4
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/CoolItem.java15
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Decorations.java17
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DirectoryDialog.java26
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java217
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FileDialog.java139
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java78
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Group.java34
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ImageList.java98
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Label.java10
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/List.java57
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java12
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java72
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MessageBox.java79
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java28
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Sash.java28
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java28
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ScrollBar.java79
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java8
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java86
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Slider.java39
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java80
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabItem.java72
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java100
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableColumn.java67
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java82
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java85
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java98
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java126
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java59
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java113
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java140
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java57
-rwxr-xr-xbundles/org.eclipse.swt/buildnotes_swt.html177
-rwxr-xr-xbundles/org.eclipse.swt/plugin.xml6
-rwxr-xr-xbundles/org.eclipse.swt/readme_swt.html80
237 files changed, 37020 insertions, 14007 deletions
diff --git a/bundles/org.eclipse.swt/.classpath_motif b/bundles/org.eclipse.swt/.classpath_motif
index 9446ffe549..d89e2d31c2 100755
--- a/bundles/org.eclipse.swt/.classpath_motif
+++ b/bundles/org.eclipse.swt/.classpath_motif
@@ -2,6 +2,7 @@
<classpath>
<classpathentry kind="var" path="JRE_LIB"/>
<classpathentry kind="src" path="Eclipse SWT/motif"/>
+ <classpathentry kind="src" path="Eclipse SWT/emulated"/>
<classpathentry kind="src" path="Eclipse SWT/common"/>
<classpathentry kind="src" path="Eclipse SWT Printing/motif"/>
<classpathentry kind="src" path="Eclipse SWT Printing/common"/>
diff --git a/bundles/org.eclipse.swt/.classpath_photon b/bundles/org.eclipse.swt/.classpath_photon
index c061bdbf30..89aa3ff82e 100755
--- a/bundles/org.eclipse.swt/.classpath_photon
+++ b/bundles/org.eclipse.swt/.classpath_photon
@@ -2,6 +2,7 @@
<classpath>
<classpathentry kind="var" path="JRE_LIB"/>
<classpathentry kind="src" path="Eclipse SWT/photon"/>
+ <classpathentry kind="src" path="Eclipse SWT/emulated"/>
<classpathentry kind="src" path="Eclipse SWT/common"/>
<classpathentry kind="src" path="Eclipse SWT Printing/photon"/>
<classpathentry kind="src" path="Eclipse SWT Printing/common"/>
diff --git a/bundles/org.eclipse.swt/.cvsignore b/bundles/org.eclipse.swt/.cvsignore
index 30e8e7346e..3f041525eb 100755
--- a/bundles/org.eclipse.swt/.cvsignore
+++ b/bundles/org.eclipse.swt/.cvsignore
@@ -1,3 +1,2 @@
bin
.classpath
-build.properties \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/.vcm_meta b/bundles/org.eclipse.swt/.vcm_meta
index 67f905f685..0c9e8d8b7a 100755
--- a/bundles/org.eclipse.swt/.vcm_meta
+++ b/bundles/org.eclipse.swt/.vcm_meta
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-description>
- <comment></comment>
<nature id="org.eclipse.jdt.core.javanature"/>
<nature id="org.eclipse.pde.PluginNature"/>
<builder name="org.eclipse.jdt.core.javabuilder">
diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/internal/awt/win32/SWT_AWT.java b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/internal/awt/win32/SWT_AWT.java
index d6777ad621..d6f26064d6 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/internal/awt/win32/SWT_AWT.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/internal/awt/win32/SWT_AWT.java
@@ -25,6 +25,8 @@ import java.awt.Panel;
import java.awt.Dimension;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
+import java.awt.event.WindowEvent;
+import java.awt.event.FocusEvent;
public class SWT_AWT {
@@ -33,6 +35,18 @@ public static Panel new_Panel (final Composite parent) {
final WEmbeddedFrame frame = new WEmbeddedFrame (handle);
Panel panel = new Panel ();
frame.add (panel);
+ parent.addListener (SWT.Activate, new Listener () {
+ public void handleEvent (Event e) {
+ frame.dispatchEvent (new WindowEvent (frame, WindowEvent.WINDOW_ACTIVATED));
+ frame.dispatchEvent (new FocusEvent (frame, FocusEvent.FOCUS_GAINED));
+ }
+ });
+ parent.addListener (SWT.Deactivate, new Listener () {
+ public void handleEvent (Event e) {
+ frame.dispatchEvent (new WindowEvent(frame, WindowEvent.WINDOW_DEACTIVATED));
+ frame.dispatchEvent (new FocusEvent(frame, FocusEvent.FOCUS_LOST));
+ }
+ });
parent.addListener (SWT.Resize, new Listener () {
public void handleEvent (Event e) {
Rectangle rect = parent.getClientArea ();
@@ -40,6 +54,11 @@ public static Panel new_Panel (final Composite parent) {
frame.validate ();
}
});
+ parent.addListener (SWT.Dispose, new Listener () {
+ public void handleEvent (Event e) {
+ frame.dispose ();
+ }
+ });
return panel;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/AnimatedProgress.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/AnimatedProgress.java
new file mode 100644
index 0000000000..efdb04a943
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/AnimatedProgress.java
@@ -0,0 +1,168 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.events.*;
+
+/**
+ * A control for showing progress feedback for a long running operation.
+ */
+public class AnimatedProgress extends Canvas {
+
+ private static final int SLEEP = 70;
+ private static final int DEFAULT_WIDTH = 160;
+ private static final int DEFAULT_HEIGHT = 18;
+ private boolean active = false;
+ private boolean showStripes = false;
+ private int value;
+ private int orientation = SWT.HORIZONTAL;
+ private boolean showBorder = false;
+
+public AnimatedProgress(Composite parent, int style) {
+ super(parent, checkStyle(style));
+
+ if ((style & SWT.VERTICAL) != 0) {
+ orientation = SWT.VERTICAL;
+ }
+ showBorder = (style & SWT.BORDER) != 0;
+
+ addControlListener(new ControlAdapter() {
+ public void controlResized(ControlEvent e) {
+ redraw();
+ }
+ });
+ addPaintListener(new PaintListener() {
+ public void paintControl(PaintEvent e) {
+ paint(e);
+ }
+ });
+ addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e){
+ stop();
+ }
+ });
+}
+private static int checkStyle (int style) {
+ int mask = SWT.NONE;
+ return style & mask;
+}
+/**
+ * Stop the animation if it is not already stopped and
+ * reset the presentation to a blank appearance.
+ */
+public synchronized void clear(){
+ if (active)
+ stop();
+ showStripes = false;
+ redraw();
+}
+public Point computeSize(int wHint, int hHint, boolean changed) {
+ Point size = null;
+ if (orientation == SWT.HORIZONTAL) {
+ size = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ } else {
+ size = new Point(DEFAULT_HEIGHT, DEFAULT_WIDTH);
+ }
+ if (wHint != SWT.DEFAULT) size.x = wHint;
+ if (hHint != SWT.DEFAULT) size.y = hHint;
+
+ return size;
+}
+private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright) {
+
+ gc.setForeground(topleft);
+ gc.drawLine(x, y, x+w-1, y);
+ gc.drawLine(x, y, x, y+h-1);
+
+ gc.setForeground(bottomright);
+ gc.drawLine(x+w, y, x+w, y+h);
+ gc.drawLine(x, y+h, x+w, y+h);
+}
+private void paint(PaintEvent event) {
+ GC gc = event.gc;
+ Display disp= getDisplay();
+
+ Rectangle rect= getClientArea();
+ gc.fillRectangle(rect);
+ if (showBorder) {
+ drawBevelRect(gc, rect.x, rect.y, rect.width-1, rect.height-1,
+ disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
+ disp.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
+ }
+
+ paintStripes(gc);
+}
+private void paintStripes(GC gc) {
+
+ if (!showStripes) return;
+
+ Rectangle rect= getClientArea();
+ // Subtracted border painted by paint.
+ rect = new Rectangle(rect.x+2, rect.y+2, rect.width-4, rect.height-4);
+
+ gc.setLineWidth(2);
+ gc.setClipping(rect);
+ Color color = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
+ gc.setBackground(color);
+ gc.fillRectangle(rect);
+ gc.setForeground(this.getBackground());
+ int step = 12;
+ int foregroundValue = value == 0 ? step - 2 : value - 2;
+ if (orientation == SWT.HORIZONTAL) {
+ int y = rect.y - 1;
+ int w = rect.width;
+ int h = rect.height + 2;
+ for (int i= 0; i < w; i+= step) {
+ int x = i + foregroundValue;
+ gc.drawLine(x, y, x, h);
+ }
+ } else {
+ int x = rect.x - 1;
+ int w = rect.width + 2;
+ int h = rect.height;
+
+ for (int i= 0; i < h; i+= step) {
+ int y = i + foregroundValue;
+ gc.drawLine(x, y, w, y);
+ }
+ }
+
+ if (active) {
+ value = (value + 2) % step;
+ }
+}
+/**
+* Start the animation.
+*/
+public synchronized void start() {
+
+ if (active) return;
+
+ active = true;
+ showStripes = true;
+
+ final Display display = getDisplay();
+ final Runnable [] timer = new Runnable [1];
+ timer [0] = new Runnable () {
+ public void run () {
+ if (!active) return;
+ GC gc = new GC(AnimatedProgress.this);
+ paintStripes(gc);
+ gc.dispose();
+ display.timerExec (SLEEP, timer [0]);
+ }
+ };
+ display.timerExec (SLEEP, timer [0]);
+}
+/**
+* Stop the animation. Freeze the presentation at its current appearance.
+*/
+public synchronized void stop() {
+ active = false;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/BusyIndicator.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/BusyIndicator.java
new file mode 100644
index 0000000000..fc640a5a31
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/BusyIndicator.java
@@ -0,0 +1,71 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+ * Support for showing a Busy Cursor during a long running process.
+ */
+public class BusyIndicator {
+
+ static int nextBusyId = 1;
+ static final String BUSYID_NAME = "SWT BusyIndicator";
+
+/**
+ * Runs the given <code>Runnable</code> while providing
+ * busy feedback using this busy indicator.
+ *
+ * @param the display on which the busy feedback should be
+ * displayed. If the display is null, the Display for the current
+ * thread will be used. If there is no Display for the current thread,
+ * the runnable code will be executed and no busy feedback will be displayed.
+ * @param the runnable for which busy feedback is to be shown
+ * @see #showWhile
+ */
+
+public static void showWhile(Display display, Runnable runnable) {
+ if (display == null) {
+ display = Display.getCurrent();
+ if (display == null) {
+ runnable.run();
+ return;
+ }
+ }
+
+ Integer busyId = new Integer(nextBusyId);
+ nextBusyId++;
+ Cursor cursor = new Cursor(display, SWT.CURSOR_WAIT);
+
+ Shell[] shells = display.getShells();
+ for (int i = 0; i < shells.length; i++) {
+ Integer id = (Integer)shells[i].getData(BUSYID_NAME);
+ if (id == null) {
+ shells[i].setCursor(cursor);
+ shells[i].setData(BUSYID_NAME, busyId);
+ }
+ }
+
+ try {
+ runnable.run();
+ } finally {
+ shells = display.getShells();
+ for (int i = 0; i < shells.length; i++) {
+ Integer id = (Integer)shells[i].getData(BUSYID_NAME);
+ if (id == busyId) {
+ shells[i].setCursor(null);
+ shells[i].setData(BUSYID_NAME, null);
+ }
+ }
+ if (cursor != null && !cursor.isDisposed()) {
+ cursor.dispose();
+ }
+ }
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CCombo.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CCombo.java
new file mode 100644
index 0000000000..3bd86c4826
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CCombo.java
@@ -0,0 +1,1067 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+ * The CCombo class represents a selectable user interface object
+ * that combines a text field and a list and issues notificiation
+ * when an item is selected from the list.
+ * <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>
+ * <dd>BORDER, READ_ONLY</dd>
+ * <dt><b>Events:</b>
+ * <dd>Selection</dd>
+ * </dl>
+ */
+public final class CCombo extends Composite {
+
+ static final int ITEMS_SHOWING = 5;
+
+ Text text;
+ List list;
+ Shell popup;
+ Button arrow;
+ boolean hasFocus;
+
+public CCombo (Composite parent, int style) {
+ super (parent, checkStyle (style));
+
+ style = getStyle();
+
+ int textStyle = SWT.SINGLE;
+ if ((style & SWT.READ_ONLY) != 0) textStyle |= SWT.READ_ONLY;
+ if ((style & SWT.FLAT) != 0) textStyle |= SWT.FLAT;
+ text = new Text (this, textStyle);
+
+ popup = new Shell (getShell (), SWT.NO_TRIM);
+
+ int listStyle = SWT.SINGLE | SWT.V_SCROLL;
+ if ((style & SWT.FLAT) != 0) listStyle |= SWT.FLAT;
+ list = new List (popup, listStyle);
+
+ int arrowStyle = SWT.ARROW | SWT.DOWN;
+ if ((style & SWT.FLAT) != 0) arrowStyle |= SWT.FLAT;
+ arrow = new Button (this, arrowStyle);
+
+ Listener listener = new Listener () {
+ public void handleEvent (Event event) {
+ if (popup == event.widget) {
+ popupEvent (event);
+ return;
+ }
+ if (text == event.widget) {
+ textEvent (event);
+ return;
+ }
+ if (list == event.widget) {
+ listEvent (event);
+ return;
+ }
+ if (arrow == event.widget) {
+ arrowEvent (event);
+ return;
+ }
+ if (CCombo.this == event.widget) {
+ comboEvent (event);
+ return;
+ }
+
+ }
+ };
+
+ int [] comboEvents = {SWT.Dispose, SWT.Move, SWT.Resize};
+ for (int i=0; i<comboEvents.length; i++) this.addListener (comboEvents [i], listener);
+
+ int [] popupEvents = {SWT.Close, SWT.Paint, SWT.Deactivate};
+ for (int i=0; i<popupEvents.length; i++) popup.addListener (popupEvents [i], listener);
+
+ int [] textEvents = {SWT.KeyDown, SWT.KeyUp, SWT.Modify, SWT.MouseDown, SWT.MouseUp, SWT.Traverse, SWT.FocusIn, SWT.FocusOut};
+ for (int i=0; i<textEvents.length; i++) text.addListener (textEvents [i], listener);
+
+ int [] listEvents = {SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.FocusOut};
+ for (int i=0; i<listEvents.length; i++) list.addListener (listEvents [i], listener);
+
+ int [] arrowEvents = {SWT.MouseDown, SWT.FocusIn, SWT.FocusOut};
+ for (int i=0; i<arrowEvents.length; i++) arrow.addListener (arrowEvents [i], listener);
+
+}
+static int checkStyle (int style) {
+ int mask = SWT.BORDER | SWT.READ_ONLY | SWT.FLAT;
+ return style & mask;
+}
+/**
+* Adds an item.
+* <p>
+* The item is placed at the end of the list.
+* Indexing is zero based.
+*
+* @param string the new 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_NULL_ARGUMENT)
+* when the string is null
+* @exception SWTError(ERROR_ITEM_NOT_ADDED)
+* when the item cannot be added
+*/
+public void add (String string) {
+ if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ list.add (string);
+}
+/**
+* Adds an item at an index.
+* <p>
+* The item is placed at an index in the list.
+* Indexing is zero based.
+*
+* This operation will fail when the index is
+* out of range.
+*
+* @param string the new item
+* @param index the index for 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_NULL_ARGUMENT)
+* when the string is null
+* @exception SWTError(ERROR_ITEM_NOT_ADDED)
+* when the item cannot be added
+*/
+public void add (String string, int index) {
+ if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ list.add (string, index);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @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_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addModifyListener (ModifyListener listener) {;
+ if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Modify, typedListener);
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @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_NULL_ARGUMENT)
+* when listener is null
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Selection,typedListener);
+ addListener (SWT.DefaultSelection,typedListener);
+}
+void arrowEvent (Event event) {
+ switch (event.type) {
+ case SWT.FocusIn: {
+ if (hasFocus) return;
+ hasFocus = true;
+ if (getEditable ()) text.selectAll ();
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.FocusIn, e);
+ break;
+ }
+ case SWT.FocusOut: {
+ Control focusControl = getDisplay ().getFocusControl();
+ if (focusControl == list || focusControl == text) return;
+ hasFocus = false;
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.FocusOut, e);
+ break;
+ }
+ case SWT.MouseDown: {
+ if (event.button != 1) return;
+ dropDown (!isDropped ());
+ break;
+ }
+ }
+}
+/**
+* Clears the current selection.
+* <p>
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void clearSelection () {
+ text.clearSelection ();
+ list.deselectAll ();
+}
+void comboEvent (Event event) {
+ switch (event.type) {
+ case SWT.Dispose:
+ if (popup != null && !popup.isDisposed ()) popup.dispose ();
+ popup = null;
+ text = null;
+ list = null;
+ arrow = null;
+ break;
+ case SWT.Move:
+ dropDown(false);
+ break;
+ case SWT.Resize:
+ internalLayout();
+ break;
+ }
+}
+
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ int width = 0, height = 0;
+ Point textSize = text.computeSize (wHint, SWT.DEFAULT, changed);
+ Point arrowSize = arrow.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
+ Point listSize = list.computeSize (wHint, SWT.DEFAULT, changed);
+ Point barSize = list.getVerticalBar().getSize();
+ int borderWidth = getBorderWidth();
+
+ height = Math.max (hHint, Math.max(textSize.y, arrowSize.y) + 2*borderWidth);
+ width = Math.max (wHint, Math.max(textSize.x + arrowSize.x + 2*borderWidth, listSize.x + 2) );
+ return new Point (width, height);
+}
+/**
+* Deselects an item.
+* <p>
+* If the item at an index is selected, it is
+* deselected. If the item at an index is not
+* selected, it remains deselected. Indices
+* that are out of range are ignored. Indexing
+* is zero based.
+*
+* @param index the index of 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
+*/
+public void deselect (int index) {
+ list.deselect (index);
+}
+/**
+* Deselects all items.
+* <p>
+*
+* If an item is selected, it is deselected.
+* If an item is not selected, it remains unselected.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void deselectAll () {
+ list.deselectAll ();
+}
+void dropDown (boolean drop) {
+ if (drop == isDropped ()) return;
+ if (!drop) {
+ popup.setVisible (false);
+ text.setFocus();
+ return;
+ }
+ int index = list.getSelectionIndex ();
+ if (index != -1) list.setTopIndex (index);
+ Rectangle listRect = list.getBounds ();
+ int borderWidth = getBorderWidth();
+ Point point = toDisplay (new Point (0 - borderWidth, 0 - borderWidth));
+ Point comboSize = getSize();
+ popup.setBounds (point.x, point.y + comboSize.y, comboSize.x, listRect.height + 2);
+ popup.setVisible (true);
+ list.setFocus();
+}
+public Control [] getChildren () {
+ return new Control [0];
+}
+boolean getEditable () {
+ return text.getEditable ();
+}
+/**
+* Gets an item 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_ITEM)
+* when the operation fails
+*/
+public String getItem (int index) {
+ return list.getItem (index);
+}
+/**
+* Gets the number of items.
+* <p>
+* This operation will fail if the number of
+* items could not be queried from the OS.
+*
+* @return the number of items in the widget
+*
+* @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_COUNT)
+* when the operation fails
+*/
+public int getItemCount () {
+ return list.getItemCount ();
+}
+/**
+* Gets the height of one item.
+* <p>
+* This operation will fail if the height of
+* one item could not be queried from the OS.
+*
+* @return the height of one item in the widget
+*
+* @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_ITEM_HEIGHT)
+* when the operation fails
+*/
+public int getItemHeight () {
+ return list.getItemHeight ();
+}
+/**
+* Gets the items.
+* <p>
+* This operation will fail if the items cannot
+* be queried from the OS.
+*
+* @return the items in the widget
+*
+* @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_ITEM)
+* when the operation fails
+*/
+public String [] getItems () {
+ return list.getItems ();
+}
+/**
+* Gets the selection.
+* <p>
+* @return a point representing the selection start and end
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Point getSelection () {
+ return text.getSelection ();
+}
+/**
+* Gets the index of the selected item.
+* <p>
+* Indexing is zero based.
+* If no item is selected -1 is returned.
+*
+* @return the index of the selected item.
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getSelectionIndex () {
+ return list.getSelectionIndex ();
+}
+/**
+* Gets the widget text.
+* <p>
+* If the widget has no text, an empty string is returned.
+*
+* @return the widget text
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public String getText () {
+ return text.getText ();
+}
+/**
+* Gets the height of the combo's text field.
+* <p>
+* The operation will fail if the height cannot
+* be queried from the OS.
+
+* @return the height of the combo's text field.
+*
+* @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_ERROR_CANNOT_GET_ITEM_HEIGHT)
+* when the operation fails
+*/
+public int getTextHeight () {
+ return text.getLineHeight();
+}
+/**
+* Gets the text limit.
+* <p>
+* @return the text limit
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public int getTextLimit () {
+ return text.getTextLimit ();
+}
+/**
+* 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 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_NULL_ARGUMENT)
+* when string is null
+*/
+public int indexOf (String string) {
+ if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ return list.indexOf (string);
+}
+/**
+* Gets the index of an item.
+* <p>
+* The widget is searched starting at start including
+* the end position until an item is found that
+* is equal to the search itenm. If no item is
+* found, -1 is returned. Indexing is zero based.
+*
+* @param string the search item
+* @param index the starting position
+* @return the index of 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_NULL_ARGUMENT)
+* when string is null
+*/
+public int indexOf (String string, int start) {
+ if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ return list.indexOf (string, start);
+}
+boolean isDropped () {
+ return popup.getVisible ();
+}
+public boolean isFocusControl () {
+ if (text.isFocusControl() || arrow.isFocusControl() || list.isFocusControl() || popup.isFocusControl()) {
+ return true;
+ } else {
+ return super.isFocusControl();
+ }
+}
+void internalLayout () {
+ if (isDropped ()) dropDown (false);
+
+ Rectangle rect = getClientArea();
+ int width = rect.width;
+ int height = rect.height;
+ Point arrowSize = arrow.computeSize(SWT.DEFAULT, height);
+ text.setBounds (0, 0, width - arrowSize.x, height);
+ arrow.setBounds (width - arrowSize.x, 0, arrowSize.x, arrowSize.y);
+
+ Point size = getSize();
+ int listHeight = list.getItemHeight () * ITEMS_SHOWING;
+ Rectangle trim = list.computeTrim (0, 0, size.x - 2, listHeight);
+ list.setBounds (1, 1, size.x - 2, trim.height);
+}
+void listEvent (Event event) {
+ switch (event.type) {
+ case SWT.FocusIn: {
+ if (hasFocus) return;
+ hasFocus = true;
+ if (getEditable ()) text.selectAll ();
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.FocusIn, e);
+ break;
+ }
+ case SWT.FocusOut: {
+ Control focusControl = getDisplay ().getFocusControl();
+ if (focusControl == text || focusControl == arrow) return;
+ hasFocus = false;
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.FocusOut, e);
+ break;
+ }
+ case SWT.MouseUp: {
+ if (event.button != 1) return;
+ dropDown (false);
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.DefaultSelection, e);
+ break;
+ }
+ case SWT.Selection: {
+ int index = list.getSelectionIndex ();
+ if (index == -1) return;
+ text.setText (list.getItem (index));
+ text.selectAll ();
+ list.setSelection(index);
+ Event e = new Event();
+ e.time = event.time;
+ e.stateMask = event.stateMask;
+ e.doit = event.doit;
+ notifyListeners(SWT.Selection, e);
+ event.doit = e.doit;
+ break;
+ }
+ case SWT.Traverse: {
+ switch (event.detail) {
+ case SWT.TRAVERSE_TAB_NEXT:
+ case SWT.TRAVERSE_RETURN:
+ case SWT.TRAVERSE_ESCAPE:
+ case SWT.TRAVERSE_ARROW_PREVIOUS:
+ case SWT.TRAVERSE_ARROW_NEXT:
+ event.doit = false;
+ break;
+ }
+ Event e = new Event();
+ e.time = event.time;
+ e.detail = event.detail;
+ e.doit = event.doit;
+ e.keyCode = event.keyCode;
+ notifyListeners(SWT.Traverse, e);
+ event.doit = e.doit;
+ break;
+ }
+ case SWT.KeyUp: {
+ Event e = new Event();
+ e.time = event.time;
+ e.character = event.character;
+ e.keyCode = event.keyCode;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.KeyUp, e);
+ break;
+ }
+ case SWT.KeyDown: {
+ if (event.character == SWT.ESC) {
+ // escape key cancels popup list
+ dropDown (false);
+ }
+ if (event.character == SWT.CR || event.character == '\t') {
+ // Enter and Tab cause default selection
+ dropDown (false);
+ Event e = new Event();
+ e.time = event.time;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.DefaultSelection, e);
+ }
+ //At this point the widget may have been disposed.
+ // If so, do not continue.
+ if (isDisposed()) break;
+ Event e = new Event();
+ e.time = event.time;
+ e.character = event.character;
+ e.keyCode = event.keyCode;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.KeyDown, e);
+ break;
+
+ }
+ }
+}
+void popupEvent(Event event) {
+ switch (event.type) {
+ case SWT.Paint:
+ // draw black rectangle around list
+ Rectangle listRect = list.getBounds();
+ Color black = getDisplay().getSystemColor(SWT.COLOR_BLACK);
+ event.gc.setForeground(black);
+ event.gc.drawRectangle(0, 0, listRect.width + 1, listRect.height + 1);
+ break;
+ case SWT.Close:
+ event.doit = false;
+ dropDown (false);
+ break;
+ case SWT.Deactivate:
+ dropDown (false);
+ break;
+ }
+}
+public void redraw (int x, int y, int width, int height, boolean all) {
+ if (!all) return;
+ Point location = text.getLocation();
+ text.redraw(x - location.x, y - location.y, width, height, all);
+ location = list.getLocation();
+ list.redraw(x - location.x, y - location.y, width, height, all);
+ if (arrow != null) {
+ location = arrow.getLocation();
+ arrow.redraw(x - location.x, y - location.y, width, height, all);
+ }
+}
+
+/**
+* Removes an item 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 removed from
+* the OS.
+*
+* @param index the index of the item
+* @return the selection state
+*
+* @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_ITEM_NOT_REMOVED)
+* when the operation fails
+*/
+public void remove (int index) {
+ list.remove (index);
+}
+/**
+* Removes a range of items.
+* <p>
+* Indexing is zero based. The range of items
+* is from the start index up to and including
+* the end index.
+*
+* This operation will fail when the index is out
+* of range or an item could not be removed from
+* the OS.
+*
+* @param start the start of the range
+* @param end the end of the range
+*
+* @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_ITEM_NOT_REMOVED)
+* when the operation fails
+*/
+public void remove (int start, int end) {
+ list.remove (start, end);
+}
+/**
+* Removes an item.
+* <p>
+* This operation will fail when the item
+* could not be removed from the OS.
+*
+* @param string the search 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_NULL_ARGUMENT)
+* when string is null
+* @exception SWTError(ERROR_ITEM_NOT_REMOVED)
+* when the operation fails
+*/
+public void remove (String string) {
+ if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ list.remove (string);
+}
+/**
+* Removes all items.
+* <p>
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public void removeAll () {
+ text.setText ("");
+ list.removeAll ();
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @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_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeModifyListener (ModifyListener listener) {
+ if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ removeListener(SWT.Modify, listener);
+}
+/**
+* Removes the listener.
+* <p>
+*
+* @param listener the listener
+*
+* @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_NULL_ARGUMENT)
+* when listener is null
+*/
+public void removeSelectionListener (SelectionListener listener) {
+ if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ removeListener(SWT.Selection, listener);
+ removeListener(SWT.DefaultSelection,listener);
+}
+/**
+* Selects an item.
+* <p>
+* If the item at an index is not selected, it is
+* selected. Indices that are out of
+* range are ignored. Indexing is zero based.
+*
+* @param index the index of 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
+*/
+public void select (int index) {
+ if (index == -1) {
+ list.deselectAll ();
+ text.setText ("");
+ return;
+ }
+ if (0 <= index && index < list.getItemCount()) {
+ if (index != getSelectionIndex()) {
+ text.setText (list.getItem (index));
+ text.selectAll ();
+ list.select (index);
+ list.showSelection ();
+ }
+ }
+}
+public void setBackground (Color color) {
+ super.setBackground(color);
+ if (text != null) text.setBackground(color);
+ if (list != null) list.setBackground(color);
+ if (arrow != null) arrow.setBackground(color);
+}
+
+
+/**
+* Sets the focus.
+*/
+public boolean setFocus () {
+ return text.setFocus ();
+}
+/**
+* Sets the widget font.
+*/
+public void setFont (Font font) {
+ super.setFont (font);
+ text.setFont (font);
+ list.setFont (font);
+ internalLayout ();
+}
+public void setForeground (Color color) {
+ super.setForeground(color);
+ if (text != null) text.setForeground(color);
+ if (list != null) list.setForeground(color);
+ if (arrow != null) arrow.setForeground(color);
+}
+/**
+* Sets the text of an item.
+* <p>
+* Indexing is zero based.
+*
+* This operation will fail when the index is out
+* of range or an item could not be changed in
+* the OS.
+*
+* @param index the index for the item
+* @param string 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_NULL_ARGUMENT)
+* when items is null
+* @exception SWTError(ERROR_ITEM_NOT_MODIFIED)
+* when the operation fails
+*/
+public void setItem (int index, String string) {
+ if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ list.setItem (index, string);
+}
+/**
+* Sets all items.
+* <p>
+* @param items the array of items
+*
+* @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_NULL_ARGUMENT)
+* when items is null
+* @exception SWTError(ERROR_ITEM_NOT_ADDED)
+* when the operation fails
+*/
+public void setItems (String [] items) {
+ if (items == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ int style = getStyle();
+ if ((style & SWT.READ_ONLY) != 0) text.setText ("");
+ list.setItems (items);
+}
+/**
+* Sets the new selection.
+* <p>
+* @param selection point representing the start and the end of the new selection
+*
+* @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_NULL_ARGUMENT)
+* when selection is null
+*/
+public void setSelection (Point selection) {
+ if (selection == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ text.setSelection (selection.x, selection.y);
+}
+
+
+/**
+* Sets the widget text
+* <p>
+* @param string the widget text
+*
+* @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_NULL_ARGUMENT)
+* when string is null
+*/
+public void setText (String string) {
+ if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ int index = list.indexOf (string);
+ if (index == -1) {
+ list.deselectAll ();
+ text.setText (string);
+ return;
+ }
+ text.setText (string);
+ text.selectAll ();
+ list.setSelection (index);
+ list.showSelection ();
+}
+/**
+* Sets the text limit
+* <p>
+* @param limit new text limit
+*
+* @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_BE_ZERO)
+* when limit is 0
+*/
+public void setTextLimit (int limit) {
+ text.setTextLimit (limit);
+}
+public void setVisible (boolean visible) {
+ super.setVisible(visible);
+ if (!getVisible()) {
+ Composite parent = getParent();
+ while (parent != null && !parent.isVisible()) {
+ parent = parent.getParent();
+ }
+ if (parent != null) parent.setFocus();
+ }
+}
+void textEvent (Event event) {
+ switch (event.type) {
+ case SWT.FocusIn: {
+ if (hasFocus) return;
+ hasFocus = true;
+ if (getEditable ()) text.selectAll ();
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.FocusIn, e);
+ break;
+ }
+ case SWT.FocusOut: {
+ Control focusControl = getDisplay ().getFocusControl();
+ if (focusControl == list || focusControl == arrow) return;
+ hasFocus = false;
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.FocusOut, e);
+ break;
+ }
+ case SWT.KeyDown: {
+
+ if (event.character == SWT.ESC) { // escape key cancels popup list
+ dropDown (false);
+ }
+ if (event.character == SWT.CR || event.character == '\t') {
+ dropDown (false);
+ Event e = new Event();
+ e.time = event.time;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.DefaultSelection, e);
+ }
+ //At this point the widget may have been disposed.
+ // If so, do not continue.
+ if (isDisposed()) break;
+
+ if (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN) {
+ int oldIndex = getSelectionIndex ();
+ if (event.keyCode == SWT.ARROW_UP) {
+ select (Math.max (oldIndex - 1, 0));
+ } else {
+ select (Math.min (oldIndex + 1, getItemCount () - 1));
+ }
+
+ if (oldIndex != getSelectionIndex ()) {
+ Event e = new Event();
+ e.time = event.time;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.Selection, e);
+ }
+ //At this point the widget may have been disposed.
+ // If so, do not continue.
+ if (isDisposed()) break;
+ }
+
+ // Further work : Need to add support for incremental search in
+ // pop up list as characters typed in text widget
+
+ Event e = new Event();
+ e.time = event.time;
+ e.character = event.character;
+ e.keyCode = event.keyCode;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.KeyDown, e);
+ break;
+ }
+ case SWT.KeyUp: {
+ Event e = new Event();
+ e.time = event.time;
+ e.character = event.character;
+ e.keyCode = event.keyCode;
+ e.stateMask = event.stateMask;
+ notifyListeners(SWT.KeyUp, e);
+ break;
+ }
+ case SWT.Modify: {
+ list.deselectAll ();
+ Event e = new Event();
+ e.time = event.time;
+ notifyListeners(SWT.Modify, e);
+ break;
+ }
+ case SWT.MouseDown: {
+ if (event.button != 1) return;
+ if (text.getEditable ()) return;
+ boolean dropped = isDropped ();
+ text.selectAll ();
+ if (!dropped) setFocus ();
+ dropDown (!dropped);
+ break;
+ }
+ case SWT.MouseUp: {
+ if (event.button != 1) return;
+ if (text.getEditable ()) return;
+ text.selectAll ();
+ break;
+ }
+ case SWT.Traverse: {
+ switch (event.detail) {
+ case SWT.TRAVERSE_TAB_NEXT:
+ case SWT.TRAVERSE_ARROW_PREVIOUS:
+ case SWT.TRAVERSE_ARROW_NEXT:
+ // The tab key causes default selection and
+ // the arrow keys are used to manipulate the list contents so
+ // do not use them for traversal.
+ event.doit = false;
+ break;
+ }
+
+ Event e = new Event();
+ e.time = event.time;
+ e.detail = event.detail;
+ e.doit = event.doit;
+ e.keyCode = event.keyCode;
+ notifyListeners(SWT.Traverse, e);
+ event.doit = e.doit;
+ break;
+ }
+ }
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CLabel.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CLabel.java
new file mode 100644
index 0000000000..799891d8fa
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CLabel.java
@@ -0,0 +1,448 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.events.*;
+
+/**
+ * A Label which supports aligned text and/or an image and different border styles.
+ * <p>
+ * If there is not enough space a SmartLabel uses the following strategy to fit the
+ * information into the available space:
+ * <pre>
+ * ignores the indent in left align mode
+ * ignores the image and the gap
+ * shortens the text by replacing the center portion of the label with an ellipsis
+ * shortens the text by removing the center portion of the label
+ * </pre>
+ * <p>
+ * <dl>
+ * <dt><b>Styles:</b>
+ * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
+ * <dt><b>Events:</b>
+ * <dd></dd>
+ * </dl>
+ */
+public class CLabel extends Canvas {
+
+ /** Gap between icon and text */
+ private static final int GAP = 5;
+ /** Left and right margins */
+ private static final int INDENT = 3;
+ /** a string inserted in the middle of text that has been shortened */
+ private static final String ellipsis = "...";
+ /** the alignment. Either CENTER, RIGHT, LEFT. Default is LEFT*/
+ private int align = SWT.LEFT;
+ private int hIndent = INDENT;
+ private int vIndent = INDENT;
+ /** the current text */
+ private String text;
+ /** the current icon */
+ private Image image;
+ // The tooltip is used for two purposes - the application can set
+ // a tooltip or the tooltip can be used to display the full text when the
+ // the text has been truncated due to the label being too short.
+ // The appToolTip stores the tooltip set by the application. Control.tooltiptext
+ // contains whatever tooltip is currently being displayed.
+ private String appToolTipText;
+
+ private Image backgroundImage;
+ private Color[] gradientColors;
+ private int[] gradientPercents;
+
+
+/**
+ * Create a CLabel with the given border style as a child of parent.
+ */
+public CLabel(Composite parent, int style) {
+ super(parent, checkStyle(style));
+
+ if ((style & SWT.CENTER) != 0) align = SWT.CENTER;
+ if ((style & SWT.RIGHT) != 0) align = SWT.RIGHT;
+ if ((style & SWT.LEFT) != 0) align = SWT.LEFT;
+
+ addPaintListener(new PaintListener(){
+ public void paintControl(PaintEvent event) {
+ onPaint(event);
+ }
+ });
+
+ addDisposeListener(new DisposeListener(){
+ public void widgetDisposed(DisposeEvent event) {
+ onDispose(event);
+ }
+ });
+
+}
+/**
+ * Check the style bits to ensure that no invalid styles are applied.
+ */
+private static int checkStyle (int style) {
+ int mask = SWT.SHADOW_IN | SWT.SHADOW_OUT | SWT.SHADOW_NONE;
+ style = style & mask;
+ style |= SWT.NO_FOCUS | SWT.NO_BACKGROUND;
+ return style;
+}
+public Point computeSize(int wHint, int hHint, boolean changed) {
+ Point e = getTotalSize(image, text);
+ if (wHint == SWT.DEFAULT){
+ e.x += 2*hIndent;
+ } else {
+ e.x = wHint;
+ }
+ if (hHint == SWT.DEFAULT) {
+ e.y += 2*vIndent;
+ } else {
+ e.y = hHint;
+ }
+ return e;
+}
+/**
+ * Draw a rectangle in the given colors.
+ */
+private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright) {
+ gc.setForeground(bottomright);
+ gc.drawLine(x+w, y, x+w, y+h);
+ gc.drawLine(x, y+h, x+w, y+h);
+
+ gc.setForeground(topleft);
+ gc.drawLine(x, y, x+w-1, y);
+ gc.drawLine(x, y, x, y+h-1);
+}
+/**
+ * Returns the alignment.
+ * The alignment style (LEFT, CENTER or RIGHT) is returned.
+ */
+public int getAlignment() {
+ return align;
+}
+/**
+ * Return the CLabel's image or <code>null</code>.
+ */
+public Image getImage() {
+ return image;
+}
+/**
+ * Compute the minimum size.
+ */
+private Point getTotalSize(Image image, String text) {
+ Point size = new Point(0, 0);
+
+ if (image != null) {
+ Rectangle r = image.getBounds();
+ size.x += r.width;
+ size.y += r.height;
+ }
+
+ GC gc = new GC(this);
+ if (text != null && text.length() > 0) {
+ Point e = gc.textExtent(text);
+ size.x += e.x;
+ size.y = Math.max(size.y, e.y);
+ if (image != null) size.x += GAP;
+ } else {
+ size.y = Math.max(size.y, gc.getFontMetrics().getHeight());
+ }
+ gc.dispose();
+
+ return size;
+}
+public void setToolTipText (String string) {
+ super.setToolTipText (string);
+ appToolTipText = super.getToolTipText();
+}
+/**
+ * Return the Label's text.
+ */
+public String getText() {
+ return text;
+}
+public String getToolTipText () {
+ return appToolTipText;
+}
+/**
+ * Paint the Label's border.
+ */
+private void paintBorder(GC gc, Rectangle r) {
+ Display disp= getDisplay();
+
+ Color c1 = null;
+ Color c2 = null;
+
+ int style = getStyle();
+ if ((style & SWT.SHADOW_IN) != 0) {
+ c1 = disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ c2 = disp.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
+ }
+ if ((style & SWT.SHADOW_OUT) != 0) {
+ c1 = disp.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
+ c2 = disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ }
+
+ if (c1 != null && c2 != null) {
+ gc.setLineWidth(1);
+ drawBevelRect(gc, r.x, r.y, r.width-1, r.height-1, c1, c2);
+ }
+}
+private void onDispose(DisposeEvent event) {
+ gradientColors = null;
+ gradientPercents = null;
+ backgroundImage = null;
+}
+/*
+ * Process the paint event
+ */
+private void onPaint(PaintEvent event) {
+ Rectangle rect = getClientArea();
+ if (rect.width == 0 || rect.height == 0) return;
+
+ boolean shortenText = false;
+ String t = text;
+ Image img = image;
+ int availableWidth = rect.width - 2*hIndent;
+ Point extent = getTotalSize(img, t);
+ if (extent.x > availableWidth) {
+ img = null;
+ extent = getTotalSize(img, t);
+ if (extent.x > availableWidth) {
+ shortenText = true;
+ }
+ }
+
+ GC gc = event.gc;
+
+ // shorten the text
+ if (shortenText) {
+ t = shortenText(gc, text, availableWidth);
+ extent = getTotalSize(img, t);
+ if (appToolTipText == null) {
+ super.setToolTipText(text);
+ }
+ } else {
+ super.setToolTipText(appToolTipText);
+ }
+
+ // determine horizontal position
+ int x = rect.x + hIndent;
+ if (align == SWT.CENTER) {
+ x = (rect.width-extent.x)/2;
+ }
+ if (align == SWT.RIGHT) {
+ x = rect.width-extent.x - hIndent;
+ }
+
+ // draw a background image behind the text
+ try {
+ if (backgroundImage != null) {
+ // draw a background image behind the text
+ Rectangle imageRect = backgroundImage.getBounds();
+ gc.drawImage(backgroundImage, 0, 0, imageRect.width, imageRect.height,
+ 0, 0, rect.width, rect.height);
+ } else if (gradientColors != null) {
+ // draw a gradient behind the text
+ final Color oldBackground = gc.getBackground();
+ if (gradientColors.length == 1) {
+ if (gradientColors[0] != null) gc.setBackground(gradientColors[0]);
+ gc.fillRectangle(0, 0, rect.width, rect.height);
+ } else {
+ final Color oldForeground = gc.getForeground();
+ Color lastColor = gradientColors[0];
+ if (lastColor == null) lastColor = oldBackground;
+ for (int i = 0, pos = 0; i < gradientPercents.length; ++i) {
+ gc.setForeground(lastColor);
+ lastColor = gradientColors[i + 1];
+ if (lastColor == null) lastColor = oldBackground;
+ gc.setBackground(lastColor);
+ final int gradientWidth = (gradientPercents[i] * rect.width / 100) - pos;
+ gc.fillGradientRectangle(pos, 0, gradientWidth, rect.height, false);
+ pos += gradientWidth;
+ }
+ gc.setForeground(oldForeground);
+ }
+ gc.setBackground(oldBackground);
+ } else {
+ gc.setBackground(getBackground());
+ gc.fillRectangle(rect);
+ }
+ } catch (SWTException e) {
+ gc.setBackground(getBackground());
+ gc.fillRectangle(rect);
+ }
+
+ // draw border
+ int style = getStyle();
+ if ((style & SWT.SHADOW_IN) != 0 || (style & SWT.SHADOW_OUT) != 0) {
+ paintBorder(gc, rect);
+ }
+ // draw the image
+ if (img != null) {
+ Rectangle imageRect = img.getBounds();
+ gc.drawImage(img, 0, 0, imageRect.width, imageRect.height,
+ x, (rect.height-imageRect.height)/2, imageRect.width, imageRect.height);
+ x += imageRect.width + GAP;
+ }
+ // draw the text
+ if (t != null) {
+ int textHeight = gc.getFontMetrics().getHeight();
+ gc.setForeground(getForeground());
+ gc.drawText(t, x, rect.y + (rect.height-textHeight)/2, true);
+ }
+}
+/**
+ * Set the alignment of the CLabel.
+ * Use the values LEFT, CENTER and RIGHT to align image and text within the available space.
+ */
+public void setAlignment(int align) {
+ if (align != SWT.LEFT && align != SWT.RIGHT && align != SWT.CENTER) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (this.align != align) {
+ this.align = align;
+ redraw();
+ }
+}
+/**
+ * Specify a gradiant of colours to be draw in the background of the CLabel.
+ * For example to draw a gradiant that varies from dark blue to blue and then to
+ * white, use the following call to setBackground:
+ * <pre>
+ * clabel.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE),
+ * display.getSystemColor(SWT.COLOR_BLUE),
+ * display.getSystemColor(SWT.COLOR_WHITE),
+ * display.getSystemColor(SWT.COLOR_WHITE)},
+ * new int[] {25, 50, 100});
+ * </pre>
+ *
+ * @param colors an array of Color that specifies the colors to appear in the gradiant
+ * in order of appearance left to right. The value <code>null</code> clears the
+ * background gradiant. The value <code>null</code> can be used inside the array of
+ * Color to specify the background color.
+ * @param percents an array of integers between 0 and 100 specifying the percent of the width
+ * of the widget at which the color should change. The size of the percents array must be one
+ * less than the size of the colors array.
+ */
+public void setBackground(Color[] colors, int[] percents) {
+ if (colors != null) {
+ if (percents == null || percents.length != colors.length - 1) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (getDisplay().getDepth() < 15) {
+ // Don't use gradients on low color displays
+ colors = new Color[] { colors[0] };
+ percents = new int[] { };
+ }
+ for (int i = 0; i < percents.length; i++) {
+ if (percents[i] < 0 || percents[i] > 100) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (i > 0 && percents[i] < percents[i-1]) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ }
+ }
+
+ // Are these settings the same as before?
+ final Color background = getBackground();
+ if (backgroundImage == null) {
+ if ((gradientColors != null) && (colors != null) &&
+ (gradientColors.length == colors.length)) {
+ boolean same = false;
+ for (int i = 0; i < gradientColors.length; i++) {
+ same = (gradientColors[i] == colors[i]) ||
+ ((gradientColors[i] == null) && (colors[i] == background)) ||
+ ((gradientColors[i] == background) && (colors[i] == null));
+ if (!same) break;
+ }
+ if (same) {
+ for (int i = 0; i < gradientPercents.length; i++) {
+ same = gradientPercents[i] == percents[i];
+ if (!same) break;
+ }
+ }
+ if (same) return;
+ }
+ } else {
+ backgroundImage = null;
+ }
+ // Store the new settings
+ if (colors == null) {
+ gradientColors = null;
+ gradientPercents = null;
+ } else {
+ gradientColors = new Color[colors.length];
+ for (int i = 0; i < colors.length; ++i)
+ gradientColors[i] = (colors[i] != null) ? colors[i] : background;
+ gradientPercents = new int[percents.length];
+ for (int i = 0; i < percents.length; ++i)
+ gradientPercents[i] = percents[i];
+ }
+ // Refresh with the new settings
+ redraw();
+}
+public void setBackground(Image image) {
+ if (image == backgroundImage) return;
+ gradientColors = null;
+ gradientPercents = null;
+ backgroundImage = image;
+ redraw();
+
+}
+public void setFont(Font font) {
+ super.setFont(font);
+ redraw();
+}
+/**
+ * Set the label's Image.
+ * The value <code>null</code> clears it.
+ */
+public void setImage(Image image) {
+ if (image != this.image) {
+ this.image = image;
+ redraw();
+ }
+}
+/**
+ * Set the label's text.
+ * The value <code>null</code> clears it.
+ */
+public void setText(String text) {
+ if (text == null) text = "";
+ if (! text.equals(this.text)) {
+ this.text = text;
+ redraw();
+ }
+}
+/**
+ * Shorten the given text <code>t</code> so that its length doesn't exceed
+ * the given width. The default implementation replaces characters in the
+ * center of the original string with an ellipsis ("...").
+ * Override if you need a different strategy.
+ */
+protected String shortenText(GC gc, String t, int width) {
+ if (t == null) return null;
+ int w = gc.textExtent(ellipsis).x;
+ int l = t.length();
+ int pivot = l/2;
+ int s = pivot;
+ int e = pivot+1;
+ while (s >= 0 && e < l) {
+ String s1 = t.substring(0, s);
+ String s2 = t.substring(e, l);
+ int l1 = gc.textExtent(s1).x;
+ int l2 = gc.textExtent(s2).x;
+ if (l1+w+l2 < width) {
+ t = s1 + ellipsis + s2;
+ break;
+ }
+ s--;
+ e++;
+ }
+ return t;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolder.java
new file mode 100644
index 0000000000..e99057514b
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolder.java
@@ -0,0 +1,1517 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+
+/**
+ * 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>CTabItem</code>.
+ * <code>Control</code> children are created and then set into a
+ * tab item using <code>CTabItem#setControl</code>.
+ * </p><p>
+ * Note that although this class is a subclass of <code>Composite</code>,
+ * it does not make sense to set a layout on it.
+ * </p><p>
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>TOP, BOTTOM, FLAT</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>Selection</dd>
+ * <dd>"CTabFolder"</dd>
+ * </dl>
+ * <p>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ * </p>
+ */
+
+public class CTabFolder extends Composite {
+
+ /**
+ * marginWidth specifies the number of pixels of horizontal margin
+ * that will be placed along the left and right edges of the form.
+ *
+ * The default value is 0.
+ */
+ public int marginWidth = 0;
+ /**
+ * marginHeight specifies the number of pixels of vertical margin
+ * that will be placed along the top and bottom edges of the form.
+ *
+ * The default value is 0.
+ */
+ public int marginHeight = 0;
+
+ /**
+ * Color of innermost line of drop shadow border.
+ */
+ public static RGB borderInsideRGB = new RGB (132, 130, 132);
+ /**
+ * Color of middle line of drop shadow border.
+ */
+ public static RGB borderMiddleRGB = new RGB (143, 141, 138);
+ /**
+ * Color of outermost line of drop shadow border.
+ */
+ public static RGB borderOutsideRGB = new RGB (171, 168, 165);
+
+ /*
+ * A multiple of the tab height that specifies the minimum width to which a tab
+ * will be compressed before scrolling arrows are used to navigate the tabs.
+ */
+ public static int MIN_TAB_WIDTH = 3;
+
+ /* sizing, positioning */
+ int xClient, yClient;
+ boolean onBottom = false;
+ int fixedTabHeight = -1;
+ int imageHeight = -1;
+
+ /* item management */
+ private CTabItem items[] = new CTabItem[0];
+ private int selectedIndex = -1;
+ int topTabIndex = -1; // index of the left most visible tab.
+
+ /* External Listener management */
+ private CTabFolderListener[] tabListeners = new CTabFolderListener[0];
+
+ /* Color appearance */
+ Image backgroundImage;
+ Color[] gradientColors;
+ int[] gradientPercents;
+ Color selectionForeground;
+
+ // internal constants
+ private static final int DEFAULT_WIDTH = 64;
+ private static final int DEFAULT_HEIGHT = 64;
+
+ // scrolling arrows
+ private ToolBar scrollBar;
+ private ToolItem scrollLeft;
+ private ToolItem scrollRight;
+ private Image arrowLeftImage;
+ private Image arrowRightImage;
+ private Image arrowLeftDisabledImage;
+ private Image arrowRightDisabledImage;
+
+ // close button
+ boolean showClose = false;
+ private Image closeImage;
+ ToolBar closeBar;
+ private ToolItem closeItem;
+ private ToolBar inactiveCloseBar;
+ private ToolItem inactiveCloseItem;
+ private CTabItem inactiveItem;
+
+ private boolean shortenedTabs = false;
+
+ // borders
+ boolean showBorders = false;
+ private int BORDER_BOTTOM = 0;
+ private int BORDER_LEFT = 0;
+ private int BORDER_RIGHT = 0;
+ private int BORDER_TOP = 0;
+ private Color borderColor1;
+ private Color borderColor2;
+ private Color borderColor3;
+
+ // when disposing CTabFolder, don't try to layout the items or
+ // change the selection as each child is destroyed.
+ private boolean inDispose = false;
+
+ // keep track of size changes in order to redraw only affected area
+ // on Resize
+ private Rectangle oldArea;
+
+ // insertion marker
+ int insertionIndex = -2; // Index of insert marker. Marker always shown after index.
+ // -2 means no insert marker
+
+ // tool tip
+ private Shell tip;
+
+ private boolean inDoubleClick = false;
+
+/**
+ * Construct a CTabFolder with the specified parent and style.
+ * @param parent org.eclipse.swt.widgets.Composite
+ * @param swtStyle int
+ */
+public CTabFolder(Composite parent, int style) {
+ super(parent, checkStyle (style));
+
+ onBottom = (getStyle() & SWT.BOTTOM) != 0;
+
+ borderColor1 = new Color(getDisplay(), borderInsideRGB);
+ borderColor2 = new Color(getDisplay(), borderMiddleRGB);
+ borderColor3 = new Color(getDisplay(), borderOutsideRGB);
+ Color background = getBackground();
+
+ // create scrolling arrow buttons
+ scrollBar = new ToolBar(this, SWT.FLAT);
+ scrollBar.setVisible(false);
+ scrollBar.setBackground(background);
+ scrollLeft = new ToolItem(scrollBar, SWT.PUSH);
+ scrollLeft.setEnabled(false);
+ scrollRight = new ToolItem(scrollBar, SWT.PUSH);
+ scrollRight.setEnabled(false);
+
+ // create close buttons
+ closeBar = new ToolBar(this, SWT.FLAT);
+ closeBar.setVisible(false);
+ closeBar.setBackground(background);
+ closeItem = new ToolItem(closeBar, SWT.PUSH);
+
+ inactiveCloseBar = new ToolBar(this, SWT.FLAT);
+ inactiveCloseBar.setVisible(false);
+ inactiveCloseBar.setBackground(background);
+ inactiveCloseItem = new ToolItem(inactiveCloseBar, SWT.PUSH);
+
+ Listener listener = new Listener() {
+ public void handleEvent(Event event) {
+ handleEvents(event);
+ }
+ };
+ addListener(SWT.Dispose, listener);
+ addListener(SWT.MouseUp, listener);
+ addListener(SWT.MouseDoubleClick, listener);
+ addListener(SWT.MouseMove, listener);
+ addListener(SWT.MouseExit, listener);
+ addListener(SWT.Paint, listener);
+ addListener(SWT.Resize, listener);
+ scrollLeft.addListener(SWT.Selection, listener);
+ scrollRight.addListener(SWT.Selection, listener);
+ closeItem.addListener(SWT.Selection, listener);
+ inactiveCloseItem.addListener(SWT.Selection, listener);
+ inactiveCloseBar.addListener (SWT.MouseExit, listener);
+
+ setBorderVisible((style & SWT.BORDER) != 0);
+
+ // tool tip support
+ Display display = getDisplay();
+ tip = new Shell (getShell(), SWT.ON_TOP);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = layout.marginHeight = 1;
+ tip.setLayout(layout);
+ Label label = new Label (tip, SWT.NONE);
+ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ label.setForeground (display.getSystemColor (SWT.COLOR_INFO_FOREGROUND));
+ label.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
+ tip.setBackground(label.getBackground());
+
+ addMouseTrackListener (new MouseTrackAdapter () {
+ public void mouseExit(MouseEvent e) {
+ if (tip.isDisposed()) return;
+ if (tip.isVisible()) tip.setVisible(false);
+ }
+ public void mouseHover(MouseEvent e) {
+ if (tip.isDisposed()) return;
+ Point pt = new Point (e.x, e.y);
+ CTabItem item = getItem(pt);
+ if (item != null) {
+ String tooltip = item.getToolTipText();
+ if (tooltip != null) {
+
+ Label label = (Label) (tip.getChildren() [0]);
+ label.setText(tooltip);
+ tip.pack();
+
+ pt.y += 16;
+ pt = toDisplay(pt);
+ /*
+ * Ensure that the tooltip is on the screen.
+ */
+ Display display = tip.getDisplay();
+ Rectangle rect = display.getBounds();
+ Point size = tip.getSize();
+ pt.x = Math.max (0, Math.min (pt.x, rect.width - size.x));
+ pt.y = Math.max (0, Math.min (pt.y, rect.height - size.y));
+ tip.setLocation(pt);
+
+ tip.setVisible(true);
+ return;
+ }
+ }
+
+ tip.setVisible(false);
+ }
+ });
+
+}
+private static int checkStyle (int style) {
+ int mask = SWT.TOP | SWT.BOTTOM | SWT.FLAT;
+ style = style & mask;
+ // TOP and BOTTOM are mutually exlusive.
+ // TOP is the default
+ if ((style & SWT.TOP) != 0)
+ style = style & ~(SWT.TOP | SWT.BOTTOM) | SWT.TOP;
+ // reduce the flash by not redrawing the entire area on a Resize event
+ style |= SWT.NO_REDRAW_RESIZE;
+ return style;
+}
+/**
+* Adds the listener to receive events.
+* <p>
+*
+* @param listener the listener
+*
+* @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 listener is null</li>
+* </ul>
+*/
+public void addSelectionListener(SelectionListener listener) {
+ if (listener == null) {
+ SWT.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 a tab item is closed.
+ *
+ * @param listener the listener which should be notified
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * </ul>
+ *
+ * @see CTabFolderListener
+ * @see #removeCTabFolderListener
+ */
+public void addCTabFolderListener(CTabFolderListener listener) {
+ if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ // add to array
+ CTabFolderListener[] newTabListeners = new CTabFolderListener[tabListeners.length + 1];
+ System.arraycopy(tabListeners, 0, newTabListeners, 0, tabListeners.length);
+ tabListeners = newTabListeners;
+ tabListeners[tabListeners.length - 1] = listener;
+ showClose = true;
+ initCloseButtonImages();
+}
+private void closeNotify(CTabItem item, int time) {
+ if (item == null) return;
+
+ CTabFolderEvent event = new CTabFolderEvent(this);
+ event.widget = this;
+ event.time = time;
+ event.item = item;
+ event.doit = true;
+ if (tabListeners != null) {
+ for (int i = 0; i < tabListeners.length; i++) {
+ tabListeners[i].itemClosed(event);
+ }
+ }
+ if (event.doit) {
+ item.dispose();
+ }
+}
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ int minWidth = 0;
+ int minHeight = 0;
+
+ // tab width
+ if (items.length > 0) {
+ CTabItem lastItem = items[items.length-1];
+ minWidth = lastItem.x + lastItem.width;
+ }
+
+ // get max preferred size of items
+ for (int i = 0; i < items.length; i++) {
+ Control control = items[i].getControl();
+ if (control != null && !control.isDisposed()){
+ Point size = control.computeSize (wHint, hHint);
+ minWidth = Math.max (minWidth, size.x);
+ minHeight = Math.max (minHeight, size.y);
+ }
+ }
+ if (minWidth == 0) minWidth = DEFAULT_WIDTH;
+ if (minHeight == 0) minHeight = DEFAULT_HEIGHT;
+
+ if (wHint != SWT.DEFAULT) minWidth = wHint;
+ if (hHint != SWT.DEFAULT) minHeight = hHint;
+
+ Rectangle trim = computeTrim(0, 0, minWidth, minHeight);
+ return new Point (trim.width, trim.height);
+}
+public Rectangle computeTrim (int x, int y, int width, int height) {
+ int tabHeight = getTabHeight();
+ int trimX = x - marginWidth - BORDER_LEFT;
+ int trimY = y - marginHeight - tabHeight - BORDER_TOP;
+ if (onBottom) {
+ trimY = y - marginHeight - BORDER_TOP;
+ }
+ int trimWidth = width + BORDER_LEFT + BORDER_RIGHT + 2*marginWidth;
+ int trimHeight = height + BORDER_TOP + BORDER_BOTTOM + 2*marginHeight + tabHeight;
+ return new Rectangle (trimX, trimY, trimWidth, trimHeight);
+}
+/**
+ * Create the specified item at 'index'.
+ */
+void createItem (CTabItem item, int index) {
+ if (0 > index || index > getItemCount ()){
+ SWT.error (SWT.ERROR_INVALID_RANGE);
+ }
+ // grow by one and rearrange the array.
+ CTabItem[] newItems = new CTabItem [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;
+
+ item.parent = this;
+
+ if (selectedIndex >= index) {
+ selectedIndex ++;
+ }
+ if (items.length == 1) {
+ topTabIndex = 0;
+ }
+
+ layoutItems();
+ ensureVisible();
+
+ if (items.length == 1) {
+ redraw();
+ } else {
+ redrawTabArea(-1);
+ }
+}
+/**
+ * Destroy the specified item.
+ */
+void destroyItem (CTabItem item) {
+ if (inDispose) return;
+
+ int index = indexOf(item);
+ if (index == -1) return; // should this trigger an error?
+
+ insertionIndex = -2;
+
+ if (items.length == 1) {
+ items = new CTabItem[0];
+ selectedIndex = -1;
+ topTabIndex = 0;
+
+ Control control = item.getControl();
+ if (control != null && !control.isDisposed()) {
+ control.setVisible(false);
+ }
+ closeBar.setVisible(false);
+ redraw();
+ return;
+ }
+
+ // shrink by one and rearrange the array.
+ CTabItem[] newItems = new CTabItem [items.length - 1];
+ System.arraycopy(items, 0, newItems, 0, index);
+ System.arraycopy(items, index + 1, newItems, index, items.length - index - 1);
+ items = newItems;
+
+ if (topTabIndex == items.length) {
+ --topTabIndex;
+ }
+
+ // move the selection if this item is selected
+ if (selectedIndex == index) {
+ Control control = item.getControl();
+ if (control != null && !control.isDisposed()) {
+ control.setVisible(false);
+ }
+ selectedIndex = -1;
+ setSelectionNotify(Math.max(0, index - 1));
+ } else if (selectedIndex > index) {
+ selectedIndex --;
+ }
+
+ layoutItems();
+ ensureVisible();
+ redrawTabArea(-1);
+}
+/**
+ * Dispose the items of the receiver
+ */
+private void onDispose() {
+ inDispose = true;
+
+ // items array is resized during CTabItem.dispose
+ // it is set to null if the last item is removed
+ int length = items.length;
+ for (int i = 0; i < length; i++) {
+ if (items[i] != null) {
+ items[i].dispose();
+ }
+ }
+
+ // clean up resources
+ if (tip != null && !tip.isDisposed()) {
+ tip.dispose();
+ tip = null;
+ }
+
+ gradientColors = null;
+ gradientPercents = null;
+ backgroundImage = null;
+
+ if (arrowLeftImage != null){
+ arrowLeftImage.dispose();
+ arrowLeftImage = null;
+ }
+
+ if (arrowRightImage != null){
+ arrowRightImage.dispose();
+ arrowRightImage = null;
+ }
+
+ if (arrowLeftDisabledImage != null) {
+ arrowLeftDisabledImage.dispose();
+ arrowLeftDisabledImage = null;
+ }
+
+ if (arrowRightDisabledImage != null) {
+ arrowRightDisabledImage.dispose();
+ arrowRightDisabledImage = null;
+ }
+
+ if (closeImage != null) {
+ closeImage.dispose();
+ closeImage = null;
+ }
+
+ if (borderColor1 != null) {
+ borderColor1.dispose();
+ borderColor1 = null;
+ }
+
+ if (borderColor2 != null) {
+ borderColor2.dispose();
+ borderColor2 = null;
+ }
+
+ if (borderColor3 != null) {
+ borderColor3.dispose();
+ borderColor3 = null;
+ }
+}
+/**
+ * Draw a border around the receiver.
+ */
+private void drawBorder(GC gc) {
+
+ Rectangle d = super.getClientArea();
+
+ if (showBorders) {
+ if ((getStyle() & SWT.FLAT) != 0) {
+ gc.setForeground(borderColor1);
+ gc.drawRectangle(d.x, d.y, d.x + d.width - 1, d.y + d.height - 1);
+ } else {
+ gc.setForeground(borderColor1);
+ gc.drawRectangle(d.x, d.y, d.x + d.width - 3, d.y + d.height - 3);
+
+ gc.setForeground(borderColor2);
+ gc.drawLine(d.x + 1, d.y + d.height - 2, d.x + d.width - 1, d.y + d.height - 2);
+ gc.drawLine(d.x + d.width - 2, d.y + 1, d.x + d.width - 2, d.y + d.height - 1);
+
+ gc.setForeground(borderColor3);
+ gc.drawLine(d.x + 2, d.y + d.height - 1, d.x + d.width - 2, d.y + d.height - 1);
+ gc.drawLine(d.x + d.width - 1, d.y + 2, d.x + d.width - 1, d.y + d.height - 2);
+
+ // fill in corners with parent's background
+ gc.setForeground(getParent().getBackground());
+ gc.drawLine(d.x + d.width - 2, d.y, d.x + d.width - 1, d.y);
+ gc.drawLine(d.x + d.width - 1, d.y + 1, d.x + d.width - 1, d.y + 1);
+
+ gc.drawLine(d.x, d.y + d.height - 2, d.x, d.y + d.height - 2);
+ gc.drawLine(d.x, d.y + d.height - 1, d.x + 1, d.y + d.height - 1);
+
+ gc.drawLine(d.x + d.width - 1, d.y + d.height - 1, d.x + d.width - 1, d.y + d.height - 1);
+ }
+
+ }
+
+ // draw a separator line
+ if (items.length > 0) {
+ int tabHeight = getTabHeight();
+ int lineY = d.y + BORDER_TOP + tabHeight;
+ if (onBottom) {
+ lineY = d.y + d.height - BORDER_BOTTOM - tabHeight - 1;
+ }
+ gc.setForeground(borderColor1);
+ gc.drawLine(d.x + BORDER_LEFT, lineY, d.x + d.width - BORDER_RIGHT, lineY);
+ }
+
+ gc.setForeground(getForeground());
+}
+public Rectangle getClientArea() {
+ Rectangle clientArea = super.getClientArea();
+ clientArea.x = xClient;
+ clientArea.y = yClient;
+ clientArea.width -= 2*marginWidth + BORDER_LEFT + BORDER_RIGHT;
+ clientArea.height -= 2*marginHeight + BORDER_TOP + BORDER_BOTTOM + getTabHeight() + 1;
+ return clientArea;
+}
+/**
+ * Return the height of item images. All images are scaled to
+ * the height of the first image.
+ */
+int getImageHeight() {
+ return imageHeight;
+}
+public int getTabHeight(){
+ if (fixedTabHeight > 0) return fixedTabHeight;
+
+ if (isDisposed()) return 0;
+
+ int tempHeight = 0;
+ GC gc = new GC(this);
+ for (int i=0; i < items.length; i++) {
+ int height = items[i].preferredHeight(gc);
+ tempHeight = Math.max(tempHeight, height);
+ }
+ gc.dispose();
+ return tempHeight;
+}
+/**
+ * Return the tab that is located at the specified index.
+ */
+public CTabItem getItem (int index) {
+ if (index < 0 || index > items.length)
+ SWT.error(SWT.ERROR_INVALID_RANGE);
+ return items [index];
+}
+/**
+* Gets the item at a point in the widget.
+* <p>
+*
+* @return the item at a point
+*
+* @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_CANNOT_GET_COUNT when the operation fails</li>
+* </ul>
+*/
+public CTabItem getItem (Point pt) {
+ for (int i = 0; i < items.length; i++) {
+ Rectangle bounds = items[i].getBounds();
+ if (bounds.contains(pt)) return items[i];
+ }
+ return null;
+}
+/**
+ * Return the number of tabs in the folder.
+ */
+public int getItemCount(){
+ return items.length;
+}
+/**
+ * Return the tab items.
+ */
+public CTabItem [] getItems() {
+ CTabItem[] tabItems = new CTabItem [items.length];
+ System.arraycopy(items, 0, tabItems, 0, items.length);
+ return tabItems;
+}
+/**
+ * Return the selected tab item, or an empty array if there
+ * is no selection.
+ */
+public CTabItem getSelection() {
+ if (selectedIndex == -1) return null;
+ return items[selectedIndex];
+}
+/**
+ * Return the index of the selected tab item, or -1 if there
+ * is no selection.
+ */
+public int getSelectionIndex() {
+ return selectedIndex;
+}
+
+private void handleEvents (Event event){
+ switch (event.type) {
+ case SWT.Dispose:
+ onDispose();
+ break;
+ case SWT.Paint:
+ onPaint(event);
+ break;
+ case SWT.Resize:
+ onResize();
+ break;
+ case SWT.MouseDoubleClick:
+ inDoubleClick = true;
+ break;
+ case SWT.MouseUp:
+ onMouseUp(event);
+ break;
+ case SWT.MouseExit:
+ if (event.widget == this) {
+ Rectangle inactiveBounds = inactiveCloseBar.getBounds();
+ if (inactiveBounds.contains(event.x, event.y)) return;
+ inactiveCloseBar.setVisible(false);
+ inactiveItem = null;
+ }
+ if (event.widget == inactiveCloseBar) {
+ if (inactiveItem != null) {
+ Rectangle itemBounds = inactiveItem.getBounds();
+ if (itemBounds.contains(event.x, event.y)) return;
+ }
+ inactiveCloseBar.setVisible(false);
+ inactiveItem = null;
+ }
+ break;
+ case SWT.MouseMove:
+ onMouseMove(event);
+ break;
+ case SWT.Selection:
+ if (event.widget == scrollLeft) {
+ scroll_scrollLeft();
+ }
+ if (event.widget == scrollRight) {
+ scroll_scrollRight();
+ }
+ if (event.widget == closeItem) {
+ closeNotify(getSelection(), event.time);
+ }
+ if (event.widget == inactiveCloseItem) {
+ closeNotify(inactiveItem, event.time);
+ inactiveCloseBar.setVisible(false);
+ inactiveItem = null;
+ }
+ break;
+ default:
+ break;
+ }
+}
+/**
+ * Return the index of the specified tab or -1 if the tab is not
+ * in the receiver.
+ */
+public int indexOf(CTabItem item) {
+ if (item == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] == item) return i;
+ }
+ return -1;
+}
+/**
+ * 'item' has changed. Store the image size if this is the
+ * first item with an image.
+ */
+void itemChanged(CTabItem item) {
+ Image itemImage = item.getImage();
+ if (imageHeight == -1 && itemImage != null) {
+ imageHeight = itemImage.getBounds().height;
+ }
+
+ int height = getTabHeight();
+ Point size = scrollBar.computeSize(SWT.DEFAULT, height);
+ scrollBar.setSize(size);
+ height = (onBottom) ? height - 2 : height - 1;
+ size = closeBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ closeBar.setSize(size);
+ inactiveCloseBar.setSize(size);
+
+ layoutItems();
+ redrawTabArea(-1);
+}
+private void layoutButtons() {
+
+ boolean leftVisible = scroll_leftVisible();
+ boolean rightVisible = scroll_rightVisible();
+
+ if (leftVisible || rightVisible) {
+ initScrollBarImages();
+ Point size = scrollBar.getSize();
+ Rectangle area = super.getClientArea();
+ int x = area.x + area.width - size.x - BORDER_RIGHT;
+ int y = 0;
+ if (!onBottom) {
+ y = area.y + BORDER_TOP;
+ } else {
+ y = area.y + area.height - BORDER_BOTTOM - size.y;
+ }
+ scrollBar.setLocation(x, y);
+ scrollLeft.setEnabled(leftVisible);
+ scrollRight.setEnabled(rightVisible);
+ scrollBar.setVisible(true);
+ } else {
+ scrollBar.setVisible(false);
+ }
+
+ // When the close button is right at the edge of the Tab folder, hide it because
+ // otherwise it may block off a part of the border on the right
+ if (showClose) {
+ Point size = closeBar.getSize();
+ CTabItem item = getSelection();
+ if (item == null) {
+ closeBar.setVisible(false);
+ } else {
+ int x = item.x + item.width - size.x - 2;
+ int y = item.y + 1 + (item.height - 2 - size.y) / 2; // +1 for white line across top of tab
+ closeBar.setLocation(x, y);
+ if (scrollBar.isVisible()) {
+ Rectangle scrollRect = scrollBar.getBounds();
+ scrollRect.width += BORDER_RIGHT;
+ closeBar.setVisible(!scrollRect.contains(x, y));
+ } else {
+ closeBar.setVisible(true);
+ }
+ }
+ }
+}
+/**
+ * Layout the items and store the client area size.
+ */
+private void layoutItems() {
+ if (isDisposed()) return;
+
+ Rectangle area = super.getClientArea();
+ int tabHeight = getTabHeight();
+
+ shortenedTabs = false;
+ if (items.length > 0) {
+ int[] widths = new int[items.length];
+ int totalWidth = 0;
+ GC gc = new GC(this);
+ for (int i = 0; i < items.length; i++) {
+ widths[i] = items[i].preferredWidth(gc);
+ totalWidth += widths[i];
+ }
+ gc.dispose();
+ if (totalWidth < (area.width - BORDER_LEFT - BORDER_RIGHT) ) {
+ topTabIndex = 0;
+ } else {
+
+ int oldAverageWidth = 0;
+ int averageWidth = (area.width - BORDER_LEFT - BORDER_RIGHT) / items.length;
+ while (averageWidth > oldAverageWidth) {
+ int width = area.width - BORDER_LEFT - BORDER_RIGHT;
+ int count = items.length;
+ for (int i = 0; i < items.length; i++) {
+ if (widths[i] < averageWidth) {
+ width -= widths[i];
+ count--;
+ }
+ }
+ oldAverageWidth = averageWidth;
+ if (count > 0) {
+ averageWidth = width / count;
+ }
+ }
+ if (averageWidth > MIN_TAB_WIDTH * tabHeight) {
+ for (int i = 0; i < items.length; i++) {
+ if (widths[i] > averageWidth) {
+ widths[i] = averageWidth;
+ }
+ }
+ topTabIndex = 0;
+ shortenedTabs = true;
+ }
+ }
+ int x = area.x;
+ int y = area.y + BORDER_TOP;
+ if (onBottom) {
+ y = Math.max(0, area.y + area.height - BORDER_BOTTOM - tabHeight);
+ }
+ for (int i = topTabIndex - 1; i>=0; i--) {
+ // if the first visible tab is not the first tab
+ CTabItem tab = items[i];
+ tab.width = widths[i];
+ tab.height = getTabHeight();
+ x -= tab.width;
+ // layout tab items from right to left thus making them invisible
+ tab.x = x;
+ tab.y = y;
+ }
+
+ x = area.x + BORDER_LEFT;
+ for (int i=topTabIndex; i<items.length; i++) {
+ // continue laying out remaining, visible items left to right
+ CTabItem tab = items[i];
+ tab.x = x;
+ tab.y = y;
+ tab.height = tabHeight;
+ tab.width = widths[i];
+ x = x + tab.width;
+ }
+ }
+
+ xClient = area.x + BORDER_LEFT + marginWidth;
+ if (onBottom) {
+ yClient = area.y + BORDER_TOP + marginHeight;
+ } else {
+ yClient = area.y + BORDER_TOP + tabHeight + 1 + marginHeight;
+ // +1 is for the line at the bottom of the tabs
+ }
+
+ // resize the scrollbar and close butotns
+ layoutButtons();
+}
+/**
+ * Paint the receiver.
+ */
+private void onPaint(Event event) {
+ GC gc = event.gc;
+ Rectangle rect = super.getClientArea();
+ if (items.length == 0) {
+
+ if (showBorders) {
+ gc.setForeground(borderColor1);
+ gc.drawRectangle(rect.x + BORDER_RIGHT,
+ rect.y + BORDER_BOTTOM,
+ rect.x + rect.width - BORDER_RIGHT - 1,
+ rect.y + rect.height - BORDER_BOTTOM - 1);
+ // fill in top and left edge with parent's background color
+ gc.setBackground(getParent().getBackground());
+ gc.fillRectangle(rect.x, rect.y, BORDER_RIGHT, rect.height);
+ gc.fillRectangle(rect.x, rect.y, rect.width, BORDER_BOTTOM);
+
+ }
+ if (fixedTabHeight > 0) {
+ int y = rect.y + BORDER_BOTTOM + fixedTabHeight;
+ if (onBottom) {
+ y = rect.y + rect.height - fixedTabHeight - 1;
+ }
+ gc.setForeground(borderColor1);
+ gc.drawLine(rect.x + BORDER_RIGHT, y, rect.x + rect.width, y);
+ }
+ gc.setForeground(getForeground());
+ gc.setBackground(getBackground());
+ return;
+ }
+
+ // redraw the Border
+ drawBorder(gc);
+
+ rect.x += BORDER_LEFT;
+ rect.y += BORDER_TOP;
+ rect.width -= BORDER_LEFT + BORDER_RIGHT;
+ rect.height -= BORDER_TOP + BORDER_BOTTOM;
+ gc.setClipping(rect);
+
+ // Draw the unselected tabs first.
+ for (int i=0; i < items.length; i++) {
+ if (i != selectedIndex && event.getBounds().intersects(items[i].getBounds())) {
+ items[i].onPaint(gc, false);
+ }
+ }
+ // Selected tab comes last
+ if (selectedIndex != -1) {
+ items[selectedIndex].onPaint(gc, true);
+ }
+
+ // draw insertion mark
+ if (insertionIndex > -2) {
+ gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
+ if (insertionIndex == -1) {
+ Rectangle bounds = items[0].getBounds();
+ gc.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height - 1);
+ gc.drawLine(bounds.x - 2, bounds.y, bounds.x + 2, bounds.y);
+ gc.drawLine(bounds.x - 1, bounds.y + 1, bounds.x + 1, bounds.y + 1);
+ gc.drawLine(bounds.x - 1, bounds.y + bounds.height - 2, bounds.x + 1, bounds.y + bounds.height - 2);
+ gc.drawLine(bounds.x - 2, bounds.y + bounds.height - 1, bounds.x + 2, bounds.y + bounds.height - 1);
+
+ } else {
+ Rectangle bounds = items[insertionIndex].getBounds();
+ gc.drawLine(bounds.x + bounds.width, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height - 1);
+ gc.drawLine(bounds.x + bounds.width - 2, bounds.y, bounds.x + bounds.width + 2, bounds.y);
+ gc.drawLine(bounds.x + bounds.width - 1, bounds.y + 1, bounds.x + bounds.width + 1, bounds.y + 1);
+ gc.drawLine(bounds.x + bounds.width - 1, bounds.y + bounds.height - 2, bounds.x + bounds.width + 1, bounds.y + bounds.height - 2);
+ gc.drawLine(bounds.x + bounds.width - 2, bounds.y + bounds.height - 1, bounds.x + bounds.width + 2, bounds.y + bounds.height - 1);
+ }
+ }
+
+ gc.setForeground(getForeground());
+ gc.setBackground(getBackground());
+}
+private void redrawTabArea(int index) {
+ int x = 0, y = 0, width = 0, height = 0;
+ if (index == -1) {
+ Rectangle area = super.getClientArea();
+ if (area.width == 0 || area.height == 0) return;
+ width = area.x + area.width - BORDER_LEFT - BORDER_RIGHT;
+ height = getTabHeight() + 1; // +1 causes top line between content and tabs to be redrawn
+ x = area.x + BORDER_LEFT;
+ y = area.y + BORDER_TOP;
+ if (onBottom) {
+ y = Math.max(0, area.y + area.height - BORDER_BOTTOM - height);
+ }
+ } else {
+ CTabItem item = items[index];
+ x = item.x;
+ y = item.y;
+ Rectangle area = super.getClientArea();
+ width = area.x + area.width - x;
+ height = item.height;
+ }
+ redraw(x, y, width, height, false);
+}
+
+/**
+ * Removes the listener.
+ *
+ * @param listener the listener
+ *
+ * @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 listener is null</li></ul>
+ */
+public void removeSelectionListener(SelectionListener listener) {
+ if (listener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ removeListener(SWT.Selection, listener);
+ removeListener(SWT.DefaultSelection, listener);
+}
+/**
+ * Removes the listener.
+ *
+ * @param listener the listener
+ *
+ * @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 listener is null</li></ul>
+ */
+public void removeCTabFolderListener(CTabFolderListener listener) {
+ if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ if (tabListeners.length == 0) return;
+ int index = -1;
+ for (int i = 0; i < tabListeners.length; i++) {
+ if (listener == tabListeners[i]){
+ index = i;
+ break;
+ }
+ }
+ if (index == -1) return;
+ if (tabListeners.length == 1) {
+ tabListeners = new CTabFolderListener[0];
+ showClose = false;
+ return;
+ }
+ CTabFolderListener[] newTabListeners = new CTabFolderListener[tabListeners.length - 1];
+ System.arraycopy(tabListeners, 0, newTabListeners, 0, index);
+ System.arraycopy(tabListeners, index + 1, newTabListeners, index, tabListeners.length - index - 1);
+ tabListeners = newTabListeners;
+}
+
+/**
+ * The widget was resized. Adjust the size of the currently selected page.
+ */
+private void onResize() {
+
+ if (items.length == 0) {
+ redraw();
+ return;
+ }
+
+ Rectangle area = super.getClientArea();
+ if (oldArea == null || oldArea.width == 0 || oldArea.height == 0) {
+ layoutItems();
+ redraw();
+ } else {
+ if (onBottom && oldArea.height != area.height){
+ // move tabs up or down if tabs on bottom
+ layoutItems();
+ redraw();
+ } else {
+ int width = 0;
+ if (oldArea.width < area.width) {
+ width = area.width - oldArea.width + BORDER_RIGHT;
+ } else if (oldArea.width > area.width) {
+ width = BORDER_RIGHT;
+ }
+ redraw(area.x + area.width - width, area.y, width, area.height, false);
+
+ int height = 0;
+ if (oldArea.height < area.height) {
+ height = area.height - oldArea.height + BORDER_BOTTOM;
+ }
+ if (oldArea.height > area.height) {
+ height = BORDER_BOTTOM;
+ }
+ redraw(area.x, area.y + area.height - height, area.width, height, false);
+
+ if (oldArea.width != area.width) {
+ // resize the widths so that all tabs are visible
+ layoutItems();
+ redrawTabArea(-1);
+ }
+ }
+ }
+ oldArea = area;
+
+ // resize content
+ if (selectedIndex != -1) {
+ Control control = items[selectedIndex].getControl();
+ if (control != null && !control.isDisposed()) {
+ control.setBounds(getClientArea());
+ }
+ }
+}
+public void setBackground (Color color) {
+ super.setBackground(color);
+ color = getBackground();
+ Color foreground = getForeground();
+
+ // init inactive close button
+ inactiveCloseBar.setBackground(color);
+
+ // init scroll buttons
+ scrollBar.setBackground(color);
+
+ // init close button
+ if (gradientColors == null) {
+ closeBar.setBackground(color);
+ }
+}
+/**
+ * Specify a gradiant of colours to be draw in the background of the selected tab.
+ * For example to draw a gradiant that varies from dark blue to blue and then to
+ * white, use the following call to setBackground:
+ * <pre>
+ * cfolder.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE),
+ * display.getSystemColor(SWT.COLOR_BLUE),
+ * display.getSystemColor(SWT.COLOR_WHITE),
+ * display.getSystemColor(SWT.COLOR_WHITE)},
+ * new int[] {25, 50, 100});
+ * </pre>
+ *
+ * @param colors an array of Color that specifies the colors to appear in the gradiant
+ * in order of appearance left to right. The value <code>null</code> clears the
+ * background gradiant. The value <code>null</code> can be used inside the array of
+ * Color to specify the background color.
+ * @param percents an array of integers between 0 and 100 specifying the percent of the width
+ * of the widget at which the color should change. The size of the percents array must be one
+ * less than the size of the colors array.
+ */
+
+public void setSelectionBackground(Color[] colors, int[] percents) {
+ if (colors != null) {
+ if (percents == null || percents.length != colors.length - 1) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (getDisplay().getDepth() < 15) {
+ // Don't use gradients on low color displays
+ colors = new Color[] { colors[0] };
+ percents = new int[] { };
+ }
+ for (int i = 0; i < percents.length; i++) {
+ if (percents[i] < 0 || percents[i] > 100) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (i > 0 && percents[i] < percents[i-1]) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ }
+ }
+
+ // Are these settings the same as before?
+ final Color background = getBackground();
+ if (backgroundImage == null) {
+ if ((gradientColors != null) && (colors != null) &&
+ (gradientColors.length == colors.length)) {
+ boolean same = false;
+ for (int i = 0; i < gradientColors.length; i++) {
+ same = (gradientColors[i] == colors[i]) ||
+ ((gradientColors[i] == null) && (colors[i] == background)) ||
+ ((gradientColors[i] == background) && (colors[i] == null));
+ if (!same) break;
+ }
+ if (same) {
+ for (int i = 0; i < gradientPercents.length; i++) {
+ same = gradientPercents[i] == percents[i];
+ if (!same) break;
+ }
+ }
+ if (same) return;
+ }
+ } else {
+ backgroundImage = null;
+ }
+ // Store the new settings
+ if (colors == null) {
+ gradientColors = null;
+ gradientPercents = null;
+ closeBar.setBackground(background);
+ } else {
+ gradientColors = new Color[colors.length];
+ for (int i = 0; i < colors.length; ++i)
+ gradientColors[i] = (colors[i] != null) ? colors[i] : background;
+ gradientPercents = new int[percents.length];
+ for (int i = 0; i < percents.length; ++i)
+ gradientPercents[i] = percents[i];
+ if (getDisplay().getDepth() < 15) closeBar.setBackground(background);
+ else closeBar.setBackground(gradientColors[gradientColors.length - 1]);
+ }
+
+ // Refresh with the new settings
+ if (selectedIndex > -1) redrawTabArea(selectedIndex);
+}
+public void setSelectionBackground(Image image) {
+ if (image == backgroundImage) return;
+ gradientColors = null;
+ gradientPercents = null;
+ backgroundImage = image;
+ redrawTabArea(selectedIndex);
+}
+public void setBorderVisible(boolean show) {
+ if (showBorders == show) return;
+
+ showBorders = show;
+ if (showBorders) {
+ if ((getStyle() & SWT.FLAT) != 0) {
+ BORDER_BOTTOM = BORDER_TOP = BORDER_LEFT = BORDER_RIGHT = 1;
+ } else {
+ BORDER_LEFT = BORDER_TOP = 1;
+ BORDER_RIGHT = BORDER_BOTTOM = 3;
+ }
+ } else {
+ BORDER_BOTTOM = BORDER_TOP = BORDER_LEFT = BORDER_RIGHT = 0;
+ }
+ layoutItems();
+ redraw();
+}
+public void setFont(Font font) {
+ if (font != null && font.equals(getFont())) return;
+ super.setFont(font);
+ layoutItems();
+ redrawTabArea(-1);
+}
+public void setSelectionForeground (Color color) {
+ if (selectionForeground == color) return;
+ if (color == null) color = getForeground();
+ selectionForeground = color;
+ if (selectedIndex > -1) {
+ redrawTabArea(selectedIndex);
+ }
+}
+public void setInsertMark(CTabItem item, boolean after) {
+ int index = -1;
+ if (item != null) {
+ index = indexOf(item);
+ }
+ setInsertMark(index, after);
+}
+public void setInsertMark(int index, boolean after) {
+ if (index < -1 || index >= getItemCount()) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+
+ if (index == -1) {
+ index = -2;
+ } else {
+ index = after ? index : --index;
+ }
+
+ if (insertionIndex == index) return;
+ int oldIndex = insertionIndex;
+ insertionIndex = index;
+ if (index > -1) redrawTabArea(index);
+ if (oldIndex > 1) redrawTabArea(oldIndex);
+}
+
+/**
+ * Set the selection to the tab at the specified index.
+ */
+public void setSelection(int index) {
+ if (index < 0 || index >= items.length)
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+
+ if (selectedIndex == index) return;
+
+ if (showClose) {
+ inactiveCloseBar.setVisible(false);
+ inactiveItem = null;
+ }
+
+ int oldIndex = selectedIndex;
+ selectedIndex = index;
+
+ Control control = items[index].control;
+ if (control != null && !control.isDisposed()) {
+ control.setBounds(getClientArea());
+ control.setVisible(true);
+ }
+
+ if (oldIndex != -1) {
+ control = items[oldIndex].control;
+ if (control != null && !control.isDisposed()) {
+ control.setVisible(false);
+ }
+ }
+ ensureVisible();
+
+ redrawTabArea(-1);
+}
+private void ensureVisible() {
+ if (selectedIndex == -1) return;
+ // make sure selected item is visible
+ Rectangle area = super.getClientArea();
+ if (area.width == 0) return;
+ int areaWidth = area.x + area.width - BORDER_RIGHT;
+
+ CTabItem tabItem = items[selectedIndex];
+ if (selectedIndex < topTabIndex) {
+ topTabIndex = selectedIndex;
+ }
+ layoutItems();
+
+ int scrollWidth = scrollBar.getSize().x;
+ int width = areaWidth;
+ if (scroll_leftVisible() || scroll_rightVisible()) {
+ width -= scrollWidth;
+ }
+ while (tabItem.x + tabItem.width > width && selectedIndex != topTabIndex) {
+ topTabIndex++;
+ layoutItems();
+ width = areaWidth;
+ if (scroll_leftVisible() || scroll_rightVisible()) {
+ width -= scrollWidth;
+ }
+ }
+}
+/**
+ * Set the selection to the specified item.
+ */
+public void setSelection(CTabItem item) {
+ if (item == null)
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ int index = indexOf(item);
+ setSelection(index);
+}
+/**
+ * Set the selection to the tab at the specified index.
+ */
+private void setSelectionNotify(int index) {
+ int oldSelectedIndex = selectedIndex;
+ setSelection(index);
+ if (selectedIndex != oldSelectedIndex && selectedIndex != -1) {
+ Event event = new Event();
+ event.item = getItem(selectedIndex);
+ notifyListeners(SWT.Selection, event);
+ }
+}
+
+private void initCloseButtonImages() {
+ if (closeImage != null) return;
+
+ try {
+ Display display = getDisplay();
+ Image image = new Image(display, CTabFolder.class.getResourceAsStream("close.gif"));
+ ImageData source = image.getImageData();
+ ImageData mask = source.getTransparencyMask();
+ image.dispose();
+ closeImage = new Image(display, source, mask);
+ } catch (Error e) {
+ closeImage = null;
+ return;
+ }
+
+ closeItem.setDisabledImage(closeImage);
+ closeItem.setImage(closeImage);
+ inactiveCloseItem.setDisabledImage(closeImage);
+ inactiveCloseItem.setImage(closeImage);
+
+ int height = getTabHeight();
+ Point size = closeBar.computeSize(SWT.DEFAULT, height);
+ closeBar.setSize(size);
+ inactiveCloseBar.setSize(size);
+}
+private void initScrollBarImages() {
+ if (arrowLeftImage != null) return;
+
+ try {
+ Display display = getDisplay();
+ Image image = new Image(display, CTabFolder.class.getResourceAsStream("leftDisabled.gif"));
+ ImageData source = image.getImageData();
+ ImageData mask = source.getTransparencyMask();
+ image.dispose();
+ arrowLeftDisabledImage = new Image(display, source, mask);
+
+ image = new Image(display, CTabFolder.class.getResourceAsStream("left.gif"));
+ source = image.getImageData();
+ mask = source.getTransparencyMask();
+ image.dispose();
+ arrowLeftImage = new Image(display, source, mask);
+
+ image = new Image(display, CTabFolder.class.getResourceAsStream("rightDisabled.gif"));
+ source = image.getImageData();
+ mask = source.getTransparencyMask();
+ image.dispose();
+ arrowRightDisabledImage = new Image(display, source, mask);
+
+ image = new Image(display, CTabFolder.class.getResourceAsStream("right.gif"));
+ source = image.getImageData();
+ mask = source.getTransparencyMask();
+ image.dispose();
+ arrowRightImage = new Image(display, source, mask);
+ } catch (Error e) {
+ if (arrowLeftDisabledImage != null){
+ arrowLeftDisabledImage.dispose();
+ arrowLeftDisabledImage = null;
+ }
+ if (arrowLeftImage != null){
+ arrowLeftImage.dispose();
+ arrowLeftImage = null;
+ }
+ if (arrowRightDisabledImage != null){
+ arrowRightDisabledImage.dispose();
+ arrowRightDisabledImage = null;
+ }
+ if (arrowRightImage != null){
+ arrowRightImage.dispose();
+ arrowRightImage = null;
+ }
+ return;
+ }
+
+ scrollLeft.setDisabledImage(arrowLeftDisabledImage);
+ scrollLeft.setImage(arrowLeftImage);
+
+ scrollRight.setDisabledImage(arrowRightDisabledImage);
+ scrollRight.setImage(arrowRightImage);
+
+ int height = getTabHeight();
+ Point size = scrollBar.computeSize(SWT.DEFAULT, height);
+ scrollBar.setSize(size);
+}
+
+/**
+ * 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.
+ */
+private void onMouseUp(Event event) {
+ if (inDoubleClick) {
+ inDoubleClick = false;
+ Event e = new Event();
+ e.item = getItem(new Point(event.x, event.y));
+ notifyListeners(SWT.DefaultSelection, e);
+ return;
+ }
+
+ for (int i=0; i<items.length; i++) {
+ if (items[i].getBounds().contains(new Point(event.x, event.y))) {
+ setSelectionNotify(i);
+ return;
+ }
+ }
+}
+private void onMouseMove(Event event) {
+ if (!showClose) return;
+
+ CTabItem item = null;
+ Rectangle itemRect = null;
+ for (int i=0; i<items.length; i++) {
+ itemRect = items[i].getBounds();
+ if (itemRect.contains(new Point(event.x, event.y))) {
+ item = items[i];
+ break;
+ }
+ }
+ if (item == inactiveItem) return;
+
+ inactiveCloseBar.setVisible(false);
+ inactiveItem = null;
+
+ if (item == null || item == getSelection()) return;
+
+ Point closeRect = inactiveCloseBar.getSize();
+ int x = itemRect.x + itemRect.width - closeRect.x - 2;
+ int y = itemRect.y + 1 + (itemRect.height - 2 - closeRect.y)/2;
+ if (scrollBar.isVisible()) {
+ Rectangle scrollArea = scrollBar.getBounds();
+ scrollArea.width += BORDER_RIGHT;
+ if (scrollArea.contains(x, y)) return;
+ }
+
+ inactiveCloseBar.setLocation(x, y);
+ inactiveCloseBar.setVisible(true);
+ inactiveItem = item;
+}
+/**
+ * Answer the area where the left scroll button is drawn.
+ */
+private Rectangle scroll_getBounds() {
+ if (scrollBar != null)
+ return scrollBar.getBounds();
+ return new Rectangle(0, 0, 0, 0);
+}
+
+/**
+ * Answer true if not all tabs can be visible in the receive
+ * thus requiring the scroll buttons to be visible.
+ */
+private boolean scroll_leftVisible() {
+ return topTabIndex > 0;
+}
+
+/**
+ * Answer true if not all tabs can be visible in the receive
+ * thus requiring the scroll buttons to be visible.
+ */
+private boolean scroll_rightVisible() {
+ if (topTabIndex < items.length - 1) {
+ // only show Scroll buttons if there is more than one item
+ // and if we are not alread at the last item
+ CTabItem tabItem = items[items.length-1];
+ int tabStopX = tabItem.x + tabItem.width;
+ Rectangle area = super.getClientArea();
+ if (tabStopX > area.x + area.width - BORDER_RIGHT) {
+ return true; // not all tabs fit in the client area
+ }
+ }
+ return false;
+}
+
+/**
+ * Scroll the tab items to the left.
+ */
+private void scroll_scrollLeft() {
+ if (scroll_leftVisible()) {
+ --topTabIndex;
+ layoutItems();
+ redrawTabArea(-1);
+ }
+}
+
+/**
+ * Scroll the tab items to the right.
+ */
+private void scroll_scrollRight() {
+ if (scroll_rightVisible()) {
+ topTabIndex++;
+ layoutItems();
+ redrawTabArea(-1);
+ }
+}
+public void setTabHeight(int height) {
+ if (height < 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ fixedTabHeight = height + CTabItem.TOP_MARGIN + CTabItem.BOTTOM_MARGIN;
+ layoutItems();
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderAdapter.java
new file mode 100644
index 0000000000..1b72804de7
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderAdapter.java
@@ -0,0 +1,10 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+public class CTabFolderAdapter implements CTabFolderListener {
+ public void itemClosed(CTabFolderEvent event){};
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderEvent.java
new file mode 100644
index 0000000000..c19ecfc43d
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderEvent.java
@@ -0,0 +1,18 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.TypedEvent;
+import org.eclipse.swt.widgets.*;
+
+public class CTabFolderEvent extends TypedEvent {
+ public Widget item;
+ public boolean doit;
+
+CTabFolderEvent(Widget w) {
+ super(w);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderListener.java
new file mode 100644
index 0000000000..c46e30c8d5
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabFolderListener.java
@@ -0,0 +1,12 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import java.util.EventListener;
+
+public interface CTabFolderListener {
+ public void itemClosed(CTabFolderEvent event);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabItem.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabItem.java
new file mode 100644
index 0000000000..5a20b6622b
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/CTabItem.java
@@ -0,0 +1,436 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+
+public class CTabItem extends Item {
+ CTabFolder parent;
+ int x,y,width,height = 0;
+ String toolTipText;
+ Control control; // the tab page
+
+ private Image disabledImage;
+
+ // internal constants
+ private static final int LEFT_MARGIN = 3;
+ private static final int RIGHT_MARGIN = 3;
+ static final int TOP_MARGIN = 2;
+ static final int BOTTOM_MARGIN = 2;
+ private static final int INTERNAL_SPACING = 2;
+
+ private static final String ellipsis = "...";
+
+/**
+ * Construct a CTabItem with the specified parent and style.
+ */
+public CTabItem (CTabFolder parent, int style) {
+ this(parent, style, parent.getItemCount());
+}
+/**
+ * Construct a CTabItem with the specified parent and style, inserted at
+ * the specified index.
+ */
+public CTabItem (CTabFolder parent, int style, int index) {
+ super (parent, checkStyle(style));
+ parent.createItem (this, index);
+}
+private static int checkStyle(int style) {
+ return SWT.NONE;
+}
+
+public void dispose () {
+ if (isDisposed()) return;
+ super.dispose();
+ parent.destroyItem(this);
+ parent = null;
+ control = null;
+ toolTipText = null;
+}
+/**
+ * Return the bounds of the CTabItem.
+ */
+public Rectangle getBounds () {
+ return new Rectangle(x, y, width, height);
+}
+/**
+* Gets the control.
+* <p>
+* @return the control
+*
+* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+* when called from the wrong thread
+* @exception SWTError(ERROR_WIDGET_DISPOSED)
+* when the widget has been disposed
+*/
+public Control getControl () {
+ return control;
+}
+/**
+ * Answer the display of the receiver's parent widget.
+ */
+public Display getDisplay() {
+ if (parent == null) SWT.error(SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay();
+}
+public Image getDisabledImage(){
+ return disabledImage;
+}
+/**
+ * Return the parent of the CTabItem.
+ */
+public CTabFolder getParent () {
+ return parent;
+}
+/**
+ * Gets the tool tip text.
+ * <p>
+ * @return the tool tip text.
+ *
+ * @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+ * when called from the wrong thread
+ * @exception SWTError(ERROR_WIDGET_DISPOSED)
+ * when the widget has been disposed
+ */
+public String getToolTipText () {
+ return toolTipText;
+}
+private int imageHeight() {
+ int imageHeight = 0;
+ if (parent.getImageHeight() != -1) {
+ imageHeight = parent.getImageHeight();
+ } else {
+ Image image = getImage();
+ if (image != null) {
+ imageHeight = image.getBounds().height;
+ }
+ }
+ return imageHeight;
+}
+private int imageWidth() {
+ int imageWidth = 0;
+ Image image = getImage();
+ if (image != null) {
+ imageWidth = image.getBounds().width;
+ }
+ return imageWidth;
+}
+/**
+ * Paint the receiver.
+ */
+void onPaint(GC gc, boolean isSelected) {
+
+ if (width == 0 || height == 0) return;
+
+ Display display = getDisplay();
+ Color highlightShadow = display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
+ Color normalShadow = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+
+ int index = parent.indexOf(this);
+
+ if (isSelected) {
+ final Rectangle bounds;
+ if (index == parent.topTabIndex) {
+ bounds = new Rectangle(x + 1, y, width - 2, height);
+ } else {
+ bounds = new Rectangle(x + 2, y, width - 3, height);
+ }
+ if (parent.backgroundImage != null) {
+ // draw a background image behind the text
+ Rectangle imageRect = parent.backgroundImage.getBounds();
+ gc.drawImage(parent.backgroundImage, 0, 0, imageRect.width, imageRect.height,
+ bounds.x, bounds.y, bounds.width, bounds.height);
+ } else if (parent.gradientColors != null) {
+ // draw a gradient behind the text
+ final Color oldBackground = gc.getBackground();
+ if (parent.gradientColors.length == 1) {
+ if (parent.gradientColors[0] != null) gc.setBackground(parent.gradientColors[0]);
+ gc.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
+ } else {
+ final Color oldForeground = gc.getForeground();
+ Color lastColor = parent.gradientColors[0];
+ if (lastColor == null) lastColor = oldBackground;
+ for (int i = 0, pos = 0; i < parent.gradientPercents.length; ++i) {
+ gc.setForeground(lastColor);
+ lastColor = parent.gradientColors[i + 1];
+ if (lastColor == null) lastColor = oldBackground;
+ gc.setBackground(lastColor);
+ final int gradientWidth = (parent.gradientPercents[i] * bounds.width / 100) - pos;
+ gc.fillGradientRectangle(bounds.x + pos, bounds.y, gradientWidth, bounds.height, false);
+ pos += gradientWidth;
+ }
+ gc.setForeground(oldForeground);
+ }
+ gc.setBackground(oldBackground);
+ }
+
+ // draw tab lines
+ if (!parent.onBottom) {
+ gc.setForeground(normalShadow);
+ if (index != parent.topTabIndex) {
+ gc.drawLine(x + 1, y, x + 1, y);
+ gc.drawLine(x, y + 1, x, y + height - 2);
+ gc.drawLine(x, y + height - 1, x, y + height - 1);
+ }
+ gc.drawLine(x + width - 1, y, x + width - 1, y);
+ gc.drawLine(x + width, y + 1, x + width, y + height - 2);
+ gc.drawLine(x + width, y + height - 1, x + width, y + height - 1);
+
+ gc.setForeground(highlightShadow);
+ if (index != parent.topTabIndex) {
+ gc.drawLine(x + 2, y, x + 2, y);
+ gc.drawLine(x + 1, y + 1, x + 1, y + height - 2);
+ gc.drawLine(x + 1, y + height - 1, x + 1, y + height - 1);
+ } else {
+ gc.drawLine(x, y, x, y + height - 1);
+ }
+
+ gc.drawLine(x + width - 2, y, x + width - 2, y);
+ gc.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 2);
+ gc.drawLine(x + width - 1, y + height - 1, x + width - 1, y + height - 1);
+
+ // light line across top
+ if (index != parent.topTabIndex) {
+ gc.drawLine(x + 3, y, x + width - 3, y);
+ } else {
+ gc.drawLine(x + 1, y, x + width - 3, y);
+ }
+ } else {
+ gc.setForeground(normalShadow);
+ if (index != parent.topTabIndex) {
+ gc.drawLine(x, y, x, y);
+ gc.drawLine(x, y + 1, x, y + height - 2);
+ gc.drawLine(x + 1, y + height - 1, x + 1, y + height - 1);
+ }
+ gc.drawLine(x + width, y, x + width, y);
+ gc.drawLine(x + width, y + 1, x + width, y + height - 2);
+ gc.drawLine(x + width - 1, y + height - 1, x + width - 1, y + height - 1);
+
+ gc.setForeground(highlightShadow);
+ if (index != parent.topTabIndex) {
+ gc.drawLine(x + 1, y, x + 1, y);
+ gc.drawLine(x + 1, y + 1, x + 1, y + height - 2);
+ gc.drawLine(x + 2, y + height - 1, x + 2, y + height - 1);
+ } else {
+ gc.drawLine(x, y, x, y + height - 1);
+ }
+
+ gc.drawLine(x + width - 1, y, x + width - 1, y);
+ gc.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 2);
+ gc.drawLine(x + width - 2, y + height - 1, x + width - 2, y + height - 1);
+
+ // light line across top and bottom
+ if (index != parent.topTabIndex) {
+ gc.drawLine(x + 1, y, x + width - 2, y);
+ gc.drawLine(x + 2, y + height - 1, x + width - 3, y + height - 1);
+ } else {
+ gc.drawLine(x + 1, y, x + width - 2, y);
+ gc.drawLine(x + 1, y + height - 1, x + width - 3, y + height - 1);
+ }
+ }
+ } else {
+ // draw tab lines for unselected items
+ gc.setForeground(normalShadow);
+ if (!parent.onBottom) {
+ if (index != parent.topTabIndex && index != parent.getSelectionIndex() + 1) {
+ gc.drawLine(x, y, x, y + (height / 2));
+ }
+ } else {
+ if (index != parent.topTabIndex && index != parent.getSelectionIndex() + 1) {
+ gc.drawLine(x, y + (height / 2), x, y + height - 1);
+ }
+ }
+
+ }
+
+ // draw Image
+ int xDraw = x + LEFT_MARGIN;
+
+ Image image = getImage();
+ if (!isSelected && image != null) {
+ Image temp = getDisabledImage();
+ if (temp != null){
+ image = temp;
+ }
+ }
+ if (image != null) {
+ Rectangle imageBounds = image.getBounds();
+ int imageHeight = imageHeight();
+ int imageY = y + (height - parent.getImageHeight()) / 2;
+ gc.drawImage(image,
+ imageBounds.x, imageBounds.y, imageBounds.width, imageBounds.height,
+ xDraw, imageY, imageBounds.width, imageHeight);
+ xDraw += imageBounds.width + INTERNAL_SPACING;
+ }
+
+ // draw Text
+ int textWidth = x + width - xDraw - RIGHT_MARGIN;
+ if (isSelected && parent.showClose) {
+ textWidth = x + width - xDraw - parent.closeBar.getSize().x - RIGHT_MARGIN;
+ }
+ String text = shortenText(gc, getText(), textWidth);
+
+ if (isSelected && parent.selectionForeground != null) {
+ gc.setForeground(parent.selectionForeground);
+ } else {
+ gc.setForeground(parent.getForeground());
+ }
+ int textY = y + (height - textHeight(gc)) / 2;
+ gc.drawString(text, xDraw, textY, true);
+
+ gc.setForeground(parent.getForeground());
+}
+private String shortenText(GC gc, String text, int width) {
+ if (gc.textExtent(text).x <= width) return text;
+
+ int ellipseWidth = gc.textExtent(ellipsis).x;
+ int length = text.length();
+ int end = length - 1;
+ while (end > 0) {
+ text = text.substring(0, end);
+ int l1 = gc.textExtent(text).x;
+ if (l1 + ellipseWidth <= width) {
+ return text + ellipsis;
+ }
+ end--;
+ }
+ return "";
+}
+/**
+ * Answer the preferred height of the receiver for the GC.
+ */
+int preferredHeight(GC gc) {
+ return Math.max(textHeight(gc), imageHeight()) + TOP_MARGIN + BOTTOM_MARGIN;
+}
+/**
+ * Answer the preferred width of the receiver for the GC.
+ */
+int preferredWidth(GC gc) {
+ int tabWidth = LEFT_MARGIN + RIGHT_MARGIN;
+ Image image = getImage();
+ if (image != null) tabWidth += imageWidth() + INTERNAL_SPACING;
+ tabWidth += textWidth(gc);
+ if (parent.showClose) tabWidth += parent.closeBar.getSize().x;
+ return tabWidth;
+}
+/**
+ * Sets the control.
+ * <p>
+ * @param control the new control
+ *
+ * @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
+ * when called from the wrong thread
+ * @exception SWTError(ERROR_WIDGET_DISPOSED)
+ * when the widget has been disposed
+ */
+public void setControl (Control control) {
+ if (control != null && control.getParent() != parent) {
+ SWT.error (SWT.ERROR_INVALID_PARENT);
+ }
+ if (this.control != null && !this.control.isDisposed()) {
+ this.control.setVisible(false);
+ }
+
+ this.control = control;
+ if (this.control != null) {
+ int index = parent.indexOf (this);
+ if (index == parent.getSelectionIndex ()){
+ this.control.setBounds(parent.getClientArea ());
+ this.control.setVisible(true);
+ } else {
+ this.control.setVisible(false);
+ }
+ }
+}
+/**
+ * Sets the image.
+ * <p>
+ * @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
+ */
+public void setImage (Image image) {
+ Image oldImage = getImage();
+
+ super.setImage(image);
+ if (image == null || !image.equals(oldImage)) {
+ parent.itemChanged(this);
+ }
+}
+public void setDisabledImage (Image image) {
+ Image oldImage = getDisabledImage();
+
+ disabledImage = image;
+ if (disabledImage == null || !disabledImage.equals(oldImage)) {
+ parent.itemChanged(this);
+ }
+}
+
+/**
+ * Set the widget text.
+ * <p>
+ * This method sets the widget label. The label may include
+ * the mnemonic characters but must not contain line delimiters.
+ *
+ * @param string the new label for the widget
+ *
+ */
+public void setText (String string) {
+ String oldText = getText();
+
+ super.setText(string);
+ if (!string.equals(oldText)) {
+ parent.itemChanged(this);
+ }
+}
+
+/**
+ * Sets the tool tip text.
+ * <p>
+ * @param string the new tool tip text (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
+ */
+public void setToolTipText (String string) {
+ toolTipText = string;
+}
+/**
+ * Answer the text height.
+ */
+private int textHeight(GC gc) {
+ int textHeight = 0;
+
+ if (isDisposed()) return textHeight;
+
+ String text = getText();
+ if (text != null) {
+ textHeight = gc.stringExtent(text).y;
+ }
+ return textHeight;
+}
+/**
+ * Answer the text width.
+ */
+private int textWidth(GC gc) {
+ int textWidth = 0;
+
+ if (isDisposed()) return 0;
+
+ String text = getText();
+ if (text != null) {
+ textWidth = gc.stringExtent(text).x;
+ }
+ return textWidth;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ControlEditor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ControlEditor.java
new file mode 100644
index 0000000000..9dfd02a16d
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ControlEditor.java
@@ -0,0 +1,237 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+*
+* A ControlEditor is a manager for a Control that appears above a composite and tracks with the
+* moving and resizing of that composite. It can be used to display one control above
+* another control. This could be used when editing a control that does not have editing
+* capabilities by using a text editor or for launching a dialog by placing a button
+* above a control.
+*
+* <p> Here is an example of using a ControlEditor:
+*
+* <code><pre>
+* Canvas canvas = new Canvas(shell, SWT.BORDER);
+* canvas.setBounds(10, 10, 300, 300);
+* Color color = new Color(null, 255, 0, 0);
+* canvas.setBackground(color);
+* ControlEditor editor = new ControlEditor (canvas);
+* // The editor will be a button in the bottom right corner of the canvas.
+* // When selected, it will launch a Color dialog that will change the background
+* // of the canvas.
+* Button button = new Button(canvas, SWT.PUSH);
+* button.setText("Select Color...");
+* button.addSelectionListener (new SelectionAdapter() {
+* public void widgetSelected(SelectionEvent e) {
+* ColorDialog dialog = new ColorDialog(shell);
+* dialog.open();
+* RGB rgb = dialog.getRGB();
+* if (rgb != null) {
+* if (color != null) color.dispose();
+* color = new Color(null, rgb);
+* canvas.setBackground(color);
+* }
+*
+* }
+* });
+*
+* editor.horizontalAlignment = SWT.RIGHT;
+* editor.verticalAlignment = SWT.BOTTOM;
+* editor.grabHorizontal = false;
+* editor.grabVertical = false;
+* Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+* editor.minimumWidth = size.x;
+* editor.minimumHeight = size.y;
+* editor.setEditor (button);
+* </pre></code>
+*/
+public class ControlEditor {
+
+ /**
+ * Specifies how the editor should be aligned relative to the control. Allowed values
+ * are SWT.LEFT, SWT.RIGHT and SWT.CENTER. The default value is SWT.CENTER.
+ */
+ public int horizontalAlignment = SWT.CENTER;
+
+ /**
+ * Specifies whether the editor should be sized to use the entire width of the control.
+ * True means resize the editor to the same width as the cell. False means do not adjust
+ * the width of the editor. The default value is false.
+ */
+ public boolean grabHorizontal = false;
+
+ /**
+ * Specifies the minimum width the editor can have. This is used in association with
+ * a true value of grabHorizontal. If the cell becomes smaller than the minimumWidth, the
+ * editor will not made smaller than the minumum width value. The default value is 0.
+ */
+ public int minimumWidth = 0;
+
+ /**
+ * Specifies how the editor should be aligned relative to the control. Allowed values
+ * are SWT.TOP, SWT.BOTTOM and SWT.CENTER. The default value is SWT.CENTER.
+ */
+ public int verticalAlignment = SWT.CENTER;
+
+ /**
+ * Specifies whether the editor should be sized to use the entire height of the control.
+ * True means resize the editor to the same height as the underlying control. False means do not adjust
+ * the height of the editor. The default value is false.
+ */
+ public boolean grabVertical = false;
+
+ /**
+ * Specifies the minimum height the editor can have. This is used in association with
+ * a true value of grabVertical. If the control becomes smaller than the minimumHeight, the
+ * editor will not made smaller than the minumum height value. The default value is 0.
+ */
+ public int minimumHeight = 0;
+
+ Composite parent;
+ Control editor;
+ private boolean hadFocus;
+ private Listener internalListener;
+/**
+* Creates a ControlEditor for the specified Composite.
+*
+* @param parent the Composite above which this editor will be displayed
+*
+*/
+public ControlEditor (Composite parent) {
+ this.parent = parent;
+
+ internalListener = new Listener() {
+ public void handleEvent(Event e) {
+ if (e.widget instanceof ScrollBar && e.type == SWT.Selection)
+ scroll (e);
+ else if (e.type == SWT.Resize)
+ resize ();
+ }
+ };
+
+ parent.addListener (SWT.Resize, internalListener);
+
+ ScrollBar hBar = parent.getHorizontalBar ();
+ if (hBar != null) hBar.addListener (SWT.Selection, internalListener);
+ ScrollBar vBar = parent.getVerticalBar ();
+ if (vBar != null) vBar.addListener (SWT.Selection, internalListener);
+}
+Rectangle computeBounds (){
+ Rectangle clientArea = parent.getClientArea();
+ Rectangle editorRect = new Rectangle(clientArea.x, clientArea.y, minimumWidth, minimumHeight);
+
+ if (grabHorizontal)
+ editorRect.width = Math.max(clientArea.width, minimumWidth);
+
+ if (grabVertical)
+ editorRect.height = Math.max(clientArea.height, minimumHeight);
+
+ switch (horizontalAlignment) {
+ case SWT.RIGHT:
+ editorRect.x += clientArea.width - editorRect.width;
+ break;
+ case SWT.LEFT:
+ // do nothing - clientArea.x is the right answer
+ break;
+ default:
+ // default is CENTER
+ editorRect.x += (clientArea.width - editorRect.width)/2;
+ }
+
+ switch (verticalAlignment) {
+ case SWT.BOTTOM:
+ editorRect.y += clientArea.height - editorRect.height;
+ break;
+ case SWT.TOP:
+ // do nothing - clientArea.y is the right answer
+ break;
+ default :
+ // default is CENTER
+ editorRect.y += (clientArea.height - editorRect.height)/2;
+ }
+
+
+ return editorRect;
+
+}
+/**
+ * Removes all associations between the Editor and the underlying composite. The
+ * composite and the editor Control are <b>not</b> disposed.
+ */
+public void dispose () {
+ if (!parent.isDisposed()) {
+ parent.removeListener (SWT.Resize, internalListener);
+ ScrollBar hBar = parent.getHorizontalBar ();
+ if (hBar != null) hBar.removeListener (SWT.Selection, internalListener);
+ ScrollBar vBar = parent.getVerticalBar ();
+ if (vBar != null) vBar.removeListener (SWT.Selection, internalListener);
+ }
+
+ parent = null;
+ editor = null;
+ hadFocus = false;
+ internalListener = null;
+}
+/**
+* Returns the Control that is displayed above the composite being edited.
+*
+* @return the Control that is displayed above the composite being edited
+*/
+public Control getEditor () {
+ return editor;
+}
+void resize () {
+ if (editor == null || editor.isDisposed()) return;
+ if (editor.getVisible ()) {
+ hadFocus = editor.isFocusControl();
+ } // this doesn't work because
+ // resizing the column takes the focus away
+ // before we get here
+ editor.setBounds (computeBounds ());
+ if (hadFocus) editor.setFocus ();
+}
+void scroll (Event e) {
+ if (editor == null || editor.isDisposed()) return;
+ if (editor.getVisible ()) {
+ hadFocus = editor.isFocusControl();
+ }
+ boolean visible = e.detail != SWT.DRAG;
+ if (visible) {
+ editor.setBounds (computeBounds ());
+ }
+ editor.setVisible (visible);
+ if (visible && hadFocus) editor.setFocus ();
+}
+/**
+* Specify the Control that is to be displayed.
+*
+* <p>Note: The Control provided as the editor <b>must</b> be created with its parent
+* being the Composite specified in the ControlEditor constructor.
+*
+* @param editor the Control that is displayed above the composite being edited
+*/
+public void setEditor (Control editor) {
+
+ if (editor == null) {
+ // this is the case where the caller is setting the editor to be blank
+ // set all the values accordingly
+ this.editor = null;
+ return;
+ }
+
+ this.editor = editor;
+
+ editor.setVisible (false);
+ editor.setBounds (computeBounds ());
+ editor.setVisible (true);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/DefaultContent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/DefaultContent.java
new file mode 100644
index 0000000000..1ed76069b5
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/DefaultContent.java
@@ -0,0 +1,878 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.widgets.*;
+import java.io.*;
+import java.util.*;
+
+class DefaultContent implements StyledTextContent {
+ private final static String LineDelimiter = System.getProperty("line.separator");
+
+ Vector textListeners = new Vector(); // stores text listeners for event sending
+ char[] textStore = new char[0]; // stores the actual text
+ int gapStart = -1; // the character position start of the gap
+ int gapEnd = -1; // the character position after the end of the gap
+ int gapLine = -1; // the line on which the gap exists, the gap will always be associated
+ // with one line
+ int highWatermark = 300;
+ int lowWatermark = 50;
+
+ int[][] lines = new int[50][2]; // array of character positions and lengths representing
+ // the lines of text
+ int lineCount = 0; // the number of lines of text
+ int expandExp = 1; // the expansion exponent, used to increase the lines array exponentially
+ int replaceExpandExp = 1; // the expansion exponent, used to increase the lines array exponentially
+
+/**
+ * Creates a new DefaultContent and initializes it. A <code>StyledTextContent</> will always have
+ * at least one empty line.
+ */
+DefaultContent() {
+ super();
+ setText("");
+}
+/**
+ * Adds a line to the end of the line indexes array. Increases the size of the array if necessary.
+ * <code>lineCount</code> is updated to reflect the new entry.
+ * <p>
+ *
+ * @param start the start of the line
+ * @param length the length of the line
+ */
+void addLineIndex(int start, int length) {
+ int size = lines.length;
+ if (lineCount == size) {
+ // expand the lines by powers of 2
+ int[][] newLines = new int[size+(int)Math.pow(2, expandExp)][2];
+ System.arraycopy(lines, 0, newLines, 0, size);
+ lines = newLines;
+ expandExp++;
+ }
+ int[] range = new int[] {start, length};
+ lines[lineCount] = range;
+ lineCount++;
+}
+/**
+ * Adds a line index to the end of <code>linesArray</code>. Increases the
+ * size of the array if necessary and returns a new array.
+ * <p>
+ *
+ * @param start the start of the line
+ * @param length the length of the line
+ * @param linesArray the array to which to add the line index
+ * @param count the position at which to add the line
+ * @return a new array of line indexes
+ */
+int[][] addLineIndex(int start, int length, int[][] linesArray, int count) {
+ int size = linesArray.length;
+ int[][] newLines = linesArray;
+ if (count == size) {
+ newLines = new int[size+(int)Math.pow(2, replaceExpandExp)][2];
+ replaceExpandExp++;
+ System.arraycopy(linesArray, 0, newLines, 0, size);
+ }
+ int[] range = new int[] {start, length};
+ newLines[count] = range;
+ return newLines;
+}
+/**
+ * Adds a <code>TextChangeListener</code> listening for
+ * <code>TextChangingEvent</code> and <code>TextChangedEvent</code>. A
+ * <code>TextChangingEvent</code> is sent before changes to the text occur.
+ * A <code>TextChangedEvent</code> is sent after changes to the text
+ * occured.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT when listener is null</li>
+ * </ul>
+ */
+public void addTextChangeListener(TextChangeListener listener) {
+ if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);
+ StyledTextListener typedListener = new StyledTextListener(listener);
+ textListeners.addElement(typedListener);
+}
+/**
+ * Adjusts the gap to accomodate a text change that is occurring.
+ * <p>
+ *
+ * @param position the position at which a change is occurring
+ * @param sizeHint the size of the change
+ * @param line the line where the gap will go
+ */
+void adjustGap(int position, int sizeHint, int line) {
+ if (position == gapStart) {
+ // text is being inserted at the gap position
+ int size = (gapEnd - gapStart) - sizeHint;
+ if (lowWatermark <= size && size <= highWatermark)
+ return;
+ } else if ((position + sizeHint == gapStart) && (sizeHint < 0)) {
+ // text is being deleted at the gap position
+ int size = (gapEnd - gapStart) - sizeHint;
+ if (lowWatermark <= size && size <= highWatermark)
+ return;
+ }
+ moveAndResizeGap(position, sizeHint, line);
+}
+/**
+ * Calculates the indexes of each line in the text store. Assumes no gap exists.
+ * Optimized to do less checking.
+ */
+void indexLines(){
+ int start = 0;
+ lineCount = 0;
+ int textLength = textStore.length;
+ int i;
+ for (i=start; i<textLength; i++) {
+ char ch = textStore[i];
+ if (ch == SWT.CR) {
+ // see if the next character is a LF
+ if (i + 1 < textLength) {
+ ch = textStore[i+1];
+ if (ch == SWT.LF) {
+ i++;
+ }
+ }
+ addLineIndex(start, i - start + 1);
+ start = i + 1;
+ } else if (ch == SWT.LF) {
+ addLineIndex(start, i - start + 1);
+ start = i + 1;
+ }
+ }
+ addLineIndex(start, i - start);
+}
+/**
+ * Returns whether or not the given character is a line delimiter. Both CR and LF
+ * are valid line delimiters.
+ * <p>
+ *
+ * @param ch the character to test
+ * @return true if ch is a delimiter, false otherwise
+ */
+boolean isDelimiter(char ch) {
+ if (ch == SWT.CR) return true;
+ if (ch == SWT.LF) return true;
+ return false;
+}
+/**
+ * Determine whether or not the replace operation is valid. DefaultContent will not allow
+ * the /r/n line delimiter to be split or partially deleted.
+ * <p>
+ *
+ * @param start start offset of text to replace
+ * @param replaceLength start offset of text to replace
+ * @param newText start offset of text to replace
+ */
+protected boolean isValidReplace(int start, int replaceLength, String newText){
+ if (replaceLength == 0) {
+ // inserting text, see if the \r\n line delimiter is being split
+ if (start == 0) return true;
+ if (start == getCharCount()) return true;
+ char before = getTextRange(start - 1, 1).charAt(0);
+ if (before == '\r') {
+ char after = getTextRange(start, 1).charAt(0);
+ if (after == '\n') return false;
+ }
+ } else {
+ // deleting text, see if part of a \r\n line delimiter is being deleted
+ char startChar = getTextRange(start, 1).charAt(0);
+ if (startChar == '\n') {
+ // see if char before delete position is \r
+ if (start != 0) {
+ char before = getTextRange(start - 1, 1).charAt(0);
+ if (before == '\r') return false;
+ }
+ }
+ char endChar = getTextRange(start + replaceLength - 1, 1).charAt(0);
+ if (endChar == '\r') {
+ // see if char after delete position is \n
+ if (start + replaceLength != getCharCount()) {
+ char after = getTextRange(start + replaceLength, 1).charAt(0);
+ if (after == '\n') return false;
+ }
+ }
+ }
+ return true;
+}
+/**
+ * Calculates the indexes of each line of text in the given range.
+ * <p>
+ *
+ * @param offset the logical start offset of the text lineate
+ * @param length the length of the text to lineate, includes gap
+ * @param numLines the number of lines to initially allocate for the line index array,
+ * passed in for efficiency (the exact number of lines may be known)
+ * @return a line indexes array where each line is identified by a start offset and
+ * a length
+ */
+int[][] indexLines(int offset, int length, int numLines){
+ int[][] indexedLines = new int[numLines][2];
+ int start = 0;
+ int lineCnt = 0;
+ int i;
+ replaceExpandExp = 1;
+ for (i=start; i<length; i++) {
+ int location = i + offset;
+ if ((location >= gapStart) && (location < gapEnd)) {
+ // ignore the gap
+ } else {
+ char ch = textStore[location];
+ if (ch == SWT.CR) {
+ // see if the next character is a LF
+ if (location+1 < textStore.length) {
+ ch = textStore[location+1];
+ if (ch == SWT.LF) {
+ i++;
+ }
+ }
+ indexedLines = addLineIndex(start, i - start + 1, indexedLines, lineCnt);
+ lineCnt++;
+ start = i + 1;
+ } else if (ch == SWT.LF) {
+ indexedLines = addLineIndex(start, i - start + 1, indexedLines, lineCnt);
+ lineCnt++;
+ start = i + 1;
+ }
+ }
+ }
+ int[][] newLines = new int[lineCnt+1][2];
+ System.arraycopy(indexedLines, 0, newLines, 0, lineCnt);
+ int[] range = new int[] {start, i - start};
+ newLines[lineCnt]=range;
+ return newLines;
+}
+/**
+ * Inserts text.
+ * <p>
+ *
+ * @param position the position at which to insert the text
+ * @param length the text to insert
+ */
+void insert(int position, String text) {
+ if (text.length() == 0) return;
+
+ int startLine = getLineAtOffset(position);
+ int change = text.length();
+ boolean endInsert = position == getCharCount();
+ adjustGap(position, change, startLine);
+
+ // during an insert the gap will be adjusted to start at
+ // position and it will be associated with startline, the
+ // inserted text will be placed in the gap
+ int startLineOffset = getOffsetAtLine(startLine);
+ // at this point, startLineLength will include the start line
+ // and all of the newly inserted text
+ int startLineLength = getPhysicalLine(startLine).length();
+
+ if (change > 0) {
+ // shrink gap
+ gapStart += (change);
+ for (int i = 0; i < text.length(); i++)
+ textStore[position + i]= text.charAt(i);
+ }
+
+ // figure out the number of new lines that have been inserted
+ int [][] newLines = indexLines(startLineOffset, startLineLength, 10);
+ // only insert an empty line if it is the last line in the text
+ int numNewLines = newLines.length - 1;
+ if (newLines[numNewLines][1] == 0) {
+ // last inserted line is a new line
+ if (endInsert) {
+ // insert happening at end of the text, leave numNewLines as
+ // is since the last new line will not be concatenated with another
+ // line
+ numNewLines += 1;
+ } else {
+ numNewLines -= 1;
+ }
+ }
+
+ // make room for the new lines
+ expandLinesBy(numNewLines);
+ // shift down the lines after the replace line
+ for (int i = lineCount-1; i > startLine; i--) {
+ lines[i + numNewLines]=lines[i];
+ }
+ // insert the new lines
+ for (int i=0; i<numNewLines; i++) {
+ newLines[i][0] += startLineOffset;
+ lines[startLine + i]=newLines[i];
+ }
+ // update the last inserted line
+ if (numNewLines < newLines.length) {
+ newLines[numNewLines][0] += startLineOffset;
+ lines[startLine + numNewLines] = newLines[numNewLines];
+ }
+
+ lineCount += numNewLines;
+ gapLine = getLineAtPhysicalOffset(gapStart);
+}
+/**
+ * Moves the gap and adjusts its size in anticipation of a text change.
+ * The gap is resized to actual size + the specified size and moved to the given
+ * position.
+ * <p>
+ *
+ * @param position the position at which a change is occurring
+ * @param sizeHint the size of the change
+ * @param line the line where the gap should be put
+ */
+void moveAndResizeGap(int position, int size, int newGapLine) {
+ char[] content = null;
+ int oldSize = gapEnd - gapStart;
+ int newSize;
+ if (size > 0) {
+ newSize = highWatermark + size;
+ } else {
+ newSize = lowWatermark - size;
+ }
+ // remove the old gap from the lines information
+ if (gapExists()) {
+ // adjust the line length
+ lines[gapLine][1] = lines[gapLine][1] - oldSize;
+ // adjust the offsets of the lines after the gapLine
+ for (int i=gapLine+1; i<lineCount; i++) {
+ lines[i][0]=lines[i][0]-oldSize;
+ }
+ }
+
+ if (newSize < 0) {
+ if (oldSize > 0) {
+ // removing the gap
+ content = new char[textStore.length - oldSize];
+ System.arraycopy(textStore, 0, content, 0, gapStart);
+ System.arraycopy(textStore, gapEnd, content, gapStart, content.length - gapStart);
+ textStore= content;
+ }
+ gapStart = gapEnd= position;
+ return;
+ }
+ content = new char[textStore.length + (newSize - oldSize)];
+ int newGapStart = position;
+ int newGapEnd = newGapStart + newSize;
+ if (oldSize == 0) {
+ System.arraycopy(textStore, 0, content, 0, newGapStart);
+ System.arraycopy(textStore, newGapStart, content, newGapEnd, content.length - newGapEnd);
+ } else if (newGapStart < gapStart) {
+ int delta = gapStart - newGapStart;
+ System.arraycopy(textStore, 0, content, 0, newGapStart);
+ System.arraycopy(textStore, newGapStart, content, newGapEnd, delta);
+ System.arraycopy(textStore, gapEnd, content, newGapEnd + delta, textStore.length - gapEnd);
+ } else {
+ int delta = newGapStart - gapStart;
+ System.arraycopy(textStore, 0, content, 0, gapStart);
+ System.arraycopy(textStore, gapEnd, content, gapStart, delta);
+ System.arraycopy(textStore, gapEnd + delta, content, newGapEnd, content.length - newGapEnd);
+ }
+ textStore = content;
+ gapStart = newGapStart;
+ gapEnd = newGapEnd;
+
+ // add the new gap to the lines information
+ if (gapExists()) {
+ gapLine = newGapLine;
+ // adjust the line length
+ int gapLength = gapEnd - gapStart;
+ lines[gapLine][1] = lines[gapLine][1] + (gapLength);
+ // adjust the offsets of the lines after the gapLine
+ for (int i=gapLine+1; i<lineCount; i++) {
+ lines[i][0]=lines[i][0]+gapLength;
+ }
+ }
+}
+/**
+ * Returns the number of lines that are in the specified text.
+ * <p>
+ *
+ * @param startOffset the start of the text to lineate
+ * @param length the length of the text to lineate
+ * @return number of lines
+ */
+int lineCount(int startOffset, int length){
+ if (length == 0) {
+ return 0;
+ }
+ int lineCnt = 0;
+ int count = 0;
+ int i = startOffset;
+ if (i >= gapStart) {
+ i += gapEnd - gapStart;
+ }
+ while (count < length) {
+ if ((i >= gapStart) && (i < gapEnd)) {
+ // ignore the gap
+ } else {
+ char ch = textStore[i];
+ if (ch == SWT.CR) {
+ // see if the next character is a LF
+ if (i + 1 < textStore.length) {
+ ch = textStore[i+1];
+ if (ch == SWT.LF) {
+ i++;
+ count++;
+ }
+ }
+ lineCnt++;
+ } else if (ch == SWT.LF) {
+ lineCnt++;
+ }
+ count++;
+ }
+ i++;
+ }
+ return lineCnt;
+}
+/**
+ * Returns the number of lines that are in the specified text.
+ * <p>
+ *
+ * @param text the text to lineate
+ * @return number of lines in the text
+ */
+int lineCount(String text){
+ int lineCount = 0;
+ int length = text.length();
+ for (int i = 0; i < length; i++) {
+ char ch = text.charAt(i);
+ if (ch == SWT.CR) {
+ if (i + 1 < length && text.charAt(i + 1) == SWT.LF) {
+ i++;
+ }
+ lineCount++;
+ }
+ else
+ if (ch == SWT.LF) {
+ lineCount++;
+ }
+ }
+ return lineCount;
+}
+/**
+ * @return the logical length of the text store
+ */
+public int getCharCount() {
+ int length = gapEnd - gapStart;
+ return (textStore.length - length);
+}
+/**
+ * Returns the line at <code>index</code> without delimiters.
+ * <p>
+ *
+ * @param index the index of the line to return
+ * @return the logical line text (i.e., without the gap)
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT when index is out of range</li>
+ * </ul>
+ */
+public String getLine(int index) {
+ if ((index >= lineCount) || (index < 0)) error(SWT.ERROR_INVALID_ARGUMENT);
+ int start = lines[index][0];
+ int length = lines[index][1];
+ int end = start + length - 1;
+ if (!gapExists() || (end < gapStart) || (start >= gapEnd)) {
+ // line is before or after the gap
+ while ((length - 1 >= 0) && isDelimiter(textStore[start+length-1])) {
+ length--;
+ }
+ return new String(textStore, start, length);
+ } else {
+ // gap is in the specified range, strip out the gap
+ StringBuffer buf = new StringBuffer();
+ int gapLength = gapEnd - gapStart;
+ buf.append(textStore, start, gapStart - start);
+ buf.append(textStore, gapEnd, length - gapLength - (gapStart - start));
+ length = buf.length();
+ while ((length - 1 >=0) && isDelimiter(buf.charAt(length-1))) {
+ length--;
+ }
+ return buf.substring(0, length);
+ }
+}
+/**
+ * Returns the line delimiter that should be used by the StyledText
+ * widget when inserting new lines. This delimiter may be different than the
+ * delimiter that is used by the <code>StyledTextContent</code> interface.
+ * <p>
+ *
+ * @return the platform line delimiter as specified in the line.separator
+ * system property.
+ */
+public String getLineDelimiter() {
+ return LineDelimiter;
+}
+/**
+ * Returns the line at the given index with delimiters.
+ * <p>
+ * @param index the index of the line to return
+ * @return the logical line text (i.e., without the gap) with delimiters
+ */
+String getFullLine(int index) {
+ int start = lines[index][0];
+ int length = lines[index][1];
+ int end = start + length - 1;
+ if (!gapExists() || (end < gapStart) || (start >= gapEnd)) {
+ // line is before or after the gap
+ return new String(textStore, start, length);
+ } else {
+ // gap is in the specified range, strip out the gap
+ StringBuffer buf = new StringBuffer();
+ int gapLength = gapEnd - gapStart;
+ buf.append(textStore, start, gapStart - start);
+ buf.append(textStore, gapEnd, length - gapLength - (gapStart - start));
+ return buf.toString();
+ }
+}
+/**
+ * Returns the physical line at the given index (i.e., with delimiters and the gap).
+ * <p>
+ *
+ * @param index the line index
+ * @return the physical line
+ */
+String getPhysicalLine(int index) {
+ int start = lines[index][0];
+ int length = lines[index][1];
+ return getPhysicalText(start, length);
+}
+/**
+ * @return the number of lines in the text store
+ */
+public int getLineCount(){
+ return lineCount;
+}
+/**
+ * Returns the line at the given offset.
+ * <p>
+ *
+ * @param charPosition logical character offset (i.e., does not include gap)
+ * @return the line index
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT when charPosition is out of range</li>
+ * </ul>
+ */
+public int getLineAtOffset(int charPosition){
+ int position;
+ if ((charPosition > getCharCount()) || (charPosition < 0)) error(SWT.ERROR_INVALID_ARGUMENT);
+ if (charPosition < gapStart) {
+ // position is before the gap
+ position = charPosition;
+ } else {
+ // position includes the gap
+ position = charPosition + (gapEnd - gapStart);
+ }
+
+ // if last line and the line is not empty you can ask for
+ // a position that doesn't exist (the one to the right of the
+ // last character) - for inserting
+ if (lineCount > 0) {
+ int lastLine = lineCount - 1;
+ if (position == lines[lastLine][0] + lines[lastLine][1])
+ return lastLine;
+ }
+
+ int high = lineCount;
+ int low = -1;
+ int index = lineCount;
+ while (high - low > 1) {
+ index = (high + low) / 2;
+ int lineStart = lines[index][0];
+ int lineEnd = lineStart + lines[index][1] - 1;
+ if (position <= lineStart) {
+ high = index;
+ } else if (position <= lineEnd) {
+ high = index;
+ break;
+ } else {
+ low = index;
+ }
+ }
+
+ return high;
+}
+/**
+ * Returns the line index at the given physical offset.
+ * <p>
+ *
+ * @param position physical character offset (i.e., includes gap)
+ * @return the line index
+ */
+int getLineAtPhysicalOffset(int position){
+ int high = lineCount;
+ int low = -1;
+ int index = lineCount;
+ while (high - low > 1) {
+ index = (high + low) / 2;
+ int lineStart = lines[index][0];
+ int lineEnd = lineStart + lines[index][1] - 1;
+ if (position <= lineStart) {
+ high = index;
+ } else if (position <= lineEnd) {
+ high = index;
+ break;
+ } else {
+ low = index;
+ }
+ }
+ return high;
+}
+/**
+ * Returns the logical offset of the given line.
+ * <p>
+ *
+ * @param lineIndex index of line
+ * @return the logical starting offset of the line. When there are not any lines,
+ * getOffsetAtLine(0) is a valid call that should answer 0.
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT when lineIndex is out of range</li>
+ * </ul>
+ */
+public int getOffsetAtLine(int lineIndex) {
+ if (lineIndex == 0) return 0;
+ if ((lineIndex >= lineCount) || (lineIndex < 0)) error(SWT.ERROR_INVALID_ARGUMENT);
+ int start = lines[lineIndex][0];
+ if (start > gapEnd) {
+ return start - (gapEnd - gapStart);
+ } else {
+ return start;
+ }
+}
+/**
+ * Increases the line indexes array to accomodate more lines.
+ * <p>
+ *
+ * @param numLines the number to increase the array by
+ */
+void expandLinesBy(int numLines) {
+ int size = lines.length;
+ if (size - lineCount >= numLines) {
+ return;
+ }
+ int[][] newLines = new int[size+Math.max(10, numLines)][2];
+ System.arraycopy(lines, 0, newLines, 0, size);
+ lines = newLines;
+}
+/**
+ * Reports an SWT error.
+ * <p>
+ *
+ * @param code the error code
+ */
+void error (int code) {
+ SWT.error(code);
+}
+/**
+ * Returns whether or not a gap exists in the text store.
+ * <p>
+ *
+ * @return true if gap exists, false otherwise
+ */
+boolean gapExists() {
+ return gapStart != gapEnd;
+}
+
+/**
+ * Returns a string representing the continous content of
+ * the text store.
+ * <p>
+ *
+ * @param start the physical start offset of the text to return
+ * @param length the physical length of the text to return
+ * @return the text
+ */
+String getPhysicalText(int start, int length) {
+ return new String(textStore, start, length);
+}
+/**
+ * Returns a string representing the logical content of
+ * the text store (i.e., gap stripped out).
+ * <p>
+ *
+ * @param start the logical start offset of the text to return
+ * @param length the logical length of the text to return
+ * @return the text
+ */
+public String getTextRange(int start, int length) {
+ if (textStore == null)
+ return "";
+ if (length == 0)
+ return "";
+ int end= start + length;
+ if (!gapExists() || (end < gapStart))
+ return new String(textStore, start, length);
+ if (gapStart < start) {
+ int gapLength= gapEnd - gapStart;
+ return new String(textStore, start + gapLength , length);
+ }
+ StringBuffer buf = new StringBuffer();
+ buf.append(textStore, start, gapStart - start);
+ buf.append(textStore, gapEnd, end - gapStart);
+ return buf.toString();
+}
+/**
+ * Removes the specified <code>TextChangeListener</code>.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT when listener is null</li>
+ * </ul>
+ */
+public void removeTextChangeListener(TextChangeListener listener){
+ if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);
+ for (int i=0; i<textListeners.size(); i++) {
+ TypedListener typedListener = (TypedListener) textListeners.elementAt(i);
+ if (typedListener.getEventListener () == listener) {
+ textListeners.removeElementAt(i);
+ break;
+ }
+ }
+}
+/**
+ * Replaces the text with <code>newText</code> starting at position <code>start</code>
+ * for a length of <code>replaceLength</code>. Notifies the appropriate listeners.
+ * <p>
+ *
+ * When sending the TextChangingEvent, <code>newLineCount</code> is the number of
+ * lines that are going to be inserted and <code>replaceLineCount</code> is
+ * the number of lines that are going to be deleted, based on the change
+ * that occurs visually. For example:
+ * <ul>
+ * <li>(replaceText,newText) ==> (replaceLineCount,newLineCount)
+ * <li>("","\n") ==> (0,1)
+ * <li>("\n\n","a") ==> (2,0)
+ * </ul>
+ * </p>
+ *
+ * @param start start offset of text to replace
+ * @param replaceLength start offset of text to replace
+ * @param newText start offset of text to replace
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_INVALID_ARGUMENT when the text change results in a multi byte
+ * line delimiter being split or partially deleted. Splitting a line
+ * delimiter by inserting text between the CR and LF characters of the
+ * \r\n delimiter or deleting part of this line delimiter is not supported</li>
+ * </ul>
+ */
+public void replaceTextRange(int start, int replaceLength, String newText){
+ // check for invalid replace operations
+// if (!isValidReplace(start, replaceLength, newText)) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+
+ // inform listeners
+ StyledTextEvent event = new StyledTextEvent(this);
+ event.type = StyledText.TextChanging;
+ event.start = start;
+ event.replaceLineCount = lineCount(start, replaceLength);
+ event.text = newText;
+ event.newLineCount = lineCount(newText);
+ event.replaceCharCount = replaceLength;
+ event.newCharCount = newText.length();
+ sendTextEvent(event);
+
+ // first delete the text to be replaced
+ delete(start, replaceLength, event.replaceLineCount + 1);
+ // then insert the new text
+ insert(start, newText);
+ // inform listeners
+ event = new StyledTextEvent(this);
+ event.type = StyledText.TextChanged;
+ sendTextEvent(event);
+ // printLines();
+}
+/**
+ * Sends the text listeners the TextChanged event.
+ */
+void sendTextEvent(StyledTextEvent event) {
+ for (int i=0; i<textListeners.size(); i++) {
+ ((StyledTextListener)textListeners.elementAt(i)).handleEvent(event);
+ }
+}
+/**
+ * Sets the content to text and removes the gap since there are no sensible predictions
+ * about where the next change will occur.
+ * <p>
+ *
+ * @param text the text
+ */
+public void setText (String text){
+ textStore = text.toCharArray();
+ gapStart = -1;
+ gapEnd = -1;
+ expandExp = 1;
+ indexLines();
+ StyledTextEvent event = new StyledTextEvent(this);
+ event.type = StyledText.TextSet;
+ event.text = "";
+ sendTextEvent(event);
+}
+/**
+ * Deletes text.
+ * <p>
+ * @param position the position at which the text to delete starts
+ * @param length the length of the text to delete
+ * @param numLines the number of lines that are being deleted
+ */
+void delete(int position, int length, int numLines) {
+ if (length == 0) return;
+
+ int startLine = getLineAtOffset(position);
+ int startLineOffset = getOffsetAtLine(startLine);
+ int endLine = getLineAtOffset(position + length);
+
+ String endText = "";
+ boolean splittingDelimiter = false;
+ if (position + length < getCharCount()) {
+ endText = getTextRange(position + length - 1, 2);
+ if ((endText.charAt(0) == SWT.CR) && (endText.charAt(1) == SWT.LF)) {
+ splittingDelimiter = true;
+ }
+ }
+
+ adjustGap(position + length, -length, startLine);
+ int [][] oldLines = indexLines(position, length + (gapEnd - gapStart), numLines);
+
+ // enlarge the gap - the gap can be enlarged either to the
+ // right or left
+ if (position + length == gapStart) {
+ gapStart -= length;
+ } else {
+ gapEnd += length;
+ }
+
+ // figure out the length of the new concatenated line, do so by
+ // finding the first line delmiter after position
+ int j = position;
+ boolean eol = false;
+ while (j < textStore.length && !eol) {
+ if (j < gapStart || j >= gapEnd) {
+ char ch = textStore[j];
+ if (isDelimiter(ch)) {
+ if (j + 1 < textStore.length)
+ if (ch == SWT.CR && (textStore[j+1] == SWT.LF))
+ j++;
+ eol = true;
+ }
+ }
+ j++;
+ }
+ // update the line where the deletion started
+ lines[startLine][1] = (position - startLineOffset) + (j - position);
+ // figure out the number of lines that have been deleted
+ int numOldLines = oldLines.length - 1;
+ if (splittingDelimiter) numOldLines -= 1;
+ // shift up the lines after the last deleted line, no need to update
+ // the offset or length of the lines
+ for (int i = endLine + 1; i < lineCount; i++) {
+ lines[i - numOldLines]=lines[i];
+ }
+ lineCount -= numOldLines;
+ gapLine = getLineAtPhysicalOffset(gapStart);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/DefaultLineStyler.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/DefaultLineStyler.java
new file mode 100644
index 0000000000..1c82bbcd4c
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/DefaultLineStyler.java
@@ -0,0 +1,625 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import java.util.*;
+
+class DefaultLineStyler implements LineStyleListener, LineBackgroundListener {
+ StyledTextContent content;
+ StyleRange styles[] = new StyleRange[0];
+ int styleCount = 0; // the number of styles
+ int styleExpandExp = 1; // the expansion exponent, used to increase the styles array exponentially
+ int lineExpandExp = 1; // the expansion exponent, used to increase the lines array exponentially
+ int lineCount = 0;
+ Color lineBackgrounds[];
+
+/**
+ * Creates a new default line styler.
+ * <p>
+ *
+ * @param content the text to which the styles apply
+ */
+public DefaultLineStyler(StyledTextContent content) {
+ this.content = content;
+ lineCount = content.getLineCount();
+ lineBackgrounds = new Color[lineCount];
+}
+/**
+ * Inserts a style at the given location.
+ * <p>
+ *
+ * @param style the new style
+ * @param index the index at which to insert the style (the new style
+ * will reside at this index)
+ *
+ */
+void insertStyle(StyleRange style, int index) {
+ int size = styles.length;
+ if (styleCount == size) {
+ // expand the styles array by powers of 2
+ StyleRange[] newStyles = new StyleRange[size+(int)Math.pow(2, styleExpandExp)];
+ System.arraycopy(styles, 0, newStyles, 0, size);
+ styles = newStyles;
+ styleExpandExp++;
+ }
+ // shift the styles down to make room for the new style
+ for (int i=styleCount-1; i>=index; i--) {
+ styles[i+1]=styles[i];
+ }
+ styles[index] = style;
+ styleCount++;
+}
+/**
+ * Inserts a style, merging it with adjacent styles if possible.
+ * <p>
+ *
+ * @param style the new style
+ * @param index the index at which to insert the style (the new style
+ * will reside at this index)
+ * @return true if the style was inserted, false if the style was merged with an adjacent
+ * style
+ */
+boolean insertMergeStyle(StyleRange style, int index) {
+ if (mergeStyleBefore(style, index)) return false;
+ if (mergeStyleAfter(style, index)) return false;
+ insertStyle(style, index);
+ return true;
+}
+/**
+ * Merges the style with the style before it if possible.
+ * <p>
+ *
+ * @param style the new style
+ * @param index the index at which to attempt the merge.
+ * @return true if the style was merged, false otherwise
+ */
+boolean mergeStyleBefore(StyleRange style, int index) {
+ // see if the style is similar to the style before it and merge the
+ // styles if possible
+ if (index > 0) {
+ StyleRange previous = styles[index-1];
+ if (style.similarTo(previous)) {
+ // the start of style needs to be in the range of the previous style
+ // and the end of style needs to be < the start of the next style
+ int previousEnd = previous.start + previous.length;
+ if ((style.start <= previousEnd) && (style.start >= previous.start)) {
+ int styleEnd = style.start + style.length;
+ if ((index == styleCount) || (styleEnd <= styles[index].start)) {
+ previous.length = style.start + style.length - previous.start;
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+/**
+ * Merges the style with the style after it if possible.
+ * <p>
+ *
+ * @param style the new style
+ * @param index the index at which to attempt the merge.
+ * @return true if the style was merged, false otherwise
+ */
+boolean mergeStyleAfter(StyleRange style, int index) {
+ // see if the style is similar to the style that will be after it and
+ // merge the styles if possible
+ if (index < styleCount) {
+ StyleRange next = styles[index];
+ if (style.similarTo(next)) {
+ // the end of style needs to be in the range of the next style and
+ // the start of style needs to be > the end of the previous style
+ int styleEnd = style.start + style.length;
+ int nextEnd = next.start + next.length;
+ if ((styleEnd <= nextEnd) && (styleEnd >= next.start)) {
+ if ((index == 0) || (style.start >= styles[index-1].start + styles[index-1].length)) {
+ next.length = next.start + next.length - style.start;
+ next.start = style.start;
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+/**
+ * Removes style information that is defined for the range of text in <code>clearStyle</code>.
+ * <p>
+ *
+ * @param clearStyle the style information to use for clearing
+ */
+void clearStyle(StyleRange clearStyle) {
+ Point pt = getOverlappingStyles(clearStyle.start, clearStyle.length);
+ int clearStyleEnd = clearStyle.start + clearStyle.length - 1;
+
+ // no overlapped styles exist
+ if ((pt == null) || (pt.y == 0)) return;
+
+ // the newStyle overlaps one or more of the existing styles
+ // pt.x is the index of the first overlapped style, pt.y is the number of overlapped
+ // styles
+ int count = 0;
+ for (int i=pt.x; count<pt.y; i++) {
+ StyleRange overlap = styles[i];
+ int overlapEnd = overlap.start + overlap.length - 1;
+ if (overlap.start < clearStyle.start) {
+ if (overlapEnd <= clearStyleEnd) {
+ // the end of overlap needs to be cleared
+ overlap.length=clearStyle.start - overlap.start;
+ } else {
+ // middle of overlap needs to be cleared, this will
+ // cause overlap to be broken into two
+ StyleRange endStyle = (StyleRange)overlap.clone();
+ endStyle.start = clearStyleEnd + 1;
+ endStyle.length = overlapEnd - clearStyleEnd;
+ overlap.length = clearStyle.start - overlap.start;
+ insertStyle(endStyle, i+1);
+ break;
+ }
+ } else {
+ if (overlapEnd <= clearStyleEnd) {
+ // entire overlap needs to be cleared
+ deleteStyle(i);
+ i--;
+ } else {
+ // beginning of overlap needs to be cleared
+ overlap.start=clearStyleEnd + 1;
+ overlap.length=overlapEnd - overlap.start + 1;
+ break;
+ }
+ }
+ count++;
+ }
+}
+/**
+ * Increases the <code>linebackgrounds</code> array to accomodate new line background
+ * information.
+ * <p>
+ *
+ * @param numLines the number to increase the array by
+ */
+void expandLinesBy(int numLines) {
+ int size = lineBackgrounds.length;
+ if (size - lineCount >= numLines) {
+ return;
+ }
+ Color[] newLines = new Color[size+Math.max((int)Math.pow(2, lineExpandExp), numLines)];
+ System.arraycopy(lineBackgrounds, 0, newLines, 0, size);
+ lineBackgrounds = newLines;
+ lineExpandExp++;
+}
+/**
+ * Deletes the style at <code>index</code>.
+ * <p>
+ *
+ * @param index the index of the style to be deleted
+ */
+void deleteStyle(int index) {
+ // move the styles up
+ for (int i=index+1; i<styleCount; i++) {
+ styles[i-1] = styles[i];
+ }
+ styles[styleCount-1]=null;
+ styleCount--;
+}
+/**
+ * Returns the styles that are defined.
+ * <p>
+ *
+ * @return the copied array of styles
+ */
+StyleRange [] getStyleRanges() {
+ StyleRange[] newStyles = new StyleRange[styleCount];
+ System.arraycopy(styles, 0, newStyles, 0, styleCount);
+ return newStyles;
+}
+/**
+ * Handles the get line background color callback.
+ * <p>
+ *
+ * @param event.lineOffset line number (input)
+ * @param event.lineText line text (input)
+ * @param event.background line background color (output)
+ */
+public void lineGetBackground(LineBackgroundEvent event) {
+ int lineIndex = content.getLineAtOffset(event.lineOffset);
+ // 1GDX9PN
+ if (lineIndex > (lineBackgrounds.length - 1)) event.lineBackground = null;
+ else event.lineBackground = lineBackgrounds[lineIndex];
+}
+/**
+ * Handles the get line style information callback.
+ * <p>
+ *
+ * @param event.lineOffset line number (input)
+ * @param event.lineText line text (input)
+ * @param event.styles array of StyleRanges, need to be in order (output)
+ */
+public void lineGetStyle(LineStyleEvent event) {
+ int lineStart = event.lineOffset;
+ int lineEnd = lineStart + event.lineText.length();
+
+ int high = searchForStyle(lineStart, lineEnd);
+ StyleRange style = null;
+ Vector lineStyles = new Vector();
+
+ // index will represent a style that
+ // -- starts after the line (end processing)
+ // -- ends before the line (continue processing)
+ // -- starts before the line, ends in the line (add range)
+ // -- starts in the line, ends in the line (add range)
+ // -- starts in the line, ends after the line (add range)
+ // -- starts before the line, ends after the line (add range)
+ for (int index = high; index < styleCount; index++) {
+ style = styles[index];
+ if (style.start > lineEnd)
+ // style starts after the line, end looping
+ break;
+ int styleEnd = style.start + style.length - 1;
+ if (styleEnd >= lineStart) lineStyles.add(style);
+ }
+ event.styles = new StyleRange[lineStyles.size()];
+ lineStyles.copyInto(event.styles);
+}
+/**
+ * Searches for the first style in the <code>start</code> - <code>end</code> range.
+ * <p>
+ *
+ * @return the index of the first style that overlaps the input range
+ */
+int searchForStyle(int start, int end) {
+ int high = styleCount;
+ int low = -1;
+ int index = high;
+ // find the index of the first style for the given range, use a binary search
+ while (high - low > 1) {
+ index = (high + low) / 2;
+ StyleRange style = styles[index];
+ int styleEnd = style.start + style.length - 1;
+ if (start <= style.start || end <= styleEnd || (start > style.start && styleEnd >= start && styleEnd < end)) {
+ high = index;
+ }
+ else {
+ low = index;
+ }
+ }
+ return high;
+}
+/**
+ * Updates the line background colors to reflect a new color. Called by StyledText.
+ * <p>
+ *
+ * @param startLine index of the first line to color
+ * @param lineCount number of lines to color starting at startLine
+ * @param background the background color for the lines
+ */
+void setLineBackground(int startLine, int count, Color background) {
+ for (int i=startLine; i<startLine + count; i++) {
+ lineBackgrounds[i]=background;
+ }
+}
+/**
+ * Update the styles to reflect the new style. <code>newStyle</code> will
+ * replace any old style for the range. When this method is called, the
+ * DefaultLineStyler may merge the new style with an existing style (if possible).
+ * Called by StyledText when a style is added. Called by StyledText.
+ * <p>
+ *
+ * @param newStyle the new style information.
+ */
+void setStyleRange(StyleRange newStyle) {
+ if (newStyle == null) {
+ styles = new StyleRange[0];
+ styleExpandExp = 1;
+ styleCount = 0;
+ return;
+ }
+ if (newStyle.length ==0) return;
+ if (newStyle.isUnstyled()) {
+ clearStyle(newStyle);
+ return;
+ }
+
+ Point pt = getOverlappingStyles(newStyle.start, newStyle.length);
+ int newStyleEnd = newStyle.start + newStyle.length - 1;
+
+ // no styles exist
+ if (pt == null) {
+ insertStyle(newStyle, 0);
+ return;
+ }
+
+ // newStyle does not overlap any other styles
+ if (pt.y == 0) {
+ insertMergeStyle(newStyle, pt.x);
+ return;
+ }
+
+ // the newStyle overlaps one or more of the existing styles
+ boolean added = false; // indicates whether or not the new style has been added
+ int count = 0;
+ // pt.x is the index of the first overlapped style, pt.y is the number of overlapped
+ // styles
+ for (int i=pt.x; count<pt.y; i++) {
+ StyleRange overlap = styles[i];
+ int overlapEnd = overlap.start + overlap.length - 1;
+ if (overlap.start < newStyle.start) {
+ if (overlapEnd <= newStyleEnd) {
+ // the end of overlap needs to be replaced by newStyle
+ if (newStyle.similarTo(overlap)) {
+ // update overlap to accomodate the new style
+ overlap.length = newStyle.start + newStyle.length - overlap.start;
+ } else {
+ overlap.length=newStyle.start - overlap.start;
+ // see if newStyle can be merged with the style after overlap, if so,
+ // processing is done
+ if (mergeStyleAfter(newStyle, i+1)) break;
+ // otherwise, insert the newStyle, newStyle may still overlap other
+ // styles after it so continue processing
+ insertStyle(newStyle, i+1);
+ i++;
+ }
+ added = true;
+ } else {
+ // middle of overlap needs to be replaced by newStyle, this will
+ // cause overlap to be broken into two
+ if (newStyle.similarTo(overlap)) break;
+ StyleRange endStyle = (StyleRange)overlap.clone();
+ endStyle.start = newStyleEnd + 1;
+ endStyle.length = overlapEnd - newStyleEnd;
+ overlap.length = newStyle.start - overlap.start;
+ insertStyle(newStyle, i+1);
+ i++;
+ insertStyle(endStyle, i+1);
+ // when newStyle overlaps the middle of a style, this implies that
+ // processing is done (no more overlapped styles)
+ break;
+ }
+ } else {
+ if (overlapEnd <= newStyleEnd) {
+ // overlap will be replaced by the newStyle, make sure newStyle
+ // hasn't already been added, if it has just delete overlap
+ if (!added) {
+ styles[i] = newStyle;
+ added = true;
+ } else {
+ deleteStyle(i);
+ i--;
+ }
+ } else {
+ // beginning of overlap needs to be replaced by newStyle
+ overlap.start=newStyleEnd + 1;
+ overlap.length=overlapEnd - overlap.start + 1;
+ if (!added) {
+ insertMergeStyle(newStyle, i);
+ }
+ // when newStyle overlaps only the beginning of a style, this implies
+ // that processing is done (no more overlapped styles)
+ break;
+ }
+ }
+ count++;
+ }
+}
+/**
+ * Sets the array of styles and discards old styles. Called by StyledText.
+ * <p>
+ *
+ * @param styles the new styles, must be in order and non-overlapping
+ */
+void setStyleRanges(StyleRange[] styles) {
+ this.styles = new StyleRange[styles.length];
+ System.arraycopy(styles, 0, this.styles, 0, styles.length);
+ styleCount = styles.length;
+ styleExpandExp = 1;
+}
+/**
+ * Updates the style ranges and line backgrounds to reflect a pending text
+ * change.
+ * Called by StyledText when a TextChangingEvent is received.
+ * <p>
+ *
+ * @param event the event with the text change information
+ */
+public void textChanging(TextChangingEvent event) {
+ int startLine = content.getLineAtOffset(event.start);
+ int startLineOffset = content.getOffsetAtLine(startLine);
+
+ textChanging(event.start, -event.replaceCharCount);
+ textChanging(event.start, event.newCharCount);
+
+ if (event.replaceCharCount == content.getCharCount()) {
+ // all text is going to be replaced, clear line backgrounds
+ linesChanging(0, -lineCount);
+ linesChanging(0, content.getLineCount() - event.replaceLineCount + event.newLineCount);
+ return;
+ }
+
+ if (event.start != startLineOffset) {
+ startLine = startLine + 1;
+ }
+
+ linesChanging(startLine, -event.replaceLineCount);
+ linesChanging(startLine, event.newLineCount);
+}
+/*
+ * Updates the line backgrounds to reflect a pending text change.
+ * <p>
+ *
+ * @param start the starting line of the change that is about to take place
+ * @param delta the number of lines in the change, > 0 indicates lines inserted,
+ * < 0 indicates lines deleted
+ */
+void linesChanging(int start, int delta) {
+ if (delta == 0) return;
+ boolean inserting = delta > 0;
+ if (inserting) {
+ // shift the lines down to make room for new lines
+ expandLinesBy(delta);
+ for (int i = lineCount-1; i >= start; i--) {
+ lineBackgrounds[i + delta]=lineBackgrounds[i];
+ }
+ for (int i=start; i<start + delta; i++) {
+ lineBackgrounds[i]=null;
+ }
+ } else {
+ // shift up the lines
+ for (int i = start - delta; i < lineCount; i++) {
+ lineBackgrounds[i+delta]=lineBackgrounds[i];
+ }
+ }
+ lineCount += delta;
+}
+/*
+ * Updates the style ranges to reflect a text change.
+ * <p>
+ *
+ * @param start the starting offset of the change that is about to
+ * take place
+ * @param delta the length of the change, > 0 indicates text inserted,
+ * < 0 indicates text deleted
+ */
+void textChanging(int start, int delta) {
+ if (delta == 0) return;
+ StyleRange style;
+ // find the index of the first style for the given offset, use a binary search
+ // to find the index
+ int end;
+ boolean inserting = delta > 0;
+ if (inserting) {
+ end = (start + delta) - 1;
+ } else {
+ end = (start - delta) - 1;
+ }
+ int high = searchForStyle(start, end);
+ int index;
+ // update the styles that are in the affected range
+ for (index = high; index < styleCount; index++) {
+ style = styles[index];
+ if (inserting) {
+ if (style.start >= start) break;
+ // in the insert case only one style range will be directly affected,
+ // it will need to be split into two and then the newStyle inserted
+ StyleRange beforeStyle = (StyleRange)style.clone();
+ beforeStyle.length = start - style.start;
+ style.start = start;
+ style.length = style.length - beforeStyle.length;
+ if (beforeStyle.length != 0) insertStyle(beforeStyle, index);
+ index++;
+ break;
+ } else {
+ int styleEnd = style.start + style.length - 1;
+ if (style.start > end) break;
+ // in the delete case, any style that overlaps the change range will be
+ // affected
+ if (style.start < start) {
+ if (styleEnd <= end) {
+ // style starts before change range, ends in change range
+ style.length = start - style.start;
+ } else {
+ // style starts before change range, ends after change range
+ style.length = style.length + delta;
+ index++;
+ break;
+ }
+ } else {
+ if (styleEnd <= end) {
+ // style starts in change range, ends in change range
+ deleteStyle(index);
+ index--;
+ } else {
+ // style starts in change range, ends after change range
+ style.start = start;
+ style.length = styleEnd - end;
+ index++;
+ break;
+ }
+ }
+ }
+ }
+ // change the offsets of the styles after the affected styles
+ for (int i = index ; i < styleCount; i++) {
+ style = styles[i];
+ style.start = style.start + delta;
+ }
+}
+/**
+ * Returns the indexes of the styles that overlap the given range. Styles that partially
+ * or fully overlap the range will be returned.
+ * <p>
+ *
+ * @return Point where x is the index of the starting overlap style, y is the number of
+ * styles that overlap the range
+ */
+Point getOverlappingStyles(int start, int length) {
+ StyleRange style;
+ if (styleCount == 0) return null;
+ // find the index of the first style for the given offset, use a binary search
+ // to find the index
+ int end = start + length - 1;
+ int high = searchForStyle(start, end);
+ int count = 0;
+ for (int index = high; index < styleCount; index++) {
+ style = styles[index];
+ int styleEnd = style.start + style.length - 1;
+ if (style.start > end) break;
+ if (styleEnd >= start) count++;
+ }
+ return new Point(high, count);
+}
+/**
+ * Returns the background color of a line. Called by StyledText. It is safe to return
+ * the existing Color object since the colors are set and managed by the client.
+ * <p>
+ *
+ * @param index the line index
+ * @return the background color of the line at the given index
+ */
+Color getLineBackground(int index) {
+ return lineBackgrounds[index];
+}
+/**
+ * Returns the style for the character at <code>offset</code>. Called by StyledText.
+ * Returns a new style. Does not return the existing style.
+ * <p>
+ *
+ * @param offset the character position in the text
+ * @return a cloned StyleRange with start == offset and length == 1 if a style is
+ * specified or null if no style is specified
+ */
+StyleRange getStyleRangeAtOffset(int offset) {
+ if (styleCount == 0) return null;
+ Point pt = getOverlappingStyles(offset, 1);
+ if (pt == null || pt.y == 0) return null;
+ StyleRange newStyle = (StyleRange)styles[pt.x].clone();
+ newStyle.start = offset;
+ newStyle.length = 1;
+ return newStyle;
+}
+/**
+ * Returns the styles for the given range. Returns the existing styles,
+ * so be careful not to modify the return value. Styles are not cloned
+ * in order to make this method as efficient as possible.
+ * <p>
+ *
+ * @param offset the start position of the text range
+ * @param length the length of the text range
+ * @return a StyleRange array or null if no styles are specified for the text
+ * range
+ */
+StyleRange[] getStyleRangesFor(int offset, int length) {
+ if (styleCount == 0) return null;
+ Point pt = getOverlappingStyles(offset, length);
+ if (pt == null || pt.y == 0) return null;
+ StyleRange[] ranges = new StyleRange[pt.y];
+ for (int i=0; i<pt.y; i++) {
+ StyleRange newStyle = styles[pt.x + i];
+ ranges[i]=newStyle;
+ }
+ return ranges;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ExtendedModifyEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ExtendedModifyEvent.java
new file mode 100644
index 0000000000..517471267d
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ExtendedModifyEvent.java
@@ -0,0 +1,23 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.*;
+
+/**
+ * This event is sent after a text change occurs.
+ */
+public final class ExtendedModifyEvent extends TypedEvent {
+ public int start; // start offset of the new text
+ public int length; // length of the new text
+ public String replacedText; // replaced text or empty string if no text was replaced
+
+public ExtendedModifyEvent(StyledTextEvent e) {
+ super(e);
+ start = e.start;
+ length = e.end - e.start;
+ replacedText = e.text;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ExtendedModifyListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ExtendedModifyListener.java
new file mode 100644
index 0000000000..59952fcdda
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ExtendedModifyListener.java
@@ -0,0 +1,21 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import java.util.EventListener;
+
+public interface ExtendedModifyListener extends EventListener {
+/**
+ * This method is called after a text change occurs.
+ * <p>
+ *
+ * @param event.start the start offset of the new text (input)
+ * @param event.length the length of the new text (input)
+ * @param event.replacedText the replaced text (input)
+ */
+public void modifyText(ExtendedModifyEvent event);
+}
+
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineBackgroundEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineBackgroundEvent.java
new file mode 100644
index 0000000000..711c84302d
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineBackgroundEvent.java
@@ -0,0 +1,25 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+
+/**
+ * This event is sent when a line is about to be drawn.
+ */
+public class LineBackgroundEvent extends TypedEvent {
+ public int lineOffset; // line start offset
+ public String lineText; // line text
+ public Color lineBackground; // line background color
+
+public LineBackgroundEvent(StyledTextEvent e) {
+ super(e);
+ lineOffset = e.detail;
+ lineText = e.text;
+}
+}
+
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineBackgroundListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineBackgroundListener.java
new file mode 100644
index 0000000000..9607851c96
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineBackgroundListener.java
@@ -0,0 +1,23 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+
+import java.util.*;
+
+
+public interface LineBackgroundListener extends EventListener {
+
+/**
+ * This method is called when a line is about to be drawn in order to get its
+ * background color.
+ * <p>
+ *
+ * @param event.lineOffset line start offset (input)
+ * @param event.lineText line text (input)
+ * @param event.lineBackground line background color (output)
+ */
+public void lineGetBackground(LineBackgroundEvent event);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineStyleEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineStyleEvent.java
new file mode 100644
index 0000000000..86a7e0c7a6
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineStyleEvent.java
@@ -0,0 +1,24 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+
+/**
+ * This event is sent when a line is about to be drawn.
+ */
+public class LineStyleEvent extends TypedEvent {
+ public int lineOffset; // line start offset
+ public String lineText; // line text
+ public StyleRange[] styles; // array of StyleRanges
+
+public LineStyleEvent(StyledTextEvent e) {
+ super(e);
+ lineOffset = e.detail;
+ lineText = e.text;
+ styles = e.styles;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineStyleListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineStyleListener.java
new file mode 100644
index 0000000000..23fc3b518e
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/LineStyleListener.java
@@ -0,0 +1,20 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import java.util.*;
+
+public interface LineStyleListener extends EventListener {
+/**
+ * This method is called when a line is about to be drawn in order to get the
+ * line's style information.
+ * <p>
+ *
+ * @param event.lineOffset line start offset (input)
+ * @param event.lineText line text (input)
+ * @param event.styles array of StyleRanges, need to be in order (output)
+ */
+public void lineGetStyle(LineStyleEvent event);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/PopupList.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/PopupList.java
new file mode 100644
index 0000000000..5f650a3396
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/PopupList.java
@@ -0,0 +1,248 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+/**
+* A PopupList is a list of selectable items that appears in its own shell positioned above
+* its parent shell. It it used for selecting items when editing a Table cell (similar to the
+* list that appears when you open a Combo box).
+*
+* The list will be positioned so that does not run off the screen and the largest number of items
+* are visible. It may appear above the current cursor location or below it depending how close you
+* are to the edge of the screen.
+*/
+public class PopupList {
+ private Shell shell;
+ private List list;
+ private int minimumWidth;
+/**
+* Creates a PopupList above the specified shell.
+*/
+public PopupList(Shell parent) {
+
+ shell = new Shell(parent, 0);
+
+ list = new List(shell, SWT.SINGLE | SWT.V_SCROLL);
+
+ // close dialog if user selects outside of the shell
+ shell.addListener(SWT.Deactivate, new Listener() {
+ public void handleEvent(Event e){
+ shell.setVisible (false);
+ };
+ });
+
+ // resize shell when list resizes
+ shell.addControlListener(new ControlListener() {
+ public void controlMoved(ControlEvent e){}
+ public void controlResized(ControlEvent e){
+ Rectangle shellSize = shell.getClientArea();
+ list.setSize(shellSize.width, shellSize.height);
+ }
+ });
+
+ // return list selection on Mouse Up or Carriage Return
+ list.addMouseListener(new MouseListener() {
+ public void mouseDoubleClick(MouseEvent e){};
+ public void mouseDown(MouseEvent e){};
+ public void mouseUp(MouseEvent e){
+ shell.setVisible (false);
+ };
+ });
+ list.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent e){};
+ public void keyPressed(KeyEvent e){
+ if (e.character == '\r'){
+ shell.setVisible (false);
+ }
+ };
+ });
+
+}
+/**
+* Gets the widget font.
+* <p>
+* @return the widget font
+*
+* @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 Font getFont () {
+ return list.getFont();
+}
+/**
+* Gets the items.
+* <p>
+* This operation will fail if the items cannot
+* be queried from the OS.
+*
+* @return the items in the widget
+*
+* @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_CANNOT_GET_ITEM when the operation fails</li>
+* </ul>
+*/
+public String[] getItems () {
+ return list.getItems();
+}
+/**
+* Gets the minimum width of the list.
+*
+* @return the minimum width of the list
+*/
+public int getMinimumWidth () {
+ return minimumWidth;
+}
+/**
+* Launches the Popup List, waits for an item to be selected and then closes PopupList.
+*
+* @param rect the initial size and location of the PopupList; the dialog will be
+* positioned so that it does not run off the screen and the largest number of items are visible
+*
+* @return the text of the selected item or null if no item is selected
+*/
+public String open (Rectangle rect) {
+
+ Point listSize = list.computeSize (rect.width, SWT.DEFAULT);
+ Rectangle screenSize = shell.getDisplay().getBounds();
+
+ // Position the dialog so that it does not run off the screen and the largest number of items are visible
+ int spaceBelow = screenSize.height - (rect.y + rect.height) - 30;
+ int spaceAbove = rect.y - 30;
+
+ int y = 0;
+ if (spaceAbove > spaceBelow && listSize.y > spaceBelow) {
+ // place popup list above table cell
+ if (listSize.y > spaceAbove){
+ listSize.y = spaceAbove;
+ } else {
+ listSize.y += 2;
+ }
+ y = rect.y - listSize.y;
+
+ } else {
+ // place popup list below table cell
+ if (listSize.y > spaceBelow){
+ listSize.y = spaceBelow;
+ } else {
+ listSize.y += 2;
+ }
+ y = rect.y + rect.height;
+ }
+
+ // Make dialog as wide as the cell
+ listSize.x = rect.width;
+ // dialog width should not be les than minimumwidth
+ if (listSize.x < minimumWidth)
+ listSize.x = minimumWidth;
+
+ // Align right side of dialog with right side of cell
+ int x = rect.x + rect.width - listSize.x;
+
+ shell.setBounds(x, y, listSize.x, listSize.y);
+
+ shell.open();
+ list.setFocus();
+
+ Display display = shell.getDisplay();
+ while (!shell.isDisposed () && shell.isVisible ()) {
+ if (!display.readAndDispatch()) display.sleep();
+ }
+
+ String result = null;
+ if (!shell.isDisposed ()) {
+ String [] strings = list.getSelection ();
+ shell.dispose();
+ if (strings.length != 0) result = strings [0];
+ }
+ return result;
+}
+/**
+* Selects an item with text that starts with specified String.
+* <p>
+* If the item is not currently selected, it is selected.
+* If the item at an index is selected, it remains selected.
+* If the string is not matched, it is ignored.
+*
+* @param string the text of the item
+*
+* @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 select(String string) {
+ String[] items = list.getItems();
+
+ // find the first entry in the list that starts with the
+ // specified string
+ if (string != null){
+ for (int i = 0; i < items.length; i++) {
+ if (items[i].startsWith(string)){
+ int index = list.indexOf(items[i]);
+ list.select(index);
+ break;
+ }
+ }
+ }
+}
+/**
+* Sets the widget font.
+* <p>
+* When new font is null, the font reverts
+* to the default system font for the widget.
+*
+* @param font the new font (or null)
+*
+* @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 setFont (Font font) {
+ list.setFont(font);
+}
+/**
+* Sets all items.
+* <p>
+* The previous selection is cleared.
+* The previous items are deleted.
+* The new items are added.
+* The top index is set to 0.
+*
+* @param items the array of items
+*
+* This operation will fail when an item is null
+* or could not be added in the OS.
+*
+* @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 items is null</li>
+* <li>ERROR_ITEM_NOT_ADDED when the operation fails</li>
+* </ul>
+*/
+public void setItems (String[] strings) {
+ list.setItems(strings);
+}
+/**
+* Sets the minimum width of the list.
+*
+* @param width the minimum width of the list
+*/
+public void setMinimumWidth (int width) {
+ if (width < 0)
+ throw new SWTError(SWT.ERROR_INVALID_ARGUMENT);
+
+ minimumWidth = width;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ST.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ST.java
new file mode 100644
index 0000000000..5be042724e
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ST.java
@@ -0,0 +1,56 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+
+/**
+ * This class provides access to the public constants provided by <code>StyledText</code>.
+ */
+public class ST {
+
+ /* StyledText key action constants */
+ /* Navigation */
+ public static final int LINE_UP = SWT.ARROW_UP;
+ public static final int LINE_DOWN = SWT.ARROW_DOWN;
+ public static final int LINE_START = SWT.HOME;
+ public static final int LINE_END = SWT.END;
+ public static final int COLUMN_PREVIOUS = SWT.ARROW_LEFT;
+ public static final int COLUMN_NEXT = SWT.ARROW_RIGHT;
+ public static final int PAGE_UP = SWT.PAGE_UP;
+ public static final int PAGE_DOWN = SWT.PAGE_DOWN;
+ public static final int WORD_PREVIOUS = SWT.ARROW_LEFT | SWT.CTRL;
+ public static final int WORD_NEXT = SWT.ARROW_RIGHT | SWT.CTRL;
+ public static final int TEXT_START = SWT.HOME | SWT.CTRL;
+ public static final int TEXT_END = SWT.END | SWT.CTRL;
+ public static final int WINDOW_START = SWT.PAGE_UP | SWT.CTRL;
+ public static final int WINDOW_END = SWT.PAGE_DOWN | SWT.CTRL;
+
+ /* Selection */
+ public static final int SELECT_LINE_UP = SWT.ARROW_UP | SWT.SHIFT;
+ public static final int SELECT_LINE_DOWN = SWT.ARROW_DOWN | SWT.SHIFT;
+ public static final int SELECT_LINE_START = SWT.HOME | SWT.SHIFT;
+ public static final int SELECT_LINE_END = SWT.END | SWT.SHIFT;
+ public static final int SELECT_COLUMN_PREVIOUS = SWT.ARROW_LEFT | SWT.SHIFT;
+ public static final int SELECT_COLUMN_NEXT = SWT.ARROW_RIGHT | SWT.SHIFT;
+ public static final int SELECT_PAGE_UP = SWT.PAGE_UP | SWT.SHIFT;
+ public static final int SELECT_PAGE_DOWN = SWT.PAGE_DOWN | SWT.SHIFT;
+ public static final int SELECT_WORD_PREVIOUS = SWT.ARROW_LEFT | SWT.CTRL | SWT.SHIFT;
+ public static final int SELECT_WORD_NEXT = SWT.ARROW_RIGHT | SWT.CTRL | SWT.SHIFT;
+ public static final int SELECT_TEXT_START = SWT.HOME | SWT.CTRL | SWT.SHIFT;
+ public static final int SELECT_TEXT_END = SWT.END | SWT.CTRL | SWT.SHIFT;
+ public static final int SELECT_WINDOW_START = SWT.PAGE_UP | SWT.CTRL| SWT.SHIFT;
+ public static final int SELECT_WINDOW_END = SWT.PAGE_DOWN | SWT.CTRL | SWT.SHIFT;
+
+ /* Modification */
+ public static final int CUT = SWT.DEL | SWT.SHIFT;
+ public static final int COPY = SWT.INSERT | SWT.CTRL;
+ public static final int PASTE = SWT.INSERT | SWT.SHIFT;
+ public static final int DELETE_PREVIOUS = SWT.BS;
+ public static final int DELETE_NEXT = SWT.DEL;
+
+ /* Miscellaneous */
+ public static final int TOGGLE_OVERWRITE = SWT.INSERT;
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/SashForm.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/SashForm.java
new file mode 100644
index 0000000000..86abf0b90b
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/SashForm.java
@@ -0,0 +1,397 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.graphics.*;
+
+/**
+ * The SashForm lays out its children in a Row or Column arrangement (as specified
+ * by the orientation) and places a Sash between the children.
+ * One child may be maximized to occupy the entire size of the SashForm.
+ * The relative sizes of the children may be specfied using weights.
+ *
+ * <p>
+ * <dl>
+ * <dt><b>Styles:</b><dd>HORIZONTAL, VERTICAL
+ * </dl>
+ */
+public class SashForm extends Composite {
+
+ public int SASH_WIDTH = 3;
+
+ private static final int DRAG_MINIMUM = 20;
+
+ private int orientation = SWT.HORIZONTAL;
+ private Sash[] sashes = new Sash[0];
+ private Control[] controls = new Control[0];
+ private Control maxControl = null;
+ private Listener sashListener;
+
+public SashForm(Composite parent, int style) {
+ super(parent, checkStyle(style));
+ if ((style & SWT.VERTICAL) != 0){
+ orientation = SWT.VERTICAL;
+ }
+
+ this.addListener(SWT.Resize, new Listener() {
+ public void handleEvent(Event e) {
+ layout(true);
+ }
+ });
+
+ sashListener = new Listener() {
+ public void handleEvent(Event e) {
+ onDragSash(e);
+ }
+ };
+}
+private static int checkStyle (int style) {
+ int mask = SWT.BORDER;
+ return style & mask;
+}
+public Point computeSize (int wHint, int hHint, boolean changed) {
+
+ Control[] controls = getControls(true);
+ if (controls.length == 0) return new Point(wHint, hHint);
+
+ int width = 0;
+ int height = 0;
+ boolean vertical = (getStyle() & SWT.VERTICAL) != 0;
+ if (vertical) {
+ width = wHint;
+ height += (controls.length - 1) * SASH_WIDTH;
+ } else {
+ height = hHint;
+ width += controls.length *SASH_WIDTH;
+ }
+ for (int i = 0; i < controls.length; i++) {
+ if (vertical) {
+ Point size = controls[i].computeSize(wHint, SWT.DEFAULT);
+ height += size.y;
+ } else {
+ Point size = controls[i].computeSize(SWT.DEFAULT, hHint);
+ width += size.x;
+ }
+ }
+ if (wHint != SWT.DEFAULT) width = wHint;
+ if (hHint != SWT.DEFAULT) height = hHint;
+
+ return new Point(width, height);
+}
+/**
+ * Answer SWT.HORIZONTAL if the controls in the SashForm are laid out side by side.
+ * Answer SWT.VERTICAL if the controls in the SashForm are laid out top to bottom.
+ */
+public int getOrientation() {
+ return orientation;
+}
+/**
+ * Answer the control that currently is maximized in the SashForm. This value may be null.
+ */
+public Control getMaximizedControl(){
+ return this.maxControl;
+}
+/**
+ * Answer the relative weight of each child in the SashForm. The weight represents the
+ * percent of the total width (if SashForm has Horizontal orientation) or
+ * total height (if SashForm has Vertical orientation) each control occupies.
+ * The weights are returned in order of the creation of the widgets (weight[0]
+ * corresponds to the weight of the first child created).
+ */
+
+public int[] getWeights() {
+ Control[] cArray = getControls(false);
+ float[] ratios = new float[cArray.length];
+ for (int i = 0; i < cArray.length; i++) {
+ Float ratio = (Float)cArray[i].getData("layout ratio");
+ if (ratio != null) {
+ ratios[i] = ratio.floatValue();
+ } else {
+ ratios[i] = (float)0.2;
+ }
+ }
+
+ int[] weights = new int[cArray.length];
+ for (int i = 0; i < weights.length; i++) {
+ weights[i] = (int)(ratios[i] * 1000);
+ }
+ return weights;
+}
+private Control[] getControls(boolean onlyVisible) {
+ Control[] children = getChildren();
+ Control[] controls = new Control[0];
+ for (int i = 0; i < children.length; i++) {
+ if (children[i] instanceof Sash) continue;
+ if (onlyVisible && !children[i].getVisible()) continue;
+
+ Control[] newControls = new Control[controls.length + 1];
+ System.arraycopy(controls, 0, newControls, 0, controls.length);
+ newControls[controls.length] = children[i];
+ controls = newControls;
+ }
+ return controls;
+}
+public void layout(boolean changed) {
+ Rectangle area = getClientArea();
+ if (area.width == 0 || area.height == 0) return;
+
+ Control[] newControls = getControls(true);
+ if (controls.length == 0 && newControls.length == 0) return;
+ controls = newControls;
+
+ if (maxControl != null && !maxControl.isDisposed()) {
+ for (int i= 0; i < controls.length; i++){
+ if (controls[i] != maxControl) {
+ controls[i].setBounds(-200, -200, 0, 0);
+ } else {
+ controls[i].setBounds(area);
+ }
+ }
+ return;
+ }
+
+ // keep just the right number of sashes
+ if (sashes.length < controls.length - 1) {
+ Sash[] newSashes = new Sash[controls.length - 1];
+ System.arraycopy(sashes, 0, newSashes, 0, sashes.length);
+ int sashOrientation = (orientation == SWT.HORIZONTAL) ? SWT.VERTICAL : SWT.HORIZONTAL;
+ for (int i = sashes.length; i < newSashes.length; i++) {
+ newSashes[i] = new Sash(this, sashOrientation);
+ newSashes[i].addListener(SWT.Selection, sashListener);
+ }
+ sashes = newSashes;
+ }
+ if (sashes.length > controls.length - 1) {
+ if (controls.length == 0) {
+ for (int i = 0; i < sashes.length; i++) {
+ sashes[i].dispose();
+ }
+ sashes = new Sash[0];
+ } else {
+ Sash[] newSashes = new Sash[controls.length - 1];
+ System.arraycopy(sashes, 0, newSashes, 0, newSashes.length);
+ for (int i = controls.length - 1; i < sashes.length; i++) {
+ sashes[i].dispose();
+ }
+ sashes = newSashes;
+ }
+ }
+
+ if (controls.length == 0) return;
+
+ // get the ratios
+ float[] ratios = new float[controls.length];
+ float total = 0;
+ for (int i = 0; i < controls.length; i++) {
+ Float ratio = (Float)controls[i].getData("layout ratio");
+ if (ratio != null) {
+ ratios[i] = ratio.floatValue();
+ } else {
+ ratios[i] = (float)0.2;
+ }
+ total += ratios[i];
+ }
+
+ if (orientation == SWT.HORIZONTAL) {
+ total += (float)sashes.length * ((float)SASH_WIDTH / (float)area.width);
+ } else {
+ total += (float)sashes.length * ((float)SASH_WIDTH / (float)area.height);
+ }
+
+ if (orientation == SWT.HORIZONTAL) {
+ int width = (int)((ratios[0] / total) * (float)area.width);
+ int x = area.x;
+ controls[0].setBounds(x, area.y, width, area.height);
+ x += width;
+ for (int i = 1; i < controls.length - 1; i++) {
+ sashes[i - 1].setBounds(x, area.y, SASH_WIDTH, area.height);
+ x += SASH_WIDTH;
+ width = (int)((ratios[i] / total) * (float)area.width);
+ controls[i].setBounds(x, area.y, width, area.height);
+ x += width;
+ }
+ if (controls.length > 1) {
+ sashes[sashes.length - 1].setBounds(x, area.y, SASH_WIDTH, area.height);
+ x += SASH_WIDTH;
+ width = area.width - x;
+ controls[controls.length - 1].setBounds(x, area.y, width, area.height);
+ }
+ } else {
+ int height = (int)((ratios[0] / total) * (float)area.height);
+ int y = area.y;
+ controls[0].setBounds(area.x, y, area.width, height);
+ y += height;
+ for (int i = 1; i < controls.length - 1; i++) {
+ sashes[i - 1].setBounds(area.x, y, area.width, SASH_WIDTH);
+ y += SASH_WIDTH;
+ height = (int)((ratios[i] / total) * (float)area.height);
+ controls[i].setBounds(area.x, y, area.width, height);
+ y += height;
+ }
+ if (controls.length > 1) {
+ sashes[sashes.length - 1].setBounds(area.x, y, area.width, SASH_WIDTH);
+ y += SASH_WIDTH;
+ height = area.height - y;
+ controls[controls.length - 1].setBounds(area.x, y, area.width, height);
+ }
+
+ }
+}
+private void onDragSash(Event event) {
+ if (event.detail == SWT.DRAG) {
+ // constrain feedback
+ Rectangle area = getClientArea();
+ if (orientation == SWT.HORIZONTAL) {
+ event.x = Math.min(Math.max(DRAG_MINIMUM, event.x), area.width - DRAG_MINIMUM);
+ } else {
+ event.y = Math.min(Math.max(DRAG_MINIMUM, event.y), area.height - DRAG_MINIMUM);
+ }
+ return;
+ }
+
+ Sash sash = (Sash)event.widget;
+ int sashIndex = -1;
+ for (int i= 0; i < sashes.length; i++) {
+ if (sashes[i] == sash) {
+ sashIndex = i;
+ break;
+ }
+ }
+ if (sashIndex == -1) return;
+
+ Control c1 = controls[sashIndex];
+ Control c2 = controls[sashIndex + 1];
+ Rectangle b1 = c1.getBounds();
+ Rectangle b2 = c2.getBounds();
+
+ Rectangle sashBounds = sash.getBounds();
+ Rectangle area = getClientArea();
+ if (orientation == SWT.HORIZONTAL) {
+ int shift = event.x - sashBounds.x;
+ b1.width += shift;
+ b2.x += shift;
+ b2.width -= shift;
+ if (b1.width < DRAG_MINIMUM || b2.width < DRAG_MINIMUM) {
+ return;
+ }
+ c1.setData("layout ratio", new Float((float)b1.width / (float)area.width));
+ c2.setData("layout ratio", new Float((float)b2.width / (float)area.width));
+ } else {
+ int shift = event.y - sashBounds.y;
+ b1.height += shift;
+ b2.y += shift;
+ b2.height -= shift;
+ if (b1.height < DRAG_MINIMUM || b2.height < DRAG_MINIMUM) {
+ return;
+ }
+ c1.setData("layout ratio", new Float((float)b1.height / (float)area.height));
+ c2.setData("layout ratio", new Float((float)b2.height / (float)area.height));
+ }
+
+ c1.setBounds(b1);
+ sash.setBounds(event.x, event.y, event.width, event.height);
+ c2.setBounds(b2);
+}
+/**
+ * If orientation is SWT.HORIZONTAL, lay the controls in the SashForm out side by side.
+ * If orientation is SWT.VERTICAL, lay the controls in the SashForm out top to bottom.
+ */
+public void setOrientation(int orientation) {
+ if (this.orientation == orientation) return;
+ if (orientation != SWT.HORIZONTAL && orientation != SWT.VERTICAL) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ this.orientation = orientation;
+
+ int sashOrientation = (orientation == SWT.HORIZONTAL) ? SWT.VERTICAL : SWT.HORIZONTAL;
+ for (int i = 0; i < sashes.length; i++) {
+ sashes[i].dispose();
+ sashes[i] = new Sash(this, sashOrientation);
+ sashes[i].addListener(SWT.Selection, sashListener);
+ }
+ layout();
+}
+/**
+ * Sets the layout which is associated with the receiver to be
+ * the argument which may be null.
+ * <p>
+ * Note : SashForm does not use a layout class to size and position its children.
+ * </p>
+ *
+ * @param 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) {
+}
+/**
+ * Specify the control that should take up the entire client area of the SashForm.
+ * If one control has been maximized, and this method is called with a different control,
+ * the previous control will be minimized and the new control will be maximized..
+ * if the value of control is null, the SashForm will minimize all controls and return to
+ * the default layout where all controls are laid out separated by sashes.
+ */
+public void setMaximizedControl(Control control){
+ if (control == null) {
+ if (maxControl != null) {
+ this.maxControl = null;
+ layout();
+ for (int i= 0; i < sashes.length; i++){
+ sashes[i].setVisible(true);
+ }
+ }
+ return;
+ }
+
+ for (int i= 0; i < sashes.length; i++){
+ sashes[i].setVisible(false);
+ }
+ maxControl = control;
+ layout();
+
+// // walk up
+// w= getParent();
+// if (w instanceof SplitForm)
+// ((SplitForm) w).internalMaximize(this);
+// else
+// layout(true);
+}
+
+/**
+ * Specify the relative weight of each child in the SashForm. This will determine
+ * what percent of the total width (if SashForm has Horizontal orientation) or
+ * total height (if SashForm has Vertical orientation) each control will occupy.
+ * The weights must be positive values and there must be an entry for each
+ * non-sash child of the SashForm.
+ */
+public void setWeights(int[] weights) {
+ Control[] cArray = getControls(false);
+ if (weights == null || weights.length != cArray.length) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+
+ int total = 0;
+ for (int i = 0; i < weights.length; i++) {
+ if (weights[i] < 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ total += weights[i];
+ }
+ if (total == 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ for (int i = 0; i < cArray.length; i++) {
+ cArray[i].setData("layout ratio", new Float((float)weights[i] / (float)total));
+ }
+
+ layout();
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ScrolledComposite.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ScrolledComposite.java
new file mode 100644
index 0000000000..fcc237a78c
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ScrolledComposite.java
@@ -0,0 +1,378 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+ * A ScrolledComposite provides scrollbars and will scroll its content when the user
+ * uses the scrollbars.
+ *
+ *
+ * <p>There are two ways to use the ScrolledComposite:
+ *
+ * <p>
+ * 1) Set the size of the control that is being scrolled and the ScrolledComposite
+ * will show scrollbars when the contained control can not be fully seen.
+ *
+ * 2) The second way imitates the way a browser would work. Set the minimum size of
+ * the control and the ScrolledComposite will show scroll bars if the visible area is
+ * less than the minimum size of the control and it will expand the size of the control
+ * if the visible area is greater than the minimum size. This requires invoking
+ * both setMinWidth(), setMinHeight() and setExpandHorizontal(), setExpandVertical().
+ *
+ * <code><pre>
+ * public static void main (String [] args) {
+ * Display display = new Display ();
+ * Color red = display.getSystemColor(SWT.COLOR_RED);
+ * Color blue = display.getSystemColor(SWT.COLOR_BLUE);
+ * Shell shell = new Shell (display);
+ * shell.setLayout(new FillLayout());
+ *
+ * // set the size of the scrolled content - method 1
+ * final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+ * final Composite c1 = new Composite(sc1, SWT.NONE);
+ * sc1.setContent(c1);
+ * c1.setBackground(red);
+ * GridLayout layout = new GridLayout();
+ * layout.numColumns = 4;
+ * c1.setLayout(layout);
+ * Button b1 = new Button (c1, SWT.PUSH);
+ * b1.setText("first button");
+ * c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ *
+ * // set the minimum width and height of the scrolled content - method 2
+ * final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+ * sc2.setExpandHorizontal(true);
+ * sc2.setExpandVertical(true);
+ * final Composite c2 = new Composite(sc2, SWT.NONE);
+ * sc2.setContent(c2);
+ * c2.setBackground(blue);
+ * layout = new GridLayout();
+ * layout.numColumns = 4;
+ * c2.setLayout(layout);
+ * Button b2 = new Button (c2, SWT.PUSH);
+ * b2.setText("first button");
+ * sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ *
+ * Button add = new Button (shell, SWT.PUSH);
+ * add.setText("add children");
+ * final int[] index = new int[]{0};
+ * add.addListener(SWT.Selection, new Listener() {
+ * public void handleEvent(Event e) {
+ * index[0]++;
+ * Button button = new Button(c1, SWT.PUSH);
+ * button.setText("button "+index[0]);
+ * // reset size of content so children can be seen - method 1
+ * c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ * c1.layout();
+ *
+ * button = new Button(c2, SWT.PUSH);
+ * button.setText("button "+index[0]);
+ * // reset the minimum width and height so children can be seen - method 2
+ * sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ * c2.layout();
+ * }
+ * });
+ *
+ * shell.open ();
+ * while (!shell.isDisposed ()) {
+ * if (!display.readAndDispatch ()) display.sleep ();
+ * }
+ * display.dispose ();
+ * }
+ * </pre></code>
+ *
+ * <dl>
+ * <dt><b>Styles:</b><dd>H_SCROLL, V_SCROLL
+ * </dl>
+ */
+public class ScrolledComposite extends Composite {
+
+ private Control content;
+ private Listener contentListener;
+
+ private int minHeight = 0;
+ private int minWidth = 0;
+ private boolean expandHorizontal = false;
+ private boolean expandVertical = false;
+ private boolean alwaysShowScroll = false;
+ private boolean inResize = false;
+
+public ScrolledComposite(Composite parent, int style) {
+ super(parent, checkStyle(style));
+
+ ScrollBar hBar = getHorizontalBar ();
+ if (hBar != null) {
+ hBar.addListener (SWT.Selection, new Listener () {
+ public void handleEvent (Event e) {
+ hScroll();
+ }
+ });
+ }
+
+ ScrollBar vBar = getVerticalBar ();
+ if (vBar != null) {
+ vBar.addListener (SWT.Selection, new Listener () {
+ public void handleEvent (Event e) {
+ vScroll();
+ }
+ });
+ }
+
+ addListener (SWT.Resize, new Listener () {
+ public void handleEvent (Event e) {
+ resize();
+ }
+ });
+
+ contentListener = new Listener() {
+ public void handleEvent(Event e) {
+ if (e.type != SWT.Resize) return;
+ resize();
+ }
+ };
+}
+
+private static int checkStyle (int style) {
+ int mask = SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
+ return style & mask;
+}
+
+/**
+ * Returns the Always Show Scrollbars flag. True if the scrollbars are
+ * always shown even if they are not required. False if the scrollbars are only
+ * visible when some part of the composite needs to be scrolled to be seen.
+ * The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the
+ * horizontal and vertical directions.
+ *
+ * @return the Always Show Scrollbars flag value
+ */
+public boolean getAlwaysShowScrollBars() {
+ return alwaysShowScroll;
+}
+
+/**
+ * Get the content that is being scrolled.
+ */
+public Control getContent() {
+ return content;
+}
+
+private void hScroll() {
+ if (content == null) return;
+ Point location = content.getLocation ();
+ ScrollBar hBar = getHorizontalBar ();
+ int hSelection = hBar.getSelection ();
+ content.setLocation (-hSelection, location.y);
+}
+
+public void layout(boolean changed) {
+ if (content == null) return;
+ Rectangle contentRect = content.getBounds();
+ ScrollBar hBar = getHorizontalBar ();
+ ScrollBar vBar = getVerticalBar ();
+ if (!alwaysShowScroll) {
+ boolean hVisible = needHScroll(contentRect, false);
+ boolean vVisible = needVScroll(contentRect, hVisible);
+ if (!hVisible && vVisible) hVisible = needHScroll(contentRect, vVisible);
+ if (hBar != null) hBar.setVisible(hVisible);
+ if (vBar != null) vBar.setVisible(vVisible);
+ }
+
+ Rectangle hostRect = getClientArea();
+ if (expandHorizontal) {
+ contentRect.width = Math.max(minWidth, hostRect.width);
+ }
+ if (expandVertical) {
+ contentRect.height = Math.max(minHeight, hostRect.height);
+ }
+
+ if (hBar != null) {
+ hBar.setMaximum (contentRect.width);
+ hBar.setThumb (Math.min (contentRect.width, hostRect.width));
+ int hPage = contentRect.width - hostRect.width;
+ int hSelection = hBar.getSelection ();
+ if (hSelection >= hPage) {
+ if (hPage <= 0) {
+ hSelection = 0;
+ hBar.setSelection(0);
+ }
+ contentRect.x = -hSelection;
+ }
+ }
+
+ if (vBar != null) {
+ vBar.setMaximum (contentRect.height);
+ vBar.setThumb (Math.min (contentRect.height, hostRect.height));
+ int vPage = contentRect.height - hostRect.height;
+ int vSelection = vBar.getSelection ();
+ if (vSelection >= vPage) {
+ if (vPage <= 0) {
+ vSelection = 0;
+ vBar.setSelection(0);
+ }
+ contentRect.y = -vSelection;
+ }
+ }
+
+ content.setBounds (contentRect);
+}
+
+private boolean needHScroll(Rectangle contentRect, boolean vVisible) {
+ ScrollBar hBar = getHorizontalBar();
+ if (hBar == null) return false;
+
+ Rectangle hostRect = getBounds();
+ int border = getBorderWidth();
+ hostRect.width -= 2*border;
+ ScrollBar vBar = getVerticalBar();
+ if (vVisible && vBar != null) hostRect.width -= vBar.getSize().x;
+
+ if (!expandHorizontal && contentRect.width > hostRect.width) return true;
+ if (expandHorizontal && minWidth > hostRect.width) return true;
+ return false;
+}
+
+private boolean needVScroll(Rectangle contentRect, boolean hVisible) {
+ ScrollBar vBar = getVerticalBar();
+ if (vBar == null) return false;
+
+ Rectangle hostRect = getBounds();
+ int border = getBorderWidth();
+ hostRect.height -= 2*border;
+ ScrollBar hBar = getHorizontalBar();
+ if (hVisible && hBar != null) hostRect.height -= hBar.getSize().y;
+
+ if (!expandHorizontal && contentRect.height > hostRect.height) return true;
+ if (expandHorizontal && minHeight > hostRect.height) return true;
+ return false;
+}
+
+private void resize() {
+ if (inResize) return;
+ inResize = true;
+ layout();
+ inResize = false;
+}
+
+/**
+ * Set the Always Show Scrollbars flag. True if the scrollbars are
+ * always shown even if they are not required. False if the scrollbars are only
+ * visible when some part of the composite needs to be scrolled to be seen.
+ * The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the
+ * horizontal and vertical directions.
+ */
+public void setAlwaysShowScrollBars(boolean show) {
+ if (show == alwaysShowScroll) return;
+ alwaysShowScroll = show;
+ ScrollBar hBar = getHorizontalBar ();
+ if (hBar != null && alwaysShowScroll) hBar.setVisible(true);
+ ScrollBar vBar = getVerticalBar ();
+ if (vBar != null && alwaysShowScroll) vBar.setVisible(true);
+ layout();
+}
+
+/**
+ * Set the content that will be scrolled.
+ */
+public void setContent(Control content) {
+ if (this.content != null && !this.content.isDisposed()) {
+ this.content.removeListener(SWT.Resize, contentListener);
+ this.content.setBounds(new Rectangle(-200, -200, 0, 0));
+ }
+
+ this.content = content;
+ ScrollBar vBar = getVerticalBar ();
+ ScrollBar hBar = getHorizontalBar ();
+ if (this.content != null) {
+ if (vBar != null) {
+ vBar.setMaximum (0);
+ vBar.setThumb (0);
+ vBar.setSelection(0);
+ }
+ if (hBar != null) {
+ hBar.setMaximum (0);
+ hBar.setThumb (0);
+ hBar.setSelection(0);
+ }
+ content.setLocation(0, 0);
+ layout();
+ this.content.addListener(SWT.Resize, contentListener);
+ } else {
+ if (hBar != null) hBar.setVisible(alwaysShowScroll);
+ if (vBar != null) vBar.setVisible(alwaysShowScroll);
+ }
+}
+/**
+ * Configure the ScrolledComposite to resize the content object to be as wide as the
+ * ScrolledComposite when the width of the ScrolledComposite is greater than the
+ * minimum width specified in setMinWidth. If the ScrolledComposite is less than the
+ * minimum width, the content will not resized and instead the horizontal scroll bar will be
+ * used to view the entire width.
+ * If expand is false, this behaviour is turned off. By default, this behaviour is turned off.
+ */
+public void setExpandHorizontal(boolean expand) {
+ if (expand == expandHorizontal) return;
+ expandHorizontal = expand;
+ layout();
+}
+/**
+ * Configure the ScrolledComposite to resize the content object to be as tall as the
+ * ScrolledComposite when the height of the ScrolledComposite is greater than the
+ * minimum height specified in setMinHeight. If the ScrolledComposite is less than the
+ * minimum height, the content will not resized and instead the vertical scroll bar will be
+ * used to view the entire height.
+ * If expand is false, this behaviour is turned off. By default, this behaviour is turned off.
+ */
+public void setExpandVertical(boolean expand) {
+ if (expand == expandVertical) return;
+ expandVertical = expand;
+ layout();
+}
+public void setLayout (Layout layout) {
+ // do not allow a layout to be set on this class because layout is being handled by the resize listener
+ return;
+}
+/**
+ * Specify the minimum height at which the ScrolledComposite will begin scrolling the
+ * content with the vertical scroll bar. This value is only relevant if
+ * setExpandVertical(true) has been set.
+ */
+public void setMinHeight(int height) {
+ setMinSize(minWidth, height);
+}
+public void setMinSize(Point size) {
+ setMinSize(size.x, size.y);
+}
+public void setMinSize(int width, int height) {
+ if (width == minWidth && height == minHeight) return;
+ minWidth = Math.max(0, width);
+ minHeight = Math.max(0, height);
+ layout();
+}
+/**
+ * Specify the minimum width at which the ScrolledComposite will begin scrolling the
+ * content with the horizontal scroll bar. This value is only relevant if
+ * setExpandHorizontal(true) has been set.
+ */
+
+public void setMinWidth(int width) {
+ setMinSize(width, minHeight);
+}
+
+private void vScroll() {
+ Control[] children = getChildren();
+ if (children.length == 0) return;
+ Control content = children[0];
+ Point location = content.getLocation ();
+ ScrollBar vBar = getVerticalBar ();
+ int vSelection = vBar.getSelection ();
+ content.setLocation (location.x, -vSelection);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StackLayout.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StackLayout.java
new file mode 100644
index 0000000000..02fab5cb46
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StackLayout.java
@@ -0,0 +1,74 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+
+/**
+ * This Layout stacks all the controls one on top of the other and resizes all controls
+ * to have the same size and location.
+ * The control specified in topControl is visible and all other controls are not visible.
+ * Users must set the topControl value to flip between the visible items and the call
+ * layout() on the composite which has the StackLayout.
+ */
+
+public class StackLayout extends Layout {
+
+ /**
+ * marginWidth specifies the number of pixels of horizontal margin
+ * that will be placed along the left and right edges of the layout.
+ *
+ * The default value is 0.
+ */
+ public int marginWidth = 0;
+ /**
+ * marginHeight specifies the number of pixels of vertical margin
+ * that will be placed along the top and bottom edges of the layout.
+ *
+ * The default value is 0.
+ */
+ public int marginHeight = 0;
+
+ /**
+ * topControl the Control that is displayed at the top of the stack.
+ * All other controls that are children of the parent composite will not be visible.
+ */
+ public Control topControl;
+
+protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
+ Control children[] = composite.getChildren();
+
+ int maxWidth = 0;
+ int maxHeight = 0;
+ for (int i = 0; i < children.length; i++) {
+ Point size = children[i].computeSize(wHint, hHint, flushCache);
+ maxWidth = Math.max(size.x, maxWidth);
+ maxHeight = Math.max(size.y, maxHeight);
+ }
+
+ int width = wHint, height = hHint;
+ if (wHint == SWT.DEFAULT) width = maxWidth;
+ if (hHint == SWT.DEFAULT) height = maxHeight;
+ return new Point(width + 2 * marginWidth, height + 2 * marginHeight);
+}
+
+protected void layout(Composite composite, boolean flushCache) {
+ Control children[] = composite.getChildren();
+ Rectangle rect = composite.getClientArea();
+ rect.x += marginWidth;
+ rect.y += marginHeight;
+ rect.width -= 2 * marginWidth;
+ rect.height -= 2 * marginHeight;
+ for (int i = 0; i < children.length; i++) {
+ children[i].setBounds(rect);
+ children[i].setVisible(children[i] == topControl);
+
+ }
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyleRange.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyleRange.java
new file mode 100644
index 0000000000..10ca96699c
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyleRange.java
@@ -0,0 +1,146 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+public class StyleRange implements Cloneable {
+ public int start; // style start offset. 0 based from the document start
+ public int length; // style length.
+ public Color foreground;
+ public Color background;
+ public int fontStyle = SWT.NORMAL; // may be SWT.NORMAL or SWT.BOLD
+
+public StyleRange() {
+}
+/**
+ * Create a new style range.
+ * <p>
+ *
+ * @param start start offset of the style
+ * @param length length of the style
+ * @param foreground foreground color of the style, null if none
+ * @param background background color of the style, null if none
+ */
+public StyleRange(int start, int length, Color foreground, Color background) {
+ this.start = start;
+ this.length = length;
+ this.foreground = foreground;
+ this.background = background;
+}
+
+/**
+ * Create a new style range.
+ * <p>
+ *
+ * @param start start offset of the style
+ * @param length length of the style
+ * @param foreground foreground color of the style, null if none
+ * @param background background color of the style, null if none
+ * @param fontStyle font style of the style, may be SWT.NORMAL or SWT.BOLD
+ */
+public StyleRange(int start, int length, Color foreground, Color background, int fontStyle) {
+ this.start = start;
+ this.length = length;
+ this.foreground = foreground;
+ this.background = background;
+ this.fontStyle = fontStyle;
+}
+
+/**
+ * Compare the specified object to this StyleRange and answer if the two
+ * are equal. The object must be an instance of StyleRange and have the
+ * same field values.
+ * <p>
+ *
+ * @param object the object to compare with this object
+ * @return true if the objects are equal, false otherwise
+ */
+public boolean equals(Object object) {
+ StyleRange style;
+ if (object == this) return true;
+ if (object instanceof StyleRange) style = (StyleRange)object;
+ else return false;
+ if (this.start != style.start) return false;
+ if (this.length != style.length) return false;
+ if (this.foreground != null) {
+ if (!this.foreground.equals(style.foreground)) return false;
+ } else if (style.foreground != null) return false;
+ if (this.background != null) {
+ if (!this.background.equals(style.background)) return false;
+ } else if (style.background != null) return false;
+ if (this.fontStyle != style.fontStyle) return false;
+ return true;
+}
+/**
+ * Returns an integer hash code for the receiver. Objects which are
+ * equal answer the same value for this method.
+ * <p>
+ *
+ * @return the receiver's hash
+ */
+public int hashCode() {
+ return start + length + foreground.hashCode() + background.hashCode() + fontStyle;
+}
+/**
+ * Returns whether or not the receiver is unstyled (i.e., does not have any
+ * style attributes specified).
+ * <p>
+ *
+ * @return true if the receiver is unstyled, false otherwise.
+ */
+public boolean isUnstyled() {
+ if (this.foreground != null) return false;
+ if (this.background != null) return false;
+ if (this.fontStyle != SWT.NORMAL) return false;
+ return true;
+}
+/**
+ * Compares the specified object to this StyleRange and answer if the two
+ * are similar. The object must be an instance of StyleRange and have the
+ * same field values for except for start and length.
+ * <p>
+ *
+ * @param object the object to compare with this object
+ * @return true if the objects are similar, false otherwise
+ */
+public boolean similarTo(StyleRange style) {
+ if (this.foreground != null) {
+ if (!this.foreground.equals(style.foreground)) return false;
+ } else if (style.foreground != null) return false;
+ if (this.background != null) {
+ if (!this.background.equals(style.background)) return false;
+ } else if (style.background != null) return false;
+ if (this.fontStyle != style.fontStyle) return false;
+ return true;
+}
+/**
+ * Answers a new StyleRange with the same values as this StyleRange.
+ * <p>
+ *
+ * @return a shallow copy of this StyleRange
+ */
+public Object clone() {
+ StyleRange style = new StyleRange(start, length, foreground, background, fontStyle);
+ return style;
+}
+/**
+ * Answers a string description of the receiver.
+ * <p>
+ *
+ * @return a printable representation for the receiver.
+ */
+public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(start + "," + length + " fg:" + foreground + " bg:" + background + " fStyle:");
+ if (fontStyle == SWT.NORMAL) {
+ buf.append("normal");
+ } else if (fontStyle == SWT.BOLD) {
+ buf.append("bold");
+ }
+ return buf.toString();
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledText.java
new file mode 100644
index 0000000000..d0f1d8257f
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledText.java
@@ -0,0 +1,6418 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.dnd.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.printing.*;
+import java.util.*;
+
+/**
+ * A StyledText is an editable user interface object that displays lines
+ * of text. The following style attributes can be defined for the text:
+ * <ul>
+ * <li>foreground color
+ * <li>background color
+ * <li>font style (bold, regular)
+ * </ul>
+ * <p>
+ * In addition to text style attributes, the background color of a line may
+ * be specified.
+ * </p>
+ * <p>
+ * There are two ways to use this widget when specifying text style information.
+ * You may use the API that is defined for StyledText or you may define your own
+ * LineStyleListener. If you define your own listener, you will be responsible
+ * for maintaining the text style information for the widget. IMPORTANT: You may
+ * not define your own listener and use the StyledText API. The following
+ * StyledText API is not supported if you have defined a LineStyleListener:
+ * <ul>
+ * <li>getStyleRangeAtOffset(int)
+ * <li>getStyleRanges()
+ * <li>setStyleRange(StyleRange)
+ * <li>setStyleRanges(StyleRange[])
+ * </ul>
+ * </p>
+ * <p>
+ * There are two ways to use this widget when specifying line background colors.
+ * You may use the API that is defined for StyledText or you may define your own
+ * LineBackgroundListener. If you define your own listener, you will be responsible
+ * for maintaining the line background color information for the widget.
+ * IMPORTANT: You may not define your own listener and use the StyledText API.
+ * The following StyledText API is not supported if you have defined a
+ * LineBackgroundListener:
+ * <ul>
+ * <li>getLineBackground(int)
+ * <li>setLineBackground(int,int,Color)
+ * </ul>
+ * </p>
+ * <p>
+ * The content implementation for this widget may also be user-defined. To do so,
+ * you must implement the StyledTextContent interface and use the StyledText API
+ * setContent(StyledTextContent) to initialize the widget.
+ * </p>
+ * <p>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ * </p>
+ * <dl>
+ * <dt><b>Styles:</b><dd>FULL_SELECTION, MULTI, SINGLE, READ_ONLY
+ * <dt><b>Events:</b><dd>ExtendedModify, LineGetBackground, LineGetStyle, Modify, Selection, Verify, VerifyKey
+ * </dl>
+ */
+public class StyledText extends Canvas {
+ static final char TAB = '\t';
+ private final static String PlatformLineDelimiter = System.getProperty("line.separator");
+
+ StyledTextContent content;
+ TextChangeListener textChangeListener; // listener for TextChanging, TextChanged and TextSet events from StyledTextContent
+ DefaultLineStyler defaultLineStyler;// used for setStyles API when no LineStyleListener is registered
+ boolean userLineStyle = false; // true=widget is using a user defined line style listener for line styles. false=widget is using the default line styler to store line styles
+ boolean userLineBackground = false;// true=widget is using a user defined line background listener for line backgrounds. false=widget is using the default line styler to store line backgrounds
+ int verticalScrollOffset = 0; // pixel based
+ int horizontalScrollOffset = 0; // pixel based
+ int topIndex = 0; // top visible line
+ int clientAreaHeight = 0; // the client area height. Needed to calculate content width for new
+ // visible lines during Resize callback
+ int contentWidth = 0; // width of widest known (already visible) line
+ int lineHeight; // line height=font height
+ int tabLength = 4; // number of characters in a tab
+ int tabWidth; // width of a tab character in the current GC
+ int lineEndSpaceWidth; // space, in pixel, used to indicated a selected line break
+ Cursor ibeamCursor;
+ int caretOffset = 0;
+ Point selection = new Point(0, 0); // x is character offset, y is length
+ int selectionAnchor; // position of selection anchor. 0 based offset from beginning of text
+ boolean editable = true;
+ boolean doubleClickEnabled = true; // see getDoubleClickEnabled
+ boolean overwrite = false; // insert/overwrite edit mode
+ int textLimit = -1; // limits the number of characters the user can type in the widget. Unlimited by default.
+ Hashtable keyActionMap = new Hashtable();
+ Font boldFont;
+ Font regularFont;
+ Clipboard clipboard;
+ boolean mouseDoubleClick = false; // true=a double click ocurred. Don't do mouse swipe selection.
+ int autoScrollDirection = SWT.NULL; // the direction of autoscrolling (up, down, right, left)
+ int lastTextChangeStart; // cache data of the
+ int lastTextChangeNewLineCount; // last text changing
+ int lastTextChangeNewCharCount; // event for use in the
+ int lastTextChangeReplaceLineCount; // text changed handler
+ int lastTextChangeReplaceCharCount;
+
+ boolean bidiColoring = false; // apply the BIDI algorithm on text segments of the same color
+ static final int BIDI_CARET_WIDTH = 4;
+ static int xInset = 0;
+ Image leftCaretBitmap = null;
+ Image rightCaretBitmap = null;
+ int caretDirection = SWT.NULL;
+ PaletteData caretPalette = null;
+ int lastCaretDirection = SWT.NULL;
+
+ static final int DEFAULT_WIDTH = 64;
+ static final int DEFAULT_HEIGHT = 64;
+
+ static final int ExtendedModify = 3000;
+ static final int LineGetBackground = 3001;
+ static final int LineGetStyle = 3002;
+ static final int TextChanging = 3003;
+ static final int TextChanged = 3006;
+ static final int TextSet = 3004;
+ static final int VerifyKey = 3005;
+ /**
+ * The <code>RTFWriter</code> class is used to write widget content as
+ * rich text. The implementation complies with the RTF specification
+ * version 1.5.
+ * <p>
+ * toString() is guaranteed to return a valid RTF string only after
+ * close() has been called.
+ * </p>
+ * <p>
+ * Whole and partial lines and line breaks can be written. Lines will be
+ * formatted using the styles queried from the LineStyleListener, if
+ * set, or those set directly in the widget. All styles are applied to
+ * the RTF stream like they are rendered by the widget. In addition, the
+ * widget font name and size is used for the whole text.
+ * </p>
+ */
+ class RTFWriter extends TextWriter {
+ final int DEFAULT_FOREGROUND = 0;
+ final int DEFAULT_BACKGROUND = 1;
+ Vector colorTable = new Vector();
+
+ /**
+ * Creates a RTF writer that writes content starting at offset "start"
+ * in the document. <code>start</code> and <code>length</code>can be set to specify partial
+ * lines.
+ * <p>
+ *
+ * @param start start offset of content to write, 0 based from
+ * beginning of document
+ * @param length length of content to write
+ */
+ public RTFWriter(int start, int length) {
+ super(start, length);
+ colorTable.addElement(getForeground());
+ colorTable.addElement(getBackground());
+ }
+ /**
+ * Closes the RTF writer. Once closed no more content can be written.
+ * <b>NOTE:</b> <code>toString()</code> does not return a valid RTF string until
+ * <code>close()</code> has been called.
+ */
+ public void close() {
+ if (isClosed() == false) {
+ writeHeader();
+ write("\n}}\0");
+ super.close();
+ }
+ }
+ /**
+ * Returns the index of the specified color in the RTF color table.
+ * <p>
+ *
+ * @param color the color
+ * @param defaultIndex return value if color is null
+ * @return the index of the specified color in the RTF color table
+ * or "defaultIndex" if "color" is null.
+ */
+ int getColorIndex(Color color, int defaultIndex) {
+ int index;
+
+ if (color == null) {
+ index = defaultIndex;
+ }
+ else {
+ index = colorTable.indexOf(color);
+ if (index == -1) {
+ index = colorTable.size();
+ colorTable.addElement(color);
+ }
+ }
+ return index;
+ }
+ /**
+ * Writes the RTF header including font table and color table.
+ */
+ void writeHeader() {
+ StringBuffer header = new StringBuffer();
+ FontData fontData = getFont().getFontData()[0];
+ header.append("{\\rtf1\\ansi\\deff0{\\fonttbl{\\f0\\fnil");
+ // specify code page, necessary for copy to work in bidi
+ // systems
+ String cpg = System.getProperty("file.encoding");
+ if (cpg.startsWith("Cp") || cpg.startsWith("MS")) {
+ cpg = cpg.substring(2, cpg.length());
+ header.append("\\cpg");
+ header.append(cpg);
+ }
+ header.append(" ");
+ header.append(fontData.getName());
+ header.append(";}}\n{\\colortbl");
+ for (int i = 0; i < colorTable.size(); i++) {
+ Color color = (Color) colorTable.elementAt(i);
+ header.append("\\red");
+ header.append(color.getRed());
+ header.append("\\green");
+ header.append(color.getGreen());
+ header.append("\\blue");
+ header.append(color.getBlue());
+ header.append(";");
+ }
+ // some RTF readers ignore the deff0 font tag. Explicitly
+ // set the font for the whole document to work around this.
+ header.append("}\n{\\f0\\fs");
+ // font size is specified in half points
+ header.append(fontData.getHeight() * 2);
+ header.append(" ");
+ write(header.toString(), 0);
+ }
+ /**
+ * Appends the specified line text to the RTF data. Lines will be formatted
+ * using the styles queried from the LineStyleListener, if set, or those set
+ * directly in the widget.
+ * <p>
+ *
+ * @param line line text to write as RTF. Must not contain line breaks
+ * Line breaks should be written using writeLineDelimiter()
+ * @param lineOffset offset of the line. 0 based from the start of the
+ * widget document. Any text occurring before the start offset or after the
+ * end offset specified during object creation is ignored.
+ * @exception SWTException <ul>
+ * <li>ERROR_IO when the writer is closed.</li>
+ * </ul>
+ */
+ public void writeLine(String line, int lineOffset) {
+ StyleRange[] styles = new StyleRange[0];
+ Color lineBackground = null;
+ StyledTextEvent event;
+
+ if (isClosed()) {
+ SWT.error(SWT.ERROR_IO);
+ }
+ event = getLineStyleData(lineOffset, line);
+ if (event != null) {
+ styles = event.styles;
+ }
+ event = getLineBackgroundData(lineOffset, line);
+ if (event != null) {
+ lineBackground = event.lineBackground;
+ }
+ if (lineBackground == null) {
+ lineBackground = getBackground();
+ }
+ writeStyledLine(line, lineOffset, styles, lineBackground);
+ }
+ /**
+ * Appends the specified line delmimiter to the RTF data.
+ * <p>
+ *
+ * @param lineDelimiter line delimiter to write as RTF.
+ * @exception SWTException <ul>
+ * <li>ERROR_IO when the writer is closed.</li>
+ * </ul>
+ */
+ public void writeLineDelimiter(String lineDelimiter) {
+ if (isClosed()) {
+ SWT.error(SWT.ERROR_IO);
+ }
+ write(lineDelimiter, 0, lineDelimiter.length());
+ write("\\par ");
+ }
+ /**
+ * Appends the specified segment of "string" to the RTF data.
+ * Copy from <code>start</code> up to, but excluding, <code>end</code>.
+ * <p>
+ *
+ * @param string string to copy a segment from. Must not contain
+ * line breaks. Line breaks should be written using writeLineDelimiter()
+ * @param start start offset of segment. 0 based.
+ * @param end end offset of segment
+ */
+ void write(String string, int start, int end) {
+ int index;
+
+ for (index = start; index < end; index++) {
+ char c = string.charAt(index);
+ if (c == '}' || c == '{' || c == '\\') {
+ break;
+ }
+ }
+ if (index == end) {
+ write(string.substring(start, end)); // string doesn't contain RTF formatting characters, write as is
+ }
+ else { // string needs to be transformed
+ char[] text = new char[end - start];
+
+ string.getChars(start, end, text, 0);
+ for (index = 0; index < text.length; index++) {
+ switch (text[index]) {
+ case '}':
+ case '{':
+ case '\\':
+ write("\\");
+ default:
+ write(text[index]);
+ }
+ }
+ }
+ }
+ /**
+ * Appends the specified line text to the RTF data.
+ * Use the colors and font styles specified in "styles" and "lineBackground".
+ * Formatting is written to reflect the text rendering by the text widget.
+ * Style background colors take precedence over the line background color.
+ * Background colors are written using the \highlight tag (vs. the \cb tag).
+ * <p>
+ *
+ * @param line line text to write as RTF. Must not contain line breaks
+ * Line breaks should be written using writeLineDelimiter()
+ * @param lineOffset offset of the line. 0 based from the start of the
+ * widget document. Any text occurring before the start offset or after the
+ * end offset specified during object creation is ignored.
+ * @param styles styles to use for formatting. Must not be null.
+ * @param linebackground line background color to use for formatting.
+ * May be null.
+ */
+ void writeStyledLine(String line, int lineOffset, StyleRange[] styles, Color lineBackground) {
+ int lineLength = line.length();
+ int lineIndex;
+ int copyEnd;
+ int startOffset = getStart();
+ int endOffset = startOffset + super.getCharCount();
+ int writeOffset = startOffset - lineOffset;
+
+ if (writeOffset >= line.length()) {
+ return; // whole line is outside write range
+ }
+ else
+ if (writeOffset > 0) {
+ lineIndex = writeOffset; // line starts before RTF write start
+ }
+ else {
+ lineIndex = 0;
+ }
+ if (lineBackground != null) {
+ write("{\\highlight");
+ write(getColorIndex(lineBackground, DEFAULT_BACKGROUND));
+ write(" ");
+ }
+ for (int i = 0; i < styles.length; i++) {
+ StyleRange style = styles[i];
+ int start = style.start - lineOffset;
+ int end = start + style.length;
+ int colorIndex;
+ // skip over partial first line
+ if (end < writeOffset) {
+ continue;
+ }
+ // break on partial last line
+ if (style.start > endOffset) {
+ break;
+ }
+ // write any unstyled text
+ if (lineIndex < start) {
+ // copy to start of style or end of write range (specified
+ // during object creation) or end of line
+ copyEnd = Math.min(start, endOffset - lineOffset);
+ copyEnd = Math.min(copyEnd, lineLength);
+ write(line, lineIndex, copyEnd);
+ lineIndex = copyEnd;
+ if (copyEnd != start) {
+ break;
+ }
+ }
+ // write styled text
+ colorIndex = getColorIndex(style.background, DEFAULT_BACKGROUND);
+ write("{\\cf");
+ write(getColorIndex(style.foreground, DEFAULT_FOREGROUND));
+ if (colorIndex != DEFAULT_BACKGROUND) {
+ write("\\highlight");
+ write(colorIndex);
+ }
+ if (style.fontStyle == SWT.BOLD) {
+ write("\\b");
+ }
+ write(" ");
+ // copy to end of style or end of write range (specified
+ // during object creation) or end of line
+ copyEnd = Math.min(end, endOffset - lineOffset);
+ copyEnd = Math.min(copyEnd, lineLength);
+ write(line, lineIndex, copyEnd);
+ if (style.fontStyle == SWT.BOLD) {
+ write("\\b0");
+ }
+ write("}");
+ lineIndex = copyEnd;
+ if (copyEnd != end) {
+ break;
+ }
+ }
+ copyEnd = Math.min(lineLength, endOffset - lineOffset);
+ if (lineIndex < copyEnd) {
+ write(line, lineIndex, copyEnd);
+ }
+ if (lineBackground != null) {
+ write("}");
+ }
+ }
+ }
+ /**
+ * The <code>TextWriter</code> class is used to write widget content to
+ * a string. Whole and partial lines and line breaks can be written. To write
+ * partial lines, specify the start and length of the desired segment
+ * during object creation.
+ * <p>
+ * </b>NOTE:</b> <code>toString()</code> is guaranteed to return a valid string only after close()
+ * has been called.
+ */
+ class TextWriter {
+ private StringBuffer buffer;
+ private int startOffset; // offset of first character that will be written
+ private int endOffset; // offset of last character that will be written.
+ // 0 based from the beginning of the widget text.
+ private boolean isClosed = false;
+
+ /**
+ * Creates a writer that writes content starting at offset "start"
+ * in the document. <code>start</code> and <code>length</code> can be set to specify partial lines.
+ * <p>
+ *
+ * @param start start offset of content to write, 0 based from beginning of document
+ * @param length length of content to write
+ */
+ public TextWriter(int start, int length) {
+ buffer = new StringBuffer(length);
+ startOffset = start;
+ endOffset = start + length;
+ }
+ /**
+ * Closes the writer. Once closed no more content can be written.
+ * <b>NOTE:</b> <code>toString()</code> is not guaranteed to return a valid string unless
+ * the writer is closed.
+ */
+ public void close() {
+ if (isClosed == false) {
+ isClosed = true;
+ }
+ }
+ /**
+ * Returns the number of characters to write.
+ */
+ public int getCharCount() {
+ return endOffset - startOffset;
+ }
+ /**
+ * Returns the offset where writing starts. 0 based from the start of
+ * the widget text. Used to write partial lines.
+ */
+ public int getStart() {
+ return startOffset;
+ }
+ /**
+ * Returns whether the writer is closed.
+ */
+ public boolean isClosed() {
+ return isClosed;
+ }
+ /**
+ * Returns the string. <code>close()</code> must be called before <code>toString()</code>
+ * is guaranteed to return a valid string.
+ * <p>
+ *
+ * @return the string
+ */
+ public String toString() {
+ return buffer.toString();
+ }
+ /**
+ * Appends the given string to the data.
+ */
+ void write(String string) {
+ buffer.append(string);
+ }
+ /**
+ * Inserts the given string to the data at the specified offset.
+ * Do nothing if "offset" is < 0 or > getCharCount()
+ * <p>
+ *
+ * @param string text to insert
+ * @param offset offset in the existing data to insert "string" at.
+ */
+ void write(String string, int offset) {
+ if (offset < 0 || offset > buffer.length()) {
+ return;
+ }
+ buffer.insert(offset, string);
+ }
+ /**
+ * Appends the given int to the data.
+ */
+ void write(int i) {
+ buffer.append(i);
+ }
+ /**
+ * Appends the given character to the data.
+ */
+ void write(char i) {
+ buffer.append(i);
+ }
+ /**
+ * Appends the specified line text to the data.
+ * <p>
+ *
+ * @param line line text to write. Must not contain line breaks
+ * Line breaks should be written using writeLineDelimiter()
+ * @param lineOffset offset of the line. 0 based from the start of the
+ * widget document. Any text occurring before the start offset or after the
+ * end offset specified during object creation is ignored.
+ * @exception SWTException <ul>
+ * <li>ERROR_IO when the writer is closed.</li>
+ * </ul>
+ */
+ public void writeLine(String line, int lineOffset) {
+ int lineLength = line.length();
+ int lineIndex;
+ int copyEnd;
+ int writeOffset = startOffset - lineOffset;
+
+ if (isClosed) {
+ SWT.error(SWT.ERROR_IO);
+ }
+ if (writeOffset >= lineLength) {
+ return; // whole line is outside write range
+ }
+ else
+ if (writeOffset > 0) {
+ lineIndex = writeOffset; // line starts before write start
+ }
+ else {
+ lineIndex = 0;
+ }
+ copyEnd = Math.min(lineLength, endOffset - lineOffset);
+ if (lineIndex < copyEnd) {
+ write(line.substring(lineIndex, copyEnd));
+ }
+ }
+ /**
+ * Appends the specified line delmimiter to the data.
+ * <p>
+ *
+ * @param lineDelimiter line delimiter to write
+ * @exception SWTException <ul>
+ * <li>ERROR_IO when the writer is closed.</li>
+ * </ul>
+ */
+ public void writeLineDelimiter(String lineDelimiter) {
+ if (isClosed) {
+ SWT.error(SWT.ERROR_IO);
+ }
+ write(lineDelimiter);
+ }
+ }
+
+public StyledText(Composite parent, int style) {
+ // use NO_BACKGROUND style when implemented by SWT.
+ // always need to draw background in drawLine when using NO_BACKGROUND!
+ super(parent, checkStyle(style | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND));
+ Display display = getDisplay();
+
+ if ((style & SWT.READ_ONLY) != 0) {
+ setEditable(false);
+ }
+ clipboard = new Clipboard(display);
+ calculateLineHeight();
+ calculateTabWidth();
+ installDefaultContent();
+ setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
+ setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+ initializeFonts();
+ if (isBidi() == false) {
+ Caret caret = new Caret(this, SWT.NULL);
+ caret.setSize(1, caret.getSize().y);
+ }
+ else {
+ createCaretBitmaps();
+ createBidiCaret();
+ xInset = BIDI_CARET_WIDTH - 1;
+ Runnable runnable = new Runnable() {
+ public void run() {
+ createBidiCaret();
+ Caret caret = getCaret();
+ // don't use setBidiCaret, will position the caret
+ // incorrectly
+ int caretX = caret.getLocation().x;
+ if (StyledTextBidi.getKeyboardLanguageDirection() == SWT.RIGHT) {
+ caretX -= (getCaretWidth() - 1);
+ } else {
+ caretX += (getCaretWidth() - 1);
+ }
+ int line = content.getLineAtOffset(caretOffset);
+ caret.setLocation(caretX, line * lineHeight - verticalScrollOffset);
+ }
+ };
+ StyledTextBidi.addLanguageListener(this.handle, runnable);
+ }
+ // set the caret width, the height of the caret will default to the line height
+ calculateScrollBars();
+ createKeyBindings();
+ ibeamCursor = new Cursor(display, SWT.CURSOR_IBEAM);
+ setCursor(ibeamCursor);
+ installListeners();
+ installDefaultLineStyler();
+}
+
+/**
+ * Sets the BIDI coloring mode. When true the BIDI text display
+ * algorithm is applied to segments of text that are the same
+ * color.
+ *
+ * @param mode the new coloring 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>
+ * <p>
+ * IMPORTANT: This API is in-progress and may change in the future.
+ * </p>
+ */
+public void setBidiColoring(boolean mode) {
+ checkWidget();
+ bidiColoring = mode;
+}
+
+/**
+ * Gets the BIDI coloring mode. When true the BIDI text display
+ * algorithm is applied to segments of text that are the same
+ * color.
+ *
+ * @return the current coloring 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>
+ * <p>
+ * IMPORTANT: This API is in-progress and may change in the future.
+ * </p>
+ */
+public boolean getBidiColoring() {
+ checkWidget();
+ return bidiColoring;
+}
+
+int [] getStyleOffsets (String line, int lineOffset) {
+ StyledTextEvent event = getLineStyleData(lineOffset, line);
+ StyleRange [] styles = new StyleRange [0];
+ if (event != null) {
+ styles = event.styles;
+ }
+ if (styles.length == 0 || !bidiColoring) {
+ return new int[] {0, line.length()};
+ }
+
+ int k=0, count = 1;
+ while (k < styles.length && styles[k].start == 0 && styles[k].length == line.length()) {
+ k++;
+ }
+ int[] offsets = new int[(styles.length - k) * 2 + 2];
+ for (int i = k; i < styles.length; i++) {
+ StyleRange style = styles[i];
+ int styleLineStart = Math.max(style.start - lineOffset, 0);
+ int styleLineEnd = Math.max(style.start + style.length - lineOffset, styleLineStart);
+ styleLineEnd = Math.min (styleLineEnd, line.length ());
+ if (i > 0 && count > 1 &&
+ ((styleLineStart >= offsets[count-2] && styleLineStart <= offsets[count-1]) ||
+ (styleLineEnd >= offsets[count-2] && styleLineEnd <= offsets[count-1])) &&
+ style.similarTo(styles[i-1])) {
+ offsets[count-2] = Math.min(offsets[count-2], styleLineStart);
+ offsets[count-1] = Math.max(offsets[count-1], styleLineEnd);
+ } else {
+ if (styleLineStart > offsets[count - 1]) {
+ offsets[count] = styleLineStart;
+ count++;
+ }
+ offsets[count] = styleLineEnd;
+ count++;
+ }
+ }
+ // add offset for last non-colored segment in line, if any
+ if (line.length() > offsets[count-1]) {
+ offsets [count] = line.length();
+ count++;
+ }
+ if (count == offsets.length)
+ return offsets;
+ int [] result = new int [count];
+ System.arraycopy (offsets, 0, result, 0, count);
+ return result;
+}
+
+/**
+ * Adds an extended modify listener. An ExtendedModify event is sent by the
+ * widget when the widget text has changed.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void addExtendedModifyListener(ExtendedModifyListener extendedModifyListener) {
+ checkWidget();
+ if (extendedModifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ StyledTextListener typedListener = new StyledTextListener(extendedModifyListener);
+ addListener(ExtendedModify, typedListener);
+}
+/**
+ * Maps a key to an action.
+ * One action can be associated with N keys. However, each key can only
+ * have one action (key:action is N:1 relation).
+ * <p>
+ *
+ * @param key a key code defined in SWT.java or a character.
+ * Optionally ORd with a state mask (one or more of SWT.CTRL, SWT.SHIFT, SWT.ALT)
+ * @param action one of the predefined actions defined in ST.java.
+ * Use SWT.NULL to remove a key binding.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setKeyBinding(int key, int action) {
+ checkWidget();
+ if (action == SWT.NULL) {
+ keyActionMap.remove(new Integer(key));
+ }
+ else {
+ keyActionMap.put(new Integer(key), new Integer(action));
+ }
+}
+/**
+ * Adds a line background listener. A LineGetBackground event is sent by the
+ * widget to determine the background color for a line.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void addLineBackgroundListener(LineBackgroundListener listener) {
+ checkWidget();
+ if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (userLineBackground == false) {
+ removeLineBackgroundListener(defaultLineStyler);
+ defaultLineStyler.setLineBackground(0, content.getLineCount(), null);
+ userLineBackground = true;
+ }
+ StyledTextListener typedListener = new StyledTextListener(listener);
+ addListener(LineGetBackground, typedListener);
+}
+/**
+ * Adds a line style listener. A LineGetStyle event is sent by the widget to
+ * determine the styles for a line.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void addLineStyleListener(LineStyleListener listener) {
+ checkWidget();
+ if (listener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (userLineStyle == false) {
+ removeLineStyleListener(defaultLineStyler);
+ defaultLineStyler.setStyleRange(null);
+ userLineStyle = true;
+ }
+ StyledTextListener typedListener = new StyledTextListener(listener);
+ addListener(LineGetStyle, typedListener);
+}
+/**
+ * Adds a modify listener. A Modify event is sent by the widget when the widget text
+ * has changed.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void addModifyListener(ModifyListener modifyListener) {
+ checkWidget();
+ if (modifyListener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ TypedListener typedListener = new TypedListener(modifyListener);
+ addListener(SWT.Modify, typedListener);
+}
+/**
+ * Adds a selection listener. A Selection event is sent by the widget when the
+ * selection has changed.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void addSelectionListener(SelectionListener listener) {
+ checkWidget();
+ if (listener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Selection, typedListener);
+}
+/**
+ * Adds a verify key listener. A VerifyKey event is sent by the widget when a key
+ * is pressed. The widget ignores the key press if the listener sets the doit field
+ * of the event to false.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void addVerifyKeyListener(VerifyKeyListener listener) {
+ checkWidget();
+ if (listener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ StyledTextListener typedListener = new StyledTextListener(listener);
+ addListener(VerifyKey, typedListener);
+}
+/**
+ * Adds a verify listener. A Verify event is sent by the widget when the widget text
+ * is about to change. The listener can set the event text and the doit field to
+ * change the text that is set in the widget or to force the widget to ignore the
+ * text change.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void addVerifyListener(VerifyListener verifyListener) {
+ checkWidget();
+ if (verifyListener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ TypedListener typedListener = new TypedListener(verifyListener);
+ addListener(SWT.Verify, typedListener);
+}
+/**
+ * Appends a string to the text at the end of the widget.
+ * <p>
+ *
+ * @param string the string to be appended
+ * @see #replaceTextRange(int,int,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>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT when listener is null</li>
+ * </ul>
+ */
+public void append(String string) {
+ checkWidget();
+ if (string == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ int lastChar = Math.max(getCharCount(), 0);
+ replaceTextRange(lastChar, 0, string);
+}
+/**
+ * Calculates the width of the widest visible line.
+ */
+void calculateContentWidth() {
+ if (lineHeight != 0) {
+ int itemCount = (int) Math.ceil((float) getClientArea().height / lineHeight);
+ calculateContentWidth(topIndex, Math.min(itemCount, content.getLineCount() - topIndex));
+ }
+}
+/**
+ * Calculates the width of the widget text in the specified line range.
+ * <p>
+ *
+ * @param startline the first line
+ * @param lineCount number of lines to consider for the calculation
+ */
+void calculateContentWidth(int startLine, int lineCount) {
+ String line;
+ GC gc = new GC(this);
+ FontData fontData = gc.getFont().getFontData()[0];
+ int stopLine;
+ boolean isBidi = isBidi();
+
+ if (lineCount < 0) {
+ startLine += lineCount;
+ lineCount *= -1;
+ }
+ stopLine = startLine + lineCount;
+ setLineFont(gc, fontData, SWT.BOLD);
+ for (int i = startLine; i < stopLine; i++) {
+ line = content.getLine(i);
+ if (isBidi) {
+ int lineOffset = content.getOffsetAtLine (i);
+ StyledTextBidi bidi = new StyledTextBidi(gc, tabWidth, line, null, null, getStyleOffsets (line, lineOffset));
+ contentWidth = Math.max(bidi.getTextWidth() + getCaretWidth(), contentWidth);
+ }
+ else {
+ contentWidth = Math.max(contentWidth(line, i, gc) + getCaretWidth(), contentWidth);
+ }
+ }
+ gc.dispose();
+}
+/**
+ * Calculates the line height
+ */
+void calculateLineHeight() {
+ GC gc = new GC(this);
+ lineHeight = gc.getFontMetrics().getHeight();
+ gc.dispose();
+}
+/**
+ * Calculates the width in pixel of a tab character
+ */
+void calculateTabWidth() {
+ StringBuffer tabBuffer = new StringBuffer(tabLength);
+ GC gc = new GC(this);
+
+ for (int i = 0; i < tabLength; i++) {
+ tabBuffer.append(' ');
+ }
+ tabWidth = gc.stringExtent(tabBuffer.toString()).x;
+ gc.dispose();
+}
+/**
+ * Calculates the scroll bars
+ */
+void calculateScrollBars() {
+ ScrollBar horizontalBar = getHorizontalBar();
+ ScrollBar verticalBar = getVerticalBar();
+
+ setScrollBars();
+ if (verticalBar != null) {
+ verticalBar.setIncrement(getVerticalIncrement());
+ }
+ if (horizontalBar != null) {
+ horizontalBar.setIncrement(getHorizontalIncrement());
+ }
+}
+/**
+ * Hides the scroll bars if widget is created in single line mode.
+ */
+static int checkStyle(int style) {
+ if ((style & SWT.SINGLE) != 0) {
+ style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
+ }
+ return style;
+}
+/**
+ * Scrolls down the text to use new space made available by a resize or by
+ * deleted lines.
+ */
+void claimBottomFreeSpace() {
+ int newVerticalOffset = Math.max(0, content.getLineCount() * lineHeight - getClientArea().height);
+
+ if (newVerticalOffset < verticalScrollOffset) {
+ // Scroll up so that empty lines below last text line are used.
+ // Fixes 1GEYJM0
+ setVerticalScrollOffset(newVerticalOffset, true);
+ }
+}
+/**
+ * Scrolls text to the right to use new space made available by a resize.
+ */
+void claimRightFreeSpace() {
+ int newHorizontalOffset = Math.max(0, contentWidth - getClientArea().width);
+
+ if (newHorizontalOffset < horizontalScrollOffset) {
+ // item is no longer drawn past the right border of the client area
+ // align the right end of the item with the right border of the
+ // client area (window is scrolled right).
+ scrollHorizontalBar(newHorizontalOffset - horizontalScrollOffset);
+ }
+}
+/**
+ * Removes the widget selection.
+ * <p>
+ *
+ * @param sendEvent a Selection event is sent when set to true and when the selection is actually reset.
+ */
+void clearSelection(boolean sendEvent) {
+ int selectionStart = selection.x;
+ int selectionEnd = selection.y;
+ int length = content.getCharCount();
+
+ resetSelection();
+ // redraw old selection, if any
+ if (selectionEnd - selectionStart > 0) {
+ // called internally to remove selection after text is removed
+ // therefore make sure redraw range is valid.
+ int redrawStart = Math.min(selectionStart, length);
+ int redrawEnd = Math.min(selectionEnd, length);
+ if (redrawEnd - redrawStart > 0) {
+ internalRedrawRange(redrawStart, redrawEnd - redrawStart, true);
+ }
+ if (sendEvent == true) {
+ sendSelectionEvent();
+ }
+ }
+}
+/**
+ * Computes 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>
+ */
+public Point computeSize (int wHint, int hHint, boolean changed) {
+ checkWidget();
+ int count, width, height;
+ boolean singleLine = (getStyle() & SWT.SINGLE) != 0;
+ count = content.getLineCount();
+
+ // If a height or width has been specified (via hHint and wHint),
+ // use those values. Otherwise calculate the size based on the
+ // text that is defined.
+ if (hHint != SWT.DEFAULT) {
+ height = hHint;
+ } else {
+ if (singleLine) count = 1;
+ height = count * lineHeight;
+ }
+ if (wHint != SWT.DEFAULT) {
+ width = wHint;
+ } else {
+ // Only calculate what can actually be displayed.
+ // Do this because measuring each text line is a
+ // time-consuming process.
+ int visibleCount = Math.min (count, getDisplay().getBounds().width / lineHeight);
+ calculateContentWidth(0, visibleCount);
+ width = contentWidth;
+ }
+
+ // Use default values if no text is defined.
+ if (width == 0) width = DEFAULT_WIDTH;
+ if (height == 0) {
+ if (singleLine) height = lineHeight;
+ else height = DEFAULT_HEIGHT;
+ }
+
+ // Hardcode the inset margins. Assume text is inset
+ // 1 pixel on each side.
+ width += 2;
+ height += 2;
+
+ Rectangle rect = computeTrim(0,0,width,height);
+ return new Point (rect.width, rect.height);
+}
+/**
+ * Returns the width of the specified text. Expand tabs to tab stops using
+ * the widget tab width.
+ * This is a quick and inaccurate measurement. Text styles are not taken
+ * into consideration. The gc should be setup to reflect the widest
+ * possible font style.
+ * <p>
+ *
+ * @param text text to be measured.
+ * @param lineIndex index of the line.
+ * @param gc GC to use for measuring text
+ * @return width of the text with tabs expanded to tab stops
+ */
+int contentWidth(String text, int lineIndex, GC gc) {
+ int paintX = 0;
+ int textLength = text.length();
+
+ for (int i = 0; i < textLength; i++) {
+ int tabIndex = text.indexOf(TAB, i);
+ // is tab not present or past the rendering range?
+ if (tabIndex == -1 || tabIndex > textLength) {
+ tabIndex = textLength;
+ }
+ if (tabIndex != i) {
+ String tabSegment = text.substring(i, tabIndex);
+ paintX += gc.stringExtent(tabSegment).x;
+ if (tabIndex != textLength && tabWidth > 0) {
+ paintX += tabWidth;
+ paintX -= paintX % tabWidth;
+ }
+ i = tabIndex;
+ }
+ else
+ if (tabWidth > 0) {
+ paintX += tabWidth;
+ paintX -= paintX % tabWidth;
+ }
+ }
+ return paintX;
+}
+/**
+ * Copies the selected text to the clipboard. The text will be put in the
+ * clipboard in plain text format and RTF format.
+ * <p>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 length = selection.y - selection.x;
+ if (length > 0) {
+ RTFTransfer rtfTransfer = RTFTransfer.getInstance();
+ TextTransfer plainTextTransfer = TextTransfer.getInstance();
+ RTFWriter rtfWriter = new RTFWriter(selection.x, length);
+ TextWriter plainTextWriter = new TextWriter(selection.x, length);
+ String rtfText = getPlatformDelimitedText(rtfWriter);
+ String plainText = getPlatformDelimitedText(plainTextWriter);
+
+ try {
+ clipboard.setContents(
+ new String[]{rtfText, plainText},
+ new Transfer[]{rtfTransfer, plainTextTransfer});
+ }
+ catch (SWTError error) {
+ // Copy to clipboard failed. This happens when another application
+ // is accessing the clipboard while we copy. Ignore the error.
+ // Fixes 1GDQAVN
+ }
+ }
+}
+/**
+ * Returns a string that uses only the line delimiter specified by the
+ * StyledTextContent implementation.
+ * Returns only the first line if the widget has the SWT.SINGLE style.
+ * <p>
+ *
+ * @param text the text that may have line delimiters that don't
+ * match the model line delimiter. Possible line delimiters
+ * are CR ('\r'), LF ('\n'), CR/LF ("\r\n")
+ * @return the converted text that only uses the line delimiter
+ * specified by the model. Returns only the first line if the widget
+ * has the SWT.SINGLE style.
+ */
+String getModelDelimitedText(String text) {
+ StringBuffer convertedText;
+ String delimiter = getLineDelimiter();
+ int length = text.length();
+ int crIndex = 0;
+ int lfIndex = 0;
+ int i = 0;
+
+ if (length == 0) {
+ return text;
+ }
+ convertedText = new StringBuffer(length);
+ while (i < length) {
+ if (crIndex != -1) {
+ crIndex = text.indexOf(SWT.CR, i);
+ }
+ if (lfIndex != -1) {
+ lfIndex = text.indexOf(SWT.LF, i);
+ }
+ if (lfIndex == -1 && crIndex == -1) { // no more line breaks?
+ break;
+ }
+ else // CR occurs before LF or no LF present?
+ if ((crIndex < lfIndex && crIndex != -1) || lfIndex == -1) {
+ convertedText.append(text.substring(i, crIndex));
+ if (lfIndex == crIndex + 1) { // CR/LF combination?
+ i = lfIndex + 1;
+ }
+ else {
+ i = crIndex + 1;
+ }
+ }
+ else { // LF occurs before CR!
+ convertedText.append(text.substring(i, lfIndex));
+ i = lfIndex + 1;
+ }
+ if (isSingleLine()) {
+ break;
+ }
+ convertedText.append(delimiter);
+ }
+ // copy remaining text if any and if not in single line mode or no
+ // text copied thus far (because there only is one line)
+ if (i < length && (isSingleLine() == false || convertedText.length() == 0)) {
+ convertedText.append(text.substring(i));
+ }
+ return convertedText.toString();
+}
+/**
+ * Creates default key bindings.
+ */
+void createKeyBindings() {
+ // Navigation
+ setKeyBinding(SWT.ARROW_UP, ST.LINE_UP);
+ setKeyBinding(SWT.ARROW_DOWN, ST.LINE_DOWN);
+ setKeyBinding(SWT.HOME, ST.LINE_START);
+ setKeyBinding(SWT.END, ST.LINE_END);
+ setKeyBinding(SWT.ARROW_LEFT, ST.COLUMN_PREVIOUS);
+ setKeyBinding(SWT.ARROW_RIGHT, ST.COLUMN_NEXT);
+ setKeyBinding(SWT.PAGE_UP, ST.PAGE_UP);
+ setKeyBinding(SWT.PAGE_DOWN, ST.PAGE_DOWN);
+ setKeyBinding(SWT.ARROW_LEFT | SWT.CTRL, ST.WORD_PREVIOUS);
+ setKeyBinding(SWT.ARROW_RIGHT | SWT.CTRL, ST.WORD_NEXT);
+ setKeyBinding(SWT.HOME | SWT.CTRL, ST.TEXT_START);
+ setKeyBinding(SWT.END | SWT.CTRL, ST.TEXT_END);
+ setKeyBinding(SWT.PAGE_UP | SWT.CTRL, ST.WINDOW_START);
+ setKeyBinding(SWT.PAGE_DOWN | SWT.CTRL, ST.WINDOW_END);
+
+ // Selection
+ setKeyBinding(SWT.ARROW_UP | SWT.SHIFT, ST.SELECT_LINE_UP);
+ setKeyBinding(SWT.ARROW_DOWN | SWT.SHIFT, ST.SELECT_LINE_DOWN);
+ setKeyBinding(SWT.HOME | SWT.SHIFT, ST.SELECT_LINE_START);
+ setKeyBinding(SWT.END | SWT.SHIFT, ST.SELECT_LINE_END);
+ setKeyBinding(SWT.ARROW_LEFT | SWT.SHIFT, ST.SELECT_COLUMN_PREVIOUS);
+ setKeyBinding(SWT.ARROW_RIGHT | SWT.SHIFT, ST.SELECT_COLUMN_NEXT);
+ setKeyBinding(SWT.PAGE_UP | SWT.SHIFT, ST.SELECT_PAGE_UP);
+ setKeyBinding(SWT.PAGE_DOWN | SWT.SHIFT, ST.SELECT_PAGE_DOWN);
+ setKeyBinding(SWT.ARROW_LEFT | SWT.CTRL | SWT.SHIFT, ST.SELECT_WORD_PREVIOUS);
+ setKeyBinding(SWT.ARROW_RIGHT | SWT.CTRL | SWT.SHIFT, ST.SELECT_WORD_NEXT);
+ setKeyBinding(SWT.HOME | SWT.CTRL | SWT.SHIFT, ST.SELECT_TEXT_START);
+ setKeyBinding(SWT.END | SWT.CTRL | SWT.SHIFT, ST.SELECT_TEXT_END);
+ setKeyBinding(SWT.PAGE_UP | SWT.CTRL | SWT.SHIFT, ST.SELECT_WINDOW_START);
+ setKeyBinding(SWT.PAGE_DOWN | SWT.CTRL | SWT.SHIFT, ST.SELECT_WINDOW_END);
+
+ // Modification
+ // Cut, Copy, Paste
+ // CUA style
+ setKeyBinding('\u0018' | SWT.CTRL, ST.CUT);
+ setKeyBinding('\u0003' | SWT.CTRL, ST.COPY);
+ setKeyBinding('\u0016' | SWT.CTRL, ST.PASTE);
+ // Wordstar style
+ setKeyBinding(SWT.DEL | SWT.SHIFT, ST.CUT);
+ setKeyBinding(SWT.INSERT | SWT.CTRL, ST.COPY);
+ setKeyBinding(SWT.INSERT | SWT.SHIFT, ST.PASTE);
+
+ setKeyBinding(SWT.BS, ST.DELETE_PREVIOUS);
+ setKeyBinding(SWT.DEL, ST.DELETE_NEXT);
+
+ // Miscellaneous
+ setKeyBinding(SWT.INSERT, ST.TOGGLE_OVERWRITE);
+}
+/**
+ * Create the bidi caret. Use the caret for the current keyboard
+ * mode.
+ */
+void createBidiCaret() {
+ Caret caret = getCaret();
+ if (caret == null) {
+ caret = new Caret(this, SWT.NULL);
+ }
+
+ int direction = StyledTextBidi.getKeyboardLanguageDirection();
+ if (direction == caretDirection) {
+ return;
+ }
+ caretDirection = direction;
+ if (caretDirection == SWT.LEFT) {
+ caret.setImage(leftCaretBitmap);
+ }
+ else
+ if (caretDirection == SWT.RIGHT) {
+ caret.setImage(rightCaretBitmap);
+ }
+}
+/**
+ * Create the bitmaps to use for the caret in bidi mode. This
+ * method only needs to be called upon widget creation and when the
+ * font changes (the caret bitmap height needs to match font height).
+ */
+void createCaretBitmaps() {
+ int caretWidth = BIDI_CARET_WIDTH;
+
+ Display display = getDisplay();
+ if (caretPalette == null) {
+ caretPalette = new PaletteData(new RGB[] {new RGB (0,0,0), new RGB (255,255,255)});
+ }
+
+ if (leftCaretBitmap != null) {
+ leftCaretBitmap.dispose();
+ }
+ ImageData imageData = new ImageData(caretWidth, lineHeight, 1, caretPalette);
+
+ leftCaretBitmap = new Image(display, imageData);
+ GC gc = new GC (leftCaretBitmap);
+ gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
+ gc.drawLine(0,0,0,lineHeight);
+ gc.drawLine(0,0,caretWidth-1,0);
+ gc.drawLine(0,1,1,1);
+ gc.dispose();
+
+ if (rightCaretBitmap != null) {
+ rightCaretBitmap.dispose();
+ }
+ rightCaretBitmap = new Image(display, imageData);
+ gc = new GC (rightCaretBitmap);
+ gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
+ gc.drawLine(caretWidth-1,0,caretWidth-1,lineHeight);
+ gc.drawLine(0,0,caretWidth-1,0);
+ gc.drawLine(caretWidth-1,1,1,1);
+ gc.dispose();
+}
+/**
+ * Moves the selected text to the clipboard. The text will be put in the
+ * clipboard in plain text format and RTF format.
+ * <p>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void cut(){
+ checkWidget();
+ if (selection.y > selection.x) {
+ copy();
+ doDelete();
+ }
+}
+/**
+ * A mouse move event has occurred. See if we should start autoscrolling. If
+ * the move position is outside of the client area, initiate autoscrolling.
+ * Otherwise, we've moved back into the widget so end autoscrolling.
+ */
+void doAutoScroll(Event event) {
+ Rectangle area = getClientArea();
+ if (event.y > area.height) doAutoScroll(SWT.DOWN);
+ else if (event.y < 0) doAutoScroll(SWT.UP);
+ else if (event.x < 0) doAutoScroll(SWT.LEFT);
+ else if (event.x > area.width) doAutoScroll(SWT.RIGHT);
+ else endAutoScroll();
+}
+/**
+ * Initiates autoscrolling.
+ * <p>
+ *
+ * @param direction SWT.UP, SWT.DOWN, SWT.RIGHT, SWT.LEFT
+ */
+void doAutoScroll(int direction) {
+ Runnable timer = null;
+ final int TIMER_INTERVAL = 5;
+
+ // If we're already autoscrolling in the given direction do nothing
+ if (autoScrollDirection == direction) {
+ return;
+ }
+
+ final Display display = getDisplay();
+ // Set a timer that will simulate the user pressing and holding
+ // down a cursor key (i.e., arrowUp, arrowDown).
+ if (direction == SWT.UP) {
+ timer = new Runnable() {
+ public void run() {
+ if (autoScrollDirection == SWT.UP) {
+ doLineUp();
+ doSelection(SWT.LEFT);
+ display.timerExec(TIMER_INTERVAL, this);
+ }
+ }
+ };
+ } else if (direction == SWT.DOWN) {
+ timer = new Runnable() {
+ public void run() {
+ if (autoScrollDirection == SWT.DOWN) {
+ doLineDown();
+ doSelection(SWT.RIGHT);
+ display.timerExec(TIMER_INTERVAL, this);
+ }
+ }
+ };
+ } else if (direction == SWT.RIGHT) {
+ timer = new Runnable() {
+ public void run() {
+ if (autoScrollDirection == SWT.RIGHT) {
+ doColumnRight();
+ doSelection(SWT.RIGHT);
+ display.timerExec(TIMER_INTERVAL, this);
+ }
+ }
+ };
+ } else if (direction == SWT.LEFT) {
+ timer = new Runnable() {
+ public void run() {
+ if (autoScrollDirection == SWT.LEFT) {
+ doColumnLeft();
+ doSelection(SWT.LEFT);
+ display.timerExec(TIMER_INTERVAL, this);
+ }
+ }
+ };
+ }
+ if (timer != null) {
+ autoScrollDirection = direction;
+ display.timerExec(TIMER_INTERVAL, timer);
+ }
+}
+/**
+ * Deletes the previous character. Delete the selected text if any.
+ * Move the caret in front of the deleted text.
+ */
+void doBackspace() {
+ Event event = new Event();
+ event.text = "";
+ if (selection.x != selection.y) {
+ event.start = selection.x;
+ event.end = selection.y;
+ sendKeyEvent(event);
+ }
+ else
+ if (caretOffset > 0) {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+
+ if (caretOffset == lineOffset) {
+ lineOffset = content.getOffsetAtLine(line - 1);
+ event.start = lineOffset + content.getLine(line - 1).length();
+ event.end = caretOffset;
+ }
+ else {
+ event.start = caretOffset - 1;
+ event.end = caretOffset;
+ }
+ sendKeyEvent(event);
+ }
+}
+void doBidiCursorNext() {
+ if (selection.y - selection.x > 0) {
+ caretOffset = selection.y;
+ showCaret();
+ }
+ else {
+ doBidiSelectionCursorNext();
+ }
+}
+void doBidiCursorPrevious() {
+ if (selection.y - selection.x > 0) {
+ caretOffset = selection.x;
+ showCaret();
+ }
+ else {
+ doBidiSelectionCursorPrevious();
+ }
+}
+void doBidiMouseLocationChange(int x, int y, boolean select) {
+ int line = (y + verticalScrollOffset) / lineHeight;
+ int lineCount = content.getLineCount();
+
+ if (line > lineCount - 1) {
+ line = lineCount - 1;
+ }
+ if (line >= 0) {
+ String lineText = content.getLine(line);
+ int lineOffset = content.getOffsetAtLine(line);
+
+
+ GC gc = new GC(this);
+ StyleRange[] styles = null;
+ StyledTextEvent event = getLineStyleData(lineOffset, lineText);
+
+ x += horizontalScrollOffset;
+ if (event != null) {
+ styles = filterLineStyles(event.styles);
+ }
+ lastCaretDirection = SWT.NULL;
+ int[] boldStyles = getBoldRanges(styles, lineOffset, lineText.length());
+ StyledTextBidi bidi = new StyledTextBidi(gc, tabWidth, lineText, boldStyles, boldFont, getStyleOffsets (lineText, lineOffset));
+ int[] values = bidi.getCaretOffsetAndDirectionAtX(x);
+ int offsetInLine = values[0];
+ lastCaretDirection = values[1];
+ int newCaretOffset = lineOffset + offsetInLine;
+// if (newCaretOffset != caretOffset) {
+ caretOffset = newCaretOffset;
+ if (select) {
+ doMouseSelection();
+ }
+ Caret caret = getCaret();
+ if (caret != null) {
+ int caretX = bidi.getCaretPosition(offsetInLine, lastCaretDirection);
+ caretX = caretX - horizontalScrollOffset;
+ if (StyledTextBidi.getKeyboardLanguageDirection() == SWT.RIGHT) {
+ caretX -= (getCaretWidth() - 1);
+ }
+ createBidiCaret();
+ caret.setLocation(caretX, line * lineHeight - verticalScrollOffset);
+ }
+// }
+ if (select == false) {
+ clearSelection(true);
+ }
+ }
+}
+void doBidiSelectionCursorNext() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+
+ if (offsetInLine < content.getLine(line).length()) {
+ caretOffset++;
+ boolean scrolled = scrollBidiCaret();
+ if (scrolled) return;
+ // remember the last direction, should reset
+ // this variable whenever the caret offset changes
+ lastCaretDirection = ST.COLUMN_NEXT;
+ setBidiCaret(false);
+ }
+ else
+ if (line < content.getLineCount() - 1) {
+ line++;
+ caretOffset = content.getOffsetAtLine(line);
+ showCaret();
+ }
+}
+void doBidiSelectionCursorPrevious() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+
+ if (offsetInLine > 0) {
+ caretOffset--;
+ boolean scrolled = scrollBidiCaret();
+ if (scrolled) return;
+ // remember the last direction, should reset
+ // this variable whenever the caret offset changes
+ lastCaretDirection = ST.COLUMN_PREVIOUS;
+ setBidiCaret(false);
+ }
+ else
+ if (line > 0) {
+ line--;
+ lineOffset = content.getOffsetAtLine(line);
+ caretOffset = lineOffset + content.getLine(line).length();
+ showCaret();
+ }
+}
+/**
+ * Moves the caret one character to the left. Do not go to the previous line.
+ * When in a bidi locale and at a R2L character the caret is moved to the
+ * beginning of the R2L segment (visually right) and then one character to the
+ * left (visually left because it's now in a L2R segment).
+ */
+void doColumnLeft() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+
+ if (isBidi()) {
+ GC gc = new GC(this);
+ String lineText = content.getLine(line);
+ int lineLength = lineText.length();
+ StyledTextEvent event = getLineStyleData(lineOffset, lineText);
+ int[] boldStyles = null;
+ StyledTextBidi bidi;
+
+ if (event != null) {
+ boldStyles = getBoldRanges(event.styles, lineOffset, lineLength);
+ }
+ bidi = new StyledTextBidi(gc, tabWidth, lineText, boldStyles, boldFont, getStyleOffsets (lineText, lineOffset));
+ if (horizontalScrollOffset > 0 || offsetInLine > 0) {
+ if (offsetInLine < lineLength && bidi.isRightToLeft(offsetInLine)) {
+ // advance caret logically if in R2L segment (move visually left)
+ caretOffset++;
+ doSelection(SWT.RIGHT);
+ if (caretOffset - lineOffset == lineLength) {
+ // if the line end is reached in a R2L segment, make the caret position
+ // (visual left border) visible before jumping to segment start
+ showCaret();
+ }
+ // end of R2L segment reached (visual left side)?
+ if (bidi.isRightToLeft(caretOffset - lineOffset) == false) {
+ // go to beginning of R2L segment (visually end of next L2R segment)/beginning of line
+ caretOffset--;
+ while (caretOffset - lineOffset > 0 && bidi.isRightToLeft(caretOffset - lineOffset)) {
+ caretOffset--;
+ }
+ }
+ }
+ else
+ if (offsetInLine < lineLength && bidi.isRightToLeft(offsetInLine) == false) {
+ // decrease caret logically if in L2R segment (move visually left)
+ caretOffset--;
+ doSelection(SWT.LEFT);
+ // end of L2R segment reached (visual left side of preceeding R2L segment)?
+ if (caretOffset - lineOffset > 0 && bidi.isRightToLeft(caretOffset - lineOffset - 1)) {
+ // go to beginning of R2L segment (visually start of next L2R segment)/beginning of line
+ caretOffset--;
+ while (caretOffset - lineOffset > 1 && bidi.isRightToLeft(caretOffset - lineOffset - 2)) {
+ caretOffset--;
+ }
+ }
+ }
+ else
+ if (offsetInLine == lineLength && bidi.getCaretPosition(lineLength) != xInset) {
+ // at logical line end in R2L segment but there's more text (a L2R segment)
+ // go to end of R2L segment (visually left of next L2R segment)/end of line
+ caretOffset--;
+ while (caretOffset < lineOffset + lineLength && bidi.isRightToLeft(caretOffset - lineOffset)) {
+ caretOffset--;
+ }
+ }
+ // if new caret position is to the left of the client area
+ if (bidi.getCaretPosition(caretOffset - lineOffset) < horizontalScrollOffset) {
+ // scroll to the caret position
+ showCaret();
+ }
+ else {
+ // otherwise just update caret position without scrolling it into view
+ setCaretLocation();
+ }
+ }
+ gc.dispose();
+ }
+ else
+ if (offsetInLine > 0) {
+ caretOffset--;
+ showCaret();
+ }
+}
+/**
+ * Moves the caret one character to the right. Do not go to the next line.
+ * When in a bidi locale and at a R2L character the caret is moved to the
+ * end of the R2L segment (visually left) and then one character to the
+ * right (visually right because it's now in a L2R segment).
+ */
+void doColumnRight() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+ String lineText = content.getLine(line);
+ int lineLength = lineText.length();
+
+ if (isBidi()) {
+ GC gc = new GC(this);
+ StyledTextEvent event = getLineStyleData(lineOffset, lineText);
+ int[] boldStyles = null;
+ StyledTextBidi bidi;
+
+ if (event != null) {
+ boldStyles = getBoldRanges(event.styles, lineOffset, lineLength);
+ }
+ bidi = new StyledTextBidi(gc, tabWidth, lineText, boldStyles, boldFont, getStyleOffsets (lineText, lineOffset));
+ if (bidi.getTextWidth() > horizontalScrollOffset + getClientArea().width || offsetInLine < lineLength) {
+ if (bidi.isRightToLeft(offsetInLine) == false && offsetInLine < lineLength) {
+ // advance caret logically if in L2R segment (move visually right)
+ caretOffset++;
+ doSelection(SWT.RIGHT);
+ // end of L2R segment reached (visual right side)?
+ if (bidi.isRightToLeft(caretOffset - lineOffset)) {
+ // go to end of R2L segment (visually left of next R2L segment)/end of line
+ caretOffset++;
+ while (caretOffset < lineOffset + lineLength && bidi.isRightToLeft(caretOffset - lineOffset)) {
+ caretOffset++;
+ }
+ }
+ }
+ else
+ if (offsetInLine > 0 && (bidi.isRightToLeft(offsetInLine) || bidi.getTextWidth() > horizontalScrollOffset + getClientArea().width || offsetInLine < lineLength)) {
+ // advance caret visually if in R2L segment or logically at line end
+ // but right end of line is not fully visible yet
+ caretOffset--;
+ doSelection(SWT.LEFT);
+ offsetInLine = caretOffset - lineOffset;
+ // end of R2L segment reached (visual right side)?
+ if (offsetInLine > 0 && bidi.isRightToLeft(offsetInLine) == false) {
+ // go to end of R2L segment (visually left of next L2R segment)/end of line
+ caretOffset++;
+ while (caretOffset < lineOffset + lineLength && bidi.isRightToLeft(caretOffset - lineOffset)) {
+ caretOffset++;
+ }
+ }
+ }
+ else
+ if (offsetInLine == 0 && bidi.getCaretPosition(0) != bidi.getTextWidth()) {
+ // at logical line start in R2L segment but there's more text (a L2R segment)
+ // go to end of R2L segment (visually left of next L2R segment)/end of line
+ caretOffset++;
+ while (caretOffset < lineOffset + lineLength && bidi.isRightToLeft(caretOffset - lineOffset - 1)) {
+ caretOffset++;
+ }
+ }
+ offsetInLine = caretOffset - lineOffset;
+ // if new caret position is to the right of the client area
+ if (bidi.getCaretPosition(offsetInLine) >= horizontalScrollOffset) {
+ // scroll to the caret position
+ showCaret();
+ }
+ else {
+ // otherwise just update caret position without scrolling it into view
+ setCaretLocation();
+ }
+ if (offsetInLine > 0 && offsetInLine < lineLength - 1) {
+ int clientAreaEnd = horizontalScrollOffset + getClientArea().width;
+ boolean directionChange = bidi.isRightToLeft(offsetInLine - 1) == false && bidi.isRightToLeft(offsetInLine);
+ int textWidth = bidi.getTextWidth();
+ // between L2R and R2L segment and second character of R2L segment is left of right border and logical line end is left of right border but visual line end is not left of right border
+ if (directionChange &&
+ bidi.isRightToLeft(offsetInLine + 1) && bidi.getCaretPosition(offsetInLine + 1) < clientAreaEnd &&
+ bidi.getCaretPosition(lineLength) < clientAreaEnd && textWidth > clientAreaEnd) {
+ // make visual line end visible
+ scrollHorizontalBar(textWidth - clientAreaEnd);
+ }
+ }
+ }
+ gc.dispose();
+ }
+ else
+ if (offsetInLine < lineLength) {
+ caretOffset++;
+ showCaret();
+ }
+}
+/**
+ * Replaces the selection with the character or insert the character at the
+ * current caret position if no selection exists.
+ * If a carriage return was typed replace it with the line break character
+ * used by the widget on this platform.
+ * <p>
+ *
+ * @param key the character typed by the user
+ */
+void doContent(char key) {
+ Event event;
+
+ if (textLimit > 0 && content.getCharCount() - (selection.y - selection.x) >= textLimit) {
+ return;
+ }
+ event = new Event();
+ event.start = selection.x;
+ event.end = selection.y;
+ // replace a CR line break with the widget line break
+ // CR does not make sense on Windows since most (all?) applications
+ // don't recognize CR as a line break.
+ if (key == SWT.CR || key == SWT.LF) {
+ if (isSingleLine() == false) {
+ event.text = getLineDelimiter();
+ }
+ }
+ // no selection and overwrite mode is on and the typed key is not a
+ // tab character (tabs are always inserted without overwriting)?
+ else
+ if (selection.x == selection.y && overwrite == true && key != TAB) {
+ int lineIndex = content.getLineAtOffset(event.end);
+ int lineOffset = content.getOffsetAtLine(lineIndex);
+ String line = content.getLine(lineIndex);
+ // replace character at caret offset if the caret is not at the
+ // end of the line
+ if (event.end < lineOffset + line.length()) {
+ event.end++;
+ }
+ event.text = new String(new char[] {key});
+ }
+ else {
+ event.text = new String(new char[] {key});
+ }
+ if (event.text != null) {
+ sendKeyEvent(event);
+ }
+}
+/**
+ * Moves the caret after the last character of the widget content.
+ */
+void doContentEnd() {
+ int length = content.getCharCount();
+
+ if (caretOffset < length) {
+ caretOffset = length;
+ showCaret();
+ }
+}
+/**
+ * Moves the caret in front of the first character of the widget content.
+ */
+void doContentStart() {
+ if (caretOffset > 0) {
+ caretOffset = 0;
+ showCaret();
+ }
+}
+/**
+ * Moves the caret to the start of the selection if a selection exists.
+ * Otherwise, if no selection exists move the cursor according to the
+ * cursor selection rules.
+ * <p>
+ *
+ * @see #doSelectionCursorLeft
+ */
+void doCursorPrevious() {
+ if (isBidi()) {
+ doBidiCursorPrevious();
+ return;
+ }
+ if (selection.y - selection.x > 0) {
+ caretOffset = selection.x;
+ showCaret();
+ }
+ else {
+ doSelectionCursorPrevious();
+ }
+}
+/**
+ * Moves the caret to the end of the selection if a selection exists.
+ * Otherwise, if no selection exists move the cursor according to the
+ * cursor selection rules.
+ * <p>
+ *
+ * @see #doSelectionCursorRight
+ */
+void doCursorNext() {
+ if (isBidi()) {
+ doBidiCursorNext();
+ return;
+ }
+ if (selection.y - selection.x > 0) {
+ caretOffset = selection.y;
+ showCaret();
+ }
+ else {
+ doSelectionCursorNext();
+ }
+}
+/**
+ * Deletes the next character. Delete the selected text if any.
+ */
+void doDelete() {
+ Event event = new Event();
+
+ event.text = "";
+ if (selection.x != selection.y) {
+ event.start = selection.x;
+ event.end = selection.y;
+ sendKeyEvent(event);
+ }
+ else
+ if (caretOffset < content.getCharCount()) {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int lineLength = content.getLine(line).length();
+
+ if (caretOffset == lineOffset + lineLength) {
+ event.start = caretOffset;
+ event.end = content.getOffsetAtLine(line + 1);
+ }
+ else {
+ event.start = caretOffset;
+ event.end = caretOffset + 1;
+ }
+ sendKeyEvent(event);
+ }
+}
+/**
+ * Moves the caret one line down and to the same character offset relative
+ * to the beginning of the line. Move the caret to the end of the new line
+ * if the new line is shorter than the character offset.
+ * Make the new caret position visible.
+ */
+void doLineDown() {
+ doSelectionLineDown();
+ showCaret();
+}
+/**
+ * Moves the caret to the end of the line.
+ */
+void doLineEnd() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int lineLength = content.getLine(line).length();
+ int lineEndOffset = lineOffset + lineLength;
+
+ if (caretOffset < lineEndOffset) {
+ caretOffset = lineEndOffset;
+ showCaret();
+ }
+}
+/**
+ * Moves the caret to the beginning of the line.
+ */
+void doLineStart() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+
+ if (caretOffset > lineOffset) {
+ caretOffset = lineOffset;
+ showCaret();
+ }
+}
+/**
+ * Moves the caret one line up and to the same character offset relative
+ * to the beginning of the line. Move the caret to the end of the new line
+ * if the new line is shorter than the character offset.
+ */
+void doLineUp() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+
+ if (line > 0) {
+ line--;
+ lineOffset = content.getOffsetAtLine(line);
+ int lineLength = content.getLine(line).length();
+ if (offsetInLine > lineLength) {
+ offsetInLine = lineLength;
+ }
+ caretOffset = lineOffset + offsetInLine;
+ showCaret();
+ }
+}
+/**
+ * Moves the caret to the specified location.
+ * <p>
+ *
+ * @param x x location of the new caret position
+ * @param y y location of the new caret position
+ * @param select the location change is a selection operation.
+ * include the line delimiter in the selection
+ */
+void doMouseLocationChange(int x, int y, boolean select) {
+ if (isBidi()) {
+ doBidiMouseLocationChange(x, y, select);
+ return;
+ }
+ int line = (y + verticalScrollOffset) / lineHeight;
+ int lineCount = content.getLineCount();
+
+ if (line > lineCount - 1) {
+ line = lineCount - 1;
+ }
+ if (line >= 0) {
+ String lineText = content.getLine(line);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = getCaretOffsetAtX(lineText, lineOffset, x);
+ int newCaretOffset = lineOffset + offsetInLine;
+
+ if (newCaretOffset != caretOffset) {
+ caretOffset = newCaretOffset;
+ if (select) {
+ doMouseSelection();
+ }
+ setCaretLocation();
+ }
+ if (select == false) {
+ clearSelection(true);
+ }
+ }
+}
+/**
+ * Updates the selection based on the caret position
+ */
+void doMouseSelection() {
+ if (caretOffset <= selection.x || (caretOffset > selection.x && caretOffset < selection.y && selectionAnchor == selection.x)) {
+ doSelection(SWT.LEFT);
+ }
+ else {
+ doSelection(SWT.RIGHT);
+ }
+}
+/**
+ * Scrolls one page down so that the last line (truncated or whole)
+ * of the current page becomes the fully visible top line.
+ * The caret is scrolled the same number of lines so that its location
+ * relative to the top line remains the same. The exception is the end
+ * of the text where a full page scroll is not possible. In this case the
+ * caret is moved after the last character.
+ * <p>
+ *
+ * @param select whether or not to select the page
+ */
+void doPageDown(boolean select) {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineCount = content.getLineCount();
+
+ if (line < lineCount) {
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+ int lineLength;
+ int verticalMaximum = content.getLineCount() * getVerticalIncrement();
+ int pageSize = getClientArea().height;
+ int scrollLines = Math.min(lineCount - line - 1, getLineCountWhole() - 1);
+ int scrollOffset;
+
+ line += scrollLines;
+ lineOffset = content.getOffsetAtLine(line);
+ lineLength = content.getLine(line).length();
+ // set cursor to end of line if cursor would be beyond the end
+ // of line or if page down goes to last line
+ if (offsetInLine > lineLength || line == lineCount - 1) {
+ offsetInLine = lineLength;
+ }
+ caretOffset = lineOffset + offsetInLine;
+ if (select) {
+ doSelection(SWT.RIGHT);
+ }
+ // scroll one page down or to the bottom
+ scrollOffset = verticalScrollOffset + scrollLines * getVerticalIncrement();
+ if (scrollOffset + pageSize > verticalMaximum) {
+ scrollOffset = verticalMaximum - pageSize;
+ }
+ if (scrollOffset > verticalScrollOffset) {
+ setVerticalScrollOffset(scrollOffset, true);
+ }
+ else {
+ showCaret();
+ }
+ }
+}
+/**
+ * Moves the cursor to the end of the last fully visible line.
+ */
+void doPageEnd() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineCount = content.getLineCount();
+
+ if (line < lineCount) {
+ line = getBottomIndex();
+ caretOffset = content.getOffsetAtLine(line) + content.getLine(line).length();
+ showCaret();
+ }
+}
+/**
+ * Moves the cursor to the beginning of the first fully visible line.
+ */
+void doPageStart() {
+ if (content.getLineAtOffset(caretOffset) > topIndex) {
+ caretOffset = content.getOffsetAtLine(topIndex);
+ showCaret();
+ }
+}
+/**
+ * Scrolls one page up so that the first line (truncated or whole)
+ * of the current page becomes the fully visible last line.
+ * The caret is scrolled the same number of lines so that its location
+ * relative to the top line remains the same. The exception is the beginning
+ * of the text where a full page scroll is not possible. In this case the
+ * caret is moved in front of the first character.
+ */
+void doPageUp() {
+ int line = content.getLineAtOffset(caretOffset);
+
+ if (line > 0) {
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+ int lineLength;
+ int scrollLines = Math.min(line, getLineCountWhole() - 1);
+ int scrollOffset;
+
+ line -= scrollLines;
+ lineOffset = content.getOffsetAtLine(line);
+ lineLength = content.getLine(line).length();
+ // set cursor to start of line if page up goes to first line
+ if (line == 0) {
+ offsetInLine = 0;
+ }
+ else
+ if (offsetInLine > lineLength) {
+ offsetInLine = lineLength;
+ }
+ caretOffset = lineOffset + offsetInLine;
+ // scroll one page up or to the top
+ scrollOffset = Math.max(0, verticalScrollOffset - scrollLines * getVerticalIncrement());
+ if (scrollOffset < verticalScrollOffset) {
+ setVerticalScrollOffset(scrollOffset, true);
+ }
+ else {
+ showCaret();
+ }
+ }
+}
+/**
+ * Moves the caret one line down and to the same character offset relative
+ * to the beginning of the line. Move the caret to the end of the new line
+ * if the new line is shorter than the character offset.
+ */
+void doSelectionLineDown() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+
+ if (line < content.getLineCount() - 1) {
+ line++;
+ lineOffset = content.getOffsetAtLine(line);
+ int lineLength = content.getLine(line).length();
+ if (offsetInLine > lineLength) {
+ offsetInLine = lineLength;
+ }
+ caretOffset = lineOffset + offsetInLine;
+ }
+}
+/**
+ * Updates the selection to extend to the current caret position.
+ */
+void doSelection(int direction) {
+ int redrawStart = -1;
+ int redrawEnd = -1;
+
+ if (selectionAnchor == -1) {
+ selectionAnchor = selection.x;
+ }
+ if (direction == SWT.LEFT) {
+ if (caretOffset < selection.x) {
+ // grow selection
+ redrawEnd = selection.x;
+ redrawStart = selection.x = caretOffset;
+ // check if selection has reversed direction
+ if (selection.y != selectionAnchor) {
+ redrawEnd = selection.y;
+ selection.y = selectionAnchor;
+ }
+ }
+ else // test whether selection actually changed. Fixes 1G71EO1
+ if (selectionAnchor == selection.x && caretOffset < selection.y) {
+ // caret moved towards selection anchor (left side of selection).
+ // shrink selection
+ redrawEnd = selection.y;
+ redrawStart = selection.y = caretOffset;
+ }
+ }
+ else {
+ if (caretOffset > selection.y) {
+ // grow selection
+ redrawStart = selection.y;
+ redrawEnd = selection.y = caretOffset;
+ // check if selection has reversed direction
+ if (selection.x != selectionAnchor) {
+ redrawStart = selection.x;
+ selection.x = selectionAnchor;
+ }
+ }
+ else // test whether selection actually changed. Fixes 1G71EO1
+ if (selectionAnchor == selection.y && caretOffset > selection.x) {
+ // caret moved towards selection anchor (right side of selection).
+ // shrink selection
+ redrawStart = selection.x;
+ redrawEnd = selection.x = caretOffset;
+ }
+ }
+ if (redrawStart != -1 && redrawEnd != -1) {
+ internalRedrawRange(redrawStart, redrawEnd - redrawStart, true);
+ sendSelectionEvent();
+ }
+}
+/**
+ * Moves the caret to the previous character or to the end of the previous
+ * line if the cursor is at the beginning of a line.
+ */
+void doSelectionCursorPrevious() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+
+ if (offsetInLine > 0) {
+ caretOffset--;
+ showCaret();
+ }
+ else
+ if (line > 0) {
+ line--;
+ lineOffset = content.getOffsetAtLine(line);
+ caretOffset = lineOffset + content.getLine(line).length();
+ showCaret();
+ }
+}
+/**
+ * Moves the caret to the next character or to the beginning of the
+ * next line if the cursor is at the end of a line.
+ */
+void doSelectionCursorNext() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+
+ if (offsetInLine < content.getLine(line).length()) {
+ caretOffset++;
+ showCaret();
+ }
+ else
+ if (line < content.getLineCount() - 1) {
+ line++;
+ caretOffset = content.getOffsetAtLine(line);
+ showCaret();
+ }
+}
+/**
+ * Moves the caret to the start of the previous word.
+ * If a selection exists, move the caret to the start of the selection
+ * and remove the selection.
+ */
+void doWordPrevious() {
+ if (selection.y - selection.x > 0) {
+ caretOffset = selection.x;
+ showCaret();
+ }
+ else {
+ doSelectionWordPrevious();
+ }
+}
+/**
+ * Moves the caret to the end of the next word.
+ * If a selection exists, move the caret to the end of the selection
+ * and remove the selection.
+ */
+void doWordNext() {
+ if (selection.y - selection.x > 0) {
+ caretOffset = selection.y;
+ showCaret();
+ }
+ else {
+ doSelectionWordNext();
+ }
+}
+/**
+ * Moves the caret to the start of the previous word.
+ */
+void doSelectionWordPrevious() {
+ caretOffset = getWordStart(caretOffset);
+ showCaret();
+}
+/**
+ * Moves the caret to the end of the next word .
+ */
+void doSelectionWordNext() {
+ caretOffset = getWordEnd(caretOffset);
+ showCaret();
+}
+/**
+ * Draws the specified rectangle.
+ * Draw directly without invalidating the affected area when clearBackground is
+ * false.
+ * <p>
+ *
+ * @param x the x position
+ * @param y the y position
+ * @param width the width
+ * @param height the height
+ * @param clearBackground true=clear the background by invalidating the requested
+ * redraw area, false=draw the foreground directly without invalidating the
+ * redraw area.
+ */
+void draw(int x, int y, int width, int height, boolean clearBackground) {
+ if (clearBackground) {
+ redraw(x, y, width, height, true);
+ }
+ else {
+ int startLine = (y + verticalScrollOffset) / lineHeight;
+ int endY = y + height;
+ int paintYFromTopLine = (startLine - topIndex) * lineHeight;
+ int topLineOffset = (topIndex * lineHeight - verticalScrollOffset);
+ int paintY = paintYFromTopLine + topLineOffset; // adjust y position for pixel based scrolling
+ int lineCount = content.getLineCount();
+ Color background = getBackground();
+ Color foreground = getForeground();
+ GC gc = new GC(this);
+
+ if (isSingleLine()) {
+ lineCount = 1;
+ if (startLine > 1) {
+ startLine = 1;
+ }
+ }
+ for (int i = startLine; paintY < endY && i < lineCount; i++, paintY += lineHeight) {
+ String line = content.getLine(i);
+ drawLine(line, i, paintY, gc, background, foreground, clearBackground);
+ }
+ gc.dispose();
+ }
+}
+/**
+ * Draws a line of text at the specified location.
+ * <p>
+ *
+ * @param line the line to draw
+ * @param lineIndex index of the line to draw
+ * @param paintY y location to draw at
+ * @param gc GC to draw on
+ * @param widgetBackground the widget background color. Used as the default rendering color.
+ * @param widgetForeground the widget foreground color. Used as the default rendering color.
+ */
+void drawLine(String line, int lineIndex, int paintY, GC gc, Color widgetBackground, Color widgetForeground, boolean clearBackground) {
+ int lineOffset = content.getOffsetAtLine(lineIndex);
+ int lineLength = line.length();
+ int selectionStart = selection.x;
+ int selectionEnd = selection.y;
+ StyleRange[] styles = new StyleRange[0];
+ Color lineBackground = null;
+ StyledTextEvent event = getLineStyleData(lineOffset, line);
+ StyledTextBidi bidi = null;
+
+ if (event != null) {
+ styles = event.styles;
+ }
+ if (isBidi()) {
+ int[] boldStyles = getBoldRanges(styles, lineOffset, lineLength);
+ setLineFont(gc, gc.getFont().getFontData()[0], SWT.NORMAL);
+ bidi = new StyledTextBidi(gc, tabWidth, line, boldStyles, boldFont, getStyleOffsets (line, lineOffset));
+ }
+ event = getLineBackgroundData(lineOffset, line);
+ if (event != null) {
+ lineBackground = event.lineBackground;
+ }
+ if (lineBackground == null) {
+ lineBackground = widgetBackground;
+ }
+ if (clearBackground && ((getStyle() & SWT.FULL_SELECTION) == 0 || selectionStart > lineOffset || selectionEnd <= lineOffset + lineLength)) {
+ // draw background if full selection is off or if line is not completely selected
+ gc.setBackground(lineBackground);
+ gc.setForeground(lineBackground);
+ gc.fillRectangle(0, paintY, getClientArea().width, lineHeight);
+ }
+ if (selectionStart != selectionEnd) {
+ drawLineSelectionBackground(line, lineOffset, styles, paintY, gc, bidi);
+ }
+ if (selectionStart != selectionEnd && ((selectionStart >= lineOffset && selectionStart < lineOffset + lineLength) || (selectionStart < lineOffset && selectionEnd > lineOffset))) {
+ styles = getSelectionLineStyles(styles);
+ }
+ if (isBidi()) {
+ int paintX = textWidth(line, lineOffset, 0, 0, styles, 0, gc, bidi);
+ drawStyledLine(line, lineOffset, 0, styles, paintX, paintY, gc, lineBackground, widgetForeground, bidi);
+ }
+ else {
+ drawStyledLine(line, lineOffset, 0, styles, 0, paintY, gc, lineBackground, widgetForeground, bidi);
+ }
+}
+/**
+ * Draws the background of the line selection.
+ * <p>
+ *
+ * @param line the line to draw
+ * @param lineOffset offset of the first character in the line.
+ * Relative to the start of the document.
+ * @param styles line styles
+ * @param paintY y location to draw at
+ * @param gc GC to draw on
+ * @param bidi the bidi object to use for measuring and rendering text in bidi locales.
+ * null when not in bidi mode.
+ */
+void drawLineSelectionBackground(String line, int lineOffset, StyleRange[] styles, int paintY, GC gc, StyledTextBidi bidi) {
+ int lineLength = line.length();
+ int paintX;
+ int selectionBackgroundWidth = -1;
+ int selectionStart = Math.max(0, selection.x - lineOffset);
+ int selectionEnd = selection.y - lineOffset;
+ int selectionLength = selectionEnd - selectionStart;
+
+ if (selectionEnd == selectionStart || selectionEnd < 0 || selectionStart > lineLength) {
+ return;
+ }
+ paintX = textWidth(line, lineOffset, 0, selectionStart, filterLineStyles(styles), 0, gc, bidi);
+ // selection extends past end of line?
+ if (selectionEnd > lineLength) {
+ if ((getStyle() & SWT.FULL_SELECTION) != 0) {
+ // use the greater of the client area width and the content width
+ // fixes 1G8IYRD
+ selectionBackgroundWidth = Math.max(getClientArea().width, contentWidth);
+ }
+ else {
+ selectionLength = lineLength - selectionStart;
+ }
+ }
+ gc.setBackground(getSelectionBackground());
+ gc.setForeground(getSelectionForeground());
+ if (selectionBackgroundWidth == -1) {
+ selectionBackgroundWidth = textWidth(line, lineOffset, selectionStart, selectionLength, styles, paintX, gc, bidi);
+ if (selectionBackgroundWidth < 0) {
+ // width can be negative when in R2L bidi segment
+ paintX += selectionBackgroundWidth;
+ selectionBackgroundWidth *= -1;
+ }
+ if (selectionEnd > lineLength) {
+ selectionEnd = selectionStart + selectionLength;
+ // if the selection extends past this line, render an additional whitespace
+ // background at the end of the line to represent the selected line break
+ if (bidi != null && selectionEnd > 0 && bidi.isRightToLeft(selectionEnd - 1)) {
+ int lineEndX = bidi.getTextWidth();
+ gc.fillRectangle(lineEndX - horizontalScrollOffset, paintY, lineEndSpaceWidth, lineHeight);
+ }
+ else {
+ selectionBackgroundWidth += lineEndSpaceWidth;
+ }
+ }
+ }
+ // handle empty line case
+ if (bidi != null && (paintX == 0)) {
+ paintX = xInset;
+ }
+ // fill the background first since expanded tabs are not
+ // drawn as spaces. tabs just move the draw position.
+ gc.fillRectangle(paintX - horizontalScrollOffset, paintY, selectionBackgroundWidth, lineHeight);
+}
+/**
+ * Draws the line at the specified location.
+ * <p>
+ *
+ * @param line the line to draw
+ * @param lineOffset offset of the first character in the line.
+ * Relative to the start of the document.
+ * @param renderOffset offset of the first character that should be rendered.
+ * Relative to the start of the line.
+ * @param styles the styles to use for rendering line segments. May be empty but not null.
+ * @param paintX x location to draw at
+ * @param paintY y location to draw at
+ * @param gc GC to draw on
+ * @param lineBackground line background color, used when no style is specified for a line segment.
+ * @param lineForeground line foreground color, used when no style is specified for a line segment.
+ * @param bidi the bidi object to use for measuring and rendering text in bidi locales.
+ * null when not in bidi mode.
+ */
+void drawStyledLine(String line, int lineOffset, int renderOffset, StyleRange[] styles, int paintX, int paintY, GC gc, Color lineBackground, Color lineForeground, StyledTextBidi bidi) {
+ int lineLength = line.length();
+ Color background = gc.getBackground();
+ Color foreground = gc.getForeground();
+ StyleRange style = null;
+ StyleRange[] filteredStyles = filterLineStyles(styles);
+ int renderStopX = getClientArea().width + horizontalScrollOffset;
+ FontData fontData = gc.getFont().getFontData()[0];
+
+ // Always render the entire line when in a bidi locale.
+ // Since we render the line in logical order we may start past the end
+ // of the visual right border of the client area and work towards the
+ // left.
+ for (int i = 0; i < styles.length && (paintX < renderStopX || bidi != null); i++) {
+ int styleLineLength;
+ int styleLineStart;
+ int styleLineEnd;
+ style = styles[i];
+ styleLineEnd = style.start + style.length - lineOffset;
+ styleLineStart = Math.max(style.start - lineOffset, 0);
+ // render unstyled text between the start of the current
+ // style range and the end of the previously rendered
+ // style range
+ if (styleLineStart > renderOffset) {
+ background = setLineBackground(gc, background, lineBackground);
+ foreground = setLineForeground(gc, foreground, lineForeground);
+ setLineFont(gc, fontData, SWT.NORMAL);
+ // don't try to render more text than requested
+ styleLineStart = Math.min(lineLength, styleLineStart);
+ paintX = drawText(line, lineOffset, renderOffset, styleLineStart - renderOffset, paintX, paintY, gc, bidi);
+ renderOffset = styleLineStart;
+ }
+ else
+ if (styleLineEnd <= renderOffset) {
+ // style ends before render start offset
+ // skip to the next style
+ continue;
+ }
+ if (styleLineStart >= lineLength) {
+ // there are line styles but no text for those styles
+ // possible when called with partial line text
+ break;
+ }
+ styleLineLength = Math.min(styleLineEnd, lineLength) - renderOffset;
+ // set style background color if specified
+ if (style.background != null) {
+ background = setLineBackground(gc, background, style.background);
+ foreground = setLineForeground(gc, foreground, style.background);
+ if (bidi != null) {
+ bidi.fillBackground(renderOffset, styleLineLength, -horizontalScrollOffset, paintY, lineHeight);
+ }
+ else {
+ int fillWidth = textWidth(line, lineOffset, renderOffset, styleLineLength, filteredStyles, paintX, gc, bidi);
+ gc.fillRectangle(paintX - horizontalScrollOffset, paintY, fillWidth, lineHeight);
+ }
+ }
+ else {
+ background = setLineBackground(gc, background, lineBackground);
+ }
+ // set style foreground color if specified
+ if (style.foreground != null) {
+ foreground = setLineForeground(gc, foreground, style.foreground);
+ }
+ else {
+ foreground = setLineForeground(gc, foreground, lineForeground);
+ }
+ setLineFont(gc, fontData, style.fontStyle);
+ paintX = drawText(line, lineOffset, renderOffset, styleLineLength, paintX, paintY, gc, bidi);
+ renderOffset += styleLineLength;
+ }
+ // render unstyled text at the end of the line
+ if ((style == null || renderOffset < lineLength) && (paintX < renderStopX || bidi != null)) {
+ setLineBackground(gc, background, lineBackground);
+ setLineForeground(gc, foreground, lineForeground);
+ setLineFont(gc, fontData, SWT.NORMAL);
+ drawText(line, lineOffset, renderOffset, lineLength - renderOffset, paintX, paintY, gc, bidi);
+ }
+}
+/**
+ * Draws the text at the specified location. Expands tabs to tab stops using
+ * the widget tab width.
+ * <p>
+ *
+ * @param text text to draw
+ * @param lineOffset offset of the first character in the line.
+ * Relative to the start of the document.
+ * @param startOffset offset of the first character in text to draw
+ * @param length number of characters to draw
+ * @param paintX x location to start drawing at
+ * @param paintY y location to draw at. Unused when draw is false
+ * @param gc GC to draw on
+ * location where drawing would stop
+ * @param bidi the bidi object to use for measuring and rendering text in bidi locales.
+ * null when not in bidi mode.
+ * @return x location where drawing stopped or 0 if the startOffset or
+ * length is outside the specified text.
+ */
+int drawText(String text, int lineOffset, int startOffset, int length, int paintX, int paintY, GC gc, StyledTextBidi bidi) {
+ int endOffset = startOffset + length;
+ int textLength = text.length();
+
+ if (startOffset < 0 || startOffset >= textLength || startOffset + length > textLength) {
+ return paintX;
+ }
+ for (int i = startOffset; i < endOffset; i++) {
+ int tabIndex = text.indexOf(TAB, i);
+ // is tab not present or past the rendering range?
+ if (tabIndex == -1 || tabIndex > endOffset) {
+ tabIndex = endOffset;
+ }
+ if (tabIndex != i) {
+ String tabSegment = text.substring(i, tabIndex);
+ if (bidi != null) {
+ paintX = bidi.drawBidiText(i, tabIndex - i, -horizontalScrollOffset, paintY);
+ }
+ else {
+ gc.drawString(tabSegment, paintX - horizontalScrollOffset, paintY, true);
+ paintX += gc.stringExtent(tabSegment).x;
+ if (tabIndex != endOffset && tabWidth > 0) {
+ paintX += tabWidth;
+ paintX -= paintX % tabWidth;
+ }
+ }
+ i = tabIndex;
+ }
+ else // is tab at current rendering offset?
+ if (tabWidth > 0 && isBidi() == false) {
+ paintX += tabWidth;
+ paintX -= paintX % tabWidth;
+ }
+ }
+ return paintX;
+}
+/**
+ * Ends the autoscroll process.
+ */
+void endAutoScroll() {
+ autoScrollDirection = SWT.NULL;
+}
+/**
+ * @param styles styles that may contain font styles.
+ * @return null if the styles contain only regular font styles, the
+ * unchanged styles otherwise.
+ */
+StyleRange[] filterLineStyles(StyleRange[] styles) {
+ if (styles != null) {
+ int styleIndex = 0;
+ while (styleIndex < styles.length && styles[styleIndex].fontStyle == SWT.NORMAL) {
+ styleIndex++;
+ }
+ if (styleIndex == styles.length) {
+ styles = null;
+ }
+ }
+ return styles;
+}
+/**
+ * Returns an array of bold text ranges for a line.
+ * <p>
+ * @param styles style ranges in the line, may be bold and non-bold
+ * @param lineOffset start index of the line, relative to the start of the document
+ * @param length of the line
+ * @return
+ * array[i] = bold start, relative to the start of the line
+ * array[i + 1] = bold length, no more than lineLength
+ * null if styles parameter is null
+ */
+int[] getBoldRanges(StyleRange[] styles, int lineOffset, int lineLength) {
+ int boldCount = 0;
+ int[] boldRanges = null;
+
+ if (styles == null) {
+ return null;
+ }
+ for (int i = 0; i < styles.length; i++) {
+ if (styles[i].fontStyle == SWT.BOLD) {
+ boldCount++;
+ }
+ }
+ if (boldCount > 0) {
+ boldRanges = new int[boldCount * 2];
+ boldCount = 0;
+ for (int i = 0; i < styles.length; i++) {
+ StyleRange style = styles[i];
+ if (style.fontStyle == SWT.BOLD) {
+ int styleEnd = Math.min(style.start + style.length - lineOffset, lineLength);
+ int styleStart = Math.max(0, style.start - lineOffset);
+ boldRanges[boldCount] = styleStart;
+ boldRanges[boldCount + 1] = styleEnd - styleStart;
+ boldCount += 2;
+ }
+ }
+ }
+ return boldRanges;
+}
+/**
+ * Returns the index of the last fully visible line.
+ * <p>
+ *
+ * @return index of the last fully visible line.
+ */
+int getBottomIndex() {
+ return Math.min(content.getLineCount(), topIndex + getLineCountWhole()) - 1;
+}
+/**
+ * Returns the caret position relative to the start of the text.
+ * <p>
+ *
+ * @return the caret position relative to the start of 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 int getCaretOffset() {
+ checkWidget();
+
+ return caretOffset;
+}
+/**
+ * Returns the caret offset at the given x location in the line.
+ * The caret offset is the offset of the character where the caret will be
+ * placed when a mouse click occurs. The caret offset will be the offset of
+ * the character after the clicked one if the mouse click occurs at the second
+ * half of a character.
+ * Doesn't properly handle ligatures and other context dependent characters
+ * unless the current locale is a bidi locale.
+ * Ligatures are handled properly as long as they don't occur at lineXOffset.
+ * <p>
+ *
+ * @param line text of the line to calculate the offset in
+ * @param lineOffset offset of the first character in the line.
+ * 0 based from the beginning of the document.
+ * @param lineXOffset x location in the line
+ * @return caret offset at the x location relative to the start of the line.
+ */
+int getCaretOffsetAtX(String line, int lineOffset, int lineXOffset) {
+ int offset = 0;
+ GC gc = new GC(this);
+ StyleRange[] styles = null;
+ StyledTextEvent event = getLineStyleData(lineOffset, line);
+
+ lineXOffset += horizontalScrollOffset;
+ if (event != null) {
+ styles = filterLineStyles(event.styles);
+ }
+ int low = -1;
+ int high = line.length();
+ while (high - low > 1) {
+ offset = (high + low) / 2;
+ int x = textWidth(line, lineOffset, 0, offset, styles, 0, gc, null);
+ int charWidth = textWidth(line, lineOffset, 0, offset + 1, styles, 0, gc, null) - x;
+ if (lineXOffset <= x + charWidth / 2) {
+ high = offset;
+ }
+ else {
+ low = offset;
+ }
+ }
+ offset = high;
+ gc.dispose();
+ return offset;
+}
+
+/**
+ * Returns the caret width.
+ * <p>
+ *
+ * @return the caret width, 0 if caret is null.
+ */
+int getCaretWidth() {
+ Caret caret = getCaret();
+ if (caret == null) return 0;
+ return caret.getSize().x;
+}
+/**
+ * Returns the content implementation that is used for text storage
+ * or null if no user defined content implementation has been set.
+ * <p>
+ *
+ * @return content implementation that is used for text storage or null
+ * if no user defined content implementation has been set.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public StyledTextContent getContent() {
+ checkWidget();
+
+ return content;
+}
+/**
+ * Returns whether the widget implements double click mouse behavior.
+ * <p>
+ *
+ * @return true if double clicking a word selects the word, false if double clicks
+ * have the same effect as regular mouse clicks
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 doubleClickEnabled;
+}
+/**
+ * Returns whether the widget content can be edited.
+ * <p>
+ *
+ * @return true if content can be edited, 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>
+ */
+public boolean getEditable() {
+ checkWidget();
+
+ return editable;
+}
+/**
+ * Returns the horizontal scroll increment.
+ * <p>
+ *
+ * @return horizontal scroll increment.
+ */
+int getHorizontalIncrement() {
+ GC gc = new GC(this);
+ int increment = gc.getFontMetrics().getAverageCharWidth();
+
+ gc.dispose();
+ return increment;
+}
+/**
+ * Returns the horizontal scroll offset relative to the start of the line.
+ * <p>
+ *
+ * @return horizontal scroll offset relative to the start of the line,
+ * measured in character increments starting at 0, if > 0 the content is scrolled
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public int getHorizontalIndex() {
+ checkWidget();
+
+ return horizontalScrollOffset / getHorizontalIncrement();
+}
+/**
+ * Returns the horizontal scroll offset relative to the start of the line.
+ * <p>
+ *
+ * @return the horizontal scroll offset relative to the start of the line,
+ * measured in pixel starting at 0, if > 0 the content is scrolled.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public int getHorizontalPixel() {
+ checkWidget();
+
+ return horizontalScrollOffset;
+}
+/**
+ * Returns the action assigned to the key.
+ * Returns SWT.NULL if there is no action associated with the key.
+ * <p>
+ *
+ * @param key a key code defined in SWT.java or a character.
+ * Optionally ORd with a state mask (one or more of SWT.CTRL, SWT.SHIFT, SWT.ALT)
+ * @return one of the predefined actions defined in ST.java or SWT.NULL
+ * if there is no action associated with the key.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public int getKeyBinding(int key) {
+ checkWidget();
+ Integer action = (Integer) keyActionMap.get(new Integer(key));
+ int intAction;
+
+ if (action == null) {
+ intAction = SWT.NULL;
+ }
+ else {
+ intAction = action.intValue();
+ }
+ return intAction;
+}
+/**
+ * Gets the number of characters.
+ * <p>
+ *
+ * @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 content.getCharCount();
+}
+/**
+ * Returns the background color of the line at the given index.
+ * Returns null if a LineBackgroundListener has been set or if no background
+ * color has been specified for the line. Should not be called if a
+ * LineBackgroundListener has been set since the listener maintains the
+ * line background colors.
+ * <p>
+ *
+ * @return the background color of the line at the given 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>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT when the index is invalid</li>
+ * </ul>
+ */
+public Color getLineBackground(int index) {
+ checkWidget();
+ Color lineBackground = null;
+
+ if (index < 0 || index > content.getLineCount()) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (userLineBackground == false) {
+ lineBackground = defaultLineStyler.getLineBackground(index);
+ }
+ return lineBackground;
+}
+/**
+ * Gets the number of text lines.
+ * <p>
+ *
+ * @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 getLineAtOffset(getCharCount()) + 1;
+}
+/**
+ * Returns the number of lines that are at least partially displayed in the widget client area.
+ * <p>
+ *
+ * @return number of lines that are at least partially displayed in the widget client area.
+ */
+int getLineCountTruncated() {
+ int lineCount;
+
+ if (lineHeight != 0) {
+ lineCount = (int) Math.ceil((float) getClientArea().height / lineHeight);
+ }
+ else {
+ lineCount = 1;
+ }
+ return lineCount;
+}
+
+/**
+ * Returns the number of lines that are completely displayed in the widget client area.
+ * <p>
+ *
+ * @return number of lines that are completely displayed in the widget client area.
+ */
+int getLineCountWhole() {
+ int lineCount;
+
+ if (lineHeight != 0) {
+ lineCount = getClientArea().height / lineHeight;
+ }
+ else {
+ lineCount = 1;
+ }
+ return lineCount;
+}
+
+/**
+ * Returns the line at the specified offset in the text.
+ * 0 <= offset <= getCharCount() so that getLineAtOffset(getCharCount())
+ * returns the line of the insert location.
+ * <p>
+ *
+ * @param offset offset relative to the start of the content. 0 <= offset <= getCharCount()
+ * @return line at the specified offset in 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>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_RANGE when the offset is outside the valid range (< 0 or > getCharCount())</li>
+ * </ul>
+ */
+public int getLineAtOffset(int offset) {
+ checkWidget();
+
+ if (offset < 0 || offset > getCharCount()) {
+ SWT.error(SWT.ERROR_INVALID_RANGE);
+ }
+ return content.getLineAtOffset(offset);
+}
+
+/**
+ * Returns the line delimiter used for entering new lines by key down
+ * or paste operation.
+ * <p>
+ *
+ * @return line delimiter used for entering new lines by key down
+ * or paste operation.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 content.getLineDelimiter();
+}
+/**
+ * Returns the line height.
+ * <p>
+ *
+ * @return line height in pixel.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 lineHeight;
+}
+/**
+ * Returns the line style data for the given line or null if there is none.
+ * If there is a LineStyleListener but it does not set any styles, the
+ * StyledTextEvent.styles field will be initialized to an empty array.
+ */
+StyledTextEvent getLineStyleData(int lineOffset, String line) {
+ if (isListening(LineGetStyle)) {
+ StyledTextEvent event = new StyledTextEvent(content);
+ event.detail = lineOffset;
+ event.text = line;
+ notifyListeners(LineGetStyle, event);
+ if (event.styles == null) {
+ event.styles = new StyleRange[0];
+ }
+ return event;
+ }
+ return null;
+}
+/**
+ * Returns the line background data for the given line or null if there is none.
+ */
+StyledTextEvent getLineBackgroundData(int lineOffset, String line) {
+ if (isListening(LineGetBackground)) {
+ StyledTextEvent event = new StyledTextEvent(content);
+ event.detail = lineOffset;
+ event.text = line;
+ notifyListeners(LineGetBackground, event);
+ return event;
+ }
+ return null;
+}
+/**
+ * Returns the x, y location of the upper left corner of the character
+ * bounding box at the specified offset in the text. The point is
+ * relative to the upper left corner of the widget client area.
+ * <p>
+ *
+ * @param offset offset relative to the start of the content.
+ * 0 <= offset <= getCharCount()
+ * @return x, y location of the upper left corner of the character
+ * bounding box at the specified offset in 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>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_RANGE when the offset is outside the valid range (< 0 or > getCharCount())</li>
+ * </ul>
+ */
+public Point getLocationAtOffset(int offset) {
+ checkWidget();
+ if (offset < 0 || offset > getCharCount()) {
+ SWT.error(SWT.ERROR_INVALID_RANGE);
+ }
+ int line = getLineAtOffset(offset);
+ int lineOffset = content.getOffsetAtLine(line);
+ String lineContent = content.getLine(line);
+ int x = getXAtOffset(lineContent, line, offset - lineOffset);
+ int y = line * lineHeight - verticalScrollOffset;
+
+ return new Point(x, y);
+}
+/**
+ * Returns the offset of the character at the given location relative
+ * to the first character in the document.
+ * The return value reflects the character offset that the caret will
+ * be placed at if a mouse click occurred at the specified location.
+ * If the x coordinate of the location is beyond the center of a character
+ * the returned offset will be behind the character.
+ * <p>
+ *
+ * @param point the origin of character bounding box relative to
+ * the origin of the widget client area.
+ * @return offset of the character at the given location relative
+ * to the first character in the document.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when point is null</li>
+ * <li>ERROR_INVALID_ARGUMENT when there is no character at the specified location</li>
+ * </ul>
+ */
+public int getOffsetAtLocation(Point point) {
+ checkWidget();
+ int line;
+ int lineOffset;
+ int offsetInLine;
+ String lineText;
+
+ if (point == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ // is y above first line or is x before first column?
+ if (point.y + verticalScrollOffset < 0 || point.x + horizontalScrollOffset < 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ line = (getTopPixel() + point.y) / lineHeight;
+ // does the referenced line exist?
+ if (line >= content.getLineCount()) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ lineText = content.getLine(line);
+ lineOffset = content.getOffsetAtLine(line);
+ offsetInLine = getOffsetAtX(lineText, lineOffset, point.x);
+ // is the x position within the line?
+ if (offsetInLine == -1) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ return lineOffset + offsetInLine;
+}
+/**
+ * Returns the offset of the character at the given x location in the line.
+ * <p>
+ *
+ * @param line text of the line to calculate the offset in
+ * @param lineOffset offset of the first character in the line.
+ * 0 based from the beginning of the document.
+ * @param lineXOffset x location in the line
+ * @return offset of the character at the x location relative to the start
+ * of the line. -1 if the x location is past the end if the line.
+ */
+int getOffsetAtX(String line, int lineOffset, int lineXOffset) {
+ int offset;
+ GC gc = new GC(this);
+ StyleRange[] styles = null;
+ StyledTextEvent event = getLineStyleData(lineOffset, line);
+
+ if (event != null) {
+ styles = filterLineStyles(event.styles);
+ }
+ lineXOffset += horizontalScrollOffset;
+ if (isBidi()) {
+ int[] boldStyles = getBoldRanges(styles, lineOffset, line.length());
+ StyledTextBidi bidi = new StyledTextBidi(gc, tabWidth, line, boldStyles, boldFont, getStyleOffsets (line, lineOffset));
+ offset = bidi.getOffsetAtX(lineXOffset);
+ }
+ else {
+ int low = -1;
+ int high = line.length();
+ while (high - low > 1) {
+ offset = (high + low) / 2;
+ if (lineXOffset <= textWidth(line, lineOffset, 0, offset + 1, styles, 0, gc, null)) {
+ high = offset;
+ }
+ else
+ if (high == line.length() && high - offset == 1) {
+ // requested x location is past end of line
+ high = -1;
+ }
+ else {
+ low = offset;
+ }
+ }
+ offset = high;
+ }
+ gc.dispose();
+ return offset;
+}
+/**
+ * Returns the index of the last partially visible line.
+ *
+ * @return index of the last partially visible line.
+ */
+int getPartialBottomIndex() {
+ int partialLineCount = (int) Math.ceil((float) getClientArea().height / lineHeight);
+
+ return Math.min(content.getLineCount(), topIndex + partialLineCount) - 1;
+}
+/**
+ * Returns the content in the specified range using the platform line
+ * delimiter to separate lines.
+ * <p>
+ *
+ * @param writer the TextWriter to write line text into
+ * @return the content in the specified range using the platform line
+ * delimiter to separate lines as written by the specified TextWriter.
+ */
+String getPlatformDelimitedText(TextWriter writer) {
+ int end = writer.getStart() + writer.getCharCount();
+ int startLine = content.getLineAtOffset(writer.getStart());
+ int endLine = content.getLineAtOffset(end);
+ String endLineText = content.getLine(endLine);
+ int endLineOffset = content.getOffsetAtLine(endLine);
+
+ for (int i = startLine; i <= endLine; i++) {
+ writer.writeLine(content.getLine(i), content.getOffsetAtLine(i));
+ if (i < endLine) {
+ writer.writeLineDelimiter(PlatformLineDelimiter);
+ }
+ }
+ if (end > endLineOffset + endLineText.length()) {
+ writer.writeLineDelimiter(PlatformLineDelimiter);
+ }
+ writer.close();
+ return writer.toString();
+}
+/**
+ * Returns the selection.
+ * <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
+ * <p>
+ *
+ * @return start and end of the selection, x is the offset of the first selected
+ * character, y is the offset after the last selected character
+ * @see #getSelectionRange
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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();
+ return new Point(selection.x, selection.y);
+}
+/**
+ * Returns the selection.
+ * <p>
+ *
+ * @return start and length of the selection, x is the offset of the first selected
+ * character, relative to the first character of the widget content. y is the length
+ * 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 getSelectionRange() {
+ checkWidget();
+ return new Point(selection.x, selection.y - selection.x);
+}
+/*
+Pseudo code for getSelectionLineStyles
+ for each style {
+ if (style ends before selection start) {
+ add style to list
+ }
+ else
+ if (style overlaps selection start (i.e., starts before selection start, ends after selection start) {
+ change style end
+ create new selection style with same font style starting at selection start ending at style end
+ add selection style
+ // does style extend beyond selection?
+ if (selection style end > selection end) {
+ selection style end = selection end
+ // preserve rest (unselected part) of old style
+ style start = selection end
+ style length = old style end - selection end
+ add style
+ }
+ }
+ else
+ if (style starts within selection) {
+ if (no selection style created) {
+ create selection style with regular font style, starting at selection start, ending at style start
+ add selection style
+ if (style start == selection start) {
+ set selection style font to style font
+ }
+ }
+ // gap between current selection style end and new style start?
+ if (style start > selection styke end && selection style font style != NORMAL) {
+ create selection style with regular font style, starting at selection style end, ending at style start
+ add selection style
+ }
+ if (selection style font != style font) {
+ selection style end = style start
+ add selection style
+ create selection style with style font style, starting at style start, ending at style end
+ }
+ else {
+ selection style end = style end
+ }
+ // does style extend beyond selection?
+ if (selection style end > selection end) {
+ selection style end = selection end
+ // preserve rest (unselected part) of old style
+ style start = selection end
+ style length = old style end - selection end
+ style start = selection end
+ add style
+ }
+ }
+ else {
+ if (no selection style created) {
+ create selection style with regular font style, starting at selection start, ending at selection end
+ add selection style
+ }
+ else
+ if (selection style end < selection end) {
+ if (selection style font style != NORMAL) {
+ create selection style with regular font style, starting at selection style end, ending at selection end
+ add selection style
+ }
+ else {
+ selection style end = selection end
+ }
+ }
+ add style
+ }
+ }
+ if (no selection style created) {
+ create selection style with regular font style, starting at selection start, ending at selection end
+ add selection style to list
+ }
+ else
+ if (selection style end < selection end) {
+ if (selection style font style != NORMAL) {
+ create selection style with regular font style, starting at selection style end, ending at selection end
+ add selection style
+ }
+ else {
+ selection style end = selection end
+ }
+ }
+*/
+/**
+ * Merges the selection into the styles that are passed in.
+ * The font style of existing style ranges is preserved in the selection.
+ * <p>
+ * @param styles the existing styles that the selection should be applied to.
+ * @return the selection style range merged with the existing styles
+ */
+StyleRange[] getSelectionLineStyles(StyleRange[] styles) {
+ int selectionStart = selection.x;
+ int selectionEnd = selection.y;
+ Vector newStyles = new Vector(styles.length);
+ StyleRange selectionStyle = null;
+ Color foreground = getSelectionForeground();
+ Color background = getSelectionBackground();
+
+ // potential optimization: ignore styles if there is no bold style and the entire line is selected
+ for (int i = 0; i < styles.length; i++) {
+ StyleRange style = styles[i];
+ int styleEnd = style.start + style.length;
+
+ if (styleEnd <= selectionStart) {
+ newStyles.addElement(style);
+ }
+ else // style overlaps selection start? (i.e., starts before selection start, ends after selection start
+ if (style.start < selectionStart && styleEnd > selectionStart) {
+ StyleRange newStyle = (StyleRange) style.clone();
+ newStyle.length -= styleEnd - selectionStart;
+ newStyles.addElement(newStyle);
+ // create new selection style with same font style starting at selection start ending at style end
+ selectionStyle = new StyleRange(selectionStart, styleEnd - selectionStart, foreground, background, newStyle.fontStyle);
+ newStyles.addElement(selectionStyle);
+ // if style extends beyond selection a new style is returned for the unselected part of the style
+ newStyle = setSelectionStyleEnd(selectionStyle, style);
+ if (newStyle != null) {
+ newStyles.addElement(newStyle);
+ }
+ }
+ else // style starts within selection?
+ if (style.start >= selectionStart && style.start < selectionEnd) {
+ StyleRange newStyle;
+ int selectionStyleEnd;
+ // no selection style created yet?
+ if (selectionStyle == null) {
+ // create selection style with regular font style, starting at selection start, ending at style start
+ selectionStyle = new StyleRange(selectionStart, style.start - selectionStart, foreground, background);
+ newStyles.addElement(selectionStyle);
+ if (style.start == selectionStart) {
+ selectionStyle.fontStyle = style.fontStyle;
+ }
+ }
+ selectionStyleEnd = selectionStyle.start + selectionStyle.length;
+ // gap between current selection style end and style start?
+ if (style.start > selectionStyleEnd && selectionStyle.fontStyle != SWT.NORMAL) {
+ // create selection style with regular font style, starting at selection style end, ending at style start
+ selectionStyle = new StyleRange(selectionStyleEnd, style.start - selectionStyleEnd, foreground, background);
+ newStyles.addElement(selectionStyle);
+ }
+ if (selectionStyle.fontStyle != style.fontStyle) {
+ // selection style end = style start
+ selectionStyle.length = style.start - selectionStyle.start;
+ // create selection style with style font style, starting at style start, ending at style end
+ selectionStyle = new StyleRange(style.start, style.length, foreground, background, style.fontStyle);
+ newStyles.addElement(selectionStyle);
+ }
+ else {
+ // selection style end = style end
+ selectionStyle.length = styleEnd - selectionStyle.start;
+ }
+ // if style extends beyond selection a new style is returned for the unselected part of the style
+ newStyle = setSelectionStyleEnd(selectionStyle, style);
+ if (newStyle != null) {
+ newStyles.addElement(newStyle);
+ }
+ }
+ else {
+ // no selection style created yet?
+ if (selectionStyle == null) {
+ // create selection style with regular font style, starting at selection start, ending at selection end
+ selectionStyle = new StyleRange(selectionStart, selectionEnd - selectionStart, foreground, background);
+ newStyles.addElement(selectionStyle);
+ }
+ else // does the current selection style end before the selection end?
+ if (selectionStyle.start + selectionStyle.length < selectionEnd) {
+ if (selectionStyle.fontStyle != SWT.NORMAL) {
+ int selectionStyleEnd = selectionStyle.start + selectionStyle.length;
+ // create selection style with regular font style, starting at selection style end, ending at selection end
+ selectionStyle = new StyleRange(selectionStyleEnd, selectionEnd - selectionStyleEnd, foreground, background);
+ newStyles.addElement(selectionStyle);
+ }
+ else {
+ selectionStyle.length = selectionEnd - selectionStyle.start;
+ }
+ }
+ newStyles.addElement(style);
+ }
+ }
+ if (selectionStyle == null) {
+ // create selection style with regular font style, starting at selection start, ending at selection end
+ selectionStyle = new StyleRange(selectionStart, selectionEnd - selectionStart, foreground, background);
+ newStyles.addElement(selectionStyle);
+ }
+ else // does the current selection style end before the selection end?
+ if (selectionStyle.start + selectionStyle.length < selectionEnd) {
+ if (selectionStyle.fontStyle != SWT.NORMAL) {
+ int selectionStyleEnd = selectionStyle.start + selectionStyle.length;
+ // create selection style with regular font style, starting at selection style end, ending at selection end
+ selectionStyle = new StyleRange(selectionStyleEnd, selectionEnd - selectionStyleEnd, foreground, background);
+ newStyles.addElement(selectionStyle);
+ }
+ else {
+ selectionStyle.length = selectionEnd - selectionStyle.start;
+ }
+ }
+ styles = new StyleRange[newStyles.size()];
+ newStyles.copyInto(styles);
+ return styles;
+}
+/**
+ * Returns the background color to be used for rendering selected text.
+ * <p>
+ *
+ * @return background color to be used for rendering selected text
+ */
+Color getSelectionBackground() {
+ return getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
+}
+/**
+ * Gets the number of selected characters.
+ * <p>
+ *
+ * @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();
+ return getSelectionRange().y;
+}
+/**
+ * Returns the foreground color to be used for rendering selected text.
+ * <p>
+ *
+ * @return foreground color to be used for rendering selected text
+ */
+Color getSelectionForeground() {
+ return getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
+}
+/**
+ * Returns the selected text.
+ * <p>
+ *
+ * @return selected text, or an empty String if there is no selection.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public String getSelectionText() {
+ checkWidget();
+
+ return content.getTextRange(selection.x, selection.y - selection.x);
+}
+
+/**
+ * Returns the style range at the given offset.
+ * Returns null if a LineStyleListener has been set or if a style is not set
+ * for the offset.
+ * Should not be called if a LineStyleListener has been set since the
+ * listener maintains the styles.
+ * <p>
+ *
+ * @return a StyleRange with start == offset and length == 1, indicating
+ * the style at the given offset. null if a LineStyleListener has been set
+ * or if a style is not set for the given offset.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT when the offset is invalid</li>
+ * </ul>
+ */
+public StyleRange getStyleRangeAtOffset(int offset) {
+ checkWidget();
+ if (offset < 0 || offset > getCharCount()) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (userLineStyle == false) {
+ return defaultLineStyler.getStyleRangeAtOffset(offset);
+ }
+ return null;
+}
+/**
+ * Returns the styles.
+ * Returns an empty array if a LineStyleListener has been set.
+ * Should not be called if a LineStyleListener has been set since the
+ * listener maintains the styles.
+ * <p>
+ *
+ * @return the styles or null if a LineStyleListener has been set.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public StyleRange [] getStyleRanges() {
+ checkWidget();
+ StyleRange styles[];
+
+ if (userLineStyle == false) {
+ styles = defaultLineStyler.getStyleRanges();
+ }
+ else {
+ styles = new StyleRange[0];
+ }
+ return styles;
+}
+/**
+ * Returns the tab width measured in characters.
+ *
+ * @return tab width measured in 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 tabLength;
+}
+/**
+ * Returns a copy of the widget content.
+ * <p>
+ *
+ * @return copy of the widget content
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 content.getTextRange(0, getCharCount());
+}
+
+/**
+ * Returns the widget content between the two offsets.
+ * <p>
+ *
+ * @param start offset of the first character in the returned String
+ * @param end offset of the last character in the returned String
+ * @return widget content starting at start and ending at end
+ * @see #getTextRange(int,int)
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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_INVALID_RANGE when start and/or end are outside the widget content</li>
+ * </ul>
+ */
+public String getText(int start, int end) {
+ checkWidget();
+ int contentLength = getCharCount();
+
+ if (start < 0 || start >= contentLength || end < 0 || end >= contentLength || start > end) {
+ SWT.error(SWT.ERROR_INVALID_RANGE);
+ }
+ return content.getTextRange(start, end - start + 1);
+}
+/**
+ * Returns the widget content starting at start for length characters.
+ * <p>
+ *
+ * @param start offset of the first character in the returned String
+ * @param length number of characters to return
+ * @return widget content starting at start and extending length 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>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_RANGE when start and/or length are outside the widget content</li>
+ * </ul>
+ */
+public String getTextRange(int start, int length) {
+ checkWidget();
+ int contentLength = getCharCount();
+ int end = start + length;
+
+ if (start < 0 || start > contentLength || end < 0 || end > contentLength || start > end) {
+ SWT.error(SWT.ERROR_INVALID_RANGE);
+ }
+ return content.getTextRange(start, length);
+}
+
+/**
+ * Gets the text limit. The text limit specifies the amount of text that the user
+ * can type into the widget.
+ * <p>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public int getTextLimit() {
+ checkWidget();
+
+ return textLimit;
+}
+
+/**
+ * Gets the top index. The top index is the index of the fully visible line that
+ * is currently at the top of the widget. The top index changes when the widget
+ * is scrolled. Indexing is zero based.
+ * <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();
+
+ return topIndex;
+}
+
+/**
+ * Gets the top pixel. The top pixel is the pixel position of the line that is
+ * currently at the top of the widget.The text widget can be scrolled by pixels
+ * by dragging the scroll thumb so that a partial line may be displayed at the top
+ * the widget. The top pixel changes when the widget is scrolled. The top pixel
+ * does not include the widget trimming.
+ * <p>
+ *
+ * @return 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 verticalScrollOffset;
+}
+
+/**
+ * Returns the vertical scroll increment.
+ * <p>
+ *
+ * @return vertical scroll increment.
+ */
+int getVerticalIncrement() {
+ return lineHeight;
+}
+/**
+ * Returns the offset of the character after the word at the specified
+ * offset.
+ * <p>
+ * There are two classes of words formed by a sequence of characters:
+ * <ul>
+ * <li>from 0-9 and A-z (ASCII 48-57 and 65-122)
+ * <li>every other character except line breaks
+ * </ul>
+ * </p>
+ * <p>
+ * Space characters ' ' (ASCII 20) are special as they are treated as
+ * part of the word leading up to the space character. Line breaks are
+ * treated as one word.
+ * </p>
+ */
+int getWordEnd(int offset) {
+ int line = content.getLineAtOffset(offset);
+ int lineOffset = content.getOffsetAtLine(line);
+ String lineText = content.getLine(line);
+ int lineLength = lineText.length();
+
+ if (offset >= getCharCount()) {
+ return offset;
+ }
+ if (offset == lineOffset + lineLength) {
+ line++;
+ offset = content.getOffsetAtLine(line);
+ }
+ else {
+ offset -= lineOffset;
+ char ch = lineText.charAt(offset);
+ boolean letterOrDigit = Character.isLetterOrDigit(ch);
+ while (offset < lineLength - 1 && Character.isLetterOrDigit(ch) == letterOrDigit) {
+ offset++;
+ ch = lineText.charAt(offset);
+ }
+ // skip over trailing whitespace
+ while (offset < lineLength - 1 && Character.isSpaceChar(ch)) {
+ offset++;
+ ch = lineText.charAt(offset);
+ }
+ if (offset == lineLength - 1 && (Character.isLetterOrDigit(ch) == letterOrDigit || Character.isSpaceChar(ch))) {
+ offset++;
+ }
+ offset += lineOffset;
+ }
+ return offset;
+}
+
+/**
+ * Returns the offset of the character after the word at the specified
+ * offset.
+ * <p>
+ * There are two classes of words formed by a sequence of characters:
+ * <ul>
+ * <li>from 0-9 and A-z (ASCII 48-57 and 65-122)
+ * <li>every other character except line breaks
+ * </ul>
+ * </p>
+ * <p>
+ * Spaces are ignored and do not represent a word. Line breaks are treated
+ * as one word.
+ * </p>
+ */
+int getWordEndNoSpaces(int offset) {
+ int line = content.getLineAtOffset(offset);
+ int lineOffset = content.getOffsetAtLine(line);
+ String lineText = content.getLine(line);
+ int lineLength = lineText.length();
+
+ if (offset >= getCharCount()) {
+ return offset;
+ }
+ if (offset == lineOffset + lineLength) {
+ line++;
+ offset = content.getOffsetAtLine(line);
+ }
+ else {
+ offset -= lineOffset;
+ char ch = lineText.charAt(offset);
+ boolean letterOrDigit = Character.isLetterOrDigit(ch);
+
+ while (offset < lineLength - 1 && Character.isLetterOrDigit(ch) == letterOrDigit && Character.isSpaceChar(ch) == false) {
+ offset++;
+ ch = lineText.charAt(offset);
+ }
+ if (offset == lineLength - 1 && Character.isLetterOrDigit(ch) == letterOrDigit && Character.isSpaceChar(ch) == false) {
+ offset++;
+ }
+ offset += lineOffset;
+ }
+ return offset;
+}
+
+/**
+ * Returns the start offset of the word at the specified offset.
+ * There are two classes of words formed by a sequence of characters:
+ * <p>
+ * <ul>
+ * <li>from 0-9 and A-z (ASCII 48-57 and 65-122)
+ * <li>every other character except line breaks
+ * </ul>
+ * </p>
+ * <p>
+ * Space characters ' ' (ASCII 20) are special as they are treated as
+ * part of the word leading up to the space character. Line breaks are treated
+ * as one word.
+ * </p>
+ */
+int getWordStart(int offset) {
+ int line = content.getLineAtOffset(offset);
+ int lineOffset = content.getOffsetAtLine(line);
+ String lineText = content.getLine(line);
+
+ if (offset <= 0) {
+ return offset;
+ }
+ if (offset == lineOffset) {
+ line--;
+ lineText = content.getLine(line);
+ offset = content.getOffsetAtLine(line) + lineText.length();
+ }
+ else {
+ char ch;
+ boolean letterOrDigit;
+
+ offset -= lineOffset;
+ // skip over trailing whitespace
+ do {
+ offset--;
+ ch = lineText.charAt(offset);
+ } while (offset > 0 && Character.isSpaceChar(ch));
+ letterOrDigit = Character.isLetterOrDigit(ch);
+ while (offset > 0 && Character.isLetterOrDigit(ch) == letterOrDigit && Character.isSpaceChar(ch) == false) {
+ offset--;
+ ch = lineText.charAt(offset);
+ }
+ if (offset > 0 || Character.isLetterOrDigit(ch) != letterOrDigit) {
+ offset++;
+ }
+ offset += lineOffset;
+ }
+ return offset;
+}
+
+/**
+ * Returns the x location of the character at the give offset in the line.
+ * <b>NOTE:</b> Does not return correct values for true italic fonts (vs. slanted fonts).
+ * <p>
+ *
+ * @return x location of the character at the give offset in the line.
+ */
+int getXAtOffset(String line, int lineIndex, int lineOffset) {
+ int x;
+
+ if (lineOffset == 0 && isBidi() == false) {
+ x = 0;
+ }
+ else {
+ GC gc = new GC(this);
+ x = textWidth(line, lineIndex, Math.min(line.length(), lineOffset), gc);
+ gc.dispose();
+ if (lineOffset > line.length()) {
+ // offset is not on the line. return an x location one character
+ // after the line to indicate the line delimiter.
+ x += lineEndSpaceWidth;
+ }
+ }
+ return x - horizontalScrollOffset;
+}
+/**
+ * Inserts a string. The old selection is replaced with the new text.
+ * <p>
+ *
+ * @param string the string
+ * @see #replaceTextRange(int,int,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>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT when string is null</li>
+ * </ul>
+ */
+public void insert(String string) {
+ checkWidget();
+ if (string == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ Point sel = getSelectionRange();
+ replaceTextRange(sel.x, sel.y, string);
+}
+/**
+ * Creates content change listeners and set the default content model.
+ */
+void installDefaultContent() {
+ textChangeListener = new TextChangeListener() {
+ public void textChanging(TextChangingEvent event) {
+ handleTextChanging(event);
+ }
+ public void textChanged(TextChangedEvent event) {
+ handleTextChanged(event);
+ }
+ public void textSet(TextChangedEvent event) {
+ handleTextSet(event);
+ }
+ };
+ content = new DefaultContent();
+ content.addTextChangeListener(textChangeListener);
+}
+/**
+ * Creates a default line style listener.
+ * Used to store line background colors and styles.
+ * Removed when the user sets a LineStyleListener.
+ * <p>
+ *
+ * @see #addLineStyleListener
+ */
+void installDefaultLineStyler() {
+ defaultLineStyler = new DefaultLineStyler(content);
+ StyledTextListener typedListener = new StyledTextListener(defaultLineStyler);
+ if (userLineStyle == false) {
+ addListener(LineGetStyle, typedListener);
+ }
+ if (userLineBackground == false) {
+ addListener(LineGetBackground, typedListener);
+ }
+}
+/**
+ * Adds event listeners
+ */
+void installListeners() {
+ ScrollBar verticalBar = getVerticalBar();
+ ScrollBar horizontalBar = getHorizontalBar();
+
+ addListener(SWT.Dispose, new Listener() {
+ public void handleEvent(Event event) {
+ handleDispose();
+ }
+ });
+ addListener(SWT.KeyDown, new Listener() {
+ public void handleEvent(Event event) {
+ handleKeyDown(event);
+ }
+ });
+ addListener(SWT.MouseDown, new Listener() {
+ public void handleEvent(Event event) {
+ handleMouseDown(event);
+ }
+ });
+ addListener(SWT.MouseUp, new Listener() {
+ public void handleEvent(Event event) {
+ handleMouseUp(event);
+ }
+ });
+ addListener(SWT.MouseDoubleClick, new Listener() {
+ public void handleEvent(Event event) {
+ handleMouseDoubleClick(event);
+ }
+ });
+ addListener(SWT.MouseMove, new Listener() {
+ public void handleEvent(Event event) {
+ handleMouseMove(event);
+ }
+ });
+ addListener(SWT.Paint, new Listener() {
+ public void handleEvent(Event event) {
+ handlePaint(event);
+ }
+ });
+ addListener(SWT.Resize, new Listener() {
+ public void handleEvent(Event event) {
+ handleResize(event);
+ }
+ });
+ addListener(SWT.Traverse, new Listener() {
+ public void handleEvent(Event event) {
+ // do nothing
+ // hooked to disable automatic tab traversal on tab key press
+ }
+ });
+ if (verticalBar != null) {
+ verticalBar.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ handleVerticalScroll(event);
+ }
+ });
+ }
+ if (horizontalBar != null) {
+ horizontalBar.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ handleHorizontalScroll(event);
+ }
+ });
+ }
+}
+/**
+ * Redraws the specified text range.
+ * <p>
+ *
+ * @param start offset of the first character to redraw
+ * @param length number of characters to redraw
+ * @param clearBackground true if the background should be cleared as part of the
+ * redraw operation. If true, the entire redraw area will be cleared before anything
+ * is redrawn. The redraw operation will be faster and smoother if clearBackground
+ * is set to false. Whether or not the flag can be set to false depends on the type
+ * of change that has taken place. If font styles or background colors for the redraw
+ * area have changed, clearBackground should be set to true. If only foreground colors
+ * have changed for the redraw area, clearBackground can be set to false.
+ */
+void internalRedrawRange(int start, int length, boolean clearBackground) {
+ int end = start + length;
+ int firstLine = content.getLineAtOffset(start);
+ int lastLine = content.getLineAtOffset(end);
+ int offsetInFirstLine;
+ int partialBottomIndex = getPartialBottomIndex();
+ int partialTopIndex = verticalScrollOffset / lineHeight;
+
+ // do nothing if redraw range is completely invisible
+ if (firstLine > partialBottomIndex || lastLine < partialTopIndex) {
+ return;
+ }
+ // only redraw visible lines
+ if (partialTopIndex > firstLine) {
+ firstLine = partialTopIndex;
+ offsetInFirstLine = 0;
+ }
+ else {
+ offsetInFirstLine = start - content.getOffsetAtLine(firstLine);
+ }
+ if (partialBottomIndex + 1 < lastLine) {
+ lastLine = partialBottomIndex + 1; // + 1 to redraw whole bottom line, including line break
+ end = content.getOffsetAtLine(lastLine);
+ }
+ // redraw first and last lines
+ if (isBidi()) {
+ redrawBidiLines(firstLine, offsetInFirstLine, lastLine, end, clearBackground);
+ }
+ else {
+ redrawLines(firstLine, offsetInFirstLine, lastLine, end, clearBackground);
+ }
+ // redraw entire center lines if redraw range includes more than two lines
+ if (lastLine - firstLine > 1) {
+ Rectangle clientArea = getClientArea();
+ int redrawStopY = lastLine * lineHeight - verticalScrollOffset;
+ int redrawY = (firstLine + 1) * lineHeight - verticalScrollOffset;
+ draw(0, redrawY, clientArea.width, redrawStopY - redrawY, clearBackground);
+ }
+}
+/**
+ * Returns the widget text with style information encoded using RTF format
+ * specification version 1.5.
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+String getRtf(){
+ checkWidget();
+ String rtfText = null;
+ int length = getCharCount();
+
+ if (length > 0) {
+ RTFWriter rtfWriter = new RTFWriter(0, length);
+ rtfText = getPlatformDelimitedText(rtfWriter);
+ }
+ return rtfText;
+}
+/**
+ * Frees resources.
+ */
+void handleDispose() {
+ Enumeration colors;
+
+ clipboard.dispose();
+ ibeamCursor.dispose();
+ if (boldFont != null) {
+ boldFont.dispose();
+ }
+ if (content != null) {
+ content.removeTextChangeListener(textChangeListener);
+ }
+ if (leftCaretBitmap != null) {
+ leftCaretBitmap.dispose();
+ }
+ if (rightCaretBitmap != null) {
+ rightCaretBitmap.dispose();
+ }
+ if (isBidi()) {
+ StyledTextBidi.removeLanguageListener(this.handle);
+ }
+}
+/**
+ * Updates the caret location and selection if mouse button 1 has been
+ * pressed.
+ */
+void handleMouseDoubleClick(Event event) {
+ if (event.button != 1 || doubleClickEnabled == false) {
+ return;
+ }
+ mouseDoubleClick = true;
+ caretOffset = getWordEndNoSpaces(caretOffset);
+ resetSelection();
+ caretOffset = getWordStart(caretOffset);
+ showCaret();
+ doMouseSelection();
+}
+/**
+ * Updates the caret location and selection if mouse button 1 has been
+ * pressed.
+ */
+void handleMouseDown(Event event) {
+ if (event.button != 1) {
+ return;
+ }
+ mouseDoubleClick = false;
+ doMouseLocationChange(event.x, event.y, (event.stateMask & SWT.SHIFT) != 0);
+}
+/**
+ * Autoscrolling ends when the mouse button is released.
+ */
+void handleMouseUp(Event event) {
+ endAutoScroll();
+}
+/**
+ * Updates the caret location and selection if mouse button 1 is pressed
+ * during the mouse move.
+ */
+void handleMouseMove(Event event) {
+ if (mouseDoubleClick == true || (event.stateMask & SWT.BUTTON1) == 0) {
+ return;
+ }
+ doMouseLocationChange(event.x, event.y, true);
+ doAutoScroll(event);
+ // caret location only needs to be updated if we are not autoscrolling
+// if (autoScrollDirection == SWT.NULL) {
+// doMouseLocationChange(event.x, event.y, true);
+// }
+}
+/**
+ * Replaces the selection with the clipboard text or insert the text at
+ * the current caret offset if there is no selection.
+ * If the widget has the SWT.SINGLE style and the clipboard text contains
+ * more than one line, only the first line without line delimiters is
+ * inserted in the widget.
+ * <p>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void paste(){
+ checkWidget();
+ TextTransfer transfer = TextTransfer.getInstance();
+ String text;
+
+ text = (String) clipboard.getContents(transfer);
+ if (text != null && text.length() > 0) {
+ Event event = new Event();
+ event.start = selection.x;
+ event.end = selection.y;
+ event.text = getModelDelimitedText(text);
+ sendKeyEvent(event);
+ }
+}
+/**
+ * Prints the widget's text to the default printer.
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void print() {
+ checkWidget();
+ StyledTextPrinter.print(this);
+}
+ /**
+ * Returns a runnable that will print the widget's text
+ * to the specified printer.
+ * <p>
+ * The runnable may be run in a non-UI thread.
+ * </p>
+ *
+ * @param printer the printer to print 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>
+ */
+public Runnable print(Printer printer) {
+ checkWidget();
+ return new StyledTextPrinter(this, printer);
+}
+
+/**
+ * Scrolls the widget horizontally.
+ */
+void handleHorizontalScroll(Event event) {
+ int scrollPixel = getHorizontalBar().getSelection() - horizontalScrollOffset;
+ scrollHorizontal(scrollPixel);
+}
+
+/**
+ * If a VerifyKey listener exists, verify that the key that was entered
+ * should be processed.
+ * <p>
+ *
+ * @param event keyboard event
+ */
+void handleKeyDown(Event event) {
+ Event verifyEvent = new Event();
+
+ verifyEvent.character = event.character;
+ verifyEvent.keyCode = event.keyCode;
+ verifyEvent.stateMask = event.stateMask;
+ verifyEvent.doit = true;
+ notifyListeners(VerifyKey, verifyEvent);
+ if (verifyEvent.doit == true) {
+ handleKey(event);
+ }
+}
+
+/**
+ * If an action has been registered for the key stroke execute the action.
+ * Otherwise, if a character has been entered treat it as new content.
+ * <p>
+ *
+ * @param event keyboard event
+ */
+void handleKey(Event event) {
+ int action;
+
+ if (event.keyCode != 0) {
+ action = getKeyBinding(event.keyCode | event.stateMask);
+ }
+ else {
+ action = getKeyBinding(event.character | event.stateMask);
+ }
+ if (action == SWT.NULL) {
+ // ignore anything below SPACE and ignore DEL
+ if (event.character > 31 && event.character != SWT.DEL ||
+ event.character == SWT.CR || event.character == SWT.LF ||
+ event.character == TAB) {
+ doContent(event.character);
+ }
+ }
+ else {
+ invokeAction(action);
+ }
+}
+/**
+ * Renders the invalidated area specified in the paint event.
+ * <p>
+ *
+ * @param event paint event
+ */
+void handlePaint(Event event) {
+ int startLine = (event.y + verticalScrollOffset) / lineHeight;
+ int paintYFromTopLine = (startLine - topIndex) * lineHeight;
+ int topLineOffset = topIndex * lineHeight - verticalScrollOffset;
+ int startY = paintYFromTopLine + topLineOffset; // adjust y position for pixel based scrolling
+ int renderHeight = event.y + event.height - startY;
+ int paintY = 0;
+ int lineCount = content.getLineCount();
+ Rectangle clientArea = getClientArea();
+ Color background = getBackground();
+ Color foreground = getForeground();
+ Image lineBuffer;
+ GC lineGC;
+
+ // Check if there is work to do. clientArea.width should never be 0
+ // if we receive a paint event but we never want to try and create
+ // an Image with 0 width.
+ if (clientArea.width == 0 || event.height == 0) {
+ return;
+ }
+ if (isSingleLine()) {
+ lineCount = 1;
+ if (startLine > 1) {
+ startLine = 1;
+ }
+ }
+ lineBuffer = new Image(getDisplay(), clientArea.width, renderHeight);
+ lineGC = new GC(lineBuffer);
+ lineGC.setFont(event.gc.getFont());
+ lineGC.setForeground(foreground);
+ lineGC.setBackground(background);
+ for (int i = startLine; paintY < renderHeight && i < lineCount; i++, paintY += lineHeight) {
+ String line = content.getLine(i);
+ drawLine(line, i, paintY, lineGC, background, foreground, true);
+ }
+ if (paintY < renderHeight) {
+ lineGC.setBackground(background);
+ lineGC.setForeground(background);
+ lineGC.fillRectangle(0, paintY, clientArea.width, renderHeight - paintY);
+ }
+ event.gc.drawImage(lineBuffer, 0, startY);
+ lineGC.dispose();
+ lineBuffer.dispose();
+}
+/**
+ * Recalculates the scroll bars.
+ * <p>
+ *
+ * @param event resize event
+ */
+void handleResize(Event event) {
+ ScrollBar verticalBar = getVerticalBar();
+ int oldHeight = clientAreaHeight;
+
+ clientAreaHeight = getClientArea().height;
+ if (clientAreaHeight > oldHeight) {
+ int lineCount = content.getLineCount();
+ int oldBottomIndex = topIndex + oldHeight / lineHeight;
+ int newItemCount = (int) Math.ceil((float) (clientAreaHeight - oldHeight) / lineHeight);
+ oldBottomIndex = Math.min(oldBottomIndex, lineCount);
+ newItemCount = Math.min(newItemCount, lineCount - oldBottomIndex);
+ calculateContentWidth(oldBottomIndex, newItemCount);
+ }
+ setScrollBars();
+ claimBottomFreeSpace();
+ claimRightFreeSpace();
+}
+/**
+ * Updates the caret position and selection and the scroll bars to reflect
+ * the content change.
+ * <p>
+ */
+void handleTextChanged(TextChangedEvent event) {
+ int clientAreaHeight = getClientArea().height;
+ int visibleItemCount = (int) Math.ceil((float) clientAreaHeight / lineHeight);
+ int firstLine = content.getLineAtOffset(lastTextChangeStart);
+ int stopLine;
+
+ // calculate width of visible changed lines
+ stopLine = firstLine + lastTextChangeNewLineCount + 1;
+ if (stopLine > topIndex && firstLine < topIndex + visibleItemCount) {
+ int startLine = Math.max(firstLine, topIndex);
+ calculateContentWidth(
+ startLine,
+ Math.min(stopLine, topIndex + visibleItemCount) - startLine);
+ }
+ setScrollBars();
+ // update selection/caret location after styles have been changed.
+ // otherwise any text measuring could be incorrect
+ //
+ // also, this needs to be done after all scrolling. Otherwise,
+ // selection redraw would be flushed during scroll which is wrong.
+ // in some cases new text would be drawn in scroll source area even
+ // though the intent is to scroll it.
+ // fixes 1GB93QT
+ updateSelection(
+ lastTextChangeStart,
+ lastTextChangeReplaceCharCount,
+ lastTextChangeNewCharCount);
+
+ if (lastTextChangeReplaceLineCount > 0) {
+ // Only check for unused space when lines are deleted.
+ // Fixes 1GFL4LY
+ // Scroll up so that empty lines below last text line are used.
+ // Fixes 1GEYJM0
+ claimBottomFreeSpace();
+ }
+}
+/**
+ * Updates the screen to reflect a pending content change.
+ * <p>
+ *
+ * @param event.start the start offset of the change
+ * @param event.newText text that is going to be inserted or empty String
+ * if no text will be inserted
+ * @param event.replaceCharCount length of text that is going to be replaced
+ * @param event.newCharCount length of text that is going to be inserted
+ * @param event.replaceLineCount number of lines that are going to be replaced
+ * @param event.newLineCount number of new lines that are going to be inserted
+ */
+void handleTextChanging(TextChangingEvent event) {
+ int firstLine;
+ int textChangeY;
+ boolean isMultiLineChange = event.replaceLineCount > 0 || event.newLineCount > 0;
+
+ if (event.replaceCharCount < 0) {
+ event.start += event.replaceCharCount;
+ event.replaceCharCount *= -1;
+ }
+ lastTextChangeStart = event.start;
+ lastTextChangeNewLineCount = event.newLineCount;
+ lastTextChangeNewCharCount = event.newCharCount;
+ lastTextChangeReplaceLineCount = event.replaceLineCount;
+ lastTextChangeReplaceCharCount = event.replaceCharCount;
+ firstLine = content.getLineAtOffset(event.start);
+ textChangeY = firstLine * lineHeight - verticalScrollOffset;
+ if (isMultiLineChange) {
+ redrawMultiLineChange(textChangeY, event.newLineCount, event.replaceLineCount);
+ }
+ else {
+ redraw(0, textChangeY, getClientArea().width, lineHeight, true);
+ }
+ // notify default line styler about text change
+ if (defaultLineStyler != null) {
+ defaultLineStyler.textChanging(event);
+ }
+}
+/**
+ * Called when the widget content is set programatically, overwriting
+ * the old content. Resets the caret position, selection and scroll offsets.
+ * Recalculates the content width and scroll bars. Redraws the widget.
+ * <p>
+ *
+ * @param event text change event.
+ */
+void handleTextSet(TextChangedEvent event) {
+ reset();
+}
+/**
+ * Scrolls the widget vertically.
+ */
+void handleVerticalScroll(Event event) {
+ setVerticalScrollOffset(getVerticalBar().getSelection(), false);
+}
+/**
+ * Initializes the fonts used to render font styles.
+ * Presently only regular and bold fonts are supported.
+ */
+void initializeFonts() {
+ FontData fontData;
+ GC gc = new GC(this);
+
+ lineEndSpaceWidth = gc.stringExtent(" ").x;
+ regularFont = getFont();
+ fontData = regularFont.getFontData()[0];
+ fontData.setStyle(fontData.getStyle() | SWT.BOLD);
+ boldFont = new Font(getDisplay(), fontData);
+ gc.dispose();
+}
+/**
+ * Executes the action.
+ * <p>
+ *
+ * @param action one of the actions defined in ST.java
+ */
+public void invokeAction(int action) {
+ checkWidget();
+ switch (action) {
+ // Navigation
+ case ST.LINE_UP:
+ doLineUp();
+ clearSelection(true);
+ break;
+ case ST.LINE_DOWN:
+ doLineDown();
+ clearSelection(true);
+ break;
+ case ST.LINE_START:
+ doLineStart();
+ clearSelection(true);
+ break;
+ case ST.LINE_END:
+ doLineEnd();
+ clearSelection(true);
+ break;
+ case ST.COLUMN_PREVIOUS:
+ doCursorPrevious();
+ clearSelection(true);
+ break;
+ case ST.COLUMN_NEXT:
+ doCursorNext();
+ clearSelection(true);
+ break;
+ case ST.PAGE_UP:
+ doPageUp();
+ clearSelection(true);
+ break;
+ case ST.PAGE_DOWN:
+ doPageDown(false);
+ clearSelection(true);
+ break;
+ case ST.WORD_PREVIOUS:
+ doWordPrevious();
+ clearSelection(true);
+ break;
+ case ST.WORD_NEXT:
+ doWordNext();
+ clearSelection(true);
+ break;
+ case ST.TEXT_START:
+ doContentStart();
+ clearSelection(true);
+ break;
+ case ST.TEXT_END:
+ doContentEnd();
+ clearSelection(true);
+ break;
+ case ST.WINDOW_START:
+ doPageStart();
+ clearSelection(true);
+ break;
+ case ST.WINDOW_END:
+ doPageEnd();
+ clearSelection(true);
+ break;
+ // Selection
+ case ST.SELECT_LINE_UP:
+ doLineUp();
+ doSelection(SWT.LEFT);
+ break;
+ case ST.SELECT_LINE_DOWN:
+ doSelectionLineDown();
+ doSelection(SWT.RIGHT);
+ showCaret();
+ break;
+ case ST.SELECT_LINE_START:
+ doLineStart();
+ doSelection(SWT.LEFT);
+ break;
+ case ST.SELECT_LINE_END:
+ doLineEnd();
+ doSelection(SWT.RIGHT);
+ break;
+ case ST.SELECT_COLUMN_PREVIOUS:
+ doSelectionCursorPrevious();
+ doSelection(SWT.LEFT);
+ break;
+ case ST.SELECT_COLUMN_NEXT:
+ doSelectionCursorNext();
+ doSelection(SWT.RIGHT);
+ break;
+ case ST.SELECT_PAGE_UP:
+ doPageUp();
+ doSelection(SWT.LEFT);
+ break;
+ case ST.SELECT_PAGE_DOWN:
+ doPageDown(true);
+ break;
+ case ST.SELECT_WORD_PREVIOUS:
+ doSelectionWordPrevious();
+ doSelection(SWT.LEFT);
+ break;
+ case ST.SELECT_WORD_NEXT:
+ doSelectionWordNext();
+ doSelection(SWT.RIGHT);
+ break;
+ case ST.SELECT_TEXT_START:
+ doContentStart();
+ doSelection(SWT.LEFT);
+ break;
+ case ST.SELECT_TEXT_END:
+ doContentEnd();
+ doSelection(SWT.RIGHT);
+ break;
+ case ST.SELECT_WINDOW_START:
+ doPageStart();
+ doSelection(SWT.LEFT);
+ break;
+ case ST.SELECT_WINDOW_END:
+ doPageEnd();
+ doSelection(SWT.RIGHT);
+ break;
+ // Modification
+ case ST.CUT:
+ cut();
+ break;
+ case ST.COPY:
+ copy();
+ break;
+ case ST.PASTE:
+ paste();
+ break;
+ case ST.DELETE_PREVIOUS:
+ doBackspace();
+ clearSelection(true);
+ break;
+ case ST.DELETE_NEXT:
+ doDelete();
+ clearSelection(true);
+ break;
+ // Miscellaneous
+ case ST.TOGGLE_OVERWRITE:
+ overwrite = !overwrite; // toggle insert/overwrite mode
+ break;
+ }
+}
+/**
+ * Temporary until SWT provides this
+ */
+boolean isBidi() {
+ String codePage = System.getProperty("file.encoding").toUpperCase();
+ boolean isWindows = System.getProperty("os.name").startsWith("Windows");
+
+ // Running on Windows and with Hebrew or Arabic codepage?
+ return isWindows && ("CP1255".equals(codePage) || "CP1256".equals(codePage));
+}
+/**
+ * Returns whether the given offset is inside a multi byte line delimiter.
+ * Example:
+ * "Line1\r\n" isLineDelimiter(5) == false but isLineDelimiter(6) == true
+ *
+ * @return true if the given offset is inside a multi byte line delimiter.
+ * false if the given offset is before or after a line delimiter.
+ */
+boolean isLineDelimiter(int offset) {
+ return false;
+// int line = content.getLineAtOffset(offset);
+// int lineOffset = content.getOffsetAtLine(line);
+// int offsetInLine = offset - lineOffset;
+
+ // offsetInLine will be greater than line length if the line
+ // delimiter is longer than one character and the offset is set
+ // in between parts of the line delimiter.
+// return offsetInLine > content.getLine(line).length();
+}
+/**
+ * Returns whether the widget can have only one line.
+ * <p>
+ *
+ * @return true if widget can have only one line, false if widget can have
+ * multiple lines
+ */
+boolean isSingleLine() {
+ return (getStyle() & SWT.SINGLE) != 0;
+}
+/**
+ * Returns whether the font style in the given style range is changing
+ * from SWT.NORMAL to SWT.BOLD or vice versa.
+ * <p>
+ *
+ * @param range StyleRange to compare current font style with.
+ * @param start offset of the first font style to compare
+ * @param end offset behind the last font style to compare
+ * @return true if the font style is changing in the given style range,
+ * false if the font style is not changing in the given style 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>
+ */
+boolean isStyleChanging(StyleRange range, int start, int end) {
+ checkWidget();
+ StyleRange[] styles = defaultLineStyler.getStyleRangesFor(start, end - start);
+
+ if (styles == null) {
+ return (range.fontStyle != SWT.NORMAL);
+ }
+ for (int i = 0; i < styles.length; i++) {
+ StyleRange newStyle = styles[i];
+ if (newStyle.fontStyle != range.fontStyle) {
+ return true;
+ }
+ }
+ return false;
+}
+/**
+ * Sends the specified verify event, replace/insert text as defined by
+ * the event and send a modify event.
+ * <p>
+ *
+ * @param event the text change event.
+ * <ul>
+ * <li>event.start - the replace start offset</li>
+ * <li>event.end - the replace end offset</li>
+ * <li>event.text - the new text</li>
+ * </ul>
+ * @param updateCaret whether or not he caret should be set behind
+ * the new text
+ */
+void modifyContent(Event event, boolean updateCaret) {
+ event.doit = true;
+ notifyListeners(SWT.Verify, event);
+ if (event.doit) {
+ StyledTextEvent styledTextEvent = null;
+ int replacedLength = event.end - event.start;
+ if (isListening(ExtendedModify)) {
+ styledTextEvent = new StyledTextEvent(content);
+ styledTextEvent.start = event.start;
+ styledTextEvent.end = event.start + event.text.length();
+ styledTextEvent.text = content.getTextRange(event.start, replacedLength);
+ }
+ content.replaceTextRange(event.start, replacedLength, event.text);
+ // set the caret position prior to sending the modify event.
+ // fixes 1GBB8NJ
+ if (updateCaret) {
+ internalSetSelection(event.start + event.text.length(), 0);
+ // always update the caret location. fixes 1G8FODP
+ if (isBidi()) {
+ lastCaretDirection = SWT.NULL;
+ showBidiCaret();
+ }
+ else {
+ showCaret();
+ }
+ }
+ notifyListeners(SWT.Modify, event);
+ if (isListening(ExtendedModify)) {
+ notifyListeners(ExtendedModify, styledTextEvent);
+ }
+ }
+}
+/**
+ * Redraws a text range in the specified lines
+ * <p>
+ *
+ * @param firstLine first line to redraw at the specified offset
+ * @param offsetInFirstLine offset in firstLine to start redrawing
+ * @param lastLine last line to redraw
+ * @param endOffset offset in the last where redrawing should stop
+ * @param clearBackground true=clear the background by invalidating the requested
+ * redraw area, false=draw the foreground directly without invalidating the
+ * redraw area.
+ */
+void redrawBidiLines(int firstLine, int offsetInFirstLine, int lastLine, int endOffset, boolean clearBackground) {
+ Rectangle clientArea = getClientArea();
+ int lineCount = lastLine - firstLine + 1;
+ int redrawY = firstLine * lineHeight - verticalScrollOffset;
+ int firstLineOffset = content.getOffsetAtLine(firstLine);
+ String line = content.getLine(firstLine);
+ GC gc = new GC(this);
+ StyleRange[] styles = null;
+ StyledTextEvent event = getLineStyleData(firstLineOffset, line);
+ StyledTextBidi bidi;
+ int[] boldStyles;
+
+ if (event != null) {
+ styles = event.styles;
+ }
+ boldStyles = getBoldRanges(styles, firstLineOffset, line.length());
+ bidi = new StyledTextBidi(gc, tabWidth, line, boldStyles, boldFont, getStyleOffsets (line, firstLineOffset));
+ bidi.redrawRange(this, offsetInFirstLine, Math.min(line.length(), endOffset) - offsetInFirstLine, -horizontalScrollOffset, redrawY, lineHeight);
+ // redraw line break marker (either space or full client area width)
+ // if redraw range extends over more than one line and background should be redrawn
+ if (lastLine > firstLine && clearBackground) {
+ int lineBreakStartX = bidi.getTextWidth();
+ // handle empty line case
+ if (lineBreakStartX == 0) lineBreakStartX = xInset;
+ lineBreakStartX = lineBreakStartX - horizontalScrollOffset;
+ int lineBreakWidth;
+ if ((getStyle() & SWT.FULL_SELECTION) != 0) {
+ lineBreakWidth = clientArea.width - lineBreakStartX;
+ }
+ else {
+ lineBreakWidth = lineEndSpaceWidth;
+ }
+ draw(lineBreakStartX, redrawY, lineBreakWidth, lineHeight, clearBackground);
+ }
+ // redraw last line if more than one line needs redrawing
+ if (lineCount > 1) {
+ int lastLineOffset = content.getOffsetAtLine(lastLine);
+ int offsetInLastLine = endOffset - lastLineOffset;
+ // no redraw necessary if redraw offset is 0
+ if (offsetInLastLine > 0) {
+ line = content.getLine(lastLine);
+ redrawY = lastLine * lineHeight - verticalScrollOffset;
+ event = getLineStyleData(lastLineOffset, line);
+ if (event != null) {
+ styles = event.styles;
+ }
+ else {
+ styles = null;
+ }
+ boldStyles = getBoldRanges(styles, lastLineOffset, line.length());
+ bidi = new StyledTextBidi(gc, tabWidth, line, boldStyles, boldFont, getStyleOffsets (line, lastLineOffset));
+ bidi.redrawRange(this, 0, offsetInLastLine, -horizontalScrollOffset, redrawY, lineHeight);
+ }
+ }
+ gc.dispose();
+}
+/**
+ * Redraws a text range in the specified lines
+ * <p>
+ *
+ * @param firstLine first line to redraw at the specified offset
+ * @param offsetInFirstLine offset in firstLine to start redrawing
+ * @param lastLine last line to redraw
+ * @param endOffset offset in the last where redrawing should stop
+ * @param clearBackground true=clear the background by invalidating the requested
+ * redraw area, false=draw the foreground directly without invalidating the
+ * redraw area.
+ */
+void redrawLines(int firstLine, int offsetInFirstLine, int lastLine, int endOffset, boolean clearBackground) {
+ Rectangle clientArea = getClientArea();
+ String line = content.getLine(firstLine);
+ int lineCount = lastLine - firstLine + 1;
+ int redrawX = getXAtOffset(line, firstLine, offsetInFirstLine);
+ int redrawStopX;
+ int redrawY = firstLine * lineHeight - verticalScrollOffset;
+ int firstLineOffset = content.getOffsetAtLine(firstLine);
+
+ // calculate redraw stop location
+ if ((getStyle() & SWT.FULL_SELECTION) != 0 && lastLine > firstLine) {
+ redrawStopX = clientArea.width;
+ }
+ else {
+ redrawStopX = getXAtOffset(line, firstLine, endOffset - firstLineOffset);
+ }
+ draw(redrawX, redrawY, redrawStopX - redrawX, lineHeight, clearBackground);
+ // redraw last line if more than one line needs redrawing
+ if (lineCount > 1) {
+ int offsetInLastLine = endOffset - content.getOffsetAtLine(lastLine);
+ // no redraw necessary if redraw offset is 0
+ if (offsetInLastLine > 0) {
+ line = content.getLine(lastLine);
+ redrawStopX = getXAtOffset(line, lastLine, offsetInLastLine);
+ redrawY = lastLine * lineHeight - verticalScrollOffset;
+ draw(0, redrawY, redrawStopX, lineHeight, clearBackground);
+ }
+ }
+}
+/**
+ * Fixes the widget to display a text change.
+ * Bit blitting and redrawing is done as necessary.
+ * <p>
+ *
+ * @param y y location of the text change
+ * @param newLineCount number of new lines.
+ * @param replacedLineCount number of replaced lines.
+ */
+void redrawMultiLineChange(int y, int newLineCount, int replacedLineCount) {
+ Rectangle clientArea = getClientArea();
+ int lineCount = newLineCount - replacedLineCount;
+ int sourceY;
+ int destinationY;
+
+ if (lineCount > 0) {
+ sourceY = Math.max(0, y + lineHeight);
+ destinationY = sourceY + lineCount * lineHeight;
+ }
+ else {
+ destinationY = Math.max(0, y + lineHeight);
+ sourceY = destinationY - lineCount * lineHeight;
+ }
+ scroll(
+ 0, destinationY, // destination x, y
+ 0, sourceY, // source x, y
+ clientArea.width, clientArea.height, true);
+ // Always redrawing causes the bottom line to flash when a line is
+ // deleted. This is because SWT merges the paint area of the scroll
+ // with the paint area of the redraw call below.
+ // To prevent this we could call update after the scroll. However,
+ // adding update can cause even more flash if the client does other
+ // redraw/update calls (ie. for syntax highlighting).
+ // We could also redraw only when a line has been added or when
+ // contents has been added to a line. This would require getting
+ // line index info from the content and is not worth the trouble
+ // (the flash is only on the bottom line and minor).
+ // Specifying the NO_MERGE_PAINTS style bit prevents the merged
+ // redraw but could cause flash/slowness elsewhere.
+ if (y + lineHeight > 0 && y <= clientArea.height) {
+ // redraw first changed line in case a line was split/joined
+ redraw(0, y, clientArea.width, lineHeight, true);
+ }
+ if (newLineCount > 0) {
+ int redrawStartY = y + lineHeight;
+ int redrawHeight = newLineCount * lineHeight;
+
+ if (redrawStartY + redrawHeight > 0 && redrawStartY <= clientArea.height) {
+ // display new text
+ redraw(0, redrawStartY, clientArea.width, redrawHeight, true);
+ }
+ }
+}
+/**
+ * Redraws the specified text range.
+ * <p>
+ *
+ * @param start offset of the first character to redraw
+ * @param length number of characters to redraw
+ * @param clearBackground true if the background should be cleared as part of the
+ * redraw operation. If true, the entire redraw area will be cleared before anything
+ * is redrawn. The redraw operation will be faster and smoother if clearBackground
+ * is set to false. Whether or not the flag can be set to false depends on the type
+ * of change that has taken place. If font styles or background colors for the redraw
+ * area have changed, clearBackground should be set to true. If only foreground colors
+ * have changed for the redraw area, clearBackground can be set to false.
+ */
+public void redrawRange(int start, int length, boolean clearBackground) {
+ checkWidget();
+ internalRedrawRange(start, length, clearBackground);
+}
+/**
+ * Removes the specified extended modify listener.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void removeExtendedModifyListener(ExtendedModifyListener extendedModifyListener) {
+ checkWidget();
+ if (extendedModifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ removeListener(ExtendedModify, extendedModifyListener);
+}
+/**
+ * Removes the specified line background listener.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void removeLineBackgroundListener(LineBackgroundListener listener) {
+ checkWidget();
+ if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ removeListener(LineGetBackground, listener);
+ // use default line styler if last user line styler was removed.
+ if (isListening(LineGetBackground) == false && userLineBackground) {
+ StyledTextListener typedListener = new StyledTextListener(defaultLineStyler);
+ addListener(LineGetBackground, typedListener);
+ userLineBackground = false;
+ }
+}
+/**
+ * Removes the specified line style listener.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void removeLineStyleListener(LineStyleListener listener) {
+ checkWidget();
+ if (listener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ removeListener(LineGetStyle, listener);
+ // use default line styler if last user line styler was removed. Fixes 1G7B1X2
+ if (isListening(LineGetStyle) == false && userLineStyle) {
+ StyledTextListener typedListener = new StyledTextListener(defaultLineStyler);
+ addListener(LineGetStyle, typedListener);
+ userLineStyle = false;
+ }
+}
+/**
+ * Removes the specified modify listener.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void removeModifyListener(ModifyListener modifyListener) {
+ checkWidget();
+ if (modifyListener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ removeListener(SWT.Modify, modifyListener);
+}
+
+/**
+ * Removes the specified selection listener.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void removeSelectionListener(SelectionListener listener) {
+ checkWidget();
+ if (listener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ removeListener(SWT.Selection, listener);
+}
+
+/**
+ * Removes the specified verify listener.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void removeVerifyListener(VerifyListener verifyListener) {
+ checkWidget();
+ if (verifyListener == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ removeListener(SWT.Verify, verifyListener);
+}
+
+/**
+ * Removes the specified key verify listener.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void removeVerifyKeyListener(VerifyKeyListener listener) {
+ if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ removeListener(VerifyKey, listener);
+}
+
+/**
+ * Replaces the given text range with new text.
+ * If the widget has the SWT.SINGLE style and "text" contains more than
+ * one line, only the first line is rendered but the text is stored
+ * unchanged. A subsequent call to getText will return the same text
+ * that was set. Note that only a single line of text should be set when
+ * the SWT.SINGLE style is used.
+ * <p>
+ * <b>NOTE:</b> During the replace operation the current selection is changed
+ * as follows:
+ * <ul>
+ * <li>selection before replaced text: selection unchanged
+ * <li>selection after replaced text: adjust the selection so that same text
+ * remains selected
+ * <li>selection intersects replaced text: selection is cleared and caret is placed
+ * after inserted text
+ * </ul>
+ * </p>
+ *
+ * @param start offset of first character to replace
+ * @param length number of characters to replace. Use 0 to insert text
+ * @param text new text. May be empty to delete text.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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_INVALID_RANGE when either start or end is outside the valid range (0 <= offset <= getCharCount())</li>
+ * <li>ERROR_INVALID_ARGUMENT when either start or end is inside a multi byte line delimiter.
+ * Splitting a line delimiter for example by inserting text in between the CR and LF and deleting part of a line delimiter is not supported</li>
+ * </ul>
+ */
+public void replaceTextRange(int start, int length, String text) {
+ checkWidget();
+ int contentLength = getCharCount();
+ int end = start + length;
+ Event event = new Event();
+
+ if (start < 0 || start > contentLength || end < 0 || end > contentLength || start > end) {
+ SWT.error(SWT.ERROR_INVALID_RANGE);
+ }
+ event.start = start;
+ event.end = end;
+ event.text = text;
+ modifyContent(event, false);
+}
+/**
+ * Resets the caret position, selection and scroll offsets. Recalculate
+ * the content width and scroll bars. Redraw the widget.
+ */
+void reset() {
+ ScrollBar verticalBar = getVerticalBar();
+ ScrollBar horizontalBar = getHorizontalBar();
+ caretOffset = 0;
+ topIndex = 0;
+ verticalScrollOffset = 0;
+ horizontalScrollOffset = 0;
+ contentWidth = 0;
+ resetSelection();
+ // discard any styles that may have been set by creating a
+ // new default line styler
+ if (defaultLineStyler != null) {
+ removeLineBackgroundListener(defaultLineStyler);
+ removeLineStyleListener(defaultLineStyler);
+ installDefaultLineStyler();
+ }
+ calculateContentWidth();
+ if (verticalBar != null) {
+ verticalBar.setSelection(0);
+ }
+ if (horizontalBar != null) {
+ horizontalBar.setSelection(0);
+ }
+ setScrollBars();
+ setCaret();
+ redraw();
+}
+/**
+ * Resets the selection.
+ */
+void resetSelection() {
+ selection.x = selection.y = caretOffset;
+ selectionAnchor = -1;
+}
+/**
+ * Scrolls the widget horizontally.
+ * <p>
+ *
+ * @param pixels number of pixels to scroll, > 0 = scroll left, < 0 scroll right
+ */
+void scrollHorizontal(int pixels) {
+ Rectangle clientArea;
+
+ if (pixels == 0) {
+ return;
+ }
+ clientArea = getClientArea();
+ scroll(
+ pixels * -1, 0, // destination x, y
+ 0, 0, // source x, y
+ clientArea.width, clientArea.height, true);
+ horizontalScrollOffset += pixels;
+ setCaret();
+}
+/**
+ * Scrolls the widget horizontally and adjust the horizontal scroll bar to
+ * reflect the new horizontal offset..
+ * <p>
+ *
+ * @param pixels number of pixels to scroll, > 0 = scroll left, < 0 scroll right
+ */
+void scrollHorizontalBar(int pixels) {
+ if (pixels == 0) {
+ return;
+ }
+ ScrollBar horizontalBar = getHorizontalBar();
+ if (horizontalBar != null) {
+ horizontalBar.setSelection(horizontalScrollOffset + pixels);
+ }
+ scrollHorizontal(pixels);
+}
+/**
+ * Selects all the text.
+ * <p>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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();
+ setSelection(new Point(0, Math.max(getCharCount(),0)));
+}
+/**
+ * Replaces/inserts text as defined by the event.
+ * <p>
+ *
+ * @param event the text change event.
+ * <ul>
+ * <li>event.start - the replace start offset</li>
+ * <li>event.end - the replace end offset</li>
+ * <li>event.text - the new text</li>
+ * </ul>
+ */
+void sendKeyEvent(Event event) {
+ if (editable == false) {
+ return;
+ }
+ modifyContent(event, true);
+}
+/**
+ * Sends the specified selection event.
+ */
+void sendSelectionEvent() {
+ Event event = new Event();
+
+ event.x = selection.x;
+ event.y = selection.y;
+ notifyListeners(SWT.Selection, event);
+}
+void setCaret () {
+ if (isBidi()) {
+ setBidiCaret(false);
+ }
+ else {
+ setCaretLocation();
+ }
+}
+/**
+ * Sets the receiver's caret. Set the caret's height and location.
+ *
+ * </p>
+ * @param caret the new caret 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 setCaret (Caret caret) {
+ checkWidget ();
+ super.setCaret(caret);
+ if (caret != null) {
+ if (isBidi() == false) {
+ caret.setSize(caret.getSize().x, lineHeight);
+ }
+ setCaretLocation();
+ }
+}
+/**
+ * Moves the Caret to the current caret offset and switches the
+ * keyboard according to the input part.
+ */
+void setBidiCaret(boolean setKeyboard) {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineStartOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineStartOffset;
+ String lineText = content.getLine(line);
+ GC gc = new GC(this);
+ StyledTextEvent event = getLineStyleData(lineStartOffset, lineText);
+ StyledTextBidi bidi;
+ int[] boldStyles = null;
+ Caret caret;
+
+ if (event != null) {
+ boldStyles = getBoldRanges(event.styles, lineStartOffset, lineText.length());
+ }
+ bidi = new StyledTextBidi(gc, tabWidth, lineText, boldStyles, boldFont, getStyleOffsets (lineText, lineStartOffset));
+ if (setKeyboard) {
+ if (offsetInLine > 0 && bidi.isRightToLeft(offsetInLine - 1) != bidi.isRightToLeft(offsetInLine)) {
+ // continue with previous character type
+ bidi.setKeyboardLanguage(offsetInLine - 1);
+ }
+ else {
+ bidi.setKeyboardLanguage(offsetInLine);
+ }
+ }
+ caret = getCaret();
+ if (caret != null) {
+ int caretX;
+ if (lastCaretDirection == SWT.NULL) {
+ caretX = bidi.getCaretPosition(offsetInLine);
+ } else {
+ caretX = bidi.getCaretPosition(offsetInLine, lastCaretDirection);
+ }
+ caretX = caretX - horizontalScrollOffset;
+ if (StyledTextBidi.getKeyboardLanguageDirection() == SWT.RIGHT) {
+ caretX -= (getCaretWidth() - 1);
+ }
+ createBidiCaret();
+ caret.setLocation(caretX, line * lineHeight - verticalScrollOffset);
+ }
+ gc.dispose();
+}
+/**
+ * Moves the Caret to the current caret offset.
+ */
+void setBidiCaretLocation() {
+ // set the caret location, also set the keyboard
+ setBidiCaret(true);
+}
+/**
+ * Moves the Caret to the current caret offset.
+ */
+void setCaretLocation() {
+ if (isBidi()) {
+ setBidiCaretLocation();
+ }
+ else {
+ Caret caret = getCaret();
+ if (caret != null) {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineStartOffset = content.getOffsetAtLine(line);
+ int caretX = getXAtOffset(content.getLine(line), line, caretOffset - lineStartOffset);
+ caret.setLocation(caretX, line * lineHeight - verticalScrollOffset);
+ }
+ }
+}
+/**
+ * Sets the caret offset.
+ * <p>
+ * <b>NOTE:</b> If offset is greater than the number of characters of text in the
+ * widget, the value will be ignored.
+ * </p>
+ *
+ * @param offset caret offset, relative to the first character in 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>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT when either the start or the end of the selection range is inside a
+ * multi byte line delimiter (and thus neither clearly in front of or after the line delimiter)
+ * </ul>
+ */
+public void setCaretOffset(int offset) {
+ checkWidget();
+ int length = getCharCount();
+
+ if (length > 0 && offset != caretOffset) {
+ if (offset < 0) {
+ caretOffset = 0;
+ }
+ else
+ if (offset > length) {
+ caretOffset = length;
+ }
+ else {
+ if (isLineDelimiter(offset)) {
+ // offset is inside a multi byte line delimiter. This is an
+ // illegal operation and an exception is thrown. Fixes 1GDKK3R
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ caretOffset = offset;
+ }
+ // clear the selection if the caret is moved.
+ // don't notify listeners about the selection change.
+ clearSelection(false);
+ }
+ // always update the caret location. fixes 1G8FODP
+ setCaretLocation();
+}
+/**
+ * Sets the content implementation to use for text storage.
+ * <p>
+ *
+ * @param content StyledTextContent implementation to use for text storage.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when listener is null</li>
+ * </ul>
+ */
+public void setContent(StyledTextContent content) {
+ checkWidget();
+ if (content == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (this.content != null) {
+ this.content.removeTextChangeListener(textChangeListener);
+ }
+ this.content = content;
+ content.addTextChangeListener(textChangeListener);
+ reset();
+}
+/**
+ * Sets whether the widget implements double click mouse behavior.
+ * </p>
+ *
+ * @param enable if true double clicking a word selects the word, if false
+ * double clicks have the same effect as regular mouse clicks.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 enable) {
+ checkWidget();
+
+ doubleClickEnabled = enable;
+}
+/**
+ * Sets whether the widget content can be edited.
+ * </p>
+ *
+ * @param editable if true content can be edited, if false content can not be
+ * edited
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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();
+
+ this.editable = editable;
+}
+/**
+ * Sets a new font to render text with.
+ * <p>
+ * <b>NOTE:</b> Italic fonts are not supported unless they have no overhang
+ * and the same baseline as regular fonts.
+ * </p>
+ *
+ * @param font new 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 void setFont(Font font) {
+ checkWidget();
+
+ super.setFont(font);
+ if (boldFont != null) {
+ boldFont.dispose();
+ }
+ initializeFonts();
+ calculateLineHeight();
+ contentWidth = 0;
+ calculateContentWidth();
+ calculateScrollBars();
+ setTabs(getTabs());
+ if (isBidi()) {
+ caretDirection = SWT.NULL;
+ createCaretBitmaps();
+ createBidiCaret();
+ setCaret();
+ }
+ else {
+ Caret caret = getCaret();
+ if (caret != null) {
+ caret.setSize(caret.getSize().x, lineHeight);
+ }
+ }
+ redraw();
+}
+/**
+ * Sets the horizontal scroll offset relative to the start of the line.
+ * Do nothing if there is no text set.
+ * <p>
+ * <b>NOTE:</b> The horizontal index is reset to 0 when new text is set in the
+ * widget.
+ * </p>
+ *
+ * @param offset horizontal scroll offset relative to the start
+ * of the line, measured in character increments starting at 0, if
+ * equal to 0 the content is not scrolled, if > 0 = the content is scrolled.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
+public void setHorizontalIndex(int offset) {
+ checkWidget();
+ int clientAreaWidth = getClientArea().width;
+
+ if (getCharCount() == 0) {
+ return;
+ }
+ if (offset < 0) {
+ offset = 0;
+ }
+ offset *= getHorizontalIncrement();
+ // allow any value if client area width is unknown or 0.
+ // offset will be checked in resize handler.
+ // don't use isVisible since width is known even if widget
+ // is temporarily invisible
+ if (clientAreaWidth > 0) {
+ // prevent scrolling if the content fits in the client area.
+ // align end of longest line with right border of client area
+ // if offset is out of range.
+ if (offset > contentWidth - clientAreaWidth) {
+ offset = Math.max(0, contentWidth - clientAreaWidth);
+ }
+ }
+ scrollHorizontalBar(offset - horizontalScrollOffset);
+}
+/**
+ * Sets the background color of the specified lines.
+ * The background color is drawn for the width of the widget. All
+ * line background colors are discarded when setText is called.
+ * The text background color if defined in a StyleRange overlays the
+ * line background color. Should not be called if a LineBackgroundListener
+ * has been set since the listener maintains the line backgrounds.
+ * <p>
+ * During text changes, when entire lines are inserted or removed, the line
+ * background colors that are associated with the lines after the change
+ * will "move" with their respective text. For all other text changes,
+ * line background colors will remain unchanged.
+ * </p>
+ *
+ * @param startLine first line the color is applied to, 0 based
+ * @param lineCount number of lines the color applies to.
+ * @param background line 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>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT when the specified line range is invalid</li>
+ * </ul>
+ */
+public void setLineBackground(int startLine, int lineCount, Color background) {
+ checkWidget();
+ int partialBottomIndex = getPartialBottomIndex();
+
+ // this API can not be used if the client is providing the line background
+ if (userLineBackground) {
+ return;
+ }
+ if (startLine < 0 || startLine + lineCount > content.getLineCount()) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ defaultLineStyler.setLineBackground(startLine, lineCount, background);
+ // do nothing if redraw range is completely invisible
+ if (startLine > partialBottomIndex || startLine + lineCount - 1 < topIndex) {
+ return;
+ }
+ // only redraw visible lines
+ if (startLine < topIndex) {
+ lineCount -= topIndex - startLine;
+ startLine = topIndex;
+ }
+ if (startLine + lineCount - 1 > partialBottomIndex) {
+ lineCount = partialBottomIndex - startLine + 1;
+ }
+ startLine -= topIndex;
+ redraw(
+ 0, startLine * lineHeight,
+ getClientArea().width, lineCount * lineHeight, true);
+}
+/**
+ * Sets the background of the specified GC for a line rendering operation,
+ * if it is not already set.
+ * </p>
+ *
+ * @param gc GC to set the background color in
+ * @param currentBackground background color currently set in gc
+ * @param newBackground new background color of gc
+ */
+Color setLineBackground(GC gc, Color currentBackground, Color newBackground) {
+ if (currentBackground.equals(newBackground) == false) {
+ gc.setBackground(newBackground);
+ }
+ return newBackground;
+}
+
+/**
+ * Sets the font of the specified GC if it is not already set.
+ * </p>
+ *
+ * @param gc GC to set the font in
+ * @param currentFont font data of font currently set in gc
+ * @param style desired style of the font in gc. Can be one of
+ * SWT.NORMAL, SWT.ITALIC, SWT.BOLD
+ */
+void setLineFont(GC gc, FontData currentFont, int style) {
+ if (currentFont.getStyle() != style) {
+ if (style == SWT.BOLD) {
+ currentFont.setStyle(style);
+ gc.setFont(boldFont);
+ }
+ else
+ if (style == SWT.NORMAL) {
+ currentFont.setStyle(style);
+ gc.setFont(regularFont);
+ }
+ }
+}
+/**
+ * Sets the foreground of the specified GC for a line rendering operation,
+ * if it is not already set.
+ * </p>
+ *
+ * @param gc GC to set the foreground color in
+ * @param currentForeground foreground color currently set in gc
+ * @param newForeground new foreground color of gc
+ */
+Color setLineForeground(GC gc, Color currentForeground, Color newForeground) {
+ if (currentForeground.equals(newForeground) == false) {
+ gc.setForeground(newForeground);
+ }
+ return newForeground;
+}
+/**
+ * Adjusts the scroll bar maximum and page size to reflect content
+ * width/length changes.
+ */
+void setScrollBars() {
+ ScrollBar verticalBar = getVerticalBar();
+ ScrollBar horizontalBar = getHorizontalBar();
+ Rectangle clientArea = getClientArea();
+ final int INACTIVE = 1;
+
+ if (verticalBar != null) {
+ int maximum = content.getLineCount() * getVerticalIncrement();
+ // only set the real values if the scroll bar can be used
+ // (ie. because the thumb size is less than the scroll maximum)
+ // avoids flashing on Motif, fixes 1G7RE1J and 1G5SE92
+ if (clientArea.height < maximum) {
+ verticalBar.setValues(
+ verticalBar.getSelection(),
+ verticalBar.getMinimum(),
+ maximum,
+ clientArea.height, // thumb size
+ verticalBar.getIncrement(),
+ clientArea.height); // page size
+ }
+ else
+ if (verticalBar.getThumb() != INACTIVE || verticalBar.getMaximum() != INACTIVE) {
+ verticalBar.setValues(
+ verticalBar.getSelection(),
+ verticalBar.getMinimum(),
+ INACTIVE,
+ INACTIVE,
+ verticalBar.getIncrement(),
+ INACTIVE);
+ }
+ }
+ if (horizontalBar != null) {
+ // only set the real values if the scroll bar can be used
+ // (ie. because the thumb size is less than the scroll maximum)
+ // avoids flashing on Motif, fixes 1G7RE1J and 1G5SE92
+ if (clientArea.width < contentWidth) {
+ horizontalBar.setValues(
+ horizontalBar.getSelection(),
+ horizontalBar.getMinimum(),
+ contentWidth, // maximum
+ clientArea.width, // thumb size
+ horizontalBar.getIncrement(),
+ clientArea.width); // page size
+ }
+ else
+ if (horizontalBar.getThumb() != INACTIVE || horizontalBar.getMaximum() != INACTIVE) {
+ horizontalBar.setValues(
+ horizontalBar.getSelection(),
+ horizontalBar.getMinimum(),
+ INACTIVE,
+ INACTIVE,
+ horizontalBar.getIncrement(),
+ INACTIVE);
+ }
+ }
+}
+/**
+ * Sets the selection to the given position and scrolls it into view. Equivalent to setSelection(start,start).
+ * <p>
+ *
+ * @param start new caret position
+ * @see #setSelection(int,int)
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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_INVALID_RANGE when start is outside the widget content
+ * <li>ERROR_INVALID_ARGUMENT when either the start or the end of the selection range is inside a
+ * multi byte line delimiter (and thus neither clearly in front of or after the line delimiter)
+ * </ul>
+ */
+public void setSelection(int start) {
+ setSelection(start, start);
+}
+/**
+ * Sets the selection and scrolls it into view.
+ * <p>
+ * Indexing is zero based. 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
+ * </p>
+ *
+ * @param point x=selection start offset, y=selection end offset
+ * @see #setSelection(int,int)
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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 when point is null</li>
+ * <li>ERROR_INVALID_RANGE when start and end is outside the widget content
+ * <li>ERROR_INVALID_ARGUMENT when either the start or the end of the selection range is inside a
+ * multi byte line delimiter (and thus neither clearly in front of or after the line delimiter)
+ * </ul>
+ */
+public void setSelection(Point point) {
+ checkWidget();
+ if (point == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ setSelection(point.x, point.y);
+}
+/**
+ * Sets the selection and scrolls it into view.
+ * <p>
+ * Indexing is zero based. 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
+ * </p>
+ *
+ * @param start selection start offset
+ * @param end selection end offset
+ * @see #setSelectionRange(int,int)
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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_INVALID_RANGE when start and end is outside the widget content
+ * <li>ERROR_INVALID_ARGUMENT when either the start or the end of the selection range is inside a
+ * multi byte line delimiter (and thus neither clearly in front of or after the line delimiter)
+ * </ul>
+ */
+public void setSelection(int start, int end) {
+ checkWidget();
+ int contentLength = getCharCount();
+
+ if (start > end || start < 0 || end > contentLength) {
+ SWT.error(SWT.ERROR_INVALID_RANGE);
+ }
+ if (isLineDelimiter(start) || isLineDelimiter(end)) {
+ // the start offset or end offset of the selection range is inside a
+ // multi byte line delimiter. This is an illegal operation and an exception
+ // is thrown. Fixes 1GDKK3R
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ internalSetSelection(start, end - start);
+ // always update the caret location. fixes 1G8FODP
+ setCaretLocation();
+ showSelection();
+}
+/**
+ * Sets the selection. The new selection may not be visible. Call showSelection to scroll
+ * the selection into view.
+ * <p>
+ *
+ * @param start offset of the first selected character, start >= 0 must be true.
+ * @param length number of characters to select, start <= start + length <= getCharCount()
+ * must be true.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - 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_INVALID_RANGE when the range specified by start and length is outside the widget content
+ * <li>ERROR_INVALID_ARGUMENT when either the start or the end of the selection range is inside a
+ * multi byte line delimiter (and thus neither clearly in front of or after the line delimiter)
+ * </ul>
+ */
+public void setSelectionRange(int start, int length) {
+ checkWidget();
+ int contentLength = getCharCount();
+ int end = start + length;
+
+ if (start > end || start < 0 || end > contentLength) {
+ SWT.error(SWT.ERROR_INVALID_RANGE);
+ }
+ if (isLineDelimiter(start) || isLineDelimiter(end)) {
+ // the start offset or end offset of the selection range is inside a
+ // multi byte line delimiter. This is an illegal operation and an exception
+ // is thrown. Fixes 1GDKK3R
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ internalSetSelection(start, length);
+ // always update the caret location. fixes 1G8FODP
+ setCaretLocation();
+}
+/**
+ * Sets the selection.
+ * The new selection may not be visible. Call showSelection to scroll
+ * the selection into view.
+ * <p>
+ *
+ * @param start offset of the first selected character, start >= 0 must be true.
+ * @param length number of characters to select, start <= start + length
+ * <= getCharCount() must be true.
+ */
+void internalSetSelection(int start, int length) {
+ int end = start + length;
+
+ if (selection.x != start || selection.y != end) {
+ clearSelection(false);
+ selectionAnchor = selection.x = start;
+ caretOffset = selection.y = end;
+ if (length > 0) {
+ internalRedrawRange(selection.x, selection.y - selection.x, true);
+ }
+ }
+}
+/**
+ * Adds the specified style. The new style overwrites existing styles for the
+ * specified range. Existing style ranges are adjusted if they partially
+ * overlap with the new style, To clear an individual style, call setStyleRange
+ * with a StyleRange that has null attributes.
+ * <p>
+ * Should not be called if a LineStyleListener has been set since the
+ * listener maintains the styles.
+ * </p>
+ *
+ * @param range StyleRange object containing the style information.
+ * Overwrites the old style in the given range. May be null to delete
+ * all styles.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_RANGE when the style range is outside the valid range (> getCharCount())</li>
+ * </ul>
+ */
+public void setStyleRange(StyleRange range) {
+ checkWidget();
+ boolean redrawFirstLine = false;
+ boolean redrawLastLine = false;
+
+ // this API can not be used if the client is providing the line styles
+ if (userLineStyle) {
+ return;
+ }
+ // check the range, make sure it falls within the range of the
+ // text
+ if (range != null && range.start + range.length > content.getCharCount()) {
+ SWT.error(SWT.ERROR_INVALID_RANGE);
+ }
+ if (range != null) {
+ // the first and last line needs to be redrawn completely if the
+ // font style is changing from SWT.NORMAL to something else or
+ // vice versa. fixes 1G7M5WE.
+ int rangeEnd = range.start + range.length;
+ int firstLine = content.getLineAtOffset(range.start);
+ int lastLine = content.getLineAtOffset(rangeEnd);
+ int firstLineOffset = content.getOffsetAtLine(firstLine);
+ if (isStyleChanging(range, range.start, Math.min(rangeEnd, firstLineOffset + content.getLine(firstLine).length()))) {
+ redrawFirstLine = true;
+ }
+ if (lastLine != firstLine) {
+ int lastLineOffset = content.getOffsetAtLine(lastLine);
+ if (isStyleChanging(range, lastLineOffset, rangeEnd)) {
+ redrawLastLine = true;
+ }
+ }
+ }
+ if (isBidi()) {
+ redrawFirstLine = true;
+ redrawLastLine = true;
+ }
+ defaultLineStyler.setStyleRange(range);
+ if (range != null) {
+ internalRedrawRange(range.start, range.length, true);
+ if (redrawFirstLine) {
+ // redraw starting at the style change start offset since
+ // single line text changes, followed by style changes will
+ // flash otherwise
+ int firstLine = content.getLineAtOffset(range.start);
+ int firstLineOffset = content.getOffsetAtLine(firstLine);
+ String firstLineText = content.getLine(firstLine);
+ int redrawX = getXAtOffset(firstLineText, firstLine, range.start - firstLineOffset);
+ int redrawY = firstLine * lineHeight - verticalScrollOffset;
+ redraw(redrawX, redrawY, getClientArea().width, lineHeight, true);
+ }
+ if (redrawLastLine) {
+ // redraw the whole line if the font style changed on the last line
+ int lastLine = content.getLineAtOffset(range.start + range.length);
+ int redrawY = lastLine * lineHeight - verticalScrollOffset;
+ redraw(0, redrawY, getClientArea().width, lineHeight, true);
+ }
+ }
+ else {
+ redraw();
+ }
+ // make sure that the caret is positioned correctly.
+ // caret location may change if font style changes.
+ // fixes 1G8FODP
+ setCaret();
+}
+
+/**
+ * Sets styles to be used for rendering the widget content. All styles
+ * will be replaced with the given set of styles.
+ * <p>
+ * Should not be called if a LineStyleListener has been set since the
+ * listener maintains the styles.
+ * </p>
+ *
+ * @param ranges StyleRange objects containing the style information.
+ * The ranges should not overlap. The style rendering is undefined if
+ * the ranges do overlap. Must not be null.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT when listener is null</li>
+ * <li>ERROR_INVALID_RANGE when the last of the style ranges is outside the valid range (> getCharCount())</li>
+ * </ul>
+ */
+public void setStyleRanges(StyleRange[] ranges) {
+ checkWidget();
+ // this API can not be used if the client is providing the line styles
+ if (userLineStyle) {
+ return;
+ }
+ if (ranges == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ // check the last range, make sure it falls within the range of the
+ // current text
+ if (ranges.length != 0) {
+ StyleRange last = ranges[ranges.length-1];
+ if (last.start + last.length > content.getCharCount()) {
+ SWT.error(SWT.ERROR_INVALID_RANGE);
+ }
+ }
+ defaultLineStyler.setStyleRanges(ranges);
+ redraw(); // should only redraw affected area to avoid flashing
+ // make sure that the caret is positioned correctly.
+ // caret location may change if font style changes.
+ // fixes 1G8FODP
+ setCaret();
+}
+/**
+ * Ensures that the selection style ends at the selection end.
+ * <code>selectionStyle</code> is assumed to be created based on the style
+ * range of <code>style</code>. If <code>selectionStyle</code> does extend
+ * beyond the selection range a new style is returned to preserve the style
+ * passed in with <code>style</code>.
+ * <p>
+ * @param selectionStyle the selection style based on the style range in
+ * <code>style</code>
+ * @param style the existing style that is to be merged with the selection
+ * @return a new style that preserves the style passed in with <code>style</code>
+ * if the selection does not fully extend over the existing style range.
+ * null otherwise.
+ */
+StyleRange setSelectionStyleEnd(StyleRange selectionStyle, StyleRange style) {
+ int selectionEnd = selection.y;
+ StyleRange newStyle = null;
+
+ // does style extend beyond selection?
+ if (selectionStyle.start + selectionStyle.length > selectionEnd) {
+ int styleEnd = style.start + style.length;
+ selectionStyle.length = selectionEnd - selectionStyle.start;
+ // preserve rest (unselected part) of old style
+ newStyle = (StyleRange) style.clone();
+ newStyle.start = selectionEnd;
+ newStyle.length = styleEnd - selectionEnd;
+ }
+ return newStyle;
+}
+/**
+ * Sets the tab width.
+ * <p>
+ *
+ * @param tabs tab width measured in 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 void setTabs(int tabs) {
+ checkWidget();
+ tabLength = tabs;
+ calculateTabWidth();
+ if (caretOffset > 0) {
+ caretOffset = 0;
+ if (isBidi()) {
+ showBidiCaret();
+ }
+ else {
+ showCaret();
+ }
+ clearSelection(false);
+ }
+ redraw();
+}
+/**
+ * Sets the widget content.
+ * If the widget has the SWT.SINGLE style and "text" contains more than
+ * one line, only the first line is rendered but the text is stored
+ * unchanged. A subsequent call to getText will return the same text
+ * that was set.
+ * <p>
+ * <b>Note:</b> Only a single line of text should be set when the SWT.SINGLE
+ * style is used.
+ * </p>
+ *
+ * @param text new widget content. Replaces existing content. Line styles
+ * that were set using StyledText API are discarded. The
+ * current selection is also discarded.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 text) {
+ checkWidget();
+ Event event = new Event();
+
+ event.start = 0;
+ event.end = getCharCount();
+ event.text = text;
+ event.doit = true;
+ notifyListeners(SWT.Verify, event);
+ if (event.doit) {
+ String replacedText = content.getTextRange(event.start, event.end - event.start);
+ content.setText(event.text);
+ event.end = event.start + event.text.length();
+ event.text = replacedText;
+ notifyListeners(SWT.Modify, event);
+ }
+}
+/**
+ * Sets the text limit.
+ * <p>
+ * The text limit specifies the amount of text that
+ * the user can type into the widget.
+ * </p>
+ *
+ * @param limit the new 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>
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_CANNOT_BE_ZERO when limit is 0</li>
+ * </ul>
+ */
+public void setTextLimit(int limit) {
+ checkWidget();
+ if (limit == 0) {
+ SWT.error(SWT.ERROR_CANNOT_BE_ZERO);
+ }
+ textLimit = limit;
+}
+/**
+ * Sets the top index. Do nothing if there is no text set.
+ * <p>
+ * The top index is the index of the line that is currently at the top
+ * of the widget. The top index changes when the widget is scrolled.
+ * Indexing starts from zero.
+ * Note: The top index is reset to 0 when new text is set in the widget.
+ * </p>
+ *
+ * @param index new top index. Must be between 0 and getLineCount() -
+ * visible lines per page. An out of range index will be adjusted accordingly.
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 topIndex) {
+ checkWidget();
+ int lineCount = content.getLineCount();
+ int pageSize = Math.min(lineCount, getLineCountWhole());
+
+ if (getCharCount() == 0) {
+ return;
+ }
+ if (topIndex < 0) {
+ topIndex = 0;
+ }
+ else
+ if (topIndex > lineCount - pageSize) {
+ topIndex = lineCount - pageSize;
+ }
+ setVerticalScrollOffset(topIndex * getVerticalIncrement(), true);
+ // set the top index directly in case setVerticalScrollOffset didn't
+ // (ie. because the widget is not yet visible)
+ this.topIndex = topIndex;
+}
+/**
+ * Scrolls the widget vertically.
+ * <p>
+ *
+ * @param pixels number of pixels to scroll. > 0 = scroll up, < 0 scroll down
+ */
+void setVerticalScrollOffset(int pixelOffset, boolean adjustScrollBar) {
+ Rectangle clientArea;
+ ScrollBar verticalBar = getVerticalBar();
+ int verticalIncrement = getVerticalIncrement();
+
+ if (pixelOffset == verticalScrollOffset) {
+ return;
+ }
+ if (verticalBar != null && adjustScrollBar) {
+ verticalBar.setSelection(pixelOffset);
+ }
+ clientArea = getClientArea();
+ scroll(
+ 0, 0, // destination x, y
+ 0, pixelOffset - verticalScrollOffset, // source x, y
+ clientArea.width, clientArea.height, true);
+ if (verticalIncrement != 0) {
+ int oldTopIndex = topIndex;
+
+ topIndex = (int) Math.ceil((float) pixelOffset / verticalIncrement);
+ if (topIndex != oldTopIndex) {
+ int lineCount = content.getLineCount();
+ int visibleItemCount = (int) Math.ceil((float) clientArea.height / verticalIncrement);
+ int oldBottomIndex = Math.min(oldTopIndex + visibleItemCount, lineCount);
+ int newItemCount = topIndex - oldTopIndex;
+
+ if (Math.abs(newItemCount) > visibleItemCount) {
+ calculateContentWidth();
+ }
+ else {
+ if (newItemCount > 0) {
+ newItemCount = Math.min(newItemCount, lineCount - oldBottomIndex);
+ calculateContentWidth(oldBottomIndex, newItemCount);
+ }
+ else
+ if (newItemCount < 0) {
+ // make sure calculation range does not exceed number of lines
+ // fixes 1GBKCLF
+ calculateContentWidth(topIndex, Math.min(newItemCount * -1, lineCount - topIndex));
+ }
+ }
+ setScrollBars();
+ }
+ }
+ verticalScrollOffset = pixelOffset;
+ setCaret();
+}
+
+boolean scrollBidiCaret() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+ String lineText = content.getLine(line);
+ int xAtOffset = getXAtOffset(lineText, line, offsetInLine);
+ int clientAreaWidth = getClientArea().width;
+ int verticalIncrement = getVerticalIncrement();
+ int horizontalIncrement = clientAreaWidth / 4;
+ boolean scrolled = false;
+
+ if (xAtOffset < 0) {
+ // always make 1/4 of a page visible
+ xAtOffset = Math.max(horizontalScrollOffset * -1, xAtOffset - horizontalIncrement);
+ scrollHorizontalBar(xAtOffset);
+ scrolled = true;
+ }
+ else
+ if (xAtOffset > clientAreaWidth) {
+ // always make 1/4 of a page visible
+ xAtOffset = Math.min(contentWidth - horizontalScrollOffset, xAtOffset + horizontalIncrement);
+ scrollHorizontalBar(xAtOffset - clientAreaWidth);
+ scrolled = true;
+ }
+ if (line < topIndex) {
+ setVerticalScrollOffset(line * verticalIncrement, true);
+ scrolled = true;
+ }
+ else
+ if (line > getBottomIndex()) {
+ setVerticalScrollOffset((line - getBottomIndex()) * verticalIncrement + verticalScrollOffset, true);
+ scrolled = true;
+ }
+ return scrolled;
+}
+/**
+ * Sets the caret location and scrolls the caret offset into view.
+ */
+void showBidiCaret() {
+ boolean scrolled = scrollBidiCaret();
+ if (scrolled == false) {
+ setCaret();
+ }
+}
+/**
+ * Sets the caret location and scrolls the caret offset into view.
+ */
+void showCaret() {
+ int line = content.getLineAtOffset(caretOffset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = caretOffset - lineOffset;
+ String lineText = content.getLine(line);
+ int xAtOffset = getXAtOffset(lineText, line, offsetInLine);
+ int clientAreaWidth = getClientArea().width;
+ int verticalIncrement = getVerticalIncrement();
+ int horizontalIncrement = clientAreaWidth / 4;
+ boolean scrolled = false;
+
+ if (xAtOffset < 0) {
+ // always make 1/4 of a page visible
+ xAtOffset = Math.max(horizontalScrollOffset * -1, xAtOffset - horizontalIncrement);
+ scrollHorizontalBar(xAtOffset);
+ scrolled = true;
+ }
+ else
+ if (xAtOffset > clientAreaWidth) {
+ // always make 1/4 of a page visible
+ xAtOffset = Math.min(contentWidth - horizontalScrollOffset, xAtOffset + horizontalIncrement);
+ scrollHorizontalBar(xAtOffset - clientAreaWidth);
+ scrolled = true;
+ }
+ if (line < topIndex) {
+ setVerticalScrollOffset(line * verticalIncrement, true);
+ scrolled = true;
+ }
+ else
+ if (line > getBottomIndex()) {
+ setVerticalScrollOffset((line - getBottomIndex()) * verticalIncrement + verticalScrollOffset, true);
+ scrolled = true;
+ }
+ if (scrolled == false) {
+ setCaretLocation();
+ }
+}
+/**
+ * Scrolls the specified offset into view.
+ * <p>
+ *
+ * @param offset offset that should be scolled into view
+ */
+void showOffset(int offset) {
+ int line = content.getLineAtOffset(offset);
+ int lineOffset = content.getOffsetAtLine(line);
+ int offsetInLine = offset - lineOffset;
+ String lineText = content.getLine(line);
+ int xAtOffset = getXAtOffset(lineText, line, offsetInLine);
+ int clientAreaWidth = getClientArea().width;
+ int verticalIncrement = getVerticalIncrement();
+ int horizontalIncrement = clientAreaWidth / 4;
+
+ if (xAtOffset < 0) {
+ // always make 1/4 of a page visible
+ xAtOffset = Math.max(horizontalScrollOffset * -1, xAtOffset - horizontalIncrement);
+ scrollHorizontalBar(xAtOffset);
+ }
+ else
+ if (xAtOffset > clientAreaWidth) {
+ // always make 1/4 of a page visible
+ xAtOffset = Math.min(contentWidth - horizontalScrollOffset, xAtOffset + horizontalIncrement);
+ scrollHorizontalBar(xAtOffset - clientAreaWidth);
+ }
+ if (line < topIndex) {
+ setVerticalScrollOffset(line * verticalIncrement, true);
+ }
+ else
+ if (line > getBottomIndex()) {
+ setVerticalScrollOffset((line - getBottomIndex()) * verticalIncrement + verticalScrollOffset, true);
+ }
+}
+/**
+ * Scrolls the selection into view.
+ * <p>
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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();
+ showOffset(selection.x);
+ showOffset(selection.y);
+}
+/**
+ * Returns the width of the specified text. Expand tabs to tab stops using
+ * the widget tab width.
+ * <p>
+ *
+ * @param line line to be measured.
+ * @param lineIndex index of the line relative to the first kine of the
+ * document
+ * @param length number of characters to measure. Tabs are counted
+ * as one character in this parameter.
+ * @param gc GC to use for measuring text
+ * @return width of the text with tabs expanded to tab stops or 0 if the
+ * length is beyond the text length.
+ */
+int textWidth(String line, int lineIndex, int length, GC gc) {
+ StyleRange[] styles = null;
+ int lineOffset = content.getOffsetAtLine(lineIndex);
+ StyledTextEvent event = getLineStyleData(lineOffset, line);
+ StyledTextBidi bidi = null;
+
+ if (event != null) {
+ styles = filterLineStyles(event.styles);
+ }
+ if (isBidi()) {
+ int[] boldStyles = getBoldRanges(styles, lineOffset, line.length());
+ bidi = new StyledTextBidi(gc, tabWidth, line, boldStyles, boldFont, getStyleOffsets (line, lineOffset));
+ }
+ return textWidth(line, lineOffset, 0, length, styles, 0, gc, bidi);
+}
+/**
+ * Returns the width of the specified text. Expand tabs to tab stops using
+ * the widget tab width.
+ * <p>
+ *
+ * @param text text to be measured.
+ * @param lineOffset offset of the first character in the line.
+ * @param startOffset offset of the character to start measuring and
+ * expand tabs.
+ * @param length number of characters to measure. Tabs are counted
+ * as one character in this parameter.
+ * @param styles line styles
+ * @param startXOffset x position of "startOffset" in "text". Used for
+ * calculating tab stops
+ * @param gc GC to use for measuring text
+ * @param bidi the bidi object to use for measuring text in bidi locales.
+ * null when not in bidi mode.
+ * @return width of the text with tabs expanded to tab stops or 0 if the
+ * startOffset or length is outside the specified text.
+ */
+int textWidth(String text, int lineOffset, int startOffset, int length, StyleRange[] lineStyles, int startXOffset, GC gc, StyledTextBidi bidi) {
+ int paintX = 0;
+ int endOffset = startOffset + length;
+ int textLength = text.length();
+ FontData fontData = gc.getFont().getFontData()[0];
+
+ if (startOffset < 0 || startOffset >= textLength || startOffset + length > textLength) {
+ return paintX;
+ }
+ if (bidi != null) {
+ paintX = bidi.getCaretPosition(endOffset) - startXOffset;
+ }
+ else {
+ for (int i = startOffset; i < endOffset; i++) {
+ int tabIndex = text.indexOf(TAB, i);
+ // is tab not present or past the rendering range?
+ if (tabIndex == -1 || tabIndex > endOffset) {
+ tabIndex = endOffset;
+ }
+ if (tabIndex != i) {
+ String tabSegment = text.substring(i, tabIndex);
+ if (lineStyles != null) {
+ paintX = styledTextWidth(tabSegment, lineOffset + i, lineStyles, paintX, 0, gc, fontData);
+ }
+ else {
+ setLineFont(gc, fontData, SWT.NORMAL);
+ paintX += gc.stringExtent(tabSegment).x;
+ }
+ if (tabIndex != endOffset && tabWidth > 0) {
+ paintX += tabWidth;
+ paintX -= (startXOffset + paintX) % tabWidth;
+ }
+ i = tabIndex;
+ }
+ else
+ if (tabWidth > 0) {
+ paintX += tabWidth;
+ paintX -= (startXOffset + paintX) % tabWidth;
+ }
+ }
+ }
+ return paintX;
+}
+/**
+ * Measures the text as rendered at the specified location. Expand tabs to tab stops using
+ * the widget tab width.
+ * <p>
+ *
+ * @param text text to draw
+ * @param textStartOffset offset of the first character in text relative
+ * to the first character in the document
+ * @param lineStyles styles of the line
+ * @param paintX x location to start drawing at
+ * @param paintY y location to draw at
+ * @param gc GC to draw on
+ * @param fontData the font data of the font currently set in gc
+ * @return x location where drawing stopped or 0 if the startOffset or
+ * length is outside the specified text.
+ */
+int styledTextWidth(String text, int textStartOffset, StyleRange[] lineStyles, int paintX, int paintY, GC gc, FontData fontData) {
+ String textSegment;
+ int textLength = text.length();
+ int textIndex = 0;
+ for (int styleIndex = 0; styleIndex < lineStyles.length; styleIndex++) {
+ StyleRange style = lineStyles[styleIndex];
+ int textEnd;
+ int styleSegmentStart = style.start - textStartOffset;
+ if (styleSegmentStart + style.length < 0) {
+ continue;
+ }
+ if (styleSegmentStart >= textLength) {
+ break;
+ }
+ // is there a style for the current string position?
+ if (textIndex < styleSegmentStart) {
+ setLineFont(gc, fontData, SWT.NORMAL);
+ textSegment = text.substring(textIndex, styleSegmentStart);
+ paintX += gc.stringExtent(textSegment).x;
+ textIndex = styleSegmentStart;
+ }
+ textEnd = Math.min(textLength, styleSegmentStart + style.length);
+ setLineFont(gc, fontData, style.fontStyle);
+ textSegment = text.substring(textIndex, textEnd);
+ paintX += gc.stringExtent(textSegment).x;
+ textIndex = textEnd;
+ }
+ // is there unmeasured and unstyled text?
+ if (textIndex < textLength) {
+ setLineFont(gc, fontData, SWT.NORMAL);
+ textSegment = text.substring(textIndex, textLength);
+ paintX += gc.stringExtent(textSegment).x;
+ }
+ return paintX;
+}
+/**
+ * Updates the selection and caret position depending on the text change.
+ * If the selection intersects with the replaced text, the selection is
+ * reset and the caret moved to the end of the new text.
+ * If the selection is behind the replaced text it is moved so that the
+ * same text remains selected. If the selection is before the replaced text
+ * it is left unchanged.
+ * <p>
+ *
+ * @param startOffset offset of the text change
+ * @param replacedLength length of text being replaced
+ * @param newLength length of new text
+ */
+void updateSelection(int startOffset, int replacedLength, int newLength) {
+ if (selection.y <= startOffset) {
+ // selection ends before text change
+ return;
+ }
+ if (selection.x < startOffset) {
+ // clear selection fragment before text change
+ internalRedrawRange(selection.x, startOffset - selection.x, true);
+ }
+ if (selection.y > startOffset + replacedLength && selection.x < startOffset + replacedLength) {
+ // clear selection fragment after text change.
+ // do this only when the selection is actually affected by the
+ // change. Selection is only affected if it intersects the change (1GDY217).
+ int netNewLength = newLength - replacedLength;
+ int redrawStart = startOffset + newLength;
+ internalRedrawRange(redrawStart, selection.y + netNewLength - redrawStart, true);
+ }
+ if (selection.y > startOffset && selection.x < startOffset + replacedLength) {
+ // selection intersects replaced text. set caret behind text change
+ internalSetSelection(startOffset + newLength, 0);
+ // always update the caret location. fixes 1G8FODP
+ setCaretLocation();
+ }
+ else {
+ // move selection to keep same text selected
+ internalSetSelection(selection.x + newLength - replacedLength, selection.y - selection.x);
+ // always update the caret location. fixes 1G8FODP
+ setCaretLocation();
+ }
+}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextBidi.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextBidi.java
new file mode 100644
index 0000000000..3b76d81b11
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextBidi.java
@@ -0,0 +1,719 @@
+package org.eclipse.swt.custom;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.internal.BidiUtil;
+import org.eclipse.swt.internal.Converter;
+import org.eclipse.swt.widgets.Control;
+import java.io.*;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/*
+ */
+class StyledTextBidi {
+ GC gc;
+ int tabWidth;
+ int[] renderPositions;
+ int[] order;
+ int[] dx;
+ byte[] classBuffer;
+ byte[] glyphBuffer;
+
+ class DirectionRun {
+ int logicalStart;
+ int logicalEnd;
+
+ DirectionRun(int logicalStart, int logicalEnd) {
+ this.logicalStart = logicalStart;
+ this.logicalEnd = logicalEnd;
+ }
+ int getVisualStart() {
+ int visualStart = order[logicalStart];
+ int visualEnd = order[logicalEnd];
+
+ if (visualEnd < visualStart) {
+ visualStart = visualEnd;
+ }
+ return visualStart;
+ }
+ int getVisualEnd() {
+ int visualStart = order[logicalStart];
+ int visualEnd = order[logicalEnd];
+
+ if (visualEnd < visualStart) {
+ visualEnd = visualStart;
+ }
+ return visualEnd;
+ }
+ int getRenderStartX() {
+ return renderPositions[getVisualStart()];
+ }
+ int getRenderStopX() {
+ int visualEnd = getVisualEnd();
+
+ return renderPositions[visualEnd] + dx[visualEnd];
+ }
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append("vStart,Stop:" + getVisualStart() + "," + getVisualEnd() + " lStart,Stop:" + logicalStart + "," + logicalEnd + " renderStart,Stop: " + getRenderStartX() + "," + getRenderStopX());
+ return buf.toString();
+ }
+ }
+
+public StyledTextBidi(GC gc, int tabWidth, String text, int[] boldRanges, Font boldFont, int [] offsets) {
+ int length = text.length();
+
+ setGC(gc);
+ setTabWidth(tabWidth);
+ renderPositions = new int[length];
+ order = new int[length];
+ dx = new int[length];
+ classBuffer = new byte[length];
+ if (text.length() == 0) {
+ glyphBuffer = new byte[0];
+ }
+ else {
+ glyphBuffer = BidiUtil.getRenderInfo(gc, text, order, classBuffer, dx, 0, offsets);
+ if (boldRanges != null) {
+ Font normalFont = gc.getFont();
+ gc.setFont(boldFont);
+ for (int i = 0; i < boldRanges.length; i += 2) {
+ int rangeStart = boldRanges[i];
+ int rangeLength = boldRanges[i + 1];
+ prepareBoldText(text, rangeStart, rangeLength);
+ }
+ gc.setFont(normalFont);
+ }
+ adjustTabStops(text);
+ calculateRenderPositions();
+ }
+}
+public static void addLanguageListener (int hwnd, Runnable runnable) {
+ BidiUtil.addLanguageListener(hwnd, runnable);
+}
+void adjustTabStops(String text) {
+ int tabIndex = text.indexOf('\t', 0);
+ int logicalIndex = 0;
+ int x = StyledText.xInset;
+
+ while (tabIndex != -1) {
+ for (; logicalIndex < tabIndex; logicalIndex++) {
+ x += dx[order[logicalIndex]];
+ }
+ int tabStop = x + tabWidth;
+ tabStop -= tabStop % tabWidth;
+ dx[order[tabIndex]] = tabStop - x;
+ tabIndex = text.indexOf('\t', tabIndex + 1);
+ }
+}
+void calculateRenderPositions() {
+ renderPositions = new int[dx.length];
+ renderPositions[0] = StyledText.xInset;
+ for (int i = 0; i < dx.length - 1; i++) {
+ renderPositions[i + 1] = renderPositions[i] + dx[i];
+ }
+}
+/**
+ *
+ * @param logicalStart start offset in the logical text
+ * @param length number of logical characters to render
+ * @param xOffset x location of the line start
+ * @param yOffset y location of the line start
+ */
+public int drawBidiText(int logicalStart, int length, int xOffset, int yOffset) {
+ Enumeration directionRuns = getDirectionRuns(logicalStart, length).elements();
+ int endOffset = logicalStart + length;
+ int stopX;
+
+ if (endOffset > getTextLength()) {
+ return StyledText.xInset;
+ }
+ while (directionRuns.hasMoreElements()) {
+ DirectionRun run = (DirectionRun) directionRuns.nextElement();
+ int visualStart = run.getVisualStart();
+ int visualEnd = run.getVisualEnd();
+ int x = xOffset + run.getRenderStartX();
+ drawGlyphs(visualStart, visualEnd - visualStart + 1, x, yOffset);
+ }
+ // between R2L and L2R direction segment?
+ if (endOffset < order.length && isRightToLeft(endOffset) == false && isRightToLeft(endOffset - 1)) {
+ // continue drawing at start of L2R segment
+ stopX = renderPositions[endOffset];
+ }
+ else
+ if (isRightToLeft(endOffset - 1)) {
+ // we rendered a R2L segment
+ stopX = renderPositions[order[endOffset - 1]];
+ }
+ else {
+ int visualEnd = order[endOffset - 1];
+ // we rendered a L2R segment
+ stopX = renderPositions[visualEnd] + dx[visualEnd];
+ }
+ return stopX;
+}
+/**
+ *
+ */
+void drawGlyphs(int visualStart, int length, int x, int y) {
+ byte[] renderBuffer = new byte[length * 2];
+ int[] renderDx = new int[length];
+
+ if (length == 0) {
+ return;
+ }
+ System.arraycopy(glyphBuffer, visualStart * 2, renderBuffer, 0, length * 2);
+ // copy the distance values for the desired rendering range
+ System.arraycopy(dx, visualStart, renderDx, 0, length);
+ BidiUtil.drawGlyphs(gc, renderBuffer, renderDx, x, y);
+}
+public boolean equals(Object object) {
+ StyledTextBidi test;
+ if (object == this) return true;
+ if (object instanceof StyledTextBidi) test = (StyledTextBidi) object;
+ else return false;
+
+ int[] intArray1 = test.order;
+ int[] intArray2 = this.order;
+ if (intArray1.length != intArray2.length) return false;
+ for (int i=0; i<intArray1.length; i++) {
+ if (intArray1[i] != intArray2[i]) return false;
+ }
+ intArray1 = test.dx;
+ intArray2 = this.dx;
+ if (intArray1.length != intArray2.length) return false;
+ for (int i=0; i<intArray1.length; i++) {
+ if (intArray1[i] != intArray2[i]) return false;
+ }
+ intArray1 = test.renderPositions;
+ intArray2 = this.renderPositions;
+ if (intArray1.length != intArray2.length) return false;
+ for (int i=0; i<intArray1.length; i++) {
+ if (intArray1[i] != intArray2[i]) return false;
+ }
+ byte[] byteArray1 = test.classBuffer;
+ byte[] byteArray2 = this.classBuffer;
+ if (byteArray1.length != byteArray2.length) return false;
+ for (int i=0; i<byteArray1.length; i++) {
+ if (byteArray1[i] != byteArray2[i]) return false;
+ }
+ byteArray1 = test.glyphBuffer;
+ byteArray2 = this.glyphBuffer;
+ if (byteArray1.length != byteArray2.length) return false;
+ for (int i=0; i<byteArray1.length; i++) {
+ if (byteArray1[i] != byteArray2[i]) return false;
+ }
+ return true;
+}
+public void fillBackground(int logicalStart, int length, int xOffset, int yOffset, int height) {
+ Enumeration directionRuns = getDirectionRuns(logicalStart, length).elements();
+
+ if (logicalStart + length > getTextLength()) {
+ return;
+ }
+ while (directionRuns.hasMoreElements()) {
+ DirectionRun run = (DirectionRun) directionRuns.nextElement();
+ int visualStart = run.getVisualStart();
+ int visualEnd = run.getVisualEnd();
+ int startX = run.getRenderStartX();
+ gc.fillRectangle(xOffset + startX, yOffset, run.getRenderStopX() - startX, height);
+ }
+}
+public int[] getCaretOffsetAndDirectionAtX(int x) {
+ int lineLength = getTextLength();
+ int low = -1;
+ int high = lineLength;
+ int offset;
+
+ if (lineLength == 0) {
+ return new int[] {0,0};
+ }
+
+ int eol = renderPositions[renderPositions.length - 1] + dx[dx.length - 1];
+ if (x > eol) {
+ return new int[] {lineLength,ST.COLUMN_NEXT};
+ }
+
+ // get the index visually clicked character
+ int visualIndex = 0;
+ int visualX = renderPositions[visualIndex];
+ while ((x > visualX) && (visualIndex < renderPositions.length)) {
+ visualIndex++;
+ if (visualIndex < renderPositions.length) visualX = renderPositions[visualIndex];
+ }
+ visualIndex = Math.max(0,visualIndex-1);
+ // figure out if the character was clicked on the right or left
+ int halfway = renderPositions[visualIndex] + (dx[visualIndex] / 2);
+ boolean visualLeft = (x <= halfway);
+ int direction;
+ offset = getLogicalOffset(visualIndex);
+
+ // handle visual beginning
+ if (visualIndex == 0) {
+ if (isRightToLeft(offset)) {
+ if (visualLeft) {
+ offset = getLigatureOffset(offset);
+ offset = offset + 1;
+ direction = ST.COLUMN_NEXT;
+ }
+ else {
+ direction = ST.COLUMN_PREVIOUS;
+ }
+ }
+ else {
+ if (visualLeft) {
+ direction = ST.COLUMN_PREVIOUS;
+ }
+ else {
+ offset = offset + 1;
+ direction = ST.COLUMN_NEXT;
+ }
+ }
+ return new int[] {offset, direction};
+ }
+
+ // handle visual end
+ if (visualIndex == renderPositions.length - 1) {
+ if (isRightToLeft(offset)) {
+ if (visualLeft) {
+ offset = getLigatureOffset(offset);
+ offset = offset + 1;
+ direction = ST.COLUMN_NEXT;
+ }
+ else {
+ offset = offset;
+ direction = ST.COLUMN_PREVIOUS;
+ }
+ }
+ else {
+ if (visualLeft) {
+ offset = offset;
+ direction = ST.COLUMN_PREVIOUS;
+ }
+ else {
+ offset = offset + 1;
+ direction = ST.COLUMN_NEXT;
+ }
+ }
+ return new int[] {offset, direction};
+ }
+
+ if (isRightToLeft(offset)) {
+ if (visualLeft) {
+ offset = getLigatureOffset(offset);
+ offset = offset + 1;
+ direction = ST.COLUMN_NEXT;
+ }
+ else {
+ offset = offset;
+ direction = ST.COLUMN_PREVIOUS;
+ }
+ }
+ else {
+ if (visualLeft) {
+ offset = offset;
+ direction = ST.COLUMN_PREVIOUS;
+ }
+ else {
+ offset = offset + 1;
+ direction = ST.COLUMN_NEXT;
+ }
+ }
+ return new int[] {offset, direction};
+}
+public int getCaretPosition(int logicalOffset) {
+ int caretX;
+
+ if (getTextLength() == 0) {
+ return StyledText.xInset;
+ }
+ // at or past end of line?
+ if (logicalOffset >= order.length) {
+ logicalOffset = Math.min(logicalOffset, order.length - 1);
+ int visualOffset = order[logicalOffset];
+ if (isRightToLeft(logicalOffset)) {
+ caretX = renderPositions[visualOffset];
+ }
+ else {
+ caretX = renderPositions[visualOffset] + dx[visualOffset];
+ }
+ }
+ else
+ if (logicalOffset > 0 && isRightToLeft(logicalOffset) != isRightToLeft(logicalOffset - 1)) {
+ // logically first character of different direction segment?
+ // go behind last character of previous direction segment
+ int visualOffset = order[logicalOffset - 1];
+ if (isRightToLeft(logicalOffset - 1)) {
+ caretX = renderPositions[visualOffset];
+ }
+ else {
+ caretX = renderPositions[visualOffset] + dx[visualOffset];
+ }
+ }
+ else
+ // at R2L character or beginning of line?
+ if (isRightToLeft(logicalOffset) || logicalOffset == 0) {
+ int visualOffset = order[logicalOffset];
+
+
+ if (isRightToLeft(logicalOffset)) {
+ caretX = renderPositions[visualOffset] + dx[visualOffset];
+ }
+ else {
+ caretX = renderPositions[visualOffset];
+ }
+ }
+ else {
+ // L2R segment
+ caretX = renderPositions[order[logicalOffset]];
+ }
+ return caretX;
+}
+public int getCaretPosition(int logicalOffset, int direction) {
+ // moving to character at logicalOffset
+ if (getTextLength() == 0) {
+ return StyledText.xInset;
+ }
+ int caretX;
+ // at or past end of line?
+ if (logicalOffset >= order.length) {
+ logicalOffset = Math.min(logicalOffset, order.length - 1);
+ int visualOffset = order[logicalOffset];
+ if (isRightToLeft(logicalOffset)) {
+ caretX = renderPositions[visualOffset];
+ }
+ else {
+ caretX = renderPositions[visualOffset] + dx[visualOffset];
+ }
+ setKeyboardLanguage(logicalOffset);
+ return caretX;
+ }
+
+ // at beginning of line?
+ if (logicalOffset == 0) {
+ int visualOffset = order[logicalOffset];
+ if (isRightToLeft(logicalOffset)) {
+ caretX = renderPositions[visualOffset] + dx[visualOffset];
+ }
+ else {
+ caretX = renderPositions[visualOffset];
+ }
+ setKeyboardLanguage(logicalOffset);
+ return caretX;
+ }
+
+ if (direction == ST.COLUMN_NEXT) {
+ if (isRightToLeft(logicalOffset) != isRightToLeft(logicalOffset - 1)) {
+ // moving between segments
+ if (isRightToLeft(logicalOffset - 1)) {
+ // moving from RtoL to LtoR
+ int visualOffset = order[logicalOffset-1];
+ caretX = renderPositions[visualOffset];
+ }
+ else {
+ // moving from LtoR to RtoL
+ int visualOffset = order[logicalOffset-1];
+ caretX = renderPositions[visualOffset] + dx[visualOffset];
+ }
+ setKeyboardLanguage(logicalOffset-1);
+ return caretX;
+ }
+ }
+
+ if (direction == ST.COLUMN_PREVIOUS) {
+ if (isRightToLeft(logicalOffset) != isRightToLeft(logicalOffset - 1)) {
+ // moving between segments
+ if (isRightToLeft(logicalOffset - 1)) {
+ // moving from LtoR to RtoL
+ int visualOffset = order[logicalOffset];
+ caretX = renderPositions[visualOffset];
+ }
+ else {
+ // moving from RtoL to LtoR
+ int visualOffset = order[logicalOffset];
+ caretX = renderPositions[visualOffset] + dx[visualOffset];
+ }
+ setKeyboardLanguage(logicalOffset);
+ return caretX;
+ }
+ }
+
+ if (isRightToLeft(logicalOffset)) {
+ int visualOffset = order[logicalOffset];
+ caretX = renderPositions[visualOffset] + dx[visualOffset];
+ }
+ else {
+ caretX = renderPositions[order[logicalOffset]];
+ }
+ setKeyboardLanguage(logicalOffset);
+ return caretX;
+}
+
+Vector getDirectionRuns(int logicalStart, int length) {
+ Vector directionRuns = new Vector();
+ int logicalEnd = logicalStart + length - 1;
+ int segmentLogicalStart = logicalStart;
+ int segmentLogicalEnd = segmentLogicalStart;
+
+ if (logicalEnd < getTextLength()) {
+ while (segmentLogicalEnd <= logicalEnd) {
+ int segType = classBuffer[segmentLogicalStart];
+ // Search for the end of the direction segment. Each segment needs to
+ // be rendered separately.
+ // E.g., 11211 (1=R2L, 2=L2R), rendering from logical index 0 to 5
+ // would be visual 1 to 4 and would thus miss visual 0. Rendering the
+ // segments separately would render from visual 1 to 0, then 2, then
+ // 4 to 3.
+ while (segmentLogicalEnd < logicalEnd && segType == classBuffer[segmentLogicalEnd + 1]) {
+ segmentLogicalEnd++;
+ }
+ directionRuns.addElement(new DirectionRun(segmentLogicalStart, segmentLogicalEnd));
+ segmentLogicalStart = ++segmentLogicalEnd;
+ }
+ }
+ return directionRuns;
+}
+/**
+ * Answer SWT.LEFT or SWT.RIGHT.
+ */
+public static int getKeyboardLanguageDirection() {
+ int language = BidiUtil.getKeyboardLanguage();
+ if (language == BidiUtil.KEYBOARD_HEBREW) {
+ return SWT.RIGHT;
+ }
+ if (language == BidiUtil.KEYBOARD_ARABIC) {
+ return SWT.RIGHT;
+ }
+ return SWT.LEFT;
+}
+int getLigatureOffset(int offset) {
+ // should call BidiText to see if font has ligatures...
+ int newOffset = offset;
+ int i = offset + 1;
+ while (i<order.length && (order[i] == order[offset])) {
+ newOffset = i;
+ i++;
+ }
+ return newOffset;
+}
+int getLogicalOffset(int visualOffset) {
+ int logicalOffset = 0;
+
+ while (logicalOffset < order.length && order[logicalOffset] != visualOffset) {
+ logicalOffset++;
+ }
+ return logicalOffset;
+}
+public int getOffsetAtX(int x) {
+ int lineLength = getTextLength();
+ int low = -1;
+ int high = lineLength;
+
+ if (lineLength == 0) {
+ return 0;
+ }
+ if (x > renderPositions[renderPositions.length - 1] + dx[dx.length - 1]) {
+ return lineLength;
+ }
+ while (high - low > 1) {
+ int offset = (high + low) / 2;
+ int visualX = renderPositions[offset];
+
+
+ if (x <= visualX + dx[offset]) {
+ high = offset;
+ }
+ else
+ if (high == lineLength && high - offset == 1) {
+ // requested x location is past end of line
+ high = -1;
+ }
+ else {
+ low = offset;
+ }
+ }
+ return getLogicalOffset(high);
+}
+int[] getRenderIndexesFor(int start, int length) {
+ int[] positions = new int[length];
+ int end = start + length;
+
+ for (int i = start; i < end; i++) {
+ positions[i-start] = order[i];
+ }
+ return positions;
+}
+int getTextLength() {
+ return order.length;
+}
+public int getTextWidth() {
+ int width = 0;
+
+ if (getTextLength() > 0) {
+ width = renderPositions[renderPositions.length - 1] + dx[dx.length - 1];
+ }
+ return width;
+}
+/**
+ *
+ */
+public boolean isRightToLeft(int logicalIndex) {
+ // for rendering, caret positioning, consider numbers as LtoR
+ boolean isRightToLeft = false;
+
+ if (logicalIndex < classBuffer.length) {
+ isRightToLeft = (classBuffer[logicalIndex] == BidiUtil.CLASS_ARABIC) ||
+ (classBuffer[logicalIndex] == BidiUtil.CLASS_HEBREW);
+ }
+ return isRightToLeft;
+}
+/**
+ *
+ */
+public boolean isRightToLeftMode(int logicalIndex) {
+ // for keyboard positioning, consider numbers as RtoL
+ boolean isRightToLeft = false;
+
+ if (logicalIndex < classBuffer.length) {
+ isRightToLeft = (classBuffer[logicalIndex] == BidiUtil.CLASS_ARABIC) ||
+ (classBuffer[logicalIndex] == BidiUtil.CLASS_HEBREW) ||
+ (classBuffer[logicalIndex] == BidiUtil.CLASS_LOCALNUMBER);
+ }
+ return isRightToLeft;
+}/**
+ *
+ */
+void prepareBoldText(String textline, int logicalStart, int length) {
+ int byteCount = length;
+ int flags = 0;
+ String text = textline.substring(logicalStart, logicalStart + length);
+
+ // figure out what is before and after the substring
+ // so that the proper character shaping will occur
+ if (logicalStart != 0
+ && !Character.isWhitespace(textline.charAt(logicalStart - 1))
+ && isRightToLeft(logicalStart - 1)) {
+ // if the start of the substring is not the beginning of the
+ // text line, check to see what is before the string
+ flags |= BidiUtil.LINKBEFORE;
+ }
+ if ((logicalStart + byteCount) != dx.length
+ && !Character.isWhitespace(textline.charAt(logicalStart + byteCount))
+ && isRightToLeft(logicalStart + byteCount)) {
+ // if the end of the substring is not the end of the text line,
+ // check to see what is after the substring
+ flags |= BidiUtil.LINKAFTER;
+ }
+ // set classification values for the substring
+ flags |= BidiUtil.CLASSIN;
+ byte[] classArray = new byte[byteCount];
+ int[] renderIndexes = getRenderIndexesFor(logicalStart, byteCount);
+ for (int i = 0; i < byteCount; i++) {
+ classArray[i] = classBuffer[renderIndexes[i]];
+ }
+ int[] dxArray = new int[byteCount];
+ int[] orderArray = new int[byteCount];
+ BidiUtil.getRenderInfo(gc, text, orderArray, classArray, dxArray, flags);
+ // update the existing dx array with the new dx values based on the bold font
+ for (int i = 0; i < dxArray.length; i++) {
+ int dxValue = dxArray[orderArray[i]];
+ int visualIndex = renderIndexes[i];
+ dx[visualIndex] = dxValue;
+ }
+}
+public void redrawRange(Control parent, int logicalStart, int length, int xOffset, int yOffset, int height) {
+ Enumeration directionRuns = getDirectionRuns(logicalStart, length).elements();
+
+ if (logicalStart + length > getTextLength()) {
+ return;
+ }
+ while (directionRuns.hasMoreElements()) {
+ DirectionRun run = (DirectionRun) directionRuns.nextElement();
+ int visualStart = run.getVisualStart();
+ int visualEnd = run.getVisualEnd();
+ int startX = run.getRenderStartX();
+
+ parent.redraw(xOffset + startX, yOffset, run.getRenderStopX() - startX, height, true);
+ }
+}
+public static void removeLanguageListener (int hwnd) {
+ BidiUtil.removeLanguageListener(hwnd);
+}
+void setGC(GC gc) {
+ this.gc = gc;
+}
+/**
+ *
+ */
+public void setKeyboardLanguage(int logicalIndex) {
+ int language = BidiUtil.KEYBOARD_LATIN;
+
+ if (logicalIndex >= classBuffer.length) {
+ return;
+ }
+ if (isRightToLeftMode(logicalIndex)) {
+ String codePage = System.getProperty("file.encoding").toUpperCase();
+ if ("CP1255".equals(codePage)) {
+ language = BidiUtil.KEYBOARD_HEBREW;
+ }
+ else
+ if ("CP1256".equals(codePage)) {
+ language = BidiUtil.KEYBOARD_ARABIC;
+ }
+ }
+ BidiUtil.setKeyboardLanguage(language);
+}
+void setTabWidth(int tabWidth) {
+ this.tabWidth = tabWidth;
+}
+/**
+ * Should change output to conform with other SWT toString output (i.e., Class {value1, value2})
+ */
+public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append("\n");
+ buf.append("Render Positions: ");
+ buf.append("\n");
+ for (int i=0; i<renderPositions.length; i++) {
+ buf.append(renderPositions[i]);
+ buf.append(" ");
+ }
+ buf.append("\n");
+ buf.append("Order: ");
+ buf.append("\n");
+ for (int i=0; i<order.length; i++) {
+ buf.append(order[i]);
+ buf.append(" ");
+ }
+ buf.append("\n");
+ buf.append("DX: ");
+ buf.append("\n");
+ for (int i=0; i<dx.length; i++) {
+ buf.append(dx[i]);
+ buf.append(" ");
+ }
+ buf.append("\n");
+ buf.append("Class: ");
+ buf.append("\n");
+ for (int i=0; i<classBuffer.length; i++) {
+ buf.append(classBuffer[i]);
+ buf.append(" ");
+ }
+ buf.append("\n");
+ buf.append("Glyph Buffer: ");
+ buf.append("\n");
+ for (int i=0; i<glyphBuffer.length; i++) {
+ buf.append(glyphBuffer[i]);
+ buf.append(" ");
+ }
+/* buf.append("\n");
+ buf.append("Glyphs: ");
+ buf.append("\n");
+ buf.append(getGlyphs());
+ buf.append("\n");
+*/
+ return buf.toString();
+}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextContent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextContent.java
new file mode 100644
index 0000000000..cd4995f94d
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextContent.java
@@ -0,0 +1,187 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.*;
+
+public interface StyledTextContent {
+
+/**
+ * Called by StyledText to add itself as an Observer to content changes.
+ * Implementors should send a TextChangingEvent when changes to the content
+ * are about to occur and a TextChangedEvent when the changes did occur.
+ * The widget only updates the screen properly when it receives both events.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT when listener is null</li>
+ * </ul>
+ */
+public void addTextChangeListener(TextChangeListener listener);
+
+/**
+ * Return the number of characters in the content.
+ * <p>
+ *
+ * @return the number of characters in the content.
+ */
+public int getCharCount();
+
+/**
+ * Return the line at the given character offset without delimiters.
+ * <p>
+ *
+ * @param offset offset of the line to return. Does not include delimiters
+ * of preceeding lines. Offset 0 is the first character of the document.
+ * @return the line text without delimiters
+ */
+public String getLine(int offset);
+
+/**
+ * Return the line index at the given character offset.
+ * <p>
+ *
+ * @param offset offset of the line to return. The first character of the document
+ * is at offset 0. An offset of getLength() is valid and should answer
+ * the number of lines.
+ * @return the line index. The first line is at index 0. If the character at offset
+ * is a delimiter character, answer the line index of the line that is delimited.
+ * For example, if text = "\r\n\r\n", and delimiter = "\r\n", then:
+ * <ul>
+ * <li>getLineAtOffset(0) == 0
+ * <li>getLineAtOffset(1) == 0
+ * <li>getLineAtOffset(2) == 1
+ * <li>getLineAtOffset(3) == 1
+ * <li>getLineAtOffset(4) == 2
+ * </ul>
+ */
+public int getLineAtOffset(int offset);
+
+/**
+ * Return the number of lines. Should answer 1 when no text is specified.
+ * The StyledText widget relies on this behavior for drawing the cursor.
+ * <p>
+ *
+ * @return the number of lines. For example:
+ * <ul>
+ * <li> text value ==> getLineCount
+ * <li> null ==> 1
+ * <li> "" ==> 1
+ * <li> "a\n" ==> 2
+ * <li> "\n\n" ==> 3
+ * </ul>
+ */
+public int getLineCount();
+
+/**
+ * Return the line delimiter that should be used by the StyledText
+ * widget when inserting new lines. New lines entered using key strokes
+ * and paste operations use this line delimiter.
+ * Implementors may use System.getProperty("line.separator") to return
+ * the platform line delimiter.
+ * <p>
+ *
+ * @return the line delimiter that should be used by the StyledText widget
+ * when inserting new lines.
+ */
+public String getLineDelimiter();
+
+/**
+ * Return the character offset of the first character of the given line.
+ * <p>
+ * <b>NOTE:</b> When there is no text (i.e., no lines), getOffsetAtLine(0)
+ * is a valid call that should return 0.
+ * </p>
+ *
+ * @param lineIndex index of the line. The first line is at index 0.
+ * @return offset offset of the first character of the line. The first character
+ * of the document is at offset 0. The return value should include
+ * line delimiters. For example, if text = "\r\ntest\r\n" and delimiter = "\r\n",
+ * then:
+ * <ul>
+ * <li>getOffsetAtLine(0) == 0
+ * <li>getOffsetAtLine(1) == 2
+ * <li>getOffsetAtLine(2) == 8
+ * </ul>
+ */
+public int getOffsetAtLine(int lineIndex);
+
+/**
+ * Returns a string representing the content at the given range.
+ * <p>
+ *
+ * @param start the start offset of the text to return. Offset 0 is the first
+ * character of the document.
+ * @param length the length of the text to return
+ * @return the text at the given range
+ */
+public String getTextRange(int start, int length);
+
+/**
+ * Remove the specified text changed listener.
+ * <p>
+ *
+ * @param listener the listener
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT when listener is null</li>
+ * </ul>
+ */
+public void removeTextChangeListener(TextChangeListener listener);
+
+/**
+ * Replace the text with "newText" starting at position "start"
+ * for a length of "replaceLength".
+ * <p>
+ * Implementors have to notify the TextChangeListeners that were added
+ * using <code>addTextChangeListener</code> before and after the content
+ * is changed. A <code>TextChangingEvent</code> has to be sent before the
+ * content is changed and a <code>TextChangedEvent</code> has to be sent
+ * after the content has changed.
+ * The text change that occurs after the <code>TextChangingEvent</code>
+ * has been sent has to be consistent with the data provided in the
+ * <code>TextChangingEvent</code>.
+ * This data will be cached by the widget and will be used when the
+ * <code>TextChangedEvent</code> is received.
+ * <p>
+ * The <code>TextChangingEvent</code> should be set as follows:
+ * <ul>
+ * <li>event.start = start of the replaced text
+ * <li>event.newText = text that is going to be inserted or empty String
+ * if no text will be inserted
+ * <li>event.replaceCharCount = length of text that is going to be replaced
+ * <li>event.newCharCount = length of text that is going to be inserted
+ * <li>event.replaceLineCount = number of lines that are going to be replaced
+ * <li>event.newLineCount = number of new lines that are going to be inserted
+ * </ul>
+ * <b>NOTE:</b> newLineCount is the number of inserted lines and replaceLineCount is
+ * the number of deleted lines based on the change that occurs visually. For
+ * example:
+ * <ul>
+ * <li>(replaceText, newText) ==> (replaceLineCount, newLineCount)
+ * <li>("", "\n") ==> (0, 1)
+ * <li>("\n\n", "a") ==> (2, 0)
+ * <li>("a", "\n\n") ==> (0, 2)
+ * <li>("\n", "") ==> (1, 0)
+ * </ul>
+ * </p>
+ *
+ * @param start start offset of text to replace, none of the offsets include
+ * delimiters of preceeding lines, offset 0 is the first character of the document
+ * @param replaceLength start offset of text to replace
+ * @param newText start offset of text to replace
+ */
+public void replaceTextRange(int start, int replaceLength, String text);
+
+/**
+ * Set text to "text".
+ * Implementors have to send a <code>TextChangedEvent</code> to the
+ * TextChangeListeners that were added using <code>addTextChangeListener</code>.
+ * <p>
+ *
+ * @param text the new text
+ */
+public void setText(String text);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextEvent.java
new file mode 100644
index 0000000000..f67b669139
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextEvent.java
@@ -0,0 +1,30 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+ *
+ */
+class StyledTextEvent extends Event {
+ // used by LineStyleEvent
+ StyleRange[] styles;
+ // used by LineBackgroundEvent
+ Color lineBackground;
+ // used by TextChangedEvent
+ int replaceCharCount;
+ int newCharCount;
+ int replaceLineCount;
+ int newLineCount;
+
+StyledTextEvent (StyledTextContent content) {
+ super();
+ data = content;
+}
+}
+
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextListener.java
new file mode 100644
index 0000000000..2808634a45
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextListener.java
@@ -0,0 +1,65 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.widgets.*;
+import java.util.*;
+
+class StyledTextListener extends TypedListener {
+/**
+ */
+StyledTextListener(EventListener listener) {
+ super(listener);
+}
+/**
+ * Process StyledText events by invoking the event's handler.
+ */
+public void handleEvent(Event e) {
+ TextChangedEvent textChangedEvent;
+
+ switch (e.type) {
+ case StyledText.ExtendedModify:
+ ExtendedModifyEvent extendedModifyEvent = new ExtendedModifyEvent((StyledTextEvent) e);
+ ((ExtendedModifyListener) eventListener).modifyText(extendedModifyEvent);
+ break;
+
+ case StyledText.LineGetStyle:
+ LineStyleEvent lineStyleEvent = new LineStyleEvent((StyledTextEvent) e);
+ ((LineStyleListener) eventListener).lineGetStyle(lineStyleEvent);
+ ((StyledTextEvent) e).styles = lineStyleEvent.styles;
+ break;
+
+ case StyledText.LineGetBackground:
+ LineBackgroundEvent lineBgEvent = new LineBackgroundEvent((StyledTextEvent) e);
+ ((LineBackgroundListener) eventListener).lineGetBackground(lineBgEvent);
+ ((StyledTextEvent) e).lineBackground = lineBgEvent.lineBackground;
+ break;
+
+ case StyledText.VerifyKey:
+ VerifyEvent verifyEvent = new VerifyEvent(e);
+ ((VerifyKeyListener) eventListener).verifyKey(verifyEvent);
+ e.doit = verifyEvent.doit;
+ break;
+
+ case StyledText.TextChanging:
+ TextChangingEvent textChangingEvent = new TextChangingEvent((StyledTextContent) e.data, (StyledTextEvent) e);
+ ((TextChangeListener) eventListener).textChanging(textChangingEvent);
+ break;
+
+ case StyledText.TextChanged:
+ textChangedEvent = new TextChangedEvent((StyledTextContent) e.data);
+ ((TextChangeListener) eventListener).textChanged(textChangedEvent);
+ break;
+
+ case StyledText.TextSet:
+ textChangedEvent = new TextChangedEvent((StyledTextContent) e.data);
+ ((TextChangeListener) eventListener).textSet(textChangedEvent);
+ break;
+ }
+}
+}
+
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextPrinter.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextPrinter.java
new file mode 100644
index 0000000000..bc90308868
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/StyledTextPrinter.java
@@ -0,0 +1,352 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import java.io.*;
+import java.util.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.custom.*;
+import org.eclipse.swt.printing.*;
+
+class StyledTextPrinter implements Runnable {
+ class RTFState {
+ int fontStyle;
+ int foreground;
+ int background;
+ }
+ Vector savedState = new Vector();
+
+ Printer printer;
+ GC gc;
+ String rtf;
+ StringBuffer wordBuffer;
+ int index, end;
+ String tabs = "";
+ int tabWidth = 0;
+ int lineHeight = 0;
+ int leftMargin, rightMargin, topMargin, bottomMargin;
+ int x, y;
+
+ /* We can optimize for fonts because we know styledText only has one font.
+ * As soon as we know the font name and point size, we will create and store
+ * fonts for the following styles: normal, bold, italic, and bold italic.
+ */
+ Font fontTable[][] = new Font[1][4];
+ boolean creatingFontTable = false;
+ String fontName;
+ int fontSize;
+ int currentFontStyle = SWT.NORMAL;
+ int currentFont = -1;
+ int defaultFont = -1;
+
+ Vector colorTable = new Vector();
+ boolean creatingColorTable = false;
+ int red, green, blue;
+ int currentForeground = -1;
+ int currentBackground = -1;
+
+ static void print(StyledText styledText) {
+ Printer printer = new Printer();
+ new StyledTextPrinter(styledText, printer).run();
+ printer.dispose();
+ }
+
+ StyledTextPrinter(StyledText styledText, Printer printer) {
+ this.printer = printer;
+
+ /* Create a buffer for computing tab width. */
+ int tabSize = styledText.getTabs();
+ StringBuffer tabBuffer = new StringBuffer(tabSize);
+ for (int i = 0; i < tabSize; i++) tabBuffer.append(' ');
+ tabs = tabBuffer.toString();
+
+ /* Get RTF from the StyledText.*/
+ rtf = styledText.getRtf();
+ }
+
+ public void run() {
+ if (printer.startJob("Printing")) {
+ Rectangle clientArea = printer.getClientArea();
+ Rectangle trim = printer.computeTrim(0, 0, 0, 0);
+ Point dpi = printer.getDPI();
+ leftMargin = dpi.x + trim.x; // one inch from left side of paper
+ rightMargin = clientArea.width - dpi.x + trim.x + trim.width; // one inch from right side of paper
+ topMargin = dpi.y + trim.y; // one inch from top edge of paper
+ bottomMargin = clientArea.height - dpi.y + trim.y + trim.height; // one inch from bottom edge of paper
+
+ /* Create a printer GC and print the RTF to it. */
+ gc = new GC(printer);
+ x = leftMargin;
+ y = topMargin;
+ printer.startPage();
+ end = rtf.length();
+ index = 0;
+ wordBuffer = new StringBuffer();
+ while (index < end) {
+ char c = rtf.charAt(index);
+ index++;
+ switch (c) {
+ case '\\':
+ printWordBuffer();
+ parseControlWord();
+ break;
+ case '{':
+ printWordBuffer();
+ saveState();
+ break;
+ case '}':
+ printWordBuffer();
+ restoreState();
+ break;
+ case 0x0a:
+ case 0x0d:
+ printWordBuffer();
+ break;
+ default:
+ parseChar(c);
+ }
+ }
+ if (y + lineHeight <= bottomMargin) {
+ printer.endPage();
+ }
+ printer.endJob();
+
+ /* Cleanup */
+ gc.dispose();
+ for (int i = 0; i < 4; i++) {
+ fontTable[currentFont][i].dispose();
+ }
+ for (int i = 0; i < colorTable.size(); i++) {
+ ((Color)colorTable.elementAt(i)).dispose();
+ }
+ }
+ }
+
+ void parseControlWord() {
+ if (index >= end) return;
+ char c = rtf.charAt(index);
+ index++;
+ if (!Character.isLetter(c)) {
+ handleControlSymbol(c);
+ return;
+ }
+ StringBuffer controlWord = new StringBuffer();
+ controlWord.append(c);
+ while (index < end) {
+ c = rtf.charAt(index);
+ index++;
+ if (!Character.isLetter(c)) break;
+ controlWord.append(c);
+ }
+ boolean isNegative = false;
+ if (c == '-') {
+ isNegative = true;
+ c = rtf.charAt(index);
+ index++;
+ }
+ boolean hasParameter = false;
+ StringBuffer paramBuffer = new StringBuffer();
+ int parameter = 0;
+ if (Character.isDigit(c)) {
+ hasParameter = true;
+ paramBuffer.append(c);
+ while (index < end) {
+ c = rtf.charAt(index);
+ index++;
+ if (!Character.isDigit(c)) break;
+ paramBuffer.append(c);
+ }
+ try {
+ parameter = Integer.valueOf(paramBuffer.toString()).intValue();
+ } catch (NumberFormatException e) {}
+ if (isNegative) parameter = -parameter;
+ }
+ if (c != ' ') index--;
+ if (hasParameter) {
+ handleControlWord(controlWord.toString(), parameter);
+ } else {
+ handleControlWord(controlWord.toString());
+ }
+ }
+
+ void parseChar(char c) {
+ if (c == 0) return;
+ if (c == ';') {
+ if (creatingFontTable) {
+ fontName = wordBuffer.toString();
+ wordBuffer = new StringBuffer();
+ creatingFontTable = false;
+ return;
+ }
+ if (creatingColorTable) {
+ colorTable.addElement(new Color(printer, red, green, blue));
+ red = green = blue = 0;
+ return;
+ }
+ }
+ if (c != '\t') {
+ wordBuffer.append(c);
+ }
+ if (!Character.isLetterOrDigit(c) && !creatingFontTable) {
+ printWordBuffer();
+ if (c == '\t') {
+ x += tabWidth;
+ }
+ }
+ }
+
+ void printWordBuffer() {
+ if (wordBuffer.length() > 0) {
+ String word = wordBuffer.toString();
+ int wordWidth = gc.stringExtent(word).x;
+ if (x + wordWidth > rightMargin) {
+ /* word doesn't fit on current line, so wrap */
+ newline();
+ }
+ gc.drawString(word, x, y, true);
+ x += wordWidth;
+ wordBuffer = new StringBuffer();
+ }
+ }
+
+ void handleControlSymbol(char c) {
+ switch (c) {
+ case '\\':
+ case '{':
+ case '}':
+ parseChar(c);
+ }
+ }
+
+ void handleControlWord(String controlWord) {
+ if (controlWord.equals("par")) newline();
+ else if (controlWord.equals("b")) setFontStyle(currentFontStyle | SWT.BOLD);
+ else if (controlWord.equals("i")) setFontStyle(currentFontStyle | SWT.ITALIC);
+ else if (controlWord.equals("fnil")) setFont(defaultFont);
+ else if (controlWord.equals("fonttbl")) createFontTable();
+ else if (controlWord.equals("colortbl")) createColorTable();
+ }
+
+ void handleControlWord(String controlWord, int parameter) {
+ if (controlWord.equals("highlight")) setBackground(parameter);
+ else if (controlWord.equals("cf")) setForeground(parameter);
+ else if (controlWord.equals("b")) setFontStyle(currentFontStyle & ~SWT.BOLD);
+ else if (controlWord.equals("i")) setFontStyle(currentFontStyle & ~SWT.ITALIC);
+ else if (controlWord.equals("f")) setFont(parameter);
+ else if (controlWord.equals("fs")) setFontSize(parameter);
+ else if (controlWord.equals("red")) red = parameter;
+ else if (controlWord.equals("green")) green = parameter;
+ else if (controlWord.equals("blue")) blue = parameter;
+ else if (controlWord.equals("deff")) setDefaultFont(parameter);
+ }
+
+ void setDefaultFont(int number) {
+ defaultFont = number;
+ }
+
+ void setFont(int number) {
+ currentFont = number;
+ }
+
+ void createFontTable() {
+ creatingFontTable = true;
+ currentFont = 0;
+ }
+
+ void setFontSize(int size) {
+ fontSize = size / 2;
+ createFonts();
+ }
+
+ void createFonts() {
+ if (fontName != null && fontSize != -1) {
+ // currentFont must already be set
+ fontTable[currentFont][0] = new Font(printer, fontName, fontSize, SWT.NORMAL);
+ fontTable[currentFont][1] = new Font(printer, fontName, fontSize, SWT.BOLD);
+ fontTable[currentFont][2] = new Font(printer, fontName, fontSize, SWT.ITALIC);
+ fontTable[currentFont][3] = new Font(printer, fontName, fontSize, SWT.BOLD | SWT.ITALIC);
+ setFontStyle(SWT.NORMAL);
+ }
+ }
+
+ void setFontStyle(int style) {
+ // currentFont must already be set
+ Font font;
+ if ((style & SWT.BOLD) != 0) {
+ if ((style & SWT.ITALIC) != 0) {
+ font = fontTable[currentFont][3];
+ } else {
+ font = fontTable[currentFont][1];
+ }
+ } else if ((style & SWT.ITALIC) != 0) {
+ font = fontTable[currentFont][2];
+ } else {
+ font = fontTable[currentFont][0];
+ }
+ gc.setFont(font);
+ tabWidth = gc.stringExtent(tabs).x;
+ lineHeight = gc.getFontMetrics().getHeight();
+ currentFontStyle = style;
+ }
+
+ void createColorTable() {
+ creatingColorTable = true;
+ red = green = blue = 0;
+ }
+
+ void setForeground(int color) {
+ if (color != currentForeground) {
+ // colors must already be in table
+ gc.setForeground((Color)colorTable.elementAt(color));
+ currentForeground = color;
+ }
+ }
+
+ void setBackground(int color) {
+ if (color != currentBackground) {
+ // colors must already be in table
+ gc.setBackground((Color)colorTable.elementAt(color));
+ currentBackground = color;
+ }
+ }
+
+ void newline() {
+ x = leftMargin;
+ y += lineHeight;
+ if (y + lineHeight > bottomMargin) {
+ printer.endPage();
+ if (index + 1 < end) {
+ y = topMargin;
+ printer.startPage();
+ }
+ }
+ }
+
+ void saveState() {
+ RTFState state = new RTFState();
+ state.fontStyle = currentFontStyle;
+ state.foreground = currentForeground;
+ state.background = currentBackground;
+ savedState.addElement(state);
+ }
+
+ void restoreState() {
+ if (savedState.isEmpty()) return;
+ if (creatingColorTable) {
+ setForeground(0);
+ setBackground(1);
+ creatingColorTable = false;
+ }
+ RTFState state = (RTFState)savedState.remove(savedState.size() - 1);
+ setFontStyle(state.fontStyle);
+ if (state.foreground != -1) setForeground(state.foreground);
+ if (state.background != -1) setBackground(state.background);
+ }
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableEditor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableEditor.java
new file mode 100644
index 0000000000..1fdca24770
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableEditor.java
@@ -0,0 +1,179 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+*
+* A TableEditor is a manager for a Control that appears above a cell in a Table and tracks with the
+* moving and resizing of that cell. It can be used to display a text widget above a cell
+* in a Table so that the user can edit the contents of that cell. It can also be used to display
+* a button that can launch a dialog for modifying the contents of the associated cell.
+*
+* <p> Here is an example of using a TableEditor:
+* <code><pre>
+* Table table = new Table(parent, SWT.FULL_SELECTION);
+* TableEditor editor = new TableEditor (table);
+* table.addSelectionListener (new SelectionAdapter() {
+* public void widgetSelected(SelectionEvent e) {
+*
+* // Clean up any previous editor control
+* Control oldEditor = editor.getEditor();
+* if (oldEditor != null)
+* oldEditor.dispose();
+*
+* // Identify the selected row
+* int index = table.getSelectionIndex ();
+* if (index == -1) return;
+* TableItem item = table.getItem (index);
+*
+* // The control that will be the editor must be a child of the Table
+* Text text = new Text(table, SWT.NONE);
+*
+* //The text editor must have the same size as the cell and must
+* //not be any smaller than 50 pixels.
+* editor.horizontalAlignment = SWT.LEFT;
+* editor.grabHorizontal = true;
+* editor.minimumWidth = 50;
+*
+* // Open the text editor in the second column of the selected row.
+* editor.setEditor (text, item, 1);
+*
+* // Assign focus to the text control
+* text.setFocus ();
+* }
+* });
+* </pre></code>
+*/
+public class TableEditor extends ControlEditor {
+
+ Table table;
+ TableItem item;
+ int column = -1;
+ Listener columnListener;
+/**
+* Creates a TableEditor for the specified Table.
+*
+* @param table the Table Control above which this editor will be displayed
+*
+*/
+public TableEditor (Table table) {
+ super(table);
+ this.table = table;
+
+ columnListener = new Listener() {
+ public void handleEvent(Event e) {
+ resize ();
+ }
+ };
+
+}
+Rectangle computeBounds () {
+ if (item == null || column == -1 || item.isDisposed()) return new Rectangle(0, 0, 0, 0);
+
+ Rectangle cell = item.getBounds(column);
+ Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, cell.height);
+ Rectangle area = table.getClientArea();
+ if (cell.x < area.x + area.width) {
+ if (cell.x + cell.width > area.x + area.width) {
+ cell.width = area.width - cell.x;
+ }
+ }
+
+ if (grabHorizontal){
+ editorRect.width = Math.max(cell.width, minimumWidth);
+ }
+
+ if (horizontalAlignment == SWT.RIGHT) {
+ editorRect.x += cell.width - editorRect.width;
+ } else if (horizontalAlignment == SWT.LEFT) {
+ // do nothing - cell.x is the right answer
+ } else { // default is CENTER
+ editorRect.x += (cell.width - editorRect.width)/2;
+ }
+
+ return editorRect;
+}
+/**
+ * Removes all associations between the TableEditor and the cell in the table. The
+ * Table and the editor Control are <b>not</b> disposed.
+ */
+public void dispose () {
+
+ if (this.column > -1 && this.column < table.getColumnCount()){
+ TableColumn tableColumn = table.getColumn(this.column);
+ tableColumn.removeListener(SWT.Resize, columnListener);
+ tableColumn.removeListener(SWT.Move, columnListener);
+ }
+
+ table = null;
+ item = null;
+ column = -1;
+
+ super.dispose();
+}
+/**
+* Returns the zero based index of the column of the cell being tracked by this editor.
+*
+* @return the zero based index of the column of the cell being tracked by this editor
+*/
+public int getColumn () {
+ return column;
+}
+public void setColumn(int column) {
+
+ if (this.column > -1 && this.column < table.getColumnCount()){
+ TableColumn tableColumn = table.getColumn(this.column);
+ tableColumn.removeListener(SWT.Resize, columnListener);
+ tableColumn.removeListener(SWT.Move, columnListener);
+ this.column = -1;
+ }
+
+ if (column < 0 || column >= table.getColumnCount()) return;
+
+ this.column = column;
+ TableColumn tableColumn = table.getColumn(this.column);
+ tableColumn.addListener(SWT.Resize, columnListener);
+ tableColumn.addListener(SWT.Move, columnListener);
+}
+/**
+* Returns the TableItem for the row of the cell being tracked by this editor.
+*
+* @return the TableItem for the row of the cell being tracked by this editor
+*/
+public TableItem getItem () {
+ return item;
+}
+public void setItem (TableItem item) {
+ this.item = item;
+}
+public void setEditor (Control editor) {
+ TableItem item = null;
+ if (table.getItemCount() > 0) {
+ item = table.getItem(0);
+ }
+ this.setEditor(editor, item, 0);
+}
+
+/**
+* Specify the Control that is to be displayed and the cell in the table that it is to be positioned above.
+*
+* <p>Note: The Control provided as the editor <b>must</b> be created with its parent being the Table control
+* specified in the TableEditor constructor.
+*
+* @param editor the Control that is displayed above the cell being edited
+* @param item the TableItem for the row of the cell being tracked by this editor
+* @param column the zero based index of the column of the cell being tracked by this editor
+*/
+public void setEditor (Control editor, TableItem item, int column) {
+ setItem(item);
+ setColumn(column);
+ super.setEditor(editor);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTree.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTree.java
new file mode 100644
index 0000000000..ae8005ab4c
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTree.java
@@ -0,0 +1,708 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import java.util.Enumeration;
+import java.util.Vector;
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+ * A TableTree is a selectable user interface object
+ * that displays a hierarchy of items, and issues
+ * notification when an item is selected.
+ * A TableTree may be single or multi select.
+ * <p>
+ * The item children that may be added to instances of this class
+ * must be of type <code>TableTreeItem</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> <dd> SINGLE, MULTI, CHECK, FULL_SELECTION
+ * <dt><b>Events:</b> <dd> Selection, DefaultSelection, Collapse, Expand
+ * </dl>
+ */
+public class TableTree extends Composite {
+ Table table;
+ TableTreeItem[] items = EMPTY_ITEMS;
+ Image plusImage, minusImage, sizeImage;
+
+ /*
+ * TableTreeItems are not treated as children but rather as items.
+ * When the TableTree is disposed, all children are disposed because
+ * TableTree inherits this behaviour from Composite. The items
+ * must be disposed separately. Because TableTree is not part of
+ * the org.eclipse.swt.widgets package, the method releaseWidget can
+ * not be overriden (this is how items are disposed of in Table and Tree).
+ * Instead, the items are disposed of in response to the dispose event on the
+ * TableTree. The "inDispose" flag is used to distinguish between disposing
+ * one TableTreeItem (e.g. when removing an entry from the TableTree) and
+ * disposing the entire TableTree.
+ */
+ boolean inDispose = false;
+
+ static final TableTreeItem[] EMPTY_ITEMS = new TableTreeItem [0];
+ static final String[] EMPTY_TEXTS = new String [0];
+ static final Image[] EMPTY_IMAGES = new Image [0];
+
+/**
+ * Creates a new instance of the widget.
+ *
+ * @param parent a composite widget
+ * @param style the bitwise OR'ing of widget styles
+ */
+public TableTree(Composite parent, int style) {
+ super(parent, SWT.NONE);
+ table = new Table(this, style);
+ setBackground(table.getBackground());
+ setForeground(table.getForeground());
+ setFont(table.getFont());
+ table.addListener(SWT.MouseDown, new Listener() {
+ public void handleEvent(Event e) {
+ onMouseDown(e);
+ }
+ });
+ table.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ onSelection(e);
+ }
+ });
+ table.addListener(SWT.DefaultSelection, new Listener() {
+ public void handleEvent(Event e) {
+ onSelection(e);
+ }
+ });
+
+ addListener(SWT.Dispose, new Listener() {
+ public void handleEvent(Event e) {
+ onDispose();
+ }
+ });
+ addListener(SWT.Resize, new Listener() {
+ public void handleEvent(Event e) {
+ onResize();
+ }
+ });
+ addListener(SWT.FocusIn, new Listener() {
+ public void handleEvent(Event e) {
+ onFocusIn();
+ }
+ });
+}
+
+int addItem(TableTreeItem item, int index) {
+ if (index < 0 || index > items.length) throw new SWTError(SWT.ERROR_INVALID_ARGUMENT);
+ TableTreeItem[] newItems = new TableTreeItem[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;
+
+ /* Return the index in the table where this table should be inserted */
+ if (index == items.length - 1 )
+ return table.getItemCount();
+ else
+ return table.indexOf(items[index+1].tableItem);
+}
+
+/**
+ * Adds the listener to receive selection events.
+ * <p>
+ *
+ * @param listener the selection listener
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed
+ * <li>ERROR_NULL_ARGUMENT when listener is null
+ * </ul>
+ */
+public void addSelectionListener(SelectionListener listener) {
+ if (listener == null) throw new SWTError (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Selection,typedListener);
+ addListener (SWT.DefaultSelection,typedListener);
+}
+
+/**
+ * Adds the listener to receive tree events.
+ * <p>
+ *
+ * @param listener the tree listener
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed
+ * <li>ERROR_NULL_ARGUMENT when listener is null
+ * </ul>
+ */
+public void addTreeListener(TreeListener listener) {
+ if (listener == null) throw new SWTError (SWT.ERROR_NULL_ARGUMENT);
+ TypedListener typedListener = new TypedListener (listener);
+ addListener (SWT.Expand, typedListener);
+ addListener (SWT.Collapse, typedListener);
+}
+
+/**
+ * Computes the preferred size of the widget.
+ * <p>
+ * Calculate the preferred size of the widget based
+ * on the current contents. The hint arguments allow
+ * a specific client area width and/or height to be
+ * requested. The hints may be honored depending on
+ * the platform and the layout.
+ *
+ * @param wHint the width hint (can be SWT.DEFAULT)
+ * @param hHint the height hint (can be SWT.DEFAULT)
+ * @return a point containing the preferred size of the widget including trim
+ *
+ * @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 Point computeSize (int wHint, int hHint) {
+ return table.computeSize (wHint, hHint, true);
+}
+
+/**
+ * Computes the widget trim.
+ * <p>
+ * Trim is widget specific and may include scroll
+ * bars and menu bar in addition to other trimmings
+ * that are outside of the widget's client area.
+ *
+ * @param x the x location of the client area
+ * @param y the y location of the client area
+ * @param width the width of the client area
+ * @param height the height of the client area
+ * @return a rectangle containing the trim of the widget.
+ *
+ * @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 Rectangle computeTrim (int x, int y, int width, int height) {
+ return table.computeTrim(x, y, width, height);
+}
+
+/**
+ * Deselects all items.
+ * <p>
+ * If an item is selected, it is deselected.
+ * If an item is not selected, it remains unselected.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed
+ * </ul>
+ */
+public void deselectAll () {
+ table.deselectAll();
+}
+
+/* Expand upward from the specified leaf item. */
+void expandItem (TableTreeItem item) {
+ if (item == null || item.getExpanded()) return;
+ expandItem(item.parentItem);
+ item.setExpanded(true);
+ Event event = new Event();
+ event.item = item;
+ notifyListeners(SWT.Expand, event);
+}
+
+/**
+ * Gets the number of items.
+ * <p>
+ * @return the number of items in the widget
+ */
+public int getItemCount () {
+ return items.length;
+}
+
+/**
+ * Gets the height of one item.
+ * <p>
+ * This operation will fail if the height of
+ * one item could not be queried from the OS.
+ *
+ * @return the height of one item in the widget
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed
+ * <li>ERROR_CANNOT_GET_ITEM_HEIGHT when the operation fails
+ * </ul>
+ */
+public int getItemHeight () {
+ return table.getItemHeight();
+}
+
+/**
+ * Gets the items.
+ * <p>
+ * @return the items in the widget
+ *
+ */
+public TableTreeItem [] getItems () {
+ TableTreeItem[] newItems = new TableTreeItem[items.length];
+ System.arraycopy(items, 0, newItems, 0, items.length);
+ return newItems;
+}
+
+/**
+ * Gets the selected items.
+ * <p>
+ * This operation will fail if the selected
+ * items cannot be queried from the OS.
+ *
+ * @return the selected items in the widget
+ *
+ * @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_CANNOT_GET_SELECTION when the operation fails</li>
+ * </ul>
+ */
+public TableTreeItem [] getSelection () {
+ TableItem[] selection = table.getSelection();
+ TableTreeItem [] result = new TableTreeItem[selection.length];
+ for (int i = 0; i < selection.length; i++){
+ result[i] = (TableTreeItem) selection[i].getData();
+ }
+ return result;
+}
+
+/**
+ * Gets the number of selected items.
+ * <p>
+ * This operation will fail if the number of selected
+ * items cannot be queried from the OS.
+ *
+ * @return the number of selected items in the widget
+ *
+ * @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_CANNOT_GET_COUNT when the operation fails</li>
+ * </ul>
+ */
+public int getSelectionCount () {
+ return table.getSelectionCount();
+}
+
+/**
+ * Returns the underlying Table control.
+ *
+ * @return the underlying Table control
+ */
+public Table getTable () {
+ return table;
+}
+
+void createImages () {
+
+ int itemHeight = sizeImage.getBounds().height;
+ // Calculate border around image.
+ // At least 9 pixels are needed to draw the image
+ // Leave at least a 6 pixel border.
+ int indent = Math.min(6, (itemHeight - 9) / 2);
+ indent = Math.max(0, indent);
+ int size = Math.max (10, itemHeight - 2 * indent);
+ size = ((size + 1) / 2) * 2; // size must be an even number
+ int midpoint = indent + size / 2;
+
+ Color foreground = getForeground();
+ Color plusMinus = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ Color background = getBackground();
+
+ /* Plus image */
+ PaletteData palette = new PaletteData(new RGB[]{foreground.getRGB(), background.getRGB(), plusMinus.getRGB()});
+ ImageData imageData = new ImageData(itemHeight, itemHeight, 4, palette);
+ imageData.transparentPixel = 1;
+ plusImage = new Image(getDisplay(), imageData);
+ GC gc = new GC(plusImage);
+ gc.setBackground(background);
+ gc.fillRectangle(0, 0, itemHeight, itemHeight);
+ gc.setForeground(plusMinus);
+ gc.drawRectangle(indent, indent, size, size);
+ gc.setForeground(foreground);
+ gc.drawLine(midpoint, indent + 2, midpoint, indent + size - 2);
+ gc.drawLine(indent + 2, midpoint, indent + size - 2, midpoint);
+ gc.dispose();
+
+ /* Minus image */
+ palette = new PaletteData(new RGB[]{foreground.getRGB(), background.getRGB(), plusMinus.getRGB()});
+ imageData = new ImageData(itemHeight, itemHeight, 4, palette);
+ imageData.transparentPixel = 1;
+ minusImage = new Image(getDisplay(), imageData);
+ gc = new GC(minusImage);
+ gc.setBackground(background);
+ gc.fillRectangle(0, 0, itemHeight, itemHeight);
+ gc.setForeground(plusMinus);
+ gc.drawRectangle(indent, indent, size, size);
+ gc.setForeground(foreground);
+ gc.drawLine(indent + 2, midpoint, indent + size - 2, midpoint);
+ gc.dispose();
+}
+
+Image getPlusImage() {
+ if (plusImage == null) createImages();
+ return plusImage;
+}
+
+Image getMinusImage() {
+ if (minusImage == null) createImages();
+ return minusImage;
+}
+
+/**
+ * Gets the index of an item.
+ *
+ * <p>The widget 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. This index is relative to the parent only.
+ *
+ * @param item the search item
+ * @return the index of the item or -1
+ *
+ */
+public int indexOf (TableTreeItem item) {
+ for (int i = 0; i < items.length; i++) {
+ if (item == items[i]) return i;
+ }
+ return -1;
+}
+
+void onDispose() {
+ inDispose = true;
+ for (int i = 0; i < items.length; i++) {
+ items[i].dispose();
+ }
+ inDispose = false;
+ if (plusImage != null) plusImage.dispose();
+ if (minusImage != null) minusImage.dispose();
+ if (sizeImage != null) sizeImage.dispose();
+ plusImage = minusImage = sizeImage = null;
+}
+
+void onResize () {
+ Rectangle area = getClientArea();
+ table.setBounds(0, 0, area.width, area.height);
+}
+
+void onSelection (Event e) {
+ Event event = new Event();
+ TableItem tableItem = (TableItem)e.item;
+ TableTreeItem item = getItem(tableItem);
+ event.item = item;
+
+ if (e.type == SWT.Selection
+ && e.detail == SWT.CHECK
+ && item != null) {
+ event.detail = SWT.CHECK;
+ item.checked = tableItem.getChecked();
+ }
+ notifyListeners(e.type, event);
+}
+public TableTreeItem getItem(Point point) {
+ TableItem item = table.getItem(point);
+ if (item == null) return null;
+ return getItem(item);
+
+}
+TableTreeItem getItem(TableItem tableItem) {
+ if (tableItem == null) return null;
+ for (int i = 0; i < items.length; i++) {
+ TableTreeItem item = items[i].getItem(tableItem);
+ if (item != null) return item;
+ }
+ return null;
+}
+void onFocusIn () {
+ table.setFocus();
+}
+
+void onMouseDown(Event event) {
+ /* If user clicked on the [+] or [-], expand or collapse the tree. */
+ TableItem[] items = table.getItems();
+ for (int i = 0; i < items.length; i++) {
+ Rectangle rect = items[i].getImageBounds(0);
+ if (rect.contains(event.x, event.y)) {
+ TableTreeItem item = (TableTreeItem) items[i].getData();
+ event = new Event();
+ event.item = item;
+ item.setExpanded(!item.getExpanded());
+ if (item.getExpanded()) {
+ notifyListeners(SWT.Expand, event);
+ } else {
+ notifyListeners(SWT.Collapse, event);
+ }
+ return;
+ }
+ }
+}
+
+/**
+ * Removes all items.
+ * <p>
+ * This operation will fail when an item
+ * could not be removed in the OS.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed
+ * <li>ERROR_ITEM_NOT_REMOVED when the operation fails
+ * </ul>
+ */
+public void removeAll () {
+ setRedraw(false);
+ for (int i = items.length - 1; i >= 0; i--) {
+ items[i].dispose();
+ }
+ items = EMPTY_ITEMS;
+ setRedraw(true);
+}
+
+void removeItem(TableTreeItem item) {
+ int index = 0;
+ while (index < items.length && items[index] != item) index++;
+ if (index == items.length) return;
+ TableTreeItem[] newItems = new TableTreeItem[items.length - 1];
+ System.arraycopy(items, 0, newItems, 0, index);
+ System.arraycopy(items, index + 1, newItems, index, items.length - index - 1);
+ items = newItems;
+}
+
+/**
+ * Removes the listener.
+ * <p>
+ *
+ * @param listener the listener
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed
+ * <li>ERROR_NULL_ARGUMENT when listener is null
+ * </ul>
+ */
+public void removeSelectionListener (SelectionListener listener) {
+ if (listener == null) throw new SWTError (SWT.ERROR_NULL_ARGUMENT);
+ removeListener(SWT.Selection, listener);
+ removeListener(SWT.DefaultSelection, listener);
+}
+
+/**
+ * Removes the listener.
+ *
+ * @param listener the listener
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed
+ * <li>ERROR_NULL_ARGUMENT when listener is null
+ * </ul>
+ */
+public void removeTreeListener (TreeListener listener) {
+ if (listener == null) throw new SWTError (SWT.ERROR_NULL_ARGUMENT);
+ removeListener(SWT.Expand, listener);
+ removeListener(SWT.Collapse, listener);
+}
+
+/**
+ * Selects all items.
+ * <p>
+ * If an item is not selected, it is selected.
+ * If an item is selected, it remains selected.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed
+ * </ul>
+ */
+public void selectAll () {
+ table.selectAll();
+}
+
+/**
+ * Sets the widget background color.
+ * <p>
+ * When new color is null, the background reverts
+ * to the default system color for the widget.
+ *
+ * @param color the new color (or null)
+ *
+ * @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 setBackground (Color color) {
+ super.setBackground(color);
+ table.setBackground(color);
+ if (sizeImage != null) {
+ GC gc = new GC (sizeImage);
+ gc.setBackground(getBackground());
+ Rectangle size = sizeImage.getBounds();
+ gc.fillRectangle(size);
+ gc.dispose();
+ }
+}
+
+/**
+ * Sets the enabled state.
+ * <p>
+ * A disabled widget is typically not selectable from
+ * the user interface and draws with an inactive or
+ * grayed look.
+ *
+ * @param enabled the new enabled 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 setEnabled (boolean enabled) {
+ super.setEnabled(enabled);
+ table.setEnabled(enabled);
+}
+
+/**
+ * Sets the widget font.
+ * <p>
+ * When new font is null, the font reverts
+ * to the default system font for the widget.
+ *
+ * @param font the new font (or null)
+ *
+ * @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 setFont (Font font) {
+ super.setFont(font);
+ table.setFont(font);
+}
+
+/**
+ * Gets the widget foreground color.
+ * <p>
+ * @return the widget foreground color
+ *
+ * @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 setForeground (Color color) {
+ super.setForeground(color);
+ table.setForeground(color);
+}
+
+/**
+ * Sets the pop up menu.
+ * <p>
+ * Every control has an optional pop up menu that is
+ * displayed when the user requests a popup menu for
+ * the control. The sequence of key strokes/button
+ * presses/button releases that is used to request
+ * a pop up menu is platform specific.
+ *
+ * @param menu the new pop up menu
+ *
+ * @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_MENU_NOT_POP_UP when the menu is not a POP_UP</li>
+ * <li>ERROR_NO_COMMON_PARENT when the menu is not in the same widget tree</li>
+ * </ul>
+ */
+public void setMenu (Menu menu) {
+ super.setMenu(menu);
+ table.setMenu(menu);
+}
+
+/**
+ * Sets the selection.
+ * <p>
+ * @param items new selection
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed
+ * <li>ERROR_NULL_ARGUMENT when items is null
+ * </ul>
+ */
+public void setSelection (TableTreeItem[] items) {
+ TableItem[] tableItems = new TableItem[items.length];
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] == null) throw new SWTError(SWT.ERROR_NULL_ARGUMENT);
+ if (!items[i].getVisible()) expandItem (items[i]);
+ tableItems[i] = items[i].tableItem;
+ }
+ table.setSelection(tableItems);
+}
+
+/**
+ * Sets the tool tip text.
+ * <p>
+ * @param string the new tool tip text (or null)
+ *
+ * @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 setToolTipText (String string) {
+ super.setToolTipText(string);
+ table.setToolTipText(string);
+}
+
+/**
+ * Shows the item.
+ * <p>
+ * @param item the item to be shown
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed
+ * <li>ERROR_NULL_ARGUMENT when item is null
+ * </ul>
+ */
+public void showItem (TableTreeItem item) {
+ if (item == null) throw new SWTError (SWT.ERROR_NULL_ARGUMENT);
+ if (!item.getVisible()) expandItem (item);
+ TableItem tableItem = item.tableItem;
+ table.showItem(tableItem);
+}
+
+/**
+ * Shows the selection.
+ * <p>
+ * If there is no selection or the selection
+ * is already visible, this method does nothing.
+ * If the selection is scrolled out of view,
+ * the top index of the widget is changed such
+ * that selection becomes visible.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
+ * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed
+ * </ul>
+ */
+public void showSelection () {
+ table.showSelection();
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTreeEditor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTreeEditor.java
new file mode 100644
index 0000000000..2ac7bba01e
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTreeEditor.java
@@ -0,0 +1,100 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+*
+* A TableTreeEditor is a manager for a Control that appears above a cell in a TableTree and tracks with the
+* moving and resizing of that cell. It can be used to display a text widget above a cell
+* in a TableTree so that the user can edit the contents of that cell. It can also be used to display
+* a button that can launch a dialog for modifying the contents of the associated cell.
+*
+* <p>The TableTreeEditor performs the same functions as the TableEditor except that the cell is in
+* a TableTree. Refer to TableEditor for additional information. The significant differnce is that
+* the Control provided as the editor <b>must</b> be created with its parent being the <b>Table</b>
+* control that is underneath the TableTree specified in the TableTreeEditor constructor.
+* The Table can be obtained from the TableTree using tableTree.getTable().
+*
+*/
+public class TableTreeEditor {
+
+ public int horizontalAlignment = SWT.CENTER;
+ public boolean grabHorizontal = false;
+ public int minimumWidth = 0;
+
+ TableTreeItem item;
+ TableEditor editor;
+/**
+* Creates a TableTreeEditor for the specified TableTree.
+*
+* @param tableTree the TableTree Control above which this editor will be displayed
+*
+*/
+public TableTreeEditor (TableTree tableTree) {
+ editor = new TableEditor (tableTree.getTable ());
+}
+/**
+ * Removes all associations between the TableTreeEditor and the cell in the TableTree. The
+ * TableTree and the editor Control are <b>not</b> disposed.
+ */
+public void dispose () {
+
+ editor.dispose();
+}
+/**
+* Returns the zero based index of the column of the cell being tracked by this editor.
+*
+* @return the zero based index of the column of the cell being tracked by this editor
+*/
+public int getColumn () {
+ return editor.getColumn ();
+}
+/**
+* Returns the Control that is displayed above the cell being edited.
+*
+* @return the Control that is displayed above the cell being edited
+*/
+public Control getEditor () {
+ return editor.getEditor ();
+}
+/**
+* Returns the TableTreeItem for the row of the cell being tracked by this editor.
+*
+* @return the TableTreeItem for the row of the cell being tracked by this editor
+*/
+public TableTreeItem getItem () {
+ return item;
+}
+/**
+* Specify the Control that is to be displayed and the cell in the TableTree that it is to be
+* positioned above.
+*
+* <p>Note: The Control provided as the editor <b>must</b> be created with its parent being the <b>Table</b>
+* control that is underneath the TableTree specified in the TableTreeEditor constructor.
+* The Table can be obtained from the TableTree using tableTree.getTable().
+*
+* @param editor the Control that is displayed above the cell being edited
+* @param item the TableTreeItem for the row of the cell being tracked by this editor
+* @param column the zero based index of the column of the cell being tracked by this editor
+*/
+public void setEditor (Control control, TableTreeItem item, int column) {
+ if (control == null) {
+ editor.setEditor (null, null, -1);
+ return;
+ }
+
+ this.item = item;
+ TableItem tableItem = item.tableItem;
+ editor.horizontalAlignment = horizontalAlignment;
+ editor.grabHorizontal = grabHorizontal;
+ editor.minimumWidth = minimumWidth;
+
+ editor.setEditor (control, tableItem, column);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTreeItem.java
new file mode 100644
index 0000000000..31bf476b07
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TableTreeItem.java
@@ -0,0 +1,558 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+
+/**
+ * A TableTreeItem is a selectable user interface object
+ * that represents an item in a heirarchy of items in a
+ * TableTree.
+ */
+public class TableTreeItem extends Item {
+ TableItem tableItem;
+ TableTree parent;
+ TableTreeItem parentItem;
+ TableTreeItem [] items = TableTree.EMPTY_ITEMS;
+ String[] texts = TableTree.EMPTY_TEXTS;
+ Image[] images = TableTree.EMPTY_IMAGES;
+ boolean expanded;
+ boolean checked;
+
+/**
+ * Create a new instance of a root item.
+ *
+ * @param parent the TableTree that contains this root item
+ * @param style the bitwise OR'ing of widget styles
+ */
+public TableTreeItem(TableTree parent, int style) {
+ this (parent, style, parent.getItemCount());
+}
+
+/**
+ * Create a new instance of a root item in the position
+ * indicated by the specified index.
+ *
+ * @param parent the TableTree that contains this root item
+ * @param style the bitwise OR'ing of widget styles
+ * @param index specifies the position of this item in the TableTree
+ * relative to other root items
+ */
+public TableTreeItem(TableTree parent, int style, int index) {
+ this (parent, null, style, index);
+}
+
+/**
+ * Create a new instance of a sub item.
+ *
+ * @param parent this item's parent in the hierarchy of TableTree items
+ * @param style the bitwise OR'ing of widget styles
+ */
+public TableTreeItem(TableTreeItem parent, int style) {
+ this (parent, style, parent.getItemCount());
+}
+
+/**
+ * Create a new instance of a sub item in the position
+ * indicated by the specified index.
+ *
+ * @param parent this item's parent in the hierarchy of TableTree items
+ * @param style the bitwise OR'ing of widget styles
+ * @param index specifies the position of this item in the TableTree
+ * relative to other children of the same parent
+ */
+public TableTreeItem(TableTreeItem parent, int style, int index) {
+ this (parent.getParent(), parent, style, index);
+}
+
+TableTreeItem(TableTree parent, TableTreeItem parentItem, int style, int index) {
+ super(parent, style);
+ this.parent = parent;
+ this.parentItem = parentItem;
+ if (parentItem == null) {
+
+ /* Root items are visible immediately */
+ int tableIndex = parent.addItem(this, index);
+ tableItem = new TableItem(parent.getTable(), style, tableIndex);
+ tableItem.setData(this);
+ addCheck();
+ /*
+ * Feature in the Table. The table uses the first image that
+ * is inserted into the table to size the table rows. If the
+ * user is allowed to insert the first image, this will cause
+ * the +/- images to be scaled. The fix is to insert a dummy
+ * image to force the size.
+ */
+ if (parent.sizeImage == null) {
+ int itemHeight = parent.getItemHeight();
+ parent.sizeImage = new Image(null, itemHeight, itemHeight);
+ GC gc = new GC (parent.sizeImage);
+ gc.setBackground(parent.getBackground());
+ gc.fillRectangle(0, 0, itemHeight, itemHeight);
+ gc.dispose();
+ tableItem.setImage(0, parent.sizeImage);
+ }
+ } else {
+ parentItem.addItem(this, index);
+ }
+}
+void addCheck() {
+ Table table = parent.getTable();
+ if ((table.getStyle() & SWT.CHECK) == 0) return;
+ tableItem.setChecked(checked);
+}
+void addItem(TableTreeItem item, int index) {
+ if (item == null) throw new SWTError(SWT.ERROR_NULL_ARGUMENT);
+ if (index < 0 || index > items.length) throw new SWTError(SWT.ERROR_INVALID_ARGUMENT);
+
+ /* Now that item has a sub-node it must indicate that it can be expanded */
+ if (items.length == 0 && index == 0) {
+ if (tableItem != null) {
+ Image image = expanded ? parent.getMinusImage() : parent.getPlusImage();
+ tableItem.setImage(0, image);
+ }
+ }
+
+ /* Put the item in the items list */
+ TableTreeItem[] newItems = new TableTreeItem[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 (expanded) item.setVisible(true);
+}
+
+/**
+ * Gets the widget bounds at the specified index.
+ * <p>
+ * @return the widget bounds at the specified index
+ *
+ * @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 Rectangle getBounds (int index) {
+ if (tableItem != null) {
+ return tableItem.getBounds(index);
+ } else {
+ return new Rectangle(0, 0, 0, 0);
+ }
+}
+/**
+* Gets the checked state.
+* <p>
+* @return the item checked 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 getChecked () {
+ if (tableItem == null) {
+ return checked;
+ }
+ return tableItem.getChecked();
+}
+
+/**
+ * Gets the Display.
+ * <p>
+ * This method gets the Display that is associated
+ * with the widget.
+ *
+ * @return the widget data
+ *
+ * @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 Display getDisplay () {
+ TableTree parent = this.parent;
+ if (parent == null) throw new SWTError (SWT.ERROR_WIDGET_DISPOSED);
+ return parent.getDisplay ();
+}
+
+/**
+ * Gets the expanded state of the widget.
+ * <p>
+ * @return a boolean that is the expanded state of the widget
+ */
+public boolean getExpanded () {
+ return expanded;
+}
+
+/**
+ * Gets the first image.
+ * <p>
+ * The image in column 0 is reserved for the [+] and [-]
+ * images of the tree, therefore getImage(0) will return null.
+ *
+ * @return the image at index 0
+ */
+public Image getImage () {
+ return getImage(0);
+}
+
+/**
+ * Gets the image at the specified index.
+ * <p>
+ * Indexing is zero based. The image can be null.
+ * The image in column 0 is reserved for the [+] and [-]
+ * images of the tree, therefore getImage(0) will return null.
+ * Return null if the index is out of range.
+ *
+ * @param index the index of the image
+ * @return the image at the specified index or null
+ */
+public Image getImage (int index) {
+ if (0 < index && index < images.length) return images[index];
+ return null;
+}
+
+int getIndent() {
+ if (parentItem == null) return 0;
+ return parentItem.getIndent() + 1;
+}
+
+/**
+ * Gets the number of sub items.
+ * <p>
+ * @return the number of sub items
+ */
+public int getItemCount () {
+ return items.length;
+}
+
+/**
+ * Gets the sub items.
+ * <p>
+ * @return the sub items
+ */
+public TableTreeItem[] getItems () {
+ TableTreeItem[] newItems = new TableTreeItem[items.length];
+ System.arraycopy(items, 0, newItems, 0, items.length);
+ return newItems;
+}
+
+TableTreeItem getItem(TableItem tableItem) {
+ if (tableItem == null) return null;
+ if (this.tableItem == tableItem) return this;
+ for (int i = 0; i < items.length; i++) {
+ TableTreeItem item = items[i].getItem(tableItem);
+ if (item != null) return item;
+ }
+ return null;
+}
+
+/**
+ * Gets the parent.
+ * <p>
+ * @return the parent
+ */
+public TableTree getParent () {
+ return parent;
+}
+
+/**
+ * Gets the parent item.
+ * <p>
+ * @return the parent item.
+ */
+public TableTreeItem getParentItem () {
+ return parentItem;
+}
+
+/**
+ * Gets the first item text.
+ * <p>
+ * @return the item text at index 0, which can be null
+ *
+ * @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_CANNOT_GET_TEXT when the operation fails</li>
+ * </ul>
+ */
+public String getText () {
+ return getText(0);
+}
+
+/**
+ * Gets the item text at the specified 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 text at the specified index, which can be null
+ */
+public String getText(int index) {
+ if (0 <= index && index < texts.length) return texts[index];
+ return null;
+}
+
+boolean getVisible () {
+ return tableItem != null;
+}
+
+/**
+ * Gets the index of the specified item.
+ *
+ * <p>The widget 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. This index is relative to the parent only.
+ *
+ * @param item the search item
+ * @return the index of the item or -1 if the item is not found
+ *
+ */
+public int indexOf (TableTreeItem item) {
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] == item) return i;
+ }
+ return -1;
+}
+
+int expandedIndexOf (TableTreeItem item) {
+ int index = 0;
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] == item) return index;
+ if (items[i].expanded) index += items[i].visibleChildrenCount ();
+ index++;
+ }
+ return -1;
+}
+
+int visibleChildrenCount () {
+ int count = 0;
+ for (int i = 0; i < items.length; i++) {
+ if (items[i].getVisible ()) {
+ count += 1 + items[i].visibleChildrenCount ();
+ }
+ }
+ return count;
+}
+
+public void dispose () {
+ if (isDisposed()) return;
+ for (int i = items.length - 1; i >= 0; i--) {
+ items[i].dispose();
+ }
+ super.dispose();
+ if (!parent.inDispose) {
+ if (parentItem != null) {
+ parentItem.removeItem(this);
+ } else {
+ parent.removeItem(this);
+ }
+ if (tableItem != null) tableItem.dispose();
+ }
+ items = null;
+ parentItem = null;
+ parent = null;
+ images = null;
+ texts = null;
+ tableItem = null;
+}
+
+void removeItem(TableTreeItem item) {
+ int index = 0;
+ while (index < items.length && items[index] != item) index++;
+ if (index == items.length) return;
+ TableTreeItem[] newItems = new TableTreeItem[items.length - 1];
+ System.arraycopy(items, 0, newItems, 0, index);
+ System.arraycopy(items, index + 1, newItems, index, items.length - index - 1);
+ items = newItems;
+ if (items.length == 0) {
+ if (tableItem != null) tableItem.setImage(0, null);
+ }
+}
+
+/**
+* Sets the checked state.
+* <p>
+* @param checked the new checked 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 setChecked (boolean checked) {
+ if (tableItem != null) {
+ tableItem.setChecked(checked);
+ }
+ this.checked = checked;
+}
+/**
+ * Sets the expanded state.
+ * <p>
+ * @param expanded the new expanded 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 setExpanded (boolean expanded) {
+ if (items.length == 0) return;
+ this.expanded = expanded;
+ if (tableItem == null) return;
+ parent.setRedraw(false);
+ for (int i = 0; i < items.length; i++) {
+ items[i].setVisible(expanded);
+ }
+ Image image = expanded ? parent.getMinusImage() : parent.getPlusImage();
+ tableItem.setImage(0, image);
+ parent.setRedraw(true);
+}
+
+/**
+ * Sets the image at an index.
+ * <p>
+ * The image can be null.
+ * The image in column 0 is reserved for the [+] and [-]
+ * images of the tree, therefore do nothing if index is 0.
+ *
+ * @param image the new image or null
+ *
+ * @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 setImage (int index, Image image) {
+ int columnCount = Math.max(parent.getTable().getColumnCount(), 1);
+ if (index <= 0 || index >= columnCount) return;
+ if (images.length < columnCount) {
+ Image[] newImages = new Image[columnCount];
+ System.arraycopy(images, 0, newImages, 0, images.length);
+ images = newImages;
+ }
+ images[index] = image;
+ if (tableItem != null) tableItem.setImage(index, image);
+}
+
+/**
+ * Sets the first image.
+ * <p>
+ * The image can be null.
+ * The image in column 0 is reserved for the [+] and [-]
+ * images of the tree, therefore do nothing.
+ *
+ * @param image the new image or null
+ */
+public void setImage (Image image) {
+ setImage(0, image);
+}
+
+/**
+ * Sets the widget text.
+ * <p>
+ *
+ * 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
+ *
+ * @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 string is null</li>
+ * </ul>
+ */
+public void setText(int index, String text) {
+ int columnCount = Math.max(parent.getTable().getColumnCount(), 1);
+ if (index < 0 || index >= columnCount) return;
+ if (texts.length < columnCount) {
+ String[] newTexts = new String[columnCount];
+ System.arraycopy(texts, 0, newTexts, 0, texts.length);
+ texts = newTexts;
+ }
+ texts[index] = text;
+ if (tableItem != null) tableItem.setText(index, text);
+}
+
+/**
+ * Sets the widget text.
+ * <p>
+ *
+ * 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
+ *
+ * @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 string is null</li>
+ * </ul>
+ */
+public void setText (String string) {
+ setText(0, string);
+}
+
+void setVisible (boolean show) {
+ if (parentItem == null) return; // this is a root and can not be toggled between visible and hidden
+ if (getVisible() == show) return;
+
+ if (show) {
+ if (!parentItem.getVisible()) return; // parentItem must already be visible
+ // create underlying table item and set data in table item to stored data
+ Table table = parent.getTable();
+ int parentIndex = table.indexOf(parentItem.tableItem);
+ int index = parentItem.expandedIndexOf(this) + parentIndex + 1;
+ if (index < 0) return;
+ tableItem = new TableItem(table, getStyle(), index);
+ tableItem.setData(this);
+ tableItem.setImageIndent(getIndent());
+ addCheck();
+
+ // restore fields to item
+ // ignore any images in the first column
+ int columnCount = Math.max(table.getColumnCount(), 1);
+ for (int i = 0; i < columnCount; i++) {
+ if (i < texts.length && texts[i] != null) setText(i, texts[i]);
+ if (i < images.length && images[i] != null) setImage(i, images[i]);
+ }
+
+ // display the children and the appropriate [+]/[-] symbol as required
+ if (items.length != 0) {
+ if (expanded) {
+ tableItem.setImage(0, parent.getMinusImage());
+ for (int i = 0, length = items.length; i < length; i++) {
+ items[i].setVisible(true);
+ }
+ } else {
+ tableItem.setImage(0, parent.getPlusImage());
+ }
+ }
+
+ } else {
+
+ for (int i = 0, length = items.length; i < length; i++) {
+ items[i].setVisible(false);
+ }
+ // remove row from table
+ tableItem.dispose();
+ tableItem = null;
+ }
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangeListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangeListener.java
new file mode 100644
index 0000000000..0ec851abe5
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangeListener.java
@@ -0,0 +1,43 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import java.util.*;
+
+/**
+ * The StyledText widget implements this listener to receive
+ * notifications when changes to the model occur.
+ * It is not intended for use by users of the StyledText widget
+ * or implementors of StyledTextContent. Users should listen to
+ * the ModifyEvent or ExtendedModifyEvent that is sent by the StyledText
+ * widget to receive text change notifications.
+ */
+public interface TextChangeListener extends EventListener {
+
+/**
+ * @param event.start replace start offset (input)
+ * @param event.newText text that is going to be inserted or empty String
+ * if no text will be inserted (input)
+ * @param event.replaceCharCount length of text that is going to be
+ * replaced (input)
+ * @param event.newCharCount length of text that is going to be inserted
+ * (input)
+ * @param event.replaceLineCount number of lines that are going to be
+ * replaced (input)
+ * @param event.newLineCount number of new lines that are going to be
+ * inserted (input)
+ */
+public void textChanging(TextChangingEvent event);
+
+/**
+ */
+public void textChanged(TextChangedEvent event);
+
+/**
+ */
+public void textSet(TextChangedEvent event);
+}
+
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangedEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangedEvent.java
new file mode 100644
index 0000000000..5a7648cd8b
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangedEvent.java
@@ -0,0 +1,23 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.*;
+
+/**
+ * This event is sent by the StyledTextContent implementor when a change to
+ * the text occurs.
+ */
+public class TextChangedEvent extends TypedEvent {
+/**
+ * Create the TextChangedEvent to be used by the StyledTextContent implementor.
+ * <p>
+ *
+ * @param source the object that will be sending the TextChangedEvent, cannot be null
+ */
+public TextChangedEvent(StyledTextContent source) {
+ super(source);
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangingEvent.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangingEvent.java
new file mode 100644
index 0000000000..b334ead550
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TextChangingEvent.java
@@ -0,0 +1,41 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.*;
+
+/**
+ * This event is sent by the StyledTextContent implementor when a change to
+ * the text is about to occur.
+ */
+public class TextChangingEvent extends TypedEvent {
+ public int start; // replace start offset
+ public String newText; // text that is going to be inserted or empty
+ // String if no text will be inserted
+ public int replaceCharCount; // length of text that is going to be replaced
+ public int newCharCount; // length of text that is going to be inserted
+ public int replaceLineCount; // number of lines that are going to be replaced
+ public int newLineCount; // number of new lines that are going to be inserted
+
+/**
+ * Create the TextChangedEvent to be used by the StyledTextContent implementor.
+ * <p>
+ *
+ * @param source the object that will be sending the TextChangedEvent, cannot be null
+ */
+public TextChangingEvent(StyledTextContent source) {
+ super(source);
+}
+TextChangingEvent(StyledTextContent source, StyledTextEvent e) {
+ super(source);
+ start = e.start;
+ replaceCharCount = e.replaceCharCount;
+ newCharCount = e.newCharCount;
+ replaceLineCount = e.replaceLineCount;
+ newLineCount = e.newLineCount;
+ newText = e.text;
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TreeEditor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TreeEditor.java
new file mode 100644
index 0000000000..9200f0e789
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/TreeEditor.java
@@ -0,0 +1,163 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.events.*;
+
+/**
+*
+* A TreeEditor is a manager for a Control that appears above a cell in a Tree and tracks with the
+* moving and resizing of that cell. It can be used to display a text widget above a cell
+* in a Tree so that the user can edit the contents of that cell. It can also be used to display
+* a button that can launch a dialog for modifying the contents of the associated cell.
+*
+* <p> Here is an example of using a TreeEditor:
+* <code><pre>
+* Tree tree = new Tree(parent, SWT.FULL_SELECTION);
+* TreeEditor editor = new TreeEditor (tree);
+* tree.addSelectionListener (new SelectionAdapter() {
+* public void widgetSelected(SelectionEvent e) {}
+*
+* // Clean up any previous editor control
+* Control oldEditor = editor.getEditor();
+* if (oldEditor != null)
+* oldEditor.dispose();
+*
+* // Identify the selected row
+* int index = tree.getSelectionIndex ();
+* if (index == -1) return;
+* TreeItem item = tree.getItem (index);
+*
+* // The control that will be the editor must be a child of the Tree
+* Text text = new Text(tree, SWT.NONE);
+*
+* //The text editor must have the same size as the cell and must
+* //not be any smaller than 50 pixels.
+* editor.horizontalAlignment = SWT.LEFT;
+* editor.grabHorizontal = true;
+* editor.minimumWidth = 50;
+*
+* // Open the text editor on the selected row.
+* editor.setEditor (text, item);
+*
+* // Assign focus to the text control
+* text.setFocus ();
+* }
+* });
+* </pre></code>
+*/
+public class TreeEditor extends ControlEditor {
+ Tree tree;
+ TreeItem item;
+ TreeListener treeListener;
+/**
+* Creates a TreeEditor for the specified Tree.
+*
+* @param tree the Tree Control above which this editor will be displayed
+*
+*/
+public TreeEditor (Tree tree) {
+ super(tree);
+ this.tree = tree;
+ treeListener = new TreeAdapter () {
+ final Runnable runnable = new Runnable() {
+ public void run() {
+ if (TreeEditor.this.tree.isDisposed() || editor == null) return;
+ resize();
+ editor.setVisible(true);
+ }
+ };
+ public void treeCollapsed(TreeEvent e) {
+ if (editor == null) return;
+ editor.setVisible(false);
+ Display display = TreeEditor.this.tree.getDisplay();
+ display.asyncExec(runnable);
+ }
+ public void treeExpanded(TreeEvent e) {
+ if (editor == null) return;
+ editor.setVisible(false);
+ Display display = TreeEditor.this.tree.getDisplay();
+ display.asyncExec(runnable);
+ }
+ };
+ tree.addTreeListener(treeListener);
+}
+Rectangle computeBounds () {
+ if (item == null || item.isDisposed()) return new Rectangle(0, 0, 0, 0);
+
+ Rectangle cell = item.getBounds();
+ Rectangle area = tree.getClientArea();
+ if (cell.x < area.x + area.width) {
+ if (cell.x + cell.width > area.x + area.width) {
+ cell.width = area.x + area.width - cell.x;
+ }
+ }
+ Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, cell.height);
+
+ if (grabHorizontal) {
+ editorRect.width = Math.max(area.x + area.width - cell.x, minimumWidth);
+ }
+
+ if (horizontalAlignment == SWT.RIGHT) {
+ editorRect.x = Math.max(cell.x, cell.x + cell.width - editorRect.width);
+ } else if (horizontalAlignment == SWT.LEFT) {
+ // do nothing - cell.x is the right answer
+ } else { // default is CENTER
+ editorRect.x = Math.max(cell.x, cell.x + (cell.width - editorRect.width)/2);
+ }
+
+ return editorRect;
+}
+/**
+ * Removes all associations between the TreeEditor and the cell in the tree. The
+ * tree and the editor Control are <b>not</b> disposed.
+ */
+public void dispose () {
+ if (treeListener != null)
+ tree.removeTreeListener(treeListener);
+ treeListener = null;
+ tree = null;
+ item = null;
+ super.dispose();
+}
+/**
+* Returns the TreeItem for the row of the cell being tracked by this editor.
+*
+* @return the TreeItem for the row of the cell being tracked by this editor
+*/
+public TreeItem getItem () {
+ return item;
+}
+public void setItem (TreeItem item) {
+ this.item = item;
+}
+
+/**
+* Specify the Control that is to be displayed and the cell in the tree that it is to be positioned above.
+*
+* <p>Note: The Control provided as the editor <b>must</b> be created with its parent being the Tree control
+* specified in the TreeEditor constructor.
+*
+* @param editor the Control that is displayed above the cell being edited
+* @param item the TreeItem for the row of the cell being tracked by this editor
+* @param column the zero based index of the column of the cell being tracked by this editor
+*/
+public void setEditor (Control editor, TreeItem item) {
+ setItem (item);
+ super.setEditor (editor);
+}
+public void setEditor (Control editor) {
+ TreeItem item = null;
+ if (tree.getItemCount() != 0) {
+ item = tree.getItems()[0];
+ }
+ this.setEditor(editor, item);
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/VerifyKeyListener.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/VerifyKeyListener.java
new file mode 100644
index 0000000000..930531a984
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/VerifyKeyListener.java
@@ -0,0 +1,18 @@
+package org.eclipse.swt.custom;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.events.*;
+import java.util.*;
+
+public interface VerifyKeyListener extends EventListener {
+/**
+ * @param event.character the character that was typed (input)
+ * @param event.keyCode the key code that was typed (input)
+ * @param event.stateMask the state of the keyboard (input)
+ * @param event.doit processed or not (output)
+ */
+public void verifyKey (VerifyEvent event);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ViewForm.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ViewForm.java
new file mode 100644
index 0000000000..6529b0109d
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/ViewForm.java
@@ -0,0 +1,491 @@
+package org.eclipse.swt.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.events.*;
+
+public class ViewForm extends Composite {
+
+ /**
+ * marginWidth specifies the number of pixels of horizontal margin
+ * that will be placed along the left and right edges of the form.
+ *
+ * The default value is 0.
+ */
+ public int marginWidth = 0;
+ /**
+ * marginHeight specifies the number of pixels of vertical margin
+ * that will be placed along the top and bottom edges of the form.
+ *
+ * The default value is 0.
+ */
+ public int marginHeight = 0;
+
+ /**
+ * Color of innermost line of drop shadow border.
+ */
+ public static RGB borderInsideRGB = new RGB (132, 130, 132);
+ /**
+ * Color of middle line of drop shadow border.
+ */
+ public static RGB borderMiddleRGB = new RGB (143, 141, 138);
+ /**
+ * Color of outermost line of drop shadow border.
+ */
+ public static RGB borderOutsideRGB = new RGB (171, 168, 165);
+
+ // SWT widgets
+ private Control topLeft;
+ private Control topCenter;
+ private Control topRight;
+ private Control content;
+
+ // Configuration and state info
+ private boolean separateTopCenter = false;
+ private int drawLine1 = -1;
+ private int drawLine2 = -1;
+
+ private boolean showBorder = false;
+
+ private int BORDER_TOP = 0;
+ private int BORDER_BOTTOM = 0;
+ private int BORDER_LEFT = 0;
+ private int BORDER_RIGHT = 0;
+
+ private Color borderColor1;
+ private Color borderColor2;
+ private Color borderColor3;
+
+ private Rectangle oldArea;
+ private static final int OFFSCREEN = -200;
+/**
+* Creates a ViewForm.
+* <p>
+* This method creates a child widget using style bits
+* to select a particular look or set of properties.
+*
+* @param parent a composite widget (cannot be null)
+* @param style the bitwise OR'ing of widget styles
+*
+* @exception SWTError <ul>
+* <li> ERROR_THREAD_INVALID_ACCESS when called from the wrong thread </li>
+* <li> ERROR_ERROR_NULL_ARGUMENT when the parent is null </li>
+* </ul>
+*/
+public ViewForm(Composite parent, int style) {
+ super(parent, checkStyle(style));
+
+ borderColor1 = new Color(getDisplay(), borderInsideRGB);
+ borderColor2 = new Color(getDisplay(), borderMiddleRGB);
+ borderColor3 = new Color(getDisplay(), borderOutsideRGB);
+ setBorderVisible((style & SWT.BORDER) != 0);
+
+ addPaintListener(new PaintListener() {
+ public void paintControl(PaintEvent event) {
+ onPaint(event.gc);
+ }
+ });
+ addControlListener(new ControlAdapter(){
+ public void controlResized(ControlEvent e) {
+ onResize();
+ }
+ });
+
+ addListener(SWT.Dispose, new Listener() {
+ public void handleEvent(Event e) {
+ onDispose();
+ }
+ });
+}
+/**
+ * Check the style bits to ensure that no invalid styles are applied.
+ * @private
+ */
+private static int checkStyle (int style) {
+ int mask = SWT.FLAT;
+ return style & mask | SWT.NO_REDRAW_RESIZE;
+}
+public Point computeSize(int wHint, int hHint, boolean changed) {
+ // size of title bar area
+ Point leftSize = new Point(0, 0);
+ if (topLeft != null) {
+ leftSize = topLeft.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ }
+ Point centerSize = new Point(0, 0);
+ if (topCenter != null) {
+ centerSize = topCenter.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ }
+ Point rightSize = new Point(0, 0);
+ if (topRight != null) {
+ rightSize = topRight.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ }
+ Point size = new Point(0, 0);
+ // calculate width of title bar
+ if (separateTopCenter) {
+ size.x = leftSize.x + rightSize.x;
+ size.x = Math.max(centerSize.x, size.x);
+ size.y = Math.max(leftSize.y, rightSize.y);
+ if (topCenter != null){
+ size.y += centerSize.y;
+ }
+ } else {
+ size.x = leftSize.x + centerSize.x + rightSize.x;
+ size.y = Math.max(leftSize.y, Math.max(centerSize.y, rightSize.y));
+ }
+
+ if (content != null) {
+ Point contentSize = new Point(0, 0);
+ contentSize = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ size.x = Math.max (size.x, contentSize.x);
+ size.y += contentSize.y;
+ }
+
+ size.x += 2 * marginWidth + BORDER_LEFT + BORDER_RIGHT;
+ size.y += 2 * marginHeight + BORDER_TOP + BORDER_BOTTOM;
+
+ return size;
+}
+public Rectangle getClientArea() {
+ Rectangle clientArea = super.getClientArea();
+ clientArea.x += BORDER_LEFT;
+ clientArea.y += BORDER_TOP;
+ clientArea.width -= BORDER_LEFT + BORDER_RIGHT;
+ clientArea.height -= BORDER_TOP + BORDER_BOTTOM;
+ return clientArea;
+}
+/**
+* Returns the content area.
+*/
+public Control getContent() {
+ return content;
+}
+/**
+* Returns Control that appears in the top center of the pane.
+* Typically this is a toolbar.
+*/
+public Control getTopCenter() {
+ return topCenter;
+}
+/**
+* Returns the Control that appears in the top left corner of the pane.
+* Typically this is a label such as CLabel.
+*/
+public Control getTopLeft() {
+ return topLeft;
+}
+/**
+* Returns the control in the top right corner of the pane.
+* Typically this is a Close button or a composite with a Menu and Close button.
+*/
+public Control getTopRight() {
+ return topRight;
+}
+public void layout (boolean changed) {
+ Rectangle rect = getClientArea();
+
+ drawLine1 = -1;
+ drawLine2 = -1;
+
+ Point leftSize = new Point(0, 0);
+ if (topLeft != null && !topLeft.isDisposed()) {
+ leftSize = topLeft.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ }
+ Point centerSize = new Point(0, 0);
+ if (topCenter != null && !topCenter.isDisposed()) {
+ centerSize = topCenter.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ }
+ Point rightSize = new Point(0, 0);
+ if (topRight != null && !topRight.isDisposed()) {
+ rightSize = topRight.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ }
+
+ int minTopWidth = leftSize.x + centerSize.x + rightSize.x + 2*marginWidth + 1; // +1 for highlight line
+ int height = rect.y + marginHeight;
+
+ boolean top = false;
+ if (separateTopCenter || minTopWidth > rect.width) {;
+ int topHeight = Math.max(rightSize.y, leftSize.y);
+ if (topRight != null && !topRight.isDisposed()) {
+ top = true;
+ topRight.setBounds(rect.x + rect.width - marginWidth - rightSize.x,
+ rect.y + 1 + marginHeight,
+ rightSize.x, topHeight);
+ height += 1 + topHeight; // +1 for highlight line
+ }
+ if (topLeft != null && !topLeft.isDisposed()) {
+ top = true;
+ leftSize = topLeft.computeSize(rect.width - 2* marginWidth - rightSize.x - 1, SWT.DEFAULT);
+ topLeft.setBounds(rect.x + 1 + marginWidth,
+ rect.y + 1 + marginHeight,
+ leftSize.x, topHeight);
+ height = Math.max(height, rect.y + marginHeight + 1 + topHeight); // +1 for highlight line
+ }
+ if (topCenter != null && !topCenter.isDisposed()) {
+ top = true;
+ if (height > rect.y + marginHeight) {
+ drawLine1 = height;
+ height += 1; // +1 for divider line
+ }
+ centerSize = topCenter.computeSize(rect.width - 2 * marginWidth, SWT.DEFAULT);
+ topCenter.setBounds(rect.x + rect.width - marginWidth - centerSize.x,
+ height,
+ centerSize.x, centerSize.y);
+ height += centerSize.y;
+
+ }
+ } else {
+ int topHeight = Math.max(rightSize.y, Math.max(centerSize.y, leftSize.y));
+ if (topRight != null && !topRight.isDisposed()) {
+ top = true;
+ topRight.setBounds(rect.x + rect.width - marginWidth - rightSize.x,
+ rect.y + marginHeight + 1, // +1 for highlight line
+ rightSize.x, topHeight);
+ height += 1 + topHeight; // +1 for highlight line
+ }
+ if (topCenter != null && !topCenter.isDisposed()) {
+ top = true;
+ topCenter.setBounds(rect.x + rect.width - marginWidth - rightSize.x - centerSize.x,
+ rect.y + marginHeight + 1, // +1 for highlight line
+ centerSize.x, topHeight);
+ height = Math.max(height, rect.y + marginHeight + 1 + topHeight); // +1 for highlight line
+ }
+ if (topLeft != null && !topLeft.isDisposed()) {
+ top = true;
+ leftSize = topLeft.computeSize(rect.width - 2 * marginWidth - rightSize.x - centerSize.x - 1, topHeight);
+ topLeft.setBounds(rect.x + marginWidth + 1, // +1 for highlight line
+ rect.y + marginHeight + 1, // +1 for highlight line
+ leftSize.x, topHeight);
+ height = Math.max(height, rect.y + marginHeight + 1 + topHeight); // +1 for highlight line
+ }
+ }
+
+ if (content != null && !content.isDisposed()) {
+ if (top) {
+ drawLine2 = height;
+ height += 1; // +1 for divider line
+ }
+ content.setBounds(rect.x + marginWidth,
+ height,
+ rect.width - 2 * marginWidth,
+ rect.y + rect.height - height - marginHeight);
+ }
+}
+private void onDispose() {
+ if (borderColor1 != null) {
+ borderColor1.dispose();
+ }
+ borderColor1 = null;
+
+ if (borderColor2 != null) {
+ borderColor2.dispose();
+ }
+ borderColor2 = null;
+
+ if (borderColor3 != null) {
+ borderColor3.dispose();
+ }
+ borderColor3 = null;
+}
+/**
+* Draws the focus border.
+*/
+private void onPaint(GC gc) {
+ Rectangle d = super.getClientArea();
+
+ if (showBorder) {
+ if ((getStyle() & SWT.FLAT) !=0) {
+ gc.setForeground(borderColor1);
+ gc.drawRectangle(d.x, d.y, d.x + d.width - 1, d.y + d.height - 1);
+ } else {
+ gc.setForeground(borderColor1);
+ gc.drawRectangle(d.x, d.y, d.x + d.width - 3, d.y + d.height - 3);
+
+ gc.setForeground(borderColor2);
+ gc.drawLine(d.x + 1, d.y + d.height - 2, d.x + d.width - 1, d.y + d.height - 2);
+ gc.drawLine(d.x + d.width - 2, d.y + 1, d.x + d.width - 2, d.y + d.height - 1);
+
+ gc.setForeground(borderColor3);
+ gc.drawLine(d.x + 2, d.y + d.height - 1, d.x + d.width - 2, d.y + d.height - 1);
+ gc.drawLine(d.x + d.width - 1, d.y + 2, d.x + d.width - 1, d.y + d.height - 2);
+ }
+ }
+
+ if (drawLine1 != -1) {
+ // top seperator line
+ gc.setForeground(borderColor1);
+ gc.drawLine(d.x + BORDER_LEFT, drawLine1, d.x + d.width - BORDER_RIGHT, drawLine1);
+ }
+ if (drawLine2 != -1) {
+ // content separator line
+ gc.setForeground(borderColor1);
+ gc.drawLine(d.x + BORDER_LEFT, drawLine2, d.x + d.width - BORDER_RIGHT, drawLine2);
+ }
+ // highlight on top
+ int y = drawLine1;
+ if (y == -1){
+ y = drawLine2;
+ }
+ if (y != -1) {
+ gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
+ gc.drawLine(d.x + BORDER_LEFT + marginWidth, d.y + BORDER_TOP + marginHeight,
+ d.x + BORDER_LEFT + marginWidth, y - 1);
+ gc.drawLine(d.x + BORDER_LEFT + marginWidth, d.y + BORDER_TOP + marginHeight,
+ d.x + d.width - BORDER_RIGHT - marginWidth - 1, d.y + BORDER_TOP + marginHeight);
+ }
+
+ gc.setForeground(getForeground());
+}
+private void onResize() {
+ layout();
+
+ Rectangle area = super.getClientArea();
+ if (oldArea == null || oldArea.width == 0 || oldArea.height == 0) {
+ redraw();
+ } else {
+ int width = 0;
+ if (oldArea.width < area.width) {
+ width = area.width - oldArea.width + BORDER_RIGHT;
+ } else if (oldArea.width > area.width) {
+ width = BORDER_RIGHT;
+ }
+ redraw(area.x + area.width - width, area.y, width, area.height, false);
+
+ int height = 0;
+ if (oldArea.height < area.height) {
+ height = area.height - oldArea.height + BORDER_BOTTOM;
+ }
+ if (oldArea.height > area.height) {
+ height = BORDER_BOTTOM;
+ }
+ redraw(area.x, area.y + area.height - height, area.width, height, false);
+ }
+ oldArea = area;
+}
+/**
+* Sets the content.
+* Setting the content to null will remove it from
+* the pane - however, the creator of the content must dispose of the content.
+*/
+public void setContent(Control content) {
+ if (content != null && content.getParent() != this) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (this.content != null && !this.content.isDisposed()) {
+ this.content.setBounds(OFFSCREEN, OFFSCREEN, 0, 0);
+ }
+ this.content = content;
+ layout();
+}
+
+/**
+* Set the widget font.
+* This will apply the font to the topLeft, topRight and topCenter widgets.
+*/
+public void setFont(Font f) {
+ super.setFont(f);
+ if (topLeft != null && !topLeft.isDisposed()) topLeft.setFont(f);
+ if (topCenter != null && !topCenter.isDisposed()) topCenter.setFont(f);
+ if (topRight != null && !topRight.isDisposed()) topRight.setFont(f);
+
+ layout();
+}
+/**
+ * Sets the layout which is associated with the receiver to be
+ * the argument which may be null.
+ * <p>
+ * Note : ViewForm does not use a layout class to size and position its children.
+ * </p>
+ *
+ * @param 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) {
+ return;
+}
+/**
+* Set the control that appears in the top center of the pane.
+* Typically this is a toolbar.
+* The topCenter is optional. Setting the topCenter to null will remove it from
+* the pane - however, the creator of the topCenter must dispose of the topCenter.
+*/
+public void setTopCenter(Control topCenter) {
+ if (topCenter != null && topCenter.getParent() != this) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (this.topCenter != null && !this.topCenter.isDisposed()) {
+ this.topCenter.setBounds(OFFSCREEN, OFFSCREEN, 0, 0);
+ }
+ this.topCenter = topCenter;
+ layout();
+}
+/**
+* Set the control that appears in the top left corner of the pane.
+* Typically this is a label such as CLabel.
+* The topLeft is optional. Setting the top left control to null will remove it from
+* the pane - however, the creator of the control must dispose of the control.
+*/
+public void setTopLeft(Control c) {
+ if (c != null && c.getParent() != this) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (this.topLeft != null && !this.topLeft.isDisposed()) {
+ this.topLeft.setBounds(OFFSCREEN, OFFSCREEN, 0, 0);
+ }
+ this.topLeft = c;
+ layout();
+}
+/**
+* Set the control that appears in the top right corner of the pane.
+* Typically this is a Close button or a composite with a Menu and Close button.
+* The topRight is optional. Setting the top right control to null will remove it from
+* the pane - however, the creator of the control must dispose of the control.
+*/
+public void setTopRight(Control c) {
+ if (c != null && c.getParent() != this) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ if (this.topRight != null && !this.topRight.isDisposed()) {
+ this.topRight.setBounds(OFFSCREEN, OFFSCREEN, 0, 0);
+ }
+ this.topRight = c;
+ layout();
+}
+public void setBorderVisible(boolean show) {
+ if (showBorder == show) return;
+
+ showBorder = show;
+ if (showBorder) {
+ if ((getStyle() & SWT.FLAT)!= 0) {
+ BORDER_LEFT = BORDER_TOP = BORDER_RIGHT = BORDER_BOTTOM = 1;
+ } else {
+ BORDER_LEFT = BORDER_TOP = 1;
+ BORDER_RIGHT = BORDER_BOTTOM = 3;
+ }
+ } else {
+ BORDER_BOTTOM = BORDER_TOP = BORDER_LEFT = BORDER_RIGHT = 0;
+ }
+
+ layout();
+ redraw();
+}
+/**
+* If true, the topCenter will always appear on a separate line by itself, otherwise the
+* topCenter will appear in the top row if there is room and will be moved to the second row if
+* required.
+*/
+public void setTopCenterSeparate(boolean show) {
+ separateTopCenter = show;
+ layout();
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/close.gif b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/close.gif
new file mode 100644
index 0000000000..5d99e83d59
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/close.gif
Binary files differ
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/left.gif b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/left.gif
new file mode 100644
index 0000000000..d805f3aadf
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/left.gif
Binary files differ
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/leftDisabled.gif b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/leftDisabled.gif
new file mode 100644
index 0000000000..6317a41635
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/leftDisabled.gif
Binary files differ
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/package.html b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/package.html
new file mode 100644
index 0000000000..cb946ce558
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/package.html
@@ -0,0 +1,14 @@
+ <html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="Author" content="IBM">
+ <title>Package-level Javadoc</title>
+</head>
+<body>
+SWT Custom widgets.
+<h2>
+Package Specification</h2>
+This package contains the custom widgets which were written to provide the
+standard look and feel of the Eclipse platform.
+</body>
+</html>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/right.gif b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/right.gif
new file mode 100644
index 0000000000..8333e9a940
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/right.gif
Binary files differ
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/rightDisabled.gif b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/rightDisabled.gif
new file mode 100644
index 0000000000..231e6c81ff
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common_j2se/org/eclipse/swt/custom/rightDisabled.gif
Binary files differ
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Clipboard.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Clipboard.java
index 424a799cc3..4bf7a126ff 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Clipboard.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Clipboard.java
@@ -95,6 +95,7 @@ public Object getContents(Transfer transfer) {
// Pass data to transfer agent for conversion to a Java Object
// Memory is allocated here to emulate the way Drag and Drop transfers data.
TransferData transferData = new TransferData();
+ /* Use the character encoding for the default locale */
byte[] bName = Converter.wcsToMbcs (null, type, false);
transferData.type = OS.XmInternAtom (xDisplay, bName, false);
transferData.pValue = OS.XtMalloc(data.length);
@@ -145,6 +146,7 @@ public void setContents(Object[] data, Transfer[] transferAgents){
for (int j = 0; j < names.length; j++) {
TransferData transferData = new TransferData();
+ /* Use the character encoding for the default locale */
byte[] bName = Converter.wcsToMbcs (null, names[j], false);
transferData.type = OS.XmInternAtom (xDisplay, bName, false);
transferAgents[i].javaToNative(data[i], transferData);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Transfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Transfer.java
index 9de9048d0e..adfd307815 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Transfer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Transfer.java
@@ -54,6 +54,7 @@ abstract protected Object nativeToJava(TransferData transferData);
public static int registerType(String formatName){
int xDisplay = Display.getDefault().xDisplay; // using default because we don't have a particular widget
+ /* Use the character encoding for the default locale */
byte[] bName = Converter.wcsToMbcs (null, formatName, false);
int atom = OS.XmInternAtom (xDisplay, bName, false);
return atom;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/ByteArrayTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/ByteArrayTransfer.java
index 63f1eb6159..0786eb51db 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/ByteArrayTransfer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/ByteArrayTransfer.java
@@ -30,19 +30,19 @@ protected void javaToNative (Object object, TransferData transferData){
return;
}
byte[] buffer = (byte[])object;
-// transferData.pValue = OS.XtMalloc(buffer.length + 1);
-// OS.memmove(transferData.pValue, buffer, buffer.length);
+ transferData.pData = OS.malloc(buffer.length);
+ OS.memmove(transferData.pData, buffer, buffer.length);
transferData.length = buffer.length;
- transferData.format = 8;
transferData.result = 1;
}
protected Object nativeToJava(TransferData transferData){
- if (transferData.pValue == 0 || !(isSupportedType(transferData))) return null;
+ if (transferData.pData == 0 || !(isSupportedType(transferData))) return null;
- int size = transferData.format * transferData.length / 8;
+ int size = transferData.length;
+ if (size == 0) return null;
byte[] buffer = new byte[size];
-// OS.memmove(buffer, transferData.pValue, size);
+ OS.memmove(buffer, transferData.pData, size);
return buffer;
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/Clipboard.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/Clipboard.java
index bd8b75d483..217166c841 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/Clipboard.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/Clipboard.java
@@ -19,7 +19,6 @@ public class Clipboard {
private Display display;
private final int MAX_RETRIES = 10;
- private int shellHandle;
public Clipboard(Display display) {
@@ -34,11 +33,6 @@ public Clipboard(Display display) {
SWT.error(SWT.ERROR_THREAD_INVALID_ACCESS);
}
this.display = display;
-
-// int widgetClass = OS.TopLevelShellWidgetClass ();
-// shellHandle = OS.XtAppCreateShell (null, null, widgetClass, display.xDisplay, null, 0);
-// OS.XtSetMappedWhenManaged (shellHandle, false);
-// OS.XtRealizeWidget (shellHandle);
}
protected void checkSubclass () {
String name = getClass().getName ();
@@ -48,15 +42,92 @@ protected void checkSubclass () {
}
}
public void dispose () {
-// if (shellHandle != 0) OS.XtDestroyWidget (shellHandle);
-// shellHandle = 0;
display = null;
}
public Object getContents(Transfer transfer) {
if (display.isDisposed() ) return null;
- return null;
+
+ Object result = null;
+
+ int ig = OS.PhInputGroup(0);
+ int cbdata = OS.PhClipboardPasteStart((short)ig);
+ if (cbdata == 0) return result;
+ try {
+ String[] types = transfer.getTypeNames();
+ int[] ids = transfer.getTypeIds();
+ for (int i = 0; i < types.length; i++) {
+ byte[] type = Converter.wcsToMbcs(null, types[i], true);
+ int pClipHeader = OS.PhClipboardPasteType(cbdata, type);
+ if (pClipHeader != 0) {
+ PhClipHeader clipHeader = new PhClipHeader();
+ OS.memmove(clipHeader, pClipHeader, PhClipHeader.sizeof);
+ TransferData data = new TransferData();
+ data.pData = clipHeader.data;
+ data.length = clipHeader.length;
+ data.type = ids[i];
+ result = transfer.nativeToJava(data);
+ break;
+ }
+ }
+ } finally {
+ OS.PhClipboardPasteFinish(cbdata);
+ }
+
+ return result;
}
public void setContents(Object[] data, Transfer[] transferAgents){
+ if (display.isDisposed() ) return;
+
+ if (data == null) {
+ int ig = OS.PhInputGroup(0);
+ if (OS.PhClipboardCopy((short)ig, 0, null) != 0) {
+ DND.error(DND.ERROR_CANNOT_SET_CLIPBOARD);
+ }
+ return;
+ }
+ if (transferAgents == null || data.length != transferAgents.length) {
+ DND.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+
+ byte[] clips = new byte[0];
+ int count = 0;
+ for (int i = 0; i < transferAgents.length; i++) {
+ String[] names = transferAgents[i].getTypeNames();
+ int[] ids = transferAgents[i].getTypeIds();
+ for (int j = 0; j < names.length; j++) {
+ TransferData transferData = new TransferData();
+ transferData.type = ids[j];
+ transferAgents[i].javaToNative(data[i], transferData);
+ PhClipHeader clip = new PhClipHeader();
+ clip.data = transferData.pData;
+ clip.length = (short)transferData.length;
+ byte[] temp = Converter.wcsToMbcs(null, names[j], false);
+ byte[] type = new byte[8];
+ System.arraycopy(temp, 0, type, 0, Math.min(type.length, temp.length));
+ clip.type_0 = type[0];
+ clip.type_1 = type[1];
+ clip.type_2 = type[2];
+ clip.type_3 = type[3];
+ clip.type_4 = type[4];
+ clip.type_5 = type[5];
+ clip.type_6 = type[6];
+ clip.type_7 = type[7];
+ byte[] buffer = new byte[PhClipHeader.sizeof];
+ OS.memmove(buffer, clip, PhClipHeader.sizeof);
+ byte[] newClips = new byte[clips.length + buffer.length];
+ System.arraycopy(clips, 0, newClips, 0, clips.length);
+ System.arraycopy(buffer, 0, newClips, clips.length, buffer.length);
+ clips = newClips;
+ count++;
+ }
+ }
+
+ if (count > 0){
+ int ig = OS.PhInputGroup(0);
+ if (OS.PhClipboardCopy((short)ig, count, clips) != 0) {
+ DND.error(DND.ERROR_CANNOT_SET_CLIPBOARD);
+ }
+ }
}
/*
* Note: getAvailableTypeNames is a tool for writing a Transfer sub-class only. It should
@@ -64,31 +135,35 @@ public void setContents(Object[] data, Transfer[] transferAgents){
* information.
*/
public String[] getAvailableTypeNames() {
- int[] count = new int[1];
- int[] max_length = new int[1];
-// int xDisplay = OS.XtDisplay (shellHandle);
-// if (xDisplay == 0)
-// DND.error(SWT.ERROR_UNSPECIFIED);
-// int xWindow = OS.XtWindow (shellHandle);
-// if (xWindow == 0)
-// DND.error(SWT.ERROR_UNSPECIFIED);
-// if (OS.XmClipboardInquireCount(xDisplay, xWindow, count, max_length) != OS.XmClipboardSuccess)
-// DND.error(SWT.ERROR_UNSPECIFIED);
- String[] types = new String[count[0]];
-// for (int i = 0; i < count[0]; i++) {
-// byte[] buffer = new byte[max_length[0]];
-// int[] copied_length = new int[1];
-// int rc = OS.XmClipboardInquireFormat(xDisplay, xWindow, i + 1, buffer, buffer.length, copied_length);
-// if (rc == OS.XmClipboardNoData){
-// types[i] = "";
-// continue;
-// }
-// if (rc != OS.XmClipboardSuccess)
-// DND.error(SWT.ERROR_UNSPECIFIED);
-// byte[] buffer2 = new byte[copied_length[0]];
-// System.arraycopy(buffer, 0, buffer2, 0, copied_length[0]);
-// types[i] = new String(buffer2);
-// }
+ String[] types = new String[0];
+ int ig = OS.PhInputGroup(0);
+ int cbdata = OS.PhClipboardPasteStart((short)ig);
+ if (cbdata == 0) return types;
+ try {
+ int pClipHeader = 0;
+ int n = 0;
+ while ((pClipHeader = OS.PhClipboardPasteTypeN(cbdata, n++)) != 0) {
+ PhClipHeader clipHeader = new PhClipHeader();
+ OS.memmove(clipHeader, pClipHeader, PhClipHeader.sizeof);
+ byte[] buffer = new byte[8];
+ buffer[0] = clipHeader.type_0;
+ buffer[1] = clipHeader.type_1;
+ buffer[2] = clipHeader.type_2;
+ buffer[3] = clipHeader.type_3;
+ buffer[4] = clipHeader.type_4;
+ buffer[5] = clipHeader.type_5;
+ buffer[6] = clipHeader.type_6;
+ buffer[7] = clipHeader.type_7;
+ char [] unicode = Converter.mbcsToWcs (null, buffer);
+
+ String[] newTypes = new String[types.length + 1];
+ System.arraycopy(types, 0, newTypes, 0, types.length);
+ newTypes[types.length] = new String (unicode).trim();
+ types = newTypes;
+ }
+ } finally {
+ OS.PhClipboardPasteFinish(cbdata);
+ }
return types;
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/FileTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/FileTransfer.java
index 54044a03f1..f311c62182 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/FileTransfer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/FileTransfer.java
@@ -8,7 +8,7 @@ package org.eclipse.swt.dnd;
public class FileTransfer extends ByteArrayTransfer {
private static FileTransfer _instance = new FileTransfer();
- private static final String TYPENAME = "text/uri-list\0";
+ private static final String TYPENAME = "files";
private static final int TYPEID = registerType(TYPENAME);
private FileTransfer() {}
@@ -16,46 +16,11 @@ public static FileTransfer getInstance () {
return _instance;
}
public void javaToNative(Object object, TransferData transferData) {
-
- if (object == null || !(object instanceof String[])) return;
-
- // build a byte array from data
- String[] files = (String[])object;
-
- // create a string separated by "new lines" to represent list of files
- String nativeFormat = "file:";
- for (int i = 0, length = files.length; i < length; i++){
- nativeFormat += files[i]+"\r";
- }
- nativeFormat += "\0";
- // pass byte array on to super to convert to native
- super.javaToNative(nativeFormat.getBytes(), transferData);
+ DND.error(org.eclipse.swt.SWT.ERROR_NOT_IMPLEMENTED);
}
public Object nativeToJava(TransferData transferData) {
-
- byte[] data = (byte[])super.nativeToJava(transferData);
- if (data == null) return null;
- String string = new String(data);
- // parse data and convert string to array of files
- int start = string.indexOf("file:");
- if (start == -1) return null;
- start += 5;
- String[] fileNames = new String[0];
- while (start < string.length()) {
- int end = string.indexOf("\r", start);
- if (end == -1) end = string.length() - 1;
-
- String fileName = string.substring(start, end);
- String[] newFileNames = new String[fileNames.length + 1];
- System.arraycopy(fileNames, 0, newFileNames, 0, fileNames.length);
- newFileNames[fileNames.length] = fileName;
- fileNames = newFileNames;
-
- start = string.indexOf("file:", end);
- if (start == -1) break;
- start += 5;
- }
- return fileNames;
+ DND.error(org.eclipse.swt.SWT.ERROR_NOT_IMPLEMENTED);
+ return null;
}
protected String[] getTypeNames(){
return new String[]{TYPENAME};
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/RTFTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/RTFTransfer.java
index d36e6562b0..4092a3fbc0 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/RTFTransfer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/RTFTransfer.java
@@ -1,5 +1,6 @@
package org.eclipse.swt.dnd;
+import org.eclipse.swt.internal.Converter;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved
@@ -8,12 +9,8 @@ package org.eclipse.swt.dnd;
public class RTFTransfer extends ByteArrayTransfer {
private static RTFTransfer _instance = new RTFTransfer();
- private static final String TYPENAME1 = "text/rtf\0";
- private static final int TYPEID1 = registerType(TYPENAME1);
- private static final String TYPENAME2 = "TEXT/RTF\0";
- private static final int TYPEID2 = registerType(TYPENAME2);
- private static final String TYPENAME3 = "application/rtf\0";
- private static final int TYPEID3 = registerType(TYPENAME3);
+ private static final String TYPENAME = "RTF";
+ private static final int TYPEID = registerType(TYPENAME);
private RTFTransfer() {
}
@@ -22,21 +19,21 @@ public static RTFTransfer getInstance () {
}
public void javaToNative (Object object, TransferData transferData){
if (object == null || !(object instanceof String)) return;
-
- String text = (String)object;
- super.javaToNative(text.getBytes(), transferData);
+ byte [] buffer = Converter.wcsToMbcs (null, (String)object, false);
+ super.javaToNative(buffer, transferData);
}
public Object nativeToJava(TransferData transferData){
- // get byte array from super
+ /// get byte array from super
byte[] buffer = (byte[])super.nativeToJava(transferData);
if (buffer == null) return null;
// convert byte array to a string
- return new String(buffer);
+ char [] unicode = Converter.mbcsToWcs (null, buffer);
+ return new String (unicode);
}
protected String[] getTypeNames(){
- return new String[]{TYPENAME1, TYPENAME2, TYPENAME3};
+ return new String[]{TYPENAME};
}
protected int[] getTypeIds(){
- return new int[]{TYPEID1, TYPEID2, TYPEID3};
+ return new int[]{TYPEID};
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/TextTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/TextTransfer.java
index e6587940bc..685aabce78 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/TextTransfer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/TextTransfer.java
@@ -1,5 +1,8 @@
package org.eclipse.swt.dnd;
+import org.eclipse.swt.internal.Converter;
+import org.eclipse.swt.internal.photon.OS;
+
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved
@@ -8,12 +11,8 @@ package org.eclipse.swt.dnd;
public class TextTransfer extends ByteArrayTransfer {
private static TextTransfer _instance = new TextTransfer();
- private static final String TYPENAME1 = "STRING\0";
- private static final int TYPEID1 = registerType(TYPENAME1);
- private static final String TYPENAME2 = "text/plain\0";
- private static final int TYPEID2 = registerType(TYPENAME2);
- private static final String TYPENAME3 = "text/text\0";
- private static final int TYPEID3 = registerType(TYPENAME3);
+ private static final String TYPENAME = "TEXT";
+ private static final int TYPEID = registerType(TYPENAME);
private TextTransfer() {
}
@@ -22,21 +21,21 @@ public static TextTransfer getInstance () {
}
public void javaToNative (Object object, TransferData transferData){
if (object == null || !(object instanceof String)) return;
-
- String text = (String)object;
- super.javaToNative(text.getBytes(), transferData);
+ byte [] buffer = Converter.wcsToMbcs (null, (String)object, false);
+ super.javaToNative(buffer, transferData);
}
public Object nativeToJava(TransferData transferData){
// get byte array from super
byte[] buffer = (byte[])super.nativeToJava(transferData);
if (buffer == null) return null;
// convert byte array to a string
- return new String(buffer);
+ char [] unicode = Converter.mbcsToWcs (null, buffer);
+ return new String (unicode);
}
protected String[] getTypeNames(){
- return new String[]{TYPENAME1, TYPENAME2, TYPENAME3};
+ return new String[]{TYPENAME};
}
protected int[] getTypeIds(){
- return new int[]{TYPEID1, TYPEID2, TYPEID3};
+ return new int[]{TYPEID};
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/Transfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/Transfer.java
index 3634d3576d..95d9283f6b 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/Transfer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/Transfer.java
@@ -13,6 +13,9 @@ abstract protected int[] getTypeIds();
abstract protected void javaToNative (Object object, TransferData transferData);
abstract protected Object nativeToJava(TransferData transferData);
public static int registerType(String formatName){
+ if (formatName == "TEXT") return 10;
+ if (formatName == "files") return 11;
+ if (formatName == "RTF") return 12;
return 0;
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/TransferData.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/TransferData.java
index 50eabd10e9..ae75ee6293 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/TransferData.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/photon/org/eclipse/swt/dnd/TransferData.java
@@ -9,10 +9,7 @@ public class TransferData {
public int type;
// attributes specific to set/get
+ int pData;
int length;
- int format;
- int pValue;
-
int result;
-
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OLE.java b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OLE.java
index dd6d8e87d8..63c3318a85 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OLE.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OLE.java
@@ -359,6 +359,7 @@ public static String findProgramID (String extension) {
if (extension.charAt (0) != '.') extension = "." + extension;
+ /* Use the character encoding for the default locale */
byte[] extensionKey = Converter.wcsToMbcs(0, extension, true);
String result = getKeyValue(extensionKey);
if (result != null) {
@@ -385,6 +386,7 @@ private static String getKeyValue (byte [] key) {
if (OS.RegQueryValueEx (phkResult [0], null, 0, null, null, lpcbData) == 0) {
byte [] lpData = new byte [lpcbData [0]];
if (OS.RegQueryValueEx (phkResult [0], null, 0, null, lpData, lpcbData) == 0) {
+ /* Use the character encoding for the default locale */
char[] charArray = Converter.mbcsToWcs (0, lpData);
result = new String(charArray, 0, charArray.length - 1);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java
index 2c85d77347..aebdf722d3 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java
@@ -660,8 +660,8 @@ public String getProgramID(){
if (appClsid != null){
int[] lplpszProgID = new int[1];
if (COM.ProgIDFromCLSID(appClsid, lplpszProgID) == COM.S_OK) {
+ int length = OS.GlobalSize(lplpszProgID[0]);
int ptr = OS.GlobalLock(lplpszProgID[0]);
- int length = OS.GlobalSize(ptr);
char[] buffer = new char[length];
COM.MoveMemory(buffer, lplpszProgID[0], length);
OS.GlobalUnlock(ptr);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleFrame.java b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleFrame.java
index 87d4432ebc..ed6c4987c8 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleFrame.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleFrame.java
@@ -199,6 +199,9 @@ static int getMsgProc(int code, int wParam, int lParam) {
if (site.handle == hwnd) {
OleFrame frame = site.frame;
if (frame.translateOleAccelerator(msg)) {
+ // In order to prevent this message from also being processed
+ // by the application, zero out message, wParam and lParam
+ OS.MoveMemory(lParam + 4, new int[] {OS.WM_NULL, 0, 0}, 12);
return 0;
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/common/org/eclipse/swt/printing/PrinterData.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/common/org/eclipse/swt/printing/PrinterData.java
index e0aaf4cc38..87b953254e 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Printing/common/org/eclipse/swt/printing/PrinterData.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/common/org/eclipse/swt/printing/PrinterData.java
@@ -122,8 +122,8 @@ public final class PrinterData extends DeviceData {
* Constructs an instance of this class that can be
* used to print to the default printer.
*
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_UNSPECIFIED - if there are no valid printers
+ * @exception SWTError <ul>
+ * <li>ERROR_NO_HANDLES - if an error occurred constructing the default printer data</li>
* </ul>
*/
public PrinterData() {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/motif/org/eclipse/swt/printing/Printer.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/motif/org/eclipse/swt/printing/Printer.java
index b3685e7048..92ba747e51 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Printing/motif/org/eclipse/swt/printing/Printer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/motif/org/eclipse/swt/printing/Printer.java
@@ -39,21 +39,18 @@ public final class Printer extends Device {
* Returns an array of <code>PrinterData</code> objects
* representing all available printers.
*
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_UNSPECIFIED - if there are no valid printers
- * </ul>
- *
* @return the list of available printers
*/
public static PrinterData[] getPrinterList() {
- SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
+ if (true) return new PrinterData[0]; // printing on X is currently unimplemented
+
/* Connect to the default X print server */
//byte [] buffer = Converter.wcsToMbcs(null, XDefaultPrintServer, true);
//int pdpy = OS.XOpenDisplay(buffer);
int pdpy = xPrinter;
if (pdpy == 0) {
/* no print server */
- SWT.error(SWT.ERROR_IO);
+ return new PrinterData[0];
}
/* Get the list of printers */
@@ -63,7 +60,7 @@ public static PrinterData[] getPrinterList() {
if (plist == 0 || printerCount == 0) {
/* no printers */
//OS.XCloseDisplay(pdpy);
- SWT.error(SWT.ERROR_IO);
+ return new PrinterData[0];
}
/* Copy the printer names into PrinterData objects */
@@ -77,6 +74,7 @@ public static PrinterData[] getPrinterList() {
int length = OS.strlen(address);
byte[] buffer = new byte [length];
OS.memmove(buffer, address, length);
+ /* Use the character encoding for the default locale */
name = new String(Converter.mbcsToWcs(null, buffer));
}
printerList[i] = new PrinterData(Device.XDefaultPrintServer, name);
@@ -86,6 +84,16 @@ public static PrinterData[] getPrinterList() {
return printerList;
}
+/*
+ * Returns a <code>PrinterData</code> object representing
+ * the default printer.
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_NO_HANDLES - if an error occurred constructing the default printer data</li>
+ * </ul>
+ *
+ * @return the default printer data
+ */
static PrinterData getDefaultPrinterData() {
/* Use the first printer in the list as the default */
PrinterData[] list = getPrinterList();
@@ -150,6 +158,7 @@ protected void init() {
super.init();
/* Create the printContext for the printer */
+ /* Use the character encoding for the default locale */
byte[] name = Converter.wcsToMbcs(null, data.name, true);
printContext = OS.XpCreateContext(xDisplay, name);
if (printContext == OS.None) {
@@ -170,6 +179,7 @@ protected void init() {
OS.XtDestroyWidget(shellHandle);
/* Initialize the default font */
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs(null, "-*-courier-medium-r-*-*-*-120-*-*-*-*-*-*", true);
int fontListEntry = OS.XmFontListEntryLoad(xDisplay, buffer, 0, OS.XmFONTLIST_DEFAULT_TAG);
if (fontListEntry == 0) SWT.error(SWT.ERROR_NO_HANDLES);
@@ -251,6 +261,7 @@ public void internal_dispose_GC(int xGC, GCData data) {
*/
public boolean startJob(String jobName) {
checkDevice();
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs(null, "*job-name: " + jobName, true);
OS.XpSetAttributes(xDisplay, printContext, OS.XPJobAttr, buffer, OS.XPAttrMerge);
OS.XpStartJob(xDisplay, OS.XPSpool);
@@ -348,6 +359,7 @@ public void endPage() {
*/
public Point getDPI() {
checkDevice();
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs(null, "default-printer-resolution", true);
int pool = OS.XpGetOneAttribute(xDisplay, printContext, OS.XPDocAttr, buffer);
int length = OS.strlen(pool);
@@ -358,6 +370,7 @@ public Point getDPI() {
int res = 300; // default
if (resolution.length() == 0) {
/* If we can't get the info from the DocAttrs, ask the printer. */
+ /* Use the character encoding for the default locale */
buffer = Converter.wcsToMbcs(null, "printer-resolutions-supported", true);
pool = OS.XpGetOneAttribute(xDisplay, printContext, OS.XPPrinterAttr, buffer);
length = OS.strlen(pool);
@@ -457,14 +470,12 @@ public Rectangle computeTrim(int x, int y, int width, int height) {
return new Rectangle(x - rect.x, y - rect.y, width + hTrim, height + vTrim);
}
-/**
- * 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
- */
+/**
+ * Returns a <code>PrinterData</code> object representing the
+ * target printer for this print job.
+ *
+ * @return a PrinterData object describing the receiver
+ */
public PrinterData getPrinterData() {
return data;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/photon/org/eclipse/swt/printing/Printer.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/photon/org/eclipse/swt/printing/Printer.java
index 5e4b1952e0..9e19c3c43a 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Printing/photon/org/eclipse/swt/printing/Printer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/photon/org/eclipse/swt/printing/Printer.java
@@ -79,6 +79,12 @@ public Rectangle computeTrim(int x, int y, int width, int height) {
return new Rectangle(0,0,0,0);
}
+/**
+ * Returns a <code>PrinterData</code> object representing the
+ * target printer for this print job.
+ *
+ * @return a PrinterData object describing the receiver
+ */
public PrinterData getPrinterData() {
return data;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java
index b4aea6212a..8555def86c 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PrintDialog.java
@@ -212,8 +212,8 @@ public PrinterData open() {
pd.nToPage = (short) endPage;
if (OS.PrintDlg(pd)) {
/* Get driver and device from the DEVNAMES struct */
+ int size = OS.GlobalSize(pd.hDevNames);
int ptr = OS.GlobalLock(pd.hDevNames);
- int size = OS.GlobalSize(ptr);
byte [] DEVNAMES = new byte[size];
OS.MoveMemory(DEVNAMES, ptr, size);
OS.GlobalUnlock(ptr);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/Printer.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/Printer.java
index 4554b3c30f..4de1780b0f 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/Printer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/Printer.java
@@ -64,16 +64,12 @@ public final class Printer extends Device {
* Returns an array of <code>PrinterData</code> objects
* representing all available printers.
*
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_UNSPECIFIED - if there are no valid printers
- * </ul>
- *
* @return the list of available printers
*/
public static PrinterData[] getPrinterList() {
byte[] buf = new byte[1024];
int n = OS.GetProfileString(profile, null, new byte[] {0}, buf, buf.length);
- if (n == 0) SWT.error(SWT.ERROR_UNSPECIFIED);
+ if (n == 0) return new PrinterData[0];
byte[][] deviceNames = new byte[5][];
int nameCount = 0;
int index = 0;
@@ -108,21 +104,21 @@ public static PrinterData[] getPrinterList() {
return printerList;
}
-/**
+/*
* Returns a <code>PrinterData</code> object representing
* the default printer.
*
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_UNSPECIFIED - if there are no valid printers
+ * @exception SWTError <ul>
+ * <li>ERROR_NO_HANDLES - if an error occurred constructing the default printer data</li>
* </ul>
*
- * @return the default printer
+ * @return the default printer data
*/
static PrinterData getDefaultPrinterData() {
byte [] deviceName = null;
byte[] buf = new byte[1024];
int n = OS.GetProfileString(appName, keyName, new byte[] {0}, buf, buf.length);
- if (n == 0) SWT.error(SWT.ERROR_UNSPECIFIED);
+ if (n == 0) SWT.error(SWT.ERROR_NO_HANDLES);
int commaIndex = 0;
while(buf[commaIndex] != ',' && commaIndex < buf.length) commaIndex++;
if (commaIndex < buf.length) {
@@ -186,6 +182,7 @@ public Printer(PrinterData data) {
*/
protected void create(DeviceData deviceData) {
data = (PrinterData)deviceData;
+ /* Use the character encoding for the default locale */
byte[] driver = Converter.wcsToMbcs(0, data.driver, true);
byte[] device = Converter.wcsToMbcs(0, data.name, true);
int lpInitData = 0;
@@ -272,6 +269,7 @@ public boolean startJob(String jobName) {
int hHeap = OS.GetProcessHeap();
int lpszDocName = 0;
if (jobName != null && jobName.length() != 0) {
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs(0, jobName, true);
lpszDocName = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, buffer.length);
OS.MoveMemory(lpszDocName, buffer, buffer.length);
@@ -279,6 +277,7 @@ public boolean startJob(String jobName) {
}
int lpszOutput = 0;
if (data.printToFile && data.fileName != null) {
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs(0, data.fileName, true);
lpszOutput = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, buffer.length);
OS.MoveMemory(lpszOutput, buffer, buffer.length);
@@ -459,12 +458,10 @@ public Rectangle computeTrim(int x, int y, int width, int height) {
}
/**
- * 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
+ * Returns a <code>PrinterData</code> object representing the
+ * target printer for this print job.
+ *
+ * @return a PrinterData object describing the receiver
*/
public PrinterData getPrinterData() {
return data;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/motif/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/motif/org/eclipse/swt/program/Program.java
index 52f5f9b5f4..5f58b97556 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Program/motif/org/eclipse/swt/program/Program.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Program/motif/org/eclipse/swt/program/Program.java
@@ -1,700 +1,1065 @@
-package org.eclipse.swt.program;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-import org.eclipse.swt.widgets.Display;
-
-import java.io.*;
-import java.util.Iterator;
-import java.util.Hashtable;
-import java.util.Vector;
-
+package org.eclipse.swt.program;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.internal.*;
+import org.eclipse.swt.internal.motif.*;
+import org.eclipse.swt.*;
+import org.eclipse.swt.graphics.*;
+
+import org.eclipse.swt.widgets.Display;
+
+import java.io.*;
+import java.util.Iterator;
+import java.util.Hashtable;
+import java.util.Vector;
+
/**
* Instances of this class represent programs and
* their assoicated file extensions in the operating
* system.
- */
-public final class Program {
- String name;
- String extension;
- String command;
-
- static final int DESKTOP_UNKNOWN = 0;
- static final int DESKTOP_KDE = 1;
- static final int DESKTOP_GNOME = 2;
- static final int Desktop = getDesktop ();
-
-/**
- * Prevents uninitialized instances from being created outside the package.
- */
-Program () {
-}
-
-static int getDesktop () {
- File root = new File ("/proc");
- if (!root.exists () || !root.isDirectory ()) return DESKTOP_UNKNOWN;
- File [] procDirs = root.listFiles ();
- for (int i=0; i<procDirs.length; i++) {
- String directory = procDirs [i].getAbsolutePath ();
- File file = new File (directory + "/stat");
- if (file.exists ()) {
- String procName = getProcName (file);
- if (procName.indexOf ("gnome") >= 0) {
- return gnome_init() ? DESKTOP_GNOME : DESKTOP_UNKNOWN;
- }
- if (procName.indexOf ("kdeinit") >= 0) {
- return kde_init () ? DESKTOP_KDE : DESKTOP_UNKNOWN;
- }
- }
- }
- return DESKTOP_UNKNOWN;
-}
-
-static String getProcName (File file) {
- try {
- FileInputStream stream = new FileInputStream (file);
- while (true) {
- char ch = (char) stream.read ();
- if (ch < 0 || ch == 0xFF) return null;
- if (ch == '(') break;
- }
- String name = "";
- while (true) {
- char ch = (char) stream.read ();
- if (ch < 0 || ch == 0xFF) return null;
- if (ch == ')') break;
- name += ch;
- }
- stream.close ();
- return name;
- } catch (IOException e) {
- return null;
- }
-}
-/*
- * Finds the program that is associated with an extension.
- * The extension may or may not begin with a '.'.
- *
- * @param extension the program extension
- * @return the program or nil
- *
- * @exception SWTError <ul>
- * <li>ERROR_NULL_ARGUMENT when extension is null</li>
- * </ul>
- */
-public static Program findProgram (String extension) {
- if (extension == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (extension.length () == 0) return null;
- if (extension.charAt (0) != '.') extension = "." + extension;
- String command = null;
- String name = "";
- switch (Desktop) {
- case DESKTOP_KDE: {
- String urlString = "file://any." + extension;
- byte [] buffer = Converter.wcsToMbcs (null, urlString, true);
- int qString = KDE.QString_new (buffer);
- int url = KDE.KURL_new (qString);
- KDE.QString_delete (qString);
- int mimeType = KDE.KMimeType_findByURL (url);
- int mimeName = KDE.KMimeType_name (mimeType);
- int service = KDE.KServiceTypeProfile_preferredService (mimeName, 1);
- if (service == 0) return null;
- int execQString = KDE.KService_exec (service);
- command = kde_convertQStringAndFree (execQString);
- break;
- }
-
- case DESKTOP_GNOME: {
- String fileName = "file" + extension;
- String mimeType = gnome_getMimeType (fileName);
- if (mimeType == null) return null;
- command = gnome_getMimeValue (mimeType, "open");
- if (command == null) return null;
- name = mimeType;
- break;
- }
-
- case DESKTOP_UNKNOWN:
- return null;
- }
- Program program = new Program ();
- program.name = name;
- program.command = command;
- program.extension = extension;
- return program;
-}
-
-/*
- * Answer all program extensions in the operating system.
- *
- * @return an array of extensions
- */
-public static String [] getExtensions () {
- switch (Desktop) {
- case DESKTOP_KDE:
- Vector names = new Vector ();
- int serviceList = KDE.KService_allServices ();
- int listBeginning = KDE.KServiceList_begin (serviceList);
- int listEnd = KDE.KServiceList_end (serviceList);
- int iterator = KDE.KServiceListIterator_new (listBeginning);
- while (true) {
- if (KDE.KServiceListIterator_equals (iterator, listEnd) != 0) break;
- int kService = KDE.KServiceListIterator_dereference (iterator);
- int serviceType = KDE.KService_type (kService);
- byte [] applicationType = Converter.wcsToMbcs (null, "Application", true);
- int appString = KDE.QString_new (applicationType);
- if (KDE.QString_equals (serviceType, appString) != 0) {
- int appName = KDE.KService_name (kService);
- names.addElement (kde_convertQStringAndFree (appName));
- }
- KDE.QString_delete (appString);
- KDE.KServiceListIterator_increment (iterator);
- }
- KDE.KServiceListIterator_delete (iterator);
- KDE.KServiceList_delete (serviceList);
- String[] appNames = new String [names.size ()];
- for (int i=0; i <names.size (); i++) {
- appNames [i] = (String) names.elementAt (i);
- }
- return appNames;
-
- case DESKTOP_GNOME:
- // Obtain the mime type/extension information.
- Hashtable mimeInfo = gnome_getMimeInfo();
- int index;
-
- // Create a sorted set of the file extensions.
- Vector extensions = new Vector();
- Iterator keys = mimeInfo.keySet().iterator();
- while (keys.hasNext()) {
- String mimeType = (String) keys.next();
- Vector mimeExts = (Vector) mimeInfo.get( mimeType );
- for (index = 0; index < mimeExts.size(); index++){
- if (!extensions.contains( mimeExts.elementAt( index ) )) {
- extensions.add( mimeExts.elementAt( index ) );
- }
- }
- }
-
- // Return the list of extensions.
- String[] extStrings = new String[ extensions.size() ];
- for (index = 0; index < extensions.size(); index++) {
- extStrings[ index ] = (String) extensions.elementAt( index );
- }
-
- return extStrings;
- }
- return new String[0];
-}
-
-/*
- * Answers all available programs in the operating system.
- *
- * @return an array of programs
- */
-public static Program [] getPrograms () {
- switch (Desktop) {
- case DESKTOP_KDE:
- return new Program[0]; // TBD
-
- case DESKTOP_GNOME:
- // Obtain the mime type/extension information.
- Hashtable mimeInfo = gnome_getMimeInfo();
- Vector programs = new Vector();
-
- // Create a list of programs with commands.
- Iterator keys = mimeInfo.keySet().iterator();
- while (keys.hasNext()) {
- String mimeType = (String) keys.next();
- String extension = "";
- Vector mimeExts = (Vector) mimeInfo.get( mimeType );
- if (mimeExts.size() > 0){
- extension = (String) mimeExts.elementAt( 0 );
- }
- String command = gnome_getMimeValue( mimeType, "open" );
- if (command != null) {
- Program program = new Program ();
- program.name = mimeType;
- program.command = command;
- program.extension = extension;
- programs.add( program );
- }
- }
-
- // Return the list of programs to the user.
- Program[] programList = new Program[ programs.size() ];
- for (int index = 0; index < programList.length; index++) {
- programList[ index ] = (Program) programs.elementAt( index );
- }
- return programList;
- }
- return new Program[0];
-}
-
-/*
- * Obtain the registered mime type information and
- * return it in a map. The key of each entry
- * in the map is the mime type name. The value is
- * a vector of the associated file extensions.
- */
-
-private static Hashtable gnome_getMimeInfo() {
- Hashtable mimeInfo = new Hashtable();
-
- // Extract the mime info from the system directory.
- String mimeDirectory = gnome_getDataDirectory ("mime-info");
- gnome_getMimeInfoFromDirectory( mimeInfo, new File( mimeDirectory ) );
-
- // Append the mime info from the user's directory (if it exists).
- String userDirectory = gnome_getHomeDirectory();
- if (userDirectory != null) {
- userDirectory = userDirectory + File.separator + ".gnome" + File.separator + "mime-info";
- gnome_getMimeInfoFromDirectory( mimeInfo, new File( userDirectory ) );
- }
-
- return mimeInfo;
-}
-
-// Given a map and a directory, find all of the
-// mime information files (*.mime) and parse them for
-// relavent mime type information. Each entry in the
-// map corresponds to one mime type, and its
-// associated file extensions.
-
-private static void gnome_getMimeInfoFromDirectory( Hashtable info, File directory ) {
- // For each entry in the given directory (if it exists)
- if (directory.exists()) {
- File[] files = directory.listFiles();
- for (int i = 0; i < files.length; i++) {
-
- // If the entry is a subdirectory, process it and
- // merge the mime type into the given map.
- if (files[i].isDirectory()) {
- gnome_getMimeInfoFromDirectory( info, files[i] );
- }
-
- // else if the entry is a mime info file (*.mime)
- else if (files[i].getName().endsWith(".mime")) {
- try {
- // Parse the mime file and merge the info
- // into the given map.
- FileReader in = new FileReader( files[i] );
- BufferedReader reader = new BufferedReader( in );
- gnome_parseMimeFile( info, reader );
- reader.close();
- in.close();
- }
- catch (IOException e) {
- // Ignore file exceptions silently. If we
- // can't read it, the info is not available.
- }
- }
- }
- }
-}
-
-private static void gnome_parseMimeFile( Hashtable info, BufferedReader reader ) {
- Vector mimeExts = null;
- String mimeType = null;
- boolean saveType = false;
- String line = "#";
- while (line != null) {
-
- // Determine if the line contains a mime type name.
- boolean newType = (line.length() > 0 && Character.isLetter( line.charAt(0) ));
-
- // If there is valid data on this line to be processed
- String data = line.trim();
- if (data.length() > 0 && data.charAt(0) != '#') {
-
- // If this line defines a new mime type
- if (newType) {
-
- // If a previous mime type has not be saved yet
- if (mimeType != null) {
- // Save the type and process this line again.
- saveType = true;
- }
- // else initialize the mime type info
- else {
- int colon = data.indexOf( ':' );
- if (colon != -1) {
- mimeType = data.substring( 0, colon );
- }
- else {
- mimeType = data;
- }
- mimeExts = new Vector();
- }
- }
-
- // else if the line defines a list of extensions
- else if (data.indexOf( "ext" ) == 0 && mimeType != null) {
-
- // Get the extensions defined on the line
- String exts = "";
- int colon = data.indexOf( ':' );
- if ((colon != -1) && ((colon+1) < data.length())) {
- exts = data.substring( (colon+1) ).trim();
- }
-
- // While there are extensions to be processed
- exts = exts.replace( '\t', ' ' );
- while (exts.length() != 0) {
- // Extract the next entension from the list
- String newExt;
- int space = exts.indexOf( ' ' );
- if (space != -1) {
- newExt = exts.substring( 0, space );
- exts = exts.substring( space ).trim();
- }
- else {
- newExt = exts;
- exts = "";
- }
-
- // Prefix an extension with a period.
- if (newExt.charAt(0) != '.') {
- newExt = "." + newExt;
- }
- mimeExts.add( newExt );
- }
- }
-
- // else if the line defines a list of regular expressions
- else if (data.indexOf( "regex" ) == 0 && mimeType != null) {
- // Do nothing with these right now.
- }
- }
-
-
- // If the current mime type is still being processed
- if (!saveType) {
- // Get the next line
- try {
- line = reader.readLine();
- }
- catch (IOException e) {
- line = null;
- }
- }
-
- // If the current type should be saved or if the end
- // of the file was reached
- if (saveType || (line == null)) {
-
- // If there is a mime type to be saved
- if (mimeType != null) {
-
- // If the mime type does not exist in the map, add it.
- Vector prevExts = (Vector) info.get( mimeType );
- if (prevExts == null) {
- info.put( mimeType, mimeExts );
- }
-
- // else append the new list of extensions.
- else {
- for (int i = 0; i < mimeExts.size(); i++) {
- prevExts.add( mimeExts.elementAt( i ) );
- }
- }
- mimeType = null;
- mimeExts = null;
- saveType = false;
- }
- }
- }
-}
-
-// Private method for parsing a command line into its arguments.
-private static String[] parseCommand( String cmd ) {
- Vector args = new Vector();
- int sIndex = 0;
- int eIndex;
- while (sIndex < cmd.length()) {
- // Trim initial white space of argument.
- while (sIndex < cmd.length() && Character.isWhitespace( cmd.charAt(sIndex) )) {
- sIndex++;
- }
- if (sIndex < cmd.length()) {
- // If the command is a quoted string
- if (cmd.charAt(sIndex) == '"' || cmd.charAt(sIndex) == '\''){
- // Find the terminating quote (or end of line).
- // This code currently does not handle escaped characters (e.g., " a\"b").
- eIndex = sIndex + 1;
- while (eIndex < cmd.length() && cmd.charAt(eIndex) != cmd.charAt(sIndex)) {
- eIndex++;
- }
- if (eIndex >= cmd.length()) { // the terminating quote was not found
- // Add the argument as is with only one initial quote.
- args.add( cmd.substring( sIndex, eIndex ) );
- }
- // else add the argument, trimming off the quotes.
- else {
- args.add( cmd.substring( sIndex+1, eIndex ) );
- }
- sIndex = eIndex + 1;
- }
-
- // else use white space for the delimiters.
- else {
- eIndex = sIndex;
- while (eIndex < cmd.length() && !Character.isWhitespace( cmd.charAt(eIndex) )) {
- eIndex++;
- }
- args.add( cmd.substring( sIndex, eIndex ) );
- sIndex = eIndex + 1;
- }
- }
- }
-
- String[] strings = new String[ args.size() ];
- for (int index =0; index < args.size(); index++) {
- strings[ index ] = (String) args.elementAt( index );
- }
- return strings;
-}
-
-
-static String gnome_getDataDirectory(String dirName) {
- byte [] nameBuffer = Converter.wcsToMbcs (null, dirName, true);
- int ptr = GNOME.gnome_datadir_file(nameBuffer);
- if (ptr == 0) return null;
- int length = OS.strlen(ptr);
- byte[] dirBuffer = new byte[length];
- OS.memmove(dirBuffer, ptr, length);
- return new String(Converter.mbcsToWcs(null, dirBuffer));
-}
-
-static String gnome_getHomeDirectory() {
- int ptr = GNOME.g_get_home_dir();
- if (ptr == 0) return null;
- int length = OS.strlen(ptr);
- byte[] homeDirBuffer = new byte[length];
- OS.memmove(homeDirBuffer, ptr, length);
- return new String(Converter.mbcsToWcs(null, homeDirBuffer));
-}
-
-static String gnome_getMimeType(String name) {
- byte [] nameBuffer = Converter.wcsToMbcs (null, name, true);
- int ptr = GNOME.gnome_mime_type(nameBuffer);
- if (ptr == 0) return null;
- int length = OS.strlen(ptr);
- byte[] mimeBuffer = new byte[length];
- OS.memmove(mimeBuffer, ptr, length);
- return new String(Converter.mbcsToWcs(null, mimeBuffer));
-}
-
-static String gnome_getMimeValue(String mimeType, String key) {
- byte [] typeBuffer = Converter.wcsToMbcs (null, mimeType, true);
- byte [] keyBuffer = Converter.wcsToMbcs (null, key, true);
- int ptr = GNOME.gnome_mime_get_value(typeBuffer, keyBuffer);
- if (ptr == 0) return null;
-
- StringBuffer stringBuffer = new StringBuffer();
- int length = OS.strlen(ptr);
- byte[] valueBuffer = new byte[length];
- OS.memmove(valueBuffer, ptr, length);
- return new String(Converter.mbcsToWcs(null, valueBuffer));
-}
-
-static boolean kde_init () {
- try {
- Callback.loadLibrary("swt-kde");
- } catch (UnsatisfiedLinkError e) {
- return false;
- }
- String appName = "KDE Platform Support";
- byte [] nameBuffer = Converter.wcsToMbcs (null, appName, true);
- int qcString = KDE.QCString_new (nameBuffer);
- KDE.KApplication_new (qcString);
- KDE.QCString_delete (qcString);
- return true;
-}
-
-static String kde_convertQStringAndFree (int qString) {
- int qCString = KDE.QString_utf8 (qString);
- int charString = KDE.QCString_data (qCString);
-
- StringBuffer stringBuffer = new StringBuffer ();
- int length = KDE.strlen (charString);
- byte[] buffer = new byte [length];
- KDE.memmove (buffer, charString, length);
- String answer = new String (Converter.mbcsToWcs (null, buffer));
-
- KDE.QCString_delete (qCString);
- KDE.QString_delete (qString);
- return answer;
-}
-
-/*
- * Launches the executable associated with the file in
- * the operating system. If the file is an executable,
- * then the executable is launched.
- *
- * @param fileName the file or program name
- * @return <code>true</code> if the file is launched, otherwise <code>false</code>
- *
- * @exception SWTError <ul>
- * <li>ERROR_NULL_ARGUMENT when fileName is null</li>
- * </ul>
- */
-public static boolean launch (String fileName) {
- if (fileName == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
-
- // If the argument appears to be a data file (it has an extension)
- int index = fileName.lastIndexOf (".");
- if (index > 0) {
-
- // Find the associated program, if one is defined.
- String extension = fileName.substring (index);
- Program program = Program.findProgram (extension);
-
- // If the associated program is defined and can be executed, return.
- if (program != null && program.execute (fileName)) return true;
- }
-
- // Otherwise, the argument was the program itself.
- try {
- Runtime.getRuntime().exec (fileName);
- return true;
- } catch (IOException e) {
- return false;
- }
-}
-
-/*
- * Executes the program with the file as the single argument
- * in the operating system. It is the responsibility of the
- * programmer to ensure that the file contains valid data for
- * this program.
- *
- * @param fileName is the argument (typically a file) for the program
- * @return <code>true</code> if the file is launched, otherwise <code>false</code>
- *
- * @exception SWTError <ul>
- * <li>ERROR_NULL_ARGUMENT when fileName is null</li>
- * </ul>
- */
-public boolean execute (String fileName) {
- if (fileName == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-
- // Parse the command into its individual arguments.
- String[] args = parseCommand( command );
- int fileArg = -1;
- int index;
- for (index=0; index < args.length; index++) {
- int j = args[ index ].indexOf( "%f" );
- if (j != -1) {
- String value = args[ index ];
- fileArg = index;
- args[ index ] = value.substring(0,j) + fileName + value.substring(j+2);
- }
- }
-
- // If a file name was given but the command did not have "%f"
- if ((fileName.length() > 0) && (fileArg < 0)) {
- String[] newArgs = new String[ args.length + 1 ];
- for (index=0; index < args.length; index++)
- newArgs[ index ] = args[ index ];
- newArgs[ args.length ] = fileName;
- args = newArgs;
- }
-
- // Execute the command.
- try {
- Runtime.getRuntime().exec( args );
- } catch (IOException e) {
- return false;
- }
-
- return true;
-}
-
-/*
- * Returns the receiver's image data. This is the icon
- * that is associated with the reciever in the operating
- * system.
- *
- * @return the image data for the program
- */
-public ImageData getImageData () {
- String iconPath = null;
- switch (Desktop) {
- case DESKTOP_KDE:
- String urlString = "file://any." + extension;
- byte [] buffer = Converter.wcsToMbcs (null, urlString, true);
- int qString = KDE.QString_new(buffer);
- int url = KDE.KURL_new(qString);
- KDE.QString_delete(qString);
- int mimeType = KDE.KMimeType_findByURL(url);
- if (mimeType == 0) return null;
- int mimeIcon = KDE.KMimeType_icon(mimeType, 0, 0);
- int loader = KDE.KGlobal_iconLoader();
- int path = KDE.KIconLoader_iconPath(loader, mimeIcon, KDE.KICON_SMALL, 1);
- iconPath = kde_convertQStringAndFree(path);
- break;
- case DESKTOP_GNOME:
- String fakeFileName = "file." + extension;
- String mime = gnome_getMimeType(fakeFileName);
- if (mime == null) return null;
- iconPath = gnome_getMimeValue(mime, "icon-filename");
- if (iconPath == null) return null;
- break;
- case DESKTOP_UNKNOWN:
- return null;
- }
- if (iconPath.endsWith ("xpm")) {
- //BAD
- Display display = Display.getCurrent ();
- int xDisplay = display.xDisplay;
- int drawable = OS.XDefaultRootWindow (xDisplay);
- int [] pixmap_ptr = new int [1], mask_ptr = new int [1];
- byte [] buffer = Converter.wcsToMbcs (null, iconPath, true);
- int result = OS.XpmReadFileToPixmap (xDisplay, drawable, buffer, pixmap_ptr, mask_ptr, 0);
- if (result < 0) return null;
- Image image = Image.motif_new (display, SWT.BITMAP, pixmap_ptr[0], mask_ptr [0]);
- ImageData imageData = image.getImageData ();
- image.dispose ();
- return imageData;
- }
- try {
- return new ImageData (iconPath);
- } catch (Exception e) {
- return null;
- }
-}
-
-/*
- * Returns the receiver's name. This is as short and
- * descriptive a name as possible for the program. If
- * the program has no descriptive name, this string may
- * be the executable name, path or empty.
- *
- * @return an the name of the program
- */
-public String getName () {
- return name;
-}
-
-public String toString () {
- return "Program {" + name + "}";
-}
-static boolean gnome_init () {
- try {
- Callback.loadLibrary("swt-gnome");
- } catch (UnsatisfiedLinkError e) {
- return false;
- }
- return true;
-}
-
-}
+ */
+public final class Program {
+ String name;
+ String extension;
+ String command;
+ Display display;
+
+ static private final String cdeShell = "Program_CDE_SHELL"; // hidden shell used for DtAppInitialize and DtActionInvoke
+ static private final String[] cdeIconExt = { ".m.pm", ".l.pm", ".s.pm", ".t.pm" };
+ static private final String[] cdeMaskExt = { ".m_m.bm", ".l_m.bm", ".s_m.bm", ".t_m.bm" };
+ static private final String desktopData = "Program_DESKTOP";
+
+ static final int DESKTOP_UNKNOWN = 0;
+ static final int DESKTOP_KDE = 1;
+ static final int DESKTOP_GNOME = 2;
+ static final int DESKTOP_CDE = 3;
+
+/**
+ * Prevents uninitialized instances from being created outside the package.
+ */
+Program () {
+}
+
+/* Determine the desktop for the given display. */
+static int getDesktop( Display display ) {
+ if (display == null) return DESKTOP_UNKNOWN;
+
+ // If the desktop type for this display is already known, return it.
+ Integer desktopValue = (Integer) display.getData( desktopData );
+ if (desktopValue != null) {
+ return desktopValue.intValue();
+ }
+
+ // Obtain the atoms for the various window manager signature properties.
+ int desktop = DESKTOP_UNKNOWN;
+ int xDisplay = display.xDisplay;
+ /* Use the character encoding for the default locale */
+ byte[] gnomeName = Converter.wcsToMbcs (null, "GNOME_NAME_SERVER", true);
+ byte[] cdeName = Converter.wcsToMbcs (null, "DTWM_IS_RUNNING", true);
+ byte[] kdeName = Converter.wcsToMbcs (null, "KWIN_RUNNING", true);
+ int gnome = OS.XInternAtom( xDisplay, gnomeName, true );
+ int cde = OS.XInternAtom( xDisplay, cdeName, true );
+ int kde = OS.XInternAtom( xDisplay, kdeName, true );
+
+ // Get the list of properties on the root window.
+ int rootWindow = OS.XDefaultRootWindow( xDisplay );
+ int[] numProp = new int[1];
+ int propList = OS.XListProperties( xDisplay, rootWindow, numProp );
+ if (propList == 0) return DESKTOP_UNKNOWN;
+ int[] property = new int[ numProp[0] ];
+ OS.memmove( property, propList, (property.length * 4) );
+ OS.XFree( propList );
+
+ // A given WM (desktop) is active if the property exists on the root window.
+ for (int index = 0; desktop == DESKTOP_UNKNOWN && index < property.length; index++) {
+ if (property[ index ] == OS.None) continue; // do not match atoms that do not exist
+ if (property[ index ] == gnome) {
+ if (gnome_init()) desktop = DESKTOP_GNOME;
+ }
+ if (property[ index ] == cde) {
+ if (cde_init( display )) desktop = DESKTOP_CDE;
+ }
+ if (property[ index ] == kde) {
+ if (kde_init()) desktop = DESKTOP_KDE;
+ }
+ }
+
+ // Save the desktop type on the display itself.
+ display.setData( desktopData, new Integer(desktop) );
+ return desktop;
+}
+
+/**
+ * Finds the program that is associated with an extension.
+ * The extension may or may not begin with a '.'.
+ *
+ * @param extension the program extension
+ * @return the program or nil
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_NULL_ARGUMENT when extension is null</li>
+ * </ul>
+ */
+public static Program findProgram (String extension) {
+ return findProgram( Display.getCurrent(), extension );
+}
+
+/*
+ * API: When support for multiple displays is added, this method will
+ * become public and the original method above can be deprecated.
+ */
+private static Program findProgram( Display display, String extension ) {
+ if (extension == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ if (extension.length () == 0) return null;
+ if (extension.charAt (0) != '.') extension = "." + extension;
+ String command = null;
+ String name = null;
+ int desktop = getDesktop( display );
+ Hashtable mimeInfo = null;
+ if (desktop == DESKTOP_KDE) mimeInfo = kde_getMimeInfo();
+ if (desktop == DESKTOP_GNOME) mimeInfo = gnome_getMimeInfo();
+ if (desktop == DESKTOP_CDE) mimeInfo = cde_getDataTypeInfo();
+ if (mimeInfo == null) return null;
+
+ // Find the data type matching the extension.
+ Iterator keys = mimeInfo.keySet().iterator();
+ while (name == null && keys.hasNext()) {
+ String mimeType = (String) keys.next();
+ Vector mimeExts = (Vector) mimeInfo.get( mimeType );
+ for (int index = 0; index < mimeExts.size(); index++){
+ if (extension.equals( mimeExts.elementAt( index ) )) {
+ name = mimeType;
+ }
+ }
+ }
+ if (name == null) return null;
+
+ // Get the corresponding command for the mime type.
+ if (desktop == DESKTOP_KDE) command = kde_getMimeTypeCommand( name );
+ if (desktop == DESKTOP_GNOME) command = gnome_getMimeValue( name, "open" );
+ if (desktop == DESKTOP_CDE) command = cde_getAction( name );
+ if (command == null) return null;
+
+ // Return the corresponding program.
+ Program program = new Program ();
+ program.name = name;
+ program.command = command;
+ program.extension = extension;
+ program.display = display;
+ return program;
+}
+
+/**
+ * Answer all program extensions in the operating system.
+ *
+ * @return an array of extensions
+ */
+public static String [] getExtensions () {
+ return getExtensions( Display.getCurrent() );
+}
+
+/*
+ * API: When support for multiple displays is added, this method will
+ * become public and the original method above can be deprecated.
+ */
+private static String[] getExtensions( Display display ) {
+ int desktop = getDesktop( display );
+ Hashtable mimeInfo = null;
+ if (desktop == DESKTOP_KDE) mimeInfo = kde_getMimeInfo();
+ if (desktop == DESKTOP_GNOME) mimeInfo = gnome_getMimeInfo();
+ if (desktop == DESKTOP_CDE) mimeInfo = cde_getDataTypeInfo();
+ if (mimeInfo == null) return new String[0];
+
+
+ // Create a unique set of the file extensions.
+ Vector extensions = new Vector();
+ Iterator keys = mimeInfo.keySet().iterator();
+ while (keys.hasNext()) {
+ String mimeType = (String) keys.next();
+ Vector mimeExts = (Vector) mimeInfo.get( mimeType );
+ for (int index = 0; index < mimeExts.size(); index++){
+ if (!extensions.contains( mimeExts.elementAt( index ) )) {
+ extensions.add( mimeExts.elementAt( index ) );
+ }
+ }
+ }
+
+ // Return the list of extensions.
+ String[] extStrings = new String[ extensions.size() ];
+ for (int index = 0; index < extensions.size(); index++) {
+ extStrings[ index ] = (String) extensions.elementAt( index );
+ }
+ return extStrings;
+}
+
+/**
+ * Answers all available programs in the operating system.
+ *
+ * @return an array of programs
+ */
+public static Program [] getPrograms () {
+ return getPrograms( Display.getCurrent() );
+}
+
+/*
+ * API: When support for multiple displays is added, this method will
+ * become public and the original method above can be deprecated.
+ */
+private static Program[] getPrograms( Display display ) {
+ int desktop = getDesktop( display );
+ Hashtable mimeInfo = null;
+ if (desktop == DESKTOP_KDE) mimeInfo = kde_getMimeInfo();
+ if (desktop == DESKTOP_GNOME) mimeInfo = gnome_getMimeInfo();
+ if (desktop == DESKTOP_CDE) mimeInfo = cde_getDataTypeInfo();
+ if (mimeInfo == null) return new Program[0];
+
+ // Create a list of programs with commands.
+ Vector programs = new Vector();
+ Iterator keys = mimeInfo.keySet().iterator();
+ while (keys.hasNext()) {
+ String mimeType = (String) keys.next();
+ Vector mimeExts = (Vector) mimeInfo.get( mimeType );
+ String extension = "";
+ if (mimeExts.size() > 0){
+ extension = (String) mimeExts.elementAt( 0 );
+ }
+ String command = null;
+ if (desktop == DESKTOP_KDE) command = kde_getMimeTypeCommand( mimeType );
+ if (desktop == DESKTOP_GNOME) command = gnome_getMimeValue( mimeType, "open" );
+ if (desktop == DESKTOP_CDE) command = cde_getAction( mimeType );
+ if (command != null) {
+ Program program = new Program ();
+ program.name = mimeType;
+ program.command = command;
+ program.extension = extension;
+ program.display = display;
+ programs.add( program );
+ }
+ }
+
+ // Return the list of programs to the user.
+ Program[] programList = new Program[ programs.size() ];
+ for (int index = 0; index < programList.length; index++) {
+ programList[ index ] = (Program) programs.elementAt( index );
+ }
+ return programList;
+}
+
+/*
+ * Obtain the registered mime type information and
+ * return it in a map. The key of each entry
+ * in the map is the mime type name. The value is
+ * a vector of the associated file extensions.
+ */
+
+private static Hashtable gnome_getMimeInfo() {
+ Hashtable mimeInfo = new Hashtable();
+
+ // Extract the mime info from the system directory.
+ String mimeDirectory = gnome_getDataDirectory ("mime-info");
+ gnome_getMimeInfoFromDirectory( mimeInfo, new File( mimeDirectory ) );
+
+ // Append the mime info from the user's directory (if it exists).
+ String userDirectory = gnome_getHomeDirectory();
+ if (userDirectory != null) {
+ userDirectory = userDirectory + File.separator + ".gnome" + File.separator + "mime-info";
+ gnome_getMimeInfoFromDirectory( mimeInfo, new File( userDirectory ) );
+ }
+
+ return mimeInfo;
+}
+
+// Given a map and a directory, find all of the
+// mime information files (*.mime) and parse them for
+// relavent mime type information. Each entry in the
+// map corresponds to one mime type, and its
+// associated file extensions.
+
+private static void gnome_getMimeInfoFromDirectory( Hashtable info, File directory ) {
+ // For each entry in the given directory (if it exists)
+ if (directory.exists()) {
+ File[] files = directory.listFiles();
+ for (int i = 0; i < files.length; i++) {
+
+ // If the entry is a subdirectory, process it and
+ // merge the mime type into the given map.
+ if (files[i].isDirectory()) {
+ gnome_getMimeInfoFromDirectory( info, files[i] );
+ }
+
+ // else if the entry is a mime info file (*.mime)
+ else if (files[i].getName().endsWith(".mime")) {
+ try {
+ // Parse the mime file and merge the info
+ // into the given map.
+ FileReader in = new FileReader( files[i] );
+ BufferedReader reader = new BufferedReader( in );
+ gnome_parseMimeFile( info, reader );
+ reader.close();
+ in.close();
+ }
+ catch (IOException e) {
+ // Ignore file exceptions silently. If we
+ // can't read it, the info is not available.
+ }
+ }
+ }
+ }
+}
+
+private static void gnome_parseMimeFile( Hashtable info, BufferedReader reader ) {
+ Vector mimeExts = null;
+ String mimeType = null;
+ boolean saveType = false;
+ String line = "#";
+ while (line != null) {
+
+ // Determine if the line contains a mime type name.
+ boolean newType = (line.length() > 0 && Character.isLetter( line.charAt(0) ));
+
+ // If there is valid data on this line to be processed
+ String data = line.trim();
+ if (data.length() > 0 && data.charAt(0) != '#') {
+
+ // If this line defines a new mime type
+ if (newType) {
+
+ // If a previous mime type has not be saved yet
+ if (mimeType != null) {
+ // Save the type and process this line again.
+ saveType = true;
+ }
+ // else initialize the mime type info
+ else {
+ int colon = data.indexOf( ':' );
+ if (colon != -1) {
+ mimeType = data.substring( 0, colon );
+ }
+ else {
+ mimeType = data;
+ }
+ mimeExts = new Vector();
+ }
+ }
+
+ // else if the line defines a list of extensions
+ else if (data.indexOf( "ext" ) == 0 && mimeType != null) {
+
+ // Get the extensions defined on the line
+ String exts = "";
+ int colon = data.indexOf( ':' );
+ if ((colon != -1) && ((colon+1) < data.length())) {
+ exts = data.substring( (colon+1) ).trim();
+ }
+
+ // While there are extensions to be processed (use space as separator)
+ exts = exts.replace( '\t', ' ' );
+ exts = exts.replace( ',', ' ' );
+ while (exts.length() != 0) {
+ // Extract the next entension from the list
+ String newExt;
+ int space = exts.indexOf( ' ' );
+ if (space != -1) {
+ newExt = exts.substring( 0, space );
+ exts = exts.substring( space ).trim();
+ }
+ else {
+ newExt = exts;
+ exts = "";
+ }
+
+ // Prefix an extension with a period.
+ if (newExt.charAt(0) != '.') {
+ newExt = "." + newExt;
+ }
+ mimeExts.add( newExt );
+ }
+ }
+
+ // else if the line defines a list of regular expressions
+ else if (data.indexOf( "regex" ) == 0 && mimeType != null) {
+ // Do nothing with these right now.
+ }
+ }
+
+
+ // If the current mime type is still being processed
+ if (!saveType) {
+ // Get the next line
+ try {
+ line = reader.readLine();
+ }
+ catch (IOException e) {
+ line = null;
+ }
+ }
+
+ // If the current type should be saved or if the end
+ // of the file was reached
+ if (saveType || (line == null)) {
+ // If there is a mime type to be saved
+ if (mimeType != null) {
+
+ // If the mime type does not exist in the map, add it.
+ Vector prevExts = (Vector) info.get( mimeType );
+ if (prevExts == null) {
+ info.put( mimeType, mimeExts );
+ }
+
+ // else append the new list of extensions.
+ else {
+ for (int i = 0; i < mimeExts.size(); i++) {
+ prevExts.add( mimeExts.elementAt( i ) );
+ }
+ }
+ }
+ mimeType = null;
+ mimeExts = null;
+ saveType = false;
+ }
+ }
+}
+
+// Private method for parsing a command line into its arguments.
+private static String[] parseCommand( String cmd ) {
+ Vector args = new Vector();
+ int sIndex = 0;
+ int eIndex;
+ while (sIndex < cmd.length()) {
+ // Trim initial white space of argument.
+ while (sIndex < cmd.length() && Character.isWhitespace( cmd.charAt(sIndex) )) {
+ sIndex++;
+ }
+ if (sIndex < cmd.length()) {
+ // If the command is a quoted string
+ if (cmd.charAt(sIndex) == '"' || cmd.charAt(sIndex) == '\''){
+ // Find the terminating quote (or end of line).
+ // This code currently does not handle escaped characters (e.g., " a\"b").
+ eIndex = sIndex + 1;
+ while (eIndex < cmd.length() && cmd.charAt(eIndex) != cmd.charAt(sIndex)) {
+ eIndex++;
+ }
+ if (eIndex >= cmd.length()) { // the terminating quote was not found
+ // Add the argument as is with only one initial quote.
+ args.add( cmd.substring( sIndex, eIndex ) );
+ }
+ // else add the argument, trimming off the quotes.
+ else {
+ args.add( cmd.substring( sIndex+1, eIndex ) );
+ }
+ sIndex = eIndex + 1;
+ }
+
+ // else use white space for the delimiters.
+ else {
+ eIndex = sIndex;
+ while (eIndex < cmd.length() && !Character.isWhitespace( cmd.charAt(eIndex) )) {
+ eIndex++;
+ }
+ args.add( cmd.substring( sIndex, eIndex ) );
+ sIndex = eIndex + 1;
+ }
+ }
+ }
+
+ String[] strings = new String[ args.size() ];
+ for (int index =0; index < args.size(); index++) {
+ strings[ index ] = (String) args.elementAt( index );
+ }
+ return strings;
+}
+
+
+static String gnome_getDataDirectory(String dirName) {
+ /* Use the character encoding for the default locale */
+ byte [] nameBuffer = Converter.wcsToMbcs (null, dirName, true);
+ int ptr = GNOME.gnome_datadir_file(nameBuffer);
+ if (ptr == 0) return null;
+ int length = OS.strlen(ptr);
+ byte[] dirBuffer = new byte[length];
+ OS.memmove(dirBuffer, ptr, length);
+ /* Use the character encoding for the default locale */
+ return new String(Converter.mbcsToWcs(null, dirBuffer));
+}
+
+static String gnome_getHomeDirectory() {
+ int ptr = GNOME.g_get_home_dir();
+ if (ptr == 0) return null;
+ int length = OS.strlen(ptr);
+ byte[] homeDirBuffer = new byte[length];
+ OS.memmove(homeDirBuffer, ptr, length);
+ /* Use the character encoding for the default locale */
+ return new String(Converter.mbcsToWcs(null, homeDirBuffer));
+}
+
+static String gnome_getMimeType(String name) {
+ /* Use the character encoding for the default locale */
+ byte [] nameBuffer = Converter.wcsToMbcs (null, name, true);
+ int ptr = GNOME.gnome_mime_type(nameBuffer);
+ if (ptr == 0) return null;
+ int length = OS.strlen(ptr);
+ byte[] mimeBuffer = new byte[length];
+ OS.memmove(mimeBuffer, ptr, length);
+ /* Use the character encoding for the default locale */
+ return new String(Converter.mbcsToWcs(null, mimeBuffer));
+}
+
+static String gnome_getMimeValue(String mimeType, String key) {
+ /* Use the character encoding for the default locale */
+ byte [] typeBuffer = Converter.wcsToMbcs (null, mimeType, true);
+ byte [] keyBuffer = Converter.wcsToMbcs (null, key, true);
+ int ptr = GNOME.gnome_mime_get_value(typeBuffer, keyBuffer);
+ if (ptr == 0) return null;
+
+ StringBuffer stringBuffer = new StringBuffer();
+ int length = OS.strlen(ptr);
+ byte[] valueBuffer = new byte[length];
+ OS.memmove(valueBuffer, ptr, length);
+ /* Use the character encoding for the default locale */
+ return new String(Converter.mbcsToWcs(null, valueBuffer));
+}
+
+static boolean kde_init () {
+ try {
+ Callback.loadLibrary("swt-kde");
+ } catch (UnsatisfiedLinkError e) {
+ return false;
+ }
+
+ /* Use the character encoding for the default locale */
+ byte [] nameBuffer = Converter.wcsToMbcs( null, "SWT", true );
+ int qcString = KDE.QCString_new( nameBuffer );
+ KDE.KApplication_new( qcString );
+ KDE.QCString_delete( qcString );
+ return true;
+}
+
+private static String kde_getMimeTypeCommand( String mimeType ) {
+ /* Use the character encoding for the default locale */
+ byte [] buffer = Converter.wcsToMbcs (null, mimeType, true);
+ int qMimeType = KDE.QString_new( buffer );
+ int serviceList = KDE.KMimeType_offers( qMimeType );
+ KDE.QString_delete( qMimeType );
+ if (serviceList == 0) return null;
+ KDE.KServiceList_delete( serviceList );
+ return "KRun::runURL(url,mimeType)";
+}
+/*
+ * Obtain the registered mime type information and
+ * return it in a map. The key of each entry
+ * in the map is the mime type name. The value is
+ * a vector of the associated file extensions.
+ */
+
+private static Hashtable kde_getMimeInfo() {
+ Hashtable mimeInfo = new Hashtable();
+ Vector mimeExts = null;
+ String mimeType;
+
+ // Get the list of all mime types available.
+ int mimeTypeList = KDE.KMimeType_allMimeTypes();
+ int iterator = KDE.KMimeTypeList_begin( mimeTypeList );
+ int listEnd = KDE.KMimeTypeList_end( mimeTypeList );
+ while (KDE.KMimeTypeListIterator_equals( iterator, listEnd ) == 0) {
+ // Get the next KMimeType from the list.
+ int kMimeType = KDE.KMimeTypeListIterator_dereference( iterator );
+
+ // Get the mime type name.
+ int mimeName = KDE.KMimeType_name( kMimeType );
+ mimeType = kde_convertQStringAndFree( mimeName );
+
+ // Get the list of extension patterns.
+ mimeExts = new Vector();
+ String extension;
+
+ // Add the mime type to the hash table with its extensions.
+ int patternList = KDE.KMimeType_patterns( kMimeType );
+ int patIterator = KDE.QStringList_begin( patternList );
+ int patListEnd = KDE.QStringList_end( patternList );
+ while (KDE.QStringListIterator_equals( patIterator, patListEnd ) == 0) {
+ // Get the next extension pattern from the list.
+ int patString = KDE.QStringListIterator_dereference( patIterator );
+ extension = kde_convertQStringAndFree( patString );
+ int period = extension.indexOf( '.' );
+ if (period != -1) {
+ mimeExts.add( extension.substring( period ) );
+ }
+
+ // Advance to the next pattern.
+ KDE.QStringListIterator_increment( patIterator );
+ }
+ KDE.QStringListIterator_delete( patIterator );
+ KDE.QStringListIterator_delete( patListEnd );
+ KDE.QStringList_delete( patternList );
+
+ // If there is at least one extension, save the mime type.
+ if (mimeExts.size() > 0) {
+ mimeInfo.put( mimeType, mimeExts );
+ }
+
+ // Advance to the next mime type.
+ KDE.KMimeTypeListIterator_increment( iterator );
+ }
+ KDE.KMimeTypeListIterator_delete( iterator );
+ KDE.KMimeTypeListIterator_delete( listEnd );
+ KDE.KMimeTypeList_delete( mimeTypeList );
+
+ return mimeInfo;
+}
+
+static String kde_convertQStringAndFree (int qString) {
+ int qCString = KDE.QString_utf8 (qString);
+ int charString = KDE.QCString_data (qCString);
+
+ StringBuffer stringBuffer = new StringBuffer ();
+ int length = KDE.strlen (charString);
+ byte[] buffer = new byte [length];
+ KDE.memmove (buffer, charString, length);
+ /* Use the character encoding for the default locale */
+ String answer = new String (Converter.mbcsToWcs (null, buffer));
+
+ KDE.QCString_delete (qCString);
+ KDE.QString_delete (qString);
+ return answer;
+}
+
+/**
+ * Launches the executable associated with the file in
+ * the operating system. If the file is an executable,
+ * then the executable is launched.
+ *
+ * @param fileName the file or program name
+ * @return <code>true</code> if the file is launched, otherwise <code>false</code>
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_NULL_ARGUMENT when fileName is null</li>
+ * </ul>
+ */
+public static boolean launch (String fileName) {
+ return launch( Display.getCurrent(), fileName );
+}
+
+/*
+ * API: When support for multiple displays is added, this method will
+ * become public and the original method above can be deprecated.
+ */
+private static boolean launch( Display display, String fileName ) {
+ if (fileName == null) SWT.error( SWT.ERROR_NULL_ARGUMENT );
+
+ // If the argument appears to be a data file (it has an extension)
+ int index = fileName.lastIndexOf(".");
+ if (index > 0) {
+
+ // Find the associated program, if one is defined.
+ String extension = fileName.substring( index );
+ Program program = Program.findProgram( display, extension );
+
+ // If the associated program is defined and can be executed, return.
+ if (program != null && program.execute( fileName )) return true;
+ }
+
+ // Otherwise, the argument was the program itself.
+ try {
+ Runtime.getRuntime().exec( fileName );
+ return true;
+ } catch (IOException e) {
+ return false;
+ }
+}
+
+/**
+ * Executes the program with the file as the single argument
+ * in the operating system. It is the responsibility of the
+ * programmer to ensure that the file contains valid data for
+ * this program.
+ *
+ * @param fileName is the argument (typically a file) for the program
+ * @return <code>true</code> if the file is launched, otherwise <code>false</code>
+ *
+ * @exception SWTError <ul>
+ * <li>ERROR_NULL_ARGUMENT when fileName is null</li>
+ * </ul>
+ */
+public boolean execute (String fileName) {
+ if (fileName == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+
+ switch (getDesktop( display )) {
+ case DESKTOP_KDE: {
+ String urlString = "file://" + fileName;
+ /* Use the character encoding for the default locale */
+ byte[] buffer = Converter.wcsToMbcs( null, urlString, true );
+ int qString = KDE.QString_new( buffer );
+ int url = KDE.KURL_new( qString );
+ KDE.QString_delete( qString );
+ /* Use the character encoding for the default locale */
+ buffer = Converter.wcsToMbcs (null, name, true);
+ int mimeTypeName = KDE.QString_new( buffer );
+ int pid = KDE.KRun_runURL( url, mimeTypeName );
+ KDE.KURL_delete( url );
+ KDE.QString_delete( mimeTypeName );
+ return (pid != 0);
+ }
+
+ case DESKTOP_GNOME: {
+ // Parse the command into its individual arguments.
+ String[] args = parseCommand( command );
+ int fileArg = -1;
+ int index;
+ for (index=0; index < args.length; index++) {
+ int j = args[ index ].indexOf( "%f" );
+ if (j != -1) {
+ String value = args[ index ];
+ fileArg = index;
+ args[ index ] = value.substring(0,j) + fileName + value.substring(j+2);
+ }
+ }
+
+ // If a file name was given but the command did not have "%f"
+ if ((fileName.length() > 0) && (fileArg < 0)) {
+ String[] newArgs = new String[ args.length + 1 ];
+ for (index=0; index < args.length; index++)
+ newArgs[ index ] = args[ index ];
+ newArgs[ args.length ] = fileName;
+ args = newArgs;
+ }
+
+ // Execute the command.
+ try {
+ Runtime.getRuntime().exec( args );
+ } catch (IOException e) {
+ return false;
+ }
+ return true;
+ }
+
+ case DESKTOP_CDE: {
+ /* Use the character encoding for the default locale */
+ byte[] action = Converter.wcsToMbcs( null, command, true );
+ byte[] fileArg = Converter.wcsToMbcs( null, fileName, true );
+ Integer shell = (Integer) display.getData( cdeShell );
+ int actionID = 0;
+ if (shell != null) {
+ actionID = CDE.DtActionInvoke( shell.intValue(), action, fileArg, 1, null, null, null, 1, 0, 0 );
+ }
+ return (actionID != 0);
+ }
+ }
+
+ return false;
+}
+
+/**
+ * Returns the receiver's image data. This is the icon
+ * that is associated with the reciever in the operating
+ * system.
+ *
+ * @return the image data for the program, may be null
+ */
+public ImageData getImageData () {
+ String iconPath = null;
+ switch (getDesktop( display )) {
+ case DESKTOP_KDE: {
+ /* Use the character encoding for the default locale */
+ byte [] buffer = Converter.wcsToMbcs (null, name, true);
+ int mimeTypeName = KDE.QString_new( buffer );
+ int mimeType = KDE.KMimeType_mimeType( mimeTypeName );
+ KDE.QString_delete( mimeTypeName );
+ if (mimeType == 0) return null;
+ int mimeIcon = KDE.KMimeType_icon(mimeType, 0, 0);
+ int loader = KDE.KGlobal_iconLoader();
+ int path = KDE.KIconLoader_iconPath(loader, mimeIcon, KDE.KICON_SMALL, 1);
+ if (path == 0) return null;
+ iconPath = kde_convertQStringAndFree(path);
+ break;
+ }
+
+ case DESKTOP_GNOME: {
+ String fakeFileName = "file" + extension;
+ String mime = gnome_getMimeType(fakeFileName);
+ if (mime == null) return null;
+ iconPath = gnome_getMimeValue(mime, "icon-filename");
+ if (iconPath == null) return null;
+ break;
+ }
+
+ case DESKTOP_CDE: {
+ return cde_getImageData();
+ }
+
+ case DESKTOP_UNKNOWN: {
+ return null;
+ }
+ }
+ if (iconPath.endsWith ("xpm")) {
+ int xDisplay = display.xDisplay;
+ int screen = OS.XDefaultScreenOfDisplay( xDisplay );
+ int fgPixel = OS.XWhitePixel( display.xDisplay, OS.XDefaultScreen( xDisplay ) );
+ int bgPixel = OS.XBlackPixel( display.xDisplay, OS.XDefaultScreen( xDisplay ) );
+ /* Use the character encoding for the default locale */
+ byte [] iconName = Converter.wcsToMbcs (null, iconPath, true);
+ int pixmap = OS.XmGetPixmap( screen, iconName, fgPixel, bgPixel );
+ if (pixmap == OS.XmUNSPECIFIED_PIXMAP) return null;
+ Image image = Image.motif_new (display, SWT.BITMAP, pixmap, 0);
+ ImageData imageData = image.getImageData ();
+
+ // The pixmap returned from XmGetPixmap is cached by Motif
+ // and must be deleted by XmDestroyPixmap. Because it cannot
+ // be deleted directly by XFreePixmap, image.dispose() must not
+ // be called. The following code should do an equivalent image.dispose().
+ OS.XmDestroyPixmap( screen, pixmap );
+ return imageData;
+ }
+ try {
+ return new ImageData (iconPath);
+ } catch (Exception e) {
+ return null;
+ }
+}
+
+/**
+ * Returns the receiver's name. This is as short and
+ * descriptive a name as possible for the program. If
+ * the program has no descriptive name, this string may
+ * be the executable name, path or empty.
+ *
+ * @return an the name of the program
+ */
+public String getName () {
+ return name;
+}
+
+/**
+ * Returns true if the receiver and the argument represent
+ * the same program.
+ *
+ * @return true if the programs are the same
+ */
+public boolean equals(Object other) {
+ if (this == other) return true;
+ if (other instanceof Program) {
+ final Program program = (Program) other;
+ return display == program.display && extension.equals(program.extension) &&
+ name.equals(program.name) && command.equals(program.command);
+ }
+ return false;
+}
+
+/**
+ * Returns a hash code suitable for this object.
+ *
+ * @return a hash code
+ */
+public int hashCode() {
+ return extension.hashCode() ^ name.hashCode() ^ command.hashCode() ^ display.hashCode();
+}
+
+public String toString () {
+ return "Program {" + name + "}";
+}
+static boolean gnome_init () {
+ try {
+ Callback.loadLibrary("swt-gnome");
+ } catch (UnsatisfiedLinkError e) {
+ return false;
+ }
+ return true;
+}
+
+/* CDE - Get Attribute Value
+ *
+ * This method takes a data type name and an attribute name, and returns
+ * the corresponding attribute value.
+ */
+
+static String cde_getAttribute(String dataType, String attrName) {
+ /* Use the character encoding for the default locale */
+ byte [] dataTypeBuf = Converter.wcsToMbcs (null, dataType, true);
+ byte [] attrNameBuf = Converter.wcsToMbcs (null, attrName, true);
+ byte [] optNameBuf = null;
+ int attrValue = CDE.DtDtsDataTypeToAttributeValue( dataTypeBuf, attrNameBuf, optNameBuf );
+ if (attrValue == 0) return null;
+ int length = OS.strlen(attrValue);
+ byte[] attrValueBuf = new byte[length];
+ OS.memmove(attrValueBuf, attrValue, length);
+ CDE.DtDtsFreeAttributeValue( attrValue );
+ /* Use the character encoding for the default locale */
+ return new String(Converter.mbcsToWcs(null, attrValueBuf));
+}
+
+/* CDE - Get Default Action of Data Type
+ *
+ * This method takes a data type and returns the corresponding default action.
+ * By default, the "Open" action is used if it is available. If it is not
+ * available, the first action in the list is used. Typically, if Open is not
+ * available, there is usually only one action anyways.
+ */
+
+static String cde_getAction(String dataType) {
+ String action = null;
+ String actions = cde_getAttribute( dataType, CDE.DtDTS_DA_ACTION_LIST );
+ if (actions != null) {
+ int index = actions.indexOf( "Open" );
+ if (index != -1) {
+ action = actions.substring( index, index+4 );
+ }
+ else {
+ index = actions.indexOf( "," );
+ if (index != -1) {
+ action = actions.substring( 0, index );
+ }
+ else {
+ action = actions;
+ }
+ }
+ }
+ return action;
+}
+
+/* CDE - Get Extension of Data Type
+ *
+ * This method takes a data type and returns the corresponding extension.
+ * The extension is obtained from the NAME TEMPLATE attribute.
+ */
+
+static String cde_getExtension(String dataType) {
+ String fileExt = cde_getAttribute( dataType, CDE.DtDTS_DA_NAME_TEMPLATE );
+ if (fileExt == null || fileExt.indexOf( "%s." ) == -1) return null;
+ int dot = fileExt.indexOf( "." );
+ return fileExt.substring( dot );
+}
+
+/* CDE - Get Data Types
+ *
+ * This method returns the list of data type names available.
+ * Each data type returned is valid, meaning it has an action and
+ * an extension.
+ */
+
+static Hashtable cde_getDataTypeInfo() {
+ Hashtable dataTypeInfo = new Hashtable();
+ int index;
+ int dataTypeList = CDE.DtDtsDataTypeNames();
+ if (dataTypeList != 0) {
+ // For each data type name in the list
+ index = 0;
+ int dataType = CDE.listElementAt( dataTypeList, index++ );
+ while (dataType != 0) {
+ int length = OS.strlen(dataType);
+ byte[] dataTypeBuf = new byte[length];
+ OS.memmove(dataTypeBuf, dataType, length);
+ /* Use the character encoding for the default locale */
+ String dataTypeName = new String(Converter.mbcsToWcs(null, dataTypeBuf));
+
+ // The data type is valid if it is not an action, and it has an extension and an action.
+ String extension = cde_getExtension( dataTypeName );
+ if (!CDE.DtDtsDataTypeIsAction( dataTypeBuf ) &&
+ extension != null && cde_getAction( dataTypeName ) != null) {
+ Vector exts = new Vector();
+ exts.add( extension );
+ dataTypeInfo.put( dataTypeName, exts );
+ }
+ dataType = CDE.listElementAt( dataTypeList, index++ );
+ }
+ CDE.DtDtsFreeDataTypeNames( dataTypeList );
+ }
+
+ return dataTypeInfo;
+}
+
+/* CDE - Get Image Data
+ *
+ * This method returns the image data of the icon associated with
+ * the data type. Since CDE supports multiple sizes of icons, several
+ * attempts are made to locate an icon of the desired size and format.
+ * CDE supports the sizes: tiny, small, medium and large. The best
+ * search order is medium, large, small and then tiny. Althoug CDE supports
+ * colour and monochrome bitmaps, only colour icons are tried. (The order is
+ * defined by the cdeIconExt and cdeMaskExt arrays above.)
+ */
+
+ImageData cde_getImageData() {
+ int xDisplay = display.xDisplay;
+ int screen = OS.XDefaultScreenOfDisplay( xDisplay );
+ int fgPixel = OS.XWhitePixel( display.xDisplay, OS.XDefaultScreen( xDisplay ) );
+ int bgPixel = OS.XBlackPixel( display.xDisplay, OS.XDefaultScreen( xDisplay ) );
+
+ String icon = cde_getAttribute( name, CDE.DtDTS_DA_ICON );
+ byte [] iconName;
+ byte [] maskName = null;
+ int pixmap = 0;
+ for (int index = 0; index < cdeIconExt.length && pixmap == 0; index++) {
+ /* Use the character encoding for the default locale */
+ iconName = Converter.wcsToMbcs (null, icon + cdeIconExt[ index ], true);
+ maskName = Converter.wcsToMbcs (null, icon + cdeMaskExt[ index ], true);
+ pixmap = OS.XmGetPixmap( screen, iconName, fgPixel, bgPixel );
+ if (pixmap == OS.XmUNSPECIFIED_PIXMAP) pixmap = 0;
+ }
+
+ if (pixmap != 0) {
+ int type = SWT.ICON;
+ // When creating the mask pixmap, do not use the screen's white and black
+ // pixel for the foreground and background respectively, because on some
+ // X servers (e.g., Solaris) pixel 0 is white and pixel 1 is black. Passing
+ // (screen, name, whitePixel, blackPixel, 1) to get the mask pixmap will
+ // result in an inverted mask. Instead explicitly use 1 (FG) and 0 (BG).
+ int mask = OS.XmGetPixmapByDepth( screen, maskName, 1, 0, 1 );
+ if (mask == OS.XmUNSPECIFIED_PIXMAP) {
+ type = SWT.BITMAP;
+ mask = 0;
+ }
+ Image image = Image.motif_new (display, type, pixmap, mask );
+ ImageData imageData = image.getImageData();
+
+ // The pixmaps returned from XmGetPixmap... are cached by Motif
+ // and must be deleted by XmDestroyPixmap. Because they cannot
+ // be deleted directly by XFreePixmap, image.dispose() must not
+ // be called. The following code should do an equivalent image.dispose().
+ OS.XmDestroyPixmap( screen, pixmap );
+ if (mask != 0) OS.XmDestroyPixmap( screen, mask );
+ return imageData;
+ }
+ return null;
+}
+
+/* CDE - Initialize
+ *
+ * This method loads the swt-cde library and initializes CDE itself.
+ * The shell created fo DtAppInitialize is kept for DtActionInvoke calls.
+ */
+static boolean cde_init( Display display ) {
+ try {
+ Callback.loadLibrary("swt-cde");
+ } catch (UnsatisfiedLinkError e) {
+ return false;
+ }
+
+ /* Use the character encoding for the default locale */
+ byte[] appName = Converter.wcsToMbcs( null, "SWT", true );
+ int xtContext = OS.XtDisplayToApplicationContext( display.xDisplay );
+ int widgetClass = OS.TopLevelShellWidgetClass();
+ int shell = OS.XtAppCreateShell( appName, appName, widgetClass, display.xDisplay, null, 0 );
+ boolean initOK = CDE.DtAppInitialize( xtContext, display.xDisplay, shell, appName, appName );
+ if (!initOK) {
+ OS.XtDestroyWidget( shell );
+ }
+ else {
+ CDE.DtDbLoad();
+ display.setData( cdeShell, new Integer(shell) );
+ display.disposeExec( new Runnable() {
+ public void run() {
+ // This logic assumes that when the corresponding display is
+ // being disposed, it must be the current one.
+ Integer shell = (Integer) Display.getCurrent().getData( cdeShell );
+ if (shell != null) {
+ OS.XtDestroyWidget( shell.intValue() );
+ }
+ }
+ });
+ }
+ return initOK;
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/photon/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/photon/org/eclipse/swt/program/Program.java
index 319ecc5547..07e458932d 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Program/photon/org/eclipse/swt/program/Program.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Program/photon/org/eclipse/swt/program/Program.java
@@ -31,7 +31,7 @@ public final class Program {
Program () {
}
-/*
+/**
* Finds the program that is associated with an extension.
* The extension may or may not begin with a '.'.
*
@@ -48,7 +48,7 @@ public static Program findProgram (String extension) {
return null;
}
-/*
+/**
* Answer all program extensions in the operating system.
*
* @return an array of extensions
@@ -57,7 +57,7 @@ public static String [] getExtensions () {
return new String[0];
}
-/*
+/**
* Answers all available programs in the operating system.
*
* @return an array of programs
@@ -86,7 +86,7 @@ public static Program [] getPrograms () {
return programs;
}
-/*
+/**
* Launches the executable associated with the file in
* the operating system. If the file is an executable,
* then the executable is launched.
@@ -113,7 +113,7 @@ public static boolean launch (String fileName) {
}
}
-/*
+/**
* Executes the program with the file as the single argument
* in the operating system. It is the responsibility of the
* programmer to ensure that the file
@@ -139,18 +139,18 @@ public boolean execute (String fileName) {
return true;
}
-/*
+/**
* Returns the receiver's image data. This is the icon
* that is associated with the reciever in the operating
* system.
*
- * @return the image data for the program
+ * @return the image data for the program, may be null
*/
public ImageData getImageData () {
return null;
}
-/*
+/**
* Returns the receiver's name. This is as short and
* descriptive a name as possible for the program. If
* the program has no descriptive name, this string may
@@ -162,6 +162,31 @@ public String getName () {
return name;
}
+/**
+ * Returns true if the receiver and the argument represent
+ * the same program.
+ *
+ * @return true if the programs are the same
+ */
+public boolean equals(Object other) {
+ if (this == other) return true;
+ if (other instanceof Program) {
+ final Program program = (Program) other;
+ return extension.equals(program.extension) && name.equals(program.name) &&
+ command.equals(program.command);
+ }
+ return false;
+}
+
+/**
+ * Returns a hash code suitable for this object.
+ *
+ * @return a hash code
+ */
+public int hashCode() {
+ return extension.hashCode() ^ name.hashCode() ^ command.hashCode();
+}
+
public String toString () {
return "Program {" + name + "}";
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java
index 46925c3dc7..ce917ea12f 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java
@@ -28,7 +28,7 @@ public final class Program {
Program () {
}
-/*
+/**
* Finds the program that is associated with an extension.
* The extension may or may not begin with a '.'.
*
@@ -43,6 +43,7 @@ public static Program findProgram (String extension) {
if (extension == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
if (extension.length () == 0) return null;
if (extension.charAt (0) != '.') extension = "." + extension;
+ /* Use the character encoding for the default locale */
byte [] key = Converter.wcsToMbcs (0, extension, true);
int [] phkResult = new int [1];
if (OS.RegOpenKeyEx (OS.HKEY_CLASSES_ROOT, key, 0, OS.KEY_READ, phkResult) != 0) {
@@ -56,7 +57,7 @@ public static Program findProgram (String extension) {
return getProgram (lpData);
}
-/*
+/**
* Answer all program extensions in the operating system.
*
* @return an array of extensions
@@ -71,6 +72,7 @@ public static String [] getExtensions () {
while (length < key.length && key [length] != 0) length++;
byte [] buffer = new byte [length];
System.arraycopy (key, 0, buffer, 0, length);
+ /* Use the character encoding for the default locale */
String extension = new String (Converter.mbcsToWcs (0, buffer));
if (count == extensions.length) {
String [] newExtensions = new String [extensions.length + 1024];
@@ -99,6 +101,7 @@ static String getKeyValue (byte [] key) {
if (OS.RegQueryValueEx (phkResult [0], null, 0, null, null, lpcbData) == 0) {
byte [] lpData = new byte [lpcbData [0]];
if (OS.RegQueryValueEx (phkResult [0], null, 0, null, lpData, lpcbData) == 0) {
+ /* Use the character encoding for the default locale */
char [] charArray = Converter.mbcsToWcs (0, lpData);
result = new String (charArray, 0, charArray.length - 1);
}
@@ -110,6 +113,7 @@ static String getKeyValue (byte [] key) {
static Program getProgram (byte [] key) {
/* Command */
+ /* Use the character encoding for the default locale */
byte [] COMMAND = Converter.wcsToMbcs (0, "\\shell\\open\\command", true);
int length = 0;
while (length < key.length && key [length] != 0) length++;
@@ -124,6 +128,7 @@ static Program getProgram (byte [] key) {
if (name == null || name.length () == 0) return null;
/* Icon */
+ /* Use the character encoding for the default locale */
byte [] DEFAULT_ICON = Converter.wcsToMbcs (0, "\\DefaultIcon", true);
for (int i=0; i<DEFAULT_ICON.length; i++) key [length + i] = DEFAULT_ICON [i];
key [length + DEFAULT_ICON.length] = 0;
@@ -137,7 +142,7 @@ static Program getProgram (byte [] key) {
return program;
}
-/*
+/**
* Answers all available programs in the operating system.
*
* @return an array of programs
@@ -166,7 +171,7 @@ public static Program [] getPrograms () {
return programs;
}
-/*
+/**
* Launches the executable associated with the file in
* the operating system. If the file is an executable,
* then the executable is launched.
@@ -180,12 +185,13 @@ public static Program [] getPrograms () {
*/
public static boolean launch (String fileName) {
if (fileName == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ /* Use the character encoding for the default locale */
byte [] OPEN = Converter.wcsToMbcs (0, "open", true);
byte [] lpFile = Converter.wcsToMbcs (0, fileName, true);
return OS.ShellExecute (0, OPEN, lpFile, null, null, OS.SW_SHOW) > 32;
}
-/*
+/**
* Executes the program with the file as the single argument
* in the operating system. It is the responsibility of the
* programmer to ensure that the file contains valid data for
@@ -223,12 +229,12 @@ public boolean execute (String fileName) {
return true;
}
-/*
+/**
* Returns the receiver's image data. This is the icon
* that is associated with the reciever in the operating
* system.
*
- * @return the image data for the program
+ * @return the image data for the program, may be null
*/
public ImageData getImageData () {
int nIconIndex = 0;
@@ -241,6 +247,7 @@ public ImageData getImageData () {
nIconIndex = Integer.parseInt (iconIndex);
} catch (NumberFormatException e) {};
}
+ /* Use the character encoding for the default locale */
byte [] lpszFile = Converter.wcsToMbcs (0, fileName, true);
int [] phiconSmall = new int[1], phiconLarge = null;
OS.ExtractIconEx (lpszFile, nIconIndex, phiconLarge, phiconSmall, 1);
@@ -251,7 +258,7 @@ public ImageData getImageData () {
return imageData;
}
-/*
+/**
* Returns the receiver's name. This is as short and
* descriptive a name as possible for the program. If
* the program has no descriptive name, this string may
@@ -263,6 +270,31 @@ public String getName () {
return name;
}
+/**
+ * Returns true if the receiver and the argument represent
+ * the same program.
+ *
+ * @return true if the programs are the same
+ */
+public boolean equals(Object other) {
+ if (this == other) return true;
+ if (other instanceof Program) {
+ final Program program = (Program) other;
+ return name.equals(program.name) && command.equals(program.command)
+ && iconName.equals(program.iconName);
+ }
+ return false;
+}
+
+/**
+ * Returns a hash code suitable for this object.
+ *
+ * @return a hash code
+ */
+public int hashCode() {
+ return name.hashCode() ^ command.hashCode() ^ iconName.hashCode();
+}
+
public String toString () {
return "Program {" + name + "}";
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c b/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c
index 5e98e3ca6a..e2cc13a6e7 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c
@@ -152,8 +152,8 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_Callback_bind
isStatic = (*env)->GetBooleanField(env,lpCallback,PGLOB(isStaticID));
argCount = (*env)->GetIntField(env,lpCallback,PGLOB(argCountID));
isArrayBased = (*env)->GetBooleanField(env,lpCallback,PGLOB(isArrayBasedID));
- methodString = (*env)->GetStringUTFChars(env, javaMethod, NULL);
- sigString = (*env)->GetStringUTFChars(env, javaSignature, NULL);
+ methodString = (const char *) (*env)->GetStringUTFChars(env, javaMethod, NULL);
+ sigString = (const char *) (*env)->GetStringUTFChars(env, javaSignature, NULL);
if (isStatic) {
mid = (*env)->GetStaticMethodID(env, javaObject, methodString, sigString);
} else {
@@ -236,72 +236,73 @@ JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_Callback_getEnabled
int callback(int index, ...)
{
- if (!CallbacksEnabled) {
- return 0;
- } else {
- DECL_GLOB(pGlob)
- jobject callback = PGLOB(dllCallbackInfo)[index].callin;
- JNIEnv *env = PGLOB(dllCallbackInfo)[index].env;
- jmethodID mid = PGLOB(dllCallbackInfo)[index].methodID;
- jobject javaObject;
- jboolean isStatic, isArrayBased;
-
- int result = 0;
- va_list vl;
+ if (!CallbacksEnabled) {
+ return 0;
+ } else {
+
+ DECL_GLOB(pGlob)
+ jobject callback = PGLOB(dllCallbackInfo)[index].callin;
+ JNIEnv *env = PGLOB(dllCallbackInfo)[index].env;
+ jmethodID mid = PGLOB(dllCallbackInfo)[index].methodID;
+ jobject javaObject;
+ jboolean isStatic, isArrayBased;
+
+ int result = 0;
+ va_list vl;
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "* callback starting %d\n", PGLOB(counter)++);
+ fprintf(stderr, "* callback starting %d\n", PGLOB(counter)++);
#endif
- /* An exception has already occurred. Allow the stack to unwind so that
- the exception will be thrown in Java */
- if ((*env)->ExceptionOccurred(env)) {
+ /* An exception has already occurred. Allow the stack to unwind so that
+ the exception will be thrown in Java */
+ if ((*env)->ExceptionOccurred(env)) {
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "************ java exception occurred\n");
+ fprintf(stderr, "************ java exception occurred\n");
#endif
- return 0;
- }
-
- javaObject = (*env)->GetObjectField(env,callback,PGLOB(objectID));
- isStatic = ((*env)->GetBooleanField(env,callback,PGLOB(isStaticID))) != 0;
- isArrayBased = ((*env)->GetBooleanField(env,callback,PGLOB(isArrayBasedID))) != 0;
-
- va_start(vl, index);
- if (isArrayBased) {
- int i;
- jint argCount = (*env)->GetIntField(env,callback,PGLOB(argCountID));
- jintArray javaArray = (*env)->NewIntArray(env,argCount);
- jint *elements = (*env)->GetIntArrayElements(env,javaArray,NULL);
- for (i=0; i<argCount; i++) {
- elements[i] = va_arg(vl, jint);
+ return 0;
}
- (*env)->ReleaseIntArrayElements(env, javaArray, elements, 0);
- if (isStatic) {
- result = (*env)->CallStaticIntMethod(env, javaObject, mid, javaArray);
- } else {
- result = (*env)->CallIntMethod(env, javaObject, mid, javaArray);
- }
- (*env)->DeleteLocalRef(env, javaArray);
- } else {
- if (isStatic) {
- result = (*env)->CallStaticIntMethodV(env, javaObject, mid, vl);
+
+ javaObject = (*env)->GetObjectField(env,callback,PGLOB(objectID));
+ isStatic = ((*env)->GetBooleanField(env,callback,PGLOB(isStaticID))) != 0;
+ isArrayBased = ((*env)->GetBooleanField(env,callback,PGLOB(isArrayBasedID))) != 0;
+
+ va_start(vl, index);
+ if (isArrayBased) {
+ int i;
+ jint argCount = (*env)->GetIntField(env,callback,PGLOB(argCountID));
+ jintArray javaArray = (*env)->NewIntArray(env,argCount);
+ jint *elements = (*env)->GetIntArrayElements(env,javaArray,NULL);
+ for (i=0; i<argCount; i++) {
+ elements[i] = va_arg(vl, jint);
+ }
+ (*env)->ReleaseIntArrayElements(env, javaArray, elements, 0);
+ if (isStatic) {
+ result = (*env)->CallStaticIntMethod(env, javaObject, mid, javaArray);
+ } else {
+ result = (*env)->CallIntMethod(env, javaObject, mid, javaArray);
+ }
+ (*env)->DeleteLocalRef(env, javaArray);
} else {
- result = (*env)->CallIntMethodV(env, javaObject, mid, vl);
+ if (isStatic) {
+ result = (*env)->CallStaticIntMethodV(env, javaObject, mid, vl);
+ } else {
+ result = (*env)->CallIntMethodV(env, javaObject, mid, vl);
+ }
}
- }
- va_end(vl);
- /* This call may be called many times before we return to Java.
- We have to explicitly delete local references to avoid GP's
- in the JDK and IBM Hursley VM.
- */
- (*env)->DeleteLocalRef(env,javaObject);
+ va_end(vl);
+ /* This call may be called many times before we return to Java.
+ We have to explicitly delete local references to avoid GP's
+ in the JDK and IBM Hursley VM.
+ */
+ (*env)->DeleteLocalRef(env,javaObject);
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "* callback exiting %d\n", --PGLOB(counter));
+ fprintf(stderr, "* callback exiting %d\n", --PGLOB(counter));
#endif
- return result;
+ return result;
}
}
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 781e40e9e7..a8d3eb635c 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
@@ -1323,6 +1323,13 @@ public class SWT {
*/
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;
+
/**
* traversal event detail field value indicating that the ESC
* key was pressed (value is 1<<1)
@@ -1675,6 +1682,7 @@ static String findErrorText (int code) {
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";
}
return "Unknown error";
}
@@ -1804,6 +1812,7 @@ public static void error (int code, Throwable throwable) {
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;
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 b8747c68bd..b7b1e8c927 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
@@ -20,6 +20,7 @@ import org.eclipse.swt.internal.image.*;
* <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
@@ -39,24 +40,40 @@ public final class ImageData implements Cloneable {
/**
* 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. If one scanline of the image
- * is not a multiple of this number, it will be padded
- * with zeros until it is
+ * 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. This is a multiple
- * of the scanline padding
+ * 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;
@@ -66,33 +83,58 @@ public final class ImageData implements Cloneable {
public PaletteData palette;
/**
- * the transparent pixel. Pixels with this value are transparent.
- * The default is -1 which means 'no transparency'
+ * 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. Every pixel can have an
- * <em>alpha blending</em> value that varies from 0, meaning
- * fully transparent, to 255 meaning fully opaque
+ * 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.
- * If this value is set the <code>alphaData</code> field
- * is ignored. The default is -1 which means 'no global alpha
- * value'
+ * 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;
@@ -154,7 +196,36 @@ public final class ImageData implements Cloneable {
* 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)
@@ -485,7 +556,7 @@ public Object clone() {
* </ul>
*/
public int getAlpha(int x, int y) {
- if (x > width || y > height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ 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;
@@ -502,15 +573,17 @@ public int getAlpha(int x, int y) {
* @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 <code>x</code> or <code>y</code> is out of bounds</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) return;
- if (x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_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;
@@ -519,6 +592,7 @@ public void getAlphas(int x, int y, int getWidth, byte[] alphas, int startIndex)
}
return;
}
+ // may throw an IndexOutOfBoundsException
System.arraycopy(alphaData, y * width + x, alphas, startIndex, getWidth);
}
@@ -538,7 +612,7 @@ public void getAlphas(int x, int y, int getWidth, byte[] alphas, int startIndex)
* </ul>
*/
public int getPixel(int x, int y) {
- if (x > width || y > height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ if (x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
int index;
int theByte;
int mask;
@@ -601,9 +675,11 @@ public int getPixel(int x, int y) {
* @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
@@ -612,8 +688,8 @@ public int getPixel(int x, int y) {
*/
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) return;
- if (x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_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;
@@ -748,9 +824,11 @@ public void getPixels(int x, int y, int getWidth, byte[] pixels, int startIndex)
* @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>
@@ -758,8 +836,8 @@ public void getPixels(int x, int y, int getWidth, byte[] pixels, int startIndex)
*/
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) return;
- if (x > width || y > height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_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;
@@ -975,6 +1053,15 @@ public int getTransparencyType() {
}
/**
+ * 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
@@ -985,97 +1072,54 @@ public int getTransparencyType() {
* @return a scaled copy of the image
*/
public ImageData scaledTo(int width, int height) {
- /* Create a destination image with no data,
- * and then scale all of the data. */
- ImageData destImage = new ImageData(
+ /* 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);
- scaleImage(destImage, 0, 0, this.width, this.height, 0, 0, width, height);
- return destImage;
-}
-void scaleImage(ImageData destImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
- boolean flipX, flipY;
- /* Flip rects if necessary so that src width and height are positive. */
- if (srcWidth < 0) {
- srcWidth = -srcWidth;
- srcX = srcX - srcWidth;
- destWidth = -destWidth;
- destX = destX - destWidth;
- }
- if (srcHeight < 0) {
- srcHeight = -srcHeight;
- srcY = srcY - srcHeight;
- destHeight = -destHeight;
- destY = destY - destHeight;
- }
- /* Ensure dest width and height are positive, remembering whether to flip. */
- flipX = destWidth < 0;
- if (flipX) {
- destWidth = -destWidth;
- destX = destX - destWidth;
- }
- flipY = destHeight < 0;
- if (flipY) {
- destHeight = -destHeight;
- destY = destY - destHeight;
- }
- /* Check source rect bounds. Succeed with 0 if out of bounds, rather
- * than failing.
- */
- if (srcX < 0 || srcY < 0 || (srcX + srcWidth > width) ||
- (srcY + srcHeight > height)) {
- return;
- }
- if (destX < 0 || destY < 0 || (destX + destWidth > destImage.width) ||
- (destY + destHeight > destImage.height)) {
- return;
- }
- /* If dest rect is 0, there is nothing to do. */
- if (destWidth == 0 || destHeight == 0) {
- return;
- }
- switch (depth) {
- case 1:
- stretch1(data, bytesPerLine, MSB_FIRST, srcX, srcY, srcWidth, srcHeight, destImage.data, destImage.bytesPerLine, MSB_FIRST, destX, destY, destWidth, destHeight, flipX, flipY);
- break;
- case 2:
- stretch2(data, bytesPerLine, srcX, srcY, srcWidth, srcHeight, destImage.data, destImage.bytesPerLine, destX, destY, destWidth, destHeight, null, flipX, flipY);
- break;
- case 4:
- stretch4(data, bytesPerLine, srcX, srcY, srcWidth, srcHeight, destImage.data, destImage.bytesPerLine, destX, destY, destWidth, destHeight, null, flipX, flipY);
- break;
- case 8:
- stretch8(data, bytesPerLine, srcX, srcY, srcWidth, srcHeight, destImage.data, destImage.bytesPerLine, destX, destY, destWidth, destHeight, null, flipX, flipY);
- break;
- case 16:
- stretch16(data, bytesPerLine, srcX, srcY, srcWidth, srcHeight, destImage.data, destImage.bytesPerLine, destX, destY, destWidth, destHeight, flipX, flipY);
- break;
- case 24:
- stretch24(data, bytesPerLine, srcX, srcY, srcWidth, srcHeight, destImage.data, destImage.bytesPerLine, destX, destY, destWidth, destHeight, flipX, flipY);
- break;
- case 32:
- stretch32(data, bytesPerLine, srcX, srcY, srcWidth, srcHeight, destImage.data, destImage.bytesPerLine, destX, destY, destWidth, destHeight, flipX, flipY);
- break;
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
- if (getTransparencyType() == SWT.TRANSPARENCY_MASK) {
- destImage.maskPad = maskPad;
- int destBpl = (destWidth + 7) / 8;
- destBpl = (destBpl + (maskPad - 1)) / maskPad * maskPad;
- destImage.maskData = new byte[destBpl * destHeight];
- int srcBpl = (srcWidth + 7) / 8;
- srcBpl = (srcBpl + (maskPad - 1)) / maskPad * maskPad;
- stretch1(maskData, srcBpl, MSB_FIRST, srcX, srcY, srcWidth, srcHeight, destImage.maskData, destBpl, MSB_FIRST, destX, destY, destWidth, destHeight, flipX, flipY);
+ /* 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,
+ 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,
+ 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,
+ dest.maskData, 1, destBpl, MSB_FIRST, 0, 0, dest.width, dest.height, null, null, null,
+ flipX, flipY);
} else if (alpha != -1) {
- destImage.alpha = alpha;
+ dest.alpha = this.alpha;
} else if (alphaData != null) {
- destImage.alphaData = new byte[destImage.width * destImage.height];
- stretch8(alphaData, width, srcX, srcY, srcWidth, srcHeight, destImage.alphaData, destImage.width, destX, destY, destWidth, destHeight, null, flipX, flipY);
- }
+ 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,
+ dest.alphaData, 8, dest.width, MSB_FIRST, 0, 0, dest.width, dest.height, null, null, null,
+ flipX, flipY);
+ }
+ return dest;
}
/**
@@ -1091,7 +1135,7 @@ void scaleImage(ImageData destImage, int srcX, int srcY, int srcWidth, int srcHe
* </ul>
*/
public void setAlpha(int x, int y, int alpha) {
- if (x > width || y > height || x < 0 || y < 0 || alpha < 0 || alpha > 255)
+ 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];
@@ -1110,17 +1154,20 @@ public void setAlpha(int x, int y, int alpha) {
* @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) return;
- if (x > width || y > height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_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);
}
@@ -1140,7 +1187,7 @@ public void setAlphas(int x, int y, int putWidth, byte[] alphas, int startIndex)
* </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);
+ if (x >= width || y >= height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
int index;
byte theByte;
int mask;
@@ -1213,9 +1260,11 @@ public void setPixel(int x, int y, int pixelValue) {
* @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
@@ -1224,8 +1273,8 @@ public void setPixel(int x, int y, int pixelValue) {
*/
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) return;
- if (x > width || y > height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_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;
@@ -1339,9 +1388,11 @@ public void setPixels(int x, int y, int putWidth, byte[] pixels, int startIndex)
* @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>
@@ -1349,8 +1400,8 @@ public void setPixels(int x, int y, int putWidth, byte[] pixels, int startIndex)
*/
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) return;
- if (x > width || y > height || x < 0 || y < 0) SWT.error(SWT.ERROR_INVALID_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;
@@ -1518,43 +1569,6 @@ static PaletteData bwPalette() {
}
/**
- * Blit operations.
- */
-static final int BLIT_SRC = 1;
-static final int BLIT_ALPHA = 2;
-/**
- * Byte and bit order constants.
- */
-static final int MSB_FIRST = 1;
-static final int LSB_FIRST = 2;
-
-/**
- * Masks for blitting.
- */
-static final byte[] msbMasks1 = {
- (byte)0x80, (byte)0x40, (byte)0x20, (byte)0x10,
- (byte)0x08, (byte)0x04, (byte)0x02, (byte)0x01
-};
-static final byte[] lsbMasks1 = {
- (byte)0x01, (byte)0x02, (byte)0x04, (byte)0x08,
- (byte)0x10, (byte)0x20, (byte)0x40, (byte)0x80
-};
-static final byte[] msbInverseMasks1 = {
- (byte)0x7F, (byte)0xBF, (byte)0xDF, (byte)0xEF,
- (byte)0xF7, (byte)0xFB, (byte)0xFD, (byte)0xFE
-};
-static final byte[] lsbInverseMasks1 = {
- (byte)0xFE, (byte)0xFD, (byte)0xFB, (byte)0xF7,
- (byte)0xEF, (byte)0xDF, (byte)0xBF, (byte)0x7F
-};
-static final byte[] masks2 = {
- (byte)0x03, (byte)0x0C, (byte)0x30, (byte)0xC0
-};
-static final byte[] inverseMasks2 = {
- (byte)0xFC, (byte)0xF3, (byte)0xCF, (byte)0x3F
-};
-
-/**
* Gets the offset of the most significant bit for
* the given mask.
*/
@@ -1596,1856 +1610,1931 @@ static int closestMatch(int depth, byte red, byte green, byte blue, int redMask,
}
/**
+ * 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 MSB_FIRST = 1;
+static final int LSB_FIRST = 2;
+
+/**
+ * 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 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 srcGlobalAlpha, byte[] srcAlphaData, int srcAlphaStride, 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) {
- int xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2;
- int dyd, dys, ey, dy, dyd2, dys2, ys, yd;
- short syd, sys;
- int dxd, dxs, ex, dx, dxd2, dxs2;
- short sxd, sxs, sas;
- int sp, dp, sap = 0;
- int sr = 0, sg = 0, sb = 0, sa = 0, dr = 0, dg = 0, db = 0, da = 0;
- int srcPixel = 0, destPixel = 0;
- short so0 = 0, so1 = 1, so2 = 2, so3 = 3;
- short do0 = 0, do1 = 1, do2 = 2, do3 = 3;
- int srcRedShift, srcGreenShift, srcBlueShift;
- int destRedShift, destGreenShift, destBlueShift;
-
- if (op == BLIT_SRC && srcDepth == destDepth &&
- srcRedMask == destRedMask &&
- srcGreenMask == destGreenMask &&
- srcBlueMask == destBlueMask)
- {
- switch (srcDepth) {
- case 16:
- stretch16(srcData, srcStride, srcX, srcY, srcWidth, srcHeight, destData, destStride, destX, destY, destWidth, destHeight, flipX, flipY);
+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,
+ 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) ? ((srcWidth << 16) - 1) / dwm1 : 0;
+ final int dhm1 = destHeight - 1;
+ final int sfyi = (dhm1 != 0) ? ((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 = srcY * alphaStride + srcX;
break;
- case 24:
- stretch24(srcData, srcStride, srcX, srcY, srcWidth, srcHeight, destData, destStride, destX, destY, destWidth, destHeight, flipX, flipY);
+ case ALPHA_MASK_PACKED:
+ if (alphaData == null) alphaMode = 0x10000;
+ alphaStride <<= 3;
+ apr = srcY * alphaStride + srcX;
break;
- case 32:
- stretch32(srcData, srcStride, srcX, srcY, srcWidth, srcHeight, destData, destStride, destX, destY, destWidth, destHeight, flipX, flipY);
+ 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;
}
- return;
- }
-
- srcRedShift = 32 - getMSBOffset(srcRedMask);
- srcGreenShift = 32 - getMSBOffset(srcGreenMask);
- srcBlueShift = 32 - getMSBOffset(srcBlueMask);
- destRedShift = 32 - getMSBOffset(destRedMask);
- destGreenShift = 32 - getMSBOffset(destGreenMask);
- destBlueShift = 32 - getMSBOffset(destBlueMask);
- if (srcOrder == LSB_FIRST) {
- switch (srcDepth) {
- case 16: so0 = 1; so1 = 0; break;
- case 24: so0 = 2; so1 = 1; so2 = 0; break;
- case 32: so0 = 3; so1 = 2; so2 = 1; so3 = 0; break;
- }
- }
- if (destOrder == LSB_FIRST) {
- switch (destDepth) {
- case 16: do0 = 1; do1 = 0; break;
- case 24: do0 = 2; do1 = 1; do2 = 0; break;
- case 32: do0 = 3; do1 = 2; do2 = 1; do3 = 0; break;
- }
- }
-
- xs1 = srcX; xs2 = srcX + srcWidth - 1;
- ys1 = srcY; ys2 = srcY + srcHeight - 1;
- if (flipX) {
- xd1 = destX + destWidth - 1;
- xd2 = destX;
} else {
- xd1 = destX;
- xd2 = destX + destWidth - 1;
- }
- if (flipY) {
- yd1 = destY + destHeight - 1;
- yd2 = destY;
- } else {
- yd1 = destY;
- yd2 = destY + destHeight - 1;
- }
-
- /* Y preliminary calculations */
- dyd = yd2 - yd1;
- if (dyd < 0) dyd = -dyd;
- dys = ys2 - ys1;
- if (dys < 0) dys = -dys;
- dyd2 = dyd << 1;
- dys2 = dys << 1;
- syd = (short)((yd2 - yd1) > 0 ? 1 : -1);
- sys = (short)((ys2 - ys1) > 0 ? 1 : -1);
- ey = dys2 - dyd;
- ys = ys1;
- yd = yd1;
- /* X preliminary calculations */
- dxd = xd2 - xd1;
- if (dxd < 0) dxd = -dxd;
- dxs = xs2 - xs1;
- if (dxs < 0) dxs = -dxs;
- dxs2 = dxs << 1;
- dxd2 = dxd << 1;
- sxs = sas = (short)((xs2 - xs1) > 0 ? 1 : -1);
- sxd = (short)((xd2 - xd1) > 0 ? 1 : -1);
-
- sxs *= srcDepth / 8;
- xs1 *= srcDepth / 8;
- sxd *= destDepth / 8;
- xd1 *= destDepth / 8;
-
- if (srcGlobalAlpha != -1) srcAlphaData = null;
- sa = srcGlobalAlpha;
- for (dy = 0; dy <= dyd; dy++) {
- /* X stretch starts here */
- ex = dxs2 - dxd;
- sp = ys * srcStride + xs1;
- dp = yd * destStride + xd1;
- if (srcAlphaData != null) sap = ys * srcAlphaStride + xs1;
- for (dx = 0; dx < dxd; dx++) {
- if (srcAlphaData != null) sa = srcAlphaData[sap] & 0xFF;
- switch (srcDepth) {
- case 16:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 8) | (srcData[sp+so1] & 0xFF);
- break;
- case 24:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 16) | ((srcData[sp+so1] & 0xFF) << 8) |
- (srcData[sp+so2] & 0xFF);
- break;
- case 32:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 24) | ((srcData[sp+so1] & 0xFF) << 16) |
- ((srcData[sp+so2] & 0xFF) << 8) | (srcData[sp+so3] & 0xFF);
- break;
- }
- dr = sr = ((srcPixel & srcRedMask) << srcRedShift) >>> 24;
- dg = sg = ((srcPixel & srcGreenMask) << srcGreenShift) >>> 24;
- db = sb = ((srcPixel & srcBlueMask) << srcBlueShift) >>> 24;
- if (op != BLIT_SRC) {
- switch (destDepth) {
- case 16:
- destPixel = ((destData[dp+do0] & 0xFF) << 8) | (destData[dp+do1] & 0xFF);
- break;
- case 24:
- destPixel = ((destData[dp+do0] & 0xFF) << 16) | ((destData[dp+do1] & 0xFF) << 8) |
- (destData[dp+do2] & 0xFF);
- break;
- case 32:
- destPixel = ((destData[dp+do0] & 0xFF) << 24) | ((destData[dp+do1] & 0xFF) << 16) |
- ((destData[dp+do2] & 0xFF) << 8) | (destData[dp+do3] & 0xFF);
- break;
+ 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);
+ }
}
- dr = ((destPixel & destRedMask) << destRedShift) >>> 24;
- dg = ((destPixel & destGreenMask) << destGreenShift) >>> 24;
- db = ((destPixel & destBlueMask) << destBlueShift) >>> 24;
- switch (op) {
- case BLIT_ALPHA:
- dr += (sr - dr) * sa / 255;
- dg += (sg - dg) * sa / 255;
- db += (sb - db) * sa / 255;
- break;
+ 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;
+ }
}
- }
- destPixel =
- (((dr << 24) >> destRedShift) & destRedMask) |
- (((dg << 24) >> destGreenShift) & destGreenMask) |
- (((db << 24) >> destBlueShift) & destBlueMask);
- switch (destDepth) {
- case 16:
- destData[dp + do0] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do1] = (byte)(destPixel & 0xFF);
- break;
- case 24:
- destData[dp + do0] = (byte)((destPixel >> 16) & 0xFF);
- destData[dp + do1] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do2] = (byte)(destPixel & 0xFF);
- break;
- case 32:
- destData[dp + do0] = (byte)((destPixel >> 24) & 0xFF);
- destData[dp + do1] = (byte)((destPixel >> 16) & 0xFF);
- destData[dp + do2] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do3] = (byte)(destPixel & 0xFF);
- break;
- }
- while (ex >= 0) {
- sp += sxs;
- ex -= dxd2;
- if (srcAlphaData != null) sap += sas;
- }
- dp += sxd;
- ex += dxs2;
- }
-
- if (srcAlphaData != null) sa = srcAlphaData[sap] & 0xFF;
- switch (srcDepth) {
- case 16:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 8) | (srcData[sp+so1] & 0xFF);
- break;
- case 24:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 16) | ((srcData[sp+so1] & 0xFF) << 8) |
- (srcData[sp+so2] & 0xFF);
- break;
- case 32:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 24) | ((srcData[sp+so1] & 0xFF) << 16) |
- ((srcData[sp+so2] & 0xFF) << 8) | (srcData[sp+so3] & 0xFF);
- break;
- }
- dr = sr = ((srcPixel & srcRedMask) << srcRedShift) >>> 24;
- dg = sg = ((srcPixel & srcGreenMask) << srcGreenShift) >>> 24;
- db = sb = ((srcPixel & srcBlueMask) << srcBlueShift) >>> 24;
- if (op != BLIT_SRC) {
- switch (destDepth) {
- case 16:
- destPixel = ((destData[dp+do0] & 0xFF) << 8) | (destData[dp+do1] & 0xFF);
- break;
- case 24:
- destPixel = ((destData[dp+do0] & 0xFF) << 16) | ((destData[dp+do1] & 0xFF) << 8) |
- (destData[dp+do2] & 0xFF);
- break;
- case 32:
- destPixel = ((destData[dp+do0] & 0xFF) << 24) | ((destData[dp+do1] & 0xFF) << 16) |
- ((destData[dp+do2] & 0xFF) << 8) | (destData[dp+do3] & 0xFF);
- break;
- }
- dr = ((destPixel & destRedMask) << destRedShift) >>> 24;
- dg = ((destPixel & destGreenMask) << destGreenShift) >>> 24;
- db = ((destPixel & destBlueMask) << destBlueShift) >>> 24;
- switch (op) {
- case BLIT_ALPHA:
- dr += (sr - dr) * sa / 255;
- dg += (sg - dg) * sa / 255;
- db += (sb - db) * sa / 255;
break;
- }
- }
- destPixel =
- (((dr << 24) >> destRedShift) & destRedMask) |
- (((dg << 24) >> destGreenShift) & destGreenMask) |
- (((db << 24) >> destBlueShift) & destBlueMask);
- switch (destDepth) {
- case 16:
- destData[dp + do0] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do1] = (byte)(destPixel & 0xFF);
- break;
- case 24:
- destData[dp + do0] = (byte)((destPixel >> 16) & 0xFF);
- destData[dp + do1] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do2] = (byte)(destPixel & 0xFF);
+ 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 32:
- destData[dp + do0] = (byte)((destPixel >> 24) & 0xFF);
- destData[dp + do1] = (byte)((destPixel >> 16) & 0xFF);
- destData[dp + do2] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do3] = (byte)(destPixel & 0xFF);
+ 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;
}
- /* X stretch ends here */
- if (dy == dyd)
- break;
- while (ey >= 0) {
- ys += sys;
- ey -= dyd2;
- }
- yd += syd;
- ey += dys2;
- }
-}
-
-/**
- * Blits an index palette image into a direct palette image.
- */
-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 srcGlobalAlpha, byte[] srcAlphaData, int srcAlphaStride, 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) {
- int xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2;
- int dyd, dys, ey, dy, dyd2, dys2, ys, yd;
- short syd, sys;
- int dxd, dxs, ex, dx, dxd2, dxs2, xs;
- short sxd, sxs, sas;
- int sp, dp, sap = 0;
- int sr = 0, sg = 0, sb = 0, sa = 0, dr = 0, dg = 0, db = 0, da = 0;
- int srcPixel = 0, destPixel = 0;
- short do0 = 0, do1 = 1, do2 = 2, do3 = 3;
- int destRedShift, destGreenShift, destBlueShift;
- int i, offset = 0;
- byte[] srcMasks = null;
- int srcN = 1 << srcDepth;
- int[] mapping = null;
-
- destRedShift = 32 - getMSBOffset(destRedMask);
- destGreenShift = 32 - getMSBOffset(destGreenMask);
- destBlueShift = 32 - getMSBOffset(destBlueMask);
- if (srcReds != null && srcN > srcReds.length) srcN = srcReds.length;
- if (op == BLIT_SRC) {
- mapping = new int[srcN];
- for (i = 0; i < srcN; i++) {
- dr = srcReds[i] & 0xFF;
- dg = srcGreens[i] & 0xFF;
- db = srcBlues[i] & 0xFF;
- mapping[i] =
- (((dr << 24) >>> destRedShift) & destRedMask) |
- (((dg << 24) >>> destGreenShift) & destGreenMask) |
- (((db << 24) >>> destBlueShift) & destBlueMask);
- }
- }
- switch (srcDepth) {
- case 1: srcMasks = msbMasks1; break;
- case 2: srcMasks = masks2; break;
- }
- if (srcOrder == LSB_FIRST) {
- switch (srcDepth) {
- case 1: srcMasks = lsbMasks1; break;
- }
- }
- if (destOrder == LSB_FIRST) {
- switch (destDepth) {
- case 16: do0 = 1; do1 = 0; break;
- case 24: do0 = 2; do1 = 1; do2 = 0; break;
- case 32: do0 = 3; do1 = 2; do2 = 1; do3 = 0; break;
- }
- }
-
- xs1 = srcX; xs2 = srcX + srcWidth - 1;
- ys1 = srcY; ys2 = srcY + srcHeight - 1;
- if (flipX) {
- xd1 = destX + destWidth - 1;
- xd2 = destX;
- } else {
- xd1 = destX;
- xd2 = destX + destWidth - 1;
- }
- if (flipY) {
- yd1 = destY + destHeight - 1;
- yd2 = destY;
- } else {
- yd1 = destY;
- yd2 = destY + destHeight - 1;
+ return;
}
-
- /* Y preliminary calculations */
- dyd = yd2 - yd1;
- if (dyd < 0) dyd = -dyd;
- dys = ys2 - ys1;
- if (dys < 0) dys = -dys;
- dyd2 = dyd << 1;
- dys2 = dys << 1;
- syd = (short)((yd2 - yd1) > 0 ? 1 : -1);
- sys = (short)((ys2 - ys1) > 0 ? 1 : -1);
- ey = dys2 - dyd;
- ys = ys1;
- yd = yd1;
- /* X preliminary calculations */
- dxd = xd2 - xd1;
- if (dxd < 0) dxd = -dxd;
- dxs = xs2 - xs1;
- if (dxs < 0) dxs = -dxs;
- dxs2 = dxs << 1;
- dxd2 = dxd << 1;
- sxs = sas = (short)((xs2 - xs1) > 0 ? 1 : -1);
- sxd = (short)((xd2 - xd1) > 0 ? 1 : -1);
-
- sxd *= destDepth / 8;
- xd1 *= destDepth / 8;
-
- if (srcGlobalAlpha != -1) srcAlphaData = null;
- sa = srcGlobalAlpha;
- for (dy = 0; dy <= dyd; dy++) {
- /* X stretch starts here */
- offset = 3 - (srcX % 4);
- ex = dxs2 - dxd;
- xs = xs1;
- sp = ys * srcStride;
- dp = yd * destStride + xd1;
- if (srcAlphaData != null) sap = ys * srcAlphaStride + xs1;
- for (dx = 0; dx < dxd; dx++) {
- if (srcAlphaData != null) sa = srcAlphaData[sap] & 0xFF;
- switch (srcDepth) {
- case 1:
- srcPixel = (srcData[sp + (xs >> 3)] & srcMasks[xs & 7]) == 0 ? 0 : 1;
+ /*** 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 2:
- srcPixel = ((srcData[sp + (xs >> 2)] & srcMasks[offset]) & 0xFF) >> (offset * 2);
+ case ALPHA_CHANNEL_SOURCE:
+ alpha = (a << 16) / 255;
break;
- case 4:
- srcPixel = srcData[sp + (xs >> 1)] & 0xFF;
- if ((xs & 0x1) == 0) {
- srcPixel = srcPixel >> 4;
- } else {
- srcPixel = srcPixel & 0x0F;
- }
+ 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 8:
- srcPixel = srcData[sp + xs] & 0xFF;
- break;
- }
- if (mapping != null) {
- destPixel = mapping[srcPixel];
- } else {
- dr = sr = srcReds[srcPixel] & 0xFF;
- dg = sg = srcGreens[srcPixel] & 0xFF;
- db = sb = srcBlues[srcPixel] & 0xFF;
- if (op != BLIT_SRC) {
- switch (destDepth) {
- case 16:
- destPixel = ((destData[dp+do0] & 0xFF) << 8) | (destData[dp+do1] & 0xFF);
- break;
- case 24:
- destPixel = ((destData[dp+do0] & 0xFF) << 16) | ((destData[dp+do1] & 0xFF) << 8) |
- (destData[dp+do2] & 0xFF);
- break;
- case 32:
- destPixel = ((destData[dp+do0] & 0xFF) << 24) | ((destData[dp+do1] & 0xFF) << 16) |
- ((destData[dp+do2] & 0xFF) << 8) | (destData[dp+do3] & 0xFF);
+ 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;
+ }
}
- dr = ((destPixel & destRedMask) << destRedShift) >>> 24;
- dg = ((destPixel & destGreenMask) << destGreenShift) >>> 24;
- db = ((destPixel & destBlueMask) << destBlueShift) >>> 24;
- switch (op) {
- case BLIT_ALPHA:
- dr += (sr - dr) * sa / 255;
- dg += (sg - dg) * sa / 255;
- db += (sb - db) * sa / 255;
- break;
- }
- }
- destPixel =
- (((dr << 24) >>> destRedShift) & destRedMask) |
- (((dg << 24) >>> destGreenShift) & destGreenMask) |
- (((db << 24) >>> destBlueShift) & destBlueMask);
- }
- switch (destDepth) {
- case 16:
- destData[dp + do0] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do1] = (byte)(destPixel & 0xFF);
break;
- case 24:
- destData[dp + do0] = (byte)((destPixel >> 16) & 0xFF);
- destData[dp + do1] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do2] = (byte)(destPixel & 0xFF);
- break;
- case 32:
- destData[dp + do0] = (byte)((destPixel >> 24) & 0xFF);
- destData[dp + do1] = (byte)((destPixel >> 16) & 0xFF);
- destData[dp + do2] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do3] = (byte)(destPixel & 0xFF);
- break;
- }
- while (ex >= 0) {
- xs += sxs;
- ex -= dxd2;
- if (srcAlphaData != null) sap += sas;
}
- dp += sxd;
- ex += dxs2;
- if (offset == 0) {
- offset = 3;
- } else {
- offset--;
- }
- }
-
- if (srcAlphaData != null) sa = srcAlphaData[sap] & 0xFF;
- switch (srcDepth) {
- case 1:
- srcPixel = (srcData[sp + (xs >> 3)] & srcMasks[xs & 7]) == 0 ? 0 : 1;
- break;
- case 2:
- srcPixel = ((srcData[sp + (xs >> 2)] & srcMasks[offset]) & 0xFF) >> (offset * 2);
- break;
- case 4:
- srcPixel = srcData[sp + (xs >> 1)] & 0xFF;
- if ((xs & 0x1) == 0) {
- srcPixel = srcPixel >> 4;
- } else {
- srcPixel = srcPixel & 0x0F;
+ 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;
}
- break;
- case 8:
- srcPixel = srcData[sp + xs] & 0xFF;
- break;
- }
- if (mapping != null) {
- destPixel = mapping[srcPixel];
- } else {
- dr = sr = srcReds[srcPixel] & 0xFF;
- dg = sg = srcGreens[srcPixel] & 0xFF;
- db = sb = srcBlues[srcPixel] & 0xFF;
- if (op != BLIT_SRC) {
- switch (destDepth) {
- case 16:
- destPixel = ((destData[dp+do0] & 0xFF) << 8) | (destData[dp+do1] & 0xFF);
- break;
- case 24:
- destPixel = ((destData[dp+do0] & 0xFF) << 16) | ((destData[dp+do1] & 0xFF) << 8) |
- (destData[dp+do2] & 0xFF);
- break;
- case 32:
- destPixel = ((destData[dp+do0] & 0xFF) << 24) | ((destData[dp+do1] & 0xFF) << 16) |
- ((destData[dp+do2] & 0xFF) << 8) | (destData[dp+do3] & 0xFF);
- break;
- }
- dr = ((destPixel & destRedMask) << destRedShift) >>> 24;
- dg = ((destPixel & destGreenMask) << destGreenShift) >>> 24;
- db = ((destPixel & destBlueMask) << destBlueShift) >>> 24;
- switch (op) {
- case BLIT_ALPHA:
- dr += (sr - dr) * sa / 255;
- dg += (sg - dg) * sa / 255;
- db += (sb - db) * sa / 255;
- break;
- }
- }
- destPixel =
- (((dr << 24) >>> destRedShift) & destRedMask) |
- (((dg << 24) >>> destGreenShift) & destGreenMask) |
- (((db << 24) >>> destBlueShift) & destBlueMask);
- }
- switch (destDepth) {
- case 16:
- destData[dp + do0] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do1] = (byte)(destPixel & 0xFF);
- break;
- case 24:
- destData[dp + do0] = (byte)((destPixel >> 16) & 0xFF);
- destData[dp + do1] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do2] = (byte)(destPixel & 0xFF);
- break;
- case 32:
- destData[dp + do0] = (byte)((destPixel >> 24) & 0xFF);
- destData[dp + do1] = (byte)((destPixel >> 16) & 0xFF);
- destData[dp + do2] = (byte)((destPixel >> 8) & 0xFF);
- destData[dp + do3] = (byte)(destPixel & 0xFF);
- break;
- }
- /* X stretch ends here */
- if (dy == dyd)
- break;
- while (ey >= 0) {
- ys += sys;
- ey -= dyd2;
- }
- yd += syd;
- ey += dys2;
- }
+ // 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 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 srcGlobalAlpha, byte[] srcAlphaData, int srcAlphaStride, 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) {
- int xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2;
- int dyd, dys, ey, dy, dyd2, dys2, ys, yd;
- short syd, sys;
- int dxd, dxs, ex, dx, dxd2, dxs2, xs, xd;
- short sxd, sxs, sas;
- int sp, dp, sap = 0;
- int sr = 0, sg = 0, sb = 0, sa = 0, dr = 0, dg = 0, db = 0, da = 0;
- int srcPixel = 0, destPixel = 0;
- int i, j, offset = 0;
- byte[] srcMasks = null, destMasks = null, destInverseMasks = null;
- int destN = 1 << destDepth, srcN = 1 << srcDepth;
- int r, g, b, nearestPixel = 0, lastPixel = -1;
- int distance, minDistance;
- int[] mapping = null;
- boolean samePalette = srcReds == destReds && srcGreens == destGreens && srcBlues == srcBlues;
- boolean sameAsSrc = op == BLIT_SRC && samePalette && srcDepth <= destDepth;
-
- if (srcReds != null && srcN > srcReds.length) srcN = srcReds.length;
- if (destReds != null && destN > destReds.length) destN = destReds.length;
- if (op == BLIT_SRC && srcReds != null) {
- mapping = new int[srcN];
- for (i = 0; i < srcN; i++) {
- minDistance = 0x7FFFFFFF;
- nearestPixel = 0;
- for (j = 0; j < destN; j++) {
- r = (destReds[j] & 0xFF) - (srcReds[i] & 0xFF);
- g = (destGreens[j] & 0xFF) - (srcGreens[i] & 0xFF);
- b = (destBlues[j] & 0xFF) - (srcBlues[i] & 0xFF);
- distance = r*r + g*g + b*b;
- if (distance < minDistance) {
- nearestPixel = j;
- if (distance == 0) break;
- minDistance = distance;
- }
- }
- mapping[i] = nearestPixel;
- }
- }
- if (op == BLIT_SRC && srcDepth == destDepth && (mapping != null || samePalette))
- {
- switch (srcDepth) {
- case 1:
- stretch1(srcData, srcStride, srcOrder, srcX, srcY, srcWidth, srcHeight, destData, destStride, destOrder, destX, destY, destWidth, destHeight, flipX, flipY);
+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,
+ 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) ? ((srcWidth << 16) - 1) / dwm1 : 0;
+ final int dhm1 = destHeight - 1;
+ final int sfyi = (dhm1 != 0) ? ((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 = srcY * alphaStride + srcX;
break;
- case 2:
- stretch2(srcData, srcStride, srcX, srcY, srcWidth, srcHeight, destData, destStride, destX, destY, destWidth, destHeight, mapping, flipX, flipY);
+ case ALPHA_MASK_PACKED:
+ if (alphaData == null) alphaMode = 0x10000;
+ alphaStride <<= 3;
+ apr = srcY * alphaStride + srcX;
break;
- case 4:
- stretch4(srcData, srcStride, srcX, srcY, srcWidth, srcHeight, destData, destStride, destX, destY, destWidth, destHeight, mapping, flipX, flipY);
+ case ALPHA_MASK_INDEX:
+ case ALPHA_MASK_RGB:
+ if (alphaData == null) alphaMode = 0x10000;
+ apr = 0;
break;
- case 8:
- stretch8(srcData, srcStride, srcX, srcY, srcWidth, srcHeight, destData, destStride, destX, destY, destWidth, destHeight, mapping, flipX, flipY);
+ default:
+ alphaMode = (alphaMode << 16) / 255; // prescale
+ case ALPHA_CHANNEL_SOURCE:
+ apr = 0;
break;
}
- return;
- }
- switch (srcDepth) {
- case 1: srcMasks = msbMasks1; break;
- case 2: srcMasks = masks2; break;
- }
- switch (destDepth) {
- case 1: destMasks = msbMasks1; destInverseMasks = msbInverseMasks1; break;
- case 2: destMasks = masks2; destInverseMasks = inverseMasks2; break;
- }
- if (srcOrder == LSB_FIRST) {
- switch (srcDepth) {
- case 1: srcMasks = lsbMasks1; break;
- }
- }
- if (destOrder == LSB_FIRST) {
- switch (destDepth) {
- case 1: destMasks = lsbMasks1; destInverseMasks = lsbInverseMasks1; break;
- }
- }
-
- xs1 = srcX; xs2 = srcX + srcWidth - 1;
- ys1 = srcY; ys2 = srcY + srcHeight - 1;
- if (flipX) {
- xd1 = destX + destWidth - 1;
- xd2 = destX;
} else {
- xd1 = destX;
- xd2 = destX + destWidth - 1;
- }
- if (flipY) {
- yd1 = destY + destHeight - 1;
- yd2 = destY;
- } else {
- yd1 = destY;
- yd2 = destY + destHeight - 1;
+ 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;
}
-
- /* Y preliminary calculations */
- dyd = yd2 - yd1;
- if (dyd < 0) dyd = -dyd;
- dys = ys2 - ys1;
- if (dys < 0) dys = -dys;
- dyd2 = dyd << 1;
- dys2 = dys << 1;
- syd = (short)((yd2 - yd1) > 0 ? 1 : -1);
- sys = (short)((ys2 - ys1) > 0 ? 1 : -1);
- ey = dys2 - dyd;
- ys = ys1;
- yd = yd1;
- /* X preliminary calculations */
- dxd = xd2 - xd1;
- if (dxd < 0) dxd = -dxd;
- dxs = xs2 - xs1;
- if (dxs < 0) dxs = -dxs;
- dxs2 = dxs << 1;
- dxd2 = dxd << 1;
- sxs = sas = (short)((xs2 - xs1) > 0 ? 1 : -1);
- sxd = (short)((xd2 - xd1) > 0 ? 1 : -1);
-
- if (srcGlobalAlpha != -1) srcAlphaData = null;
- sa = srcGlobalAlpha;
- for (dy = 0; dy <= dyd; dy++) {
- /* X stretch starts here */
- offset = 3 - (srcX % 4);
- ex = dxs2 - dxd;
- xs = xs1;
- xd = xd1;
- sp = ys * srcStride;
- dp = yd * destStride;
- if (srcAlphaData != null) sap = ys * srcAlphaStride;
- for (dx = 0; dx < dxd; dx++) {
- if (srcAlphaData != null) sa = srcAlphaData[sap] & 0xFF;
- switch (srcDepth) {
- case 1:
- srcPixel = (srcData[sp + (xs >> 3)] & srcMasks[xs & 7]) == 0 ? 0 : 1;
- break;
- case 2:
- srcPixel = ((srcData[sp + (xs >> 2)] & srcMasks[offset]) & 0xFF) >> (offset * 2);
- break;
- case 4:
- srcPixel = srcData[sp + (xs >> 1)] & 0xFF;
- if ((xs & 0x1) == 0) {
- srcPixel = srcPixel >> 4;
- } else {
- srcPixel = srcPixel & 0x0F;
+ 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 8:
- srcPixel = srcData[sp + xs] & 0xFF;
+ 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;
}
- if (mapping != null) {
- destPixel = mapping[srcPixel];
- } else if (sameAsSrc) {
- destPixel = srcPixel;
- } else {
- dr = sr = srcReds[srcPixel] & 0xFF;
- dg = sg = srcGreens[srcPixel] & 0xFF;
- db = sb = srcBlues[srcPixel] & 0xFF;
- if (op != BLIT_SRC) {
- switch (destDepth) {
- case 1:
- destPixel = (destData[dp + (xd >> 3)] & destMasks[xd & 7]) == 0 ? 0 : 1;
- break;
- case 2:
- destPixel = ((destData[dp + (xd >> 2)] & destMasks[offset]) & 0xFF) >> (offset * 2);
- break;
- case 4:
- destPixel = destData[dp + (xd >> 1)] & 0xFF;
- if ((xs & 0x1) == 0) {
- destPixel = destPixel >> 4;
- } else {
- destPixel = destPixel & 0x0F;
- }
- break;
- case 8:
- destPixel = destData[dp + xd] & 0xFF;
+ } 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;
}
- dr = destReds[destPixel] & 0xFF;
- dg = destGreens[destPixel] & 0xFF;
- db = destBlues[destPixel] & 0xFF;
- switch (op) {
- case BLIT_ALPHA:
- dr += (sr - dr) * sa / 255;
- dg += (sg - dg) * sa / 255;
- db += (sb - db) * sa / 255;
- break;
+ /*** 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;
}
- }
- if (lastPixel == -1 || lastPixel != srcPixel) {
- minDistance = 0x7FFFFFFF;
- nearestPixel = 0;
- for (j = 0; j < destN; j++) {
- r = (destReds[j] & 0xFF) - dr;
- g = (destGreens[j] & 0xFF) - dg;
- b = (destBlues[j] & 0xFF) - db;
- distance = r*r + g*g + b*b;
- if (distance < minDistance) {
- nearestPixel = j;
- if (distance == 0) break;
- minDistance = distance;
- }
+ 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;
}
- lastPixel = srcPixel;
}
- destPixel = nearestPixel;
- }
- switch (destDepth) {
- case 1:
- if ((destPixel & 0x1) == 1) {
- destData[dp + (xd >> 3)] |= destInverseMasks[xd & 7];
- } else {
- destData[dp + (xd >> 3)] &= destInverseMasks[xd & 7] ^ -1;
- }
+ }
+ }
+ 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 2:
- destData[dp + (xd >> 2)] = (byte)((destData[dp + (xd >> 2)] & destInverseMasks[offset]) | (destPixel << (offset * 2)));
+ 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 4:
- if ((xd & 0x1) == 0) {
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0x0F) | ((destPixel & 0x0F) << 4));
- } else {
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0xF0) | (destPixel & 0x0F));
- }
+ case TYPE_INDEX_2:
+ index = (srcData[sp >> 2] >>> (6 - (sp & 3) * 2)) & 0x03;
+ sp += (sfx >>> 16);
break;
- case 8:
- destData[dp + xd] = (byte)(destPixel & 0xFF);
+ 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;
}
- while (ex >= 0) {
- xs += sxs;
- ex -= dxd2;
- if (srcAlphaData != null) sap += sas;
- }
- xd += sxd;
- ex += dxs2;
- if (offset == 0) {
- offset = 3;
- } else {
- offset--;
- }
- }
-
- if (srcAlphaData != null) sa = srcAlphaData[sap] & 0xFF;
- switch (srcDepth) {
- case 1:
- srcPixel = (srcData[sp + (xs >> 3)] & srcMasks[xs & 7]) == 0 ? 0 : 1;
- break;
- case 2:
- srcPixel = ((srcData[sp + (xs >> 2)] & srcMasks[offset]) & 0xFF) >> (offset * 2);
- break;
- case 4:
- srcPixel = srcData[sp + (xs >> 1)] & 0xFF;
- if ((xs & 0x1) == 0) {
- srcPixel = srcPixel >> 4;
- } else {
- srcPixel = srcPixel & 0x0F;
- }
- break;
- case 8:
- srcPixel = srcData[sp + xs] & 0xFF;
- break;
- }
- if (mapping != null) {
- destPixel = mapping[srcPixel];
- } else if (sameAsSrc) {
- destPixel = srcPixel;
- } else {
- dr = sr = srcReds[srcPixel] & 0xFF;
- dg = sg = srcGreens[srcPixel] & 0xFF;
- db = sb = srcBlues[srcPixel] & 0xFF;
- if (op != BLIT_SRC) {
- switch (destDepth) {
- case 1:
- destPixel = (destData[dp + (xd >> 3)] & destMasks[xd & 7]) == 0 ? 0 : 1;
+
+ /*** 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 2:
- destPixel = ((destData[dp + (xd >> 2)] & destMasks[offset]) & 0xFF) >> (offset * 2);
+ case TYPE_INDEX_4:
+ if ((dp & 1) != 0) indexq = destData[dp >> 1] & 0x0f;
+ else indexq = (destData[dp >> 1] >>> 4) & 0x0f;
break;
- case 4:
- destPixel = destData[dp + (xd >> 1)] & 0xFF;
- if ((xs & 0x1) == 0) {
- destPixel = destPixel >> 4;
- } else {
- destPixel = destPixel & 0x0F;
- }
+ case TYPE_INDEX_2:
+ indexq = (destData[dp >> 2] >>> (6 - (dp & 3) * 2)) & 0x03;
break;
- case 8:
- destPixel = destData[dp + xd] & 0xFF;
+ 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;
}
- dr = destReds[destPixel] & 0xFF;
- dg = destGreens[destPixel] & 0xFF;
- db = destBlues[destPixel] & 0xFF;
- switch (op) {
- case BLIT_ALPHA:
- dr += (sr - dr) * sa / 255;
- dg += (sg - dg) * sa / 255;
- db += (sb - db) * sa / 255;
- break;
- }
- }
- if (lastPixel == -1 || lastPixel != srcPixel) {
- minDistance = 0x7FFFFFFF;
- nearestPixel = 0;
- for (j = 0; j < destN; j++) {
- r = (destReds[j] & 0xFF) - dr;
- g = (destGreens[j] & 0xFF) - dg;
- b = (destBlues[j] & 0xFF) - db;
- distance = r*r + g*g + b*b;
+ // 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) {
- nearestPixel = j;
+ lastindex = j;
if (distance == 0) break;
minDistance = distance;
}
}
- lastPixel = srcPixel;
+ 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;
}
- destPixel = nearestPixel;
}
- switch (destDepth) {
- case 1:
- if ((destPixel & 0x1) == 1) {
- destData[dp + (xd >> 3)] |= destInverseMasks[xd & 7];
- } else {
- destData[dp + (xd >> 3)] &= destInverseMasks[xd & 7] ^ -1;
- }
+ }
+}
+
+/**
+ * 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 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,
+ 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) ? ((srcWidth << 16) - 1) / dwm1 : 0;
+ final int dhm1 = destHeight - 1;
+ final int sfyi = (dhm1 != 0) ? ((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 = srcY * alphaStride + srcX;
break;
- case 2:
- destData[dp + (xd >> 2)] = (byte)((destData[dp + (xd >> 2)] & destInverseMasks[offset]) | (destPixel << (offset * 2)));
+ case ALPHA_MASK_PACKED:
+ if (alphaData == null) alphaMode = 0x10000;
+ alphaStride <<= 3;
+ apr = srcY * alphaStride + srcX;
break;
- case 4:
- if ((xd & 0x1) == 0) {
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0x0F) | ((destPixel & 0x0F) << 4));
- } else {
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0xF0) | (destPixel & 0x0F));
- }
+ case ALPHA_MASK_INDEX:
+ case ALPHA_MASK_RGB:
+ if (alphaData == null) alphaMode = 0x10000;
+ apr = 0;
break;
- case 8:
- destData[dp + xd] = (byte)(destPixel & 0xFF);
+ default:
+ alphaMode = (alphaMode << 16) / 255; // prescale
+ case ALPHA_CHANNEL_SOURCE:
+ apr = 0;
break;
}
- /* X stretch ends here */
- if (dy == dyd)
- break;
- while (ey >= 0) {
- ys += sys;
- ey -= dyd2;
- }
- yd += syd;
- ey += dys2;
- }
+ } 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) {
+ 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 ***/
+ 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 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 srcGlobalAlpha, byte[] srcAlphaData, int srcAlphaStride, 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) {
- int xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2;
- int dyd, dys, ey, dy, dyd2, dys2, ys, yd;
- short syd, sys;
- int dxd, dxs, ex, dx, dxd2, dxs2, xd;
- short sxd, sxs, sas;
- int sp, dp, sap = 0;
- int sr = 0, sg = 0, sb = 0, sa = 0, dr = 0, dg = 0, db = 0, da = 0;
- int srcPixel = 0, destPixel = 0;
- short so0 = 0, so1 = 1, so2 = 2, so3 = 3;
- int srcRedShift, srcGreenShift, srcBlueShift;
- int j, offset = 0;
- byte[] destMasks = null, destInverseMasks = null;
- int destN = 1 << destDepth;
- int r, g, b, nearestPixel = 0, lastPixel = -1;
- int distance, minDistance;
-
- srcRedShift = 32 - getMSBOffset(srcRedMask);
- srcGreenShift = 32 - getMSBOffset(srcGreenMask);
- srcBlueShift = 32 - getMSBOffset(srcBlueMask);
- if (destReds != null && destN > destReds.length) destN = destReds.length;
+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,
+ 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) ? ((srcWidth << 16) - 1) / dwm1 : 0;
+ final int dhm1 = destHeight - 1;
+ final int sfyi = (dhm1 != 0) ? ((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 1: destMasks = msbMasks1; destInverseMasks = msbInverseMasks1; break;
- case 2: destMasks = masks2; destInverseMasks = inverseMasks2; break;
- }
- if (srcOrder == LSB_FIRST) {
- switch (srcDepth) {
- case 16: so0 = 1; so1 = 0; break;
- case 24: so0 = 2; so1 = 1; so2 = 0; break;
- case 32: so0 = 3; so1 = 2; so2 = 1; so3 = 0; break;
- }
- }
- if (destOrder == LSB_FIRST) {
- switch (destDepth) {
- case 1: destMasks = lsbMasks1; destInverseMasks = lsbInverseMasks1; break;
+ 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 = srcY * alphaStride + srcX;
+ break;
+ case ALPHA_MASK_PACKED:
+ if (alphaData == null) alphaMode = 0x10000;
+ alphaStride <<= 3;
+ apr = srcY * alphaStride + srcX;
+ 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;
}
- }
-
- xs1 = srcX; xs2 = srcX + srcWidth - 1;
- ys1 = srcY; ys2 = srcY + srcHeight - 1;
- if (flipX) {
- xd1 = destX + destWidth - 1;
- xd2 = destX;
} else {
- xd1 = destX;
- xd2 = destX + destWidth - 1;
- }
- if (flipY) {
- yd1 = destY + destHeight - 1;
- yd2 = destY;
+ 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 {
- yd1 = destY;
- yd2 = destY + destHeight - 1;
- }
-
- /* Y preliminary calculations */
- dyd = yd2 - yd1;
- if (dyd < 0) dyd = -dyd;
- dys = ys2 - ys1;
- if (dys < 0) dys = -dys;
- dyd2 = dyd << 1;
- dys2 = dys << 1;
- syd = (short)((yd2 - yd1) > 0 ? 1 : -1);
- sys = (short)((ys2 - ys1) > 0 ? 1 : -1);
- ey = dys2 - dyd;
- ys = ys1;
- yd = yd1;
- /* X preliminary calculations */
- dxd = xd2 - xd1;
- if (dxd < 0) dxd = -dxd;
- dxs = xs2 - xs1;
- if (dxs < 0) dxs = -dxs;
- dxs2 = dxs << 1;
- dxd2 = dxd << 1;
- sxs = sas = (short)((xs2 - xs1) > 0 ? 1 : -1);
- sxd = (short)((xd2 - xd1) > 0 ? 1 : -1);
-
- sxs *= srcDepth / 8;
- xs1 *= srcDepth / 8;
-
- if (srcGlobalAlpha != -1) srcAlphaData = null;
- sa = srcGlobalAlpha;
- for (dy = 0; dy <= dyd; dy++) {
- /* X stretch starts here */
- offset = 3 - (srcX % 4);
- ex = dxs2 - dxd;
- xd = xd1;
- sp = ys * srcStride + xs1;
- dp = yd * destStride;
- if (srcAlphaData != null) sap = ys * srcAlphaStride + xs1;
- for (dx = 0; dx < dxd; dx++) {
- if (srcAlphaData != null) sa = srcAlphaData[sap] & 0xFF;
- switch (srcDepth) {
- case 16:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 8) | (srcData[sp+so1] & 0xFF);
+ 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 24:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 16) | ((srcData[sp+so1] & 0xFF) << 8) |
- (srcData[sp+so2] & 0xFF);
+ case ALPHA_CHANNEL_SOURCE:
+ alpha = (a << 16) / 255;
break;
- case 32:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 24) | ((srcData[sp+so1] & 0xFF) << 16) |
- ((srcData[sp+so2] & 0xFF) << 8) | (srcData[sp+so3] & 0xFF);
+ 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;
}
- dr = sr = ((srcPixel & srcRedMask) << srcRedShift) >>> 24;
- dg = sg = ((srcPixel & srcGreenMask) << srcGreenShift) >>> 24;
- db = sb = ((srcPixel & srcBlueMask) << srcBlueShift) >>> 24;
- if (op != BLIT_SRC) {
- switch (destDepth) {
- case 1:
- destPixel = (destData[dp + (xd >> 3)] & destMasks[xd & 7]) == 0 ? 0 : 1;
+ if (alpha != 0x10000) {
+ if (alpha == 0x0000) continue;
+ switch (dtype) {
+ case TYPE_INDEX_8:
+ indexq = destData[dp] & 0xff;
break;
- case 2:
- destPixel = ((destData[dp + (xd >> 2)] & destMasks[offset]) & 0xFF) >> (offset * 2);
+ case TYPE_INDEX_4:
+ if ((dp & 1) != 0) indexq = destData[dp >> 1] & 0x0f;
+ else indexq = (destData[dp >> 1] >>> 4) & 0x0f;
break;
- case 4:
- destPixel = destData[dp + (xd >> 1)] & 0xFF;
- if ((xd & 0x1) == 0) {
- destPixel = destPixel >> 4;
- } else {
- destPixel = destPixel & 0x0F;
- }
+ case TYPE_INDEX_2:
+ indexq = (destData[dp >> 2] >>> (6 - (dp & 3) * 2)) & 0x03;
break;
- case 8:
- destPixel = destData[dp + xd] & 0xFF;
+ 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;
}
- dr = destReds[destPixel] & 0xFF;
- dg = destGreens[destPixel] & 0xFF;
- db = destBlues[destPixel] & 0xFF;
- switch (op) {
- case BLIT_ALPHA:
- dr += (sr - dr) * sa / 255;
- dg += (sg - dg) * sa / 255;
- db += (sb - db) * sa / 255;
- break;
- }
- }
- if (lastPixel == -1 || lastPixel != srcPixel) {
- minDistance = 0x7FFFFFFF;
- nearestPixel = 0;
- for (j = 0; j < destN; j++) {
- r = (destReds[j] & 0xFF) - dr;
- g = (destGreens[j] & 0xFF) - dg;
- b = (destBlues[j] & 0xFF) - db;
- distance = r*r + g*g + b*b;
+ // 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) {
- nearestPixel = j;
+ lastindex = j;
if (distance == 0) break;
minDistance = distance;
}
}
- lastPixel = srcPixel;
- }
- destPixel = nearestPixel;
- switch (destDepth) {
- case 1:
- if ((destPixel & 0x1) == 1) {
- destData[dp + (xd >> 3)] |= destInverseMasks[xd & 7];
- } else {
- destData[dp + (xd >> 3)] &= destInverseMasks[xd & 7] ^ -1;
- }
+ 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 2:
- destData[dp + (xd >> 2)] = (byte)((destData[dp + (xd >> 2)] & destInverseMasks[offset]) | (destPixel << (offset * 2)));
+ 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 4:
- if ((xd & 0x1) == 0) {
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0x0F) | ((destPixel & 0x0F) << 4));
- } else {
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0xF0) | (destPixel & 0x0F));
- }
- break;
- case 8:
- destData[dp + xd] = (byte)(destPixel & 0xFF);
- break;
- }
- while (ex >= 0) {
- sp += sxs;
- ex -= dxd2;
- if (srcAlphaData != null) sap += sas;
- }
- xd += sxd;
- ex += dxs2;
- if (offset == 0) {
- offset = 3;
- } else {
- offset--;
+ 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;
}
}
-
- if (srcAlphaData != null) sa = srcAlphaData[sap] & 0xFF;
- switch (srcDepth) {
- case 16:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 8) | (srcData[sp+so1] & 0xFF);
- break;
- case 24:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 16) | ((srcData[sp+so1] & 0xFF) << 8) |
- (srcData[sp+so2] & 0xFF);
- break;
- case 32:
- srcPixel = ((srcData[sp+so0] & 0xFF) << 24) | ((srcData[sp+so1] & 0xFF) << 16) |
- ((srcData[sp+so2] & 0xFF) << 8) | (srcData[sp+so3] & 0xFF);
- break;
- }
- dr = sr = ((srcPixel & srcRedMask) << srcRedShift) >>> 24;
- dg = sg = ((srcPixel & srcGreenMask) << srcGreenShift) >>> 24;
- db = sb = ((srcPixel & srcBlueMask) << srcBlueShift) >>> 24;
- if (op != BLIT_SRC) {
- switch (destDepth) {
- case 1:
- destPixel = (destData[dp + (xd >> 3)] & destMasks[xd & 7]) == 0 ? 0 : 1;
- break;
- case 2:
- destPixel = ((destData[dp + (xd >> 2)] & destMasks[offset]) & 0xFF) >> (offset * 2);
- break;
- case 4:
- destPixel = destData[dp + (xd >> 1)] & 0xFF;
- if ((xd & 0x1) == 0) {
- destPixel = destPixel >> 4;
- } else {
- destPixel = destPixel & 0x0F;
- }
- break;
- case 8:
- destPixel = destData[dp + xd] & 0xFF;
- break;
- }
- dr = destReds[destPixel] & 0xFF;
- dg = destGreens[destPixel] & 0xFF;
- db = destBlues[destPixel] & 0xFF;
- switch (op) {
- case BLIT_ALPHA:
- dr += (sr - dr) * sa / 255;
- dg += (sg - dg) * sa / 255;
- db += (sb - db) * sa / 255;
- break;
- }
- }
- if (lastPixel == -1 || lastPixel != srcPixel) {
- minDistance = 0x7FFFFFFF;
- nearestPixel = 0;
- for (j = 0; j < destN; j++) {
- r = (destReds[j] & 0xFF) - dr;
- g = (destGreens[j] & 0xFF) - dg;
- b = (destBlues[j] & 0xFF) - db;
- distance = r*r + g*g + b*b;
- if (distance < minDistance) {
- nearestPixel = j;
- if (distance == 0) break;
- minDistance = distance;
- }
- }
- lastPixel = srcPixel;
- }
- destPixel = nearestPixel;
- switch (destDepth) {
- case 1:
- if ((destPixel & 0x1) == 1) {
- destData[dp + (xd >> 3)] |= destInverseMasks[xd & 7];
- } else {
- destData[dp + (xd >> 3)] &= destInverseMasks[xd & 7] ^ -1;
- }
- break;
- case 2:
- destData[dp + (xd >> 2)] = (byte)((destData[dp + (xd >> 2)] & destInverseMasks[offset]) | (destPixel << (offset * 2)));
- break;
- case 4:
- if ((xd & 0x1) == 0) {
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0x0F) | ((destPixel & 0x0F) << 4));
- } else {
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0xF0) | (destPixel & 0x0F));
- }
- break;
- case 8:
- destData[dp + xd] = (byte)(destPixel & 0xFF);
- break;
- }
- /* X stretch ends here */
- if (dy == dyd)
- break;
- while (ey >= 0) {
- ys += sys;
- ey -= dyd2;
- }
- yd += syd;
- ey += dys2;
}
}
/**
- * Stretches the source, a 1-bit image, into the destination, a 1-bit image.
+ * Computes the required channel shift from a mask.
*/
-static void stretch1(byte[] srcData, int srcStride, int srcOrder, int srcX, int srcY, int srcWidth, int srcHeight, byte[] destData, int destStride, int destOrder, int destX, int destY, int destWidth, int destHeight, boolean flipX, boolean flipY) {
- int xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2;
- int dyd, dys, ey, dy, dyd2, dys2, ys, yd;
- short syd, sys;
- int dxd, dxs, ex, dx, dxd2, dxs2, xs, xd;
- short sxd, sxs;
- byte pixel;
- int sp, dp;
- byte[] masks, inverseMasks;
-
- if (srcOrder == LSB_FIRST) {
- masks = lsbMasks1;
- } else {
- masks = msbMasks1;
- }
- if (destOrder == LSB_FIRST) {
- inverseMasks = lsbInverseMasks1;
- } else {
- inverseMasks = msbInverseMasks1;
- }
-
- xs1 = srcX; xs2 = srcX + srcWidth - 1;
- ys1 = srcY; ys2 = srcY + srcHeight - 1;
- if (flipX) {
- xd1 = destX + destWidth - 1;
- xd2 = destX;
- } else {
- xd1 = destX;
- xd2 = destX + destWidth - 1;
- }
- if (flipY) {
- yd1 = destY + destHeight - 1;
- yd2 = destY;
- } else {
- yd1 = destY;
- yd2 = destY + destHeight - 1;
- }
-
- /* Y preliminary calculations */
- dyd = yd2 - yd1;
- if (dyd < 0) dyd = -dyd;
- dys = ys2 - ys1;
- if (dys < 0) dys = -dys;
- dyd2 = dyd << 1;
- dys2 = dys << 1;
- syd = (short)((yd2 - yd1) > 0 ? 1 : -1);
- sys = (short)((ys2 - ys1) > 0 ? 1 : -1);
- ey = dys2 - dyd;
- ys = ys1;
- yd = yd1;
- /* X preliminary calculations */
- dxd = xd2 - xd1;
- if (dxd < 0) dxd = -dxd;
- dxs = xs2 - xs1;
- if (dxs < 0) dxs = -dxs;
- dxd2 = dxd << 1;
- dxs2 = dxs << 1;
- sxd = (short)((xd2 - xd1) > 0 ? 1 : -1);
- sxs = (short)((xs2 - xs1) > 0 ? 1 : -1);
-
- for (dy = 0; dy <= dyd; dy++) {
- /* X stretch starts here */
- ex = dxs2 - dxd;
- xs = xs1;
- xd = xd1;
- sp = ys * srcStride;
- dp = yd * destStride;
- pixel = (byte)(srcData[sp + (xs >> 3)] & masks[xs & 7]);
- for (dx = 0; dx < dxd; dx++) {
- if (pixel != 0)
- destData[dp + (xd >> 3)] |= masks[xd & 7];
- else
- destData[dp + (xd >> 3)] &= inverseMasks[xd & 7];
- if (ex >= 0) {
- do {
- xs += sxs;
- ex -= dxd2;
- } while (ex >= 0);
- pixel = (byte)(srcData[sp + (xs >> 3)] & masks[xs & 7]);
- }
- xd += sxd;
- ex += dxs2;
- }
- if (pixel != 0)
- destData[dp + (xd >> 3)] |= masks[xd & 7];
- else
- destData[dp + (xd >> 3)] &= inverseMasks[xd & 7];
- /* X stretch ends here */
- if (dy == dyd)
- break;
- while (ey >= 0) {
- ys += sys;
- ey -= dyd2;
- }
- yd += syd;
- ey += dys2;
+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;
}
/**
- * Stretches the source, a 16-bit image, into the destination, a 16-bit image.
- * The images are assumed to have the same red, green, and blue masks.
- *
- * Untested - would need an X server with the same red, green and blue
- * masks as the file has, namely, 0x7C00, 0x3E0, 0x1F. Most 16-bit X servers
- * have masks of 0xF800, 0x7E0, 0x1F.
+ * Computes the required channel width (depth) from a mask.
*/
-static void stretch16(byte[] srcData, int srcStride, int srcX, int srcY, int srcWidth, int srcHeight, byte[] destData, int destStride, int destX, int destY, int destWidth, int destHeight, boolean flipX, boolean flipY) {
- int xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2;
- int dyd, dys, ey, dy, dyd2, dys2, yd, ys;
- short syd, sys;
- int dxd, dxs, ex, dx, dxd2, dxs2, xs, xd;
- short sxd, sxs;
- byte pixel0, pixel1;
- int sp, dp;
-
- xs1 = srcX; xs2 = srcX + srcWidth - 1;
- ys1 = srcY; ys2 = srcY + srcHeight - 1;
- if (flipX) {
- xd1 = destX + destWidth - 1;
- xd2 = destX;
- } else {
- xd1 = destX;
- xd2 = destX + destWidth - 1;
- }
- if (flipY) {
- yd1 = destY + destHeight - 1;
- yd2 = destY;
- } else {
- yd1 = destY;
- yd2 = destY + destHeight - 1;
- }
-
- /* Y preliminary calculations */
- dyd = yd2 - yd1;
- if (dyd < 0) dyd = -dyd;
- dys = ys2 - ys1;
- if (dys < 0) dys = -dys;
- dyd2 = dyd << 1;
- dys2 = dys << 1;
- syd = (short)((yd2 - yd1) > 0 ? 1 : -1);
- sys = (short)((ys2 - ys1) > 0 ? 1 : -1);
- ey = dys2 - dyd;
- ys = ys1;
- yd = yd1;
- /* X preliminary calculations */
- dxd = xd2 - xd1;
- if (dxd < 0) dxd = -dxd;
- dxs = xs2 - xs1;
- if (dxs < 0) dxs = -dxs;
- dxd2 = dxd << 1;
- dxs2 = dxs << 1;
- sxd = (short)((xd2 - xd1) > 0 ? 1 : -1);
- sxs = (short)((xs2 - xs1) > 0 ? 1 : -1);
-
- for (dy = 0; dy <= dyd; dy++) {
- /* X stretch starts here */
- ex = dxs2 - dxd;
- xs = xs1;
- xd = xd1;
- sp = ys * srcStride;
- dp = yd * destStride;
- pixel0 = srcData[sp + xs];
- pixel1 = srcData[sp + xs + 1];
- for (dx = 0; dx < dxd; dx++) {
- destData[dp + xd] = pixel0;
- destData[dp + xd + 1] = pixel1;
- if (ex >= 0) {
- do {
- xs += (sxs << 1);
- ex -= dxd2;
- } while (ex >= 0);
- pixel0 = srcData[sp + xs];
- pixel1 = srcData[sp + xs + 1];
- }
- xd += (sxd << 1);
- ex += dxs2;
- }
- destData[dp + xd] = pixel0;
- destData[dp + xd + 1] = pixel1;
- /* X stretch ends here */
- if (dy == dyd)
- break;
- while (ey >= 0) {
- ys += sys;
- ey -= dyd2;
- }
- yd += syd;
- ey += dys2;
- }
+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;
}
/**
- * Stretches the source, a 2-bit image, into the destination, a 2-bit image.
+ * Extracts a field from packed RGB data given a mask for that field.
*/
-static void stretch2(byte[] srcData, int srcStride, int srcX, int srcY, int srcWidth, int srcHeight, byte[] destData, int destStride, int destX, int destY, int destWidth, int destHeight, int[] mapping, boolean flipX, boolean flipY) {
- int xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2;
- int dyd, dys, ey, dy, dyd2, dys2, yd, ys;
- short syd, sys;
- int dxd, dxs, ex, dx, dxd2, dxs2, xs, xd;
- short sxd, sxs;
- byte pixel;
- int sp, dp, x;
- byte [] masks = { (byte)0x03, (byte)0x0C, (byte)0x30, (byte)0xC0 };
- byte [] inverseMasks = { (byte)0xFC, (byte)0xF3, (byte)0xCF, (byte)0x3F };
-
- xs1 = srcX; xs2 = srcX + srcWidth - 1;
- ys1 = srcY; ys2 = srcY + srcHeight - 1;
- if (flipX) {
- xd1 = destX + destWidth - 1;
- xd2 = destX;
- } else {
- xd1 = destX;
- xd2 = destX + destWidth - 1;
- }
- if (flipY) {
- yd1 = destY + destHeight - 1;
- yd2 = destY;
- } else {
- yd1 = destY;
- yd2 = destY + destHeight - 1;
- }
-
- /* Y preliminary calculations */
- dyd = yd2 - yd1;
- if (dyd < 0) dyd = -dyd;
- dys = ys2 - ys1;
- if (dys < 0) dys = -dys;
- dyd2 = dyd << 1;
- dys2 = dys << 1;
- syd = (short)((yd2 - yd1) > 0 ? 1 : -1);
- sys = (short)((ys2 - ys1) > 0 ? 1 : -1);
- ey = dys2 - dyd;
- ys = ys1;
- yd = yd1;
- /* X preliminary calculations */
- dxd = xd2 - xd1;
- if (dxd < 0) dxd = -dxd;
- dxs = xs2 - xs1;
- if (dxs < 0) dxs = -dxs;
- dxd2 = dxd << 1;
- dxs2 = dxs << 1;
- sxd = (short)((xd2 - xd1) > 0 ? 1 : -1);
- sxs = (short)((xs2 - xs1) > 0 ? 1 : -1);
-
- for (dy = 0; dy <= dyd; dy++) {
- /* X stretch starts here */
- int offset = 3 - (srcX % 4);
- ex = dxs2 - dxd;
- xs = xs1;
- xd = xd1;
- sp = ys * srcStride;
- dp = yd * destStride;
- x = (byte)(((srcData[sp + (xs >> 2)] & masks[offset]) & 0xFF) >> (offset * 2));
- pixel = (byte)(mapping == null ? x : mapping[x]);
- for (dx = 0; dx < dxd; dx++) {
- destData[dp + (xd >> 2)] = (byte)((destData[dp + (xd >> 2)] & inverseMasks[offset]) | (pixel << (offset * 2)));
- if (ex >= 0) {
- do {
- xs += sxs;
- ex -= dxd2;
- } while (ex >= 0);
- x = (byte)(((srcData[sp + (xs >> 2)] & masks[offset]) & 0xFF) >> (offset * 2));
- pixel = (byte)(mapping == null ? x : mapping[x]);
- }
- xd += sxd;
- ex += dxs2;
- if (offset == 0) {
- offset = 3;
- } else {
- offset--;
- }
- }
- destData[dp + (xd >> 2)] = (byte)((destData[dp + (xd >> 2)] & inverseMasks[offset]) | (pixel << (offset * 2)));
- /* X stretch ends here */
- if (dy == dyd)
- break;
- while (ey >= 0) {
- ys += sys;
- ey -= dyd2;
- }
- yd += syd;
- ey += dys2;
- }
+static byte getChannelField(int data, int mask) {
+ final int shift = getChannelShift(mask);
+ return ANY_TO_EIGHT[getChannelWidth(mask, shift)][(data & mask) >>> shift];
}
/**
- * Stretches the source, a 24-bit image, into the destination, a 24-bit image.
- * The images must have the same red, green, and blue masks.
- * The image are assumed to have 24 bits per pixel; many 24-bit images
- * use 32 bits per pixel.
+ * 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.
*
- * Untested. Would require an X server with a depth of 24 which has 24 bits per
- * pixel. Most X servers with depth 24 actually have 32 bits per pixel.
+ * @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 void stretch24(byte[] srcData, int srcStride, int srcX, int srcY, int srcWidth, int srcHeight, byte[] destData, int destStride, int destX, int destY, int destWidth, int destHeight, boolean flipX, boolean flipY) {
- int xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2;
- int dyd, dys, ey, dy, dyd2, dys2, ys, yd;
- short syd, sys;
- int dxd, dxs, ex, dx, dxd2, dxs2;
- short sxd, sxs;
- byte r, g, b;
- int sp, dp;
-
- xs1 = srcX; xs2 = srcX + srcWidth - 1;
- ys1 = srcY; ys2 = srcY + srcHeight - 1;
- if (flipX) {
- xd1 = destX + destWidth - 1;
- xd2 = destX;
- } else {
- xd1 = destX;
- xd2 = destX + destWidth - 1;
- }
- if (flipY) {
- yd1 = destY + destHeight - 1;
- yd2 = destY;
+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 {
- yd1 = destY;
- yd2 = destY + destHeight - 1;
- }
-
- /* Y preliminary calculations */
- dyd = yd2 - yd1;
- if (dyd < 0) dyd = -dyd;
- dys = ys2 - ys1;
- if (dys < 0) dys = -dys;
- dyd2 = dyd << 1;
- dys2 = dys << 1;
- syd = (short)((yd2 - yd1) > 0 ? 1 : -1);
- sys = (short)((ys2 - ys1) > 0 ? 1 : -1);
- ey = dys2 - dyd;
- ys = ys1;
- yd = yd1;
- /* X preliminary calculations */
- dxd = xd2 - xd1;
- if (dxd < 0) dxd = -dxd;
- dxs = xs2 - xs1;
- if (dxs < 0) dxs = -dxs;
- dxd2 = dxd << 1;
- dxs2 = dxs << 1;
- sxd = (short)((xd2 - xd1) > 0 ? 3 : -3);
- sxs = (short)((xs2 - xs1) > 0 ? 3 : -3);
- xs1 *= 3;
- xd1 *= 3;
-
- for (dy = 0; dy <= dyd; dy++) {
- /* X stretch starts here */
- ex = dxs2 - dxd;
- sp = ys * srcStride + xs1;
- dp = yd * destStride + xd1;
- r = srcData[sp];
- g = srcData[sp + 1];
- b = srcData[sp + 2];
- for (dx = 0; dx < dxd; dx++) {
- destData[dp] = r;
- destData[dp + 1] = g;
- destData[dp + 2] = b;
- if (ex >= 0) {
- while (ex >= 0) {
- sp += sxs;
- ex -= dxd2;
+ /* 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;
}
- r = srcData[sp];
- g = srcData[sp + 1];
- b = srcData[sp + 2];
}
- dp += sxd;
- ex += dxs2;
- }
- destData[dp] = r;
- destData[dp + 1] = g;
- destData[dp + 2] = b;
- /* X stretch ends here */
- if (dy == dyd)
- break;
- while (ey >= 0) {
- ys += sys;
- ey -= dyd2;
}
- yd += syd;
- ey += dys2;
}
+ return new ImageData(bandWidth, bandHeight, bitmapDepth, paletteData, 4, bitmapData);
}
-/**
- * Stretches the source, a 32-bit image, into the destination, a 32-bit image.
- * The images must have the same red, green, and blue masks.
+/*
+ * Fill in gradated values for a color channel
*/
-static void stretch32(byte[] srcData, int srcStride, int srcX, int srcY, int srcWidth, int srcHeight, byte[] destData, int destStride, int destX, int destY, int destWidth, int destHeight, boolean flipX, boolean flipY) {
- int xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2;
- int dyd, dys, ey, dy, dyd2, dys2, ys, yd;
- short syd, sys;
- int dxd, dxs, ex, dx, dxd2, dxs2;
- short sxd, sxs;
- byte r, g, b, a;
- int sp, dp;
-
- xs1 = srcX; xs2 = srcX + srcWidth - 1;
- ys1 = srcY; ys2 = srcY + srcHeight - 1;
- if (flipX) {
- xd1 = destX + destWidth - 1;
- xd2 = destX;
- } else {
- xd1 = destX;
- xd2 = destX + destWidth - 1;
- }
- if (flipY) {
- yd1 = destY + destHeight - 1;
- yd2 = destY;
- } else {
- yd1 = destY;
- yd2 = destY + destHeight - 1;
- }
-
- /* Y preliminary calculations */
- dyd = yd2 - yd1;
- if (dyd < 0) dyd = -dyd;
- dys = ys2 - ys1;
- if (dys < 0) dys = -dys;
- dyd2 = dyd << 1;
- dys2 = dys << 1;
- syd = (short)((yd2 - yd1) > 0 ? 1 : -1);
- sys = (short)((ys2 - ys1) > 0 ? 1 : -1);
- ey = dys2 - dyd;
- ys = ys1;
- yd = yd1;
- /* X preliminary calculations */
- dxd = xd2 - xd1;
- if (dxd < 0) dxd = -dxd;
- dxs = xs2 - xs1;
- if (dxs < 0) dxs = -dxs;
- dxd2 = dxd << 1;
- dxs2 = dxs << 1;
- sxd = (short)((xd2 - xd1) > 0 ? 4 : -4);
- sxs = (short)((xs2 - xs1) > 0 ? 4 : -4);
- xs1 *= 4;
- xd1 *= 4;
-
- for (dy = 0; dy <= dyd; dy++) {
- /* X stretch starts here */
- ex = dxs2 - dxd;
- sp = ys * srcStride + xs1;
- dp = yd * destStride + xd1;
- r = srcData[sp];
- g = srcData[sp + 1];
- b = srcData[sp + 2];
- a = srcData[sp + 3];
- for (dx = 0; dx < dxd; dx++) {
- destData[dp] = r;
- destData[dp + 1] = g;
- destData[dp + 2] = b;
- destData[dp + 3] = a;
- if (ex >= 0) {
- while (ex >= 0) {
- sp += sxs;
- ex -= dxd2;
- }
- r = srcData[sp];
- g = srcData[sp + 1];
- b = srcData[sp + 2];
- a = srcData[sp + 3];
- }
- dp += sxd;
- ex += dxs2;
+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;
}
- destData[dp] = r;
- destData[dp + 1] = g;
- destData[dp + 2] = b;
- destData[dp + 3] = a;
- /* X stretch ends here */
- if (dy == dyd)
- break;
- while (ey >= 0) {
- ys += sys;
- ey -= dyd2;
+ } else {
+ for (int dx = 0; dx < bandWidth; ++dx, dp += 4) {
+ bitmapData[dp] = (byte)(val >>> 16);
+ val += inc;
}
- yd += syd;
- ey += dys2;
- }
+ }
}
-/**
- * Stretches the source, a 4-bit image, into the destination, a 4-bit image.
+/*
+ * Fill in dithered gradated values for a color channel
*/
-static void stretch4(byte[] srcData, int srcStride, int srcX, int srcY, int srcWidth, int srcHeight, byte[] destData, int destStride, int destX, int destY, int destWidth, int destHeight, int[] mapping, boolean flipX, boolean flipY) {
- int xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2;
- int dyd, dys, ey, dy, dyd2, dys2, yd, ys;
- short syd, sys;
- int dxd, dxs, ex, dx, dxd2, dxs2, xs, xd;
- short sxd, sxs;
- byte pixel;
- int sp, dp;
-
- xs1 = srcX; xs2 = srcX + srcWidth - 1;
- ys1 = srcY; ys2 = srcY + srcHeight - 1;
- if (flipX) {
- xd1 = destX + destWidth - 1;
- xd2 = destX;
- } else {
- xd1 = destX;
- xd2 = destX + destWidth - 1;
- }
- if (flipY) {
- yd1 = destY + destHeight - 1;
- yd2 = destY;
- } else {
- yd1 = destY;
- yd2 = destY + destHeight - 1;
- }
-
- /* Y preliminary calculations */
- dyd = yd2 - yd1;
- if (dyd < 0) dyd = -dyd;
- dys = ys2 - ys1;
- if (dys < 0) dys = -dys;
- dyd2 = dyd << 1;
- dys2 = dys << 1;
- syd = (short)((yd2 - yd1) > 0 ? 1 : -1);
- sys = (short)((ys2 - ys1) > 0 ? 1 : -1);
- ey = dys2 - dyd;
- ys = ys1;
- yd = yd1;
- /* X preliminary calculations */
- dxd = xd2 - xd1;
- if (dxd < 0) dxd = -dxd;
- dxs = xs2 - xs1;
- if (dxs < 0) dxs = -dxs;
- dxd2 = dxd << 1;
- dxs2 = dxs << 1;
- sxd = (short)((xd2 - xd1) > 0 ? 1 : -1);
- sxs = (short)((xs2 - xs1) > 0 ? 1 : -1);
-
- for (dy = 0; dy <= dyd; dy++) {
- /* X stretch starts here */
- ex = dxs2 - dxd;
- xs = xs1;
- xd = xd1;
- sp = ys * srcStride;
- dp = yd * destStride;
- int x = srcData[sp + (xs >> 1)];
- if ((xs & 1) != 0) {
- pixel = (byte)((mapping == null) ? (x & 0x0F) : (mapping[x & 0x0F] & 0x0F));
- } else {
- pixel = (byte)((mapping == null) ? (x >> 4) : (mapping[x >> 4] & 0x0F));
+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;
}
- for (dx = 0; dx < dxd; dx++) {
- if ((xd & 1) != 0)
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0xF0) | pixel);
- else
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0x0F) | (pixel << 4));
- if (ex >= 0) {
- do {
- xs += sxs;
- ex -= dxd2;
- } while (ex >= 0);
- x = srcData[sp + (xs >> 1)];
- if ((xd & 1) != 0) {
- pixel = (byte)((mapping == null) ? (x & 0x0F) : (mapping[x & 0x0F] & 0x0F));
- } else {
- pixel = (byte)((mapping == null) ? ((x >> 4) & 0x0F) : (mapping[x >> 4] & 0x0F));
- }
+ } 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);
}
- xd += sxd;
- ex += dxs2;
+ val += inc;
}
- if ((xd & 1) != 0)
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0xF0) | pixel);
- else
- destData[dp + (xd >> 1)] = (byte)((destData[dp + (xd >> 1)] & 0x0F) | (pixel << 4));
- /* X stretch ends here */
- if (dy == dyd)
- break;
- while (ey >= 0) {
- ys += sys;
- ey -= dyd2;
- }
- yd += syd;
- ey += dys2;
}
}
/**
- * Stretches the source, an 8-bit image, into the destination, an 8-bit image.
+ * 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 stretch8(byte[] srcData, int srcStride, int srcX, int srcY, int srcWidth, int srcHeight, byte[] destData, int destStride, int destX, int destY, int destWidth, int destHeight, int[] mapping, boolean flipX, boolean flipY) {
- int xs1, ys1, xs2, ys2, xd1, yd1, xd2, yd2;
- int dyd, dys, ey, dy, dyd2, dys2, yd, ys;
- short syd, sys;
- int dxd, dxs, ex, dx, dxd2, dxs2, xs, xd;
- short sxd, sxs;
- byte pixel;
- int sp, dp, x;
-
- xs1 = srcX; xs2 = srcX + srcWidth - 1;
- ys1 = srcY; ys2 = srcY + srcHeight - 1;
- if (flipX) {
- xd1 = destX + destWidth - 1;
- xd2 = destX;
+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 {
- xd1 = destX;
- xd2 = destX + destWidth - 1;
- }
- if (flipY) {
- yd1 = destY + destHeight - 1;
- yd2 = destY;
- } else {
- yd1 = destY;
- yd2 = destY + destHeight - 1;
- }
-
- /* Y preliminary calculations */
- dyd = yd2 - yd1;
- if (dyd < 0) dyd = -dyd;
- dys = ys2 - ys1;
- if (dys < 0) dys = -dys;
- dyd2 = dyd << 1;
- dys2 = dys << 1;
- syd = (short)((yd2 - yd1) > 0 ? 1 : -1);
- sys = (short)((ys2 - ys1) > 0 ? 1 : -1);
- ey = dys2 - dyd;
- ys = ys1;
- yd = yd1;
- /* X preliminary calculations */
- dxd = xd2 - xd1;
- if (dxd < 0) dxd = -dxd;
- dxs = xs2 - xs1;
- if (dxs < 0) dxs = -dxs;
- dxd2 = dxd << 1;
- dxs2 = dxs << 1;
- sxd = (short)((xd2 - xd1) > 0 ? 1 : -1);
- sxs = (short)((xs2 - xs1) > 0 ? 1 : -1);
-
- for (dy = 0; dy <= dyd; dy++) {
- /* X stretch starts here */
- ex = dxs2 - dxd;
- xs = xs1;
- xd = xd1;
- sp = ys * srcStride;
- dp = yd * destStride;
- x = srcData[sp + xs] & 0xFF;
- pixel = (byte)(mapping == null ? x : mapping[x]);
- for (dx = 0; dx < dxd; dx++) {
- destData[dp + xd] = pixel;
- if (ex >= 0) {
- do {
- xs += sxs;
- ex -= dxd2;
- } while (ex >= 0);
- x = srcData[sp + xs] & 0xFF;
- pixel = (byte)(mapping == null ? x : mapping[x]);
- }
- xd += sxd;
- ex += dxs2;
- }
- destData[dp + xd] = pixel;
- /* X stretch ends here */
- if (dy == dyd)
- break;
- while (ey >= 0) {
- ys += sys;
- ey -= dyd2;
+ 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);
+ }
}
- yd += syd;
- ey += dys2;
}
+ 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 1528cf33db..a892742646 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
@@ -140,10 +140,17 @@ public ImageData[] load(String filename) {
InputStream stream = null;
try {
stream = new FileInputStream(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 load(stream);
+ return null;
}
/**
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 f4acc565ba..01fb710417 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
@@ -5,7 +5,7 @@ package org.eclipse.swt.graphics;
* All Rights Reserved
*/
-import java.io.Serializable;
+import org.eclipse.swt.internal.SerializableCompatability;
/**
* Instances of this class represent places on the (x, y)
@@ -25,7 +25,7 @@ import java.io.Serializable;
* @see Rectangle
*/
-public final class Point implements Serializable {
+public final class Point implements SerializableCompatability {
/**
* the x coordinate of the point
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 50ee5806c2..fac1f0bd09 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
@@ -5,7 +5,7 @@ package org.eclipse.swt.graphics;
* All Rights Reserved
*/
-import java.io.Serializable;
+import org.eclipse.swt.internal.SerializableCompatability;
import org.eclipse.swt.*;
/**
@@ -25,7 +25,7 @@ import org.eclipse.swt.*;
* @see Color
*/
-public final class RGB implements Serializable {
+public final class RGB implements SerializableCompatability {
/**
* the red component of the RGB
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 16d01bd900..95bfa1f2b9 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
@@ -5,8 +5,8 @@ package org.eclipse.swt.graphics;
* All Rights Reserved
*/
-import java.io.Serializable;
import org.eclipse.swt.*;
+import org.eclipse.swt.internal.SerializableCompatability;
/**
* Instances of this class represent rectangular areas in an
@@ -28,7 +28,7 @@ import org.eclipse.swt.*;
* @see Point
*/
-public final class Rectangle implements Serializable {
+public final class Rectangle implements SerializableCompatability {
/**
* the x coordinate of the rectangle
@@ -238,6 +238,11 @@ public String toString () {
/**
* 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
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 412fb6f066..373ae3d652 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
@@ -31,12 +31,12 @@ public class Callback {
/**
* SWT Major version number (must be >= 0)
*/
- public static int MAJOR_VERSION = 0;
+ public static int MAJOR_VERSION = 2;
/**
* SWT Minor version number (must be in the range 0..999)
*/
- public static int MINOR_VERSION = 125;
+ public static int MINOR_VERSION = 6;
/**
* SWT revision number (must be >= 0)
@@ -158,6 +158,18 @@ public static int getVersion () {
public static native String getPlatform ();
/**
+ * Returns the OS name.
+ *
+ * @return the os name of the currently running SWT
+ */
+static String getOS () {
+ String name = System.getProperty("os.name");
+ if (name.regionMatches(true, 0, "win", 0, 3)) return "win32";
+ if (name.regionMatches(true, 0, "sun", 0, 3)) return "solaris";
+ return name.toLowerCase();
+}
+
+/**
* Returns the SWT revision number as an integer. Revision changes
* occur as a result of non-API breaking bug fixes.
*
@@ -227,7 +239,10 @@ public static void loadLibrary () {
* @param name the name of the library to load
*/
public static void loadLibrary (String name) {
- String newName = name + MAJOR_VERSION;
+ /* Include os name to support same window system on
+ * different operating systems
+ */
+ String newName = name + "-" + getOS () + "-" + MAJOR_VERSION;
/* Force 3 digits in minor version number */
if (MINOR_VERSION < 10) {
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 1b692b2383..6754225bda 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
@@ -188,7 +188,7 @@ public String getText () {
/**
* 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.
+ * <em>title</em>, to the argument, which must not be null.
*
* @param text the new text
*
@@ -201,6 +201,7 @@ public String getText () {
* </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/Item.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/widgets/Item.java
index e6c7b68425..f80c0330b0 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
@@ -79,6 +79,9 @@ void releaseWidget () {
*
* @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>
@@ -86,6 +89,7 @@ void releaseWidget () {
*/
public void setImage (Image image) {
checkWidget ();
+ if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
this.image = image;
}
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 e5aa85a87e..911f2d4044 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
@@ -15,13 +15,14 @@ package org.eclipse.swt.widgets;
class RunnableLock {
Runnable runnable;
Thread thread;
+ Throwable throwable;
RunnableLock (Runnable runnable) {
this.runnable = runnable;
}
boolean done () {
- return runnable == null;
+ return runnable == null || throwable != null;
}
void run () {
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 ce34733dc5..fd2426f6b2 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
@@ -4,6 +4,8 @@ package org.eclipse.swt.widgets;
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved
*/
+
+import org.eclipse.swt.*;
/**
* Instances of this class provide synchronization support
@@ -88,11 +90,14 @@ boolean runAsyncMessages () {
syncThread = lock.thread;
try {
lock.run ();
+ } catch (Throwable t) {
+ lock.throwable = t;
+ SWT.error (SWT.ERROR_FAILED_EXEC, t);
} finally {
syncThread = null;
+ lock.notifyAll ();
}
- lock.notifyAll ();
- };
+ }
} while (true);
}
@@ -104,6 +109,10 @@ boolean runAsyncMessages () {
*
* @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) {
@@ -134,6 +143,9 @@ protected void syncExec (Runnable runnable) {
if (interrupted) {
Thread.currentThread ().interrupt ();
}
+ if (lock.throwable != null) {
+ SWT.error (SWT.ERROR_FAILED_EXEC, lock.throwable);
+ }
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/version.txt b/bundles/org.eclipse.swt/Eclipse SWT/common/version.txt
index 1c3227e43c..95f2f505fc 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/version.txt
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/version.txt
@@ -1 +1 @@
-version 0.125 \ No newline at end of file
+version 2.006 \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/Compatability.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/Compatability.java
new file mode 100644
index 0000000000..583f5f7d4a
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/Compatability.java
@@ -0,0 +1,26 @@
+package org.eclipse.swt.internal;
+
+public class Compatability {
+
+/**
+ * Answers the double conversion of the most negative (i.e.
+ * closest to negative infinity) integer value which is
+ * greater than the argument.
+ *
+ * @author OTI
+ * @version initial
+ *
+ * @param d the value to be converted
+ * @return the ceiling of the argument.
+ */
+public static double ceil (double d) {
+ long l = (long) d;
+ if (d == l) return d;
+ if (d < 0)
+ return (double) l;
+ else
+ return (double) l + 1;
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/EventObjectCompatability.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/EventObjectCompatability.java
new file mode 100644
index 0000000000..227cf8e95d
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/EventObjectCompatability.java
@@ -0,0 +1,43 @@
+package org.eclipse.swt.internal;
+
+public class EventObjectCompatability {
+ /**
+ * The event source.
+ */
+ protected transient Object source;
+/**
+ * Constructs a new instance of this class.
+ *
+ * @author OTI
+ * @version initial
+ *
+ * @param source the object which fired the event
+ */
+public EventObjectCompatability(Object source) {
+ if (source != null) this.source = source;
+ else throw new IllegalArgumentException();
+}
+
+/**
+ * Answers the event source.
+ *
+ * @author OTI
+ * @version initial
+ *
+ * @return the object which fired the event
+ */
+public Object getSource() {
+ return source;
+}
+/**
+ * Answers the string representation of this EventObject.
+ *
+ * @author OTI
+ * @version initial
+ *
+ * @return the string representation of this EventObject
+ */
+public String toString() {
+ return getClass().getName() + "[source=" + String.valueOf(source) + ']';
+}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SerializableCompatability.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SerializableCompatability.java
new file mode 100644
index 0000000000..ef873917b2
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common_j2me/org/eclipse/swt/internal/SerializableCompatability.java
@@ -0,0 +1,6 @@
+package org.eclipse.swt.internal;
+
+public interface SerializableCompatability {
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/Compatability.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/Compatability.java
new file mode 100644
index 0000000000..a4304c28e6
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/Compatability.java
@@ -0,0 +1,21 @@
+package org.eclipse.swt.internal;
+
+public class Compatability {
+
+/**
+ * Answers the double conversion of the most negative (i.e.
+ * closest to negative infinity) integer value which is
+ * greater than the argument.
+ *
+ * @author OTI
+ * @version initial
+ *
+ * @param d the value to be converted
+ * @return the ceiling of the argument.
+ */
+public static double ceil (double d) {
+ return Math.ceil(d);
+}
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/EventObjectCompatability.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/EventObjectCompatability.java
new file mode 100644
index 0000000000..71ec4f8527
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/EventObjectCompatability.java
@@ -0,0 +1,5 @@
+package org.eclipse.swt.internal;
+
+public class EventObjectCompatability extends EventObject {
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SerializableCompatability.java b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SerializableCompatability.java
new file mode 100644
index 0000000000..ef873917b2
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common_j2se/org/eclipse/swt/internal/SerializableCompatability.java
@@ -0,0 +1,6 @@
+package org.eclipse.swt.internal;
+
+public interface SerializableCompatability {
+
+}
+
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 a57e1953da..c7623d6b6a 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
@@ -5,9 +5,11 @@ package org.eclipse.swt.widgets;
* All Rights Reserved
*/
+import java.util.Vector;
+import java.util.Enumeration;
+
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
-import java.util.*;
/**
* This class stores and manages child items of a tree item.
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Header.java b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Header.java
index 68e25b2b80..0c84cd18cf 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Header.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/emulated/treetable/org/eclipse/swt/widgets/Header.java
@@ -8,7 +8,6 @@ package org.eclipse.swt.widgets;
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
-import java.util.*;
/**
* A header draws one or more header items. Each item may have a text
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 74bbb36dee..d7d4e6776c 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
@@ -4,11 +4,14 @@ package org.eclipse.swt.widgets;
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved
*/
-
+
+import java.io.InputStream;
+import java.util.Vector;
+import java.util.Enumeration;
+
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
-import java.io.*;
-import java.util.*;
+import org.eclipse.swt.internal.Compatability;
/**
* This class is intended for widgets that display data of
@@ -947,7 +950,7 @@ int getItemCountTruncated(Rectangle rectangle) {
int startIndex;
startIndex = rectangle.y / itemHeight;
- itemCount = (int) Math.ceil(((float) rectangle.y + rectangle.height) / itemHeight)-startIndex;
+ itemCount = (int) Compatability.ceil(((float) rectangle.y + rectangle.height) / itemHeight)-startIndex;
return itemCount;
}
/**
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 86974f864d..ab24f66326 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
@@ -6,7 +6,9 @@ package org.eclipse.swt.widgets;
*/
import org.eclipse.swt.graphics.*;
-import java.util.*;
+import java.util.Vector;
+import java.util.Enumeration;
+// import java.util.*;
/**
* This class is used to store tree root items.
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/java/util/EventListener.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/java/util/EventListener.java
new file mode 100644
index 0000000000..8063143814
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/java/util/EventListener.java
@@ -0,0 +1,5 @@
+package java.util;
+public interface EventListener {
+
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/build.csh b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/build.csh
index 5a14d0d699..7485cf28c2 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/build.csh
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/build.csh
@@ -9,8 +9,8 @@
# getSharedLibraryMajorVersionNumber and getSharedLibraryMinorVersionNumber
# calls so java can query the swt shared library version number
-setenv MAJOR_VER 0
-setenv MINOR_VER 125
+setenv MAJOR_VER 2
+setenv MINOR_VER 006
setenv BUILD_NUM 0
# Some UNIX/Linux compilers don't like <CR>'s in files (DOS format).
@@ -29,24 +29,42 @@ endif
# Determine the operating system being built
set OS=`uname -s`
switch ($OS )
+ case AIX:
+ if ( "$1" == "clean" ) then
+ make -f make_aix.mak clean
+ else
+ echo "Building AIX version of SWT and CDE DLLs."
+ make -f make_aix.mak make_swt
+ make -f make_aix.mak make_cde
+ endif
+ breaksw
case Linux:
- if ( "$1" == "clean" ) then
- make -f make_linux.mak clean
- else
- echo "Building Linux version of SWT and GNOME DLLs."
- make -f make_linux.mak make_swt make_gnome
-
- set build_kde = `rpm -q kdebase | grep "not installed"`
- set build_kde = "not ported" # KDE porting not complete yet (KJC)
- if ( "$build_kde" == "" ) then
- echo "Building Linux version of KDE DLL."
- make -f make_linux.mak make_kde
- endif
- endif
- breaksw
+ if ( "$1" == "clean" ) then
+ make -f make_linux.mak clean
+ else
+ echo "Building Linux version of SWT and GNOME DLLs."
+ make -f make_linux.mak make_swt make_gnome
+
+ set build_kde = `rpm -q kdebase | grep "not installed"`
+ if ( "$build_kde" == "" ) then
+ echo "Building Linux version of KDE DLL."
+ make -f make_linux.mak make_kde
+ endif
+ endif
+ breaksw
+
+ case SunOS:
+ if ( "$1" == "clean" ) then
+ make -f make_solaris.mak clean
+ else
+ echo "Building Solaris version of SWT and CDE DLLs."
+ make -f make_solaris.mak make_swt
+ make -f make_solaris.mak make_cde
+ endif
+ breaksw
default:
- echo "Unknown"
+ echo "Unknown OS -- build aborted"
breaksw
endsw
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/kde.cc b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/kde.cc
index 79cb99f03c..6c7e251193 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/kde.cc
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/kde.cc
@@ -11,11 +11,13 @@
#define NDEBUG
#include <stdio.h>
+#include <signal.h>
#include "jni.h"
#include <kapp.h>
#include <kservice.h>
#include <kmimetype.h>
+#include <krun.h>
#include <kuserprofile.h>
#include <kurl.h>
#include <qstring.h>
@@ -30,13 +32,37 @@ extern "C" {
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KApplication_1new
(JNIEnv *env, jclass that, int appName)
{
- int myArgc = 0;
- char* myArgv[1];
+ int myArgc = 1;
+ char* myArgv[2] = { "SWT", 0 }; // KApplication requires a NULL terminated list
#ifdef DEBUG_CALL_PRINTS
fprintf(stderr, "KApplication_1new\n");
#endif
QCString qcString = *((QCString*) appName);
+
+ // NOTE: When a KDE application is initialized, it installs its own
+ // SIGSEGV signal handler so that it can pop up a dialogue box and
+ // display an error message should SIGSEGV occur. After the dialogue
+ // box is closed, it terminates the program. The Hursley Java VM (on Linux)
+ // happens to catch SIGSEGV signals so that it can throw a null pointer
+ // exception. Thus when KDE is initialized, the Java try ... catch
+ // mechanism for null pointers does not work. Eclipse code relies upon
+ // this try ... catch feature.
+ //
+ // The solution is to obtain the Java VM's signal handler before initializing
+ // KDE and to reinstall that handler after the initialization. The method
+ // sigaction() must be used instead of signal() because it returns more
+ // information on how to handle the signal.
+
+ // Obtain the current signal handling logic for SIGSEGV.
+ struct sigaction prev;
+ sigaction( SIGSEGV, NULL, &prev );
+
+ // Initialize KDE, which installs its own signal handler.
KApplication* app = new KApplication(myArgc, myArgv, qcString);
+
+ // Replace the Java VM signal handler.
+ sigaction( SIGSEGV, &prev, NULL );
+
return (jint) app;
}
@@ -60,12 +86,12 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KGlobal_1iconLoad
* Signature: (IIII)I
*/
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KIconLoader_1iconPath
- (JNIEnv *env, jclass that, jint receiver, jint iconQString, jint iconType, jint canReturnNull)
+ (JNIEnv *env, jclass that, jint kloader, jint iconQString, jint iconType, jint canReturnNull)
{
#ifdef DEBUG_CALL_PRINTS
fprintf(stderr, "KIconLoader_1iconPath\n");
#endif
- KIconLoader* loader = (KIconLoader*) receiver;
+ KIconLoader* loader = (KIconLoader*) kloader;
QString iconName = *((QString*) iconQString);
QString iconPath = loader->iconPath(iconName, iconType, canReturnNull);
if (iconPath == 0) return 0;
@@ -76,18 +102,18 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KIconLoader_1icon
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KMimeType_1findByURL
+ * Method: KMimeType_1mimeType
* Signature: (I)I
*/
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1findByURL
- (JNIEnv *env, jclass that, jint kurl)
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1mimeType
+ (JNIEnv *env, jclass that, jint mimeTypeName)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KMimeType_1findByURL\n");
+ fprintf(stderr, "KMimeType_1mimeType\n");
#endif
- KURL url = *((KURL*) kurl);
KSharedPtr<KMimeType>* mimeType = new KSharedPtr<KMimeType>();
- *mimeType = KMimeType::findByURL(url);
+ QString qMimeType = *((QString*) mimeTypeName);
+ *mimeType = KMimeType::mimeType( qMimeType );
return (jint) mimeType;
}
@@ -97,12 +123,12 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1findBy
* Signature: (III)I
*/
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1icon
- (JNIEnv *env, jclass that, jint receiver, jint unused1, jint unused2)
+ (JNIEnv *env, jclass that, jint mimeTypePtr, jint unused1, jint unused2)
{
#ifdef DEBUG_CALL_PRINTS
fprintf(stderr, "KMimeType_1icon\n");
#endif
- KSharedPtr<KMimeType> mimeType = *((KSharedPtr<KMimeType>*) receiver);
+ KSharedPtr<KMimeType> mimeType = *((KSharedPtr<KMimeType>*) mimeTypePtr);
QString* answer = new QString();
*answer = mimeType->icon((const QString&) NULL, 0);
return (jint) answer;
@@ -114,151 +140,279 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1icon
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1name
- (JNIEnv *env, jclass that, jint receiver)
+ (JNIEnv *env, jclass that, jint mimeTypePtr)
{
#ifdef DEBUG_CALL_PRINTS
fprintf(stderr, "KMimeType_1name\n");
#endif
- KSharedPtr<KMimeType> mimeType = *((KSharedPtr<KMimeType>*) receiver);
- QString* answer = new QString();
- *answer = mimeType->name();
- return (jint) answer;
+ KSharedPtr<KMimeType> mimeType = *((KSharedPtr<KMimeType>*) mimeTypePtr);
+ QString* name = new QString();
+ *name = mimeType->name();
+ return (jint) name;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KMimeType_1patterns
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1patterns
+ (JNIEnv *env, jclass that, jint mimeTypePtr)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KMimeType_1patterns\n");
+#endif
+ KSharedPtr<KMimeType> mimeType = *((KSharedPtr<KMimeType>*) mimeTypePtr);
+ QStringList* patternList = new QStringList();
+ *patternList = mimeType->patterns();
+ return (jint) patternList;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KMimeType_1offers
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1offers
+ (JNIEnv *env, jclass that, jint mimeTypeName)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KMimeType_1offers\n");
+#endif
+ QString qMimeType = *((QString*) mimeTypeName);
+ KService::List* serviceList = new KService::List();
+ *serviceList = KMimeType::offers( qMimeType );
+ return (jint) serviceList;
}
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KService_1allServices
+ * Method: KMimeType_1allMimeTypes
* Signature: ()I
*/
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1allServices
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeType_1allMimeTypes
(JNIEnv *env, jclass that)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KService_1allServices\n");
+ fprintf(stderr, "KMimeType_1allMimeTypes\n");
#endif
- KService::List* pointer = new KService::List();
- *pointer = KService::allServices();
- return (jint) pointer;
+ KMimeType::List* mimeTypeList = new KMimeType::List();
+ *mimeTypeList = KMimeType::allMimeTypes();
+ return (jint) mimeTypeList;
}
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KService_1exec
+ * Method: KMimeTypeList_1begin
* Signature: (I)I
*/
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1exec
- (JNIEnv *env, jclass that, jint receiver)
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeTypeList_1begin
+ (JNIEnv *env, jclass that, jint mimeTypeList)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KService_1exec\n");
+ fprintf(stderr, "KMimeTypeList_1begin\n");
#endif
- KSharedPtr<KService> service = *((KSharedPtr<KService>*) receiver);
- QString* answer = new QString();
- *answer = service->exec();
- return (jint) answer;
+ KMimeType::List *list= (KMimeType::List*) mimeTypeList;
+ QValueListIterator<KMimeType::Ptr>* iterator = new QValueListIterator<KMimeType::Ptr>();
+ *iterator = list->begin();
+ return (jint) iterator;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KMimeTypeList_1delete
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeTypeList_1delete
+ (JNIEnv *env, jclass that, jint mimeTypeList)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KMimeTypeList_1delete\n");
+#endif
+ delete (KMimeType::List*) mimeTypeList;
}
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KService_1icon
+ * Method: KMimeTypeList_1end
* Signature: (I)I
*/
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1icon
- (JNIEnv *env, jclass that, jint receiver)
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeTypeList_1end
+ (JNIEnv *env, jclass that, jint mimeTypeList)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KService_1icon\n");
+ fprintf(stderr, "KMimeTypeList_1end\n");
#endif
- KSharedPtr<KService> service = *((KSharedPtr<KService>*) receiver);
- QString* answer = new QString();
- *answer = service->icon();
- return (jint) answer;
+ KMimeType::List *list = (KMimeType::List*) mimeTypeList;
+ QValueListIterator<KMimeType::Ptr>* iterator = new QValueListIterator<KMimeType::Ptr>();
+ *iterator = list->end();
+ return (jint) iterator;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KMimeTypeListIterator_1delete
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeTypeListIterator_1delete
+ (JNIEnv *env, jclass that, jint iterator)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KMimeTypeListIterator_1delete\n");
+#endif
+ delete (QValueListIterator<KMimeType::Ptr>*) iterator;
}
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KService_1name
+ * Method: KMimeTypeListIterator_1dereference
* Signature: (I)I
*/
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1name
- (JNIEnv *env, jclass that, jint receiver)
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeTypeListIterator_1dereference
+ (JNIEnv *env, jclass that, jint iterator)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KService_1name\n");
+ fprintf(stderr, "KMimeTypeListIterator_1dereference\n");
#endif
- KSharedPtr<KService> service = *((KSharedPtr<KService>*) receiver);
- QString* answer = new QString();
- *answer = service->name();
- return (jint) answer;
+ KSharedPtr<KMimeType>* mimeType = new KSharedPtr<KMimeType>();
+ *mimeType = *(*((QValueListIterator<KMimeType::Ptr>*) iterator));
+ return (jint) mimeType;
}
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KService_1serviceByName
+ * Method: KMimeTypeListIterator_1equals
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeTypeListIterator_1equals
+ (JNIEnv *env, jclass that, jint iterator, jint iterator2)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "KMimeTypeListIterator_1equals\n");
+#endif
+ return *((QValueListIterator<KMimeType::Ptr>*) iterator) ==
+ *((QValueListIterator<KMimeType::Ptr>*) iterator2);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: KMimeTypeListIterator_1increment
* Signature: (I)I
*/
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1serviceByName
- (JNIEnv *env, jclass that, jint serviceName)
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KMimeTypeListIterator_1increment
+ (JNIEnv *env, jclass that, jint iterator)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KService_1serviceByName\n");
+ fprintf(stderr, "KMimeTypeListIterator_1increment\n");
#endif
- QString* name = (QString*) serviceName;
- KSharedPtr<KService> service = KService::serviceByName(*name);
- if (service == 0) return 0;
- KSharedPtr<KService>* pointer = new KSharedPtr<KService>();
- *pointer = service;
- return (jint) pointer;
+ ++(*((QValueListIterator<KMimeType::Ptr>*) iterator));
}
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KService_1type
+ * Method: QStringList_1begin
* Signature: (I)I
*/
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KService_1type
- (JNIEnv *env, jclass that, jint receiver)
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QStringList_1begin
+ (JNIEnv *env, jclass that, jint qstringList)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KService_1type\n");
+ fprintf(stderr, "QStringList_1begin\n");
#endif
- KSharedPtr<KService> service = *((KSharedPtr<KService>*) receiver);
- QString* answer = new QString();
- *answer = service->type();
- return (jint) answer;
+ QStringList *list= (QStringList*) qstringList;
+ QValueListIterator<QString>* iterator = new QValueListIterator<QString>();
+ *iterator = list->begin();
+ return (jint) iterator;
}
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KServiceTypeProfile_1preferredService
- * Signature: (II)I
+ * Method: QStringList_1delete
+ * Signature: (I)V
*/
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceTypeProfile_1preferredService
- (JNIEnv *env, jclass that, jint mimeTypeQString, jint needApp)
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_QStringList_1delete
+ (JNIEnv *env, jclass that, jint qstringList)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KServiceTypeProfile_1preferredService\n");
+ fprintf(stderr, "QStringList_1delete\n");
#endif
- QString mimeTypeName = *((QString*) mimeTypeQString);
- KSharedPtr<KService> service = KServiceTypeProfile::preferredService(mimeTypeName, needApp);
- if (service == 0) return 0;
- KSharedPtr<KService>* pointer = new KSharedPtr<KService>();
- *pointer = service;
- return (jint) pointer;
+ delete (QStringList*) qstringList;
}
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KURL_1delete
+ * Method: QStringList_1end
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QStringList_1end
+ (JNIEnv *env, jclass that, jint qstringList)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "QStringList_1end\n");
+#endif
+ QStringList *list = (QStringList*) qstringList;
+ QValueListIterator<QString>* iterator = new QValueListIterator<QString>();
+ *iterator = list->end();
+ return (jint) iterator;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: QStringListIterator_1delete
* Signature: (I)V
*/
-JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KURL_1delete
- (JNIEnv *env, jclass that, jint receiver)
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_QStringListIterator_1delete
+ (JNIEnv *env, jclass that, jint iterator)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KURL_1delete\n");
+ fprintf(stderr, "QStringListIterator_1delete\n");
+#endif
+ delete (QValueListIterator<QString>*) iterator;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: QStringListIterator_1dereference
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QStringListIterator_1dereference
+ (JNIEnv *env, jclass that, jint iterator)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "QStringListIterator_1dereference\n");
#endif
- delete (KURL*) receiver;
+ QString* qstring = new QString();
+ *qstring = *(*((QValueListIterator<QString>*) iterator));
+ return (jint) qstring;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: QStringListIterator_1equals
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QStringListIterator_1equals
+ (JNIEnv *env, jclass that, jint iterator, jint iterator2)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "QStringListIterator_1equals\n");
+#endif
+ return *((QValueListIterator<QString>*) iterator) ==
+ *((QValueListIterator<QString>*) iterator2);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_KDE
+ * Method: QStringListIterator_1increment
+ * Signature: (I)I
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_QStringListIterator_1increment
+ (JNIEnv *env, jclass that, jint iterator)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "QStringListIterator_1increment\n");
+#endif
+ ++(*((QValueListIterator<QString>*) iterator));
}
/*
@@ -267,61 +421,57 @@ JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KURL_1delete
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KURL_1new
- (JNIEnv *env, jclass that, jint qString)
+ (JNIEnv *env, jclass that, jint qURLString)
{
#ifdef DEBUG_CALL_PRINTS
fprintf(stderr, "KURL_1new\n");
#endif
- QString urlString = *((QString*) qString);
+ QString urlString = *((QString*) qURLString);
return (jint) new KURL(urlString);
}
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KServiceList_1begin
- * Signature: (I)I
+ * Method: KURL_1delete
+ * Signature: (I)V
*/
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceList_1begin
- (JNIEnv *env, jclass that, jint receiver)
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KURL_1delete
+ (JNIEnv *env, jclass that, jint url)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KServiceList_1begin\n");
+ fprintf(stderr, "KURL_1delete\n");
#endif
- KService::List *list= (KService::List*) receiver;
- QValueListConstIterator<KService::Ptr>* beginning = new QValueListConstIterator<KService::Ptr>();
- *beginning = list->begin();
- return (jint) beginning;
+ delete (KURL*) url;
}
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KServiceList_1delete
- * Signature: (I)V
+ * Method: KRun_1runURL
+ * Signature: (II)I
*/
-JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceList_1delete
- (JNIEnv *env, jclass that, jint receiver)
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KRun_1runURL
+ (JNIEnv *env, jclass that, jint kurl, jint mimeTypeName)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KServiceList_1delete\n");
+ fprintf(stderr, "KRun_1runURL\n");
#endif
- delete (KService::List*) receiver;
+ KURL url = *((KURL*) kurl);
+ QString qMimeType = *((QString*) mimeTypeName);
+ return (jint) KRun::runURL( url, qMimeType );
}
/*
* Class: org_eclipse_swt_internal_motif_KDE
- * Method: KServiceList_1end
- * Signature: (I)I
+ * Method: KServiceList_1delete
+ * Signature: (I)V
*/
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceList_1end
- (JNIEnv *env, jclass that, jint receiver)
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceList_1delete
+ (JNIEnv *env, jclass that, jint serviceList)
{
#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KServiceList_1end\n");
+ fprintf(stderr, "KServiceList_1delete\n");
#endif
- KService::List *list = (KService::List*) receiver;
- QValueListConstIterator<KService::Ptr>* end = new QValueListConstIterator<KService::Ptr>();
- *end = list->end();
- return (jint) end;
+ delete (KService::List*) serviceList;
}
/*
@@ -330,12 +480,12 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceList_1end
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QCString_1data
- (JNIEnv *env, jclass that, jint receiver)
+ (JNIEnv *env, jclass that, jint qcString)
{
#ifdef DEBUG_CALL_PRINTS
fprintf(stderr, "QCString_1data\n");
#endif
- return (jint) ((QCString*) receiver)->data();
+ return (jint) ((QCString*) qcString)->data();
}
/*
@@ -344,12 +494,12 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QCString_1data
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_QCString_1delete
- (JNIEnv *env, jclass that, jint receiver)
+ (JNIEnv *env, jclass that, jint qcString)
{
#ifdef DEBUG_CALL_PRINTS
fprintf(stderr, "QCString_1delete\n");
#endif
- delete (QCString*) receiver;
+ delete (QCString*) qcString;
}
/*
@@ -376,12 +526,12 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QCString_1new
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_QString_1delete
- (JNIEnv *env, jclass that, jint receiver)
+ (JNIEnv *env, jclass that, jint qString)
{
#ifdef DEBUG_CALL_PRINTS
fprintf(stderr, "QString_1delete\n");
#endif
- delete (QString*) receiver;
+ delete (QString*) qString;
}
/*
@@ -390,12 +540,12 @@ JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_QString_1delete
* Signature: (I[B)I
*/
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QString_1equals
- (JNIEnv *env, jclass that, jint receiver, jint object)
+ (JNIEnv *env, jclass that, jint qString, jint qString2)
{
#ifdef DEBUG_CALL_PRINTS
fprintf(stderr, "QString_1equals\n");
#endif
- return *((QString*) receiver) == *((QString*) object);
+ return *((QString*) qString) == *((QString*) qString2);
}
/*
@@ -422,93 +572,16 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QString_1new
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_QString_1utf8
- (JNIEnv *env, jclass that, jint receiver)
+ (JNIEnv *env, jclass that, jint qString)
{
#ifdef DEBUG_CALL_PRINTS
fprintf(stderr, "QString_1utf8\n");
#endif
- QString string = *((QString*) receiver);
+ QString string = *((QString*) qString);
QCString* qcString = new QCString();
*qcString = string.utf8();
return (jint) qcString;
}
-/*
- * Class: org_eclipse_swt_internal_motif_KDE
- * Method: KServiceListIterator_1delete
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceListIterator_1delete
- (JNIEnv *env, jclass that, jint receiver)
-{
-#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KServiceListIterator_1delete\n");
-#endif
- delete (QValueListIterator<KService::Ptr>*) receiver;
-}
-
-/*
- * Class: org_eclipse_swt_internal_motif_KDE
- * Method: KServiceListIterator_1dereference
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceListIterator_1dereference
- (JNIEnv *env, jclass that, jint receiver)
-{
-#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KServiceListIterator_1dereference\n");
-#endif
- KSharedPtr<KService>* service = new KSharedPtr<KService>();
- *service = *(*((QValueListIterator<KService::Ptr>*) receiver));
- return (jint) service;
-}
-
-/*
- * Class: org_eclipse_swt_internal_motif_KDE
- * Method: KServiceListIterator_1increment
- * Signature: (I)I
- */
-JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceListIterator_1increment
- (JNIEnv *env, jclass that, jint receiver)
-{
-#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KServiceListIterator_1increment\n");
-#endif
- ++(*((QValueListIterator<KService::Ptr>*) receiver));
-}
-
-/*
- * Class: org_eclipse_swt_internal_motif_KDE
- * Method: KServiceListIterator_1new
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceListIterator_1new
- (JNIEnv *env, jclass that, jint listBeginning)
-{
-#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KServiceListIterator_1new\n");
-#endif
- const QValueListIterator<KService::Ptr> *iterator =
- (const QValueListIterator<KService::Ptr> *) listBeginning;
-
- return (jint) new QValueListIterator<KService::Ptr>(*iterator);
-}
-
-/*
- * Class: org_eclipse_swt_internal_motif_KDE
- * Method: KServiceListIterator_1equals
- * Signature: (II)I
- */
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_KDE_KServiceListIterator_1equals
- (JNIEnv *env, jclass that, jint receiver, jint object)
-{
-#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "KServiceListIterator_1equals\n");
-#endif
- return *((QValueListIterator<KService::Ptr>*) receiver) ==
- *((QValueListIterator<KService::Ptr>*) object);
-}
-
-
} /* extern "C" */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/make_linux.mak b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/make_linux.mak
index def0e62635..f326f3ba33 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/make_linux.mak
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/make_linux.mak
@@ -18,28 +18,29 @@ DLL_VERSION=$(MAJOR_VER)$(MINOR_VER)
# QT_HOME - identifier namespace package (used by KDE)
IVE_HOME = /bluebird/teamswt/swt-builddir/ive/bin
MOTIF_HOME = /bluebird/teamswt/swt-builddir/motif21
-QT_HOME = /usr/lib/qt-2.2.0
+QT_HOME = /usr/lib/qt-2.2.4
# Define the various DLL (shared) libraries to be made.
SWT_PREFIX = swt
-SWT_DLL = lib$(SWT_PREFIX)$(DLL_VERSION).so
+OS_PREFIX = linux
+SWT_DLL = lib$(SWT_PREFIX)-$(OS_PREFIX)-$(DLL_VERSION).so
SWT_OBJ = callback.o globals.o library.o structs.o swt.o
SWT_LIB = -L$(MOTIF_HOME)/lib -lXm -L/usr/lib -L/usr/X11R6/lib \
- -x -shared -lX11 -lm -lXext -lXt -lXp -lXpm -ldl
+ -rpath . -x -shared -lX11 -lm -lXext -lXt -lXp -ldl
GNOME_PREFIX = swt-gnome
-GNOME_DLL = lib$(GNOME_PREFIX)$(DLL_VERSION).so
+GNOME_DLL = lib$(GNOME_PREFIX)-$(OS_PREFIX)-$(DLL_VERSION).so
GNOME_OBJ = gnome.o
GNOME_LIB = -x -shared \
- `gnome-config --libs gnome`
+ `gnome-config --libs gnome`
KDE_PREFIX = swt-kde
-KDE_DLL = lib$(KDE_PREFIX)$(DLL_VERSION).so
+KDE_DLL = lib$(KDE_PREFIX)-$(OS_PREFIX)-$(DLL_VERSION).so
KDE_OBJ = kde.o
KDE_LIB = -L/usr/lib -L$(QT_HOME)/lib \
- -shared -lksycoca -lkdecore -lq
+ -shared -lksycoca -lkdecore -lqt
#
# The following CFLAGS are for compiling both the SWT library and the GNOME
@@ -48,7 +49,7 @@ KDE_LIB = -L/usr/lib -L$(QT_HOME)/lib \
CFLAGS = -O -s \
-DSWT_LIBRARY_MAJOR_VERSION=$(MAJOR_VER) \
-DSWT_LIBRARY_MINOR_VERSION=$(MINOR_VER) \
- -DLINUX -DMOTIF -DGNOME -DXPM \
+ -DLINUX -DMOTIF -DGNOME \
-fpic \
-I./ \
-I$(IVE_HOME)/include \
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/swt.c b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/swt.c
index 99d97120cf..438b5fa5f9 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/library/swt.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/library/swt.c
@@ -15,6 +15,9 @@
#include <stdio.h>
#include <assert.h>
+#include <langinfo.h>
+#include <iconv.h>
+#include <stdlib.h>
JNIEXPORT int JNICALL Java_org_eclipse_swt_internal_motif_OS_getSharedLibraryMajorVersionNumber
(JNIEnv *env, jclass that)
@@ -1863,6 +1866,35 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XGrabPointer
/*
* Class: org_eclipse_swt_internal_motif_OS
+ * Method: XInternAtom
+ * Signature: (I[BZ)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XInternAtom
+ (JNIEnv *env, jclass that, jint display, jbyteArray name, jboolean ifExists)
+{
+ jbyte *name1 = NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XInternAtom\n");
+#endif
+ if (name)
+ name1 = (*env)->GetByteArrayElements(env, name, NULL);
+
+ rc = (jint) XInternAtom((Display *)display, (char *)name1, ifExists);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XInternAtom: call failed rc = %d\n", rc);
+#endif
+
+ if (name)
+ (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
* Method: XKeysymToString
* Signature: (I)I
*/
@@ -1911,6 +1943,35 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XListFonts
/*
* Class: org_eclipse_swt_internal_motif_OS
+ * Method: XListProperties
+ * Signature: (II[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XListProperties
+ (JNIEnv *env, jclass that, jint display, jint window, jintArray num_prop_return)
+{
+ jint *num_prop_return1=NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XListProperties\n");
+#endif
+ if (num_prop_return)
+ num_prop_return1 = (*env)->GetIntArrayElements(env, num_prop_return, NULL);
+
+ rc = (jint) XListProperties((Display *)display, (Window)window, (int *)num_prop_return1);
+
+#ifdef PRINT_FAILED_RCODES
+ if (rc == 0)
+ fprintf(stderr, "XListProperties: call failed rc = %d\n", rc);
+#endif
+
+ if (num_prop_return)
+ (*env)->ReleaseIntArrayElements(env, num_prop_return, num_prop_return1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
* Method: XLookupString
* Signature: (Lorg/eclipse/swt/internal/motif/XKeyEvent;[BI[I[I)I
*/
@@ -1939,7 +2000,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XLookupString
if (status)
status1 = (*env)->GetIntArrayElements(env, status, NULL);
rc = (jint) XLookupString((XKeyEvent *)lpxEvent, (char *)string1, size, (KeySym *)keysym1, (XComposeStatus *)status1);
-
+
#ifdef PRINT_FAILED_RCODES
if (rc < 0)
fprintf(stderr, "XLookupString: call failed rc = %d\n", rc);
@@ -4062,6 +4123,27 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmGetFocusWidget
/*
* Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmGetPixmap
+ * Signature: (I[BII)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmGetPixmap
+ (JNIEnv *env, jclass that, jint screen, jbyteArray name, jint fgPixel, jint bgPixel)
+{
+ jbyte* name1 = NULL;
+ jint pixmap;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmGetPixmap\n");
+#endif
+
+ if (name) name1 = (*env)->GetByteArrayElements(env, name, NULL);
+ pixmap = (jint) XmGetPixmap((Screen*)screen, (char*)name1, (Pixel)fgPixel, (Pixel)bgPixel);
+ if (name) (*env)->ReleaseByteArrayElements(env, name, name1, 0);
+ return pixmap;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
* Method: XmGetXmDisplay
* Signature: (I)I
*/
@@ -5236,8 +5318,9 @@ JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmWidgetGetDis
* Method: XmbLookupString
* Signature: (ILorg/eclipse/swt/internal/motif/XInputEvent;[BI[I[I)I
*/
+/*
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmbLookupString
- (JNIEnv *env, jclass that, jint widget, jobject event, jbyteArray string, jint size, jintArray keysym, jintArray status)
+ (JNIEnv *env, jclass that, jint ic, jobject event, jbyteArray string, jint size, jintArray keysym, jintArray status)
{
DECL_GLOB(pGlob)
XEvent xEvent, *lpxEvent=NULL;
@@ -5260,11 +5343,11 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmbLookupString
if (status)
status1 = (*env)->GetIntArrayElements(env, status, NULL);
- rc = (jint)XmImMbLookupString((Widget)widget, (XKeyPressedEvent *)lpxEvent, (char *)string1, size, (KeySym *)keysym1, (int *)status1);
+ rc = (jint)XmbLookupString((XIC)ic, (XKeyPressedEvent *)lpxEvent, (char *)string1, size, (KeySym *)keysym1, (int *)status1);
#ifdef PRINT_FAILED_RCODES
if (rc == 0)
- fprintf(stderr, "XmImMbLookupString: call failed rc = %d\n", rc);
+ fprintf(stderr, "XmbLookupString: call failed rc = %d\n", rc);
#endif
if (event) {
@@ -5278,6 +5361,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmbLookupString
(*env)->ReleaseIntArrayElements(env, status, status1, 0);
return rc;
}
+*/
/*
* Class: org_eclipse_swt_internal_motif_OS
@@ -6514,43 +6598,6 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmClipboardEndRetr
/*
* Class: org_eclipse_swt_internal_motif_OS
- * Method: XpmReadFileToPixmap
- * Signature: (II[B[I[II)I
- */
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XpmReadFileToPixmap
- (JNIEnv *env, jclass that, jint display, jint drawable, jbyteArray fileName, jintArray pixmap_return, jintArray shapemask_return, jint attributes)
-{
-#ifdef XPM
- jint rc;
- jbyte *fileName1 = NULL;
- jint *pixmap_return1 = NULL;
- jint *shapemask_return1 = NULL;
-#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "XpmReadFileToPixmap\n");
-#endif
- if (fileName) fileName1 = (*env)->GetByteArrayElements(env, fileName, NULL);
- if (pixmap_return) pixmap_return1 = (*env)->GetIntArrayElements(env, pixmap_return, NULL);
- if (shapemask_return) shapemask_return1 = (*env)->GetIntArrayElements(env, shapemask_return, NULL);
-
- rc = (jint) XpmReadFileToPixmap((Display *)display,
- drawable,
- fileName1,
- (Pixmap*) pixmap_return1,
- (Pixmap*) shapemask_return1,
- attributes);
-
- if (fileName) (*env)->ReleaseByteArrayElements(env, fileName, fileName1, 0);
- if (pixmap_return) (*env)->ReleaseIntArrayElements(env, pixmap_return, pixmap_return1, 0);
- if (shapemask_return) (*env)->ReleaseIntArrayElements(env, shapemask_return, shapemask_return1, 0);
- return rc;
-#endif
-#ifndef XPM
- return -1;
-#endif
-}
-
-/*
- * Class: org_eclipse_swt_internal_motif_OS
* Method: XmCreateDrawnButton
* Signature: (I[B[II)I
*/
@@ -6988,7 +7035,7 @@ JNIEXPORT int JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTabListInsertTabs
* Method: XmDestroyPixmap
* Signature: (II)Z
*/
-/* JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmDestroyPixmap
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_motif_OS_XmDestroyPixmap
(JNIEnv *env, jclass that, jint screen, jint pixmap)
{
#ifdef DEBUG_CALL_PRINTS
@@ -6996,14 +7043,13 @@ JNIEXPORT int JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTabListInsertTabs
#endif
return (jboolean) XmDestroyPixmap((Screen *)screen, pixmap);
}
-*/
/*
* Class: org_eclipse_swt_internal_motif_OS
* Method: XmGetPixmapByDepth
* Signature: (I[BIII)I
*/
-/* JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmGetPixmapByDepth
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmGetPixmapByDepth
(JNIEnv *env, jclass that, jint screen, jbyteArray image_name, jint foreground, jint background, jint depth)
{
jbyte *image_name1=NULL;
@@ -7026,7 +7072,7 @@ JNIEXPORT int JNICALL Java_org_eclipse_swt_internal_motif_OS_XmTabListInsertTabs
(*env)->ReleaseByteArrayElements(env, image_name, image_name1, 0);
return rc;
}
-*/
+
/*
* Class: org_eclipse_swt_internal_motif_OS
@@ -7595,6 +7641,8 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetIOErrorHandler
* ======== Start printing functions ========
*/
+#ifndef NO_XPRINTING_EXTENSIONS
+
/*
* Class: org_eclipse_swt_internal_motif_OS
* Method: XpCreateContext
@@ -7861,6 +7909,35 @@ JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XpCancelJob
/*
* Class: org_eclipse_swt_internal_motif_OS
+ * Method: XpQueryVersion
+ * Signature: (I[S[S)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XpQueryVersion
+ (JNIEnv *env, jclass that, jint display, jshortArray major_version, jshortArray minor_version)
+{
+ jshort *major_version1=NULL, *minor_version1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XpQueryVersion\n");
+#endif
+
+ if (major_version)
+ major_version1 = (*env)->GetShortArrayElements(env, major_version, NULL);
+ if (minor_version)
+ minor_version1 = (*env)->GetShortArrayElements(env, minor_version, NULL);
+ rc = (jint) XpQueryVersion((Display *)display, (short *)major_version1, (short *)minor_version1);
+ if (major_version)
+ (*env)->ReleaseShortArrayElements(env, major_version, major_version1, 0);
+ if (minor_version)
+ (*env)->ReleaseShortArrayElements(env, minor_version, minor_version1, 0);
+
+ return rc;
+}
+
+#endif /* ! NO_XPRINTING_EXTENSIONS */
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
* Method: XDefaultGCOfScreen
* Signature: (I)I
*/
@@ -7946,33 +8023,6 @@ JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XDestroyWindow
}
/*
- * Class: org_eclipse_swt_internal_motif_OS
- * Method: XpQueryVersion
- * Signature: (I[S[S)I
- */
-JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XpQueryVersion
- (JNIEnv *env, jclass that, jint display, jshortArray major_version, jshortArray minor_version)
-{
- jshort *major_version1=NULL, *minor_version1=NULL;
- jint rc;
-#ifdef DEBUG_CALL_PRINTS
- fprintf(stderr, "XpQueryVersion\n");
-#endif
-
- if (major_version)
- major_version1 = (*env)->GetShortArrayElements(env, major_version, NULL);
- if (minor_version)
- minor_version1 = (*env)->GetShortArrayElements(env, minor_version, NULL);
- rc = (jint) XpQueryVersion((Display *)display, (short *)major_version1, (short *)minor_version1);
- if (major_version)
- (*env)->ReleaseShortArrayElements(env, major_version, major_version1, 0);
- if (minor_version)
- (*env)->ReleaseShortArrayElements(env, minor_version, minor_version1, 0);
-
- return rc;
-}
-
-/*
* ======== End printing functions ========
*/
@@ -8015,7 +8065,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_read
if (buf)
buf1 = (*env)->GetByteArrayElements(env, buf, NULL);
- rc = (jint) read(filedes, (char *)buf, nbyte);
+ rc = (jint) read(filedes, (char *)buf1, nbyte);
if (buf)
(*env)->ReleaseByteArrayElements(env, buf, buf1, 0);
@@ -8038,7 +8088,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_write
if (buf)
buf1 = (*env)->GetByteArrayElements(env, buf, NULL);
- rc = (jint) write(filedes, (char *)buf, nbyte);
+ rc = (jint) write(filedes, (char *)buf1, nbyte);
if (buf)
(*env)->ReleaseByteArrayElements(env, buf, buf1, 0);
@@ -8089,3 +8139,484 @@ JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XtRemoveInput
XtRemoveInput((XtInputId)id);
}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmImGetXIC
+ * Signature: (II[II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmImGetXIC
+ (JNIEnv *env, jclass that, jint widget, jint input_policy, jintArray args, jint num_args)
+{
+ jint *args1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmImGetXIC\n");
+#endif
+ if (args)
+ args1 = (*env)->GetIntArrayElements(env, args, NULL);
+ rc = (jint) XmImGetXIC((Widget)widget, (XmInputPolicy)input_policy, (ArgList)args1, num_args);
+ if (args)
+ (*env)->ReleaseIntArrayElements(env, args, args1, 0);
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmImGetXIM
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XmImGetXIM
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmImGetXIM\n");
+#endif
+
+ return (jint) XmImGetXIM((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmImRegister
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmImRegister
+ (JNIEnv *env, jclass that, jint widget, jint reserved)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmImRegister\n");
+#endif
+
+ XmImRegister((Widget)widget, reserved);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmImSetFocusValues
+ * Signature: (I[II)V
+ */
+/*
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmImSetFocusValues
+ (JNIEnv *env, jclass that, jint widget, jintArray args, jint num_args)
+{
+ jint *args1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmImSetFocusValues\n");
+#endif
+ if (args)
+ args1 = (*env)->GetIntArrayElements(env, args, NULL);
+ XmImSetFocusValues((Widget)widget, (ArgList)args1, num_args);
+ if (args)
+ (*env)->ReleaseIntArrayElements(env, args, args1, 0);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmImVaSetFocusValues
+ * Signature: (IIIIIIIIII)I
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmImVaSetFocusValues
+ (JNIEnv *env, jclass that, jint widget, jint arg1, jint arg2, jint arg3, jint arg4, jint arg5, jint arg6, jint arg7, jint arg8, jint arg9)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmImVaSetFocusValues\n");
+#endif
+ XmImVaSetFocusValues((Widget)widget, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmImSetValues
+ * Signature: (I[II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmImSetValues
+ (JNIEnv *env, jclass that, jint widget, jintArray args, jint num_args)
+{
+ jint *args1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmImSetValues\n");
+#endif
+ if (args)
+ args1 = (*env)->GetIntArrayElements(env, args, NULL);
+ XmImSetValues((Widget)widget, (ArgList)args1, num_args);
+ if (args)
+ (*env)->ReleaseIntArrayElements(env, args, args1, 0);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmImUnregister
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmImUnregister
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmImUnregister\n");
+#endif
+
+ XmImUnregister((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XmImUnsetFocus
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XmImUnsetFocus
+ (JNIEnv *env, jclass that, jint widget)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XmImUnsetFocus\n");
+#endif
+
+ XmImUnsetFocus((Widget)widget);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCreateIC
+ * Signature: (IIIIIIII)I
+ */
+/*
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XCreateIC
+ (JNIEnv *env, jclass that, jint im, jint arg1, jint arg2, jint arg3, jint arg4, jint arg5, jint arg6, jint arg7)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCreateIC\n");
+#endif
+
+ return (jint)XCreateIC((XIM)im, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetICValues
+ * Signature: (IIII)I
+ */
+/*
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetICValues
+ (JNIEnv *env, jclass that, jint ic, jint arg1, jint arg2, jint arg3)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetICValues\n");
+#endif
+
+ return (jint)XSetICValues((XIC)ic, arg1, arg2, arg3);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XGetICValues
+ * Signature: (IIII)I
+ */
+/*
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XGetICValues
+ (JNIEnv *env, jclass that, jint ic, jint arg1, jint arg2, jint arg3)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XGetICValues\n");
+#endif
+
+ return (jint)XGetICValues((XIC)ic, arg1, arg2, arg3);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XSetICFocus
+ * Signature: (I)V
+ */
+/*
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XSetICFocus
+ (JNIEnv *env, jclass that, jint ic)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XSetICFocus\n");
+#endif
+
+ XSetICFocus((XIC)ic);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XUnsetICFocus
+ * Signature: (I)V
+ */
+/*
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_XUnsetICFocus
+ (JNIEnv *env, jclass that, jint ic)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XUnsetICFocus\n");
+#endif
+
+ XUnsetICFocus((XIC)ic);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XGetIMValues
+ * Signature: (IIII)I
+ */
+/*
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XGetIMValues
+ (JNIEnv *env, jclass that, jint im, jint arg1, jint arg2, jint arg3)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XGetIMValues\n");
+#endif
+
+ return (jint)XGetIMValues((XIM)im, arg1, arg2, arg3);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (I[SI)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__I_3SI
+ (JNIEnv *env, jclass that, jint dest, jshortArray src, jint count)
+{
+ jshort *src1;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__I_3SI\n");
+#endif
+
+ /* don't do anything if src pointer is NULL */
+ if (src) {
+ src1 = (*env)->GetShortArrayElements(env, src, NULL);
+ memmove((void *)dest, (void *)src1, count);
+ (*env)->ReleaseShortArrayElements(env, src, src1, 0);
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: nl_langinfo
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_nl_1langinfo
+ (JNIEnv *env, jclass that, jint item)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "nl_langinfo\n");
+#endif
+
+ return (jint)nl_langinfo(item);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: iconv_open
+ * Signature: ([B[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_iconv_1open
+ (JNIEnv *env, jclass that, jbyteArray tocode, jbyteArray fromcode)
+{
+ jbyte *tocode1=NULL, *fromcode1=NULL;
+ jint result;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "iconv_open\n");
+#endif
+ if (tocode)
+ tocode1 = (*env)->GetByteArrayElements(env, tocode, NULL);
+ if (fromcode)
+ fromcode1 = (*env)->GetByteArrayElements(env, fromcode, NULL);
+ result = (jint)iconv_open(tocode1, fromcode1);
+ if (tocode)
+ (*env)->ReleaseByteArrayElements(env, tocode, tocode1, 0);
+ if (fromcode)
+ (*env)->ReleaseByteArrayElements(env, fromcode, fromcode1, 0);
+
+ return result;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: iconv_close
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_iconv_1close
+ (JNIEnv *env, jclass that, jint cd)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "iconv_close\n");
+#endif
+
+ return (jint)iconv_close((iconv_t)cd);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: iconv
+ * Signature: (I[BI[BI)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_iconv
+ (JNIEnv *env, jclass that, jint cd, jintArray inBuf, jintArray inBytesLeft, jintArray outBuf, jintArray outBytesLeft)
+{
+ jint *inBuf1=NULL, *outBuf1=NULL, *inBytesLeft1=NULL, *outBytesLeft1=NULL;
+ jint result;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "iconv\n");
+#endif
+ if (inBuf)
+ inBuf1 = (*env)->GetIntArrayElements(env, inBuf, NULL);
+ if (outBuf)
+ outBuf1 = (*env)->GetIntArrayElements(env, outBuf, NULL);
+ if (inBytesLeft)
+ inBytesLeft1 = (*env)->GetIntArrayElements(env, inBytesLeft, NULL);
+ if (outBytesLeft)
+ outBytesLeft1 = (*env)->GetIntArrayElements(env, outBytesLeft, NULL);
+ result = (jint)iconv((iconv_t)cd, (void *)inBuf1, (size_t *)inBytesLeft1, (char **)outBuf1, (size_t *)outBytesLeft1);
+ if (inBuf)
+ (*env)->ReleaseIntArrayElements(env, inBuf, inBuf1, 0);
+ if (outBuf)
+ (*env)->ReleaseIntArrayElements(env, outBuf, outBuf1, 0);
+ if (inBytesLeft)
+ (*env)->ReleaseIntArrayElements(env, inBytesLeft, inBytesLeft1, 0);
+ if (outBytesLeft)
+ (*env)->ReleaseIntArrayElements(env, outBytesLeft, outBytesLeft1, 0);
+ return result;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: MB_1CUR_1MAX
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_MB_1CUR_1MAX
+ (JNIEnv *env, jclass that)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "MB_1CUR_1MAX\n");
+#endif
+
+ return (jint)MB_CUR_MAX;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: ([CII)V
+ */
+/*
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove___3CII
+ (JNIEnv *env, jclass that, jcharArray dest, jint src, jint count)
+{
+ jchar *dest1;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove___3CII\n");
+#endif
+
+ if (dest) {
+ dest1 = (*env)->GetCharArrayElements(env, dest, NULL);
+ memmove((void *)dest1, (void *)src, count);
+ (*env)->ReleaseCharArrayElements(env, dest, dest1, 0);
+ }
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: memmove
+ * Signature: (I[CI)V
+ */
+/*
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_motif_OS_memmove__I_3CI
+ (JNIEnv *env, jclass that, jint dest, jcharArray src, jint count)
+{
+ jchar *src1;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__I_3CI\n");
+#endif
+
+ if (src) {
+ int i;
+ unsigned char *dest1 = (unsigned char *)dest;
+ src1 = (*env)->GetCharArrayElements(env, src, NULL);
+ memmove((void *)dest, (void *)src1, count);
+ (*env)->ReleaseCharArrayElements(env, src, src1, 0);
+ }
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XCreateFontSet
+ * Signature: (I[B[I[I[I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XCreateFontSet
+ (JNIEnv *env, jclass that, jint display, jbyteArray base_font_name_list, jintArray missing_charset_list_return, jintArray missing_charset_count_return, jintArray def_string_return)
+{
+ jbyte *base_font_name_list1=NULL;
+ jint *missing_charset_list_return1=NULL, *missing_charset_count_return1=NULL, *def_string_return1=NULL;
+ jint result;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XCreateFontSet\n");
+#endif
+ if (base_font_name_list)
+ base_font_name_list1 = (*env)->GetByteArrayElements(env, base_font_name_list, NULL);
+ if (missing_charset_list_return)
+ missing_charset_list_return1 = (*env)->GetIntArrayElements(env, missing_charset_list_return, NULL);
+ if (missing_charset_count_return)
+ missing_charset_count_return1 = (*env)->GetIntArrayElements(env, missing_charset_count_return, NULL);
+ if (def_string_return)
+ def_string_return1 = (*env)->GetIntArrayElements(env, def_string_return, NULL);
+ result = (jint)XCreateFontSet((Display *)display, (char *)base_font_name_list1, (char ***)missing_charset_list_return1, (int *)missing_charset_count_return1, (char **)def_string_return1);
+ if (base_font_name_list)
+ (*env)->ReleaseByteArrayElements(env, base_font_name_list, base_font_name_list1, 0);
+ if (missing_charset_list_return)
+ (*env)->ReleaseIntArrayElements(env, missing_charset_list_return, missing_charset_list_return1, 0);
+ if (missing_charset_count_return)
+ (*env)->ReleaseIntArrayElements(env, missing_charset_count_return, missing_charset_count_return1, 0);
+ if (def_string_return)
+ (*env)->ReleaseIntArrayElements(env, def_string_return, def_string_return1, 0);
+ return result;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: XLocaleOfFontSet
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_XLocaleOfFontSet
+ (JNIEnv *env, jclass that, jint fontSet)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "XLocaleOfFontSet\n");
+#endif
+
+ return (jint)XLocaleOfFontSet((XFontSet)fontSet);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_motif_OS
+ * Method: setlocale
+ * Signature: (I[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_motif_OS_setlocale
+ (JNIEnv *env, jclass that, int category, jbyteArray locale)
+{
+ jbyte *locale1=NULL;
+ jint rc;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "setlocale\n");
+#endif
+
+ if (locale)
+ locale1 = (*env)->GetByteArrayElements(env, locale, NULL);
+ rc = (jint) setlocale(category, (char *)locale1);
+ if (locale)
+ (*env)->ReleaseByteArrayElements(env, locale, locale1, 0);
+
+ return rc;
+}
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 07ff9ce115..5dc1701dfb 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
@@ -306,6 +306,7 @@ public FontData [] getFontList (String faceName, boolean scalable) {
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);
@@ -319,6 +320,7 @@ public FontData [] getFontList (String faceName, boolean scalable) {
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;
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 3345d70dde..838b61bfe4 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
@@ -8,6 +8,7 @@ package org.eclipse.swt.graphics;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.motif.*;
import org.eclipse.swt.*;
+import java.util.Locale;
/**
* Instances of this class manage operating system resources that
@@ -174,6 +175,7 @@ public FontData[] getFontData() {
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];
@@ -251,26 +253,35 @@ public int hashCode () {
return handle;
}
int loadFont(int xDisplay, FontData fd) {
+ /* Use the character encoding for the default locale */
byte[] buffer = Converter.wcsToMbcs(null, fd.getXlfd(), true);
return OS.XLoadQueryFont(xDisplay, buffer);
}
-int matchFont(int xDisplay, FontData fd) {
- int fontStruct = loadFont(xDisplay, fd);
- if (fontStruct != 0) return fontStruct;
+int loadFontSet(int xDisplay, FontData fd) {
+ /* Use the character encoding for the default locale */
+ byte[] buffer = Converter.wcsToMbcs(null, fd.getXlfd(), true);
+ int [] missing_charset = new int [1];
+ int [] missing_charset_count = new int [1];
+ int [] def_string = new int [1];
+ return OS.XCreateFontSet(xDisplay, buffer, missing_charset, missing_charset_count, def_string);
+}
+int matchFont(int xDisplay, FontData fd, boolean fontSet) {
+ int font = fontSet ? loadFontSet(xDisplay, fd) : loadFont(xDisplay, fd);
+ if (font != 0) return font;
if (fd.slant != null) {
fd.slant = null;
- fontStruct = loadFont(xDisplay, fd);
- if (fontStruct != 0) return fontStruct;
+ font = fontSet ? loadFontSet(xDisplay, fd) : loadFont(xDisplay, fd);
+ if (font != 0) return font;
}
if (fd.weight != null) {
fd.weight = null;
- fontStruct = loadFont(xDisplay, fd);
- if (fontStruct != 0) return fontStruct;
+ font = fontSet ? loadFontSet(xDisplay, fd) : loadFont(xDisplay, fd);
+ if (font != 0) return font;
}
if (fd.points != 0) {
fd.points = 0;
- fontStruct = loadFont(xDisplay, fd);
- if (fontStruct != 0) return fontStruct;
+ font = fontSet ? loadFontSet(xDisplay, fd) : loadFont(xDisplay, fd);
+ if (font != 0) return font;
}
return 0;
}
@@ -279,8 +290,53 @@ void init (Device device, FontData fd) {
if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
this.device = device;
int xDisplay = device.xDisplay;
- int fontStruct = loadFont(xDisplay, fd);
- if (fontStruct == 0) {
+ int fontListEntry;
+// int fontStruct = loadFont(xDisplay, fd);
+// if (fontStruct == 0) {
+// /*
+// * If the desired font can not be loaded, the XLFD fields are wildcard
+// * in order to preserve the font style and height. If there is no
+// * font with the desired style and height, the slant, weight and points
+// * are wildcard in that order, until a font can be loaded.
+// */
+// FontData newFD = new FontData();
+// newFD.slant = fd.slant;
+// newFD.weight = fd.weight;
+// newFD.points = fd.points;
+// newFD.characterSetName = fd.characterSetName;
+// if (newFD.characterSetName == null) {
+// newFD.characterSetName = device.characterSetName;
+// }
+// newFD.characterSetRegistry = fd.characterSetRegistry;
+// if (newFD.characterSetRegistry == null) {
+// newFD.characterSetRegistry = device.characterSetRegistry;
+// }
+// fontStruct = matchFont(xDisplay, newFD, false);
+//
+// /* Failed to load any font. Use the system font. */
+// if (fontStruct == 0) {
+// handle = device.systemFont;
+// if (handle != 0) return;
+// }
+// }
+// fontListEntry = OS.XmFontListEntryCreate(OS.XmFONTLIST_DEFAULT_TAG, OS.XmFONT_IS_FONT, fontStruct);
+ Locale locale = fd.locale;
+ if (locale != null) {
+ String lang = locale.getLanguage();
+ String country = locale.getCountry();
+ String variant = locale.getVariant();
+ String osLocale = lang;
+ if (country != null && country.length() > 0) osLocale += "_" + country;
+ if (variant != null && variant.length() > 0) osLocale += "." + variant;
+ int length = osLocale.length();
+ byte [] buffer = new byte[length + 1];
+ for (int i=0; i<length; i++) {
+ buffer[i] = (byte)osLocale.charAt(i);
+ }
+ OS.setlocale (OS.LC_CTYPE, buffer);
+ }
+ int fontSet = loadFontSet(xDisplay, fd);
+ if (fontSet == 0) {
/*
* If the desired font can not be loaded, the XLFD fields are wildcard
* in order to preserve the font style and height. If there is no
@@ -299,16 +355,16 @@ void init (Device device, FontData fd) {
if (newFD.characterSetRegistry == null) {
newFD.characterSetRegistry = device.characterSetRegistry;
}
- fontStruct = matchFont(xDisplay, newFD);
-
- /* Failed to load any font. Use the system font. */
- if (fontStruct == 0) {
- handle = device.systemFont;
- if (handle != 0) return;
- }
+ fontSet = matchFont(xDisplay, newFD, true);
+ }
+ if (locale != null) OS.setlocale (OS.LC_CTYPE, new byte [0]);
+
+ /* Failed to load any font. Use the system font. */
+ if (fontSet == 0) {
+ handle = device.systemFont;
+ if (handle != 0) return;
}
- if (fontStruct == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int fontListEntry = OS.XmFontListEntryCreate(OS.XmFONTLIST_DEFAULT_TAG, OS.XmFONT_IS_FONT, fontStruct);
+ fontListEntry = OS.XmFontListEntryCreate(OS.XmFONTLIST_DEFAULT_TAG, OS.XmFONT_IS_FONTSET, fontSet);
if (fontListEntry == 0) SWT.error(SWT.ERROR_NO_HANDLES);
handle = OS.XmFontListAppendEntry(0, fontListEntry);
OS.XmFontListEntryFree(new int[]{fontListEntry});
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 ac4958afe4..8e2707767f 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
@@ -6,6 +6,7 @@ package org.eclipse.swt.graphics;
*/
import org.eclipse.swt.*;
+import java.util.Locale;
/**
* Instances of this class describe operating system fonts.
@@ -103,6 +104,12 @@ public final class FontData {
* Warning: This field is platform dependent.
*/
public String characterSetName;
+
+ /**
+ * The locale of the font
+ * (Warning: This field is platform dependent)
+ */
+ Locale locale;
/**
* Constructs a new un-initialized font data.
*/
@@ -381,6 +388,25 @@ public void setName(String name) {
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 Locale of the <code>FontData</code>
+ */
+public void setLocale(Locale locale) {
+ this.locale = locale;
+}
/**
* Sets the style of the receiver to the argument which must
* be a bitwise OR of one or more of the <code>SWT</code>
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 36f1186e8a..a6af8a5afb 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
@@ -413,12 +413,14 @@ void drawImageAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHei
blues[i] = (byte)((color.blue >> 8) & 0xFF);
}
ImageData.blit(ImageData.BLIT_ALPHA,
- srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, srcOrder, 0, 0, srcWidth, srcHeight, reds, greens, blues, srcImage.alpha, srcImage.alphaData, imgWidth,
+ srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, srcOrder, 0, 0, srcWidth, srcHeight, reds, greens, blues,
+ srcImage.alpha, srcImage.alphaData, imgWidth,
destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, reds, greens, blues,
false, false);
} else {
ImageData.blit(ImageData.BLIT_ALPHA,
- srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, srcOrder, 0, 0, srcWidth, srcHeight, xDestImage.red_mask, xDestImage.green_mask, xDestImage.blue_mask, srcImage.alpha, srcImage.alphaData, imgWidth,
+ srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, srcOrder, 0, 0, srcWidth, srcHeight, xDestImage.red_mask, xDestImage.green_mask, xDestImage.blue_mask,
+ srcImage.alpha, srcImage.alphaData, imgWidth,
destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, xDestImage.red_mask, xDestImage.green_mask, xDestImage.blue_mask,
false, false);
}
@@ -516,7 +518,11 @@ static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth
int bplX = ((destWidth + 7) / 8 + 3) & 0xFFFC;
int bufSize = bplX * destHeight;
byte[] buf = new byte[bufSize];
- ImageData.stretch1(srcData, xSrcImage.bytes_per_line, bitOrder, 0, 0, srcWidth, srcHeight, buf, bplX, bitOrder, 0, 0, destWidth, destHeight, flipX, flipY);
+ ImageData.blit(ImageData.BLIT_SRC,
+ srcData, 1, xSrcImage.bytes_per_line, bitOrder, 0, 0, srcWidth, srcHeight, null, null, null,
+ ImageData.ALPHA_OPAQUE, null, 0,
+ buf, 1, bplX, bitOrder, 0, 0, destWidth, destHeight, null, null, null,
+ flipX, flipY);
int bufPtr = OS.XtMalloc(bufSize);
OS.memmove(bufPtr, buf, bufSize);
xImagePtr = OS.XCreateImage(display, visual, 1, OS.XYBitmap, 0, bufPtr, destWidth, destHeight, 32, bplX);
@@ -534,7 +540,11 @@ static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth
int bplX = (destWidth + 3) & 0xFFFC;
int bufSize = bplX * destHeight;
byte[] buf = new byte[bufSize];
- ImageData.stretch4(srcData, xSrcImage.bytes_per_line, 0, 0, srcWidth, srcHeight, buf, bplX, 0, 0, destWidth, destHeight, null, flipX, flipY);
+ ImageData.blit(ImageData.BLIT_SRC,
+ srcData, 4, xSrcImage.bytes_per_line, ImageData.MSB_FIRST, 0, 0, srcWidth, srcHeight, null, null, null,
+ ImageData.ALPHA_OPAQUE, null, 0,
+ buf, 4, bplX, ImageData.MSB_FIRST, 0, 0, destWidth, destHeight, null, null, null,
+ flipX, flipY);
int bufPtr = OS.XtMalloc(bufSize);
OS.memmove(bufPtr, buf, bufSize);
xImagePtr = OS.XCreateImage(display, visual, 4, OS.ZPixmap, 0, bufPtr, destWidth, destHeight, 32, bplX);
@@ -544,7 +554,11 @@ static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth
int bplX = (destWidth + 3) & 0xFFFC;
int bufSize = bplX * destHeight;
byte[] buf = new byte[bufSize];
- ImageData.stretch8(srcData, xSrcImage.bytes_per_line, 0, 0, srcWidth, srcHeight, buf, bplX, 0, 0, destWidth, destHeight, null, flipX, flipY);
+ ImageData.blit(ImageData.BLIT_SRC,
+ srcData, 8, xSrcImage.bytes_per_line, ImageData.MSB_FIRST, 0, 0, srcWidth, srcHeight, null, null, null,
+ ImageData.ALPHA_OPAQUE, null, 0,
+ buf, 8, bplX, ImageData.MSB_FIRST, 0, 0, destWidth, destHeight, null, null, null,
+ flipX, flipY);
int bufPtr = OS.XtMalloc(bufSize);
OS.memmove(bufPtr, buf, bufSize);
xImagePtr = OS.XCreateImage(display, visual, 8, OS.ZPixmap, 0, bufPtr, destWidth, destHeight, 32, bplX);
@@ -557,7 +571,11 @@ static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth
OS.memmove(xImage, xImagePtr, XImage.sizeof);
int bufSize = xImage.bytes_per_line * destHeight;
byte[] buf = new byte[bufSize];
- ImageData.stretch16(srcData, xSrcImage.bytes_per_line, 0, 0, srcWidth, srcHeight, buf, xImage.bytes_per_line, 0, 0, destWidth, destHeight, flipX, flipY);
+ ImageData.blit(ImageData.BLIT_SRC,
+ srcData, 16, xSrcImage.bytes_per_line, ImageData.MSB_FIRST, 0, 0, srcWidth, srcHeight, 0, 0, 0,
+ ImageData.ALPHA_OPAQUE, null, 0,
+ buf, 16, xImage.bytes_per_line, ImageData.MSB_FIRST, 0, 0, destWidth, destHeight, 0, 0, 0,
+ flipX, flipY);
int bufPtr = OS.XtMalloc(bufSize);
OS.memmove(bufPtr, buf, bufSize);
xImage.data = bufPtr;
@@ -571,7 +589,11 @@ static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth
OS.memmove(xImage, xImagePtr, XImage.sizeof);
int bufSize = xImage.bytes_per_line * destHeight;
byte[] buf = new byte[bufSize];
- ImageData.stretch24(srcData, xSrcImage.bytes_per_line, 0, 0, srcWidth, srcHeight, buf, xImage.bytes_per_line, 0, 0, destWidth, destHeight, flipX, flipY);
+ ImageData.blit(ImageData.BLIT_SRC,
+ srcData, 24, xSrcImage.bytes_per_line, ImageData.MSB_FIRST, 0, 0, srcWidth, srcHeight, 0, 0, 0,
+ ImageData.ALPHA_OPAQUE, null, 0,
+ buf, 24, xImage.bytes_per_line, ImageData.MSB_FIRST, 0, 0, destWidth, destHeight, 0, 0, 0,
+ flipX, flipY);
int bufPtr = OS.XtMalloc(bufSize);
OS.memmove(bufPtr, buf, bufSize);
xImage.data = bufPtr;
@@ -585,7 +607,11 @@ static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth
OS.memmove(xImage, xImagePtr, XImage.sizeof);
int bufSize = xImage.bytes_per_line * destHeight;
byte[] buf = new byte[bufSize];
- ImageData.stretch32(srcData, xSrcImage.bytes_per_line, 0, 0, srcWidth, srcHeight, buf, xImage.bytes_per_line, 0, 0, destWidth, destHeight, flipX, flipY);
+ ImageData.blit(ImageData.BLIT_SRC,
+ srcData, 32, xSrcImage.bytes_per_line, ImageData.MSB_FIRST, 0, 0, srcWidth, srcHeight, 0, 0, 0,
+ ImageData.ALPHA_OPAQUE, null, 0,
+ buf, 32, xImage.bytes_per_line, ImageData.MSB_FIRST, 0, 0, destWidth, destHeight, 0, 0, 0,
+ flipX, flipY);
int bufPtr = OS.XtMalloc(bufSize);
OS.memmove(bufPtr, buf, bufSize);
xImage.data = bufPtr;
@@ -823,7 +849,7 @@ public void drawRoundRectangle (int x, int y, int width, int height, int arcWidt
}
if (nh < 0) {
nh = 0 - nh;
- ny = ny -nh;
+ ny = ny - nh;
}
if (naw < 0)
naw = 0 - naw;
@@ -835,14 +861,33 @@ public void drawRoundRectangle (int x, int y, int width, int height, int arcWidt
int xDisplay = data.display;
int xDrawable = data.drawable;
- OS.XDrawArc(xDisplay,xDrawable,handle,nx,ny,naw,nah,5760,5760);
- OS.XDrawArc(xDisplay,xDrawable,handle,nx,ny + nh - nah,naw,nah,11520,5760);
- OS.XDrawArc(xDisplay,xDrawable,handle,nx + nw - naw, ny + nh - nah, naw, nah,17280,5760);
- OS.XDrawArc(xDisplay,xDrawable,handle,nx + nw - naw, ny, naw, nah, 0, 5760);
- OS.XDrawLine(xDisplay,xDrawable,handle,nx + naw2, ny, nx + nw - naw2, ny);
- OS.XDrawLine(xDisplay,xDrawable,handle,nx,ny + nah2, nx, ny + nh - nah2);
- OS.XDrawLine(xDisplay,xDrawable,handle,nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
- OS.XDrawLine(xDisplay,xDrawable,handle,nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
+
+ 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
@@ -888,7 +933,7 @@ public void drawString (String string, int x, int y) {
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 (null, string, true);
+ 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);
@@ -996,7 +1041,7 @@ public void drawText (String string, int x, int y, boolean isTransparent) {
if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (data.renderTable == 0) createRenderTable();
int renderTable = data.renderTable;
- byte [] textBuffer = Converter.wcsToMbcs (null, string, true);
+ byte [] textBuffer = Converter.wcsToMbcs (getCodePage (), string, true);
int xmString = OS.XmStringGenerate(textBuffer, null, OS.XmCHARSET_TEXT, _MOTIF_DEFAULT_LOCALE);
if (isTransparent) {
OS.XmStringDraw (data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
@@ -1076,6 +1121,105 @@ public void fillArc(int x, int y, int width, int height, int startAngle, int end
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.
+ */
+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
@@ -1139,7 +1283,7 @@ public void fillPolygon(int[] pointArray) {
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.Convex, OS.CoordModeOrigin);
+ OS.XFillPolygon(xDisplay, data.drawable, handle,xPoints, xPoints.length / 2, OS.Complex, OS.CoordModeOrigin);
OS.XSetForeground (xDisplay, handle, values.foreground);
}
/**
@@ -1232,9 +1376,6 @@ public void fillRoundRectangle (int x, int y, int width, int height, int arcWidt
if (nah < 0)
nah = 0 - nah;
- naw = naw < nw ? naw : nw;
- nah = nah < nh ? nah : nh;
-
int naw2 = naw / 2;
int nah2 = nah / 2;
@@ -1243,13 +1384,30 @@ public void fillRoundRectangle (int x, int y, int width, int height, int arcWidt
XGCValues values = new XGCValues ();
OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
OS.XSetForeground(xDisplay, handle, values.background);
- OS.XFillArc(xDisplay,xDrawable,handle,nx,ny,naw,nah,5760,5760);
- OS.XFillArc(xDisplay,xDrawable,handle,nx,ny + nh - nah,naw,nah,11520,5760);
- OS.XFillArc(xDisplay,xDrawable,handle,nx + nw - naw, ny + nh - nah, naw, nah,17280,5760);
- OS.XFillArc(xDisplay,xDrawable,handle,nx + nw - naw, ny, naw, nah, 0, 5760);
- OS.XFillRectangle(xDisplay,xDrawable,handle,nx + naw2, ny, nw - naw, nh);
- OS.XFillRectangle(xDisplay,xDrawable,handle,nx,ny + nah2, naw2, nh - nah);
- OS.XFillRectangle(xDisplay,xDrawable,handle,nx + nw - (naw / 2), ny + nah2, naw2, nh -nah);
+
+ 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);
}
/**
@@ -1270,7 +1428,7 @@ public void fillRoundRectangle (int x, int y, int width, int height, int arcWidt
public int getAdvanceWidth(char ch) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
int fontList = data.fontList;
- byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch }, false);
+ 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];
@@ -1368,11 +1526,7 @@ public Color getBackground() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
int xDisplay = data.display;
XGCValues values = new XGCValues();
- if (OS.XGetGCValues(xDisplay, handle, OS.GCBackground, values) == 0) {
- // Check error case here. If a palette has been set we may be able
- // to do a better job.
- return null;
- }
+ OS.XGetGCValues(xDisplay, handle, OS.GCBackground, values);
XColor xColor = new XColor();
xColor.pixel = values.background;
OS.XQueryColor(xDisplay,data.colormap,xColor);
@@ -1398,7 +1552,7 @@ public Color getBackground() {
public int getCharWidth(char ch) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
int fontList = data.fontList;
- byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch }, false);
+ 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];
@@ -1540,6 +1694,9 @@ public void getClipping(Region region) {
OS.XSubtractRegion (hRegion, hRegion, hRegion);
OS.XUnionRegion (clipRgn, hRegion, hRegion);
}
+String getCodePage () {
+ return Converter.getCodePage(data.display, data.fontList);
+}
/**
* Returns the font currently being used by the receiver
* to draw and measure text.
@@ -1772,11 +1929,7 @@ public Color getForeground() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
int xDisplay = data.display;
XGCValues values = new XGCValues();
- if (OS.XGetGCValues(xDisplay, handle, OS.GCForeground, values) == 0) {
- // Check error case here. If a palette has been set we may be able
- // to do a better job.
- return null;
- }
+ OS.XGetGCValues(xDisplay, handle, OS.GCForeground, values);
XColor xColor = new XColor();
xColor.pixel = values.foreground;
OS.XQueryColor(xDisplay,data.colormap,xColor);
@@ -2154,7 +2307,7 @@ 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(null, string, true);
+ 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);
@@ -2185,7 +2338,7 @@ public Point textExtent(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 [] textBuffer = Converter.wcsToMbcs (null, string, true);
+ byte [] textBuffer = Converter.wcsToMbcs (getCodePage (), string, true);
int xmString = OS.XmStringGenerate(textBuffer, null, OS.XmCHARSET_TEXT, _MOTIF_DEFAULT_LOCALE);
if (data.renderTable == 0) createRenderTable();
int renderTable = data.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 70d84c99d2..d3594e936d 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
@@ -453,6 +453,7 @@ public Image(Device device, Image srcImage, int flag) {
*
* @exception IllegalArgumentException <ul>
* <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>
*/
public Image(Device device, Rectangle bounds) {
@@ -689,6 +690,11 @@ public ImageData getImageData() {
OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof);
/* Calculate the palette depending on the display attributes */
PaletteData palette = null;
+
+ /* Get the data for the source image. */
+ int length = xSrcImage.bytes_per_line * xSrcImage.height;
+ byte[] srcData = new byte[length];
+ OS.memmove(srcData, xSrcImage.data, length);
switch (xSrcImage.depth) {
case 1:
palette = new PaletteData(new RGB[] {
@@ -703,13 +709,40 @@ public ImageData getImageData() {
*/
SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
case 8:
- /* Use the RGBs from the display to make the palette */
- XColor[] xcolors = device.xcolors;
- RGB[] rgbs = new RGB[xcolors.length];
- for (int i = 0; i < rgbs.length; i++) {
- XColor xcolor = xcolors[i];
- if (xcolor == null) rgbs[i] = new RGB(0, 0, 0);
- else rgbs[i] = new RGB((xcolor.red >> 8) & 0xFF, (xcolor.green >> 8) & 0xFF, (xcolor.blue >> 8) & 0xFF);
+ /* 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;
@@ -731,9 +764,7 @@ public ImageData getImageData() {
SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
}
ImageData data = new ImageData(width, height, xSrcImage.depth, palette);
- int length = xSrcImage.bytes_per_line * xSrcImage.height;
- data.data = new byte[length];
- OS.memmove(data.data, xSrcImage.data, length);
+ data.data = srcData;
if (xSrcImage.bits_per_pixel == 32) {
/**
* If bits per pixel is 32, scale the data down to 24, since we do not
@@ -747,7 +778,7 @@ public ImageData getImageData() {
int srcIndex = 0;
int rOffset = 0, gOffset = 1, bOffset = 2;
if (xSrcImage.byte_order == OS.MSBFirst) {
- rOffset = 2; gOffset = 1; bOffset = 0;
+ rOffset = 3; gOffset = 2; bOffset = 1;
}
for (int y = 0; y < height; y++) {
destIndex = y * bytesPerLine;
@@ -954,6 +985,7 @@ 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);
}
@@ -1021,7 +1053,7 @@ public static Image motif_new(Device device, int type, int pixmap, int mask) {
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, 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 == 16 || image.depth == 24) && 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;
@@ -1035,7 +1067,7 @@ static int putImage(ImageData image, int srcX, int srcY, int srcWidth, int srcHe
destY = destY - destHeight;
}
byte[] srcReds = null, srcGreens = null, srcBlues = null;
- if (image.depth <= 8) {
+ if (! palette.isDirect) {
int length = palette.getRGBs().length;
srcReds = new byte[length];
srcGreens = new byte[length];
@@ -1051,6 +1083,7 @@ static int putImage(ImageData image, int srcX, int srcY, int srcWidth, int srcHe
}
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];
@@ -1063,12 +1096,14 @@ static int putImage(ImageData image, int srcX, int srcY, int srcWidth, int srcHe
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) {
RGB rgb = image.palette.getRGB(transparentPixel[0]);
@@ -1087,15 +1122,7 @@ static int putImage(ImageData image, int srcX, int srcY, int srcWidth, int srcHe
OS.XtFree(bufPtr);
return SWT.ERROR_NO_HANDLES;
}
- int foreground = 0, background = 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);
- }
+ int foreground = 1, background = 0;
XImage xImage = new XImage();
OS.memmove(xImage, xImagePtr, XImage.sizeof);
xImage.byte_order = OS.MSBFirst;
@@ -1103,8 +1130,11 @@ static int putImage(ImageData image, int srcX, int srcY, int srcWidth, int srcHe
xImage.bitmap_bit_order = OS.MSBFirst;
OS.memmove(xImagePtr, xImage, XImage.sizeof);
int destOrder = ImageData.MSB_FIRST;
- ImageData.stretch1(image.data, image.bytesPerLine, ImageData.MSB_FIRST, srcX, srcY, srcWidth, srcHeight,
- buf, bplX, ImageData.MSB_FIRST, 0, 0, destWidth, destHeight, flipX, flipY);
+ ImageData.blit(ImageData.BLIT_SRC,
+ image.data, 1, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, null, null, null,
+ ImageData.ALPHA_OPAQUE, null, 0,
+ buf, 1, bplX, destOrder, 0, 0, destWidth, destHeight, null, null, null,
+ flipX, flipY);
OS.memmove(xImage.data, buf, bufSize);
XGCValues values = new XGCValues();
OS.XGetGCValues(display, gc, OS.GCForeground | OS.GCBackground, values);
@@ -1127,61 +1157,76 @@ static int putImage(ImageData image, int srcX, int srcY, int srcWidth, int srcHe
int bufPtr = OS.XtMalloc(bufSize);
xImage.data = bufPtr;
OS.memmove(xImagePtr, xImage, XImage.sizeof);
- int srcOrder = image.depth == 16 ? ImageData.LSB_FIRST : ImageData.MSB_FIRST;
+ int srcOrder = image.getByteOrder();
int destOrder = xImage.byte_order == OS.MSBFirst ? ImageData.MSB_FIRST : ImageData.LSB_FIRST;
- if (image.depth > 8 && screenDepth > 8) {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, srcOrder, srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask, -1, null, 0,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask,
- flipX, flipY);
- } else if (image.depth <= 8 && screenDepth > 8) {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, srcOrder, srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues, -1, null, 0,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask,
- flipX, flipY);
- } else if (image.depth > 8 && screenDepth <= 8) {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, srcOrder, srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask, -1, null, 0,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues,
- flipX, flipY);
- } else if (image.depth <= 8 && screenDepth <= 8) {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, srcOrder, srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues, -1, null, 0,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues,
- flipX, flipY);
+ if (palette.isDirect) {
+ if (screenDirect) {
+ ImageData.blit(ImageData.BLIT_SRC,
+ image.data, image.depth, image.bytesPerLine, srcOrder, srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask,
+ ImageData.ALPHA_OPAQUE, null, 0,
+ buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 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, srcOrder, srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask,
+ ImageData.ALPHA_OPAQUE, null, 0,
+ buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues,
+ flipX, flipY);
+ }
+ } else {
+ if (screenDirect) {
+ ImageData.blit(ImageData.BLIT_SRC,
+ image.data, image.depth, image.bytesPerLine, srcOrder, srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues,
+ ImageData.ALPHA_OPAQUE, null, 0,
+ buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 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, srcOrder, srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues,
+ ImageData.ALPHA_OPAQUE, null, 0,
+ buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 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>
- * This method has no effect if the receiver does not have a transparent
- * pixel value.
- *
- * @param color the color to use when a transparent pixel is specified
- *
- * @exception IllegalArgumentException <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>
+ * </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);
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 b314d0f539..ccd0a97bcd 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
@@ -41,6 +41,7 @@ Region (int handle) {
*
* @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>
@@ -49,6 +50,8 @@ Region (int 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;
@@ -64,7 +67,8 @@ public void add (Rectangle rect) {
* @param region the region to merge
*
* @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
+ * <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>
@@ -73,6 +77,7 @@ public void add (Rectangle rect) {
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);
}
/**
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 cf248bd654..f9e73e673b 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
@@ -5,82 +5,396 @@ package org.eclipse.swt.internal;
* All Rights Reserved
*/
-/**
- * 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>
- */
+import org.eclipse.swt.internal.motif.*;
+import java.util.*;
+
+/**
+ * This class implements the conversions between unicode characters
+ * and the <em>platform supported</em> representation for characters.
+ * <p>
+ * Note that, unicode characters which can not be found in the platform
+ * encoding will be converted to an arbitrary platform specific character.
+ * </p>
+ */
public final class Converter {
- public static final byte [] NullByteArray = new byte [1];
- public static final 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
- */
+
+ 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;
+
+ /* 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 - 3);
+ }
+ }
+ } 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 () {
- /*
- | ptr cp |
- DefaultCodePage == nil ifFalse: [^DefaultCodePage].
- cp := ''. "$NON-NLS$"
- (ptr := OSStringZ address: (NlLanginfo callWith: 49)) isNull
- ifFalse: [cp := String copyFromOSMemory: ptr].
- cp isEmpty ifFalse: [
- IsSunOS ifTrue: [
- (cp size > 3 and: [(cp copyFrom: 1 to: 3) = 'ISO'])
- ifTrue: [cp := cp copyFrom: 4 to: cp size]].
- ^DefaultCodePage := cp].
- IsAIX ifTrue: [^DefaultCodePage := 'ISO8859-1'].
- IsSunOS ifTrue: [^DefaultCodePage := '8859-1'].
- ^DefaultCodePage := 'iso8859_1'
- */
- return null;
+ return CodePage;
}
-static boolean is7BitAscii (byte [] buffer) {
- for (int i=0; i<buffer.length; i++) {
- if ((buffer [i] & 0xFF) > 0x7F) return false;
+
+/**
+ * Returns the code page for the specified font list.
+ * (Warning this method is platform dependent.)
+ *
+ * @return the code page for the font list
+ */
+public 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;
+ int[] fontStructPtr = new int[1];
+ int[] fontNamePtr = new int[1];
+ 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 */
+ StringBuffer stringBuffer = new StringBuffer();
+ 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 = getAsciiString (codeset);
+
+ /* Reset the locale */
+ OS.setlocale (OS.LC_CTYPE, new byte[1]);
+ }
}
- return true;
+ OS.XmFontListFreeFontContext(context);
+ return codePage;
}
-static boolean is7BitAscii (char [] buffer) {
- for (int i=0; i<buffer.length; i++) {
- if (buffer [i] > 0x7F) return false;
+
+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 true;
+ return buffer;
}
-public static char [] mbcsToWcs (String codePage, byte [] buffer) {
- //SLOW AND BOGUS
- return new String (buffer).toCharArray ();
+
+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);
}
-/* TEMPORARY CODE */
-public static byte [] wcsToMbcs (String codePage, String string) {
- return wcsToMbcs (codePage, string, false);
+
+/**
+ * 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 (Converter.class) {
+ 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));
+ }
+ 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);
+ int result = OS.iconv (cd, inBuf, inBytesLeft, outBuf, outBytesLeft);
+ outBytes = outBuf [0] - ptr2;
+ wideCharStr = new char [outBytes / 2];
+
+ /* Memmove can not be used because of the endianess */
+// OS.memmove (wideCharStr, ptr2, outBytesLeft [0]);
+ byte[] b = new byte [outBytes];
+ OS.memmove (b, ptr2, outBytes);
+ for (int j=0; j<outBytes; j+=2) {
+ wideCharStr [j >> 1] = (char)(((b [j] & 0xFF) << 8) | (b [j + 1] & 0xFF));
+ }
+
+ if (ptr1 != BufferTimes2) OS.XtFree (ptr1);
+ if (ptr2 != BufferTimes4) OS.XtFree (ptr2);
+ }
+ return wideCharStr;
+ }
+ }
+ return wideCharStr;
}
-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);
+
+/**
+ * Free any cached resources.
+ */
+public static void release () {
+ synchronized (Converter.class) {
+ 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;
+ }
}
-/* TEMPORARY CODE */
+
+/**
+ * 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) {
- //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;
+
+ /* 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 (Converter.class) {
+ 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);
+ }
+ 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};
+
+ /* Memmove can not be used because of the endianess */
+// OS.memmove (ptr1, buffer, inBytes);
+ byte[] b = new byte[inBytes];
+ for (int j=0; j<inBytes; j+=2) {
+ int c = buffer [j >> 1];
+ b [j] = (byte)(c >> 8);
+ b [j + 1] = (byte)(c & 0xFF);
+ }
+ OS.memmove (ptr1, b, inBytes);
+
+ int result = OS.iconv (cd, inBuf, inBytesLeft, outBuf, outBytesLeft);
+ outBytes = outBuf [0] - ptr2;
+ mbcs = new byte [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/internal/motif/KDE.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/KDE.java
index 949c48c736..eeb4c65232 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/KDE.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/KDE.java
@@ -9,46 +9,50 @@ public class KDE extends OS {
public static final int KICON_SMALL = 0;
-public static final native int KApplication_new(int qcString);
+public static final native int KApplication_new(int qcString);
-public static final native int KGlobal_iconLoader();
+public static final native int KGlobal_iconLoader();
-public static final native int KIconLoader_iconPath(int receiver, int iconQString, int iconType, int canReturnNull);
+public static final native int KIconLoader_iconPath(int loader, int iconQString, int iconType, int canReturnNull);
-public static final native int KMimeType_findByURL(int kurl);
-public static final native int KMimeType_icon(int receiver, int unused1, int unused2);
-public static final native int KMimeType_name(int receiver);
+public static final native int KMimeType_mimeType(int mimeTypeName);
+public static final native int KMimeType_icon(int mimeType, int unused1, int unused2);
+public static final native int KMimeType_name(int mimeType);
+public static final native int KMimeType_patterns(int mimeType);
+public static final native int KMimeType_offers(int mimeTypeName);
+public static final native int KMimeType_allMimeTypes();
-public static final native int KService_allServices();
-public static final native int KService_exec(int receiver);
-public static final native int KService_icon(int receiver);
-public static final native int KService_name(int receiver);
-public static final native int KService_serviceByName(int serviceName);
-public static final native int KService_type(int receiver);
+public static final native int KMimeTypeList_begin(int mimeTypeList);
+public static final native int KMimeTypeList_delete(int mimeTypeList);
+public static final native int KMimeTypeList_end(int mimeTypeList);
-public static final native int KServiceTypeProfile_preferredService(int mimeTypeQString, int needApp);
+public static final native int KMimeTypeListIterator_delete(int iterator);
+public static final native int KMimeTypeListIterator_dereference(int iterator);
+public static final native int KMimeTypeListIterator_equals(int iterator, int iterator2);
+public static final native void KMimeTypeListIterator_increment(int iterator);
-public static final native void KURL_delete(int receiver);
+public static final native int QStringList_begin(int qstringList);
+public static final native int QStringList_delete(int qstringList);
+public static final native int QStringList_end(int qstringList);
-public static final native int KURL_new(int qString);
+public static final native int QStringListIterator_delete(int iterator);
+public static final native int QStringListIterator_dereference(int iterator);
+public static final native int QStringListIterator_equals(int iterator, int iterator2);
+public static final native void QStringListIterator_increment(int iterator);
-public static final native int KServiceList_begin(int receiver);
-public static final native int KServiceList_delete(int receiver);
-public static final native int KServiceList_end(int receiver);
+public static final native int KURL_new( int qURLString );
+public static final native void KURL_delete( int url );
+public static final native int KRun_runURL( int url, int mimeTypeName );
-public static final native int QCString_data(int receiver);
-public static final native int QCString_delete(int receiver);
-public static final native int QCString_new(byte[] string);
+public static final native int KServiceList_delete(int serviceList);
-public static final native int QString_delete(int receiver);
-public static final native int QString_equals(int receiver, int object);
-public static final native int QString_new(byte[] string);
-public static final native int QString_utf8(int receiver);
+public static final native int QCString_data(int qcString);
+public static final native int QCString_delete(int qcString);
+public static final native int QCString_new(byte[] string);
-public static final native int KServiceListIterator_delete(int receiver);
-public static final native int KServiceListIterator_dereference(int receiver);
-public static final native void KServiceListIterator_increment(int receiver);
-public static final native int KServiceListIterator_new(int listBeginning);
-public static final native int KServiceListIterator_equals(int receiver, int object);
+public static final native int QString_delete(int qString);
+public static final native int QString_equals(int qString, int qString2);
+public static final native int QString_new(byte[] string);
+public static final native int QString_utf8(int qString);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/OS.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/OS.java
index c311603786..6caa14ef15 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/motif/OS.java
@@ -14,6 +14,44 @@ public class OS {
Callback.loadLibrary ();
}
+ /* OS and locale Constants*/
+ public static final boolean IsAIX, IsSunOS, IsLinux;
+ public static final int CODESET;
+ public static final int LC_CTYPE;
+ static {
+
+ /* Initialize the OS flags and locale constants */
+ String osName = System.getProperty ("os.name");
+ if (osName.equals("Linux")) {
+ IsLinux = true;
+ IsAIX = IsSunOS = false;
+ } else {
+ if (osName.equals("AIX")) {
+ IsAIX = true;
+ IsLinux = IsSunOS = false;
+ } else {
+ if (osName.equals("Solaris")) {
+ IsSunOS = true;
+ IsLinux = IsAIX = false;
+ } else {
+ IsLinux = IsSunOS = IsAIX = false;
+ }
+ }
+ }
+
+ CODESET = OS.IsLinux ? 14 : 49;
+ LC_CTYPE = OS.IsAIX ? 1 : 0;
+ }
+
+ /* BEGIN Visual classes */
+ //public static final int StaticGray = 0;
+ //public static final int GrayScale = 1;
+ //public static final int StaticColor = 2;
+ //public static final int PseudoColor = 3;
+ //public static final int TrueColor = 4;
+ //public static final int DirectColor = 5;
+ /* END Visual clases */
+
/* X/Xt/Xm Constants */
public static final byte [] XmFONTLIST_DEFAULT_TAG = {0x46, 0x4F, 0x4E, 0x54, 0x4C, 0x49, 0x53, 0x54, 0x5F, 0x44, 0x45, 0x46, 0x41, 0x55, 0x4C, 0x54, 0x5F, 0x54, 0x41, 0x47, 0x5F, 0x53, 0x54, 0x52, 0x49, 0x4E, 0x47, 0x0};
public static final int Above = 0;
@@ -49,7 +87,7 @@ public class OS {
// public static final int ClipByChildren = 0x0;
// public static final int ColormapChangeMask = 1 << 23;
// public static final int ColormapNotify = 32;
-// public static final int Complex = 0;
+ public static final int Complex = 0;
public static final int ConfigureNotify = 22;
// public static final int ConfigureRequest = 23;
public static final int ControlMask = (1<<2);
@@ -160,7 +198,7 @@ public class OS {
// public static final int LeaveNotify = 8;
public static final int LeaveWindowMask = 1 << 5;
public static final int LineDoubleDash = 0x2;
-// public static final int LineOnOffDash = 0x1;
+ public static final int LineOnOffDash = 0x1;
public static final int LineSolid = 0x0;
// public static final int LockMask = (1<<1);
public static final int LSBFirst = 0;
@@ -379,7 +417,7 @@ public class OS {
public static final int XK_Shift_L = 0xFFE1;
public static final int XK_Shift_R = 0xFFE2;
public static final int XK_Tab = 0xFF09;
- public static final int XK_Up = 0xFF52;
+ public static final int XK_Up = 0xFF52;
public static final int XK_VoidSymbol = 0xFFFFFF;
// public static final int XLookupBoth = 0x4;
// public static final int XLookupChars = 0x2;
@@ -575,7 +613,7 @@ public class OS {
public static final int XmNdragInitiatorProtocolStyle = malloc ("dragInitiatorProtocolStyle");
public static final int XmNdragReceiverProtocolStyle = malloc ("dragReceiverProtocolStyle");
public static final int XmNdragOperations = malloc ("dragOperations");
- public static final int XmNeditable = malloc ("editable");
+ public static final int XmNeditable = malloc ("editable");
public static final int XmNenableThinThickness = malloc ("enableThinThickness");
public static final int XmNiconic = malloc ("iconic");
public static final int XmNlabelType = malloc ("labelType");
@@ -733,6 +771,11 @@ public class OS {
public static final int XmNvisibleItemCount = malloc ("visibleItemCount");
public static final int XmNdropTransfers = malloc ("dropTransfers");
public static final int XmNshowArrows = malloc ("showArrows");
+ public static final int XmNspotLocation = malloc ("spotLocation");
+// public static final int XNFocusWindow = malloc ("focusWindow");
+// public static final int XNInputStyle = malloc ("inputStyle");
+// public static final int XNClientWindow = malloc ("clientWindow");
+// public static final int XNQueryInputStyle = malloc ("queryInputStyle");
/* Unknown */
public static final int XmNdropSiteActivity = malloc("dropSiteActivity");
@@ -820,9 +863,7 @@ public class OS {
public static final native int XmCreateDrawnButton (int parent, byte [] name, int [] arglist, int argcount);
public static final native int XmCreateRowColumn (int parent, byte [] name, int [] arglist, int argcount);
public static final native int XmCreateScrolledWindow (int parent, byte [] name, int [] arglist, int argcount);
- public static final native boolean XmDestroyPixmap (int screen, int pixmap);
public static final native int XmGetFocusWidget (int widget);
- public static final native int XmGetPixmapByDepth (int screen, byte [] image_name, int foreground, int background, int depth);
public static final native void XmListAddItemsUnselected (int list, int xmStringTable, int item_count, int position);
public static final native void XmListDeleteItem (int list, int item);
public static final native void XmListDeselectItem (int list, int xmString);
@@ -913,8 +954,10 @@ public static final native int XGrabPointer (
int cursor,
int time);
public static final native int XInitThreads ();
+public static final native int XInternAtom( int display, byte [] name, boolean ifExists );
public static final native int XKeysymToString (int keysym);
public static final native int XListFonts(int display, byte[] pattern, int maxnames, int[] actual_count_return);
+public static final native int XListProperties(int display, int window, int[] num_prop_return);
public static final native int XLookupString (XKeyEvent event, byte [] string, int size, int [] keysym, int [] status);
public static final native int XLowerWindow (int display, int window);
public static final native boolean XPointInRegion (int region, int x, int y);
@@ -1006,6 +1049,7 @@ public static final native int XmCreateTextField (int parent, byte [] name, int
public static final native int XmCreateToggleButton (int parent, byte [] name, int [] arglist, int argcount);
public static final native int XmCreateToggleButtonGadget (int parent, byte [] name, int [] arglist, int argcount);
public static final native int XmCreateWarningDialog (int parent, byte [] name, int [] arglist, int argcount);
+public static final native boolean XmDestroyPixmap (int screen, int pixmap);
public static final native void XmDragCancel(int dragcontext);
public static final native int XmDragStart(int widget, XAnyEvent event, int[] arglist, int argcount);
public static final native void XmDropSiteRegister(int widget, int [] arglist, int argcount);
@@ -1026,6 +1070,8 @@ public static final native int XmFontListNextEntry (int context);
public static final native int XmGetAtomName (int display, int atom);
public static final native int XmGetDragContext (int widget, int timestamp);
public static final native int XmGetFocusWidget (int widget);
+public static final native int XmGetPixmap( int screen, byte [] name, int fgPixel, int bgPixel );
+public static final native int XmGetPixmapByDepth (int screen, byte [] image_name, int foreground, int background, int depth);
public static final native int XmGetXmDisplay (int display);
public static final native int XmImMbLookupString (int widget, XKeyEvent event, byte [] string, int size, int [] keysym, int [] status);
public static final native int XmInternAtom (int display, byte [] name, boolean only_if_exists);
@@ -1102,7 +1148,7 @@ public static final native void XmTextSetString (int widget, byte [] value);
public static final native void XmTextShowPosition (int widget, int position);
public static final native void XmUpdateDisplay (int widget);
public static final native boolean XmWidgetGetDisplayRect (int region, XRectangle rectangle);
-public static final native int XmbLookupString (int ic, XKeyEvent event, byte [] string, int size, int [] keysym, int [] status);
+//public static final native int XmbLookupString (int ic, XKeyEvent event, byte [] string, int size, int [] keysym, int [] status);
public static final native void XtAddCallback (int widget, int callback_name, int callback, int client_data);
public static final native void XtAddEventHandler (int widget, int event_mask, boolean nonmaskable, int proc, int client_data);
public static final native void XtAddExposureToRegion (int event, int region);
@@ -1212,7 +1258,6 @@ public static final native void memmove (XmTextVerifyCallbackStruct dest, int sr
public static final native void memmove (byte [] dest, int src, int count);
public static final native void memmove (int [] dest, int src, int count);
public static final native int strlen (int string);
-public static final native int XpmReadFileToPixmap(int display, int drawable, byte[] fileName, int[] pixmap_return, int[] shapemask_return, int attributes);
public static final native int XmCreateDrawnButton (int parent, byte [] name, int [] arglist, int argcount);
public static final native int XCheckIfEvent (int display, XAnyEvent event_return, int predicate, int arg);
public static final native boolean XtToolkitThreadInitialize ();
@@ -1257,19 +1302,47 @@ public static final native void XDestroyWindow(int display, int w);
/*
* ======== End of printing constants and functions ========
*/
-
-public static final native int pipe (int [] filedes);
-public static final native int read (int filedes, byte [] buf, int nbyte);
-public static final native int write (int filedes, byte [] buf, int nbyte);
-public static final native int close (int filedes);
-public static final native int XtAppAddInput (int app_context, int source, int condition, int proc, int client_data);
-public static final native void XtRemoveInput (int id);
-// public static final int XtInputNoneMask = 0;
- public static final int XtInputReadMask = 1;
-// public static final int XtInputWriteMask = 2;
+
+public static final native int pipe (int [] filedes);
+public static final native int read (int filedes, byte [] buf, int nbyte);
+public static final native int write (int filedes, byte [] buf, int nbyte);
+public static final native int close (int filedes);
+public static final native int XtAppAddInput (int app_context, int source, int condition, int proc, int client_data);
+public static final native void XtRemoveInput (int id);
+// public static final int XtInputNoneMask = 0;
+ public static final int XtInputReadMask = 1;
+// public static final int XtInputWriteMask = 2;
// public static final int XtInputExceptMask = 4;
public static final native int XLoadQueryFont (int display, byte[] name);
public static final native int XmFontListEntryCreate (byte[] tag, int type, int font);
-
+
+public static final native int XmImGetXIC (int widget, int input_policy, int[] args, int num_args);
+public static final native int XmImGetXIM (int widget);
+public static final native void XmImRegister (int widget, int reserved);
+//public static final native int XmImSetFocusValues (int widget, int[] args, int num_args);
+public static final native int XmImVaSetFocusValues(int widget, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9);
+public static final native int XmImSetValues (int widget, int[] args, int num_args);
+public static final native void XmImUnregister (int widget);
+public static final native void XmImUnsetFocus (int widget);
+//public static final native void XSetICFocus (int ic);
+//public static final native void XUnsetICFocus (int ic);
+//public static final native int XCreateIC (int im, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7);
+//public static final native int XSetICValues (int ic, int arg1, int arg2, int arg3);
+//public static final native int XGetICValues (int ic, int arg1, int arg2, int arg3);
+//public static final native int XGetIMValues (int im, int arg1, int arg2, int arg3);
+public static final native void memmove (int dest, short [] src, int count);
+//public static final native void memmove (char[] dest, int src, int count);
+//public static final native void memmove ( int dest, char[] src,int count);
+
+public static final native int nl_langinfo (int item);
+public static final native int iconv_open (byte[] tocode, byte[] fromcode);
+public static final native int iconv_close (int cd);
+public static final native int iconv (int cd, int[] inBuf, int[] inBytesLeft, int[] outBuf, int[] outBytesLeft);
+public static final native int MB_CUR_MAX ();
+public static final native int setlocale (int category, byte[] locale);
+
+public static final native int XCreateFontSet (int display, byte [] base_font_name_list, int [] missing_charset_list_return, int [] missing_charset_count_return, int [] def_string_return);
+public static final native int XLocaleOfFontSet (int fontSet);
+
}
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 ebacd6aa45..bfcb36a7d7 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
@@ -11,20 +11,20 @@ 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>LEFT, RIGHT, CENTER</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <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>LEFT, RIGHT, CENTER</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>Selection</dd>
+ * </dl>
+ * <p>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation.
+ * </p>
*/
public /*final*/ class Button extends Control {
@@ -41,33 +41,33 @@ public /*final*/ class Button extends Control {
}
ARM_AND_ACTIVATE = buffer;
}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * 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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 Button (Composite parent, int style) {
super (parent, checkStyle (style));
@@ -97,8 +97,7 @@ public Button (Composite parent, int style) {
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection,typedListener);
@@ -124,8 +123,7 @@ void click () {
* Computes the preferred size.
*/
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int border = getBorderWidth ();
int width = border * 2, height = border * 2;
if ((style & SWT.ARROW) != 0) {
@@ -283,25 +281,24 @@ int defaultFont () {
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
- * <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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.ARROW) != 0) {
int [] argList = {OS.XmNarrowDirection, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
@@ -326,67 +323,64 @@ boolean getDefault () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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.
- *
- * @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.
+ *
+ * @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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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] != 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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];
+ 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;
@@ -403,7 +397,7 @@ public String getText () {
byte [] buffer = new byte [length];
OS.memmove (buffer, address, length);
OS.XtFree (address);
- result = Converter.mbcsToWcs (null, buffer);
+ result = Converter.mbcsToWcs (getCodePage (), buffer);
}
if (xmString != 0) OS.XmStringFree (xmString);
int count = 0;
@@ -477,26 +471,25 @@ void releaseWidget () {
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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook(SWT.Selection, listener);
@@ -518,25 +511,24 @@ void selectRadio () {
}
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.ARROW) != 0) {
int [] argList = {OS.XmNarrowDirection, OS.XmARROW_UP};
if ((alignment & SWT.UP) != 0) argList [1] = OS.XmARROW_UP;
@@ -565,6 +557,7 @@ void setBitmap (Image image) {
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:
@@ -601,63 +594,63 @@ void setDefault (boolean value) {
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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setBitmap (this.image = image);
}
-/**
- * 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. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed.
- *
- * @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.
+ * <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.
+ *
+ * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
int [] argList = {OS.XmNset, selected ? 1 : 0};
OS.XtSetValues (handle, argList, argList.length / 2);
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.ARROW) != 0) return;
char [] text = new char [string.length ()];
@@ -672,7 +665,7 @@ public void setText (String string) {
}
}
while (j < text.length) text [j++] = 0;
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), text, true);
int xmString = OS.XmStringParseText (
buffer,
0,
@@ -681,7 +674,7 @@ public void setText (String string) {
null,
0,
0);
- if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
+ if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol;
int [] argList = {
OS.XmNlabelType, OS.XmSTRING,
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 f8e2d316b2..79336fa941 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
@@ -9,58 +9,58 @@ 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
- */
+/**
+ * Instances of this class provide a surface for drawing
+ * arbitrary graphics.
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>(none)</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>(none)</dd>
+ * </dl>
+ * <p>
+ * This class may be subclassed by custom control implementors
+ * who are building controls that are <em>not</em> constructed
+ * from aggregates of other controls. That is, they are either
+ * painted using SWT graphics calls or are handled by native
+ * methods.
+ * </p>
+ *
+ * @see Composite
+ */
public class Canvas extends Composite {
Caret caret;
Canvas () {
/* Do nothing */
}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * 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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 Canvas (Composite parent, int style) {
super (parent, style);
@@ -69,30 +69,35 @@ void createWidget (int index) {
super.createWidget (index);
fontList = defaultFont ();
}
-/**
- * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return caret;
}
+short [] getIMECaretPos () {
+ if (caret == null) return super.getIMECaretPos ();
+ int width = caret.width;
+ if (width <= 0) width = 2;
+ return new short[]{(short) (caret.x + width), (short) (caret.y + caret.height)};
+}
int processFocusIn () {
int result = super.processFocusIn ();
if (caret != null) caret.setFocus ();
@@ -128,31 +133,30 @@ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (width <= 0 || height <= 0) return;
int deltaX = destX - x, deltaY = destY - y;
if (deltaX == 0 && deltaY == 0) return;
@@ -197,56 +201,68 @@ public void scroll (int destX, int destY, int x, int y, int width, int height, b
if (isFocus) caret.setFocus ();
}
public void setBounds (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
boolean isFocus = caret != null && caret.isFocusCaret ();
if (isFocus) caret.killFocus ();
super.setBounds (x, y, width, height);
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
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Caret newCaret = caret;
Caret oldCaret = this.caret;
this.caret = newCaret;
if (hasFocus ()) {
if (oldCaret != null) oldCaret.killFocus ();
- if (newCaret != null) newCaret.setFocus ();
+ if (newCaret != null) {
+ if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ newCaret.setFocus ();
+ }
}
}
public void setLocation (int x, int y) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
boolean isFocus = caret != null && caret.isFocusCaret ();
if (isFocus) caret.killFocus ();
super.setLocation (x, y);
if (isFocus) caret.setFocus ();
}
public void setSize (int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
boolean isFocus = caret != null && caret.isFocusCaret ();
if (isFocus) caret.killFocus ();
super.setSize (width, height);
if (isFocus) caret.setFocus ();
}
+void updateCaret () {
+ if (caret == null) return;
+ if (!IsDBLocale) return;
+ short [] point = getIMECaretPos ();
+ 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);
+}
}
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 5274b4443f..b207c903b8 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
@@ -9,54 +9,55 @@ 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>
+/**
+ * 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 /*final*/ class Caret extends Widget {
Canvas parent;
+ Image image;
int x, y, width, height;
boolean moved, resized;
boolean isVisible, isShowing;
int blinkRate = 500;
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 Caret (Canvas parent, int style) {
super (parent, style);
@@ -91,26 +92,34 @@ boolean drawCaret () {
int color = foreground ^ background;
OS.XSetFunction (xDisplay, gc, OS.GXxor);
OS.XSetForeground (xDisplay, gc, color);
- int nWidth = width;
+ 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, height);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (image != null) {
+ Rectangle rect = image.getBounds ();
+ return new Rectangle (x, y, rect.width, rect.height);
+ }
return new Rectangle (x, y, width, height);
}
/**
@@ -121,87 +130,100 @@ public Display getDisplay () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent.getFont ();
}
-/**
- * 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 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return isVisible;
}
boolean hideCaret () {
@@ -211,26 +233,25 @@ boolean hideCaret () {
isShowing = false;
return drawCaret ();
}
-/**
- * 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 isVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return isVisible && parent.isVisible () && parent.hasFocus ();
}
boolean isFocusCaret () {
@@ -255,26 +276,26 @@ void releaseWidget () {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
boolean samePosition, sameExtent, showing;
samePosition = (this.x == x) && (this.y == y);
sameExtent = (this.width == width) && (this.height == height);
@@ -286,36 +307,33 @@ public void setBounds (int x, int y, int width, int height) {
moved = true;
if (isVisible ()) {
moved = false;
- //IsDBLocale ifTrue: [
- //widget == nil ifFalse: [widget updateCaret]].
+ parent.updateCaret ();
}
} else {
resized = true;
if (isVisible ()) {
moved = false;
- //IsDBLocale ifTrue: [
- //widget == nil ifFalse: [widget updateCaret]].
+ parent.updateCaret ();
resized = false;
}
}
if (isShowing) 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
setBounds (rect.x, rect.y, rect.width, rect.height);
}
@@ -325,113 +343,125 @@ void setFocus () {
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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+}
+/**
+ * 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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 (isShowing) hideCaret ();
+ this.image = image;
+ if (isShowing) 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * Marks the receiver as visible if the argument is <code>true</code>,
+ * and marks it invisible otherwise.
+ * <p>
+ * If one of the receiver's ancestors is not visible or some
+ * other condition makes the receiver not visible, marking
+ * it visible may not actually cause it to be displayed.
+ * </p>
+ *
+ * @param visible the new visibility state
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
*/
public void setVisible (boolean visible) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (visible == isVisible) return;
if (isVisible = visible) {
showCaret ();
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 c598a52931..0226056543 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
@@ -9,19 +9,19 @@ 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>
+/**
+ * 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 /*final*/ class ColorDialog extends Dialog {
private static final int DEPTH_4 = 0; // index for COLOR_SWATCH_EXTENTS
@@ -41,60 +41,60 @@ public /*final*/ class ColorDialog extends Dialog {
private boolean okSelected; // true if the dialog was hidden
// because the ok button was selected
- private RGB dialogResult;
+ private RGB rgb;
private int colorDepth; // color depth of the display
private int colorSwatchExtent; // the size of on square used
// to display one color
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
- */
+/**
+ * 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
- * 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
- */
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 ColorDialog(Shell parent, int style) {
super(parent, style | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
}
@@ -197,10 +197,6 @@ void disposeColors() {
}
}
}
-/**
- * Insert the method's description here.
- * Creation date: (7/6/99 5:07:09 PM)
- */
void drawColor(int xIndex, int yIndex, Color color, GC gc) {
int colorSwatchExtent = getColorSwatchExtent();
int colorExtent = colorSwatchExtent - COLOR_SWATCH_BORDER;
@@ -210,69 +206,37 @@ void drawColor(int xIndex, int yIndex, Color color, GC gc) {
xIndex * colorSwatchExtent, yIndex * colorSwatchExtent,
colorExtent, colorExtent);
}
-/**
- * Insert the method's description here.
- * Creation date: (7/6/99 5:07:09 PM)
- */
Canvas getColorCanvas() {
return colorsCanvas;
}
-/**
- * Insert the method's description here.
- * Creation date: (7/6/99 5:07:09 PM)
- */
int getColorDepth() {
return colorDepth;
}
-/**
- * Insert the method's description here.
- * Creation date: (7/6/99 5:07:09 PM)
- */
Color [][] getColorGrid() {
return colorGrid;
}
-/**
- * Insert the method's description here.
- * Creation date: (7/6/99 5:07:09 PM)
- */
int getColorSwatchExtent() {
return colorSwatchExtent;
}
-/**
- * Returns the currently selected color in the receiver.
- *
- * @return the RGB value for the selected color
- *
- * @see PaletteData#getRGBs
- */
-public RGB getRGB() {
- return dialogResult;
-}
/**
- * Insert the method's description here.
- * Creation date: (7/6/99 5:07:09 PM)
+ * 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;
+}
Canvas getSampleCanvas() {
return sampleCanvas;
}
-/**
- * Insert the method's description here.
- * Creation date: (7/6/99 5:07:09 PM)
- */
Label getSampleText() {
return sampleLabel;
}
-/**
- * Insert the method's description here.
- * Creation date: (7/6/99 5:07:09 PM)
- */
Canvas getSelectionCanvas() {
return selectionCanvas;
}
-/**
- * Insert the method's description here.
- * Creation date: (7/6/99 5:07:09 PM)
- */
Label getSelectionText() {
return selectionLabel;
}
@@ -303,10 +267,6 @@ void handleEvents(Event event) {
}
}
}
-/**
- * Insert the method's description here.
- * Creation date: (7/6/99 5:07:09 PM)
- */
void initialize4BitColors() {
Display display = getDialogShell().getDisplay();
@@ -330,10 +290,6 @@ void initialize4BitColors() {
colorGrid[7][0] = new Color(display, 128, 0, 128);
colorGrid[7][1] = new Color(display, 255, 0, 255);
}
-/**
- * Insert the method's description here.
- * Creation date: (7/6/99 5:07:09 PM)
- */
void initialize8BitColors() {
Display display = getDialogShell().getDisplay();
int numColumns = colorGrid.length;
@@ -366,8 +322,6 @@ void initialize8BitColors() {
void initializeWidgets() {
Display display = getDialogShell().getDisplay();
Color selectionColor;
- RGB rgb = getRGB();
-
if (rgb != null) {
selectionColor = new Color(display, rgb);
getSelectionCanvas().setBackground(selectionColor);
@@ -388,10 +342,6 @@ void installListeners() {
colorCanvas.addListener(SWT.MouseDown, listener);
colorCanvas.addListener(SWT.MouseMove, listener);
}
-/**
- * Insert the method's description here.
- * Creation date: (7/19/99 7:13:21 PM)
- */
void mouseDown(Event event) {
int swatchExtent = getColorSwatchExtent();
Color colorGrid[][] = getColorGrid();
@@ -400,10 +350,6 @@ void mouseDown(Event event) {
getSelectionCanvas().setBackground(color);
getSelectionText().setBackground(color);
}
-/**
- * Insert the method's description here.
- * Creation date: (7/19/99 7:13:21 PM)
- */
void mouseMove(Event event) {
int swatchExtent = getColorSwatchExtent();
Color colorGrid[][] = getColorGrid();
@@ -412,40 +358,41 @@ void mouseMove(Event event) {
getSampleCanvas().setBackground(color);
getSampleText().setBackground(color);
}
-/**
- * Makes the receiver visible and brings it to the front
- * of the display.
- *
- * @return the selected 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>
- */
+/**
+ * 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() {
Color selectionColor;
- RGB dialogResult = null;
Shell dialog = new Shell(getParent(), getStyle() | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
setDialogShell(dialog);
createChildren();
installListeners();
openModal();
+ rgb = null;
if (isOkSelected() == true) {
selectionColor = getSelectionCanvas().getBackground();
- dialogResult = new RGB(
+ rgb = new RGB(
selectionColor.getRed(),
selectionColor.getGreen(),
selectionColor.getBlue());
- setRGB(dialogResult);
}
disposeColors();
// Fix for 1G5NLY7
if (dialog.isDisposed() == false) {
dialog.dispose();
}
- return dialogResult;
+ return rgb;
}
void paint(Event event) {
Color colorGrid[][] = getColorGrid();
@@ -469,15 +416,17 @@ void setColorDepth(int bits) {
initialize8BitColors();
}
}
-/**
- * Returns the receiver's selected color to be the argument.
- *
- * @param rgb the new RGB value for the selected color
- *
- * @see PaletteData#getRGBs
+/**
+ * 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) {
- dialogResult = rgb;
+ this.rgb = rgb;
}
/**
* Create the widgets of the dialog.
@@ -521,12 +470,6 @@ Button getOKButton() {
return ok;
}
-
-/**
- * Insert the method's description here.
- * Creation date: (08/05/99 12:34:43)
- * @return boolean
- */
boolean isOkSelected() {
return okSelected;
}
@@ -563,7 +506,6 @@ void openModal() {
Display display = dialog.getDisplay();
initializeWidgets();
- setRGB(null);
openDialog();
while (dialog.isDisposed() == false && dialog.getVisible() == true) {
if (display.readAndDispatch() == false) {
@@ -572,12 +514,6 @@ void openModal() {
}
}
-
-/**
- * Insert the method's description here.
- * Creation date: (08/05/99 12:34:43)
- * @param newOkSelected boolean
- */
void setOkSelected(boolean newOkSelected) {
okSelected = newOkSelected;
}
@@ -588,6 +524,4 @@ void setDialogShell(Shell shell) {
this.shell = shell;
}
-
-
}
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 e1b66be8a7..1c3e81eaff 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
@@ -11,44 +11,44 @@ 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>
- * 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>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ * </p>
+ *
+ * @see List
+ */
public /*final*/ 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
- */
+ /**
+ * the operating system limit for the number of characters
+ * that the text field in an instance of this class can hold
+ */
public static int LIMIT;
/*
@@ -60,95 +60,93 @@ public /*final*/ class Combo extends Composite {
LIMIT = 0x7FFFFFFF;
}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * 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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, encodeString(string), true);
+ 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)
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if (index == -1) error (SWT.ERROR_INVALID_RANGE);
@@ -163,34 +161,33 @@ public void add (String string, int index) {
if (!(0 <= index && index <= argList [1])) {
error (SWT.ERROR_INVALID_RANGE);
}
- byte [] buffer = Converter.wcsToMbcs (null, encodeString(string), true);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Modify, typedListener);
@@ -220,8 +217,7 @@ public void addModifyListener (ModifyListener listener) {
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Selection,typedListener);
@@ -257,26 +253,25 @@ static int checkStyle (int 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
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int xDisplay = OS.XtDisplay (handle);
if (xDisplay == 0) return;
int [] argList = {OS.XmNtextField, 0};
@@ -285,8 +280,7 @@ public void clearSelection () {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {
OS.XmNlist, 0,
OS.XmNtextField, 0,
@@ -352,21 +346,20 @@ void createHandle (int index) {
handle = OS.XmCreateComboBox (formHandle, null, argList2, argList2.length / 2);
if (handle == 0) error (SWT.ERROR_NO_HANDLES);
}
-/**
- * Deselects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (index == -1) return;
int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
@@ -381,23 +374,22 @@ public void deselect (int index) {
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
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
Display display = getDisplay ();
@@ -410,28 +402,27 @@ public void deselectAll () {
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
if (!(0 <= index && index < argList [1])) {
@@ -455,45 +446,43 @@ public String getItem (int index) {
byte [] buffer = new byte [length];
OS.memmove (buffer, address, length);
OS.XtFree (address);
- return decodeString(new String (Converter.mbcsToWcs (null, buffer)));
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] listHandleArgs = {OS.XmNlist, 0};
OS.XtGetValues (handle, listHandleArgs, listHandleArgs.length / 2);
int [] argList = {OS.XmNlistSpacing, 0, OS.XmNhighlightThickness, 0};
@@ -502,33 +491,33 @@ public int getItemHeight () {
/* 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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];
@@ -545,28 +534,27 @@ public String [] getItems () {
byte [] buffer = new byte [length];
OS.memmove (buffer, address, length);
OS.XtFree (address);
- result[i] = decodeString(new String (Converter.mbcsToWcs (null, buffer)));
+ result[i] = decodeString(new String (Converter.mbcsToWcs (codePage, buffer)));
items += 4;
}
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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] start = new int [1], end = new int [1];
int [] argList = {OS.XmNtextField, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
@@ -576,21 +564,19 @@ 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
int [] argList = {OS.XmNlist, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
@@ -605,21 +591,19 @@ public int getSelectionIndex () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
int [] argList = {OS.XmNtextField, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
@@ -629,25 +613,23 @@ public String getText () {
byte [] buffer = new byte [length];
OS.memmove (buffer, ptr, length);
OS.XtFree (ptr);
- return decodeString(new String (Converter.mbcsToWcs (null, buffer)));
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
if ((style & SWT.DROP_DOWN) != 0) {
/*
* Bug in MOTIF. For some reason, XtQueryGeometry ()
@@ -679,23 +661,21 @@ public int getTextHeight () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
int [] argList = {OS.XmNtextField, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
return OS.XmTextGetMaxLength (argList[1]);
@@ -709,29 +689,28 @@ void hookEvents () {
OS.XtAddCallback (argList[1], OS.XmNactivateCallback, windowProc, SWT.DefaultSelection);
OS.XtAddCallback (argList[1], OS.XmNvalueChangedCallback, windowProc, SWT.Modify);
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, encodeString(string), true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
int xmString = OS.XmStringCreateLocalized (buffer);
if (xmString == 0) return -1;
@@ -742,33 +721,32 @@ public int indexOf (String string) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 (null, encodeString(string), true);
+ byte [] buffer1 = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
int xmString = OS.XmStringCreateLocalized (buffer1);
if (xmString == 0) return -1;
int index = start;
@@ -783,26 +761,38 @@ public int indexOf (String string, int start) {
if (index == itemCount) return -1;
return index;
}
-/**
- * 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>
+int processSelection (int callData) {
+ /*
+ * 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 (getSelectionIndex() == -1)
+ return 0;
+
+ return super.processSelection(callData);
+}
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (index == -1) error (SWT.ERROR_INVALID_RANGE);
/*
* Feature in Motif. An index out of range handled
@@ -817,28 +807,27 @@ public void remove (int index) {
}
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (start > end) return;
/*
* Feature in Motif. An index out of range handled
@@ -863,31 +852,30 @@ void register () {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, encodeString(string), true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
int xmString = OS.XmStringCreateLocalized (buffer);
if (xmString == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
@@ -899,17 +887,16 @@ public void remove (String string) {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0, OS.XmNitemCount, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
@@ -925,70 +912,67 @@ public void removeAll () {
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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (index == -1) {
int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
@@ -1013,35 +997,33 @@ public void select (int index) {
* Sets the widget bounds.
*/
public void setBounds (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int newHeight = ((style & SWT.DROP_DOWN) != 0) ? getTextHeight() : height;
super.setBounds (x, y, width, newHeight);
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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};
@@ -1049,7 +1031,7 @@ public void setItem (int index, String string) {
if (!(0 <= index && index < argList [3])) {
error (SWT.ERROR_INVALID_RANGE);
}
- byte [] buffer = Converter.wcsToMbcs (null, encodeString(string), true);
+ 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);
@@ -1057,22 +1039,21 @@ public void setItem (int index, String string) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
if (items.length == 0) {
@@ -1082,10 +1063,11 @@ public void setItems (String [] items) {
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 (null, encodeString(string), true);
+ byte [] buffer = Converter.wcsToMbcs (codePage, encodeString(string), true);
int xmString = OS.XmStringCreateLocalized (buffer);
if (xmString == 0) break;
table [index++] = xmString;
@@ -1098,25 +1080,24 @@ public void setItems (String [] items) {
OS.XtFree (ptr);
if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED);
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNtextField, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
@@ -1152,39 +1133,37 @@ public void setSelection (Point selection) {
* Sets the widget size.
*/
public void setSize (int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int newHeight = ((style & SWT.DROP_DOWN) != 0) ? getTextHeight () : height;
super.setSize (width, newHeight);
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.READ_ONLY) == 0) {
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
int xmString = OS.XmStringCreateLocalized (buffer);
if (xmString == 0) return;
int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
@@ -1208,26 +1187,25 @@ public void setText (String string) {
* it does not send a Modify to notify the application
* that the text has changed. The fix is to send the event.
*/
- if (IsLinux && (style & SWT.MULTI) != 0) sendEvent (SWT.Modify);
+ if (OS.IsLinux && (style & SWT.MULTI) != 0) sendEvent (SWT.Modify);
}
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
int [] argList = {OS.XmNtextField, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
@@ -1240,7 +1218,16 @@ void deregister () {
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
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 3b1441b524..b92a91e52c 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
@@ -9,23 +9,23 @@ import org.eclipse.swt.internal.motif.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
-/**
- * Instances of this class are controls which are capable
- * of containing other controls.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE</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 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</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 constructed from aggregates
+ * of other controls.
+ * </p>
+ *
+ * @see Canvas
+ */
public class Composite extends Scrollable {
Layout layout;
int damagedRegion;
@@ -33,34 +33,34 @@ public class Composite extends Scrollable {
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
- * 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
- */
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 Composite (Composite parent, int style) {
super (parent, style);
}
@@ -94,8 +94,7 @@ Control [] _getChildren () {
* Computes the preferred size.
*/
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Point size;
if (layout != null) {
if ((wHint == SWT.DEFAULT) || (hHint == SWT.DEFAULT)) {
@@ -186,8 +185,7 @@ int defaultForeground () {
return getDisplay ().compositeForeground;
}
public boolean forceFocus () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Control [] children = _getChildren ();
int [] traversals = new int [children.length];
int [] argList = new int [] {OS.XmNtraversalOn, 0};
@@ -204,24 +202,23 @@ public boolean forceFocus () {
}
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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return _getChildren ();
}
int getChildrenCount () {
@@ -230,20 +227,19 @@ int getChildrenCount () {
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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return layout;
}
@@ -255,44 +251,42 @@ void hookEvents () {
}
}
-/**
- * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (layout == null) return;
int count = getChildrenCount ();
if (count == 0) return;
@@ -496,20 +490,19 @@ public void setBounds (int x, int y, int width, int height) {
super.setBounds (x, y, width, height);
if (layout != null) layout (false);
}
-/**
- * Sets the layout which is associated with the receiver to be
- * the argument which may be null.
- *
- * @param 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
this.layout = layout;
}
public void setSize (int width, int height) {
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 af3b234aed..63fdccbc4d 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,9 +1,9 @@
package org.eclipse.swt.widgets;
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.motif.*;
@@ -11,21 +11,21 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
-/**
- * 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 {
Composite parent;
int fontList;
@@ -35,337 +35,327 @@ public abstract class Control extends Widget implements Drawable {
Control () {
/* Do nothing */
}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * 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
- */
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- * The <em>prefered 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
- */
+/**
+ * Returns the preferred size of the receiver.
+ * <p>
+ * The <em>prefered 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
+ */
public Point computeSize (int wHint, int hHint) {
return computeSize (wHint, hHint, true);
}
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>prefered 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
+/**
+ * Returns the preferred size of the receiver.
+ * <p>
+ * The <em>prefered 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
*/
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int width = DEFAULT_WIDTH;
int height = DEFAULT_HEIGHT;
if (wHint != SWT.DEFAULT) width = wHint;
@@ -379,29 +369,37 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
void createWidget (int index) {
super.createWidget (index);
- /*
- * 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 ();
+ /*
+ * 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.
+ */
+ 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 ();
}
/*
@@ -424,10 +422,6 @@ int defaultFont () {
int defaultForeground () {
return getDisplay ().defaultForeground;
}
-void enableHandle (boolean enabled, int widgetHandle) {
- int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
- OS.XtSetValues (widgetHandle, argList, argList.length / 2);
-}
void enableWidget (boolean enabled) {
enableHandle (enabled, handle);
}
@@ -445,40 +439,38 @@ char findMnemonic (String string) {
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
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Decorations shell = menuShell ();
shell.setSavedFocus (this);
shell.bringToTop ();
return OS.XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT);
}
-/**
- * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return Color.motif_new (getDisplay (), getXColor (getBackgroundPixel ()));
}
int getBackgroundPixel () {
@@ -486,38 +478,36 @@ int getBackgroundPixel () {
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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
@@ -531,54 +521,55 @@ Point getClientLocation () {
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]);
}
-/**
- * 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>
+String getCodePage () {
+ return Converter.getCodePage (OS.XtDisplay (handle), getFontList ());
+}
+/**
+ * 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return Font.motif_new (getDisplay (), getFontList ());
}
@@ -681,19 +672,18 @@ int getFontList () {
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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return Color.motif_new (getDisplay (), getXColor (getForegroundPixel ()));
}
int getForegroundPixel () {
@@ -701,75 +691,74 @@ int getForegroundPixel () {
OS.XtGetValues (handle, argList, argList.length / 2);
return argList [1];
}
-/**
- * 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>
- */
+short [] getIMECaretPos () {
+ 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent;
}
Control [] getPath () {
@@ -788,84 +777,80 @@ 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle = topHandle ();
int [] argList = {OS.XmNmappedWhenManaged, 0};
OS.XtGetValues (topHandle, argList, argList.length / 2);
@@ -899,29 +884,26 @@ void hookEvents () {
OS.XtAddEventHandler (handle, OS.FocusChangeMask, false, windowProc, SWT.FocusIn);
OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, SWT.Help);
}
-int inputContext () {
- return getShell ().inputContext ();
-}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!OS.XtIsRealized (handle)) {
- Shell shell = getShell ();
- shell.realizeWidget ();
+/**
+ * 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);
@@ -943,98 +925,95 @@ public int internal_new_GC (GCData data) {
}
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) {
- int xDisplay = 0;
- if (data != null) xDisplay = data.display;
+/**
+ * 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
- * <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 isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return false;
}
-/**
- * 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 isVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getVisible () && parent.isVisible ();
}
void manageChildren () {
@@ -1054,83 +1033,87 @@ boolean mnemonicHit () {
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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (control != null && control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (control != null && control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
}
int processDefaultSelection (int callData) {
@@ -1139,22 +1122,55 @@ int processDefaultSelection (int callData) {
}
int processFocusIn () {
sendEvent (SWT.FocusIn);
-// IsDBLocale ifTrue: [self killImeFocus].
+ // widget could be disposed at this point
+ if (handle == 0) return 0;
+ processIMEFocusIn ();
return 0;
}
int processFocusOut () {
sendEvent (SWT.FocusOut);
-// IsDBLocale ifTrue: [self killImeFocus].
+ // widget could be disposed at this point
+ if (handle == 0) return 0;
+ processIMEFocusOut ();
return 0;
}
int processHelp (int callData) {
sendHelpEvent (callData);
return 0;
}
+int processIMEFocusIn () {
+ if (!(hooks (SWT.KeyDown) || hooks (SWT.KeyUp))) return 0;
+ short [] point = getIMECaretPos ();
+ int ptr = OS.XtMalloc (4);
+ OS.memmove (ptr, point, 4);
+
+ /*
+ * Bug in Motif. On Linux Japanese only, XmImSetFocusValues will cause
+ * a GPF. The fix is to call XmImVaSetFocusValues instead.
+ */
+ OS.XmImVaSetFocusValues (handle,
+ OS.XmNforeground, getForegroundPixel(),
+ OS.XmNbackground, getBackgroundPixel(),
+ OS.XmNspotLocation, ptr,
+ OS.XmNfontList, getFontList(),
+ 0);
+
+ if (ptr != 0) OS.XtFree (ptr);
+ return 0;
+}
+int processIMEFocusOut () {
+ if (!(hooks (SWT.KeyDown) || hooks (SWT.KeyUp))) return 0;
+ OS.XmImUnsetFocus (handle);
+ return 0;
+}
int processKeyDown (int callData) {
XKeyEvent xEvent = new XKeyEvent ();
OS.memmove (xEvent, callData, XKeyEvent.sizeof);
- sendKeyEvent (SWT.KeyDown, xEvent);
+ if (xEvent.keycode != 0) {
+ sendKeyEvent (SWT.KeyDown, xEvent);
+ } else {
+ sendIMEKeyEvent (SWT.KeyDown, xEvent);
+ }
return 0;
}
int processKeyUp (int callData) {
@@ -1169,10 +1185,11 @@ int processModify (int callData) {
}
int processMouseDown (int callData) {
Display display = getDisplay ();
+ Shell shell = getShell ();
display.hideToolTip ();
XButtonEvent xEvent = new XButtonEvent ();
OS.memmove (xEvent, callData, XButtonEvent.sizeof);
- sendMouseEvent (SWT.MouseDown, xEvent.button, xEvent.state, xEvent);
+ sendMouseEvent (SWT.MouseDown, xEvent.button, xEvent);
if (xEvent.button == 2 && hooks (SWT.DragDetect)) {
sendEvent (SWT.DragDetect);
}
@@ -1184,11 +1201,20 @@ int processMouseDown (int callData) {
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.state, xEvent);
+ sendMouseEvent (SWT.MouseDoubleClick, eventButton, xEvent);
}
- if (eventTime == 0) eventTime = 1;
- display.lastTime = eventTime;
+ 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 processMouseEnter (int callData) {
@@ -1207,7 +1233,7 @@ int processMouseMove (int callData) {
display.addMouseHoverTimeOut (handle);
XMotionEvent xEvent = new XMotionEvent ();
OS.memmove (xEvent, callData, XMotionEvent.sizeof);
- sendMouseEvent (SWT.MouseMove, 0, xEvent.state, xEvent);
+ sendMouseEvent (SWT.MouseMove, 0, xEvent);
return 0;
}
int processMouseExit (int callData) {
@@ -1238,7 +1264,7 @@ int processMouseUp (int callData) {
display.hideToolTip ();
XButtonEvent xEvent = new XButtonEvent ();
OS.memmove (xEvent, callData, XButtonEvent.sizeof);
- sendMouseEvent (SWT.MouseUp, xEvent.button, xEvent.state, xEvent);
+ sendMouseEvent (SWT.MouseUp, xEvent.button, xEvent);
return 0;
}
int processPaint (int callData) {
@@ -1298,46 +1324,39 @@ int processSetFocus (int callData) {
/* Process the focus change for the widget */
switch (xEvent.type) {
case OS.FocusIn: {
+ Shell shell = getShell ();
processFocusIn ();
// widget could be disposed at this point
- if (handle == 0) return 0;
- int index = 0;
- Shell shell = getShell ();
- Control [] focusIn = getPath ();
- Control lastFocus = shell.lastFocus;
- if (lastFocus != null) {
- if (!lastFocus.isDisposed ()) {
- Control [] focusOut = lastFocus.getPath ();
- int length = Math.min (focusIn.length, focusOut.length);
- while (index < length) {
- if (focusIn [index] != focusOut [index]) break;
- index++;
- }
- for (int i=focusOut.length-1; i>=index; --i) {
- focusOut [i].sendEvent (SWT.Deactivate);
- }
- }
- shell.lastFocus = null;
- }
- for (int i=focusIn.length-1; i>=index; --i) {
- focusIn [i].sendEvent (SWT.Activate);
+
+ /*
+ * 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: {
- processFocusOut ();
- // widget could be disposed at this point
- if (handle == 0) return 0;
Shell shell = getShell ();
- shell.lastFocus = this;
Display display = getDisplay ();
- Control focusControl = display.getFocusControl ();
- if (focusControl == null || shell != focusControl.getShell ()) {
- Control [] focusOut = getPath ();
- for (int i=focusOut.length-1; i>=0; --i) {
- focusOut [i].sendEvent (SWT.Deactivate);
+
+ processFocusOut ();
+ // 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);
}
- shell.lastFocus = null;
}
break;
}
@@ -1347,89 +1366,56 @@ int processSetFocus (int callData) {
void propagateChildren (boolean enabled) {
propagateWidget (enabled);
}
-void propagateHandle (boolean enabled, int widgetHandle) {
- int xDisplay = OS.XtDisplay (widgetHandle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (widgetHandle);
- if (xWindow == 0) return;
- int event_mask = OS.XtBuildEventMask (widgetHandle);
- int do_not_propagate_mask = OS.KeyPressMask | OS.KeyReleaseMask | OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask;
- if (!enabled) {
- event_mask &= ~do_not_propagate_mask;
- 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);
- int [] argList = {OS.XmNtraversalOn, enabled ? 1 : 0};
- OS.XtSetValues (widgetHandle, argList, argList.length / 2);
-}
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
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (x == 0 && y == 0 && width == 0 && height == 0) return;
+ checkWidget ();
+ if (width <= 0 || height <= 0) return;
redrawWidget (x, y, width, height, all);
}
-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 redrawWidget (int x, int y, int width, int height, boolean all) {
redrawHandle (x, y, width, height, handle);
}
@@ -1442,247 +1428,219 @@ void releaseWidget () {
menu.dispose ();
}
menu = null;
-/*
- "Release the IME."
- self isMenu ifFalse: [
- handle xtIsWidget ifTrue: [
- handle xmImUnregister.
-
- "Bug in X. On Solaris only, destroying the window that has IME focus causes
- a segment fault. The fix is to set focus to the IME client window (typically
- the shell) when the receiver is being destroyed. Destroying the shell window
- does not have the problem. Note that this fix is not necessary on AIX."
- (xIC := self inputContext) == nil ifFalse: [
- (window := handle xtWindow) isNull ifFalse: [
- xIC xGetICValues: XNFocusWindow with: (buffer := ByteArray new: 4) with: 0.
- (buffer uint32At: 0) = window asInteger ifTrue: [
- xIC xGetICValues: XNClientWindow with: (buffer := ByteArray new: 4) with: 0.
- xIC
- xUnsetICFocus;
- xSetICValues: XNFocusWindow with: (buffer uint32At: 0) with: 0;
- xSetICFocus]]]]].
-*/
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+}/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Traverse, listener);
@@ -1697,104 +1655,81 @@ void sendHelpEvent (int callData) {
control = control.parent;
}
}
-void sendKeyEvent (int type, XKeyEvent xEvent) {
-
- /* Look up the keysym and character(s) */
- byte [] buffer;
- boolean isVirtual = false;
- int [] keysym = new int [1], status = new int [1];
- if (xEvent.keycode != 0) {
- buffer = new byte [1];
- isVirtual = OS.XLookupString (xEvent, buffer, buffer.length, keysym, status) == 0;
- } else {
- int size = 0;
- buffer = new byte [2];
- int xIC = inputContext ();
- if (xIC == 0) {
- size = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, keysym, status);
- if (status [0] == OS.XBufferOverflow) {
- buffer = new byte [size];
- size = OS.XmImMbLookupString (handle, xEvent, buffer, size, keysym, status);
- }
- } else {
- size = OS.XmbLookupString (xIC, xEvent, buffer, buffer.length, keysym, status);
- if (status [0] == OS.XBufferOverflow) {
- buffer = new byte [size];
- size = OS.XmbLookupString (xIC, xEvent, buffer, size, keysym, status);
- }
- }
- if (size == 0) return;
- }
-
+byte [] sendIMEKeyEvent (int type, XKeyEvent xEvent) {
/*
- * 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.
+ * 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.
*/
- if (IsSunOS) {
- if ((keysym [0] == 0x1005FF10) || (keysym [0] == 0x1005FF11)) {
- if (keysym [0] == 0x1005FF10) keysym [0] = OS.XK_F11;
- if (keysym [0] == 0x1005FF11) keysym [0] = OS.XK_F12;
- }
+ 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;
- /*
- * Bug in MOTIF. On Solaris only, their 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;
-
/* Convert from MBCS to UNICODE and send the event */
+ /* Use the character encoding for the default locale */
char [] result = Converter.mbcsToWcs (null, buffer);
- for (int i=0; i<result.length; i++) {
+ int index = 0;
+ while (index < result.length) {
+ if (result [index] == 0) break;
Event event = new Event ();
event.time = xEvent.time;
- event.character = result [i];
- if (isVirtual) event.keyCode = Display.translateKey (keysym [0]);
- if ((xEvent.state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
- if ((xEvent.state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
- if ((xEvent.state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
- if ((xEvent.state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
- if ((xEvent.state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
- if ((xEvent.state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
+ event.character = result [index];
+ setInputState (event, xEvent);
postEvent (type, event);
+ index++;
}
+ return buffer;
}
-void sendMouseEvent (int type, int button, int mask, XWindowEvent xEvent) {
+void sendKeyEvent (int type, XKeyEvent xEvent) {
+ Event event = new Event ();
+ event.time = xEvent.time;
+ setKeyState (event, xEvent);
+ postEvent (type,event);
+// 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, XInputEvent xEvent) {
Event event = new Event ();
event.time = xEvent.time;
event.button = button;
event.x = xEvent.x; event.y = xEvent.y;
- if ((mask & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
- if ((mask & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
- if ((mask & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
- if ((mask & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
- if ((mask & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
- if ((mask & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
+ 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (color == null) {
setBackgroundPixel (defaultBackground ());
} else {
- if (color.isDisposed ()) return;
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
setBackgroundPixel (color.handle.pixel);
}
}
@@ -1804,30 +1739,29 @@ void setBackgroundPixel (int pixel) {
OS.XmChangeColor (handle, pixel);
OS.XtSetValues (handle, argList, argList.length / 2);
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/*
* Feature in Motif. Motif will not allow a window
* to have a zero width or zero height. The fix is
@@ -1851,43 +1785,42 @@ public void setBounds (int x, int y, int width, int height) {
if (!sameOrigin) sendEvent (SWT.Move);
if (!sameExtent) sendEvent (SWT.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).
- * <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) {
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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int display = OS.XtDisplay (handle);
if (display == 0) return;
if (capture) {
@@ -1907,25 +1840,27 @@ public void setCapture (boolean capture) {
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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int display = OS.XtDisplay (handle);
if (display == 0) return;
int window = OS.XtWindow (handle);
@@ -1937,70 +1872,74 @@ public void setCursor (Cursor cursor) {
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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
enableWidget (enabled);
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
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Decorations shell = menuShell ();
shell.setSavedFocus (this);
shell.bringToTop ();
return OS.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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int fontList = 0;
- if (font != null) fontList = font.handle;
+ if (font != null) {
+ if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ fontList = font.handle;
+ }
if (fontList == 0) fontList = defaultFont ();
setFontList (fontList);
}
@@ -2025,25 +1964,27 @@ void setFontList (int fontList) {
/* 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (color == null) {
setForegroundPixel (defaultForeground ());
} else {
- if (color.isDisposed ()) return;
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
setForegroundPixel (color.handle.pixel);
}
}
@@ -2072,55 +2013,35 @@ void setGrabCursor (int cursor) {
XDisplay xChangeActivePointerGrab: eventMask cursor: aCursor time: CurrentTime.
*/
}
-void setKeyState (Event event, XKeyEvent xEvent) {
- if (xEvent.keycode != 0) {
- event.time = xEvent.time;
- byte [] buffer1 = new byte [1];
- int [] keysym = new int [1], status = new int [1];
- if (OS.XLookupString (xEvent, buffer1, buffer1.length, keysym, status) == 0) {
- event.keyCode = Display.translateKey (keysym [0] & 0xFFFF);
- } else {
- event.character = (char) buffer1 [0];
- }
- if ((xEvent.state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
- if ((xEvent.state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
- if ((xEvent.state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
- if ((xEvent.state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
- if ((xEvent.state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
- if ((xEvent.state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
- }
-}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle = topHandle ();
int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
OS.XtGetValues (topHandle, argList, argList.length / 2);
@@ -2129,45 +2050,46 @@ public void setLocation (int x, int y) {
OS.XtMoveWidget (topHandle, x, y);
if (!sameOrigin) sendEvent (SWT.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>
- */
+/**
+ * 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) {
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>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
}
@@ -2178,70 +2100,71 @@ 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-/**
- * 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>
- */
+ checkWidget();
+}
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/*
* Feature in Motif. Motif will not allow a window
* to have a zero width or zero height. The fix is
@@ -2257,64 +2180,62 @@ public void setSize (int width, int height) {
OS.XtResizeWidget (topHandle, newWidth, newHeight, argList [5]);
if (!sameExtent) sendEvent (SWT.Resize);
}
-/**
- * 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) {
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
setSize (size.x, size.y);
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
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>
- */
+/**
+ * Marks the receiver as visible if the argument is <code>true</code>,
+ * and marks it invisible otherwise.
+ * <p>
+ * If one of the receiver's ancestors is not visible or some
+ * other condition makes the receiver not visible, marking
+ * it visible may not actually cause it to be displayed.
+ * </p>
+ *
+ * @param visible the new visibility state
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ */
public void setVisible (boolean visible) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle = topHandle ();
int [] argList = {OS.XmNmappedWhenManaged, 0};
OS.XtGetValues (topHandle, argList, argList.length / 2);
@@ -2379,46 +2300,44 @@ void setZOrder (Control control, boolean above) {
if (parent != null) parent.moveBelow (topHandle1, topHandle2);
}
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 (point.x - root_x [0], point.y - 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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
short [] root_x = new short [1], root_y = new short [1];
OS.XtTranslateCoords (handle, (short) point.x, (short) point.y, root_x, root_y);
return new Point (root_x [0], root_y [0]);
@@ -2472,6 +2391,7 @@ boolean translateTraversal (int key, XKeyEvent xEvent) {
Event event = new Event();
event.doit = doit;
event.detail = detail;
+ event.time = xEvent.time;
setKeyState (event, xEvent);
sendEvent (SWT.Traverse, event);
doit = event.doit;
@@ -2506,24 +2426,23 @@ boolean traverseMnemonic (char key) {
if (!isVisible () || !isEnabled ()) return false;
return mnemonicMatch (key) && mnemonicHit ();
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (!isFocusControl () && !setFocus ()) return false;
switch (traversal) {
case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
@@ -2555,20 +2474,19 @@ boolean traverseReturn () {
button.click ();
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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int display = OS.XtDisplay (handle);
if (display == 0) return;
int window = OS.XtWindow (handle);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolBar.java
index 8b6bef2eb6..92c4eb637f 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolBar.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolBar.java
@@ -11,61 +11,61 @@ import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import java.util.*;
-/**
- * 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>
- */
+/**
+ * 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 /*final*/ class CoolBar extends Composite {
Vector rows;
Cursor hoverCursor;
Cursor dragCursor;
static final int ROW_SPACING = 2;
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * 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
- */
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 CoolBar (Composite parent, int style) {
super (parent, style);
}
@@ -73,8 +73,7 @@ protected void checkSubclass () {
if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int width = wHint, height = hHint;
if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
@@ -83,27 +82,26 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
if (hHint != SWT.DEFAULT) extent.y = hHint;
return extent;
}
-/**
- * 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 CoolItem getItem (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (index < 0) error (SWT.ERROR_INVALID_RANGE);
for (int i = 0; i < rows.size(); i++) {
Vector row = (Vector) rows.elementAt(i);
@@ -116,22 +114,21 @@ public CoolItem getItem (int index) {
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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int itemCount = 0;
for (int i = 0; i < rows.size(); i++) {
Vector row = (Vector) rows.elementAt(i);
@@ -139,28 +136,27 @@ public int getItemCount () {
}
return itemCount;
}
-/**
- * Returns an array of <code>CoolItems</code>s which are the
- * items in the receiver in the order those items were added.
- * <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>
- * @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>CoolItems</code>s which are the
+ * items in the receiver in the order those items were added.
+ * <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>
+ * @exception SWTError <ul>
+ * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
+ * </ul>
+ */
public CoolItem [] getItems () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
CoolItem [] result = new CoolItem [getItemCount()];
int index = 0;
for (int i = 0; i < rows.size(); i++) {
@@ -206,27 +202,28 @@ void hookEvents () {
int windowProc = getDisplay ().windowProc;
OS.XtAddEventHandler (handle, OS.ExposureMask, false, windowProc, SWT.Paint);
}
-/**
- * Searches the receiver's items, in the order they were
- * added, 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>
- */
+/**
+ * Searches the receiver's items, in the order they were
+ * added, starting at the first item (index 0) until an item
+ * is found that is equal to the argument, and returns the
+ * index of that item. If no item is found, returns -1.
+ *
+ * @param item the search item
+ * @return the index of the item
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the item is null</li>
+ * <li>ERROR_INVALID_ARGUMENT - if the item 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
int answer = 0;
for (int i = 0; i < rows.size(); i++) {
Vector row = (Vector) rows.elementAt(i);
@@ -454,6 +451,13 @@ int processPaint (int callData) {
gc.dispose();
return 0;
}
+void propagateWidget (boolean enabled) {
+ super.propagateWidget (enabled);
+ CoolItem [] items = getItems ();
+ for (int i=0; i<items.length; i++) {
+ items [i].propagateWidget (enabled);
+ }
+}
/**
* Remove the item from the row. Adjust the x and width values
* appropriately.
@@ -551,6 +555,13 @@ void relayout() {
Point size = layout(getSize().x, true);
super.setSize(size.x, size.y);
}
+void setBackgroundPixel (int pixel) {
+ super.setBackgroundPixel (pixel);
+ CoolItem[] items = getItems ();
+ for (int i = 0; i < items.length; i++) {
+ items[i].setBackgroundPixel (pixel);
+ }
+}
public void setBounds (int x, int y, int width, int height) {
super.setBounds (x, y, width, height);
layout(width, true);
@@ -569,30 +580,29 @@ CoolItem getChild (int id) {
}
return null;
}
-/**
- * Returns an array of zero-relative indices which map the order
- * that the items in the receiver were added in (which is the
- * order that they are returned by <code>getItems()</code>) to
- * the order 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 item 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>
- */
+/**
+ * Returns an array of zero-relative indices which map the order
+ * that the items in the receiver were added in (which is the
+ * order that they are returned by <code>getItems()</code>) to
+ * the order 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 item 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[] getItemOrder () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
CoolItem[] items = getItems();
int[] ids = new int[items.length];
for (int i = 0; i < items.length; i++) {
@@ -613,21 +623,20 @@ void setItemOrder (int[] itemOrder) {
rows = new Vector(1);
rows.addElement(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 the items were added.
- *
- * @return the receiver's item sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 of points whose x and y coordinates describe
+ * the widths and heights (respectively) of the items in the receiver
+ * in the order the items were added.
+ *
+ * @return the receiver's item sizes
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
CoolItem[] items = getItems();
Point[] sizes = new Point[items.length];
for (int i = 0; i < items.length; i++) {
@@ -644,21 +653,20 @@ void setItemSizes (Point[] sizes) {
items[i].setBounds(bounds.x, bounds.y, sizes[i].x, sizes[i].y);
}
}
-/**
- * Returns an array of ints which describe the zero-relative
- * row number of the row which each of the items in the
- * receiver occurs in, in the order the items were added.
- *
- * @return the receiver's wrap indices
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 of ints which describe the zero-relative
+ * row number of the row which each of the items in the
+ * receiver occurs in, in the order the items were added.
+ *
+ * @return the receiver's wrap indices
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int[] data = new int[rows.size() - 1];
int itemIndex = 0;
for (int i = 0; i < rows.size() - 1; i++) {
@@ -668,22 +676,21 @@ public int[] getWrapIndices () {
}
return data;
}
-/**
- * Sets the row that each of the receiver's items will be
- * displayed in to the given array of ints which describe
- * the zero-relative row number of the row for each item
- * in the order the items were added.
- *
- * @param indices the new wrap indices
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 row that each of the receiver's items will be
+ * displayed in to the given array of ints which describe
+ * the zero-relative row number of the row for each item
+ * in the order the items were added.
+ *
+ * @param indices the new wrap indices
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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[] data) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (data == null) error(SWT.ERROR_NULL_ARGUMENT);
CoolItem[] items = getItems();
rows = new Vector(5);
@@ -705,23 +712,22 @@ public void setWrapIndices (int[] data) {
rows.addElement(row);
relayout();
}
-/**
- * Sets the receiver's item order, wrap indices, and item
- * sizes at once. This equivalent to calling the setter
- * methods for each of these values individually.
- *
- * @param itemOrder the new item order
- * @param wrapIndices the new wrap indices
- * @param size the new item sizes
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 item order, wrap indices, and item
+ * sizes at once. This equivalent to calling the setter
+ * methods for each of these values individually.
+ *
+ * @param itemOrder the new item order
+ * @param wrapIndices the new wrap indices
+ * @param size the new item sizes
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setItemOrder(itemOrder);
setWrapIndices(wrapIndices);
setItemSizes(sizes);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolItem.java
index cbd77e60ab..c606b19cef 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/CoolItem.java
@@ -10,20 +10,20 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.*;
import org.eclipse.swt.internal.motif.*;
-/**
- * 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>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
+/**
+ * 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>(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 /*final*/ class CoolItem extends Item {
Control control;
CoolBar parent;
@@ -39,72 +39,72 @@ public /*final*/ class CoolItem extends Item {
static final int GRABBER_WIDTH = 2;
static final int MINIMUM_WIDTH = (2 * MARGIN_WIDTH) + GRABBER_WIDTH;
-/**
- * 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
- * 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
- */
+/**
+ * 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
+ * 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 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
- * 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
- */
+/**
+ * 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
+ * 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 CoolItem (CoolBar parent, int style, int index) {
super(parent, style);
this.parent = parent;
@@ -113,31 +113,30 @@ public CoolItem (CoolBar parent, int style, int index) {
protected void checkSubclass () {
if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
}
-/**
- * Returns the preferred size of the receiver.
- * <p>
- * The <em>prefered 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
- */
+/**
+ * Returns the preferred size of the receiver.
+ * <p>
+ * The <em>prefered 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
+ */
public Point computeSize (int wHint, int hHint) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (preferredWidth > -1) return new Point(preferredWidth, preferredHeight);
int width = MINIMUM_WIDTH;
int height = DEFAULT_HEIGHT;
@@ -157,44 +156,44 @@ void createHandle (int index) {
int parentHandle = parent.handle;
handle = OS.XmCreateDrawingArea(parentHandle, null, argList, argList.length / 2);
if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ int pixel = parent.getBackgroundPixel ();
+ setBackgroundPixel (pixel);
}
public void dispose () {
- if (!isValidWidget ()) return;
+ if (isDisposed()) return;
CoolBar 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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]);
}
-/**
- * Gets the control which is associated with the receiver.
- *
- * @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>
- */
+/**
+ * Gets the control which is associated with the receiver.
+ *
+ * @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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return control;
}
public Display getDisplay () {
@@ -207,19 +206,18 @@ Rectangle getGrabberArea () {
OS.XtGetValues (handle, argList, argList.length / 2);
return new Rectangle(0, 0, MINIMUM_WIDTH, argList[1]);
}
-/**
- * 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent;
}
Point getSize () {
@@ -239,6 +237,7 @@ void manageChildren () {
OS.XtManageChild (handle);
}
int processMouseDown (int callData) {
+ Shell shell = parent.getShell();
XButtonEvent xEvent = new XButtonEvent ();
OS.memmove (xEvent, callData, XButtonEvent.sizeof);
if (getGrabberArea().contains(xEvent.x, xEvent.y)) {
@@ -246,6 +245,15 @@ int processMouseDown (int callData) {
mouseXOffset = xEvent.x;
parent.setCursor(parent.dragCursor);
}
+ /*
+ * 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 processMouseExit (int callData) {
@@ -326,22 +334,36 @@ int processPaint (int callData) {
OS.XFreeGC(xDisplay, xGC);
return 0;
}
-/**
- * Sets the control which is associated with the receiver
- * to the argument.
- *
- * @param control the new 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 propagateWidget (boolean enabled) {
+ propagateHandle (enabled, handle);
+ /*
+ * CoolItems never participate in focus traversal when
+ * either enabled or disabled.
+ */
+ if (enabled) {
+ int [] argList = {OS.XmNtraversalOn, 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+}
+/**
+ * Sets the control which is associated with the receiver
+ * to the argument.
+ *
+ * @param control the new control
+ *
+ * @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 setControl (Control control) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (control != null && control.parent != parent) {
- error (SWT.ERROR_INVALID_PARENT);
+ checkWidget();
+ if (control != null) {
+ if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
}
Control oldControl = this.control;
if (oldControl != null) oldControl.setVisible(false);
@@ -367,8 +389,7 @@ public void setControl (Control control) {
}
}
public void setSize (int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
width = Math.max (width, MINIMUM_WIDTH);
height = Math.max (height, DEFAULT_HEIGHT);
OS.XtResizeWidget (handle, width, height, 0);
@@ -407,6 +428,12 @@ public void setSize (Point size) {
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
setSize (size.x, size.y);
}
+void setBackgroundPixel(int pixel) {
+ int [] argList = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
+ OS.XtGetValues (handle, argList, argList.length / 2);
+ OS.XmChangeColor (handle, pixel);
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
void setBounds (int x, int y, int width, int height) {
/*
* Feature in Motif. Motif will not allow a window
@@ -425,13 +452,11 @@ void setBounds (int x, int y, int width, int height) {
}
}
public Point getPreferredSize () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return new Point(preferredWidth, preferredHeight);
}
public void setPreferredSize (int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
preferredWidth = Math.max (width, MINIMUM_WIDTH);
preferredHeight = Math.max (height, DEFAULT_HEIGHT);
OS.XtResizeWidget (handle, preferredWidth, preferredHeight, 0);
@@ -442,6 +467,7 @@ public void setPreferredSize (int width, int height) {
}
}
public void setPreferredSize (Point size) {
+ if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
setPreferredSize(size.x, size.y);
}
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 d9af52cec6..da77360e53 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
@@ -9,78 +9,78 @@ import org.eclipse.swt.internal.motif.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
-/**
- * Instances of this class provide the appearance and
- * behavior of <code>Shells</code>, but are not top
- * level shells or dialogs. Class <code>Shell</code>
- * shares a significant amount of code with this class,
- * and is a subclass.
- * <p>
- * 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</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
- */
+/**
+ * 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</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>(none)</dd>
+ * </dl>
+ * Class <code>SWT</code> provides two "convenience constants"
+ * for the most commonly required style combinations:
+ * <dl>
+ * <dt><code>SHELL_TRIM</code></dt>
+ * <dd>
+ * the result of combining the constants which are required
+ * to produce a typical application top level shell: (that
+ * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>)
+ * </dd>
+ * <dt><code>DIALOG_TRIM</code></dt>
+ * <dd>
+ * the result of combining the constants which are required
+ * to produce a typical application dialog shell: (that
+ * is, <code>TITLE | CLOSE | BORDER</code>)
+ * </dd>
+ * </dl>
+ * <p>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation.
+ * </p>
+ *
+ * @see #getMinimized
+ * @see #getMaximized
+ * @see Shell
+ * @see SWT
+ */
public class Decorations extends Canvas {
String label;
Image image;
@@ -93,33 +93,33 @@ public class Decorations extends Canvas {
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
- * 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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 Decorations (Composite parent, int style) {
super (parent, checkStyle (style));
@@ -162,8 +162,7 @@ protected void checkSubclass () {
if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
}
public Rectangle computeTrim (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Rectangle trim = super.computeTrim (x, y, width, height);
if (menuBar != null) {
XtWidgetGeometry request = new XtWidgetGeometry ();
@@ -187,123 +186,117 @@ 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
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return label;
}
Decorations menuShell () {
@@ -344,32 +337,35 @@ void remove (Menu menu) {
}
}
}
-/**
- * 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setDefaultButton (button, true);
}
void setDefaultButton (Button button, boolean save) {
if (button == null) {
if (defaultButton == saveDefault) return;
} else {
+ if (button.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
if ((button.style & SWT.PUSH) == 0) return;
if (button == defaultButton) return;
}
@@ -383,25 +379,28 @@ void setDefaultButton (Button button, boolean save) {
if (save || saveDefault == null) 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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. 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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;
@@ -422,50 +421,52 @@ public void setImage (Image image) {
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
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
this.maximized = maximized;
}
-/**
- * Sets the receiver's menu bar to the argument, which
- * may be null.
- *
- * @param menu the new menu bar
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
}
@@ -518,56 +519,54 @@ public void setMenuBar (Menu menu) {
OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]);
}
}
-/**
- * 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
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
label = string;
}
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 2543e841c1..7b1b05beb8 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
@@ -9,74 +9,74 @@ 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>
+/**
+ * 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 /*final*/ 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>
- */
+/**
+ * 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
- * for all SWT dialog classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </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>
- */
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 dialog classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </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);
}
@@ -85,36 +85,37 @@ int activate (int widget, int client, int call) {
OS.XtUnmanageChild (widget);
return 0;
}
-/**
- * Returns the path which the receiver will use to filter
- * the directories it shows.
- *
- * @return the filter path
- */
+/**
+ * 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 receiver's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the receiver while it is open.
- *
- * @return the message
- */
+/**
+ * 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 receiver visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the selected directory
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
+/**
+ * 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 */
@@ -125,6 +126,7 @@ public String open () {
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
@@ -133,6 +135,8 @@ public String open () {
*/
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,
@@ -142,7 +146,9 @@ public String open () {
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,
@@ -155,6 +161,7 @@ public String open () {
/* 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,
@@ -165,6 +172,7 @@ public String open () {
0,
0);
+ /* Use the character encoding for the default locale */
byte [] buffer7 = Converter.wcsToMbcs (null, "Selection", true);
int xmStringPtr4 = OS.XmStringParseText (
buffer7,
@@ -174,6 +182,7 @@ public String open () {
null,
0,
0);
+
/* Create the dialog */
int [] argList1 = {
OS.XmNresizePolicy, OS.XmRESIZE_NONE,
@@ -184,6 +193,7 @@ public String open () {
OS.XmNdirectory, xmStringPtr3,
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
@@ -211,6 +221,7 @@ public String open () {
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 [] parseTable = Display.getDefault ().parseTable;
int xmString1 = OS.XmStringParseText (
@@ -261,6 +272,7 @@ public String open () {
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);
@@ -288,23 +300,23 @@ public String open () {
if (cancel) return null;
return directoryPath;
}
-/**
- * Sets the path which the receiver will use to filter
- * the directories it shows to the argument, which may be
- * null.
- *
- * @param string the filter path
- */
+/**
+ * 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 receiver's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the receiver while it is open.
- *
- * @param string the message
- */
+/**
+ * Sets the dialog's message, which is a description of
+ * the purpose for which it was opened. This message will be
+ * visible on the dialog while it is open.
+ *
+ * @param string the message
+ */
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 84a51131ea..e4c765dca1 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
@@ -10,76 +10,76 @@ import org.eclipse.swt.internal.motif.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
-/**
- * Instances of this class are responsible for managing the
- * connection between SWT and the underlying operating
- * system. Their most important function is to implement
- * the SWT event loop in terms of the platform event model.
- * They also provide various methods for accessing information
- * about the operating system, and have overall control over
- * the operating system resources which SWT allocates.
- * <p>
- * Applications which are built with SWT will <em>almost always</em>
- * require only a single display. In particular, some platforms
- * which SWT supports will not allow more than one <em>active</em>
- * display. In other words, some platforms do not support
- * creating a new display if one already exists that has not been
- * sent the <code>dispose()</code> message.
- * <p>
- * In SWT, the thread which creates a <code>Display</code>
- * instance is distinguished as the <em>user-interface thread</em>
- * for that display.
- * </p>
- * The user-interface thread for a particular display has the
- * following special attributes:
- * <ul>
- * <li>
- * The event loop for that display must be run from the thread.
- * </li>
- * <li>
- * Some SWT API methods (notably, most of the public methods in
- * <code>Widget</code> and its subclasses), may only be called
- * from the thread. (To support multi-threaded user-interface
- * applications, class <code>Display</code> provides inter-thread
- * communication methods which allow threads other than the
- * user-interface thread to request that it perform operations
- * on their behalf.)
- * </li>
- * <li>
- * The thread is not allowed to construct other
- * <code>Display</code>s until that display has been disposed.
- * (Note that, this is in addition to the restriction mentioned
- * above concerning platform support for multiple displays. Thus,
- * the only way to have multiple simultaneously active displays,
- * even on platforms which support it, is to have multiple threads.)
- * </li>
- * </ul>
- * Enforcing these attributes allows SWT to be implemented directly
- * on the underlying operating system's event model. This has
- * numerous benefits including smaller footprint, better use of
- * resources, safer memory management, clearer program logic,
- * better performance, and fewer overall operating system threads
- * required. The down side however, is that care must be taken
- * (only) when constructing multi-threaded applications to use the
- * inter-thread communication mechanisms which this class provides
- * when required.
- * </p><p>
- * All SWT API methods which may only be called from the user-interface
- * thread are distinguished in their documentation by indicating that
- * they throw the "<code>ERROR_THREAD_INVALID_ACCESS</code>"
- * SWT exception.
- * </p><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 {
+/**
+ * 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><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 {
/* Motif Only Public Fields */
public XAnyEvent xEvent = new XAnyEvent ();
@@ -234,15 +234,15 @@ public class Display extends Device {
int checkExposeProc;
int exposeCount;
- /* Wake */
- Callback wakeCallback;
- int wakeProc, read_fd, write_fd, inputID;
- byte [] wake_buffer = new byte [1];
+ /* Wake */
+ Callback wakeCallback;
+ int wakeProc, read_fd, write_fd, inputID;
+ byte [] wake_buffer = new byte [1];
/* Display Data */
Object data;
String [] keys;
- Object [] values;
+ Object [] values;
static final byte[] _MOTIF_DEFAULT_LOCALE = Converter.wcsToMbcs(null, "_MOTIF_DEFAULT_LOCALE");
@@ -270,25 +270,25 @@ 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);
}
@@ -315,25 +315,25 @@ void addMouseHoverTimeOut (int handle) {
mouseHoverID = OS.XtAppAddTimeOut (xtContext, 400, mouseHoverProc, 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 () {
checkDevice ();
OS.XBell (xDisplay, 100);
@@ -375,7 +375,7 @@ protected void checkSubclass () {
}
protected void create (DeviceData data) {
checkSubclass ();
- checkDisplay ();
+ checkDisplay ();
thread = Thread.currentThread ();
createDisplay (data);
register ();
@@ -419,6 +419,7 @@ void createDisplay (DeviceData data) {
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);
@@ -440,18 +441,18 @@ protected void destroy () {
void destroyDisplay () {
/*
* Destroy AppContext (this destroys the display)
- */
+ */
int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- OS.XtDestroyApplicationContext (xtContext);
+ 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.
- */
+/**
+ * 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];
@@ -473,7 +474,7 @@ boolean filterEvent (XAnyEvent event) {
/* Check the event and find the widget */
if (event.type != OS.KeyPress) return false;
- if (OS.XFilterEvent(event, OS.None)) return true;
+ if (!OS.IsLinux && OS.XFilterEvent(event, OS.None)) return true;
XKeyEvent keyEvent = new XKeyEvent ();
/* Move the any event into the key event */
@@ -519,58 +520,58 @@ boolean filterEvent (XAnyEvent event) {
/* 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>
- */
+/**
+ * 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 ();
Control control = getFocusControl ();
if (control == null) return null;
return control.getShell ();
}
-/**
- * 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 () {
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
- */
+/**
+ * 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];
@@ -580,17 +581,17 @@ public static synchronized Display findDisplay (Thread thread) {
}
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 ();
int [] unused = new int [1], buffer = new int [1];
@@ -612,16 +613,16 @@ public Control getCursorControl () {
} 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>
- */
+/**
+ * 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 ();
int window = OS.XDefaultRootWindow (xDisplay);
@@ -631,41 +632,41 @@ public Point getCursorLocation () {
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
- */
+/**
+ * Returns the default display. One is created (making the
+ * thread that invokes this method its user-interface thread)
+ * if it did not already exist.
+ *
+ * @return the default display
+ */
public static synchronized Display getDefault () {
if (Default == null) Default = new Display ();
return Default;
}
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility 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 ();
if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
@@ -675,59 +676,59 @@ 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 ();
return data;
}
-/**
- * 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 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>
- */
+/**
+ * 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 ();
int [] buffer1 = new int [1], buffer2 = new int [1];
@@ -747,30 +748,30 @@ public Control getFocusControl () {
} 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>
- */
+/**
+ * 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 () {
return getDepth ();
}
-/**
- * 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 ();
/*
@@ -798,38 +799,38 @@ 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 ();
@@ -860,35 +861,35 @@ public Color getSystemColor (int 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>
- */
+/**
+ * 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.motif_new (this, defaultFontList);
}
-/**
- * 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);
return thread;
@@ -1070,16 +1071,16 @@ void initializeDisplay () {
checkExposeCallback = new Callback (this, "checkExposeProc", 3);
checkExposeProc = checkExposeCallback.getAddress ();
if (checkExposeProc == 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 xtAppContext = OS.XtDisplayToApplicationContext (xDisplay);
- inputID = OS.XtAppAddInput (xtAppContext, read_fd, OS.XtInputReadMask, wakeProc, 0);
+ 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 xtAppContext = OS.XtDisplayToApplicationContext (xDisplay);
+ inputID = OS.XtAppAddInput (xtAppContext, read_fd, OS.XtInputReadMask, wakeProc, 0);
/*
* Use dynamic Drag and Drop Protocol styles.
@@ -1268,22 +1269,23 @@ void initializeTranslations () {
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
- */
+/**
+ * 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);
@@ -1297,21 +1299,21 @@ public int internal_new_GC (GCData data) {
}
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
- */
+/**
+ * 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);
}
@@ -1350,44 +1352,44 @@ 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 ();
int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
int status = OS.XtAppPending (xtContext);
- if (status != 0) {
+ if (status != 0) {
if ((status & OS.XtIMTimer) != 0) {
OS.XtAppProcessEvent (xtContext, OS.XtIMTimer);
- }
- if ((status & OS.XtIMAlternateInput) != 0) {
- OS.XtAppProcessEvent (xtContext, OS.XtIMAlternateInput);
-// runAsyncMessages ();
+ status = OS.XtAppPending (xtContext);
+ }
+ if ((status & OS.XtIMAlternateInput) != 0) {
+ OS.XtAppProcessEvent (xtContext, OS.XtIMAlternateInput);
+ status = OS.XtAppPending (xtContext);
}
- if ((status & OS.XtIMXEvent) != 0) {
+ if ((status & OS.XtIMXEvent) != 0) {
OS.XtAppNextEvent (xtContext, xEvent);
- if (filterEvent (xEvent)) return false;
- OS.XtDispatchEvent (xEvent);
+ if (!filterEvent (xEvent)) OS.XtDispatchEvent (xEvent);
}
runDeferredEvents ();
return true;
@@ -1429,15 +1431,15 @@ protected void release () {
/* Release synchronizer */
synchronizer.releaseSynchronizer ();
synchronizer = null;
- releaseDisplay ();
-
+ releaseDisplay ();
+
super.release ();
}
-void releaseDisplay () {
-
- /* Destroy the hidden Override shell parent */
- if (shellHandle != 0) OS.XtDestroyWidget (shellHandle);
- shellHandle = 0;
+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);
@@ -1457,7 +1459,7 @@ void releaseDisplay () {
timerCallback.dispose ();
timerCallback = null;
- /* Dispose the mouse hover callback */
+ /* Dispose the mouse hover callback */
if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID);
mouseHoverID = mouseHoverProc = mouseHoverHandle = toolTipHandle = 0;
mouseHoverCallback.dispose ();
@@ -1467,13 +1469,13 @@ void releaseDisplay () {
windowCallback.dispose (); windowCallback = null;
checkExposeCallback.dispose (); checkExposeCallback = null;
checkExposeProc = 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);
+
+ /* 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 != 0) OS.XmFontListFree (buttonFont);
@@ -1554,13 +1556,13 @@ boolean runDeferredEvents () {
eventQueue = null;
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;
}
@@ -1574,30 +1576,30 @@ void setCurrentCaret (Caret caret) {
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
- */
+/**
+ * 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);
@@ -1645,45 +1647,45 @@ public void setData (String key, Object 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
- */
+/**
+ * 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 ();
if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT);
@@ -1693,115 +1695,105 @@ public void setSynchronizer (Synchronizer synchronizer) {
this.synchronizer = synchronizer;
}
void showToolTip (int handle, String toolTipText) {
- if (toolTipText == null || toolTipText.length() == 0 || toolTipHandle != 0) {
+ if (toolTipText == null || toolTipText.length () == 0 || toolTipHandle != 0) {
return;
}
- /* Create the tooltip widgets */
+ /* Create the shell and tool tip widget */
int widgetClass = OS.OverrideShellWidgetClass ();
int [] argList1 = {OS.XmNmwmDecorations, 0, OS.XmNborderWidth, 1};
int shellHandle = OS.XtCreatePopupShell (null, widgetClass, handle, argList1, argList1.length / 2);
- toolTipHandle = OS.XmCreateLabel(shellHandle, null, null, 0);
-
- /* Set the tooltip foreground and background */
- Color infoForeground = getSystemColor(SWT.COLOR_INFO_FOREGROUND);
- Color infoBackground = getSystemColor(SWT.COLOR_INFO_BACKGROUND);
- int foregroundPixel = (infoForeground == null) ? defaultForeground : infoForeground.handle.pixel;
- int backgroundPixel = (infoBackground == null) ? defaultBackground : infoBackground.handle.pixel;
- int [] argList2 = {OS.XmNforeground, foregroundPixel, OS.XmNbackground, backgroundPixel};
- OS.XtSetValues (toolTipHandle, argList2, argList2.length / 2);
- OS.XtManageChild (toolTipHandle);
-
- /* Set the tooltip label string */
+ Color infoForeground = getSystemColor (SWT.COLOR_INFO_FOREGROUND);
+ Color infoBackground = getSystemColor (SWT.COLOR_INFO_BACKGROUND);
+ int foregroundPixel = infoForeground.handle.pixel;
+ int backgroundPixel = infoBackground.handle.pixel;
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs (null, toolTipText, true);
- int xmString = OS.XmStringParseText (
- buffer,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- int [] argList3 = {OS.XmNlabelString, xmString};
- OS.XtSetValues (toolTipHandle, argList3, argList3.length / 2);
- if (xmString != 0) OS.XmStringFree (xmString);
+ 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);
/*
* 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];
- OS.XQueryPointer (xDisplay, xWindow, unused, unused, rootX, rootY, unused, unused, unused);
- int x = rootX [0] + 16, y = rootY [0] + 16;
-
- /*
- * Ensure that the tooltip 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 xWindow = OS.XDefaultRootWindow (xDisplay);
+ int [] rootX = new int [1], rootY = new int [1], unused = new int [1];
+ OS.XQueryPointer (xDisplay, xWindow, unused, unused, rootX, rootY, unused, unused, unused);
+ 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);
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
- */
+/**
+ * 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 ();
int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
return OS.XtAppPeekEvent (xtContext, xEvent);
}
-/**
- * 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.
- *
- * @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.
+ *
+ * @see #asyncExec
+ */
public void syncExec (Runnable runnable) {
if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
synchronizer.syncExec (runnable);
}
int textWidth (String string, int fontList) {
if (string.length () == 0) return 0;
- byte [] textBuffer = Converter.wcsToMbcs (null, string, true);
+ String codePage = Converter.getCodePage (xDisplay, fontList);
+ byte [] textBuffer = Converter.wcsToMbcs (codePage, string, true);
int xmString = OS.XmStringGenerate (textBuffer, null, OS.XmCHARSET_TEXT, _MOTIF_DEFAULT_LOCALE);
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.
- *
- * @param milliseconds the delay before running the runnable
- * @param runnable code to run on the user-interface thread
- *
- * @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.
+ *
+ * @param milliseconds the delay before running the runnable
+ * @param runnable code to run on the user-interface thread
+ *
+ * @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 (timerList == null) timerList = new Runnable [4];
@@ -1857,22 +1849,22 @@ public void update () {
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
- */
+/**
+ * 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);
- /* Write a single byte to the wake up pipe */
+ if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
+ /* 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 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 windowProc (int handle, int clientData, int callData, int unused) {
Widget widget = WidgetTable.get (handle);
@@ -1910,9 +1902,10 @@ String wrapText (String text, int fontList, int width) {
}
if (lineWidth > width) {
if (lastStart == wordStart) {
- line = text.substring (lineStart, wordStart + 1);
- lineWidth = textWidth (line, fontList);
- while (wordStart < wordEnd && lineWidth < width) {
+ while (wordStart < wordEnd) {
+ line = text.substring (lineStart, wordStart + 1);
+ lineWidth = textWidth (line, fontList);
+ if (lineWidth >= width) break;
wordStart++;
}
if (wordStart == lastStart) wordStart++;
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 8603df10fd..fddf8d944c 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
@@ -9,55 +9,229 @@ 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>
+/**
+ * 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 /*final*/ class FileDialog extends Dialog {
+ int dialog;
String [] filterNames = new String [0];
String [] filterExtensions = new String [0];
String filterPath = "";
String fullPath = "";
String fileName = "";
- boolean cancel = true;
+ 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);
}
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 dialog classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </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);
}
-int activate (int widget, int client, int call) {
- cancel = client == OS.XmDIALOG_CANCEL_BUTTON;
+
+int cancelPressed (int widget, int client, int call) {
+ cancel = true;
OS.XtUnmanageChild (widget);
return 0;
}
+void extractValues() {
+ filterPath = fullPath = "";
+ int [] argList2 = {OS.XmNdirectory, 0, OS.XmNdirSpec, 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 */
+ filterPath = new String (Converter.mbcsToWcs (null, buffer));
+ }
+ OS.XmStringFree (xmString3);
+
+ int xmString4 = argList2 [3];
+ ptr = OS.XmStringUnparse (
+ xmString4,
+ 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));
+ }
+ OS.XmStringFree (xmString4);
+
+ int length = filterPath.length ();
+ if (length != 0 && filterPath.charAt (length - 1) == '/') {
+ filterPath = filterPath.substring (0, length - 1);
+ int index = fullPath.lastIndexOf ('/');
+ fileName = fullPath.substring (index + 1, fullPath.length ());
+ }
+}
+/**
+ * Returns the path of the first file that was
+ * selected in the dialog relative to the filter path,
+ * or null if none is available.
+ *
+ * @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};
}
+
+/**
+ * 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 path which the dialog will use to filter
+ * the files it shows.
+ *
+ * @return the filter path
+ */
public String getFilterPath () {
return filterPath;
}
+
+int okPressed (int widget, int client, int call) {
+ extractValues();
+
+ // preferred case, a file is selected
+ if (!fileName.equals("")) {
+ OS.XtUnmanageChild (widget);
+ return 0;
+ }
+
+ // no file selected, so go into the current directory
+ 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;
+}
+
+/**
+ * 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 */
@@ -77,6 +251,7 @@ public String open () {
*/
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,
@@ -100,6 +275,7 @@ public String open () {
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,
@@ -112,6 +288,7 @@ public String open () {
/* 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,
@@ -138,7 +315,7 @@ public String open () {
* 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);
+ 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);
@@ -168,13 +345,13 @@ public String open () {
*/
/* 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);
+ 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);
- /* Open the dialog and dispatch events. */
- cancel = true;
/*
shell == nil ifFalse: [
shell minimized ifTrue: [shell minimized: false]].
@@ -185,59 +362,11 @@ public String open () {
while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
if (!appContext.readAndDispatch ()) appContext.sleep ();
- /* Set the new path, file name and filter. */
- fullPath = "";
- if (!cancel) {
- filterPath = fullPath = "";
- int [] argList2 = {OS.XmNdirectory, 0, OS.XmNdirSpec, 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);
- filterPath = new String (Converter.mbcsToWcs (null, buffer));
- }
- OS.XmStringFree (xmString3);
- int xmString4 = argList2 [3];
- ptr = OS.XmStringUnparse (
- xmString4,
- 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);
- fullPath = new String (Converter.mbcsToWcs (null, buffer));
- }
- OS.XmStringFree (xmString4);
- int length = filterPath.length ();
- if ((length != 0) && (filterPath.charAt (length - 1) == '/')) {
- filterPath = filterPath.substring (0, length - 1);
- int index = fullPath.length () - 1;
- while ((index >= 0) && (fullPath.charAt (index) != '/')) --index;
- fileName = fullPath.substring (index, fullPath.length ());
- }
- }
-
/* Destroy the dialog and update the display. */
if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
if (destroyContext) appContext.dispose ();
- callback.dispose ();
+ okCallback.dispose ();
+ cancelCallback.dispose ();
// (shell == nil or: [shell isDestroyed not]) ifTrue: [dialog xtDestroyWidget].
// OSWidget updateDisplay.
@@ -246,15 +375,48 @@ public String open () {
if (cancel) return 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 path which the dialog will use to filter
+ * the files it shows to the argument, which may be
+ * null.
+ *
+ * @param string the filter path
+ */
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 ea7088a92a..dbfb589628 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
@@ -11,17 +11,20 @@ import org.eclipse.swt.layout.*;
import java.text.*;
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>
+/**
+ * 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 /*final*/ class FontDialog extends Dialog {
private static final String TEXT_SAMPLE = "AaBbYyZz";
private static final String TEXT_FONT_NOT_LOADED = "Could not load selected font"; // text used in place of sample text when the selected font could not be loaded
+ 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 = FontExtStyles.MEDIUM;
private Shell shell; // the dialog shell
private Combo characterSet;
@@ -44,24 +47,67 @@ public /*final*/ class FontDialog extends Dialog {
// Used to correctly clean up allocated fonts
// will be used to initialize the font
// combo boxes when the dialog is opened
+
/**
- * Create a new instance of the receiver with 'parent' as
- * its parent shell.
- * @param parent - the parent shell. May be null
+ * 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.NULL);
}
+
/**
- * Create a new instance of the receiver with 'parent' as
- * its parent shell using 'style' as the widget style.
- * @param parent - the parent shell. May be null
- * @param style - style bits used to create the receiver.
- * See class definition for details
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 dialog classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </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 | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
}
+
/**
* Add the fonts found in 'fonts' to the list of fonts.
* Fonts are stored by character set and face name. For each character
@@ -242,8 +288,10 @@ Combo getFaceNameCombo() {
return faceName;
}
/**
- * Returns the FontData for the selected font.
- * Returns null if no font was selected and the dialog was cancelled.
+ * 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 dialogResult;
@@ -532,32 +580,35 @@ void initFontDataCombos() {
* is used.
*/
void initSizeCombo(FontExtStyles fontExtStyles) {
- Vector sizes = null;
- Integer size;
Combo sizeCombo = getSizeCombo();
- String sizeStrings[] = {"8", "10", "11", "12", "14", "16", "18", "22", "24", "26"};
+ String previousSize = sizeCombo.getText();
+ sizeCombo.removeAll();
+
int selectionIndex = -1;
- final int SelectionSize = 14;
- sizeCombo.removeAll();
- if (fontExtStyles.isScalable() == true) {
- sizeCombo.setItems(sizeStrings);
- selectionIndex = 4;
+ if (fontExtStyles.isScalable()) {
+ sizeCombo.setItems(SCALABLE_SIZES);
+ selectionIndex = sizeCombo.indexOf(String.valueOf(DEFAULT_SIZE));
}
else {
- sizes = fontExtStyles.getSizes(getExtStyleCombo().getText());
+ Vector sizes = fontExtStyles.getSizes(getExtStyleCombo().getText());
for (int i = 0; i < sizes.size(); i++) {
- size = (Integer) sizes.elementAt(i);
+ Integer size = (Integer) sizes.elementAt(i);
sizeCombo.add(size.toString());
- if (size.intValue() >= SelectionSize && selectionIndex == -1) {
+ // select the largest height if there's no font
+ // size that is at least as high as SelectionSize
+ if (size.intValue() >= DEFAULT_SIZE && selectionIndex == -1)
selectionIndex = i;
- }
}
- }
- if (selectionIndex == -1) {
- selectionIndex = sizes.size() - 1; // select largest height if there's no font
- // size that is at least as high as SelectionSize
}
+
+ int indexOfPreviousSelection = sizeCombo.indexOf(previousSize);
+ if (indexOfPreviousSelection != -1)
+ selectionIndex = indexOfPreviousSelection;
+
+ if (selectionIndex == -1) // last resort case, should not happen
+ selectionIndex = sizeCombo.getItemCount() - 1;
+
sizeCombo.select(selectionIndex);
}
/**
@@ -565,20 +616,20 @@ void initSizeCombo(FontExtStyles fontExtStyles) {
* is available in.
*/
void initStyleCombo(FontExtStyles fontExtStyles) {
- Vector styleVector = fontExtStyles.getStyles(getExtStyleCombo().getText());
- Enumeration styleEnum = styleVector.elements();
Combo styleCombo = getStyleCombo();
- int selectionIndex = styleVector.indexOf(FontExtStyles.MEDIUM);
- String style;
-
+ String previousStyle = styleCombo.getText();
styleCombo.removeAll();
- while (styleEnum.hasMoreElements() == true) {
- style = (String) styleEnum.nextElement();
- styleCombo.add(style);
- }
- if (selectionIndex == -1) {
+
+ Enumeration styleEnum = fontExtStyles.getStyles(getExtStyleCombo().getText()).elements();
+ while (styleEnum.hasMoreElements())
+ styleCombo.add((String)styleEnum.nextElement());
+
+ int selectionIndex = styleCombo.indexOf(previousStyle);
+ if (selectionIndex == -1)
+ selectionIndex = styleCombo.indexOf(DEFAULT_STYLE);
+ if (selectionIndex == -1) // last resort
selectionIndex = 0;
- }
+
styleCombo.select(selectionIndex);
}
@@ -622,8 +673,16 @@ void installListeners() {
getExtStyleCombo().addListener(SWT.Selection, listener);
}
/**
- * Initialize the widgets of the receiver, open the dialog
- * and block the method until the dialog is closed by the user.
+ * 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() {
FontData dialogResult = null;
@@ -677,7 +736,11 @@ void setFontCombos(FontData fontData) {
getStyleCombo().setText(value);
}
/**
- * Set the preselected font of the receiver to '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) {
dialogResult = fontData;
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 65b797c6c5..b414013663 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
@@ -10,30 +10,56 @@ 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>
- * 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>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ * </p>
*/
public /*final*/ class Group extends Composite {
int labelHandle;
+
/**
-* Creates a new instance of the 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
+ * 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 Group (Composite parent, int style) {
super (parent, checkStyle (style));
}
@@ -51,8 +77,7 @@ protected void checkSubclass () {
if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
}
public Rectangle computeTrim (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int trimX, trimY, trimWidth, trimHeight;
int [] argList = {
OS.XmNwidth, 0,
@@ -65,10 +90,11 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
int thickness = argList [5];
int marginWidth = argList [7];
int marginHeight = argList [9];
- trimX = x - marginWidth + thickness;
- trimY = y - marginHeight + thickness;
- trimWidth = width + ((marginWidth + thickness) * 2);
- trimHeight = height + ((marginHeight + thickness) * 2);
+ int borderWidth = getBorderWidth ();
+ trimX = x - marginWidth + thickness - borderWidth;
+ trimY = y - marginHeight + thickness - borderWidth;
+ trimWidth = width + ((marginWidth + thickness + borderWidth) * 2);
+ trimHeight = height + ((marginHeight + thickness + borderWidth) * 2);
if (OS.XtIsManaged (labelHandle)) {
int [] argList2 = {OS.XmNy, 0, OS.XmNheight, 0};
OS.XtGetValues (labelHandle, argList2, argList2.length / 2);
@@ -127,8 +153,7 @@ int fontHandle () {
return labelHandle;
}
public Rectangle getClientArea () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {
OS.XmNwidth, 0,
OS.XmNheight, 0,
@@ -152,21 +177,20 @@ public Rectangle getClientArea () {
}
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNlabelString, 0};
OS.XtGetValues (labelHandle, argList, 1);
int xmString = argList [1];
@@ -184,7 +208,7 @@ public String getText () {
OS.memmove (buffer, address, length);
OS.XtFree (address);
OS.XmStringFree (xmString);
- return new String (Converter.mbcsToWcs (null, buffer));
+ return new String (Converter.mbcsToWcs (getCodePage (), buffer));
}
boolean mnemonicHit () {
return setFocus ();
@@ -210,26 +234,25 @@ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
int xmString = OS.XmStringParseText (
buffer,
0,
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 290359e958..d19a39b7ca 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
@@ -11,54 +11,54 @@ import org.eclipse.swt.internal.motif.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
-/**
- * Instances of this class represent a non-selectable
- * user interface object that displays a string or image.
- * When SEPARATOR is specified, displays a single
- * vertical or horizontal line.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SEPARATOR, HORIZONTAL, SHADOW_IN, SHADOW_OUT, VERTICAL</dd>
- * <dd>CENTER, LEFT, RIGHT, WRAP</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 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, SHADOW_IN, SHADOW_OUT, VERTICAL</dd>
+ * <dd>CENTER, LEFT, RIGHT, WRAP</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 /*final*/ 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.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</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
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 Label (Composite parent, int style) {
super (parent, checkStyle (style));
@@ -68,8 +68,7 @@ static int checkStyle (int style) {
return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int border = getBorderWidth ();
int width = border * 2, height = border * 2;
if ((style & SWT.SEPARATOR) != 0) {
@@ -165,23 +164,22 @@ int defaultFont () {
int defaultForeground () {
return getDisplay ().labelForeground;
}
-/**
- * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) != 0) return SWT.LEFT;
int [] argList = {OS.XmNalignment, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
@@ -191,40 +189,38 @@ public int getAlignment () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) != 0) return "";
return text;
}
@@ -277,22 +273,21 @@ int separatorType () {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) != 0) return;
int [] argList = {OS.XmNalignment, OS.XmALIGNMENT_BEGINNING};
if ((alignment & SWT.CENTER) != 0) argList [1] = OS.XmALIGNMENT_CENTER;
@@ -312,6 +307,7 @@ void setBitmap (Image image) {
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:
@@ -350,46 +346,47 @@ 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setBitmap (this.image = image);
}
public void setSize (int width, int height) {
super.setSize (width, height);
if ((style & SWT.WRAP) != 0) setText (text);
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.SEPARATOR) != 0) return;
text = string;
@@ -422,11 +419,11 @@ public void setText (String string) {
OS.XtGetValues (handle, argList, argList.length / 2);
int width = argList [3] - argList [5] - argList [7] - argList [9] * 2 - argList [11] * 2;
Display display = getDisplay ();
- if (mnemonic != 0) string = new String(unicode);
+ if (mnemonic != 0) string = new String (unicode);
string = display.wrapText (string, argList [1], width);
- buffer = Converter.wcsToMbcs (null, string, true);
+ buffer = Converter.wcsToMbcs (getCodePage (), string, true);
} else {
- buffer = Converter.wcsToMbcs (null, unicode, true);
+ buffer = Converter.wcsToMbcs (getCodePage (), unicode, true);
}
int [] parseTable = getDisplay ().parseTable;
@@ -438,8 +435,21 @@ public void setText (String string) {
parseTable,
parseTable.length,
0);
- if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol;
+ 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,
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 148b752474..ac0d9fe3aa 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
@@ -12,51 +12,51 @@ 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>
- * 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>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ * </p>
*/
public /*final*/ class List extends Scrollable {
int rows, columns;
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 List (Composite parent, int style) {
/**
@@ -68,63 +68,61 @@ public List (Composite parent, int style) {
*/
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)
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ 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)
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if (index == -1) error (SWT.ERROR_INVALID_RANGE);
/*
@@ -138,7 +136,7 @@ public void add (String string, int index) {
if (!(0 <= index && index <= argList [1])) {
error (SWT.ERROR_INVALID_RANGE);
}
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ 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);
@@ -169,8 +167,7 @@ public void add (String string, int index) {
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection,typedListener);
@@ -180,8 +177,7 @@ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
XtWidgetGeometry result = new XtWidgetGeometry ();
result.request_mode = OS.CWWidth;
OS.XtQueryGeometry (handle, null, result);
@@ -210,8 +206,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
return new Point (rect.width, rect.height);
}
public Rectangle computeTrim (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Display display = getDisplay ();
int border = getBorderWidth ();
int trimX = x - border;
@@ -305,45 +300,43 @@ int defaultFont () {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (start > end) return;
/*
* Note: We rely on the fact that XmListDeselectPos ()
@@ -354,26 +347,25 @@ public void deselect (int start, int end) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
/*
* Note: We rely on the fact that XmListDeselectPos ()
@@ -384,56 +376,53 @@ public void deselect (int [] indices) {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
if (!(0 <= index && index < argList [1])) {
@@ -457,45 +446,43 @@ public String getItem (int index) {
byte [] buffer = new byte [length];
OS.memmove (buffer, address, length);
OS.XtFree (address);
- return new String (Converter.mbcsToWcs (null, buffer));
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {
OS.XmNlistSpacing, 0,
OS.XmNhighlightThickness, 0,
@@ -506,34 +493,34 @@ public int getItemHeight () {
/* 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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];
@@ -550,39 +537,39 @@ public String [] getItems () {
byte [] buffer = new byte [length];
OS.memmove (buffer, address, length);
OS.XtFree (address);
- result[i] = new String (Converter.mbcsToWcs (null, buffer));
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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];
@@ -599,48 +586,46 @@ public String [] getSelection () {
byte [] buffer = new byte [length];
OS.memmove (buffer, address, length);
OS.XtFree (address);
- result[i] = new String (Converter.mbcsToWcs (null, buffer));
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int index = OS.XmListGetKbdItemPos (handle);
if (OS.XmListPosSelected (handle, index)) return index - 1;
int [] count = new int [1], positions = new int [1];
@@ -652,27 +637,26 @@ public int getSelectionIndex () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] count = new int [1], positions = new int [1];
OS.XmListGetSelectedPos (handle, positions, count);
int [] result = new int [count [0]];
@@ -681,21 +665,20 @@ public int [] getSelectionIndices () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNtopItemPosition, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
return argList [1] - 1;
@@ -707,67 +690,65 @@ void hookEvents () {
OS.XtAddCallback (handle, OS.XmNextendedSelectionCallback, windowProc, SWT.Selection);
OS.XtAddCallback (handle, OS.XmNdefaultActionCallback, windowProc, SWT.DefaultSelection);
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 (null, string, true);
+ byte [] buffer1 = Converter.wcsToMbcs (getCodePage (), string, true);
int xmString = OS.XmStringCreateLocalized (buffer1);
if (xmString == 0) return -1;
int index = start;
@@ -782,45 +763,43 @@ public int indexOf (String string, int start) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (index == -1) return false;
return OS.XmListPosSelected (handle, index + 1);
}
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (index == -1) error (SWT.ERROR_INVALID_RANGE);
/*
* Feature in Motif. An index out of range handled
@@ -835,28 +814,27 @@ public void remove (int index) {
}
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (start > end) return;
int count = end - start + 1;
/*
@@ -873,30 +851,29 @@ public void remove (int start, int end) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ 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);
@@ -904,26 +881,25 @@ public void remove (String string) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
/*
* Feature in Motif. An index out of range handled
@@ -943,17 +919,16 @@ public void remove (int [] indices) {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
OS.XmListDeselectAllItems (handle);
OS.XmListDeleteAllItems (handle);
/*
@@ -966,46 +941,44 @@ public void removeAll () {
*/
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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (index == -1) return;
if (OS.XmListPosSelected (handle, index + 1)) return;
/*
@@ -1033,23 +1006,22 @@ public void select (int index) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (start > end) return;
if ((style & SWT.SINGLE) != 0) {
int [] argList = {OS.XmNitemCount, 0};
@@ -1088,26 +1060,25 @@ public void select (int start, int end) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.SINGLE) != 0) {
int [] argList = {OS.XmNitemCount, 0};
@@ -1153,12 +1124,12 @@ public void select (int [] indices) {
}
}
void select (String [] items) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 (null, string, true);
+ byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
int xmString = OS.XmStringCreateLocalized (buffer);
table [i] = xmString;
}
@@ -1170,17 +1141,16 @@ void select (String [] items) {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SINGLE) != 0) return;
/*
* Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
@@ -1245,30 +1215,29 @@ public void setBounds (int x, int y, int width, int height) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if (index == -1) error (SWT.ERROR_INVALID_RANGE);
int [] argList = {OS.XmNitemCount, 0};
@@ -1276,7 +1245,7 @@ public void setItem (int index, String string) {
if (!(0 <= index && index < argList [1])) {
error (SWT.ERROR_INVALID_RANGE);
}
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ 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);
@@ -1284,22 +1253,21 @@ public void setItem (int index, String string) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
/*
* Bug in AIX. When all list items are replaced
@@ -1317,10 +1285,11 @@ public void setItems (String [] items) {
}
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 (null, string, true);
+ byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
int xmString = OS.XmStringCreateLocalized (buffer);
if (xmString == 0) break;
table [index++] = xmString;
@@ -1341,92 +1310,92 @@ public void setItems (String [] items) {
}
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)
+/**
+ * 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) {
if ((style & SWT.MULTI) != 0) deselectAll ();
select (index);
}
-/**
- * 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) {
if ((style & SWT.MULTI) != 0) deselectAll ();
select (start, end);
}
-/**
- * Selects the items at the given zero-relative indices in the receiver.
- * The current selected of 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 selected of 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) {
if ((style & SWT.MULTI) != 0) 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
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 (null, string, true);
+ byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
int xmString = OS.XmStringCreateLocalized (buffer);
if (xmString != 0) {
int index = OS.XmListItemPos (handle, xmString);
@@ -1445,7 +1414,7 @@ public void setSelection (String [] items) {
for (int i=0; i<items.length; i++) {
String string = items [i];
if (string != null) {
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
int xmString = OS.XmStringCreateLocalized (buffer);
if (xmString != 0) table [length++] = xmString;
}
@@ -1492,21 +1461,20 @@ public void setSize (int width, int height) {
OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]);
OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]);
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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]));
@@ -1514,22 +1482,21 @@ public void setTopIndex (int index) {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] buffer = new int [1], positions = new int [1];
if (!OS.XmListGetSelectedPos (handle, positions, buffer)) return;
if (buffer [0] == 0) return;
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 38ef27e42f..04bc251665 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
@@ -9,18 +9,18 @@ import org.eclipse.swt.internal.motif.*;
import org.eclipse.swt.*;
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</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Help, Hide, Show </dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
+/**
+ * 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>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ * </p>
*/
public /*final*/ class Menu extends Widget {
boolean hasLocation;
@@ -52,54 +52,52 @@ public Menu (Menu parentMenu) {
public Menu (MenuItem parentItem) {
this (checkNull(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
- * 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 help events are generated for the control, 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
+/**
+ * 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>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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener(SWT.Hide,typedListener);
@@ -190,21 +188,20 @@ void createWidget (int index) {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return defaultItem;
}
public Display getDisplay () {
@@ -212,44 +209,42 @@ public Display getDisplay () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
@@ -268,19 +263,18 @@ public MenuItem getItem (int index) {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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;
@@ -292,25 +286,24 @@ public int getItemCount () {
}
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
int ptr = argList [1], count = argList [3];
@@ -341,96 +334,91 @@ String 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return OS.XtIsManaged (handle);
}
void hookEvents () {
@@ -439,26 +427,25 @@ void hookEvents () {
OS.XtAddCallback (handle, OS.XmNmapCallback, windowProc, SWT.Show);
OS.XtAddCallback (handle, OS.XmNunmapCallback, windowProc, SWT.Hide);
}
-/**
- * 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
int [] handles = new int [argList [3]];
@@ -472,46 +459,44 @@ public int indexOf (MenuItem item) {
}
return -1;
}
-/**
- * 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 isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Menu parentMenu = getParentMenu ();
if (parentMenu == null) return getEnabled ();
return getEnabled () && parentMenu.isEnabled ();
}
-/**
- * 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 isVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getVisible ();
}
int processHelp (int callData) {
@@ -564,50 +549,48 @@ void releaseWidget () {
parent = null;
cascade = defaultItem = null;
}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook(SWT.Hide, listener);
@@ -620,84 +603,84 @@ void sendHelpEvent (int callData) {
}
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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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;
}
-/**
- * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
if (visible) {
if (!hasLocation) {
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 92404313c1..6581d10281 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
@@ -11,87 +11,143 @@ 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>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </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>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>Arm, Help, Selection</dd>
+ * </dl>
+ *<p>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ * </p>
*/
public /*final*/ class MenuItem extends Item {
int accelerator;
Menu parent, menu;
+
/**
-* Creates a new instance of the widget.
-*/
+ * 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
+ * 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 MenuItem (Menu parent, int style) {
super (parent, checkStyle (style));
this.parent = parent;
createWidget (OS.XmLAST_POSITION);
}
+
/**
-* Creates a new instance of the widget.
-*/
+ * 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
+ * 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 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);
}
-/**
- * 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
+
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Help, typedListener);
@@ -121,8 +177,7 @@ public void addHelpListener (HelpListener listener) {
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection,typedListener);
@@ -194,22 +249,21 @@ void destroyWidget () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return accelerator;
}
public Display getDisplay () {
@@ -217,81 +271,77 @@ public Display getDisplay () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
int [] argList = {OS.XmNset, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
@@ -303,13 +353,12 @@ public boolean getSelection () {
* delimiters.
*/
String getText2 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.ARROW) != 0) return "";
int [] argList = {OS.XmNlabelString, 0, OS.XmNmnemonic, 0, OS.XmNacceleratorText, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
- int xmString1 = argList [1], xmString2 = argList [5];
- int mnemonic = argList [3];
+ int xmString1 = argList [1], xmString2 = argList [5];
+ int mnemonic = argList [3];
if (mnemonic == OS.XK_VoidSymbol) mnemonic = 0;
if (xmString1 == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
char [] result = null;
@@ -326,6 +375,7 @@ String getText2 () {
byte [] buffer = new byte [length];
OS.memmove (buffer, address, length);
OS.XtFree (address);
+ /* Use the character encoding for the default locale */
result = Converter.mbcsToWcs (null, buffer);
}
String accelText = "";
@@ -344,6 +394,7 @@ String getText2 () {
byte [] buffer = new byte [length];
OS.memmove (buffer, address, length);
OS.XtFree (address);
+ /* Use the character encoding for the default locale */
accelText = '\t' + new String (Converter.mbcsToWcs (null, buffer));
}
}
@@ -384,18 +435,18 @@ void hookEvents () {
OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, SWT.Selection);
}
}
-/**
- * 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 isEnabled () {
return getEnabled ();
@@ -417,6 +468,7 @@ String keysymName (int keysym) {
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 () {
@@ -434,28 +486,24 @@ int processHelp (int callData) {
parent.sendHelpEvent (callData);
return 0;
}
-int processSelection (int callData) {
- XmAnyCallbackStruct struct = new XmAnyCallbackStruct ();
- OS.memmove (struct, callData, 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:
- if ((xEvent.state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
- if ((xEvent.state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
- if ((xEvent.state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
- if ((xEvent.state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
- if ((xEvent.state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
- if ((xEvent.state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
- }
- }
- postEvent (SWT.Selection, event);
+int processSelection (int callData) {
+ XmAnyCallbackStruct struct = new XmAnyCallbackStruct ();
+ OS.memmove (struct, callData, 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;
}
void releaseChild () {
@@ -476,95 +524,91 @@ void releaseWidget () {
}
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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook(SWT.Selection, listener);
eventTable.unhook(SWT.DefaultSelection,listener);
}
-/**
- * Sets the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
this.accelerator = accelerator;
int ptr = 0;
if (accelerator != 0) {
@@ -581,7 +625,8 @@ public void setAccelerator (int accelerator) {
keysym = wcsToMbcs ((char) keysym);
}
String key = "<Key>" + keysymName (keysym);
- byte [] buffer = Converter.wcsToMbcs (null, ctrl + alt + shift + key, true);
+ /* Use the character encoding for the default locale */
+ byte [] buffer = Converter.wcsToMbcs (null, ctrl + alt + shift + key, true);
ptr = OS.XtMalloc (buffer.length);
if (ptr != 0) OS.memmove (ptr, buffer, buffer.length);
}
@@ -589,53 +634,52 @@ public void setAccelerator (int accelerator) {
OS.XtSetValues (handle, argList, argList.length / 2);
if (ptr != 0) OS.XtFree (ptr);
}
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
OS.XtSetValues (handle, argList, argList.length / 2);
}
-/**
- * Sets the receiver's cascade 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 pop up menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_DROP_DOWN - the menu is not a drop down menu</li>
- * <li>ERROR_MENUITEM_NOT_CASCADE - the menu item is not a <code>CASCADE</code></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>
+/**
+ * Sets the receiver's cascade 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 pop up menu
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_MENU_NOT_DROP_DOWN - the menu is not a drop down menu</li>
+ * <li>ERROR_MENUITEM_NOT_CASCADE - 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ 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);
}
@@ -659,22 +703,21 @@ public void setMenu (Menu menu) {
int [] argList = {OS.XmNsubMenuId, menuHandle};
OS.XtSetValues (handle, argList, argList.length / 2);
}
-/**
- * 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
int [] argList = {OS.XmNset, selected ? 1 : 0};
OS.XtSetValues (handle, argList, argList.length / 2);
@@ -692,8 +735,7 @@ public void setSelection (boolean selected) {
* when string is null
*/
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
super.setText (string);
if ((style & (SWT.ARROW | SWT.SEPARATOR)) != 0) return;
@@ -714,6 +756,7 @@ public void setText (String string) {
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];
@@ -728,6 +771,7 @@ public void setText (String string) {
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,
@@ -737,7 +781,7 @@ public void setText (String string) {
null,
0,
0);
- if (xmString1 == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
+ if (xmString1 == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol;
int [] argList = {
OS.XmNlabelType, OS.XmSTRING,
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 f1980dae5b..341e83083d 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
@@ -10,29 +10,83 @@ import org.eclipse.swt.internal.motif.*;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
-/**
- * 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>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
- */
+/**
+ * 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>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation.
+ * </p>
+ */
public /*final*/ 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);
}
+
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 dialog classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </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));
}
@@ -58,9 +112,30 @@ int createHandle (int parentHandle, int [] argList) {
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 int open () {
/* Create the dialog.*/
@@ -80,6 +155,7 @@ public int open () {
*/
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,
@@ -178,6 +254,7 @@ void setButtons (int dialogHandle) {
}
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,
@@ -187,6 +264,7 @@ void setButtons (int dialogHandle) {
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,
@@ -196,6 +274,7 @@ void setButtons (int dialogHandle) {
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,
@@ -211,6 +290,7 @@ void setButtons (int dialogHandle) {
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,
@@ -220,6 +300,7 @@ void setButtons (int dialogHandle) {
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,
@@ -235,6 +316,7 @@ void setButtons (int dialogHandle) {
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,
@@ -244,6 +326,7 @@ void setButtons (int dialogHandle) {
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,
@@ -260,6 +343,7 @@ void setButtons (int dialogHandle) {
}
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,
@@ -269,6 +353,7 @@ void setButtons (int dialogHandle) {
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,
@@ -278,6 +363,7 @@ void setButtons (int dialogHandle) {
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,
@@ -308,6 +394,7 @@ void setMessage (int dialogHandle) {
text = display.wrapText (message, fontList, width * 3 / 5);
}
}
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs (null, text, true);
int [] parseTable = Display.getDefault ().parseTable;
int xmStringPtr = OS.XmStringParseText (
@@ -322,6 +409,14 @@ void setMessage (int dialogHandle) {
OS.XtSetValues (dialogHandle, argList, argList.length / 2);
OS.XmStringFree (xmStringPtr);
}
+
+/**
+ * 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/motif/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java
index c2d580ae8b..630fbbce03 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
@@ -9,28 +9,54 @@ 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>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+/**
+ * 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>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation.
+ * </p>
*/
public /*final*/ class ProgressBar extends Control {
+
/**
-* Creates a new instance of the 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
+ * 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 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
@@ -45,8 +71,7 @@ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int border = getBorderWidth ();
int width = border * 2, height = border * 2;
Display display = getDisplay ();
@@ -82,68 +107,65 @@ void createHandle (int index) {
};
handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2);
if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-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);
-}
-void disableTraversal () {
- int [] argList = {OS.XmNtraversalOn, 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
}
-/**
- * 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>
+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);
+}
+void disableTraversal () {
+ int [] argList = {OS.XmNtraversalOn, 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+}
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {
OS.XmNminimum, 0,
OS.XmNsliderSize, 0,
@@ -153,37 +175,36 @@ public int getSelection () {
int minimum = argList [1], sliderSize = argList [3], background = argList [5];
if (sliderSize == 1 && background == defaultBackground()) sliderSize = 0;
return minimum + sliderSize;
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- /*
- * ProgressBars never participate in focus traversal when
- * either enabled or disabled. Also, when enabled
- */
- if (enabled) {
- disableTraversal ();
- disableButtonPress ();
- }
+}
+void propagateWidget (boolean enabled) {
+ super.propagateWidget (enabled);
+ /*
+ * ProgressBars never participate in focus traversal when
+ * either enabled or disabled.
+ */
+ if (enabled) {
+ disableTraversal ();
+ disableButtonPress ();
+ }
}
void realizeChildren () {
- super.realizeChildren ();
+ super.realizeChildren ();
disableButtonPress ();
}
-/**
- * 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
int [] argList = {OS.XmNmaximum, value, OS.XmNvalue, 0};
Display display = getDisplay ();
@@ -192,21 +213,20 @@ public void setMaximum (int value) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
int [] argList = {
OS.XmNminimum, 0,
@@ -231,21 +251,20 @@ public void setMinimum (int value) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
int [] argList = {
OS.XmNminimum, 0,
@@ -263,7 +282,9 @@ public void setSelection (int value) {
void setThumb (int sliderSize) {
Display display = getDisplay ();
int backgroundPixel = defaultBackground ();
- int [] argList1 = new int [] {OS.XmNbackground, 0};
+ int [] argList1 = new int [] {
+ OS.XmNbackground, 0,
+ OS.XmNminimum, 0};
OS.XtGetValues (handle, argList1, argList1.length / 2);
if (sliderSize == 0) {
if (argList1 [1] != backgroundPixel) {
@@ -279,6 +300,7 @@ void setThumb (int sliderSize) {
OS.XmNtroughColor, backgroundPixel,
OS.XmNtopShadowColor, backgroundPixel,
OS.XmNbottomShadowColor, backgroundPixel,
+ OS.XmNvalue, argList1[3]
};
boolean warnings = display.getWarnings ();
display.setWarnings (false);
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 7ca606ca88..d26fa476fb 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
@@ -10,26 +10,27 @@ 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>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+/**
+ * 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>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation.
+ * </p>
*/
public /*final*/ class Sash extends Control {
boolean dragging;
int startX, startY, lastX, lastY;
int cursor;
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -61,6 +62,7 @@ public /*final*/ class Sash extends Control {
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
@@ -87,8 +89,7 @@ public Sash (Composite parent, int style) {
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection,typedListener);
@@ -98,8 +99,7 @@ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int border = getBorderWidth ();
int width = border * 2, height = border * 2;
if ((style & SWT.HORIZONTAL) != 0) {
@@ -242,26 +242,25 @@ void releaseWidget () {
}
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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook(SWT.Selection, listener);
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 8fae896a6b..4e935cbc11 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
@@ -10,20 +10,20 @@ import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
-/**
- * Instances of the receiver represent a selectable user
- * interface object that present a range of continuous
- * numeric values.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd> HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+/**
+ * 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>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation.
+ * </p>
*/
public /*final*/ class Scale extends Control {
@@ -58,28 +58,28 @@ public /*final*/ class Scale extends Control {
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
+
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection,typedListener);
@@ -89,8 +89,7 @@ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int border = getBorderWidth ();
int width = border * 2, height = border * 2;
Display display = getDisplay ();
@@ -120,89 +119,84 @@ void createHandle (int index) {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNvalue, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
return argList [1];
@@ -213,63 +207,60 @@ void hookEvents () {
OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, SWT.Selection);
OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, SWT.Selection);
}
-/**
- * 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
int [] argList = {OS.XmNmaximum, value};
Display display = getDisplay ();
@@ -278,21 +269,20 @@ public void setMaximum (int value) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
int [] argList = {OS.XmNminimum, value};
Display display = getDisplay ();
@@ -301,22 +291,21 @@ public void setMinimum (int value) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (pageIncrement < 1) return;
int [] argList = {OS.XmNscaleMultiple, pageIncrement};
Display display = getDisplay ();
@@ -325,21 +314,20 @@ public void setPageIncrement (int pageIncrement) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (selection < 0) return;
int [] argList = {OS.XmNvalue, selection};
Display display = getDisplay ();
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 0dfc32c3e9..95ffca31a4 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
@@ -10,65 +10,65 @@ 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 left and right facing buttons for incrementing and
- * decrementing the value) or <code>VERTICAL</code> (which have
- * up and down facing buttons for incrementing and decrementing
- * the value).
- * </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>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- *
- * @see Slider
- * @see Scrollable
- * @see Scrollable#getHorizontalBar
- * @see Scrollable#getVerticalBar
+/**
+ * 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 left and right facing buttons for incrementing and
+ * decrementing the value) or <code>VERTICAL</code> (which have
+ * up and down facing buttons for incrementing and decrementing
+ * the value).
+ * </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>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ *
+ * @see Slider
+ * @see Scrollable
+ * @see Scrollable#getHorizontalBar
+ * @see Scrollable#getVerticalBar
*/
public /*final*/ class ScrollBar extends Widget {
@@ -114,8 +114,7 @@ ScrollBar (Scrollable parent, int style) {
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection,typedListener);
@@ -143,190 +142,180 @@ public Display getDisplay () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNvalue, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
return argList [1];
}
-/**
- * For horizontal scroll bars, returns the height of the
- * instance, and for vertical scroll bars, returns the width
- * of the instance.
- *
- * @return the scroll bar 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>
+/**
+ * For horizontal scroll bars, returns the height of the
+ * instance, and for vertical scroll bars, returns the width
+ * of the instance.
+ *
+ * @return the scroll bar 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return OS.XtIsManaged (handle);
}
void hookEvents () {
@@ -340,49 +329,47 @@ void hookEvents () {
OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, SWT.Selection);
OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, SWT.Selection);
}
-/**
- * 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.
- * <p>
- * Note: Because of the strong connection between a scroll bar
- * and the widget which contains it (its parent), a scroll bar
- * will not indicate that it is enabled if its parent is not.
- * </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>
- */
+/**
+ * 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.
+ * <p>
+ * Note: Because of the strong connection between a scroll bar
+ * and the widget which contains it (its parent), a scroll bar
+ * will not indicate that it is enabled if its parent is not.
+ * </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 isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getEnabled () && parent.isEnabled ();
}
-/**
- * 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 isVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getVisible () && parent.isVisible ();
}
void manageChildren () {
@@ -427,85 +414,81 @@ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook(SWT.Selection, listener);
eventTable.unhook(SWT.DefaultSelection,listener);
}
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
int [] argList = {OS.XmNmaximum, value};
Display display = getDisplay ();
@@ -514,21 +497,20 @@ public void setMaximum (int value) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
int [] argList = {
OS.XmNminimum, 0,
@@ -556,41 +538,39 @@ public void setMinimum (int value) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (selection < 0) return;
int [] argList = {OS.XmNvalue, selection};
Display display = getDisplay ();
@@ -599,23 +579,22 @@ public void setSelection (int selection) {
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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 1) return;
int [] argList = {OS.XmNsliderSize, value};
Display display = getDisplay ();
@@ -624,30 +603,29 @@ public void setThumb (int value) {
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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (selection < 0) return;
if (minimum < 0) return;
if (maximum < 0) return;
@@ -669,25 +647,24 @@ public void setValues (int selection, int minimum, int maximum, int thumb, int i
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>
+/**
+ * Marks the receiver as visible if the argument is <code>true</code>,
+ * and marks it invisible otherwise.
+ * <p>
+ * If one of the receiver's ancestors is not visible or some
+ * other condition makes the receiver not visible, marking
+ * it visible may not actually cause it to be displayed.
+ * </p>
+ *
+ * @param visible the new visibility state
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
*/
public void setVisible (boolean visible) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/*
* Feature in Motif. Hiding or showing a scroll bar
* can cause the widget to automatically resize in
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 e4cebf455b..a1188a1384 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
@@ -9,103 +9,100 @@ 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>
- */
+/**
+ * This class is the abstract superclass of all classes which
+ * represent controls that have standard scroll bars.
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>H_SCROLL, V_SCROLL</dd>
+ * <dt><b>Events:</b>
+ * <dd>(none)</dd>
+ * </dl>
+ * <p>
+ * IMPORTANT: This class is intended to be subclassed <em>only</em>
+ * within the SWT implementation.
+ * </p>
+ */
public abstract class Scrollable extends Control {
int scrolledHandle, formHandle;
ScrollBar horizontalBar, verticalBar;
Scrollable () {
/* Do nothing */
}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * 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
- */
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 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
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int border = getBorderWidth ();
int trimX = x - border, trimY = y - border;
int trimWidth = width + (border * 2), trimHeight = height + (border * 2);
- boolean hasHBar = (horizontalBar != null) && (horizontalBar.getVisible ());
- boolean hasVBar = (verticalBar != null) && (verticalBar.getVisible ());
- if (hasHBar) {
+ if (horizontalBar != null) {
Display display = getDisplay ();
trimY -= display.scrolledInsetY;
trimHeight += display.scrolledInsetY + display.scrolledMarginY;
- if (!hasVBar) {
+ if (verticalBar == null) {
trimX -= display.scrolledInsetX;
trimWidth += display.scrolledInsetX * 2;
trimHeight -= display.scrolledInsetY * 2;
}
}
- if (hasVBar) {
+ if (verticalBar != null) {
Display display = getDisplay ();
trimX -= display.scrolledInsetX;
trimWidth += display.scrolledInsetX + display.scrolledMarginX;
- if (!hasHBar) {
+ if (horizontalBar == null) {
trimY -= display.scrolledInsetY;
trimHeight += display.scrolledInsetY * 2;
trimWidth -= display.scrolledInsetX * 2;
@@ -154,57 +151,54 @@ void enableWidget (boolean enabled) {
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
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return verticalBar;
}
void manageChildren () {
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 e5a3334685..835ab4a329 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
@@ -11,170 +11,172 @@ 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 which 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 which 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>
- * 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</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>
- * IMPORTANT: This class is not intended to be subclassed.
- * </p>
- *
- * @see Decorations
- * @see SWT
- */
+/**
+ * Instances of this class represent the "windows"
+ * which the desktop or "window manager" is managing.
+ * Instances which 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 which 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>
+ * 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</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>
+ * IMPORTANT: This class is not intended to be subclassed.
+ * </p>
+ *
+ * @see Decorations
+ * @see SWT
+ */
public /*final*/ class Shell extends Decorations {
Display display;
int shellHandle;
boolean reparented, realized;
int oldX, oldY, oldWidth, oldHeight;
- Control lastFocus;
-/**
- * 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>
+ Control lastActive;
+
+ static final byte [] WM_DETELE_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);
}
-/**
- * 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
- * for all SWT widget classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </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>
+/**
+ * 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
+ * for all SWT widget classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </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>
*/
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>
+/**
+ * Constructs a new instance of this class given only the display
+ * to create it on. It is created with style <code>SWT.SHELL_TRIM</code>.
+ * <p>
+ * Note: Currently, null can be passed in for the display argument.
+ * This has the effect of creating the shell on the currently active
+ * display if there is one. If there is no current display, the
+ * shell is created on a "default" display. <b>Passing in null as
+ * the display argument is not considered to be good coding style,
+ * and may not be supported in a future release of SWT.</b>
+ * </p>
+ *
+ * @param display the display to create the shell on
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
+ * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
+ * </ul>
*/
public Shell (Display display) {
this (display, SWT.SHELL_TRIM);
}
-/**
- * Constructs a new instance of this class given the display
- * to create it on and a style value describing its behavior
- * and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * 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 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>
+/**
+ * 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 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>
*/
public Shell (Display display, int style) {
this (display, null, style, 0);
@@ -192,58 +194,58 @@ Shell (Display display, Shell parent, int style, int handle) {
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>
+/**
+ * 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);
}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</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 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>
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 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>
*/
public Shell (Shell parent, int style) {
this (parent != null ? parent.getDisplay () : null, parent, style, 0);
@@ -263,28 +265,27 @@ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener(SWT.Activate,typedListener);
@@ -375,21 +376,20 @@ void adjustTrim () {
return;
}
}
-/**
- * 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>
- */
+/**
+ * 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>
+ */
public void close () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
closeWidget ();
}
void closeWidget () {
@@ -413,12 +413,11 @@ void closeWidget () {
if (event.doit && !isDisposed ()) dispose ();
}
public Rectangle computeTrim (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Rectangle trim = super.computeTrim (x, y, width, height);
int trimWidth = trimWidth (), trimHeight = trimHeight ();
trim.x -= trimWidth / 2; trim.y -= trimHeight - (trimWidth / 2);
- trim.width += trimWidth; trim.height += trimHeight;
+ trim.width += trimWidth; trim.height += trimHeight + imeHeight ();
return trim;
}
void createHandle (int index) {
@@ -459,7 +458,7 @@ void createHandle (int index) {
byte [] buffer = {(byte)' ', 0, 0, 0};
int ptr = OS.XtMalloc (buffer.length);
OS.memmove (ptr, buffer, buffer.length);
- int [] argList = {
+ int [] argList1 = {
OS.XmNmwmInputMode, inputMode,
OS.XmNmwmDecorations, decorations,
OS.XmNoverrideRedirect, (style & SWT.ON_TOP) != 0 ? 1 : 0,
@@ -469,7 +468,7 @@ void createHandle (int index) {
if (parent == null && (style & SWT.ON_TOP) == 0) {
int xDisplay = display.xDisplay;
int widgetClass = OS.TopLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (display.appName, appClass, widgetClass, xDisplay, argList, argList.length / 2);
+ shellHandle = OS.XtAppCreateShell (display.appName, appClass, widgetClass, xDisplay, argList1, argList1.length / 2);
} else {
int widgetClass = OS.TransientShellWidgetClass ();
// if ((style & SWT.ON_TOP) != 0) {
@@ -477,7 +476,7 @@ void createHandle (int index) {
// }
int parentHandle = display.shellHandle;
if (parent != null) parentHandle = parent.handle;
- shellHandle = OS.XtCreatePopupShell (appClass, widgetClass, parentHandle, argList, argList.length / 2);
+ shellHandle = OS.XtCreatePopupShell (appClass, widgetClass, parentHandle, argList1, argList1.length / 2);
}
OS.XtFree (ptr);
if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES);
@@ -493,9 +492,22 @@ void createHandle (int index) {
* on the client area.
*/
if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.RESIZE)) == 0) {
- int [] argList1 = {OS.XmNborderWidth, 1};
- OS.XtSetValues (handle, argList1, argList1.length / 2);
+ 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.
+ */
+ 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 ();
@@ -525,7 +537,7 @@ public void dispose () {
* Note: It is valid to attempt to dispose a widget
* more than once. If this happens, fail silently.
*/
- if (!isValidWidget ()) return;
+ if (isDisposed()) return;
/*
* This code is intentionally commented. On some
@@ -563,15 +575,13 @@ void enableWidget (boolean enabled) {
enableHandle (enabled, shellHandle);
}
public int getBorderWidth () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNborderWidth, 0};
OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
return argList [1];
}
public Rectangle getBounds () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
short [] root_x = new short [1], root_y = new short [1];
OS.XtTranslateCoords (scrolledHandle, (short) 0, (short) 0, root_x, root_y);
int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
@@ -586,54 +596,50 @@ 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
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return SWT.NONE;
}
public Point getLocation () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
short [] root_x = new short [1], root_y = new short [1];
OS.XtTranslateCoords (scrolledHandle, (short) 0, (short) 0, root_x, root_y);
return new Point (root_x [0], root_y [0]);
}
public Shell getShell () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int count = 0;
Shell [] shells = display.getShells ();
for (int i=0; i<shells.length; i++) {
@@ -657,8 +663,7 @@ public Shell [] getShells () {
return result;
}
public Point getSize () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
int border = argList [5];
@@ -668,8 +673,7 @@ public Point getSize () {
return new Point (width, height);
}
public boolean getVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (!OS.XtIsRealized (handle)) return false;
int xDisplay = OS.XtDisplay (handle);
if (xDisplay == 0) return false;
@@ -692,30 +696,31 @@ void hookEvents () {
OS.XtSetValues (shellHandle, argList, argList.length / 2);
int xDisplay = OS.XtDisplay (shellHandle);
if (xDisplay != 0) {
- byte [] WM_DETELE_WINDOW = Converter.wcsToMbcs (null, "WM_DELETE_WINDOW\0", false);
int atom = OS.XmInternAtom (xDisplay, WM_DETELE_WINDOW, false);
OS.XmAddWMProtocolCallback (shellHandle, atom, windowProc, SWT.Dispose);
}
}
-int inputContext () {
- //NOT DONE
- return 0;
+int imeHeight () {
+ if (!IsDBLocale) return 0;
+// realizeWidget ();
+ 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getEnabled ();
}
boolean isModal () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getVisible ();
}
void manageChildren () {
@@ -727,24 +732,23 @@ void manageChildren () {
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).
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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#setVisible
- * @see Decorations#setDefaultButton
-*/
+/**
+ * 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).
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if 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#setVisible
+ * @see Decorations#setDefaultButton
+*/
public void open () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setVisible (true);
}
int processDispose (int callData) {
@@ -846,28 +850,27 @@ void releaseWidget () {
releaseShells ();
super.releaseWidget ();
display = null;
- lastFocus = 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook(SWT.Activate, listener);
@@ -886,9 +889,46 @@ void saveBounds () {
oldX = root_x [0] - trimWidth; oldY = root_y [0] - trimHeight;
oldWidth = argList [1]; oldHeight = argList [3];
}
+
+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);
+ }
+ }
+}
+
public void setBounds (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/*
* Feature in Motif. Motif will not allow a window
* to have a zero width or zero height. The fix is
@@ -906,29 +946,27 @@ public void setBounds (int x, int y, int width, int height) {
OS.XtConfigureWidget (shellHandle, x, y, newWidth, newHeight, 0);
if (isFocus) caret.setFocus ();
}
-/**
- * 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
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
}
public void setLocation (int x, int y) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
saveBounds ();
if (!reparented) {
super.setLocation(x, y);
@@ -940,8 +978,7 @@ public void setLocation (int x, int y) {
if (isFocus) caret.setFocus ();
}
public void setMinimized (boolean minimized) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/*
* Bug in MOTIF. For some reason, the receiver does not keep the
@@ -971,8 +1008,7 @@ public void setMinimized (boolean minimized) {
}
public void setSize (int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/*
* Feature in Motif. Motif will not allow a window
* to have a zero width or zero height. The fix is
@@ -991,8 +1027,7 @@ public void setSize (int width, int height) {
if (isFocus) caret.setFocus ();
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
super.setText (string);
@@ -1001,6 +1036,7 @@ public void setText (String string) {
* 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;
@@ -1025,8 +1061,7 @@ public void setText (String string) {
OS.XtFree (ptr);
}
public void setVisible (boolean visible) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
realizeWidget ();
/* Show the shell */
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 2c78f90966..1c91455d0a 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
@@ -10,50 +10,50 @@ 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 left and right facing buttons for incrementing and
- * decrementing the value) or <code>VERTICAL</code> (which have
- * up and down facing buttons for incrementing and decrementing
- * the value).
- * </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>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- *
- * @see ScrollBar
+/**
+ * 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 left and right facing buttons for incrementing and
+ * decrementing the value) or <code>VERTICAL</code> (which have
+ * up and down facing buttons for incrementing and decrementing
+ * the value).
+ * </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>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ *
+ * @see ScrollBar
*/
public /*final*/ class Slider extends Control {
/**
@@ -120,8 +120,7 @@ public Slider (Composite parent, int style) {
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection,typedListener);
@@ -131,8 +130,7 @@ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int border = getBorderWidth ();
int width = border * 2, height = border * 2;
Display display = getDisplay ();
@@ -160,109 +158,103 @@ void createHandle (int index) {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNsliderSize, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
return argList [1];
@@ -300,66 +292,63 @@ int processSelection (int callData) {
sendEvent (SWT.Selection, event);
return 0;
}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's value changes.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see SelectionListener
- * @see #addSelectionListener
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
int [] argList = {OS.XmNmaximum, value};
Display display = getDisplay ();
@@ -368,21 +357,20 @@ public void setMaximum (int value) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
int [] argList = {
OS.XmNminimum, 0,
@@ -410,41 +398,39 @@ public void setMinimum (int value) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
int [] argList = {OS.XmNvalue, value};
Display display = getDisplay ();
@@ -453,23 +439,22 @@ public void setSelection (int value) {
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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 1) return;
int [] argList = {OS.XmNsliderSize, value};
Display display = getDisplay ();
@@ -478,30 +463,29 @@ public void setThumb (int value) {
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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (selection < 0) return;
if (minimum < 0) return;
if (maximum < 0) return;
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 e75c3305ec..1a43ec0123 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
@@ -11,20 +11,19 @@ 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>MULTI, SINGLE, READ_ONLY, WRAP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Verify</dd>
- * </dl>
- * </p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+/**
+ * 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>MULTI, SINGLE, READ_ONLY, WRAP</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>DefaultSelection, Modify, Verify</dd>
+ * </dl>
+ * </p>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
*/
-
public class Text extends Scrollable {
char echoCharacter;
boolean ignoreChange;
@@ -44,6 +43,7 @@ public class Text extends Scrollable {
LIMIT = 0x7FFFFFFF;
DELIMITER = "\n";
}
+
/**
* Constructs a new instance of this class given its parent
* and a style value describing its behavior and appearance.
@@ -75,28 +75,28 @@ public class Text extends Scrollable {
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
+
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Modify, typedListener);
@@ -126,62 +126,59 @@ public void addModifyListener (ModifyListener listener) {
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
int position = OS.XmTextGetLastPosition (handle);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
Display display = getDisplay ();
boolean warnings = display.getWarnings ();
display.setWarnings (false);
@@ -199,24 +196,22 @@ static int checkStyle (int style) {
}
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int width = wHint;
int height = hHint;
if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
@@ -276,8 +271,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
return new Point (width, height);
}
public Rectangle computeTrim (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Rectangle trim = super.computeTrim(x, y, width, height);
XRectangle rect = new XRectangle ();
OS.XmWidgetGetDisplayRect (handle, rect);
@@ -288,20 +282,19 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int xDisplay = OS.XtDisplay (handle);
if (xDisplay == 0) return;
OS.XmTextCopy (handle, OS.XtLastTimestampProcessed (xDisplay));
@@ -342,24 +335,23 @@ void createHandle (int index) {
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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int xDisplay = OS.XtDisplay (handle);
if (xDisplay == 0) return;
OS.XmTextCut (handle, OS.XtLastTimestampProcessed (xDisplay));
@@ -373,43 +365,41 @@ int defaultFont () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getLineNumber (OS.XmTextGetInsertionPosition (handle));
}
-/**
- * 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int position;
if (textVerify != null) {
position = textVerify.currInsert;
@@ -420,88 +410,83 @@ public Point getCaretLocation () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/*
* Bug in MOTIF. For some reason, when XmTextGetEditable () is called
* from inside an XmNvalueChangedCallback or XmNModifyVerifyCallback,
@@ -513,49 +498,46 @@ public boolean getEditable () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getLineNumber (echoCharacter != '\0' ? hiddenText.length () : OS.XmTextGetLastPosition (handle));
}
-/**
- * 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getFontHeight ();
}
int getLineNumber (int position) {
@@ -571,7 +553,7 @@ int getLineNumber (int position) {
* does not support multibyte locales.
*/
byte [] buffer1 = null;
- if (IsLinux) buffer1 = new byte [page + 1];
+ if (OS.IsLinux) buffer1 = new byte [page + 1];
int end = ((position + page - 1) / page) * page;
while (start < end) {
int length = page;
@@ -579,7 +561,7 @@ int getLineNumber (int position) {
if (echoCharacter != '\0') {
hiddenText.getChars (start, start + length, buffer, 0);
} else {
- if (IsLinux) {
+ if (OS.IsLinux) {
OS.XmTextGetSubstring (handle, start, length, buffer1.length, buffer1);
for (int i=0; i<length; i++) buffer [i] = (char) buffer1 [i];
} else {
@@ -593,24 +575,23 @@ int getLineNumber (int position) {
}
return count;
}
-/**
- * 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (textVerify != null) {
return new Point (textVerify.startPos, textVerify.endPos);
}
@@ -621,19 +602,18 @@ public Point getSelection () {
}
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (textVerify != null) {
return textVerify.endPos - textVerify.startPos;
}
@@ -641,19 +621,18 @@ public int getSelectionCount () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (echoCharacter != '\0' || textVerify != null) {
Point selection = getSelection ();
return getText (selection.x, selection.y);
@@ -664,45 +643,43 @@ public String getSelectionText () {
byte [] buffer = new byte [length];
OS.memmove (buffer, ptr, length);
OS.XtFree (ptr);
- return new String (Converter.mbcsToWcs (null, 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>
+ 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (echoCharacter != '\0') return hiddenText;
int ptr = OS.XmTextGetString (handle);
if (ptr == 0) return "";
@@ -710,28 +687,27 @@ public String getText () {
byte [] buffer = new byte [length];
OS.memmove (buffer, ptr, length);
OS.XtFree (ptr);
- return new String (Converter.mbcsToWcs (null, 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>
+ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int numChars = end - start + 1;
if (numChars < 0 || start < 0) return "";
if (echoCharacter != '\0') {
@@ -741,48 +717,46 @@ public String getText (int start, int end) {
byte [] buffer = new byte [length];
int code = OS.XmTextGetSubstring (handle, start, numChars, length, buffer);
if (code == OS.XmCOPY_FAILED) return "";
- char [] unicode = Converter.mbcsToWcs (null, buffer);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SINGLE) != 0) return 0;
if (scrolledHandle == 0) return 0;
int [] argList1 = {OS.XmNverticalScrollBar, 0};
@@ -792,34 +766,32 @@ public int getTopIndex () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getTopIndex () * getLineHeight ();
}
boolean getWrap () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNwordWrap, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
return argList [1] != 0;
@@ -835,29 +807,28 @@ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 (null, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
Display display = getDisplay ();
boolean warnings = display.getWarnings ();
display.setWarnings (false);
@@ -866,21 +837,20 @@ public void insert (String string) {
OS.XmTextSetInsertionPosition (handle, position);
display.setWarnings (warnings);
}
-/**
- * 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Display display = getDisplay ();
boolean warnings = display.getWarnings ();
display.setWarnings (false);
@@ -917,6 +887,12 @@ int processFocusOut () {
OS.XtSetValues (handle, argList, argList.length / 2);
return 0;
}
+int processIMEFocusIn () {
+ return 0;
+}
+int processIMEFocusOut () {
+ return 0;
+}
int processModify (int callData) {
if (!ignoreChange) super.processModify (callData);
return 0;
@@ -930,13 +906,15 @@ int processVerify (int callData) {
OS.memmove (textBlock, textVerify.text, XmTextBlockRec.sizeof);
byte [] buffer = new byte [textBlock.length];
OS.memmove (buffer, textBlock.ptr, textBlock.length);
- String text = new String (Converter.mbcsToWcs (null, buffer));
+ 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;
@@ -959,7 +937,7 @@ int processVerify (int callData) {
newText = new String (charBuffer);
}
if (newText != text) {
- byte [] buffer2 = Converter.wcsToMbcs (null, newText, true);
+ byte [] buffer2 = Converter.wcsToMbcs (codePage, newText, true);
int length = buffer2.length;
int ptr = OS.XtMalloc (length);
OS.memmove (ptr, buffer2, length);
@@ -972,91 +950,114 @@ int processVerify (int callData) {
textVerify = null;
return 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+byte [] sendIMEKeyEvent (int type, XKeyEvent xEvent) {
+ /*
+ * Bug in Motif. On Solaris and Linux, XmImMbLookupString () clears
+ * the characters from the IME. This causes tht 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.sendIMEKeyEvent (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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
/* Clear the highlight before setting the selection. */
int position = OS.XmTextGetLastPosition (handle);
// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL);
@@ -1087,7 +1088,18 @@ public void selectAll () {
* Sets the bounds.
*/
public void setBounds (int x, int y, int width, int height) {
+ /*
+ * 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);
super.setBounds (x, y, width, height);
+ display.setWarnings(warnings);
+
/*
* Bug in Motif. When the receiver is a Text widget
* (not a Text Field) and is resized to be smaller than
@@ -1103,45 +1115,43 @@ public void setBounds (int x, int y, int width, int height) {
// nWidth > inset x ifTrue: [^self].
// self showPosition: self topCharacter
}
-/**
- * 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNselectionArrayCount, doubleClick ? 4 : 1};
OS.XtSetValues (handle, argList, argList.length / 2);
}
-/**
- * Sets the echo character.
- * <p>
- * The echo character is the character that is
- * displayed when the user enters text or the
- * text is changed by the programmer.
- * </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>
+/**
+ * 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.
+ * </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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (echoCharacter == echo) return;
String newText;
if (echo == 0) {
@@ -1158,19 +1168,18 @@ public void setEchoChar (char echo) {
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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
OS.XmTextSetEditable (handle, editable);
style &= ~SWT.READ_ONLY;
if (!editable) style |= SWT.READ_ONLY;
@@ -1182,8 +1191,7 @@ public void setEditable (boolean editable) {
* Sets the redraw flag.
*/
public void setRedraw (boolean redraw) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SINGLE) != 0) return;
if (redraw) {
if (--drawCount == 0) OS.XmTextEnableRedisplay(handle);
@@ -1191,36 +1199,34 @@ public void setRedraw (boolean redraw) {
if (drawCount++ == 0) OS.XmTextDisableRedisplay(handle);
}
}
-/**
- * Sets the selection.
- * <p>
- * Indexing is zero based. The range of
- * a selection is from 0..N where N is
- * the number of characters in the widget.
- * </p><p>
- * Text selections are specified in terms of
- * caret positions. In a text widget that
- * contains N characters, there are N+1 caret
- * positions, ranging from 0..N. This differs
- * from other functions that address character
- * position such as getText () that use the
- * regular array indexing rules.
- * </p>
- *
- * @param start new caret position
- *
- * @exception 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 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 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 (int start) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
/* Clear the selection and highlight before moving the i-beam. */
int xDisplay = OS.XtDisplay (handle);
if (xDisplay == 0) return;
@@ -1236,37 +1242,35 @@ public void setSelection (int start) {
OS.XmTextSetInsertionPosition (handle, nStart);
display.setWarnings (warnings);
}
-/**
- * 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 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 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 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 (int start, int end) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
/* Clear the highlight before setting the selection. */
int position = OS.XmTextGetLastPosition (handle);
// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL);
@@ -1295,40 +1299,49 @@ public void setSelection (int start, int end) {
OS.XmTextSetInsertionPosition (handle, nEnd);
display.setWarnings (warnings);
}
-/**
- * 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 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 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
setSelection (selection.x, selection.y);
}
public void setSize (int width, int height) {
+ /*
+ * 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);
super.setSize (width, height);
+ display.setWarnings(warnings);
/*
* Bug in Motif. When the receiver is a Text widget
* (not a Text Field) and is resized to be smaller than
@@ -1344,45 +1357,43 @@ public void setSize (int width, int height) {
// nWidth > inset x ifTrue: [^self].
// self showPosition: self topCharacter
}
- /**
- * 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>
+ /**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/* Do nothing. Tabs are not supported in MOTIF. */
}
-/**
- * Sets the contents of the receiver to the given string.
- *
- * @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 to the given string.
+ *
+ * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
Display display = getDisplay ();
boolean warnings = display.getWarnings ();
display.setWarnings (false);
@@ -1394,43 +1405,41 @@ public void setText (String string) {
* it does not send a Modify to notify the application
* that the text has changed. The fix is to send the event.
*/
- if (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.
- *
- * @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>
+ 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.
+ *
+ * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SINGLE) != 0) return;
if (scrolledHandle == 0) return;
int [] argList1 = {OS.XmNverticalScrollBar, 0};
@@ -1441,30 +1450,28 @@ public void setTopIndex (int index) {
OS.XmTextScroll (handle, index - argList2 [1]);
}
void setWrap (boolean wrap) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNwordWrap, wrap ? 1 : 0};
OS.XtSetValues (handle, argList, argList.length / 2);
}
-/**
- * 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Display display = getDisplay ();
boolean warnings = display.getWarnings ();
display.setWarnings (false);
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 2bcd850d7d..b43d23c56f 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
@@ -9,57 +9,57 @@ import org.eclipse.swt.internal.motif.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
-/**
- * Instances of this class support the layout of selectable
- * tool bar items.
- * <p>
- * The item children that may be added to instances of this class
- * must be of type <code>ToolItem</code>.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add <code>Control</code> children to it,
- * or set a layout on it.
- * </p><p>
- * <dl>
- * <dt><b>Styles:</b></dt>
+/**
+ * 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</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
+ * <dt><b>Events:</b></dt>
+ * <dd>(none)</dd>
+ * </dl>
+ * <p>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+ * </p>
+ */
public /*final*/ 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.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</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
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 ToolBar (Composite parent, int style) {
super (parent, checkStyle (style));
@@ -88,8 +88,7 @@ protected void checkSubclass () {
if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int width = wHint, height = hHint;
if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
@@ -134,49 +133,47 @@ void destroyItem (ToolItem item) {
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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
ToolItem [] items = getItems ();
for (int i=0; i<items.length; i++) {
Rectangle rect = items [i].getBounds ();
@@ -185,84 +182,82 @@ public ToolItem getItem (Point pt) {
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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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;
@@ -326,6 +321,12 @@ int [] layout (int nWidth, int nHeight, boolean resize) {
return layoutHorizontal (nWidth, nHeight, resize);
}
}
+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 ();
@@ -346,14 +347,21 @@ void releaseWidget () {
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 setRedraw (boolean redraw) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (redraw) {
if (--drawCount == 0) relayout();
} else {
@@ -365,4 +373,5 @@ public void setSize (int width, int height) {
Rectangle rect = getClientArea ();
relayout (rect.width, rect.height);
}
+
}
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 b07006797f..df81e73f8f 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
@@ -33,4 +33,4 @@ public int internal_new_GC (GCData data) {
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 e3a291c072..4ea5a5c922 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
@@ -11,18 +11,18 @@ 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.
- * <p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * </p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
+/**
+ * Instances of this class represent a selectable user interface object
+ * that represents a button in a tool bar.
+ * <p>
+ * <dl>
+ * <dt><b>Styles:</b></dt>
+ * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd>
+ * <dt><b>Events:</b></dt>
+ * <dd>Selection</dd>
+ * </dl>
+ * </p>
+ * IMPORTANT: This class is <em>not</em> intended to be subclassed.
*/
public /*final*/ class ToolItem extends Item {
ToolBar parent;
@@ -32,23 +32,80 @@ public /*final*/ class ToolItem extends Item {
boolean set;
/**
-* Creates a new instance of the widget.
-*/
+ * 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
+ * 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 ToolItem (ToolBar parent, int style) {
super (parent, checkStyle (style));
this.parent = parent;
parent.createItem (this, parent.getItemCount ());
parent.relayout ();
}
+
/**
-* Creates a new instance of the widget.
-*/
+ * 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
+ * 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 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
@@ -75,8 +132,7 @@ public ToolItem (ToolBar parent, int style, int index) {
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection,typedListener);
@@ -118,6 +174,8 @@ void createHandle (int index) {
};
handle = OS.XmCreateDrawnButton (parentHandle, null, argList, argList.length / 2);
if (handle == 0) error (SWT.ERROR_NO_HANDLES);
+ int pixel = parent.getBackgroundPixel ();
+ setBackgroundPixel (pixel);
}
Point computeSize () {
@@ -142,10 +200,11 @@ Point computeSize () {
Display display = getDisplay ();
shadowThickness = Math.min (2, display.buttonShadowThickness);
}
+ final String plainText = stripMnemonicCodes(this.text);
int textWidth = 0, textHeight = 0;
- if (text.length () != 0) {
+ if (plainText.length () != 0) {
GC gc = new GC (parent);
- Point textExtent = gc.textExtent (text);
+ Point textExtent = gc.textExtent (plainText);
textWidth = textExtent.x;
textHeight = textExtent.y;
gc.dispose ();
@@ -187,43 +246,41 @@ void createWidget (int index) {
parent.relayout ();
}
public void dispose () {
- if (!isValidWidget ()) return;
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return control;
}
/**
@@ -236,29 +293,27 @@ public Control getControl () {
* @exception SWTError(ERROR_WIDGET_DISPOSED)
* when the widget has been disposed
*/
-public Image getDisabledmage () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNsensitive, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
return argList [1] != 0;
@@ -268,90 +323,85 @@ public Display getDisplay () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed.
- * </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>
+/**
+ * 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.
+ * </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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNwidth, 0};
OS.XtGetValues (handle, argList, argList.length / 2);
return argList [1];
@@ -379,24 +429,23 @@ void hookEvents () {
OS.XtAddEventHandler (handle, OS.EnterWindowMask, false, windowProc, SWT.MouseEnter);
OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, SWT.MouseExit);
}
-/**
- * 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>
+/**
+ * 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 isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getEnabled () && parent.isEnabled ();
}
void manageChildren () {
@@ -422,26 +471,25 @@ void releaseWidget () {
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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook(SWT.Selection, listener);
@@ -462,6 +510,12 @@ void selectRadio () {
item.setSelection (false);
}
}
+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);
/*
@@ -472,22 +526,25 @@ void setBounds (int x, int y, int width, int height) {
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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 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>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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);
- if (control != null && control.parent != parent) {
- error (SWT.ERROR_INVALID_PARENT);
+ 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;
@@ -495,73 +552,78 @@ public void setControl (Control control) {
control.setBounds (getBounds ());
}
}
-/**
- * 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
OS.XtSetValues (handle, argList, argList.length / 2);
}
-/**
- * Sets the receiver's disabled image to the argument, which may be
- * null indicating that no disabled image should be displayed.
- * <p>
- * The disbled image is displayed when the receiver is disabled.
- * </p>
- *
- * @param image the hot image to display on the receiver (may be null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
if ((style & SWT.SEPARATOR) != 0) return;
super.setImage (image);
Point size = computeSize ();
@@ -569,24 +631,23 @@ public void setImage (Image image) {
redraw ();
}
-/**
- * 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. When it is of type <code>TOGGLE</code>,
- * it is selected when it is pushed.
- * </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>
+/**
+ * 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. When it is of type <code>TOGGLE</code>,
+ * it is selected when it is pushed.
+ * </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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
if (selected == set) return;
set = selected;
@@ -601,8 +662,7 @@ void setSize (int width, int height) {
}
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.SEPARATOR) != 0) return;
super.setText (string);
@@ -611,35 +671,33 @@ public void setText (String string) {
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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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>
- */
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) == 0) return;
if (width < 0) return;
int [] argList = {OS.XmNheight, 0};
@@ -656,6 +714,7 @@ void setDrawPressed (boolean value) {
}
int processMouseDown (int callData) {
Display display = getDisplay ();
+// Shell shell = parent.getShell ();
display.hideToolTip ();
XButtonEvent xEvent = new XButtonEvent ();
OS.memmove (xEvent, callData, XButtonEvent.sizeof);
@@ -680,6 +739,15 @@ int processMouseDown (int callData) {
OS.memmove (callData, xEvent, XButtonEvent.sizeof);
parent.processMouseDown (callData);
+ /*
+ * 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 processMouseEnter (int callData) {
@@ -736,7 +804,7 @@ int processMouseMove (int callData) {
*/
// OS.memmove (callData, xEvent, XButtonEvent.sizeof);
// parent.processMouseMove (callData);
- parent.sendMouseEvent (SWT.MouseMove, 0, xEvent.state, xEvent);
+ parent.sendMouseEvent (SWT.MouseMove, 0, xEvent);
return 0;
}
@@ -845,10 +913,11 @@ int processPaint (int callData) {
gc.setForeground (parent.getForeground ());
}
gc.setBackground (parent.getBackground ());
-
+
+ final String plainText = stripMnemonicCodes(this.text);
int textX = 0, textY = 0, textWidth = 0, textHeight = 0;
- if (text.length () != 0) {
- Point textExtent = gc.textExtent (text);
+ if (plainText.length () != 0) {
+ Point textExtent = gc.textExtent (plainText);
textWidth = textExtent.x;
textHeight = textExtent.y;
}
@@ -876,7 +945,10 @@ int processPaint (int callData) {
if ((style & SWT.DROP_DOWN) != 0) {
textX -= 6; imageX -=6;
}
- if (textWidth > 0) gc.drawText(text, textX, textY, false);
+ if (textWidth > 0) {
+ /* To display the mnemonic underscore we'll want to use XmStringDrawUnderline here */
+ gc.drawText(plainText, textX, textY, false);
+ }
if (imageWidth > 0) gc.drawImage(currentImage, imageX, imageY);
if ((style & SWT.DROP_DOWN) != 0) {
int startX = width - 12, startY = (height - 2) / 2;
@@ -892,4 +964,33 @@ int processPaint (int callData) {
}
return 0;
}
+void propagateWidget (boolean enabled) {
+ propagateHandle (enabled, handle);
+ /*
+ * ToolItems never participate in focus traversal when
+ * either enabled or disabled.
+ */
+ if (enabled) {
+ int [] argList = {OS.XmNtraversalOn, 0};
+ OS.XtSetValues (handle, argList, argList.length / 2);
+ }
+}
+/**
+ * Returns the provided string without mnemonic indicators.
+ *
+ * @param string the string to demangle
+ */
+static String stripMnemonicCodes(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);
+}
}
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 a185c1c35f..59394ba4ca 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
@@ -10,35 +10,88 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.*;
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>
+/**
+ * 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 /*final*/ class Tracker extends Widget {
Composite parent;
Display display;
boolean tracking, stippled;
Rectangle [] rectangles = new Rectangle [0];
+
/**
-* Creates a new instance of the 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
+ * 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 ();
}
+
/**
-* Creates a new instance of the widget.
-*/
+ * 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 ();
@@ -48,41 +101,42 @@ public Tracker (Display display, int style) {
this.style = 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
+
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Move,typedListener);
}
-/**
- * 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>
- */
+/**
+ * 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;
}
void drawRectangles () {
@@ -126,41 +180,44 @@ void drawRectangles () {
public Display getDisplay () {
return display;
}
-/**
- * Returns the bounds of the Rectangles being drawn.
- *
- * @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>
- */
+/**
+ * Returns the bounds of the Rectangles being drawn.
+ *
+ * @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>
- */
+/**
+ * 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;
}
-/**
- * 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>
- */
+/**
+ * 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 xDisplay = display.xDisplay;
int color = OS.XWhitePixel (xDisplay, 0);
int xWindow = OS.XDefaultRootWindow (xDisplay);
@@ -171,7 +228,6 @@ public boolean open () {
boolean cancelled = false;
tracking = true;
drawRectangles ();
- Event event = new Event ();
XAnyEvent xEvent = new XAnyEvent ();
int [] unused = new int [1];
int [] newX = new int [1], newY = new int [1], oldX = new int [1], oldY = new int [1];
@@ -190,7 +246,10 @@ public boolean open () {
rectangles [i].x += newX [0] - oldX [0];
rectangles [i].y += newY [0] - oldY [0];
}
- sendEvent (SWT.Move);
+ 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];
}
@@ -201,7 +260,7 @@ public boolean open () {
OS.memmove (keyEvent, xEvent, XKeyEvent.sizeof);
if (keyEvent.keycode != 0) {
int [] keysym = new int [1];
- OS.XLookupString (keyEvent, null, 0, keysym, unused);
+ OS.XLookupString (keyEvent, null, 0, keysym, null);
keysym [0] &= 0xFFFF;
tracking = keysym [0] != OS.XK_Escape && keysym [0] != OS.XK_Cancel;
cancelled = !tracking;
@@ -213,54 +272,55 @@ public boolean open () {
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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Move, listener);
}
-/**
- * Specify the rectangles that should be drawn.
- *
- * @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>
- */
+/**
+ * Specify the rectangles that should be drawn.
+ *
+ * @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>
- */
+/**
+ * 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;
}
}
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 d3c445d4f8..6a4772825f 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
@@ -12,32 +12,32 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.events.*;
import java.util.EventListener;
-/**
- * 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
- */
+/**
+ * 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;
@@ -67,113 +67,95 @@ public abstract class Widget {
/* Global widget variables */
static final char Mnemonic = '&';
- static final boolean IsAIX, IsSunOS, IsLinux;
+
+ /* DBCS flags */
+ static final boolean IsDBLocale;
static {
-
- /* Initialize the X/MOTIF flags */
- String osName = System.getProperty ("os.name");
- if (osName.equals("Linux")) {
- IsLinux = true;
- IsAIX = IsSunOS = false;
- } else {
- if (osName.equals("AIX")) {
- IsAIX = true;
- IsLinux = IsSunOS = false;
- } else {
- if (osName.equals("Solaris")) {
- IsSunOS = true;
- IsLinux = IsAIX = false;
- } else {
- IsLinux = IsSunOS = IsAIX = false;
- }
- }
- }
+ IsDBLocale = OS.MB_CUR_MAX () != 1;
}
Widget () {
/* Do nothing */
}
-/**
- * Constructs a new instance of this class given its parent
- * and a style value describing its behavior and appearance.
- * <p>
- * The style value is either one of the style constants defined in
- * class <code>SWT</code> which is applicable to instances of this
- * class, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>SWT</code> style constants. The class description
- * 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 #checkSubclass
- * @see #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
+ * 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 #checkSubclass
+ * @see #getStyle
*/
public Widget (Widget parent, int style) {
if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
if (!parent.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Dispose, typedListener);
@@ -192,6 +174,7 @@ static int checkBits (int style, int int0, int int1, int int2, int int3, int int
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.
@@ -238,7 +221,7 @@ protected void checkSubclass () {
*/
protected void checkWidget () {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (isDisposed ()) error (SWT.ERROR_WIDGET_DISPOSED);
}
void createHandle (int index) {
/* Do nothing */
@@ -260,98 +243,100 @@ void destroyWidget () {
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
+/**
+ * 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 (!isValidWidget ()) return;
+ 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);
}
-/**
- * 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
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
if (keys == null) return null;
for (int i=0; i<keys.length; i++) {
@@ -360,21 +345,21 @@ public Object getData (String key) {
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>
+/**
+ * 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 () {
@@ -386,29 +371,28 @@ String getName () {
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>
+/**
+ * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return style;
}
void hookEvents () {
@@ -418,16 +402,16 @@ 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
+/**
+ * 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;
@@ -450,8 +434,7 @@ public boolean isDisposed () {
* </ul>
*/
protected boolean isListening (int eventType) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return hooks (eventType);
}
boolean isValidSubclass () {
@@ -460,15 +443,13 @@ boolean isValidSubclass () {
boolean isValidThread () {
return getDisplay ().isValidThread ();
}
-boolean isValidWidget () {
- if (handle != 0) return true;
- if ((state & HANDLE) != 0) return false;
- return (state & DISPOSED) == 0;
-}
void manageChildren () {
/* Do nothing */
}
char mbcsToWcs (char ch) {
+ return mbcsToWcs (ch, null);
+}
+char mbcsToWcs (char ch, String codePage) {
int key = ch & 0xFFFF;
if (key <= 0x7F) return ch;
byte [] buffer;
@@ -480,29 +461,28 @@ char mbcsToWcs (char ch) {
buffer [0] = (byte) ((key >> 8) & 0xFF);
buffer [1] = (byte) (key & 0xFF);
}
- char [] result = Converter.mbcsToWcs (null, buffer);
+ 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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
event.type = eventType;
@@ -612,6 +592,50 @@ int processShow (int callData) {
int processVerify (int callData) {
return 0;
}
+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);
+ int [] argList = {OS.XmNtraversalOn, enabled ? 1 : 0};
+ OS.XtSetValues (widgetHandle, argList, argList.length / 2);
+}
+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);
@@ -631,27 +655,26 @@ void releaseWidget () {
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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (eventType, handler);
@@ -660,32 +683,30 @@ public void removeListener (int eventType, Listener handler) {
* Warning: API under construction.
*/
protected void removeListener (int eventType, EventListener handler) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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.
- *
- * @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 #removeDisposeListener
+/**
+ * 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 #removeDisposeListener
*/
public void removeDisposeListener (DisposeListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Dispose, listener);
@@ -694,6 +715,44 @@ void sendEvent (int eventType) {
if (eventTable == null) return;
sendEvent (eventType, new Event ());
}
+void setInputState (Event event, XInputEvent xEvent) {
+ if ((xEvent.state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
+ if ((xEvent.state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
+ if ((xEvent.state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
+ if ((xEvent.state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
+ if ((xEvent.state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
+ if ((xEvent.state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
+}
+void setKeyState (Event event, XKeyEvent xEvent) {
+ if (xEvent.keycode != 0) {
+ byte [] buffer1 = new byte [1];
+ int [] keysym = new int [1];
+ if (OS.XLookupString (xEvent, buffer1, buffer1.length, keysym, null) == 0) {
+ /*
+ * 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) {
+ if ((keysym [0] == 0x1005FF10) || (keysym [0] == 0x1005FF11)) {
+ if (keysym [0] == 0x1005FF10) keysym [0] = OS.XK_F11;
+ if (keysym [0] == 0x1005FF11) keysym [0] = OS.XK_F12;
+ }
+ }
+ /*
+ * Bug in MOTIF. On Solaris only, their 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.
+ */
+ event.keyCode = Display.translateKey (keysym [0] & 0xFFFF);
+ } else {
+ event.character = (char) buffer1 [0];
+ }
+ }
+ setInputState (event, xEvent);
+}
void sendEvent (int eventType, Event event) {
if (eventTable == null) return;
event.type = eventType;
@@ -704,59 +763,57 @@ void sendEvent (int eventType, Event event) {
}
eventTable.sendEvent (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>
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
+/**
+ * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
/* Remove the key/value pair */
@@ -803,11 +860,11 @@ public void setData (String key, Object value) {
values = newValues;
}
-/**
- * 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 () {
String string = "*Disposed*";
@@ -821,9 +878,12 @@ int topHandle () {
return handle;
}
char wcsToMbcs (char ch) {
+ return wcsToMbcs (ch, null);
+}
+char wcsToMbcs (char ch, String codePage) {
int key = ch & 0xFFFF;
if (key <= 0x7F) return ch;
- byte [] buffer = Converter.wcsToMbcs (null, new char [] {ch}, false);
+ 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));
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/library/makefile.mak b/bundles/org.eclipse.swt/Eclipse SWT/photon/library/makefile.mak
index f688b0be28..95d765cb3a 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/library/makefile.mak
+++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/library/makefile.mak
@@ -3,14 +3,15 @@
# (c) Copyright IBM Corp., 2000, 2001
# All Rights Reserved.
-maj_ver=0
-min_ver=125
+maj_ver=2
+min_ver=006
revision=0
#assumes IVE_HOME is set in the environment
DLLPREFIX=swt
-DLLNAME=lib$(DLLPREFIX)$(maj_ver)$(min_ver).so
+OS_PREFIX=qnx
+DLLNAME=lib$(DLLPREFIX)-$(OS_PREFIX)-$(maj_ver)$(min_ver).so
#DLLNAME=lib$(DLLPREFIX)$(maj_ver)$(min_ver)r$(revision).so
DEBUG =
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/library/structs.c b/bundles/org.eclipse.swt/Eclipse SWT/photon/library/structs.c
index 51f3781910..f3cc1ea76c 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/library/structs.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/library/structs.c
@@ -431,9 +431,8 @@ void cachePhKeyEvent_tFids(JNIEnv *env, jobject lpObject, PPhKeyEvent_t_FID_CACH
lpCache->key_mods = (*env)->GetFieldID(env, lpCache->clazz, "key_mods", "I");
lpCache->key_sym = (*env)->GetFieldID(env, lpCache->clazz, "key_sym", "I");
lpCache->key_cap = (*env)->GetFieldID(env, lpCache->clazz, "key_cap", "I");
- lpCache->key_scan = (*env)->GetFieldID(env, lpCache->clazz, "key_scan", "B");
- lpCache->key_zero1 = (*env)->GetFieldID(env, lpCache->clazz, "key_zero1", "B");
- lpCache->key_zero2 = (*env)->GetFieldID(env, lpCache->clazz, "key_zero2", "S");
+ lpCache->key_scan = (*env)->GetFieldID(env, lpCache->clazz, "key_scan", "S");
+ lpCache->key_zero = (*env)->GetFieldID(env, lpCache->clazz, "key_zero", "S");
lpCache->pos_x = (*env)->GetFieldID(env, lpCache->clazz, "pos_x", "S");
lpCache->pos_y = (*env)->GetFieldID(env, lpCache->clazz, "pos_y", "S");
lpCache->button_state = (*env)->GetFieldID(env, lpCache->clazz, "button_state", "S");
@@ -446,9 +445,10 @@ void getPhKeyEvent_tFields(JNIEnv *env, jobject lpObject, PhKeyEvent_t *lpStruct
lpStruct->key_mods = (*env)->GetIntField(env, lpObject, lpCache->key_mods);
lpStruct->key_sym = (*env)->GetIntField(env, lpObject, lpCache->key_sym);
lpStruct->key_cap = (*env)->GetIntField(env, lpObject, lpCache->key_cap);
- lpStruct->key_scan = (*env)->GetByteField(env, lpObject, lpCache->key_scan);
- lpStruct->key_zero1 = (*env)->GetByteField(env, lpObject, lpCache->key_zero1);
- lpStruct->key_zero2 = (*env)->GetShortField(env, lpObject, lpCache->key_zero2);
+ lpStruct->key_scan = (*env)->GetShortField(env, lpObject, lpCache->key_scan);
+#if _NTO_VERSION+0 >= 610
+ lpStruct->key_zero = (*env)->GetShortField(env, lpObject, lpCache->key_zero);
+#endif
lpStruct->pos.x = (*env)->GetShortField(env, lpObject, lpCache->pos_x);
lpStruct->pos.y = (*env)->GetShortField(env, lpObject, lpCache->pos_y);
lpStruct->button_state = (*env)->GetShortField(env, lpObject, lpCache->button_state);
@@ -460,9 +460,10 @@ void setPhKeyEvent_tFields(JNIEnv *env, jobject lpObject, PhKeyEvent_t *lpStruct
(*env)->SetIntField(env, lpObject, lpCache->key_mods, lpStruct->key_mods);
(*env)->SetIntField(env, lpObject, lpCache->key_sym, lpStruct->key_sym);
(*env)->SetIntField(env, lpObject, lpCache->key_cap, lpStruct->key_cap);
- (*env)->SetByteField(env, lpObject, lpCache->key_scan, lpStruct->key_scan);
- (*env)->SetByteField(env, lpObject, lpCache->key_zero1, lpStruct->key_zero1);
- (*env)->SetShortField(env, lpObject, lpCache->key_zero2, lpStruct->key_zero2);
+ (*env)->SetShortField(env, lpObject, lpCache->key_scan, lpStruct->key_scan);
+#if _NTO_VERSION+0 >= 610
+ (*env)->SetShortField(env, lpObject, lpCache->key_zero, lpStruct->key_zero);
+#endif
(*env)->SetShortField(env, lpObject, lpCache->pos_x, lpStruct->pos.x);
(*env)->SetShortField(env, lpObject, lpCache->pos_y, lpStruct->pos.y);
(*env)->SetShortField(env, lpObject, lpCache->button_state, lpStruct->button_state);
@@ -1201,4 +1202,151 @@ void setPhCursorDef_tFields(JNIEnv *env, jobject lpObject, PhCursorDef_t *lpStru
(*env)->SetShortField(env, lpObject, lpCache->hdr_len, lpStruct->hdr.len);
}
+void cachePgDisplaySettings_tFids(JNIEnv *env, jobject lpObject, PPgDisplaySettings_t_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+ lpCache->clazz = (*env)->GetObjectClass(env, lpObject);
+ lpCache->reserved = (*env)->GetFieldID(env, lpCache->clazz, "reserved", "[I");
+ lpCache->flags = (*env)->GetFieldID(env, lpCache->clazz, "flags", "I");
+ lpCache->refresh = (*env)->GetFieldID(env, lpCache->clazz, "refresh", "I");
+ lpCache->yres = (*env)->GetFieldID(env, lpCache->clazz, "yres", "I");
+ lpCache->xres = (*env)->GetFieldID(env, lpCache->clazz, "xres", "I");
+ lpCache->mode = (*env)->GetFieldID(env, lpCache->clazz, "mode", "I");
+ lpCache->cached = 1;
+}
+void getPgDisplaySettings_tFields(JNIEnv *env, jobject lpObject, PgDisplaySettings_t *lpStruct, PPgDisplaySettings_t_FID_CACHE lpCache)
+{
+ jintArray reserved = (*env)->GetObjectField(env, lpObject, lpCache->reserved);
+ if (reserved) {
+ jint *reserved1 = (*env)->GetIntArrayElements(env, reserved, NULL);
+ memcpy(reserved1, lpStruct->reserved, sizeof (lpStruct->reserved));
+ (*env)->ReleaseIntArrayElements(env, reserved, reserved1, JNI_ABORT);
+ }
+ lpStruct->flags = (*env)->GetIntField(env, lpObject, lpCache->flags);
+ lpStruct->refresh = (*env)->GetIntField(env, lpObject, lpCache->refresh);
+ lpStruct->yres = (*env)->GetIntField(env, lpObject, lpCache->yres);
+ lpStruct->xres = (*env)->GetIntField(env, lpObject, lpCache->xres);
+ lpStruct->mode = (*env)->GetIntField(env, lpObject, lpCache->mode);
+}
+
+void setPgDisplaySettings_tFields(JNIEnv *env, jobject lpObject, PgDisplaySettings_t *lpStruct, PPgDisplaySettings_t_FID_CACHE lpCache)
+{
+ jintArray reserved = (*env)->GetObjectField(env, lpObject, lpCache->reserved);
+ if (reserved) {
+ jint *reserved1 = (*env)->GetIntArrayElements(env, reserved, NULL);
+ memcpy(reserved1, lpStruct->reserved, sizeof (lpStruct->reserved));
+ (*env)->ReleaseIntArrayElements(env, reserved, reserved1, 0);
+ }
+ (*env)->SetIntField(env, lpObject, lpCache->flags, lpStruct->flags);
+ (*env)->SetIntField(env, lpObject, lpCache->refresh, lpStruct->refresh);
+ (*env)->SetIntField(env, lpObject, lpCache->yres, lpStruct->yres);
+ (*env)->SetIntField(env, lpObject, lpCache->xres, lpStruct->xres);
+ (*env)->SetIntField(env, lpObject, lpCache->mode, lpStruct->mode);
+}
+
+void cachePgVideoModeInfo_tFids(JNIEnv *env, jobject lpObject, PPgVideoModeInfo_t_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+ lpCache->clazz = (*env)->GetObjectClass(env, lpObject);
+ lpCache->refresh_rates = (*env)->GetFieldID(env, lpCache->clazz, "refresh_rates", "[B");
+ lpCache->mode_capabilities6 = (*env)->GetFieldID(env, lpCache->clazz, "mode_capabilities6", "I");
+ lpCache->mode_capabilities5 = (*env)->GetFieldID(env, lpCache->clazz, "mode_capabilities5", "I");
+ lpCache->mode_capabilities4 = (*env)->GetFieldID(env, lpCache->clazz, "mode_capabilities4", "I");
+ lpCache->mode_capabilities3 = (*env)->GetFieldID(env, lpCache->clazz, "mode_capabilities3", "I");
+ lpCache->mode_capabilities2 = (*env)->GetFieldID(env, lpCache->clazz, "mode_capabilities2", "I");
+ lpCache->mode_capabilities1 = (*env)->GetFieldID(env, lpCache->clazz, "mode_capabilities1", "I");
+ lpCache->type = (*env)->GetFieldID(env, lpCache->clazz, "type", "I");
+ lpCache->bytes_per_scanline = (*env)->GetFieldID(env, lpCache->clazz, "bytes_per_scanline", "S");
+ lpCache->bits_per_pixel = (*env)->GetFieldID(env, lpCache->clazz, "bits_per_pixel", "S");
+ lpCache->height = (*env)->GetFieldID(env, lpCache->clazz, "height", "S");
+ lpCache->width = (*env)->GetFieldID(env, lpCache->clazz, "width", "S");
+ lpCache->cached = 1;
+}
+
+void getPgVideoModeInfo_tFields(JNIEnv *env, jobject lpObject, PgVideoModeInfo_t *lpStruct, PPgVideoModeInfo_t_FID_CACHE lpCache)
+{
+ jbyteArray refresh_rates = (*env)->GetObjectField(env, lpObject, lpCache->refresh_rates);
+ if (refresh_rates) {
+ jbyte *refresh_rates1 = (*env)->GetByteArrayElements(env, refresh_rates, NULL);
+ memcpy(lpStruct->refresh_rates, refresh_rates1, sizeof(lpStruct->refresh_rates));
+ (*env)->ReleaseByteArrayElements(env, refresh_rates, refresh_rates1, JNI_ABORT);
+ }
+ lpStruct->mode_capabilities6 = (*env)->GetIntField(env, lpObject, lpCache->mode_capabilities6);
+ lpStruct->mode_capabilities5 = (*env)->GetIntField(env, lpObject, lpCache->mode_capabilities5);
+ lpStruct->mode_capabilities4 = (*env)->GetIntField(env, lpObject, lpCache->mode_capabilities4);
+ lpStruct->mode_capabilities3 = (*env)->GetIntField(env, lpObject, lpCache->mode_capabilities3);
+ lpStruct->mode_capabilities2 = (*env)->GetIntField(env, lpObject, lpCache->mode_capabilities2);
+ lpStruct->mode_capabilities1 = (*env)->GetIntField(env, lpObject, lpCache->mode_capabilities1);
+ lpStruct->type = (*env)->GetIntField(env, lpObject, lpCache->type);
+ lpStruct->bytes_per_scanline = (*env)->GetShortField(env, lpObject, lpCache->bytes_per_scanline);
+ lpStruct->bits_per_pixel = (*env)->GetShortField(env, lpObject, lpCache->bits_per_pixel);
+ lpStruct->height = (*env)->GetShortField(env, lpObject, lpCache->height);
+ lpStruct->width = (*env)->GetShortField(env, lpObject, lpCache->width);
+}
+
+void setPgVideoModeInfo_tFields(JNIEnv *env, jobject lpObject, PgVideoModeInfo_t *lpStruct, PPgVideoModeInfo_t_FID_CACHE lpCache)
+{
+ jbyteArray refresh_rates = (*env)->GetObjectField(env, lpObject, lpCache->refresh_rates);
+ if (refresh_rates) {
+ jbyte *refresh_rates1 = (*env)->GetByteArrayElements(env, refresh_rates, NULL);
+ memcpy(refresh_rates1, lpStruct->refresh_rates, sizeof(lpStruct->refresh_rates));
+ (*env)->ReleaseByteArrayElements(env, refresh_rates, refresh_rates1, 0);
+ }
+ (*env)->SetIntField(env, lpObject, lpCache->mode_capabilities6, lpStruct->mode_capabilities6);
+ (*env)->SetIntField(env, lpObject, lpCache->mode_capabilities5, lpStruct->mode_capabilities5);
+ (*env)->SetIntField(env, lpObject, lpCache->mode_capabilities4, lpStruct->mode_capabilities4);
+ (*env)->SetIntField(env, lpObject, lpCache->mode_capabilities3, lpStruct->mode_capabilities3);
+ (*env)->SetIntField(env, lpObject, lpCache->mode_capabilities2, lpStruct->mode_capabilities2);
+ (*env)->SetIntField(env, lpObject, lpCache->mode_capabilities1, lpStruct->mode_capabilities1);
+ (*env)->SetIntField(env, lpObject, lpCache->type, lpStruct->type);
+ (*env)->SetShortField(env, lpObject, lpCache->bytes_per_scanline, lpStruct->bytes_per_scanline);
+ (*env)->SetShortField(env, lpObject, lpCache->bits_per_pixel, lpStruct->bits_per_pixel);
+ (*env)->SetShortField(env, lpObject, lpCache->height, lpStruct->height);
+ (*env)->SetShortField(env, lpObject, lpCache->width, lpStruct->width);
+}
+
+void cachePhClipHeaderFids(JNIEnv *env, jobject lpObject, PPhClipHeader_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+ lpCache->clazz = (*env)->GetObjectClass(env, lpObject);
+ lpCache->data = (*env)->GetFieldID(env, lpCache->clazz, "data", "I");
+ lpCache->length = (*env)->GetFieldID(env, lpCache->clazz, "length", "S");
+ lpCache->type_7 = (*env)->GetFieldID(env, lpCache->clazz, "type_7", "B");
+ lpCache->type_6 = (*env)->GetFieldID(env, lpCache->clazz, "type_6", "B");
+ lpCache->type_5 = (*env)->GetFieldID(env, lpCache->clazz, "type_5", "B");
+ lpCache->type_4 = (*env)->GetFieldID(env, lpCache->clazz, "type_4", "B");
+ lpCache->type_3 = (*env)->GetFieldID(env, lpCache->clazz, "type_3", "B");
+ lpCache->type_2 = (*env)->GetFieldID(env, lpCache->clazz, "type_2", "B");
+ lpCache->type_1 = (*env)->GetFieldID(env, lpCache->clazz, "type_1", "B");
+ lpCache->type_0 = (*env)->GetFieldID(env, lpCache->clazz, "type_0", "B");
+ lpCache->cached = 1;
+}
+
+void getPhClipHeaderFields(JNIEnv *env, jobject lpObject, PhClipHeader *lpStruct, PPhClipHeader_FID_CACHE lpCache)
+{
+ lpStruct->data = (void *)(*env)->GetIntField(env, lpObject, lpCache->data);
+ lpStruct->length = (*env)->GetShortField(env, lpObject, lpCache->length);
+ lpStruct->type[7] = (*env)->GetByteField(env, lpObject, lpCache->type_7);
+ lpStruct->type[6] = (*env)->GetByteField(env, lpObject, lpCache->type_6);
+ lpStruct->type[5] = (*env)->GetByteField(env, lpObject, lpCache->type_5);
+ lpStruct->type[4] = (*env)->GetByteField(env, lpObject, lpCache->type_4);
+ lpStruct->type[3] = (*env)->GetByteField(env, lpObject, lpCache->type_3);
+ lpStruct->type[2] = (*env)->GetByteField(env, lpObject, lpCache->type_2);
+ lpStruct->type[1] = (*env)->GetByteField(env, lpObject, lpCache->type_1);
+ lpStruct->type[0] = (*env)->GetByteField(env, lpObject, lpCache->type_0);
+}
+
+void setPhClipHeaderFields(JNIEnv *env, jobject lpObject, PhClipHeader *lpStruct, PPhClipHeader_FID_CACHE lpCache)
+{
+ (*env)->SetIntField(env, lpObject, lpCache->data, (jint)lpStruct->data);
+ (*env)->SetShortField(env, lpObject, lpCache->length, lpStruct->length);
+ (*env)->SetByteField(env, lpObject, lpCache->type_7, lpStruct->type[7]);
+ (*env)->SetByteField(env, lpObject, lpCache->type_6, lpStruct->type[6]);
+ (*env)->SetByteField(env, lpObject, lpCache->type_5, lpStruct->type[5]);
+ (*env)->SetByteField(env, lpObject, lpCache->type_4, lpStruct->type[4]);
+ (*env)->SetByteField(env, lpObject, lpCache->type_3, lpStruct->type[3]);
+ (*env)->SetByteField(env, lpObject, lpCache->type_2, lpStruct->type[2]);
+ (*env)->SetByteField(env, lpObject, lpCache->type_1, lpStruct->type[1]);
+ (*env)->SetByteField(env, lpObject, lpCache->type_0, lpStruct->type[0]);
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/library/structs.h b/bundles/org.eclipse.swt/Eclipse SWT/photon/library/structs.h
index 38be26ebdc..0ed83a42a4 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/library/structs.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/library/structs.h
@@ -39,7 +39,10 @@
PtColorSelectInfo_t_FID_CACHE PtColorSelectInfo_tFc; \
PhRegion_t_FID_CACHE PhRegion_tFc; \
PtContainerCallback_t_FID_CACHE PtContainerCallback_tFc; \
- PhCursorDef_t_FID_CACHE PhCursorDef_tFc;
+ PhCursorDef_t_FID_CACHE PhCursorDef_tFc; \
+ PgDisplaySettings_t_FID_CACHE PgDisplaySettings_tFc; \
+ PgVideoModeInfo_t_FID_CACHE PgVideoModeInfo_tFc; \
+ PhClipHeader_FID_CACHE PhClipHeaderFc;
/* PhPoint_t struct */
typedef struct PhPoint_t_FID_CACHE {
@@ -162,7 +165,7 @@ void setPhPointerEvent_tFields(JNIEnv *env, jobject lpObject, PhPointerEvent_t *
typedef struct PhKeyEvent_t_FID_CACHE {
int cached;
jclass clazz;
- jfieldID key_flags, key_mods, key_sym, key_cap, key_scan, key_zero1, key_zero2, pos_x, pos_y, button_state;
+ jfieldID key_flags, key_mods, key_sym, key_cap, key_scan, key_zero, pos_x, pos_y, button_state;
} PhKeyEvent_t_FID_CACHE;
typedef PhKeyEvent_t_FID_CACHE *PPhKeyEvent_t_FID_CACHE;
@@ -326,4 +329,40 @@ void cachePhCursorDef_tFids(JNIEnv *env, jobject lpObject, PPhCursorDef_t_FID_CA
void getPhCursorDef_tFields(JNIEnv *env, jobject lpObject, PhCursorDef_t *lpStruct, PPhCursorDef_t_FID_CACHE lpCache);
void setPhCursorDef_tFields(JNIEnv *env, jobject lpObject, PhCursorDef_t *lpStruct, PPhCursorDef_t_FID_CACHE lpCache);
+/* PgDisplaySettings_t struct */
+typedef struct PgDisplaySettings_t_FID_CACHE {
+ int cached;
+ jclass clazz;
+ jfieldID reserved, flags, refresh, yres, xres, mode;
+} PgDisplaySettings_t_FID_CACHE;
+typedef PgDisplaySettings_t_FID_CACHE *PPgDisplaySettings_t_FID_CACHE;
+
+void cachePgDisplaySettings_tFids(JNIEnv *env, jobject lpObject, PPgDisplaySettings_t_FID_CACHE lpCache);
+void getPgDisplaySettings_tFields(JNIEnv *env, jobject lpObject, PgDisplaySettings_t *lpStruct, PPgDisplaySettings_t_FID_CACHE lpCache);
+void setPgDisplaySettings_tFields(JNIEnv *env, jobject lpObject, PgDisplaySettings_t *lpStruct, PPgDisplaySettings_t_FID_CACHE lpCache);
+
+typedef struct PgVideoModeInfo_t_FID_CACHE {
+ int cached;
+ jclass clazz;
+ jfieldID refresh_rates, mode_capabilities6, mode_capabilities5, mode_capabilities4, mode_capabilities3, mode_capabilities2, mode_capabilities1, type, bytes_per_scanline, bits_per_pixel, height, width;
+} PgVideoModeInfo_t_FID_CACHE;
+typedef PgVideoModeInfo_t_FID_CACHE *PPgVideoModeInfo_t_FID_CACHE;
+
+void cachePgVideoModeInfo_tFids(JNIEnv *env, jobject lpObject, PPgVideoModeInfo_t_FID_CACHE lpCache);
+void getPgVideoModeInfo_tFields(JNIEnv *env, jobject lpObject, PgVideoModeInfo_t *lpStruct, PPgVideoModeInfo_t_FID_CACHE lpCache);
+void setPgVideoModeInfo_tFields(JNIEnv *env, jobject lpObject, PgVideoModeInfo_t *lpStruct, PPgVideoModeInfo_t_FID_CACHE lpCache);
+
+/* PhClipHeader struct */
+typedef struct PhClipHeader_FID_CACHE {
+ int cached;
+ jclass clazz;
+ jfieldID data, length, type_7, type_6, type_5, type_4, type_3, type_2, type_1, type_0;
+} PhClipHeader_FID_CACHE;
+typedef PhClipHeader_FID_CACHE *PPhClipHeader_FID_CACHE;
+
+void cachePhClipHeaderFids(JNIEnv *env, jobject lpObject, PPhClipHeader_FID_CACHE lpCache);
+void getPhClipHeaderFields(JNIEnv *env, jobject lpObject, PhClipHeader *lpStruct, PPhClipHeader_FID_CACHE lpCache);
+void setPhClipHeaderFields(JNIEnv *env, jobject lpObject, PhClipHeader *lpStruct, PPhClipHeader_FID_CACHE lpCache);
+
+
#endif // INC_structs_H
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/library/swt.c b/bundles/org.eclipse.swt/Eclipse SWT/photon/library/swt.c
index 8dbd9a0ed3..72d91f66b4 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/library/swt.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/library/swt.c
@@ -453,6 +453,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PgDrawArc
}
if (radii) {
lpRadii1 = &radii1;
+ cachePhPoint_tFids(env, radii, &PGLOB(PhPoint_tFc));
getPhPoint_tFields(env, radii, lpRadii1, &PGLOB(PhPoint_tFc));
}
return (jint) PgDrawArc(lpCenter1, lpRadii1, start, end, flags);
@@ -480,6 +481,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PgDrawEllipse
}
if (radii) {
lpRadii1 = &radii1;
+ cachePhPoint_tFids(env, radii, &PGLOB(PhPoint_tFc));
getPhPoint_tFields(env, radii, lpRadii1, &PGLOB(PhPoint_tFc));
}
return (jint) PgDrawEllipse(lpCenter1, lpRadii1, flags);
@@ -487,6 +489,47 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PgDrawEllipse
/*
* Class: org_eclipse_swt_internal_photon_OS
+ * Method: PgDrawGradient
+ * Signature: (Lorg/eclipse/swt/photon/PhPoint_t;Lorg/eclipse/swt/photon/PhPoint_t;IIIIIIII[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PgDrawGradient
+ (JNIEnv *env, jobject that, jobject ul, jobject lr, jint gradient_type, jint transition_type, jint num_color_pts, jint color1, jint color2, jint color3, jint color4, jint table_size, jbyteArray transition_table)
+{
+ DECL_GLOB(pGlob)
+ jbyte *transition_table1=NULL;
+ PhPoint_t ul1, *lpUl1 = NULL, lr1, *lpLr1 = NULL;
+ jint result;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "PgDrawGradient\n");
+#endif
+
+ if (ul) {
+ lpUl1 = &ul1;
+ cachePhPoint_tFids(env, ul, &PGLOB(PhPoint_tFc));
+ getPhPoint_tFields(env, ul, lpUl1, &PGLOB(PhPoint_tFc));
+ }
+ if (lr) {
+ lpLr1 = &lr1;
+ cachePhPoint_tFids(env, ul, &PGLOB(PhPoint_tFc));
+ getPhPoint_tFields(env, lr, lpLr1, &PGLOB(PhPoint_tFc));
+ }
+ if (transition_table)
+ transition_table1 = (*env)->GetByteArrayElements(env, transition_table, NULL);
+
+ result = (jint) PgDrawGradient(lpUl1, lpLr1,
+ (unsigned long) gradient_type, (unsigned long) transition_type, (unsigned long) num_color_pts,
+ (PgColor_t) color1, (PgColor_t) color2, (PgColor_t) color3, (PgColor_t) color4,
+ (unsigned long) table_size, (unsigned char*) transition_table1);
+
+ if (transition_table)
+ (*env)->ReleaseByteArrayElements(env, transition_table, transition_table1, 0);
+
+ return result;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
* Method: PgDrawRoundRect
* Signature: (Lorg/eclipse/swt/photon/PhRect_t;Lorg/eclipse/swt/photon/PhPoint_t;I)I
*/
@@ -4551,6 +4594,21 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PtBlockAllWindows
/*
* Class: org_eclipse_swt_internal_photon_OS
+ * Method: PtBlockWindow
+ * Signature: (ISI)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PtBlockWindow
+ (JNIEnv *env, jobject that, jint window, jshort cursor, jint cursor_color)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "PtBlockWindow\n");
+#endif
+
+ return (jint) PtBlockWindow((PtWidget_t *)window, cursor, (PgColor_t)cursor_color);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
* Method: PtUnblockWindows
* Signature: (I)V
*/
@@ -6345,3 +6403,335 @@ JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PtInflateBalloon
return result;
}
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: memmove
+ * Signature: (ILorg/eclipse/swt/internal/photon/PgDisplaySettings_t;I)V
+ */
+/*
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_photon_OS_memmove__ILorg_eclipse_swt_internal_photon_PgDisplaySettings_1t_2I
+ (JNIEnv *env, jobject that, jint dest, jobject src, jint count)
+{
+ DECL_GLOB(pGlob)
+
+ PgDisplaySettings_t object, *src1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__ILorg_eclipse_swt_internal_photon_PgDisplaySettings_1t_2I\n");
+#endif
+
+ if (src) {
+ src1=&object;
+ cachePgDisplaySettings_tFids(env, src, &PGLOB(PgDisplaySettings_tFc));
+ getPgDisplaySettings_tFields(env, src, src1, &PGLOB(PgDisplaySettings_tFc));
+ }
+ memmove((void *)dest, (void *)src1, count);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/photon/PgDisplaySettings_t;II)V
+ */
+/*
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_photon_OS_memmove__Lorg_eclipse_swt_internal_photon_PgDisplaySettings_1t_2II
+ (JNIEnv *env, jobject that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ PgDisplaySettings_t object, *dest1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_photon_PgDisplaySettings_1t_2II\n");
+#endif
+
+ memmove((void *)&object, (void *)src, count);
+ if (dest) {
+ dest1=&object;
+ cachePgDisplaySettings_tFids(env, dest, &PGLOB(PgDisplaySettings_tFc));
+ setPgDisplaySettings_tFields(env, dest, dest1, &PGLOB(PgDisplaySettings_tFc));
+ }
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: memmove
+ * Signature: (ILorg/eclipse/swt/internal/photon/PgVideoModeInfo_t;I)V
+ */
+/*
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_photon_OS_memmove__ILorg_eclipse_swt_internal_photon_PgVideoModeInfo_1t_2I
+ (JNIEnv *env, jobject that, jint dest, jobject src, jint count)
+{
+ DECL_GLOB(pGlob)
+
+ PgVideoModeInfo_t object, *src1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__ILorg_eclipse_swt_internal_photon_PgVideoModeInfo_1t_2I\n");
+#endif
+
+ if (src) {
+ src1=&object;
+ cachePgVideoModeInfo_tFids(env, src, &PGLOB(PgVideoModeInfo_tFc));
+ getPgVideoModeInfo_tFields(env, src, src1, &PGLOB(PgVideoModeInfo_tFc));
+ }
+ memmove((void *)dest, (void *)src1, count);
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/photon/PgVideoModeInfo_t;II)V
+ */
+/*
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_photon_OS_memmove__Lorg_eclipse_swt_internal_photon_PgVideoModeInfo_1t_2II
+ (JNIEnv *env, jobject that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ PgVideoModeInfo_t object, *dest1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_photon_PgVideoModeInfo_1t_2II\n");
+#endif
+
+ memmove((void *)&object, (void *)src, count);
+ if (dest) {
+ dest1=&object;
+ cachePgVideoModeInfo_tFids(env, dest, &PGLOB(PgVideoModeInfo_tFc));
+ setPgVideoModeInfo_tFields(env, dest, dest1, &PGLOB(PgVideoModeInfo_tFc));
+ }
+}
+*/
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: PgGetVideoMode
+ * Signature: (Lorg/eclipse/swt/internal/photon/PgDisplaySettings_t;)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PgGetVideoMode
+ (JNIEnv *env, jobject that, jobject settings)
+{
+ DECL_GLOB(pGlob)
+ PgDisplaySettings_t settings1 = {0}, *lpSettings1=&settings1;
+ jint result;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "PgGetVideoMode\n");
+#endif
+
+ result = (jint)PgGetVideoMode(lpSettings1);
+
+ if (settings) {
+ cachePgDisplaySettings_tFids(env, settings, &PGLOB(PgDisplaySettings_tFc));
+ setPgDisplaySettings_tFields(env, settings, lpSettings1, &PGLOB(PgDisplaySettings_tFc));
+ }
+ return result;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: PgGetVideoModeInfo
+ * Signature: (ILorg/eclipse/swt/internal/photon/PgVideoModeInfo_t;)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PgGetVideoModeInfo
+ (JNIEnv *env, jobject that, jint mode_number, jobject mode_info)
+{
+ DECL_GLOB(pGlob)
+ PgVideoModeInfo_t mode_info1, *lpmode_info1=NULL;
+ jint result;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "PgGetVideoModeInfo\n");
+#endif
+
+ if (mode_info) {
+ lpmode_info1 = &mode_info1;
+ cachePgVideoModeInfo_tFids(env, mode_info, &PGLOB(PgVideoModeInfo_tFc));
+ getPgVideoModeInfo_tFields(env, mode_info, lpmode_info1, &PGLOB(PgVideoModeInfo_tFc));
+ }
+ result = (jint)PgGetVideoModeInfo(mode_number, lpmode_info1);
+
+ if (mode_info) {
+ setPgVideoModeInfo_tFields(env, mode_info, lpmode_info1, &PGLOB(PgVideoModeInfo_tFc));
+ }
+ return result;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: PhClipboardCopy
+ * Signature: (SI[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PhClipboardCopy
+ (JNIEnv *env, jclass that, jshort ig, jint n, jbyteArray clip)
+{
+ jbyte *clip1;
+ jint result;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "PhClipboardCopy\n");
+#endif
+
+ if (clip) {
+ clip1 = (*env)->GetByteArrayElements(env, clip, NULL);
+ }
+
+ result = (jint)PhClipboardCopy(ig, n, (PhClipHeader const *)clip1);
+
+ if (clip) {
+ (*env)->ReleaseByteArrayElements(env, clip, clip1, 0);
+ }
+
+ return result;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: PhClipboardPasteStart
+ * Signature: (S)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PhClipboardPasteStart
+ (JNIEnv *env, jobject that, jshort ig)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "PhClipboardPasteStart\n");
+#endif
+
+ return (jint) PhClipboardPasteStart(ig);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: PhClipboardPasteType
+ * Signature: (I[B)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PhClipboardPasteType
+ (JNIEnv *env, jobject that, jint cbdata, jbyteArray type)
+{
+ char *type1=NULL;
+ jint result;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "PhClipboardPasteType\n");
+#endif
+
+ if (type)
+ type1 = (char *)(*env)->GetByteArrayElements(env, type, NULL);
+
+ result = (jint) PhClipboardPasteType((void *)cbdata, type1);
+
+ if (type)
+ (*env)->ReleaseByteArrayElements(env, type, (jbyte *)type1, 0);
+
+ return result;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: PhClipboardPasteTypeN
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_photon_OS_PhClipboardPasteTypeN
+ (JNIEnv *env, jobject that, jint cbdata, jint n)
+{
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "PhClipboardPasteTypeN\n");
+#endif
+ return (jint) PhClipboardPasteTypeN((void *)cbdata, n);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: PhClipboardPasteFinish
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_photon_OS_PhClipboardPasteFinish
+ (JNIEnv *env, jobject that, jint cbdata)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "PhClipboardPasteFinish\n");
+#endif
+
+ PhClipboardPasteFinish((void *)cbdata);
+
+ return;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: memmove
+ * Signature: (Lorg/eclipse/swt/internal/photon/PhClipHeader;II)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_photon_OS_memmove__Lorg_eclipse_swt_internal_photon_PhClipHeader_2II
+ (JNIEnv *env, jobject that, jobject dest, jint src, jint count)
+{
+ DECL_GLOB(pGlob)
+ PhClipHeader object, *dest1=NULL;
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove__Lorg_eclipse_swt_internal_photon_PhClipHeader_2II\n");
+#endif
+
+ memmove((void *)&object, (void *)src, count);
+ if (dest) {
+ dest1=&object;
+ cachePhClipHeaderFids(env, dest, &PGLOB(PhClipHeaderFc));
+ setPhClipHeaderFields(env, dest, dest1, &PGLOB(PhClipHeaderFc));
+ }
+
+}
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: memmove
+ * Signature: ([BLorg/eclipse/swt/internal/photon/PhClipHeader;I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_photon_OS_memmove___3BLorg_eclipse_swt_internal_photon_PhClipHeader_2I
+ (JNIEnv *env, jobject that, jbyteArray dest, jobject src, jint count)
+{
+ DECL_GLOB(pGlob)
+ jbyte *dest1=NULL;
+ PhClipHeader object, *src1= NULL;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove___3BLorg_eclipse_swt_internal_photon_PhClipHeader_2I\n");
+#endif
+
+ if (src) {
+ src1=&object;
+ cachePhClipHeaderFids(env, src, &PGLOB(PhClipHeaderFc));
+ getPhClipHeaderFields(env, src, src1, &PGLOB(PhClipHeaderFc));
+ }
+
+ if (dest) {
+ dest1 = (*env)->GetByteArrayElements(env, dest, NULL);
+ }
+
+ memmove((void *)dest1, (void *)src1, count);
+
+ if (dest) {
+ (*env)->ReleaseByteArrayElements(env, dest, (jbyte *)dest1, 0);
+ }
+}
+
+/*
+ * Class: org_eclipse_swt_internal_photon_OS
+ * Method: memmove
+ * Signature: (ILorg/eclipse/swt/internal/photon/PhClipHeader;I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_photon_OS_memmove___ILorg_eclipse_swt_internal_photon_PhClipHeader_2I
+ (JNIEnv *env, jobject that, jint dest, jobject src, jint count)
+{
+ DECL_GLOB(pGlob)
+ PhClipHeader object, *src1= NULL;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "memmove___3BLorg_eclipse_swt_internal_photon_PhClipHeader_2I\n");
+#endif
+
+ if (src) {
+ src1=&object;
+ cachePhClipHeaderFids(env, src, &PGLOB(PhClipHeaderFc));
+ getPhClipHeaderFields(env, src, src1, &PGLOB(PhClipHeaderFc));
+ }
+
+ memmove((void *)dest, (void *)src1, count);
+} \ No newline at end of file
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 ff740b3b53..78f73d66a2 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
@@ -94,6 +94,13 @@ void dispose_Object (Object object) {
public Rectangle getBounds () {
checkDevice ();
+ PgDisplaySettings_t settings = new PgDisplaySettings_t ();
+ OS.PgGetVideoMode (settings);
+ return new Rectangle (0, 0, settings.xres, settings.yres);
+}
+
+public Rectangle getClientArea () {
+ checkDevice ();
PhRect_t rect = new PhRect_t ();
OS.PhWindowQueryVisible (OS.Ph_QUERY_GRAPHICS, 0, 1, rect);
int width = rect.lr_x - rect.ul_x + 1;
@@ -101,14 +108,13 @@ public Rectangle getBounds () {
return new Rectangle (rect.ul_x, rect.ul_y, width, height);
}
-public Rectangle getClientArea () {
- return getBounds ();
-}
-
public int getDepth () {
checkDevice ();
- //NOT DONE
- return 32;
+ 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 DeviceData getDeviceData () {
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 fd9902bd2b..d7c2faff92 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
@@ -8,6 +8,7 @@ package org.eclipse.swt.graphics;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.photon.*;
import org.eclipse.swt.*;
+import java.util.Locale;
public final class FontData {
@@ -34,6 +35,12 @@ public final class FontData {
* (Warning: This field is platform dependent)
*/
public byte[] stem;
+
+ /**
+ * The locale of the font
+ * (Warning: This field is platform dependent)
+ */
+ public Locale locale;
FontData(byte[] stem) {
FontQueryInfo info = new FontQueryInfo();
@@ -157,6 +164,7 @@ public int hashCode () {
}
public void setHeight(int height) {
+ if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
this.height = height;
}
@@ -164,6 +172,10 @@ public void setName(String name) {
this.name = name;
}
+public void setLocale(Locale locale) {
+ this.locale = locale;
+}
+
public void setStyle(int style) {
this.style = style;
}
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 27bfe18b80..dea53acefe 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
@@ -288,6 +288,17 @@ public void dispose() {
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.
@@ -313,21 +324,8 @@ public void drawArc (int x, int y, int width, int height, int startAngle, int en
endAngle = newStopAngle;
}
}
-
startAngle = (int) (startAngle * 65536 / 360);
endAngle = (int) (endAngle * 65536 / 360);
-
- 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);
- }
PhPoint_t center = new PhPoint_t();
center.x = (short)(x + (width / 2));
@@ -632,64 +630,55 @@ static int scaleImage(Image image, PhImage_t phImage, int srcX, int srcY, int sr
/* 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) {
-// Image.destroyImage(memImage);
-// SWT.error(SWT.ERROR_NO_HANDLES);
-// }
-// mc = OS.PmMemCreateMC(alphaImage, scale, trans);
-// if (mc == 0) {
-// Image.destroyImage(alphaImage);
-// Image.destroyImage(memImage);
-// SWT.error(SWT.ERROR_NO_HANDLES);
-// }
-// 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.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_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);
-
- // The code above can not be used because it generates an image with
- // scanline padding. It seems that Photon does not accept
- // padding in src_alpha_map, even though there is a field to specify
- // the number of bytes per line - src_alpha_map_map_bpl.
- byte[] srcAlphaData = new byte[alpha.src_alpha_map_dim_w * alpha.src_alpha_map_dim_h];
- OS.memmove(srcAlphaData, alpha.src_alpha_map_map, srcAlphaData.length);
- byte[] destAlphaData = new byte[destWidth * destHeight];
- ImageData.stretch8(srcAlphaData, alpha.src_alpha_map_dim_w, 0, 0, srcWidth, srcHeight, destAlphaData, destWidth, 0, 0, destWidth, destHeight, null, false, false);
- int ptr = OS.malloc(destAlphaData.length);
- OS.memmove(ptr, destAlphaData, destAlphaData.length);
- alpha.src_alpha_map_dim_w = (short)destWidth;
- alpha.src_alpha_map_dim_h = (short)destHeight;
- alpha.src_alpha_map_map = ptr;
+ 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);
+ }
+ 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.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);
@@ -846,15 +835,16 @@ public void drawText (String string, int x, int y, boolean isTransparent) {
string = replaceTabs(string, 8);
byte[] buffer = Converter.wcsToMbcs(null, string, false);
PhRect_t rect = new PhRect_t();
- rect.ul_x = (short)x;
- rect.ul_y = (short)y;
- rect.lr_x = (short)0xFFFF;
- rect.lr_y = (short)0xFFFF;
int flags = OS.PtEnter(0);
try {
int prevContext = setGC();
setGCClipping();
+ OS.PgExtentMultiText(rect, null, data.font, buffer, buffer.length, 0);
+ rect.lr_x += (short)(x - rect.ul_x);
+ rect.lr_y += (short)(y - rect.ul_y);
+ rect.ul_x = (short)x;
+ rect.ul_y = (short)y;
OS.PgDrawMultiTextArea(buffer, buffer.length, rect, drawFlags, OS.Pg_TEXT_LEFT | OS.Pg_TEXT_TOP, 0);
unsetGC(prevContext);
} finally {
@@ -868,6 +858,17 @@ public boolean equals (Object object) {
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.
@@ -892,23 +893,10 @@ public void fillArc (int x, int y, int width, int height, int startAngle, int en
startAngle = newStopAngle - Math.abs(endAngle);
endAngle = newStopAngle;
}
- }
-
+ }
startAngle = (int) (startAngle * 65536 / 360);
endAngle = (int) (endAngle * 65536 / 360);
- 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);
- }
-
PhPoint_t center = new PhPoint_t();
center.x = (short)(x + (width / 2));
center.y = (short)(y + (height / 2));
@@ -927,15 +915,71 @@ public void fillArc (int x, int y, int width, int height, int startAngle, int en
}
}
+/**
+ * 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 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);
- if (width != 2) radii.x--;
radii.y = (short)(y + height);
- if (height != 2) radii.y--;
int flags = OS.PtEnter(0);
try {
@@ -1371,23 +1415,19 @@ int setGC() {
void setGCClipping() {
int rid = data.rid;
int widget = data.widget;
- int topWidget = data.topWidget;
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 to the full size of
- // the region.
+ /* NOTE: PgSetRegion resets the clipping rectangle */
OS.PgSetMultiClip(data.clipRectsCount, data.clipRects);
if (widget == 0) return;
- int clip_tile = getClipping(widget, topWidget, true, true);
+ int clip_tile = getClipping(widget, data.topWidget, true, true);
int[] clip_rects_count = new int[1];
int clip_rects = OS.PhTilesToRects(clip_tile, clip_rects_count);
- OS.PhFreeTiles(clip_tile);
-
- /* PgSetClipping sets the clipping to the full region when the count is zero */
+ OS.PhFreeTiles(clip_tile);
if (clip_rects_count[0] == 0) {
clip_rects_count[0] = 1;
OS.free(clip_rects);
@@ -1400,9 +1440,12 @@ void setGCClipping() {
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) {
+ if (clipSiblings && OS.PtWidgetClass(topWidget) != OS.PtWindow()) {
int temp_widget = topWidget;
while ((temp_widget = OS.PtWidgetBrotherInFront(temp_widget)) != 0) {
if (OS.PtWidgetIsRealized(temp_widget)) {
@@ -1410,6 +1453,17 @@ int getClipping(int widget, int topWidget, boolean clipChildren, boolean clipSib
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 */
@@ -1426,6 +1480,17 @@ int getClipping(int widget, int topWidget, boolean clipChildren, boolean clipSib
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);
}
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 2dc3f904a3..f725ef496f 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
@@ -384,8 +384,9 @@ void init(Device device, ImageData i) {
if (i.depth == 1 || 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, ImageData.MSB_FIRST, 0, 0, i.width, i.height, null, null, null, -1, null, 0,
- img.data, img.depth, img.bytesPerLine, ImageData.MSB_FIRST, 0, 0, img.width, img.height, null, null, null,
+ i.data, i.depth, i.bytesPerLine, img.getByteOrder(), 0, 0, i.width, i.height, null, null, null,
+ ImageData.ALPHA_OPAQUE, null, 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;
@@ -410,15 +411,23 @@ void init(Device device, ImageData i) {
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;
- PaletteData palette = i.palette;
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- int order = ImageData.MSB_FIRST;
+
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:
- order = ImageData.LSB_FIRST;
+ 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) {
@@ -450,10 +459,11 @@ void init(Device device, ImageData i) {
SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
}
if (newPalette != null) {
- ImageData img = new ImageData(i.width, i.height, i.depth, newPalette);
+ ImageData img = new ImageData(i.width, i.height, newDepth, newPalette);
ImageData.blit(ImageData.BLIT_SRC,
- i.data, i.depth, i.bytesPerLine, order, 0, 0, i.width, i.height, redMask, greenMask, blueMask, -1, null, 0,
- img.data, img.depth, img.bytesPerLine, order, 0, 0, img.width, img.height, newPalette.redMask, newPalette.greenMask, newPalette.blueMask,
+ i.data, i.depth, i.bytesPerLine, i.getByteOrder(), 0, 0, i.width, i.height, redMask, greenMask, blueMask,
+ ImageData.ALPHA_OPAQUE, null, 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));
@@ -531,6 +541,7 @@ void init(Device device, ImageData i) {
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;
@@ -552,6 +563,7 @@ void init(Device device, ImageData i) {
}
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.
@@ -582,6 +594,40 @@ 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);
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 dda73e3f79..049a782935 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
@@ -29,6 +29,7 @@ Region(int 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);
if (handle == 0) return;
int tile_ptr = OS.PhGetTile();
PhTile_t tile = new PhTile_t();
@@ -44,8 +45,9 @@ public void add (Rectangle rect) {
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 == 0 || region.handle == EMPTY_REGION) 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);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/photon/OS.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/photon/OS.java
index 2c83686a4f..7e4550d33c 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/photon/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/photon/OS.java
@@ -124,6 +124,27 @@ public class OS {
// public static final int Pg_BLEND_DST_DST_ALPHA = 0x06; // (Ad,Ad,Ad,Ad)
// public static final int Pg_BLEND_DST_ONE_MINUS_DST_ALPHA = 0x07; // (1,1,1,1)-(Ad,Ad,Ad,Ad)
+// public static final int Pg_GRAD_BYTES_PER_PIXEL = 3;
+// public static final int Pg_GRAD_IMAGE_TYPE = Pg_IMAGE_DIRECT_888;
+// public static final int Pg_GRAD_BOXY = 0x80000000;
+// public static final int Pg_GRAD_NOGRADIENT = 0;
+// public static final int Pg_GRAD_VECTOR = 1;
+// public static final int Pg_GRAD_RADIAL = 2;
+ public static final int Pg_GRAD_HORIZONTAL = 3;
+ public static final int Pg_GRAD_VERTICAL = 4;
+// public static final int Pg_GRAD_FAST_VECTOR = 5;
+// public static final int Pg_GRAD_DIAGF = 6;
+// public static final int Pg_GRAD_DIAGB = 7;
+// public static final int Pg_GRAD_4POINT = 8;
+// public static final int Pg_GRAD_BOX_DIAGF = Pg_GRAD_DIAGF | Pg_GRAD_BOXY;
+// public static final int Pg_GRAD_BOX_DIAGB = Pg_GRAD_DIAGB | Pg_GRAD_BOXY;
+// public static final int Pg_GRAD_BOX_4POINT = Pg_GRAD_4POINT | Pg_GRAD_BOXY;
+// public static final int Pg_GRAD_TABLE = 100;
+ public static final int Pg_GRAD_LINEAR = 0;
+// public static final int Pg_GRAD_HILL = 1;
+// public static final int Pg_GRAD_HILL2 = 2;
+// public static final int Pg_GRAD_EXP = 3;
+
// public static final int Pt_ARG_PG_FLAGS = 64 * 1000 + 0;
// public static final int Pt_ARG_PG_CURRENT = 64 * 1000 + 1;
public static final int Pt_ARG_PG_PANEL_TITLES = 64 * 1000 + 2;
@@ -176,6 +197,11 @@ public class OS {
public static final int Pt_ARG_MODIFIER_KEYS = ( 7 * 1000 + 4 );
public static final byte [] Pg_PAT_HALF = {(byte)0xAA, (byte)0x55, (byte)0xAA, (byte)0x55, (byte)0xAA, (byte)0x55, (byte)0xAA, (byte)0x55};
+
+ public static final int Pt_ARG_BEVEL_CONTRAST = ( 2 * 1000 + 20 );
+
+ public static final int Pt_NO_PARENT = 1;
+
/*** END MANUALLY ADDED/FIXED ***/
//public static final int Aw_ARG_ONOFF_STATE = ( 5 * 1000 + 1 );
@@ -1065,7 +1091,7 @@ public static final int Pg_BITMAP_TRANSPARENT =
public static final int Ph_WM_STATE_ISICONIFIED = 0x00000040;
//public static final int Ph_WM_STATE_ISMASK = 0x0000FFFF;
public static final int Ph_WM_STATE_ISMAX = 0x00000002;
-//public static final int Ph_WM_STATE_ISMAXING = 0x00004000;
+ public static final int Ph_WM_STATE_ISMAXING = 0x00004000;
//public static final int Ph_WM_STATE_ISNORMAL = 0x00000000;
//public static final int Ph_WM_STATE_ISPDM = 0x00000020;
//public static final int Ph_WM_STATE_ISREMOTE = 0x00000400;
@@ -2550,6 +2576,7 @@ public static final native int PgCreateGC (int size);
public static final native void PgDestroyGC (int GC);
public static final native int PgDrawArc (PhPoint_t center, PhPoint_t radii, int start, int end, int flags);
public static final native int PgDrawEllipse (PhPoint_t center, PhPoint_t radii, int flags);
+public static final native int PgDrawGradient (PhPoint_t ul, PhPoint_t lr, int gradient_type, int transition_type, int num_color_pts, int color1, int color2, int color3, int color4, int table_size, byte[] transition_table);
public static final native int PgDrawPolygon (short[] ptr, int num, PhPoint_t pos, int flags);
public static final native int PgDrawRoundRect (PhRect_t rect, PhPoint_t radii, int flags);
public static final native int PgDrawILine (int x1, int y1, int x2, int y2);
@@ -2710,7 +2737,6 @@ public static final native void PtListGotoPos (int widget, int pos);
public static final native int PtTextModifyText (int widget, int start, int end, int insert_pos, byte [] text, int length);
public static final native int PtTextModifyText (int widget, int start, int end, int insert_pos, int text, int length);
-public static final native int PhClipboardCopyString (short ig, byte [] string);
public static final native int PtTextGetSelection (int widget, int [] start, int [] end);
public static final native int PtTextSetSelection (int widget, int [] start, int [] end);
@@ -2806,10 +2832,8 @@ public static final native void PtWindowToBack (int widget);
public static final native void PtWindowToFront (int widget);
public static final native int PtFindDisjoint (int widget);
-//public static final native int PhClipboardCopyString (short ig, int string);
-public static final native int PhClipboardPasteString (short ig);
-
public static final native int PtBlockAllWindows(int skip, short cursor, int cursor_color);
+public static final native int PtBlockWindow(int window, short cursor, int cursor_color);
public static final native void PtUnblockWindows(int bl);
public static final native int PtNextTopLevelWidget(int widget);
public static final native int PtWindowGetState(int widget);
@@ -2924,4 +2948,24 @@ public static final native void PgSetFillTransPat (byte [] pat);
public static final native int PtInflateBalloon (int win, int me, int position, byte [] string, byte [] font, int fill, int text_color);
+//public static final native void memmove (PgDisplaySettings_t dest, int src, int size);
+//public static final native void memmove (int dest, PgDisplaySettings_t src, int size);
+
+//public static final native void memmove (PgVideoModeInfo_t dest, int src, int size);
+//public static final native void memmove (int dest, PgVideoModeInfo_t src, int size);
+
+public static final native int PgGetVideoMode (PgDisplaySettings_t settings);
+public static final native int PgGetVideoModeInfo (short mode_number, PgVideoModeInfo_t mode_info);
+
+public static final native void memmove (PhClipHeader dest, int src, int size);
+public static final native void memmove (int dest, PhClipHeader src, int size);
+public static final native void memmove (byte[] dest, PhClipHeader src, int size);
+
+public static final native int PhClipboardCopyString (short ig, byte [] string);
+public static final native int PhClipboardPasteString (short ig);
+public static final native int PhClipboardCopy (short ig, int n, byte[] clip);
+public static final native int PhClipboardPasteStart (short ig);
+public static final native int PhClipboardPasteType (int cbdata, byte[] type);
+public static final native int PhClipboardPasteTypeN (int cbdata, int n);
+public static final native void PhClipboardPasteFinish (int cbdata);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/photon/PhKeyEvent_t.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/photon/PhKeyEvent_t.java
index 1f0d2211b7..4aa5622ceb 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/photon/PhKeyEvent_t.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/internal/photon/PhKeyEvent_t.java
@@ -10,9 +10,8 @@ public class PhKeyEvent_t {
public int key_flags;
public int key_cap;
public int key_sym;
- public byte key_scan;
- public byte key_zero1;
- public short key_zero2;
+ public short key_scan;
+ public short key_zero;
// PhPoint_t pos;
public short pos_x;
public short pos_y;
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 43c4aeddc7..6cf02592ab 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
@@ -33,8 +33,7 @@ static int checkStyle (int style) {
}
public void addSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Selection,typedListener);
@@ -73,8 +72,7 @@ void click () {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int border = getBorderWidth ();
int width = border * 2, height = border * 2;
if ((style & SWT.ARROW) != 0) {
@@ -139,6 +137,7 @@ void createHandle (int index) {
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,
};
@@ -158,8 +157,7 @@ void createHandle (int index) {
}
public int getAlignment () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.ARROW) != 0) {
if ((style & SWT.UP) != 0) return SWT.UP;
if ((style & SWT.DOWN) != 0) return SWT.DOWN;
@@ -173,15 +171,20 @@ public int getAlignment () {
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 Image getImage () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return image;
}
public boolean getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
@@ -193,8 +196,7 @@ String getNameText () {
}
public String getText () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.ARROW) != 0) return "";
int [] args = {
OS.Pt_ARG_TEXT_STRING, 0, 0,
@@ -247,6 +249,26 @@ int processActivate (int info) {
return OS.Pt_CONTINUE;
}
+int processFocusIn (int info) {
+ int result = super.processFocusIn (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 processFocusOut (int info) {
+ int result = super.processFocusOut (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;
+}
+
int processPaint (int damage) {
if ((style & SWT.ARROW) != 0) {
OS.PtSuperClassDraw (OS.PtButton (), handle, damage);
@@ -280,8 +302,7 @@ void releaseWidget () {
}
public void removeSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
@@ -306,8 +327,7 @@ void selectRadio () {
}
public void setAlignment (int alignment) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
@@ -324,21 +344,29 @@ public void setAlignment (int alignment) {
OS.PtSetResources (handle, args.length / 3, args);
}
+void setDefault (boolean value) {
+ if ((style & SWT.PUSH) == 0) return;
+ if (getShell ().parent == null) return;
+ int [] args = {OS.Pt_ARG_BEVEL_CONTRAST, value ? 100 : 20, 0};
+ OS.PtSetResources (handle, args.length / 3, args);
+}
+
public void setSelection (boolean selected) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
int [] args = {OS.Pt_ARG_FLAGS, selected ? OS.Pt_SET : 0, OS.Pt_SET};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setImage (Image image) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.ARROW) != 0) return;
this.image = image;
int imageHandle = 0;
- if (image != null) imageHandle = copyPhImage (image.handle);
+ 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
@@ -348,8 +376,7 @@ public void setImage (Image image) {
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.ARROW) != 0) return;
char [] text = new char [string.length ()];
@@ -374,7 +401,7 @@ public void setText (String string) {
ptr2 = OS.malloc (buffer2.length);
OS.memmove (ptr2, buffer2, buffer2.length);
}
- replaceMnemonic (mnemonic, 0);
+ replaceMnemonic (mnemonic, true, true);
int [] args = {
OS.Pt_ARG_TEXT_STRING, ptr, 0,
OS.Pt_ARG_LABEL_TYPE, OS.Pt_Z_STRING, 0,
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 24007b320d..4c53438196 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
@@ -21,8 +21,7 @@ public Canvas (Composite parent, int style) {
}
public Caret getCaret () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return caret;
}
@@ -92,6 +91,7 @@ int processMouse (int info) {
}
public void redraw () {
+ checkWidget();
boolean isVisible = caret != null && caret.isVisible ();
if (isVisible) caret.hideCaret ();
super.redraw ();
@@ -99,6 +99,7 @@ public void redraw () {
}
public void redraw (int x, int y, int width, int height, boolean all) {
+ checkWidget();
boolean isVisible = caret != null && caret.isVisible ();
if (isVisible) caret.hideCaret ();
super.redraw (x, y, width, height, all);
@@ -115,8 +116,7 @@ void releaseWidget () {
}
public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (width <= 0 || height <= 0) return;
int deltaX = destX - x, deltaY = destY - y;
if (deltaX == 0 && deltaY == 0) return;
@@ -130,8 +130,7 @@ public void scroll (int destX, int destY, int x, int y, int width, int height, b
}
void setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
boolean isVisible = (caret != null) && (caret.isVisible ());
if (isVisible) caret.hideCaret ();
super.setBounds (x, y, width, height, move, resize);
@@ -139,15 +138,17 @@ void setBounds (int x, int y, int width, int height, boolean move, boolean resiz
}
public void setCaret (Caret caret) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Caret newCaret = caret;
Caret oldCaret = this.caret;
this.caret = newCaret;
if (isFocusControl ()) {
if (oldCaret != null) oldCaret.killFocus ();
- if (newCaret != null) newCaret.setFocus ();
+ if (newCaret != null) {
+ if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ newCaret.setFocus ();
+ }
}
}
-}
+}
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 5d6a427547..478d68fc86 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
@@ -11,6 +11,7 @@ import org.eclipse.swt.graphics.*;
public /*final*/ class Caret extends Widget {
Canvas parent;
+ Image image;
int x, y, width, height;
boolean moved, resized;
boolean isVisible, isShowing;
@@ -53,17 +54,25 @@ boolean drawCaret () {
OS.PgSetRegion (OS.PtWidgetRid (handle));
OS.PgSetDrawMode (OS.Pg_DRAWMODE_XOR);
OS.PgSetFillColor (color);
- int nWidth = width;
+ 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 + height - 1, OS.Pg_DRAW_FILL);
+ OS.PgDrawIRect (x, y, x + nWidth - 1, y + nHeight - 1, OS.Pg_DRAW_FILL);
OS.PgSetGC (prevContext);
OS.PgDestroyGC (phGC);
return true;
}
public Rectangle getBounds () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (image != null) {
+ Rectangle rect = image.getBounds ();
+ return new Rectangle (x, y, rect.width, rect.height);
+ }
return new Rectangle (x, y, width, height);
}
@@ -74,32 +83,36 @@ public Display getDisplay () {
}
public Font getFont () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent.getFont ();
}
+public Image getImage () {
+ checkWidget();
+ return image;
+}
+
public Point getLocation () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return new Point (x, y);
}
public Canvas getParent () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent;
}
public Point getSize () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (image != null) {
+ Rectangle rect = image.getBounds ();
+ return new Point (rect.width, rect.height);
+ }
return new Point (width, height);
}
public boolean getVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return isVisible;
}
@@ -112,8 +125,7 @@ boolean hideCaret () {
}
public boolean isVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return isVisible && parent.isVisible () && parent.hasFocus ();
}
@@ -137,11 +149,11 @@ void releaseWidget () {
// display.setCurrentCaret (null);
// }
parent = null;
+ image = null;
}
public void setBounds (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
boolean samePosition, sameExtent, showing;
samePosition = (this.x == x) && (this.y == y);
sameExtent = (this.width == width) && (this.height == height);
@@ -172,39 +184,40 @@ void setFocus () {
}
public void setFont (Font font) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+}
+
+public void setImage (Image image) {
+ checkWidget();
+ if (isShowing) hideCaret ();
+ this.image = image;
+ if (isShowing) showCaret ();
}
public void setLocation (int x, int y) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setBounds (x, y, width, height);
}
public void setLocation (Point location) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
setLocation (location.x, location.y);
}
public void setSize (int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setBounds (x, y, width, height);
}
public void setSize (Point size) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
setSize (size.x, size.y);
}
public void setVisible (boolean visible) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (visible == isVisible) return;
if (isVisible = visible) {
showCaret ();
@@ -219,4 +232,4 @@ boolean showCaret () {
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 dd2d8b6b81..084d914ad7 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
@@ -48,4 +48,4 @@ 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 7fe9e578b3..39e712b69d 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
@@ -46,8 +46,7 @@ static int checkStyle (int style) {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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();
@@ -107,8 +106,7 @@ void createHandle (int index) {
}
public void deselect (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {OS.Pt_ARG_CBOX_SELECTION_ITEM, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
if (args [1] == index) {
@@ -121,8 +119,7 @@ public void deselect (int index) {
}
public void deselectAll () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {
OS.Pt_ARG_TEXT_STRING, 0, 0,
OS.Pt_ARG_CBOX_SELECTION_ITEM, 0, 0
@@ -131,8 +128,7 @@ public void deselectAll () {
}
public void add (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
byte [] buffer = Converter.wcsToMbcs (null, string, true);
int ptr = OS.malloc (buffer.length);
@@ -142,8 +138,7 @@ public void add (String string) {
}
public void add (String string, int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if (index == -1) error (SWT.ERROR_INVALID_RANGE);
byte [] buffer = Converter.wcsToMbcs (null, string, true);
@@ -160,16 +155,14 @@ public void add (String string, int index) {
}
public void addModifyListener (ModifyListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Modify, typedListener);
}
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Selection,typedListener);
@@ -181,8 +174,7 @@ protected void checkSubclass () {
}
public void clearSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
OS.PtTextSetSelection (handle, new int [] {0}, new int [] {0});
}
@@ -204,8 +196,7 @@ int focusHandle () {
}
public String getItem (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {
OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
OS.Pt_ARG_ITEMS, 0, 0,
@@ -224,23 +215,20 @@ public String getItem (int index) {
}
public int getItemCount () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 getItemHeight () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
//NOT DONE - NOT NEEDED
return 0;
}
public String [] getItems () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {
OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
OS.Pt_ARG_ITEMS, 0, 0,
@@ -257,12 +245,14 @@ public String [] getItems () {
result [i] = new String (unicode);
}
return result;
+}
+String getNameText () {
+ return getText ();
}
public Point getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
@@ -284,8 +274,7 @@ public Point getSelection () {
}
public int getSelectionIndex () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {OS.Pt_ARG_CBOX_SELECTION_ITEM, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
if (args [1] == 0) return -1;
@@ -293,8 +282,7 @@ public int getSelectionIndex () {
}
public String getText () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
if (args [1] == 0) return "";
@@ -306,8 +294,7 @@ public String getText () {
}
public int getTextHeight () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
//NOT DONE - Only works for DROP_DOWN
PhDim_t dim = new PhDim_t();
if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
@@ -320,8 +307,7 @@ public int getTextHeight () {
}
public int getTextLimit () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {OS.Pt_ARG_MAX_LENGTH, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
@@ -339,15 +325,13 @@ void hookEvents () {
}
public int indexOf (String string) {
- if (!isValidThread ()) error(SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error(SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
byte [] buffer = Converter.wcsToMbcs (null, string, true);
return OS.PtListItemPos(handle, buffer) - 1;
}
public int indexOf (String string, int start) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
// NOT DONE - start is ignored
@@ -382,8 +366,7 @@ void register () {
}
public void remove (int start, int end) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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])) {
@@ -395,8 +378,7 @@ public void remove (int start, int end) {
}
public void remove (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
@@ -405,30 +387,26 @@ public void remove (int index) {
}
public void remove (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int index = indexOf (string, 0);
if (index == -1) error (SWT.ERROR_ITEM_NOT_REMOVED);
remove (index);
}
public void removeAll () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
OS.PtListDeleteAllItems (handle);
}
public void removeModifyListener (ModifyListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Modify, listener);
}
public void removeSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
@@ -436,23 +414,20 @@ public void removeSelectionListener (SelectionListener listener) {
}
public void select (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (index < 0) return;
int [] args = new int [] {OS.Pt_ARG_CBOX_SELECTION_ITEM, index + 1, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
void setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int newHeight = ((style & SWT.DROP_DOWN) != 0) ? getTextHeight() : height;
super.setBounds (x, y, width, newHeight, move, resize);
}
public void setItem (int index, String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
@@ -467,8 +442,7 @@ public void setItem (int index, String string) {
}
public void setItems (String [] items) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
OS.PtListDeleteAllItems (handle);
int[] itemsPtr = new int [items.length];
@@ -487,15 +461,13 @@ public void setItems (String [] items) {
}
public void setSelection (Point selection) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
OS.PtTextSetSelection (handle, new int [] {selection.x}, new int [] {selection.y});
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
byte [] buffer = Converter.wcsToMbcs (null, string, true);
if ((style & SWT.READ_ONLY) != 0) {
@@ -515,8 +487,7 @@ public void setText (String string) {
}
public void setTextLimit (int limit) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
int [] args = new int [] {OS.Pt_ARG_MAX_LENGTH, limit, 0};
OS.PtSetResources (handle, args.length / 3, args);
@@ -535,4 +506,13 @@ int traversalCode (int key_sym, PhKeyEvent_t ke) {
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 true;
+ }
+ return translated;
+}
+
+}
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 b120e52b4e..d55fee222f 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
@@ -51,8 +51,7 @@ protected void checkSubclass () {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Point size;
if (layout != null) {
if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
@@ -87,21 +86,43 @@ void createScrollBars () {
}
}
+public boolean forceFocus () {
+ checkWidget();
+ /*
+ * 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 [] args = {OS.Pt_ARG_FLAGS, OS.Pt_GETS_FOCUS, OS.Pt_GETS_FOCUS};
+ OS.PtSetResources (handle, args.length / 3, args);
+ boolean result = super.forceFocus ();
+ args [1] = 0;
+ OS.PtSetResources (handle, args.length / 3, args);
+ return result;
+}
+
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 ((style & SWT.NO_BACKGROUND) != 0) {
- args = new int [] {OS.Pt_ARG_FILL_COLOR, OS.Pg_TRANSPARENT, 0};
- OS.PtSetResources(scrolledHandle, args.length / 3, args);
- }
if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
Display display = getDisplay ();
+ 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,
+ };
+ OS.PtCreateWidget (OS.PtContainer (), scrolledHandle, args.length / 3, args);
int clazz = display.PtContainer;
args = new int [] {
OS.Pt_ARG_CONTAINER_FLAGS, 0, OS.Pt_ENABLE_CUA | OS.Pt_ENABLE_CUA_ARROWS,
@@ -113,17 +134,87 @@ void createScrolledHandle (int parentHandle) {
}
public Rectangle getClientArea () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 Control [] getChildren () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return _getChildren ();
}
@@ -138,8 +229,7 @@ int getChildrenCount () {
}
public Layout getLayout () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return layout;
}
@@ -158,8 +248,7 @@ void hookEvents () {
}
public void layout () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
layout (true);
}
@@ -175,8 +264,7 @@ Point minimumSize () {
}
public void layout (boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (layout == null) return;
int count = getChildrenCount ();
if (count == 0) return;
@@ -213,7 +301,37 @@ int processMouse (int info) {
int processPaint (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 */
OS.PtSuperClassDraw (OS.PtContainer (), handle, damage);
+
+ /* Reset the clipping */
+ OS.PgSetMultiClip (0, 0);
}
}
return super.processPaint (damage);
@@ -316,6 +434,14 @@ void resizeClientArea (int width, int height) {
OS.Pt_ARG_HEIGHT, Math.max (clientHeight, 0), 0,
};
OS.PtSetResources (handle, args.length / 3, args);
+ 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);
+ args = new int [] {OS.Pt_ARG_POS, ptr, 0};
+ OS.PtSetResources (OS.PtWidgetChildBack (scrolledHandle), args.length / 3, args);
+ OS.free (ptr);
}
void setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
@@ -324,8 +450,7 @@ void setBounds (int x, int y, int width, int height, boolean move, boolean resiz
}
public void setLayout (Layout layout) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
this.layout = layout;
}
@@ -334,4 +459,4 @@ int traversalCode (int key_sym, PhKeyEvent_t ke) {
return super.traversalCode (key_sym, ke);
}
-}
+}
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 e9dd1b72c3..4b584f815a 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
@@ -28,8 +28,7 @@ public Control (Composite parent, int style) {
}
public void addControlListener(ControlListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Resize,typedListener);
@@ -37,8 +36,7 @@ public void addControlListener(ControlListener listener) {
}
public void addFocusListener (FocusListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.FocusIn,typedListener);
@@ -46,16 +44,14 @@ public void addFocusListener (FocusListener listener) {
}
public void addHelpListener (HelpListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Help, typedListener);
}
public void addKeyListener (KeyListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.KeyUp,typedListener);
@@ -63,8 +59,7 @@ public void addKeyListener (KeyListener listener) {
}
public void addMouseListener (MouseListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.MouseDown,typedListener);
@@ -73,8 +68,7 @@ public void addMouseListener (MouseListener listener) {
}
public void addMouseTrackListener (MouseTrackListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.MouseEnter,typedListener);
@@ -83,32 +77,28 @@ public void addMouseTrackListener (MouseTrackListener listener) {
}
public void addMouseMoveListener (MouseMoveListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.MouseMove,typedListener);
}
public void addPaintListener (PaintListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Paint,typedListener);
}
public void addTraverseListener (TraverseListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Traverse,typedListener);
}
public boolean forceFocus () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int shellHandle = OS.PtFindDisjoint (handle);
OS.PtWindowToFront (shellHandle);
OS.PtContainerGiveFocus (handle, null);
@@ -120,8 +110,7 @@ public Point computeSize (int wHint, int hHint) {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int width = DEFAULT_WIDTH;
int height = DEFAULT_HEIGHT;
if (wHint != SWT.DEFAULT) width = wHint;
@@ -144,16 +133,14 @@ byte [] defaultFont () {
}
public Color getBackground () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 Font getFont () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {
OS.Pt_ARG_TEXT_FONT, 0, 0,
OS.Pt_ARG_LIST_FONT, 0, 0,
@@ -175,16 +162,14 @@ public Font getFont () {
}
public Color getForeground () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_COLOR, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return Color.photon_new (getDisplay (), args [1]);
}
public int getBorderWidth () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle = topHandle ();
int [] args = {
OS.Pt_ARG_BASIC_FLAGS, 0, 0,
@@ -203,8 +188,7 @@ public int getBorderWidth () {
}
public Rectangle getBounds () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle = topHandle ();
PhArea_t area = new PhArea_t ();
OS.PtWidgetArea (topHandle, area);
@@ -218,22 +202,19 @@ public Display getDisplay () {
}
public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return (args [1] & OS.Pt_BLOCKED) == 0;
}
public Object getLayoutData () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return layoutData;
}
public Point getLocation () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle = topHandle ();
PhArea_t area = new PhArea_t ();
OS.PtWidgetArea (topHandle, area);
@@ -241,14 +222,12 @@ public Point getLocation () {
}
public Menu getMenu () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return null;
}
public Composite getParent () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent;
}
@@ -270,8 +249,7 @@ Control [] getPath () {
}
public Point getSize () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle = topHandle ();
PhArea_t area = new PhArea_t ();
OS.PtWidgetArea (topHandle, area);
@@ -279,20 +257,17 @@ public Point getSize () {
}
public String getToolTipText () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return toolTipText;
}
public Shell getShell () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent.getShell ();
}
public boolean getVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle = topHandle ();
int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
OS.PtGetResources (topHandle, args.length / 3, args);
@@ -321,7 +296,7 @@ int focusHandle () {
}
public int internal_new_GC (GCData data) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ checkWidget();
int phGC = OS.PgCreateGC(0); // NOTE: PgCreateGC ignores the parameter
if (phGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
@@ -337,31 +312,27 @@ public int internal_new_GC (GCData data) {
}
public void internal_dispose_GC (int phGC, GCData data) {
- //if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ checkWidget ();
OS.PgDestroyGC(phGC);
}
public boolean isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getEnabled () && parent.isEnabled ();
}
public boolean isFocusControl () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return hasFocus ();
}
public boolean isReparentable () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return false;
}
public boolean isVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return OS.PtWidgetIsRealized (handle);
}
@@ -370,40 +341,38 @@ Decorations menuShell () {
}
public void moveAbove (Control control) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle1 = topHandle ();
if (control == null) {
OS.PtWidgetToFront (topHandle1);
OS.PtWindowToFront (topHandle1);
return;
}
+ if (control.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
int topHandle2 = control.topHandle ();
OS.PtWidgetInsert (topHandle1, topHandle2, 0);
}
public void moveBelow (Control control) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle1 = topHandle ();
if (control == null) {
OS.PtWidgetToBack (topHandle1);
OS.PtWindowToBack (topHandle1);
return;
}
+ if (control.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
int topHandle2 = control.topHandle ();
OS.PtWidgetInsert (topHandle1, topHandle2, 1);
}
public void pack () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
pack (true);
}
public void pack (boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed));
}
@@ -509,6 +478,7 @@ int processKey (int info) {
}
}
+ /* Determine if this is a traverse event */
if ((ke.key_flags & (OS.Pk_KF_Key_Down | OS.Pk_KF_Key_Repeat)) != 0) {
/*
@@ -622,12 +592,14 @@ int processMouse (int info) {
OS.memmove (pe, data, PhPointerEvent_t.sizeof);
event.x = pe.pos_x + ev.translation_x;
event.y = pe.pos_y + ev.translation_y;
- switch (pe.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;
+ if (ev.type == OS.Ph_EV_BUT_PRESS || ev.type == OS.Ph_EV_BUT_RELEASE) {
+ switch (pe.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;
+ }
}
- setMouseState (event, pe);
+ setMouseState (ev.type, event, pe);
postEvent (event.type, event);
if (ev.type == OS.Ph_EV_BUT_PRESS && pe.click_count == 2) {
Event clickEvent = new Event ();
@@ -700,6 +672,8 @@ void realizeWidget() {
void releaseWidget () {
super.releaseWidget ();
+ if (toolTipHandle != 0) destroyToolTip (toolTipHandle);
+ toolTipHandle = 0;
if (menu != null && !menu.isDisposed ()) {
menu.dispose ();
}
@@ -709,14 +683,13 @@ void releaseWidget () {
}
public void redraw () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
OS.PtDamageWidget (handle);
}
public void redraw (int x, int y, int width, int height, boolean allChildren) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget ();
+ if (width <= 0 || height <= 0) return;
PhRect_t rect = new PhRect_t ();
rect.ul_x = (short) x;
rect.ul_y = (short) y;
@@ -726,8 +699,7 @@ public void redraw (int x, int y, int width, int height, boolean allChildren) {
}
public void removeControlListener (ControlListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Move, listener);
@@ -735,8 +707,7 @@ public void removeControlListener (ControlListener listener) {
}
public void removeFocusListener(FocusListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.FocusIn, listener);
@@ -744,16 +715,14 @@ public void removeFocusListener(FocusListener listener) {
}
public void removeHelpListener (HelpListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Help, listener);
}
public void removeKeyListener(KeyListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.KeyUp, listener);
@@ -761,8 +730,7 @@ public void removeKeyListener(KeyListener listener) {
}
public void removeMouseTrackListener(MouseTrackListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.MouseEnter, listener);
@@ -771,8 +739,7 @@ public void removeMouseTrackListener(MouseTrackListener listener) {
}
public void removeMouseListener (MouseListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.MouseDown, listener);
@@ -781,24 +748,21 @@ public void removeMouseListener (MouseListener listener) {
}
public void removeMouseMoveListener(MouseMoveListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.MouseMove, listener);
}
public void removePaintListener(PaintListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook(SWT.Paint, listener);
}
public void removeTraverseListener(TraverseListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Traverse, listener);
@@ -847,29 +811,25 @@ void setBounds (int x, int y, int width, int height, boolean move, boolean resiz
}
public void setBounds (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setBounds (x, y, width, height, true, true);
}
public void setBounds (Rectangle rect) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
setBounds (rect.x, rect.y, rect.width, rect.height);
}
public void setCapture (boolean capture) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
}
public void setCursor (Cursor cursor) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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;
}
@@ -893,8 +853,7 @@ public void setCursor (Cursor cursor) {
}
public void setEnabled (boolean enabled) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_BLOCKED, OS.Pt_BLOCKED,
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_GHOST, OS.Pt_GHOST,
@@ -903,13 +862,11 @@ public void setEnabled (boolean enabled) {
}
public boolean setFocus () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return forceFocus ();
}
void sendPaintEvent (int damage) {
-
if (!hooks(SWT.Paint)) return;
/* Translate the damage to widget coordinates */
@@ -950,18 +907,25 @@ boolean sendResize () {
}
public void setBackground (Color color) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int pixel = OS.Pt_DEFAULT_COLOR;
- if (color != null) pixel = color.handle;
+ if (color != null) {
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ pixel = color.handle;
+ }
int [] args = {OS.Pt_ARG_FILL_COLOR, pixel, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setFont (Font font) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- byte [] buffer = (font != null) ? font.handle : defaultFont ();
+ checkWidget();
+ byte[] buffer;
+ if (font != null) {
+ if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ buffer = font.handle;
+ } else {
+ buffer = defaultFont();
+ }
int ptr = OS.malloc (buffer.length);
OS.memmove (ptr, buffer, buffer.length);
int [] args = {
@@ -974,65 +938,39 @@ public void setFont (Font font) {
}
public void setForeground (Color color) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int pixel = OS.Pt_DEFAULT_COLOR;
- if (color != null) pixel = color.handle;
+ if (color != null) {
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ pixel = color.handle;
+ }
int [] args = {OS.Pt_ARG_COLOR, pixel, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
-void setKeyState(Event event, PhKeyEvent_t ke) {
- int key_mods = ke.key_mods;
- int button_state = ke.button_state;
- if ((key_mods & OS.Pk_KM_Alt) != 0) {
- if (event.type != SWT.KeyDown || event.keyCode != SWT.ALT) {
- event.stateMask |= SWT.ALT;
- }
- }
- if ((key_mods & OS.Pk_KM_Shift) != 0) {
- if (event.type != SWT.KeyDown || event.keyCode != SWT.SHIFT) {
- event.stateMask |= SWT.SHIFT;
- }
- }
- if ((key_mods & OS.Pk_KM_Ctrl) != 0) {
- if (event.type != SWT.KeyDown || event.keyCode != SWT.CONTROL) {
- 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;
- if (event.type == 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;
- }
-}
-
public void setLayoutData (Object layoutData) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
this.layoutData = layoutData;
}
public void setLocation (int x, int y) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setBounds (x, y, 0, 0, true, false);
}
public void setLocation (Point location) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
setLocation (location.x, location.y);
}
public void setMenu (Menu menu) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int flags = menu != null ? OS.Pt_MENUABLE : 0;
+ checkWidget();
+ int flags = 0;
+ if (menu != null) {
+ if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ flags = OS.Pt_MENUABLE;
+ }
int [] args = {
OS.Pt_ARG_FLAGS, flags, OS.Pt_ALL_BUTTONS | OS.Pt_MENUABLE,
};
@@ -1040,49 +978,19 @@ public void setMenu (Menu menu) {
this.menu = menu;
}
-void setMouseState(Event event, PhPointerEvent_t pe) {
- int key_mods = pe.key_mods;
- int buttons = pe.buttons;
- int button_state = pe.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;
- if (event.type == SWT.MouseDown) {
- if (buttons == OS.Ph_BUTTON_SELECT && (button_state & OS.Ph_BUTTON_SELECT) != 0) {
- event.stateMask &= ~SWT.BUTTON1;
- }
- if (buttons == OS.Ph_BUTTON_ADJUST && (button_state & OS.Ph_BUTTON_ADJUST) != 0) {
- event.stateMask &= ~SWT.BUTTON2;
- }
- if (buttons == OS.Ph_BUTTON_MENU && (button_state & OS.Ph_BUTTON_MENU) != 0) {
- event.stateMask &= ~SWT.BUTTON3;
- }
- }
- if (event.type == SWT.MouseUp) {
- 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;
- }
-}
-
public boolean setParent (Composite parent) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
return false;
}
public void setSize (Point size) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
setSize (size.x, size.y);
}
public void setRedraw (boolean redraw) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (redraw) {
OS.PtContainerRelease (handle);
} else {
@@ -1090,14 +998,12 @@ public void setRedraw (boolean redraw) {
}
}
public void setSize (int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
setBounds (0, 0, width, height, false, true);
}
public void setVisible (boolean visible) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle = topHandle ();
int [] args = {
OS.Pt_ARG_FLAGS, visible ? 0 : OS.Pt_DELAY_REALIZE, OS.Pt_DELAY_REALIZE,
@@ -1113,8 +1019,7 @@ public void setVisible (boolean visible) {
}
public void setToolTipText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
toolTipText = string;
}
@@ -1139,16 +1044,14 @@ void sort (int [] items) {
}
public Point toControl (Point point) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
short [] x = new short [1], y = new short [1];
OS.PtGetAbsPosition (handle, x, y);
return new Point (point.x - x [0], point.y - y [0]);
}
public Point toDisplay (Point point) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
short [] x = new short [1], y = new short [1];
OS.PtGetAbsPosition (handle, x, y);
return new Point (point.x + x [0], point.y + y [0]);
@@ -1223,8 +1126,7 @@ int traversalCode (int key_sym, PhKeyEvent_t ke) {
}
public boolean traverse (int traversal) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (!isFocusControl () && !setFocus ()) return false;
switch (traversal) {
case SWT.TRAVERSE_ESCAPE: return traverseEscape ();
@@ -1268,8 +1170,7 @@ boolean traverseReturn () {
}
public void update () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
OS.PtFlush ();
}
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 014dca0453..9eb0d47149 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
@@ -14,6 +14,7 @@ public class Decorations extends Canvas {
Menu [] menus;
String text = "";
Image image;
+ Button defaultButton, saveDefault;
Decorations () {
/* Do nothing */
@@ -52,32 +53,27 @@ protected void checkSubclass () {
}
public Button getDefaultButton () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return null;
+ checkWidget();
+ return defaultButton;
}
public Image getImage () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return image;
}
public boolean getMaximized () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return false;
}
public boolean getMinimized () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return false;
}
public Menu getMenuBar () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return menuBar;
}
@@ -86,8 +82,7 @@ String getNameText () {
}
public String getText () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return text;
}
@@ -112,8 +107,9 @@ void releaseWidget () {
menuBar = null;
menus = null;
image = null;
- text = null;
super.releaseWidget ();
+ defaultButton = saveDefault = null;
+ text = null;
}
void remove (Menu menu) {
@@ -153,38 +149,52 @@ void resizeBounds (int width, int height) {
}
public void setDefaultButton (Button button) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- //NOT DONE
+ checkWidget();
+ setDefaultButton (button, true);
+}
+void setDefaultButton (Button button, boolean save) {
+ if (button == null) {
+ if (defaultButton == saveDefault) 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 == null) saveDefault = defaultButton;
+ if (saveDefault != null && saveDefault.isDisposed ()) saveDefault = null;
}
public void setImage (Image image) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
this.image = image;
}
public void setMaximized (boolean maximized) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
}
public void setMenuBar (Menu menu) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (menu != null && menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
//NOT DONE
}
public void setMinimized (boolean minimized) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
text = 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 4bd481006c..e9c3c630ca 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
@@ -175,13 +175,21 @@ public /*final*/ class Display extends Device {
static {
DeviceFinder = new Runnable () {
public void run () {
- CurrentDevice = getCurrent ();
- if (CurrentDevice == null) {
- CurrentDevice = getDefault ();
+ Device device = getCurrent ();
+ if (device == null) {
+ device = getDefault ();
}
+ setDevice (device);
}
};
}
+
+/*
+* TEMPORARY CODE.
+*/
+static void setDevice (Device device) {
+ CurrentDevice = device;
+}
public Display () {
this (null);
@@ -327,15 +335,6 @@ public Shell getActiveShell () {
return null;
}
-public Rectangle getBounds () {
- checkDevice ();
- PhRect_t rect = new PhRect_t ();
- OS.PhWindowQueryVisible (OS.Ph_QUERY_GRAPHICS, 0, 1, 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 Control getCursorControl () {
checkDevice ();
int ig = OS.PhInputGroup (0);
@@ -701,6 +700,7 @@ int inputProc (int data, int rcvid, int message, int size) {
}
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);
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 d030f4382b..91ec43e80b 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
@@ -122,4 +122,4 @@ 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 3737d6d850..860493f893 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
@@ -56,4 +56,4 @@ public FontData open () {
public void setFontData (FontData fontData) {
this.fontData = fontData;
}
-}
+}
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 cd6c3535ff..13abc84079 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
@@ -28,8 +28,7 @@ static int checkStyle (int style) {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Point titleSize = getTitleSize();
Point size;
if (layout != null) {
@@ -65,8 +64,7 @@ void createHandle (int index) {
}
public String getText () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_TITLE, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
if (args [1] == 0) return "";
@@ -105,8 +103,7 @@ int processPaint (int damage) {
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
int flags = OS.Pt_SHOW_TITLE | OS.Pt_ETCH_TITLE_AREA | OS.Pt_GRADIENT_TITLE_AREA;
byte [] buffer = Converter.wcsToMbcs (null, string, true);
@@ -120,4 +117,4 @@ public void setText (String string) {
OS.free (ptr);
}
-}
+}
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 0bd2a8b36b..7141de7cca 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
@@ -23,8 +23,7 @@ static int checkStyle (int style) {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) != 0) {
int border = getBorderWidth ();
int width = border * 2, height = border * 2;
@@ -121,6 +120,7 @@ void createHandle (int index) {
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);
@@ -138,6 +138,7 @@ void createHandle (int index) {
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);
@@ -145,8 +146,7 @@ void createHandle (int index) {
}
public int getAlignment () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) != 0) return 0;
if ((style & SWT.LEFT) != 0) return SWT.LEFT;
if ((style & SWT.CENTER) != 0) return SWT.CENTER;
@@ -155,8 +155,7 @@ public int getAlignment () {
}
public Image getImage () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return image;
}
@@ -165,8 +164,7 @@ String getNameText () {
}
public String getText () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) != 0) return "";
return text;
}
@@ -203,8 +201,7 @@ void releaseWidget () {
}
public void setAlignment (int alignment) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) != 0) return;
if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
@@ -221,6 +218,7 @@ void setBounds (int x, int y, int width, int height, boolean move, boolean resiz
}
public boolean setFocus () {
+ checkWidget();
return false;
}
@@ -230,12 +228,14 @@ public void setFont (Font font) {
}
public void setImage (Image image) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) != 0) return;
this.image = image;
int imageHandle = 0;
- if (image != null) imageHandle = copyPhImage (image.handle);
+ 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
@@ -245,8 +245,7 @@ public void setImage (Image image) {
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.SEPARATOR) != 0) return;
text = string;
@@ -296,7 +295,7 @@ public void setText (String string) {
ptr2 = OS.malloc (buffer2.length);
OS.memmove (ptr2, buffer2, buffer2.length);
}
- replaceMnemonic (mnemonic, 0);
+ replaceMnemonic (mnemonic, true, true);
int [] args = {
OS.Pt_ARG_TEXT_STRING, ptr, 0,
OS.Pt_ARG_LABEL_TYPE, OS.Pt_Z_STRING, 0,
@@ -307,4 +306,4 @@ public void setText (String string) {
OS.free (ptr2);
}
-}
+}
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 042df8e3d3..bf249700f2 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
@@ -22,8 +22,7 @@ static int checkStyle (int style) {
}
public void add (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
byte [] buffer = Converter.wcsToMbcs (null, string, true);
int ptr = OS.malloc (buffer.length);
@@ -33,8 +32,7 @@ public void add (String string) {
}
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Selection,typedListener);
@@ -42,8 +40,7 @@ public void addSelectionListener(SelectionListener listener) {
}
public void add (String string, int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if (index == -1) error (SWT.ERROR_INVALID_RANGE);
byte [] buffer = Converter.wcsToMbcs (null, string, true);
@@ -60,8 +57,7 @@ public void add (String string, int index) {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/**
* Feature in Photon - The preferred width calculated by
@@ -144,15 +140,13 @@ byte [] defaultFont () {
}
public void deselect (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (index < 0) return;
OS.PtListUnselectPos (handle, index + 1);
}
public void deselect (int start, int end) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (start > end) return;
if ((style & SWT.SINGLE) != 0) {
int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
@@ -168,8 +162,7 @@ public void deselect (int start, int end) {
}
public void deselect (int [] indices) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
if (indices.length == 0) return;
for (int i=0; i<indices.length; i++) {
@@ -181,8 +174,7 @@ public void deselect (int [] indices) {
}
public void deselectAll () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
int count = args [1];
@@ -196,8 +188,7 @@ public int getFocusIndex () {
}
public String getItem (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {
OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
OS.Pt_ARG_ITEMS, 0, 0,
@@ -216,16 +207,14 @@ public String getItem (int index) {
}
public int getItemCount () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 getItemHeight () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {
OS.Pt_ARG_LIST_TOTAL_HEIGHT, 0, 0,
OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
@@ -244,8 +233,7 @@ public int getItemHeight () {
}
public String [] getItems () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {
OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0,
OS.Pt_ARG_ITEMS, 0, 0,
@@ -266,8 +254,7 @@ public String [] getItems () {
}
public String [] getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] indices = getSelectionIndices ();
String [] result = new String [indices.length];
for (int i=0; i<indices.length; i++) {
@@ -277,16 +264,14 @@ public String [] getSelection () {
}
public int getSelectionCount () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 getSelectionIndex () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {
OS.Pt_ARG_LIST_SEL_COUNT, 0, 0,
OS.Pt_ARG_SELECTION_INDEXES, 0, 0,
@@ -299,8 +284,7 @@ public int getSelectionIndex () {
}
public int [] getSelectionIndices () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {
OS.Pt_ARG_LIST_SEL_COUNT, 0, 0,
OS.Pt_ARG_SELECTION_INDEXES, 0, 0,
@@ -316,8 +300,7 @@ public int [] getSelectionIndices () {
}
public int getTopIndex () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {OS.Pt_ARG_TOP_ITEM_POS, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1] - 1;
@@ -331,15 +314,13 @@ void hookEvents () {
}
public int indexOf (String string) {
- if (!isValidThread ()) error(SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error(SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
byte [] buffer = Converter.wcsToMbcs (null, string, true);
return OS.PtListItemPos(handle, buffer) - 1;
}
public int indexOf (String string, int start) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
// NOT DONE - start is ignored
@@ -347,8 +328,7 @@ public int indexOf (String string, int start) {
}
public boolean isSelected (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {
OS.Pt_ARG_LIST_SEL_COUNT, 0, 0,
OS.Pt_ARG_SELECTION_INDEXES, 0, 0,
@@ -384,8 +364,7 @@ int processSelection (int info) {
}
public void remove (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
@@ -394,16 +373,14 @@ public void remove (int index) {
}
public void remove (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int index = indexOf (string, 0);
if (index == -1) error (SWT.ERROR_ITEM_NOT_REMOVED);
remove (index);
}
public void remove (int [] indices) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
int [] newIndices = new int [indices.length];
System.arraycopy (indices, 0, newIndices, 0, indices.length);
@@ -420,8 +397,7 @@ public void remove (int [] indices) {
}
public void remove (int start, int end) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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])) {
@@ -433,14 +409,12 @@ public void remove (int start, int end) {
}
public void removeAll () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
OS.PtListDeleteAllItems (handle);
}
public void removeSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
@@ -448,8 +422,7 @@ public void removeSelectionListener(SelectionListener listener) {
}
public void select (int start, int end) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (start > end) return;
int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
@@ -470,8 +443,7 @@ public void select (int start, int end) {
}
public void select (int [] indices) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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};
@@ -489,8 +461,7 @@ public void select (int [] indices) {
}
public void select (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (index < 0) return;
int [] args = new int [] {OS.Pt_ARG_LIST_ITEM_COUNT, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
@@ -501,8 +472,7 @@ public void select (int index) {
}
public void selectAll () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
@@ -513,8 +483,7 @@ public void selectAll () {
}
public void setItem (int index, String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
@@ -529,8 +498,7 @@ public void setItem (int index, String string) {
}
public void setItems (String [] items) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
OS.PtListDeleteAllItems (handle);
int[] itemsPtr = new int [items.length];
@@ -562,8 +530,7 @@ public void setSelection(int[] indices) {
}
public void setSelection (String [] items) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.MULTI) != 0) deselectAll ();
for (int i=items.length-1; i>=0; --i) {
@@ -581,15 +548,13 @@ public void setSelection (String [] items) {
}
public void setTopIndex (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {OS.Pt_ARG_TOP_ITEM_POS, index + 1, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void showSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {
OS.Pt_ARG_LIST_SEL_COUNT, 0, 0,
OS.Pt_ARG_SELECTION_INDEXES, 0, 0,
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 535e47327f..07e7bd916f 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
@@ -54,16 +54,14 @@ static int checkStyle (int style) {
}
public void addHelpListener (HelpListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Help, typedListener);
}
public void addMenuListener (MenuListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Hide,typedListener);
@@ -91,8 +89,7 @@ void createWidget (int index) {
}
public MenuItem getDefaultItem () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return defaultItem;
}
@@ -103,16 +100,14 @@ public Display getDisplay () {
}
public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return (args [1] & OS.Pt_BLOCKED) == 0;
}
public int getItemCount () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int count = 0;
int child = OS.PtWidgetChildBack (handle);
if (child != 0 && (style & SWT.BAR) != 0) child = OS.PtWidgetChildBack (child);
@@ -124,8 +119,7 @@ public int getItemCount () {
}
public MenuItem getItem (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (index < 0) error (SWT.ERROR_INVALID_RANGE);
int i = 0;
int child = OS.PtWidgetChildBack (handle);
@@ -142,8 +136,7 @@ public MenuItem getItem (int index) {
}
public MenuItem [] getItems () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int count = 0;
int child = OS.PtWidgetChildBack (handle);
if (child != 0 && (style & SWT.BAR) != 0) child = OS.PtWidgetChildBack (child);
@@ -183,31 +176,28 @@ String getNameText () {
}
public Decorations getParent () {
+ checkWidget();
return parent;
}
public MenuItem getParentItem () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return cascade;
}
public Menu getParentMenu () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (cascade != null) return cascade.parent;
return null;
}
public Shell getShell () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent.getShell ();
}
public boolean getVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return true;
}
@@ -217,8 +207,7 @@ void hookEvents () {
}
public int indexOf (MenuItem item) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
int i = 0;
int child = OS.PtWidgetChildBack (handle);
@@ -233,16 +222,14 @@ public int indexOf (MenuItem item) {
}
public boolean isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Menu parentMenu = getParentMenu ();
if (parentMenu == null) return getEnabled ();
return getEnabled () && parentMenu.isEnabled ();
}
public boolean isVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getVisible ();
}
@@ -281,16 +268,14 @@ void releaseWidget () {
}
public void removeHelpListener (HelpListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Help, listener);
}
public void removeMenuListener (MenuListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Hide, listener);
@@ -298,14 +283,13 @@ public void removeMenuListener (MenuListener listener) {
}
public void setDefaultItem (MenuItem item) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
defaultItem = item;
}
public void setEnabled (boolean enabled) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_BLOCKED, OS.Pt_BLOCKED,
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_GHOST, OS.Pt_GHOST,
@@ -314,16 +298,15 @@ public void setEnabled (boolean enabled) {
}
public void setLocation (int x, int y) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
this.x = x; this.y = y;
hasLocation = true;
}
public void setVisible (boolean visible) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.POP_UP) == 0) return;
+ if (visible == OS.PtWidgetIsRealized (handle)) return;
if (visible) {
PhPoint_t pt = new PhPoint_t ();
pt.x = (short) x;
@@ -347,4 +330,4 @@ public void setVisible (boolean visible) {
}
}
-}
+}
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 69268fe0a7..4498d10c08 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
@@ -27,24 +27,21 @@ public MenuItem (Menu parent, int style, int index) {
}
public void addArmListener (ArmListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Arm, typedListener);
}
public void addHelpListener (HelpListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Help, typedListener);
}
public void addSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener (SWT.Selection,typedListener);
@@ -96,8 +93,7 @@ void createHandle (int index) {
}
public int getAccelerator () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return accelerator;
}
@@ -108,8 +104,7 @@ public Display getDisplay () {
}
public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
@@ -123,8 +118,7 @@ public boolean getEnabled () {
}
public Menu getMenu () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return menu;
}
@@ -134,14 +128,12 @@ String getNameText () {
}
public Menu getParent () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent;
}
public boolean getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
@@ -165,7 +157,8 @@ public boolean isEnabled () {
}
int processActivate (int info) {
- return processArm (info);
+ showMenu ();
+ return OS.Pt_CONTINUE;
}
int processSelection (int info) {
@@ -176,7 +169,32 @@ int processSelection (int info) {
return OS.Pt_CONTINUE;
}
}
- postEvent (SWT.Selection);
+ 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 (ev.type, event, pe);
+ break;
+ }
+ }
+ }
+ }
+ postEvent (SWT.Selection, event);
return OS.Pt_CONTINUE;
}
@@ -196,42 +214,8 @@ int processShow (int info) {
}
int processArm(int info) {
- if (menu != null) {
- int menuHandle = menu.handle;
- if (!OS.PtWidgetIsRealized (menuHandle)) {
- if ((parent.style & SWT.BAR) == 0) {
- int [] args = {OS.Pt_ARG_MENU_FLAGS, OS.Pt_MENU_CHILD, OS.Pt_MENU_CHILD};
- OS.PtSetResources (menuHandle, args.length / 3, args);
- }
- 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);
- args = new int [] {OS.Pt_ARG_POS, ptr, 0};
- OS.PtSetResources (menuHandle, args.length / 3, args);
- OS.free (ptr);
- } else {
- OS.PtPositionMenu (menuHandle, null);
- }
-
- menu.sendEvent (SWT.Show);
- OS.PtRealizeWidget (menuHandle);
- }
- }
+ postEvent (SWT.Arm);
+ showMenu ();
return OS.Pt_CONTINUE;
}
@@ -254,16 +238,14 @@ void releaseWidget () {
}
public void removeArmListener (ArmListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Arm, listener);
}
public void removeHelpListener (HelpListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Help, listener);
@@ -286,8 +268,7 @@ void removeAccelerator () {
}
public void removeSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
@@ -295,9 +276,7 @@ public void removeSelectionListener (SelectionListener listener) {
}
public void setAccelerator (int accelerator) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
removeAccelerator ();
this.accelerator = accelerator;
@@ -317,8 +296,7 @@ public void setAccelerator (int accelerator) {
}
public void setEnabled (boolean enabled) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
this.enabled = enabled;
int [] args = {
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_BLOCKED, OS.Pt_BLOCKED,
@@ -328,8 +306,7 @@ public void setEnabled (boolean enabled) {
}
public void setImage (Image image) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) != 0) return;
super.setImage (image);
@@ -337,12 +314,12 @@ public void setImage (Image image) {
}
public void setMenu (Menu menu) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
}
@@ -370,16 +347,14 @@ public void setMenu (Menu menu) {
}
public void setSelection (boolean selected) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
int [] args = {OS.Pt_ARG_FLAGS, selected ? OS.Pt_SET : 0, OS.Pt_SET};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
super.setText (string);
char [] text = new char [string.length ()];
@@ -429,7 +404,7 @@ public void setText (String string) {
OS.memmove (ptr3, buffer3, buffer3.length);
}
if ((parent.style & SWT.BAR) != 0) {
- replaceMnemonic (mnemonic, OS.Pk_KM_Alt);
+ replaceMnemonic (mnemonic, false, true);
}
int [] args = {
OS.Pt_ARG_TEXT_STRING, ptr1, 0,
@@ -450,4 +425,42 @@ public void setText (String string) {
if (OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
}
-}
+void showMenu() {
+ if (menu == null) return;
+ int menuHandle = menu.handle;
+ if (!OS.PtWidgetIsRealized (menuHandle)) {
+ if ((parent.style & SWT.BAR) == 0) {
+ int [] args = {OS.Pt_ARG_MENU_FLAGS, OS.Pt_MENU_CHILD, OS.Pt_MENU_CHILD};
+ OS.PtSetResources (menuHandle, args.length / 3, args);
+ }
+ 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);
+ args = new int [] {OS.Pt_ARG_POS, ptr, 0};
+ OS.PtSetResources (menuHandle, args.length / 3, args);
+ 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/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/ProgressBar.java
index 461ea7a7bb..8323fcb348 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
@@ -23,8 +23,7 @@ static int checkStyle (int style) {
* Not done - check Windows
*/
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int width = wHint, height = hHint;
if ((style & SWT.HORIZONTAL) != 0) {
if (width == SWT.DEFAULT) {
@@ -69,32 +68,28 @@ int processPaint (int damage) {
}
public int getMaximum () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MAXIMUM, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getMinimum () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MINIMUM, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_GAUGE_VALUE, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public void setMaximum (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int minimum = getMinimum();
if (0 <= minimum && minimum < value) {
int [] args = {OS.Pt_ARG_MAXIMUM, value, 0};
@@ -103,8 +98,7 @@ public void setMaximum (int value) {
}
public void setMinimum (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int maximum = getMaximum();
if (0 <= value && value < maximum) {
int [] args = {OS.Pt_ARG_MINIMUM, value, 0};
@@ -113,10 +107,9 @@ public void setMinimum (int value) {
}
public void setSelection (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
int [] args = {OS.Pt_ARG_GAUGE_VALUE, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
-}
+}
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 323de08511..ee396dd9a0 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
@@ -23,8 +23,7 @@ static int checkStyle (int style) {
}
public void addSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Selection,typedListener);
@@ -32,8 +31,7 @@ public void addSelectionListener (SelectionListener listener) {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int border = getBorderWidth ();
int width = border * 2, height = border * 2;
if ((style & SWT.HORIZONTAL) != 0) {
@@ -218,12 +216,11 @@ int processPaint (int damage) {
return OS.Pt_CONTINUE;
}
public void removeSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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/photon/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/photon/org/eclipse/swt/widgets/Scale.java
index 400c24766f..9ce22bc5ad 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
@@ -18,8 +18,7 @@ public Scale (Composite parent, int style) {
}
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Selection,typedListener);
@@ -31,8 +30,7 @@ static int checkStyle (int style) {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
PhDim_t dim = new PhDim_t();
if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
OS.PtWidgetPreferredSize(handle, dim);
@@ -59,6 +57,7 @@ void createHandle (int index) {
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);
@@ -66,40 +65,35 @@ void createHandle (int index) {
}
public int getIncrement () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_INCREMENT, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getMaximum () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MAXIMUM, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getMinimum () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MINIMUM, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getPageIncrement () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_PAGE_INCREMENT, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_SCROLL_POSITION, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
@@ -122,8 +116,7 @@ int processSelection (int info) {
}
public void removeSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
@@ -131,36 +124,31 @@ public void removeSelectionListener(SelectionListener listener) {
}
public void setIncrement (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_INCREMENT, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setMaximum (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MAXIMUM, value - 1, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setMinimum (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MINIMUM, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setPageIncrement (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_PAGE_INCREMENT, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setSelection (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_SCROLL_POSITION, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
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 586641bb58..7c741a4d34 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
@@ -32,8 +32,7 @@ static int checkStyle (int style) {
}
public void addSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener (SWT.Selection,typedListener);
@@ -78,78 +77,68 @@ public Display getDisplay () {
}
public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return (args [1] & OS.Pt_BLOCKED) == 0;
}
public int getIncrement () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_INCREMENT, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getMinimum () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MINIMUM, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getMaximum () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MAXIMUM, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getPageIncrement () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_PAGE_INCREMENT, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public Scrollable getParent () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent;
}
public int getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_SCROLL_POSITION, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public Point getSize () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 getThumb () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_SLIDER_SIZE, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public boolean getVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int topHandle = topHandle ();
int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
OS.PtGetResources (topHandle, args.length / 3, args);
@@ -162,14 +151,12 @@ void hookEvents () {
}
public boolean isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getEnabled () && parent.isEnabled ();
}
public boolean isVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return OS.PtWidgetIsRealized (handle);
}
@@ -209,8 +196,7 @@ int processSelection (int info) {
}
public void removeSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
@@ -231,8 +217,7 @@ void setBounds (int x, int y, int width, int height) {
}
public void setEnabled (boolean enabled) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_BLOCKED, OS.Pt_BLOCKED,
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_GHOST, OS.Pt_GHOST,
@@ -240,50 +225,43 @@ public void setEnabled (boolean enabled) {
OS.PtSetResources (handle, args.length / 3, args);
}
public void setIncrement (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_INCREMENT, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setMaximum (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MAXIMUM, value - 1, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setMinimum (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MINIMUM, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setPageIncrement (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_PAGE_INCREMENT, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setSelection (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_SCROLL_POSITION, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setThumb (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_SLIDER_SIZE, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (selection < 0) return;
if (minimum < 0) return;
if (maximum < 0) return;
@@ -303,8 +281,7 @@ public void setValues (int selection, int minimum, int maximum, int thumb, int i
}
public void setVisible (boolean visible) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (visible == OS.PtWidgetIsRealized (handle)) return;
int [] args = {
OS.Pt_ARG_FLAGS, visible ? 0 : OS.Pt_DELAY_REALIZE, OS.Pt_DELAY_REALIZE,
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 6781db28da..da16147532 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
@@ -47,8 +47,7 @@ void deregister () {
}
public Rectangle computeTrim (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
PhRect_t rect = new PhRect_t ();
PhArea_t area = new PhArea_t ();
rect.ul_x = (short) x;
@@ -68,8 +67,7 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
}
public Rectangle getClientArea () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
PhRect_t rect = new PhRect_t ();
int vParent = OS.PtValidParent (handle, OS.PtContainer ());
if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
@@ -80,14 +78,12 @@ public Rectangle getClientArea () {
}
public ScrollBar getHorizontalBar () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return horizontalBar;
}
public ScrollBar getVerticalBar () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return verticalBar;
}
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 6e66d3a8ca..d6d1386125 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
@@ -14,7 +14,7 @@ import org.eclipse.swt.events.*;
public class Shell extends Decorations {
int shellHandle;
Display display;
- int modal, blockedList;
+ int blockedList;
Control lastFocus;
public Shell () {
@@ -60,8 +60,7 @@ public static Shell photon_new (Display display, int handle) {
}
public void addShellListener (ShellListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Close,typedListener);
@@ -75,6 +74,16 @@ 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 ();
@@ -83,14 +92,12 @@ void closeWidget () {
}
public void close () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
closeWidget ();
}
public Rectangle computeTrim (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_WINDOW_RENDER_FLAGS, 0, 0};
OS.PtGetResources (shellHandle, args.length / 3, args);
int flags = args [1];
@@ -119,6 +126,7 @@ void createHandle (int index) {
if (handle != 0) {
int clazz = display.PtContainer;
int [] args = {
+ OS.Pt_ARG_FILL_COLOR, OS.Pg_TRANSPARENT, 0,
OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
};
shellHandle = OS.PtCreateWidget (clazz, handle, args.length / 3, args);
@@ -146,7 +154,7 @@ void createHandle (int index) {
if ((style & SWT.TITLE) != 0) decorations |= OS.Ph_WM_RENDER_TITLE;
}
int notifyFlags =
- OS.Ph_WM_ICON | OS.Ph_WM_FOCUS |
+ 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;
@@ -160,6 +168,7 @@ void createHandle (int index) {
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_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS,
};
OS.PtSetParentWidget (parentHandle);
@@ -167,15 +176,11 @@ void createHandle (int index) {
OS.free (titlePtr);
if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES);
}
- if ((style & SWT.NO_BACKGROUND) != 0) {
- int [] args = new int [] {OS.Pt_ARG_FILL_COLOR, OS.Pg_TRANSPARENT, 0};
- OS.PtSetResources(shellHandle, args.length / 3, args);
- }
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, OS.Pt_ALL_OUTLINES,
+ OS.Pt_ARG_BASIC_FLAGS, OS.Pt_ALL_OUTLINES, ~0,
};
OS.PtSetResources (scrolledHandle, args.length / 3, args);
}
@@ -196,51 +201,46 @@ public Display getDisplay () {
}
public int getImeInputMode () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return 0;
}
public boolean isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getEnabled ();
}
public Point getLocation () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
//NOT DONE - shell location is 0,0 when queried before event loop
return super.getLocation ();
}
public boolean getMaximized () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- //ONLY WORKS WHEN SET in setMaximized
+ 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- //ONLY WORKS WHEN SET in setMinimized
- int [] args = {OS.Pt_ARG_WINDOW_STATE, 0, OS.Ph_WM_STATE_ISHIDDEN};
+ 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_ISHIDDEN) != 0;
+ return (args [1] & OS.Ph_WM_STATE_ISICONIFIED) != 0;
}
public Shell getShell () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return this;
}
public Shell [] getShells () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int count = 0;
Shell [] shells = display.getShells ();
for (int i=0; i<shells.length; i++) {
@@ -265,8 +265,7 @@ public Shell [] getShells () {
}
public Point getSize () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {
OS.Pt_ARG_WINDOW_RENDER_FLAGS, 0, 0,
OS.Pt_ARG_WIDTH, 0, 0,
@@ -290,8 +289,7 @@ void hookEvents () {
}
public void open () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
bringToTop ();
setVisible (true);
}
@@ -340,7 +338,7 @@ int processMove (int info) {
break;
case OS.Ph_WM_MOVE:
sendEvent (SWT.Move);
- break;
+ break;
}
return OS.Pt_CONTINUE;
}
@@ -402,8 +400,7 @@ void releaseWidget () {
}
public void removeShellListener (ShellListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Close, listener);
@@ -414,8 +411,7 @@ public void removeShellListener (ShellListener listener) {
}
void setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (OS.PtWidgetClass (shellHandle) != OS.PtWindow ()) {
super.setBounds (x, y, width, height, move, resize);
if (resize) resizeBounds (width, height);
@@ -469,31 +465,25 @@ public void setImage (Image image) {
}
public void setImeInputMode (int mode) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
}
public void setMaximized (boolean maximized) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ int bits = 0;
+ if (maximized) bits = OS.Ph_WM_STATE_ISMAX;
+ int [] args = {OS.Pt_ARG_WINDOW_STATE, bits, OS.Ph_WM_STATE_ISMAX};
+ OS.PtSetResources (shellHandle, args.length / 3, args);
if (OS.PtWidgetIsRealized (shellHandle)) {
- // RESTORE DOESN'T WORK
PhWindowEvent_t event = new PhWindowEvent_t ();
- event.event_f = maximized ? OS.Ph_WM_MAX : OS.Ph_WM_RESTORE;
- event.event_state = (short) (maximized ? OS.Ph_WM_EVSTATE_HIDE : OS.Ph_WM_EVSTATE_UNHIDE);
event.rid = OS.PtWidgetRid (shellHandle);
+ event.event_f = maximized ? OS.Ph_WM_MAX : OS.Ph_WM_RESTORE;
OS.PtForwardWindowEvent (event);
- } else {
- int bits = 0;
- if (maximized) bits = OS.Ph_WM_STATE_ISMAX;
- int [] args = {OS.Pt_ARG_WINDOW_STATE, bits, OS.Ph_WM_STATE_ISMAX};
- OS.PtSetResources (shellHandle, args.length / 3, args);
}
}
public void setMenuBar (Menu menu) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (menuBar == menu) return;
if (menu != null) {
if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
@@ -524,39 +514,22 @@ public void setMenuBar (Menu menu) {
}
public void setMinimized (boolean minimized) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ int bits = 0;
+ if (minimized) bits = OS.Ph_WM_STATE_ISICONIFIED;
+ int [] args = {OS.Pt_ARG_WINDOW_STATE, bits, OS.Ph_WM_STATE_ISICONIFIED};
+ OS.PtSetResources (shellHandle, args.length / 3, args);
if (OS.PtWidgetIsRealized (shellHandle)) {
- // RESTORE DOESN'T WORK
PhWindowEvent_t event = new PhWindowEvent_t ();
- event.event_f = minimized ? OS.Ph_WM_HIDE : OS.Ph_WM_RESTORE;
- event.event_state = (short) (minimized ? OS.Ph_WM_EVSTATE_HIDE : OS.Ph_WM_EVSTATE_UNHIDE);
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);
- } else {
- int bits = 0;
- if (minimized) bits = OS.Ph_WM_STATE_ISHIDDEN;
- int [] args = {OS.Pt_ARG_WINDOW_STATE, bits, OS.Ph_WM_STATE_ISHIDDEN};
- OS.PtSetResources (shellHandle, args.length / 3, args);
- }
-}
-
-public void setModal (int modal) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- switch (modal) {
- case SWT.MODELESS:
- case SWT.PRIMARY_MODAL:
- case SWT.APPLICATION_MODAL:
- case SWT.SYSTEM_MODAL:
- this.modal = modal;
- break;
}
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
text = string;
byte [] buffer = Converter.wcsToMbcs (null, string, true);
@@ -568,9 +541,9 @@ public void setText (String string) {
}
public void setVisible (boolean visible) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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
@@ -581,22 +554,30 @@ public void setVisible (boolean visible) {
Shell shell = parent.getShell ();
int parentHandle = shell.shellHandle;
if (!OS.PtWidgetIsRealized (parentHandle)) {
- OS.PtReParentWidget (shellHandle, visible ? 0 : parentHandle);
+ OS.PtReParentWidget (shellHandle, visible ? OS.Pt_NO_PARENT : parentHandle);
}
}
- switch (modal) {
- case SWT.PRIMARY_MODAL:
- //NOT DONE: should not disable all windows
- case SWT.APPLICATION_MODAL:
- case SWT.SYSTEM_MODAL:
- if (visible) {
+
+ 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);
- } else {
- if (blockedList != 0) OS.PtUnblockWindows (blockedList);
- blockedList = 0;
- }
+ break;
+ }
+ } else {
+ if (blockedList != 0) OS.PtUnblockWindows (blockedList);
+ blockedList = 0;
}
super.setVisible (visible);
+
/*
* Feature in Photon. When a shell is shown, it may have child
* shells that have been temporarily reparented to NULL because
@@ -612,6 +593,7 @@ public void setVisible (boolean visible) {
}
}
}
+
OS.PtSyncWidget (shellHandle);
OS.PtFlush ();
}
@@ -620,4 +602,4 @@ int topHandle () {
return shellHandle;
}
-}
+}
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 b371b20828..39c28bc6a0 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
@@ -21,8 +21,7 @@ static int checkStyle (int style) {
}
public void addSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener (SWT.Selection,typedListener);
@@ -30,6 +29,7 @@ public void addSelectionListener (SelectionListener listener) {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
+ checkWidget();
//NOT DONE - hard coding value to be the same as list's scrollbars
int width = 17, height = 100;
if ((style & SWT.HORIZONTAL) != 0) {
@@ -64,56 +64,49 @@ void createHandle (int index) {
}
public int getIncrement () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_INCREMENT, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getMinimum () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MINIMUM, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getMaximum () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MAXIMUM, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getPageIncrement () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_PAGE_INCREMENT, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_SCROLL_POSITION, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public Point getSize () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 getThumb () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_SLIDER_SIZE, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
@@ -163,8 +156,7 @@ int processSelection (int info) {
}
public void removeSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
@@ -172,50 +164,43 @@ public void removeSelectionListener (SelectionListener listener) {
}
public void setIncrement (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_INCREMENT, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setMaximum (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MAXIMUM, value - 1, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setMinimum (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_MINIMUM, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setPageIncrement (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_PAGE_INCREMENT, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setSelection (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_SCROLL_POSITION, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setThumb (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_SLIDER_SIZE, value, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (selection < 0) return;
if (minimum < 0) return;
if (maximum < 0) return;
@@ -234,4 +219,4 @@ public void setValues (int selection, int minimum, int maximum, int thumb, int i
OS.PtSetResources (handle, args.length / 3, args);
}
-}
+}
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 dd6ef94491..d013438aeb 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
@@ -31,8 +31,7 @@ static int checkStyle (int style) {
}
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection,typedListener);
@@ -44,8 +43,7 @@ protected void checkSubclass () {
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
PhDim_t dim = new PhDim_t();
if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
OS.PtWidgetPreferredSize(handle, dim);
@@ -68,8 +66,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
}
public Rectangle computeTrim (int x, int y, int width, int height) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
PhDim_t dim = new PhDim_t();
if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
OS.PtWidgetPreferredSize(handle, dim);
@@ -185,8 +182,7 @@ void destroyItem (TabItem item) {
}
public TabItem getItem (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_PG_PANEL_TITLES, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
if (!(0 <= index && index < args [2])) error (SWT.ERROR_INVALID_RANGE);
@@ -194,8 +190,7 @@ public TabItem getItem (int index) {
}
public TabItem [] getItems () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_PG_PANEL_TITLES, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
TabItem [] result = new TabItem [args [2]];
@@ -204,24 +199,21 @@ public TabItem [] getItems () {
}
public int getItemCount () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_PG_PANEL_TITLES, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [2];
}
public TabItem [] getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int index = getSelectionIndex ();
if (index == -1) return new TabItem [0];
return new TabItem [] {items [index]};
}
public int getSelectionIndex () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_PG_CURRENT_INDEX, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1] == OS.Pt_PG_INVALID ? -1 : args [1];
@@ -234,8 +226,7 @@ void hookEvents () {
}
public int indexOf (TabItem item) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
int count = getItemCount ();
for (int i=0; i<count; i++) {
@@ -311,8 +302,7 @@ void releaseWidget () {
}
public void removeSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
@@ -320,8 +310,7 @@ public void removeSelectionListener (SelectionListener listener) {
}
public void setSelection (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_PG_CURRENT_INDEX, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
int oldIndex = args [1];
@@ -348,8 +337,7 @@ public void setSelection (int index) {
}
public void setSelection (TabItem [] items) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
if (items.length == 0) {
setSelection (-1);
@@ -361,4 +349,4 @@ public void setSelection (TabItem [] items) {
}
}
-}
+}
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 9c733f9677..a2fa31a4b5 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
@@ -30,8 +30,7 @@ protected void checkSubclass () {
}
public Control getControl () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return control;
}
@@ -42,14 +41,12 @@ public Display getDisplay () {
}
public TabFolder getParent () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent;
}
public String getToolTipText () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return toolTipText;
}
@@ -66,10 +63,10 @@ void releaseWidget () {
}
public void setControl (Control control) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (control != null && control.parent != parent) {
- error (SWT.ERROR_INVALID_PARENT);
+ checkWidget();
+ if (control != null) {
+ if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
}
Control oldControl = this.control, newControl = control;
this.control = control;
@@ -83,14 +80,12 @@ public void setControl (Control control) {
}
public void setImage (Image image) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
//NOT SUPPORTED
}
public void setText (String text) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
super.setText (text);
int index = parent.indexOf (this);
int [] args = {OS.Pt_ARG_PG_PANEL_TITLES, 0, 0};
@@ -124,8 +119,7 @@ public void setText (String text) {
}
public void setToolTipText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 d14ced445a..3e4899e1fa 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
@@ -43,8 +43,7 @@ static int checkStyle (int style) {
return style | SWT.SINGLE;
}
public Point computeSize (int wHint, int hHint, boolean changed) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
PhDim_t dim = new PhDim_t ();
if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
OS.PtWidgetPreferredSize (handle, dim);
@@ -74,9 +73,14 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
return new Point(width, height);
}
public void clearSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- OS.PtTextSetSelection (handle, new int [] {0}, new int [] {0});
+ 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;
@@ -119,16 +123,14 @@ void createWidget (int index) {
}
public void addModifyListener (ModifyListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Modify, typedListener);
}
public void addSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Selection,typedListener);
@@ -136,25 +138,21 @@ public void addSelectionListener (SelectionListener listener) {
}
public void addVerifyListener (VerifyListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Verify, typedListener);
}
public void append (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 copy () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
int [] start = new int [1], end = new int [1];
int length = OS.PtTextGetSelection (handle, start, end);
if (length <= 0) return;
@@ -167,9 +165,7 @@ public void copy () {
}
public void cut () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
int [] start = new int [1], end = new int [1];
int length = OS.PtTextGetSelection (handle, start, end);
if (length <= 0) return;
@@ -199,30 +195,26 @@ void deregister () {
}
public int getCaretLineNumber () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
//NOT DONE - NOT NEEDED
return 0;
}
public Point getCaretLocation () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
//NOT DONE - NOT NEEDED
return null;
}
public int getCaretPosition () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_CURSOR_POSITION, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getCharCount () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
if (args [1] == 0) return 0;
@@ -230,29 +222,25 @@ public int getCharCount () {
}
public boolean getDoubleClickEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
//NOT DONE - NOT NEEDED
return false;
}
public char getEchoChar () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return echoCharacter;
}
public boolean getEditable () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 int getLineCount () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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);
@@ -260,12 +248,12 @@ public int getLineCount () {
}
public String getLineDelimiter () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return "\n";
}
public int getLineHeight () {
+ checkWidget();
if ((style & SWT.SINGLE) != 0) {
PhDim_t dim = new PhDim_t ();
if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidget (handle);
@@ -298,8 +286,7 @@ String getNameText () {
}
public Point getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (textVerify != null) {
return new Point (textVerify.start_pos, textVerify.end_pos);
}
@@ -314,15 +301,13 @@ public Point getSelection () {
}
public int getSelectionCount () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
Point selection = getSelection ();
return selection.y - selection.x;
}
public String getSelectionText () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/*
* NOTE: The current implementation uses substring ()
* which can reference a potentially large character
@@ -333,8 +318,7 @@ public String getSelectionText () {
}
public int getTabs () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return tabs;
}
@@ -351,8 +335,7 @@ int getTabWidth (int tabs) {
}
public String getText (int start, int end) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/*
* NOTE: The current implementation uses substring ()
* which can reference a potentially large character
@@ -363,8 +346,7 @@ public String getText (int start, int end) {
}
public String getText () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (echoCharacter != '\0') return hiddenText;
int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
@@ -377,26 +359,22 @@ public String getText () {
}
public int getTextLimit () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = new int [] {OS.Pt_ARG_MAX_LENGTH, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
}
public int getTopIndex () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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];
+ return args [1] - 1;
}
public int getTopPixel () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
//NOT DONE - NOT NEEDED
return 0;
}
@@ -409,8 +387,7 @@ void hookEvents () {
}
public void insert (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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];
@@ -424,9 +401,7 @@ public void insert (String string) {
}
public void paste () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
int ig = OS.PhInputGroup (0);
int ptr = OS.PhClipboardPasteString((short)ig);
if (ptr == 0) return;
@@ -558,16 +533,14 @@ void releaseWidget () {
}
public void removeModifyListener (ModifyListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Modify, listener);
}
public void removeSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
@@ -575,22 +548,19 @@ public void removeSelectionListener (SelectionListener listener) {
}
public void removeVerifyListener (VerifyListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Verify, listener);
}
public void selectAll () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
OS.PtTextSetSelection (handle, new int [0], new int [] {-1});
}
public void setEchoChar (char echo) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (echoCharacter == echo) return;
String newText;
if (echo == 0) {
@@ -609,15 +579,12 @@ public void setEchoChar (char echo) {
}
public void setDoubleClickEnabled (boolean doubleClick) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
//NOT DONE - NOT NEEDED
}
public void setEditable (boolean editable) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
style &= ~SWT.READ_ONLY;
if (!editable) style |= SWT.READ_ONLY;
int [] args = {OS.Pt_ARG_TEXT_FLAGS, editable ? OS.Pt_EDITABLE : 0, OS.Pt_EDITABLE};
@@ -630,28 +597,46 @@ public void setFont (Font font) {
}
public void setSelection (int position) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_CURSOR_POSITION, position, 0};
OS.PtSetResources (handle, args.length / 3, args);
+
+ /*
+ * 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 (Point selection) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
setSelection (selection.x, selection.y);
}
public void setSelection (int start, int end) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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) {
+ int [] args = {OS.Pt_ARG_CURSOR_POSITION, start, 0};
+ OS.PtSetResources (handle, args.length / 3, args);
+ }
}
public void setTabs (int tabs) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (tabs < 0) return;
setTabStops (this.tabs = tabs);
}
@@ -667,8 +652,7 @@ void setTabStops (int tabs) {
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
byte [] buffer = Converter.wcsToMbcs (null, string, true);
int ptr = OS.malloc (buffer.length);
@@ -679,25 +663,21 @@ public void setText (String string) {
}
public void setTextLimit (int limit) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
int [] args = new int [] {OS.Pt_ARG_MAX_LENGTH, limit, 0};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setTopIndex (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SINGLE) != 0) return;
int [] args = {OS.Pt_ARG_MULTITEXT_TOP_LINE, index + 1, 0};
OS.PtSetResources(handle, args.length / 3, args);
}
public void showSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-
+ checkWidget();
//NOT DONE - NOT NEEDED
}
@@ -712,4 +692,13 @@ int traversalCode (int key_sym, PhKeyEvent_t ke) {
return SWT.TRAVERSE_ESCAPE;
}
-}
+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 true;
+ }
+ return translated;
+}
+
+}
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 707d5df752..bbe5c45713 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
@@ -47,8 +47,7 @@ protected void checkSubclass () {
public Point computeSize (int wHint, int hHint, boolean changed) {
// if (layout != null) return super.computeSize (wHint, hHint, changed);
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
PhDim_t dim = new PhDim_t();
if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
OS.PtWidgetPreferredSize(handle, dim);
@@ -109,30 +108,26 @@ void destroyItem (ToolItem item) {
}
public int getItemCount () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return itemCount;
}
public ToolItem [] getItems () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
ToolItem [] result = new ToolItem [itemCount];
System.arraycopy (items, 0, result, 0, itemCount);
return result;
}
public ToolItem getItem (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int count = itemCount;
if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);
return items [index];
}
public ToolItem getItem (Point pt) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
ToolItem [] items = getItems ();
for (int i=0; i<items.length; i++) {
Rectangle rect = items [i].getBounds ();
@@ -142,15 +137,14 @@ public ToolItem getItem (Point pt) {
}
public int getRowCount () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return 1;
}
public int indexOf (ToolItem item) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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;
@@ -169,5 +163,16 @@ void releaseWidget () {
items = null;
super.releaseWidget ();
}
-
+
+/* TEMPORARY CODE. Hack for eclipse. */
+public void setData(Object data) {
+ super.setData(data);
+ if (data != null && data.getClass().getName().indexOf("org.eclipse.ui.internal.ShortcutBarPart") != -1) {
+ int [] args = {
+ OS.Pt_ARG_ORIENTATION, OS.Pt_VERTICAL, 0,
+ };
+ OS.PtSetResources(handle, args.length / 3, args);
+ }
}
+
+}
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 305bfc6873..f5844483de 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
@@ -30,8 +30,7 @@ public ToolItem (ToolBar parent, int style, int index) {
}
public void addSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Selection,typedListener);
@@ -147,22 +146,19 @@ void deregister () {
}
public Rectangle getBounds () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
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);
}
public Control getControl () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return control;
}
public Image getDisabledImage () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return disabledImage;
}
@@ -173,28 +169,24 @@ public Display getDisplay () {
}
public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return (args [1] & OS.Pt_BLOCKED) == 0;
}
public Image getHotImage () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return hotImage;
}
public ToolBar getParent () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent;
}
public boolean getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
int [] args = {OS.Pt_ARG_FLAGS, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
@@ -202,14 +194,12 @@ public boolean getSelection () {
}
public String getToolTipText () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return toolTipText;
}
public int getWidth () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {OS.Pt_ARG_WIDTH, 0, 0};
OS.PtGetResources (handle, args.length / 3, args);
return args [1];
@@ -227,8 +217,7 @@ void hookEvents () {
}
public boolean isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getEnabled () && parent.isEnabled ();
}
@@ -307,6 +296,8 @@ void releaseHandle () {
void releaseWidget () {
super.releaseWidget ();
+ if (toolTipHandle != 0) destroyToolTip (toolTipHandle);
+ toolTipHandle = 0;
parent = null;
control = null;
hotImage = null;
@@ -315,8 +306,7 @@ void releaseWidget () {
}
public void removeSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
@@ -324,10 +314,10 @@ public void removeSelectionListener(SelectionListener listener) {
}
public void setControl (Control control) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (control != null && control.parent != parent) {
- error (SWT.ERROR_INVALID_PARENT);
+ 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;
@@ -342,15 +332,14 @@ public void setControl (Control control) {
}
public void setDisabledImage (Image image) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
+ if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
if ((style & SWT.SEPARATOR) != 0) return;
disabledImage = image;
}
public void setEnabled (boolean enabled) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int [] args = {
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_BLOCKED, OS.Pt_BLOCKED,
OS.Pt_ARG_FLAGS, enabled ? 0 : OS.Pt_GHOST, OS.Pt_GHOST,
@@ -359,16 +348,25 @@ public void setEnabled (boolean enabled) {
}
public void setHotImage (Image image) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((style & SWT.SEPARATOR) != 0) return;
+ 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) {
@@ -399,16 +397,14 @@ public void setImage (Image image) {
}
public void setSelection (boolean selected) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
int [] args = {OS.Pt_ARG_FLAGS, selected ? OS.Pt_SET : 0, OS.Pt_SET};
OS.PtSetResources (handle, args.length / 3, args);
}
public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) != 0) return;
super.setText (string);
int ptr = 0;
@@ -443,14 +439,12 @@ public void setText (String string) {
}
public void setToolTipText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
toolTipText = string;
}
public void setWidth (int width) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if ((style & SWT.SEPARATOR) == 0) return;
if (width < 0) return;
int [] args = {OS.Pt_ARG_WIDTH, width, 0};
@@ -459,4 +453,4 @@ public void setWidth (int width) {
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 9870e1603c..e35cab796e 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
@@ -32,15 +32,13 @@ public Tracker (Composite parent, int style) {
this.display = parent.getDisplay ();
}
public void addControlListener(ControlListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Move,typedListener);
}
public void close () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
tracking = false;
}
@@ -86,18 +84,15 @@ public Display getDisplay () {
}
public Rectangle [] getRectangles () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return rectangles;
}
public boolean getStippled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return stippled;
}
public boolean open () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
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 = {
@@ -159,6 +154,8 @@ public boolean open () {
* event. If this happens, return false to indicate
* that the tracking has failed.
*/
+ ev.x = newX;
+ ev.y = newY;
sendEvent (SWT.Move, ev);
if (isDisposed ()) return false;
drawRectangles ();
@@ -197,22 +194,19 @@ void releaseWidget () {
rectangles = null;
}
public void removeControlListener (ControlListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Move, listener);
}
public void setRectangles (Rectangle [] rectangles) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
this.rectangles = rectangles;
}
public void setStippled (boolean stippled) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ 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 1ca65f7b66..7ea8277cac 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
@@ -55,6 +55,7 @@ static int checkBits (int style, int int0, int int1, int int2, int int3, int int
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);
}
protected void checkSubclass () {
@@ -63,7 +64,7 @@ protected void checkSubclass () {
protected void checkWidget () {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (isDisposed ()) error (SWT.ERROR_WIDGET_DISPOSED);
}
int copyPhImage(int image) {
@@ -85,16 +86,14 @@ int copyPhImage(int image) {
}
public void addListener (int eventType, Listener handler) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) eventTable = new EventTable ();
eventTable.hook (eventType, handler);
}
public void addDisposeListener (DisposeListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Dispose, typedListener);
@@ -174,7 +173,7 @@ public void dispose () {
* Note: It is valid to attempt to dispose a widget
* more than once. If this happens, fail silently.
*/
- if (!isValidWidget ()) return;
+ if (isDisposed()) return;
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
releaseChild ();
releaseWidget ();
@@ -186,14 +185,12 @@ static void error (int code) {
}
public Object getData () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return data;
}
public Object getData (String key) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
if (keys == null) return null;
for (int i=0; i<keys.length; i++) {
@@ -216,8 +213,7 @@ String getNameText () {
}
public int getStyle () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return style;
}
@@ -241,8 +237,7 @@ boolean isValidSubclass () {
}
protected boolean isListening (int eventType) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return hooks (eventType);
}
@@ -250,15 +245,8 @@ boolean isValidThread () {
return getDisplay ().isValidThread ();
}
-boolean isValidWidget () {
- if (handle != 0) return true;
- if ((state & HANDLE) != 0) return false;
- return (state & DISPOSED) == 0;
-}
-
public void notifyListeners (int eventType, Event event) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
event.type = eventType;
@@ -401,30 +389,27 @@ void releaseWidget () {
}
public void removeListener (int eventType, Listener handler) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (eventType, handler);
}
protected void removeListener (int eventType, EventListener handler) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (eventType, handler);
}
public void removeDisposeListener (DisposeListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Dispose, listener);
}
-void replaceMnemonic (int mnemonic, int mods) {
+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);
@@ -436,13 +421,23 @@ void replaceMnemonic (int mnemonic, int mods) {
char [] accelText = Converter.mbcsToWcs (null, buffer);
if (accelText.length > 0) {
char key = Character.toLowerCase (accelText [0]);
- OS.PtRemoveHotkeyHandler (handle, key, 0, (short)0, SWT.Activate, display.windowProc);
+ if (normal) {
+ OS.PtRemoveHotkeyHandler (handle, key, 0, (short)0, SWT.Activate, display.windowProc);
+ }
+ if (alt) {
+ OS.PtRemoveHotkeyHandler (handle, key, OS.Pk_KM_Alt, (short)0, SWT.Activate, display.windowProc);
+ }
}
}
}
if (mnemonic == 0) return;
char key = Character.toLowerCase ((char)mnemonic);
- OS.PtAddHotkeyHandler (handle, key, mods, (short)0, SWT.Activate, display.windowProc);
+ if (normal) {
+ OS.PtAddHotkeyHandler (handle, key, 0, (short)0, SWT.Activate, display.windowProc);
+ }
+ if (alt) {
+ OS.PtAddHotkeyHandler (handle, key, OS.Pk_KM_Alt, (short)0, SWT.Activate, display.windowProc);
+ }
}
void sendEvent (int eventType) {
@@ -461,14 +456,12 @@ void sendEvent (int eventType, Event event) {
}
public void setData (Object data) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
this.data = data;
}
public void setData (String key, Object value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (key == null) error (SWT.ERROR_NULL_ARGUMENT);
/* Remove the key/value pair */
@@ -515,6 +508,55 @@ public void setData (String key, Object value) {
values = newValues;
}
+void setKeyState(Event event, PhKeyEvent_t ke) {
+ int key_mods = ke.key_mods;
+ int button_state = ke.button_state;
+ if ((key_mods & OS.Pk_KM_Alt) != 0) event.stateMask |= SWT.ALT;
+ if ((key_mods & OS.Pk_KM_Shift) != 0) event.stateMask |= SWT.SHIFT;
+ if ((key_mods & OS.Pk_KM_Ctrl) != 0) event.stateMask |= SWT.CONTROL;
+ if ((button_state & OS.Ph_BUTTON_SELECT) != 0) event.stateMask |= SWT.BUTTON1;
+ if ((button_state & OS.Ph_BUTTON_ADJUST) != 0) event.stateMask |= SWT.BUTTON2;
+ if ((button_state & OS.Ph_BUTTON_MENU) != 0) event.stateMask |= SWT.BUTTON3;
+ switch (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(int type, Event event, PhPointerEvent_t pe) {
+ int key_mods = pe.key_mods;
+ int buttons = pe.buttons;
+ int button_state = pe.button_state;
+ if ((key_mods & OS.Pk_KM_Alt) != 0) event.stateMask |= SWT.ALT;
+ if ((key_mods & OS.Pk_KM_Shift) != 0) event.stateMask |= SWT.SHIFT;
+ if ((key_mods & OS.Pk_KM_Ctrl) != 0) event.stateMask |= SWT.CONTROL;
+ if ((button_state & OS.Ph_BUTTON_SELECT) != 0) event.stateMask |= SWT.BUTTON1;
+ if ((button_state & OS.Ph_BUTTON_ADJUST) != 0) event.stateMask |= SWT.BUTTON2;
+ if ((button_state & OS.Ph_BUTTON_MENU) != 0) event.stateMask |= SWT.BUTTON3;
+ switch (type) {
+ case 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;
+ }
+}
+
public String toString () {
String string = "*Disposed*";
if (!isDisposed ()) {
@@ -528,4 +570,4 @@ int topHandle () {
return handle;
}
-}
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/library/makefile.mak b/bundles/org.eclipse.swt/Eclipse SWT/win32/library/makefile.mak
index e6d66f61a4..ee418ac4ad 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/library/makefile.mak
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/library/makefile.mak
@@ -12,8 +12,8 @@
APPVER=5.0
!include <win32.mak>
-maj_ver=0
-min_ver=125
+maj_ver=2
+min_ver=006
bld_num=0
pgm_ver_str="SWT $(maj_ver).0$(min_ver) for Windows"
@@ -23,7 +23,8 @@ copyright = "Copyright (C) IBM Corporation 1999, 2000. All rights reserved."
# assumes JAVA_HOME is set in the environment from which nmake is run
DLLPREFIX=swt
-DLLNAME=$(DLLPREFIX)$(maj_ver)$(min_ver).dll
+OSPREFIX=win32
+DLLNAME=$(DLLPREFIX)-$(OSPREFIX)-$(maj_ver)$(min_ver).dll
LIBNAME=swt# declaration
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/library/structs.c b/bundles/org.eclipse.swt/Eclipse SWT/win32/library/structs.c
index 63ec0a111c..2a46509153 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/library/structs.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/library/structs.c
@@ -311,6 +311,15 @@ void cacheDrawitemstructFids(JNIEnv *env, jobject lpDrawitemstruct, PDRAWITEMSTR
lpCache->itemData = (*env)->GetFieldID(env,lpCache->drawitemstructClass,"itemData","I");
lpCache->cached = 1;
}
+
+void cacheGradientrectFids(JNIEnv *env, jobject lpGradientrect, PGRADIENT_RECT_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+ lpCache->gradientrectClass = (*env)->GetObjectClass(env,lpGradientrect);
+ lpCache->UpperLeft = (*env)->GetFieldID(env,lpCache->gradientrectClass,"UpperLeft","I");
+ lpCache->LowerRight = (*env)->GetFieldID(env,lpCache->gradientrectClass,"LowerRight","I");
+ lpCache->cached = 1;
+}
void cacheHditemFids(JNIEnv *env, jobject lpHditem, PHDITEM_FID_CACHE lpCache)
{
@@ -1012,7 +1021,20 @@ void cacheTrackmouseeventFids(JNIEnv *env, jobject lpTrackmouseevent, PTRACKMOUS
lpCache->dwHoverTime = (*env)->GetFieldID(env,lpCache->trackmouseeventClass,"dwHoverTime","I");
lpCache->cached = 1;
}
-
+
+void cacheTrivertexFids(JNIEnv *env, jobject lpTrivertex, PTRIVERTEX_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+ lpCache->trivertexClass = (*env)->GetObjectClass(env,lpTrivertex);
+ lpCache->x = (*env)->GetFieldID(env,lpCache->trivertexClass,"x","I");
+ lpCache->y = (*env)->GetFieldID(env,lpCache->trivertexClass,"y","I");
+ lpCache->Red = (*env)->GetFieldID(env,lpCache->trivertexClass,"Red","S");
+ lpCache->Green = (*env)->GetFieldID(env,lpCache->trivertexClass,"Green","S");
+ lpCache->Blue = (*env)->GetFieldID(env,lpCache->trivertexClass,"Blue","S");
+ lpCache->Alpha = (*env)->GetFieldID(env,lpCache->trivertexClass,"Alpha","S");
+ lpCache->cached = 1;
+}
+
void cacheTvhittestinfoFids(JNIEnv *env, jobject lpTvhittestinfo, PTVHITTESTINFO_FID_CACHE lpCache)
{
if (lpCache->cached) return;
@@ -1504,7 +1526,23 @@ void cacheVardesc2Fids(JNIEnv *env, jobject lpVardesc, PVARDESC2_FID_CACHE lpCac
lpCache->filler = (*env)->GetFieldID(env,lpCache->vardescClass,"filler","S");
lpCache->varkind = (*env)->GetFieldID(env,lpCache->vardescClass,"varkind","I");
lpCache->cached = 1;
-}
+}
+
+void cacheGCP_RESULTSFids(JNIEnv *env, jobject lpObject, PGCP_RESULTS_FID_CACHE lpCache)
+{
+ if (lpCache->cached) return;
+ lpCache->clazz = (*env)->GetObjectClass(env, lpObject);
+ lpCache->nMaxFit = (*env)->GetFieldID(env, lpCache->clazz, "nMaxFit", "I");
+ lpCache->nGlyphs = (*env)->GetFieldID(env, lpCache->clazz, "nGlyphs", "I");
+ lpCache->lpGlyphs = (*env)->GetFieldID(env, lpCache->clazz, "lpGlyphs", "I");
+ lpCache->lpClass = (*env)->GetFieldID(env, lpCache->clazz, "lpClass", "I");
+ lpCache->lpCaretPos = (*env)->GetFieldID(env, lpCache->clazz, "lpCaretPos", "I");
+ lpCache->lpDx = (*env)->GetFieldID(env, lpCache->clazz, "lpDx", "I");
+ lpCache->lpOrder = (*env)->GetFieldID(env, lpCache->clazz, "lpOrder", "I");
+ lpCache->lpOutString = (*env)->GetFieldID(env, lpCache->clazz, "lpOutString", "I");
+ lpCache->lStructSize = (*env)->GetFieldID(env, lpCache->clazz, "lStructSize", "I");
+ lpCache->cached = 1;
+}
/* ----------- swt getters and setters ----------- */
/**
@@ -2015,7 +2053,19 @@ void setDrawitemstructFields(JNIEnv *env, jobject lpObject, DRAWITEMSTRUCT *lpDr
(*env)->SetIntField(env,lpObject,lpDrawitemstructFc->bottom, lpDrawitemstruct->rcItem.bottom);
(*env)->SetIntField(env,lpObject,lpDrawitemstructFc->itemData, lpDrawitemstruct->itemData);
}
-
+
+void getGradientrectFields(JNIEnv *env, jobject lpObject, GRADIENT_RECT *lpGradientrect, GRADIENT_RECT_FID_CACHE *lpGradientrectFc)
+{
+ lpGradientrect->UpperLeft = (*env)->GetIntField(env,lpObject,lpGradientrectFc->UpperLeft);
+ lpGradientrect->LowerRight = (*env)->GetIntField(env,lpObject,lpGradientrectFc->LowerRight);
+}
+
+void setGradientrectFields(JNIEnv *env, jobject lpObject, GRADIENT_RECT *lpGradientrect, GRADIENT_RECT_FID_CACHE *lpGradientrectFc)
+{
+ (*env)->SetIntField(env,lpObject,lpGradientrectFc->UpperLeft, (jint)lpGradientrect->UpperLeft);
+ (*env)->SetIntField(env,lpObject,lpGradientrectFc->LowerRight, (jint)lpGradientrect->LowerRight);
+}
+
void getHditemFields(JNIEnv *env, jobject lpObject, HDITEM *lpHditem, HDITEM_FID_CACHE *lpHditemFc)
{
lpHditem->mask = (*env)->GetIntField(env,lpObject,lpHditemFc->mask);
@@ -3189,6 +3239,26 @@ void setTrackmouseeventFields(JNIEnv *env, jobject lpObject, TRACKMOUSEEVENT *lp
(*env)->SetIntField(env,lpObject,lpTrackmouseeventFc->dwHoverTime, lpTrackmouseevent->dwHoverTime);
}
+void getTrivertexFields(JNIEnv *env, jobject lpObject, TRIVERTEX *lpTrivertex, TRIVERTEX_FID_CACHE *lpTrivertexFc)
+{
+ lpTrivertex->x = (*env)->GetIntField(env,lpObject,lpTrivertexFc->x);
+ lpTrivertex->y = (*env)->GetIntField(env,lpObject,lpTrivertexFc->y);
+ lpTrivertex->Red = (*env)->GetShortField(env,lpObject,lpTrivertexFc->Red);
+ lpTrivertex->Green = (*env)->GetShortField(env,lpObject,lpTrivertexFc->Green);
+ lpTrivertex->Blue = (*env)->GetShortField(env,lpObject,lpTrivertexFc->Blue);
+ lpTrivertex->Alpha = (*env)->GetShortField(env,lpObject,lpTrivertexFc->Alpha);
+}
+
+void setTrivertexFields(JNIEnv *env, jobject lpObject, TRIVERTEX *lpTrivertex, TRIVERTEX_FID_CACHE *lpTrivertexFc)
+{
+ (*env)->SetIntField(env,lpObject,lpTrivertexFc->x, (jint)lpTrivertex->x);
+ (*env)->SetIntField(env,lpObject,lpTrivertexFc->y, (jint)lpTrivertex->y);
+ (*env)->SetShortField(env,lpObject,lpTrivertexFc->Red, (jshort)lpTrivertex->Red);
+ (*env)->SetShortField(env,lpObject,lpTrivertexFc->Green, (jshort)lpTrivertex->Green);
+ (*env)->SetShortField(env,lpObject,lpTrivertexFc->Blue, (jshort)lpTrivertex->Blue);
+ (*env)->SetShortField(env,lpObject,lpTrivertexFc->Alpha, (jshort)lpTrivertex->Alpha);
+}
+
void getTvhittestinfoFields(JNIEnv *env, jobject lpObject, TVHITTESTINFO *lpTvhittestinfo, TVHITTESTINFO_FID_CACHE *lpTvhittestinfoFc)
{
lpTvhittestinfo->pt.x = (*env)->GetIntField(env,lpObject,lpTvhittestinfoFc->x);
@@ -3978,4 +4048,30 @@ void setVardesc2Fields(JNIEnv *env, jobject lpObject, VARDESC *lpVardesc, VARDES
(*env)->SetShortField(env,lpObject,lpVardescFc->elemdescVar_idldesc_wIDLFlags, (jshort)lpVardesc->elemdescVar.idldesc.wIDLFlags);
(*env)->SetShortField(env,lpObject,lpVardescFc->wVarFlags, (jshort)lpVardesc->wVarFlags);
(*env)->SetIntField(env,lpObject,lpVardescFc->varkind, (jint)lpVardesc->varkind);
-} \ No newline at end of file
+}
+
+void getGCP_RESULTSFields(JNIEnv *env, jobject lpObject, GCP_RESULTS *lpStruct, PGCP_RESULTS_FID_CACHE lpCache)
+{
+ lpStruct->nMaxFit = (*env)->GetIntField(env, lpObject, lpCache->nMaxFit);
+ lpStruct->nGlyphs = (*env)->GetIntField(env, lpObject, lpCache->nGlyphs);
+ lpStruct->lpGlyphs = (LPWSTR)(*env)->GetIntField(env, lpObject, lpCache->lpGlyphs);
+ lpStruct->lpClass = (LPSTR)(*env)->GetIntField(env, lpObject, lpCache->lpClass);
+ lpStruct->lpCaretPos = (int *)(*env)->GetIntField(env, lpObject, lpCache->lpCaretPos);
+ lpStruct->lpDx = (int *)(*env)->GetIntField(env, lpObject, lpCache->lpDx);
+ lpStruct->lpOrder = (UINT *)(*env)->GetIntField(env, lpObject, lpCache->lpOrder);
+ lpStruct->lpOutString = (LPTSTR)(*env)->GetIntField(env, lpObject, lpCache->lpOutString);
+ lpStruct->lStructSize = (*env)->GetIntField(env, lpObject, lpCache->lStructSize);
+}
+
+void setGCP_RESULTSFields(JNIEnv *env, jobject lpObject, GCP_RESULTS *lpStruct, PGCP_RESULTS_FID_CACHE lpCache)
+{
+ (*env)->SetIntField(env, lpObject, lpCache->nMaxFit, lpStruct->nMaxFit);
+ (*env)->SetIntField(env, lpObject, lpCache->nGlyphs, lpStruct->nGlyphs);
+ (*env)->SetIntField(env, lpObject, lpCache->lpGlyphs, (int)lpStruct->lpGlyphs);
+ (*env)->SetIntField(env, lpObject, lpCache->lpClass, (int)lpStruct->lpClass);
+ (*env)->SetIntField(env, lpObject, lpCache->lpCaretPos, (int)lpStruct->lpCaretPos);
+ (*env)->SetIntField(env, lpObject, lpCache->lpDx, (int)lpStruct->lpDx);
+ (*env)->SetIntField(env, lpObject, lpCache->lpOrder, (int)lpStruct->lpOrder);
+ (*env)->SetIntField(env, lpObject, lpCache->lpOutString, (int)lpStruct->lpOutString);
+ (*env)->SetIntField(env, lpObject, lpCache->lStructSize, lpStruct->lStructSize);
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/library/structs.h b/bundles/org.eclipse.swt/Eclipse SWT/win32/library/structs.h
index 6ae3474aa0..8b3539f790 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/library/structs.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/library/structs.h
@@ -111,7 +111,10 @@
FUNCDESC1_FID_CACHE Funcdesc1Fc; \
FUNCDESC2_FID_CACHE Funcdesc2Fc; \
VARDESC1_FID_CACHE Vardesc1Fc; \
- VARDESC2_FID_CACHE Vardesc2Fc;
+ VARDESC2_FID_CACHE Vardesc2Fc; \
+ GCP_RESULTS_FID_CACHE GCP_RESULTSFc; \
+ TRIVERTEX_FID_CACHE TrivertexFc; \
+ GRADIENT_RECT_FID_CACHE GradientrectFc;
/* PARAFORMAT_FID_CACHE ParaformatFc; \*/
/* CHARFORMAT_FID_CACHE CharformatFc; \*/
@@ -323,6 +326,17 @@ typedef struct DRAWITEMSTRUCT_FID_CACHE {
typedef DRAWITEMSTRUCT_FID_CACHE *PDRAWITEMSTRUCT_FID_CACHE;
+/* GRADIENT_RECT struct */
+typedef struct GRADIENT_RECT_FID_CACHE {
+
+ int cached;
+ jclass gradientrectClass;
+ jfieldID UpperLeft, LowerRight;
+
+} GRADIENT_RECT_FID_CACHE;
+
+typedef GRADIENT_RECT_FID_CACHE *PGRADIENT_RECT_FID_CACHE;
+
/* HDITEM struct */
typedef struct HDITEM_FID_CACHE {
@@ -810,6 +824,17 @@ typedef struct TRACKMOUSEEVENT_FID_CACHE {
typedef TRACKMOUSEEVENT_FID_CACHE *PTRACKMOUSEEVENT_FID_CACHE;
+/* TRIVERTEX struct */
+typedef struct TRIVERTEX_FID_CACHE {
+
+ int cached;
+ jclass trivertexClass;
+ jfieldID x, y, Red, Green, Blue, Alpha;
+
+} TRIVERTEX_FID_CACHE;
+
+typedef TRIVERTEX_FID_CACHE *PTRIVERTEX_FID_CACHE;
+
/* TVHITTESTINFO struct */
typedef struct TVHITTESTINFO_FID_CACHE {
@@ -1208,7 +1233,17 @@ typedef struct VARDESC2_FID_CACHE {
} VARDESC2_FID_CACHE;
-typedef VARDESC2_FID_CACHE *PVARDESC2_FID_CACHE;
+typedef VARDESC2_FID_CACHE *PVARDESC2_FID_CACHE;
+
+/* GCP_RESULTS struct */
+typedef struct GCP_RESULTS_FID_CACHE {
+ int cached;
+ jclass clazz;
+ jfieldID nMaxFit, nGlyphs, lpGlyphs, lpClass, lpCaretPos, lpDx, lpOrder, lpOutString, lStructSize;
+} GCP_RESULTS_FID_CACHE;
+
+typedef GCP_RESULTS_FID_CACHE *PGCP_RESULTS_FID_CACHE;
+
/* ----------- ole cache function prototypes ----------- */
@@ -1233,6 +1268,7 @@ void cacheFuncdesc1Fids(JNIEnv *env, jobject lpFuncdesc, PFUNCDESC1_FID_CACHE lp
void cacheFuncdesc2Fids(JNIEnv *env, jobject lpFuncdesc, PFUNCDESC2_FID_CACHE lpCache);
void cacheVardesc1Fids(JNIEnv *env, jobject lpVardesc, PVARDESC1_FID_CACHE lpCache);
void cacheVardesc2Fids(JNIEnv *env, jobject lpVardesc, PVARDESC2_FID_CACHE lpCache);
+void cacheGCP_RESULTSFids(JNIEnv *env, jobject lpObject, PGCP_RESULTS_FID_CACHE lpCache);
/* ----------- cache function prototypes ----------- */
@@ -1254,6 +1290,7 @@ void cacheDllversioninfoFids(JNIEnv *env, jobject lpDllversioninfo, PDLLVERSIONI
void cacheDocinfoFids(JNIEnv *env, jobject lpDocinfo, PDOCINFO_FID_CACHE lpCache);
void cacheDrawitemstructFids(JNIEnv *env, jobject lpDrawitemstruct, PDRAWITEMSTRUCT_FID_CACHE lpCache);
void cacheDropfilesFids(JNIEnv *env, jobject lpDropfiles, PDROPFILES_FID_CACHE lpCache);
+void cacheGradientrectFids(JNIEnv *env, jobject lpGradientrect, PGRADIENT_RECT_FID_CACHE lpCache);
void cacheHditemFids(JNIEnv *env, jobject lpHditem, PHDITEM_FID_CACHE lpCache);
void cacheHdlayoutFids(JNIEnv *env, jobject lpHdlayout, PHDLAYOUT_FID_CACHE lpCache);
void cacheHelpinfoFids(JNIEnv *env, jobject lpHelpinfo, PHELPINFO_FID_CACHE lpCache);
@@ -1299,6 +1336,7 @@ void cacheTcitemFids(JNIEnv *env, jobject lpTcitem, PTCITEM_FID_CACHE lpCache);
void cacheTextmetricFids(JNIEnv *env, jobject lpTextmetric, PTEXTMETRIC_FID_CACHE lpCache);
void cacheToolinfoFids(JNIEnv *env, jobject lpToolinfo, PTOOLINFO_FID_CACHE lpCache);
void cacheTrackmouseeventFids(JNIEnv *env, jobject lpTrackmouseevent, PTRACKMOUSEEVENT_FID_CACHE lpCache);
+void cacheTrivertexFids(JNIEnv *env, jobject lpTrivertex, PTRIVERTEX_FID_CACHE lpCache);
void cacheTvhittestinfoFids(JNIEnv *env, jobject lpTvhittestinfo, PTVHITTESTINFO_FID_CACHE lpCache);
void cacheTvinsertstructFids(JNIEnv *env, jobject lpTvinsertstruct, PTVINSERTSTRUCT_FID_CACHE lpCache);
void cacheTvitemFids(JNIEnv *env, jobject lpTvitem, PTVITEM_FID_CACHE lpCache);
@@ -1360,6 +1398,8 @@ void getDocinfoFields(JNIEnv *env, jobject lpObject, DOCINFO *lpDocinfo, PDOCINF
void setDocinfoFields(JNIEnv *env, jobject lpObject, DOCINFO *lpDocinfo, PDOCINFO_FID_CACHE lpDocinfoFc);
void getDrawitemstructFields(JNIEnv *env, jobject lpObject, DRAWITEMSTRUCT *lpDrawitemstruct, PDRAWITEMSTRUCT_FID_CACHE lpDrawitemstructFc);
void setDrawitemstructFields(JNIEnv *env, jobject lpObject, DRAWITEMSTRUCT *lpDrawitemstruct, PDRAWITEMSTRUCT_FID_CACHE lpDrawitemstructFc);
+void getGradientrectFields(JNIEnv *env, jobject lpObject, GRADIENT_RECT *lpGradientrect, GRADIENT_RECT_FID_CACHE *lpGradientrectFc);
+void setGradientrectFields(JNIEnv *env, jobject lpObject, GRADIENT_RECT *lpGradientrect, GRADIENT_RECT_FID_CACHE *lpGradientrectFc);
void getHditemFields(JNIEnv *env, jobject lpObject, HDITEM *lpHditem, HDITEM_FID_CACHE *lpHditemFc);
void setHditemFields(JNIEnv *env, jobject lpObject, HDITEM *lpHditem, HDITEM_FID_CACHE *lpHditemFc);
void getHdlayoutFields(JNIEnv *env, jobject lpObject, HDLAYOUT *lpHdlayout, HDLAYOUT_FID_CACHE *lpHdlayoutFc);
@@ -1444,6 +1484,8 @@ void getToolinfoFields(JNIEnv *env, jobject lpObject, TOOLINFO *lpToolinfo, TOOL
void setToolinfoFields(JNIEnv *env, jobject lpObject, TOOLINFO *lpToolinfo, TOOLINFO_FID_CACHE *lpToolinfoFc);
void getTrackmouseeventFields(JNIEnv *env, jobject lpObject, TRACKMOUSEEVENT *lpTrackmouseevent, TRACKMOUSEEVENT_FID_CACHE *lpTrackmouseeventFc);
void setTrackmouseeventFields(JNIEnv *env, jobject lpObject, TRACKMOUSEEVENT *lpTrackmouseevent, TRACKMOUSEEVENT_FID_CACHE *lpTrackmouseeventFc);
+void getTrivertexFields(JNIEnv *env, jobject lpObject, TRIVERTEX *lpTrivertex, TRIVERTEX_FID_CACHE *lpTrivertexFc);
+void setTrivertexFields(JNIEnv *env, jobject lpObject, TRIVERTEX *lpTrivertex, TRIVERTEX_FID_CACHE *lpTrivertexFc);
void getTvhittestinfoFields(JNIEnv *env, jobject lpObject, TVHITTESTINFO *lpTvhittestinfo, TVHITTESTINFO_FID_CACHE *lpTvhittestinfoFc);
void setTvhittestinfoFields(JNIEnv *env, jobject lpObject, TVHITTESTINFO *lpTvhittestinfo, TVHITTESTINFO_FID_CACHE *lpTvhittestinfoFc);
void getTvinsertstructFields(JNIEnv *env, jobject lpObject, TVINSERTSTRUCT *lpTvinsertstruct, TVINSERTSTRUCT_FID_CACHE *lpTvinsertstructFc);
@@ -1514,6 +1556,8 @@ void getVardesc1Fields(JNIEnv *env, jobject lpObject, VARDESC *lpVardesc, VARDES
void setVardesc1Fields(JNIEnv *env, jobject lpObject, VARDESC *lpVardesc, VARDESC1_FID_CACHE *lpVardescFc);
void getVardesc2Fields(JNIEnv *env, jobject lpObject, VARDESC *lpVardesc, VARDESC2_FID_CACHE *lpVardescFc);
void setVardesc2Fields(JNIEnv *env, jobject lpObject, VARDESC *lpVardesc, VARDESC2_FID_CACHE *lpVardescFc);
+void getGCP_RESULTSFields(JNIEnv *env, jobject lpObject, GCP_RESULTS *lpStruct, PGCP_RESULTS_FID_CACHE lpCache);
+void setGCP_RESULTSFields(JNIEnv *env, jobject lpObject, GCP_RESULTS *lpStruct, PGCP_RESULTS_FID_CACHE lpCache);
#endif // INC_structs_H \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/library/swt.c b/bundles/org.eclipse.swt/Eclipse SWT/win32/library/swt.c
index eb9bc7eb58..f16ddc5c0f 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/library/swt.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/library/swt.c
@@ -3220,6 +3220,38 @@ JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_win32_OS_GlobalUnlock
return (jboolean) GlobalUnlock((HANDLE)hMem);
}
+#ifdef USE_2000_CALLS
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: GradientFill
+ * Signature: (IIIIII)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_win32_OS_GradientFill
+ (JNIEnv *env, jclass that, jint hdc, int pVertex, jint dwNumVertex, int pMesh, jint dwNumMesh, jint dwMode)
+{
+ DECL_GLOB(pGlob)
+ BOOL rc = FALSE;
+ HMODULE hm;
+ FARPROC fp;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "GradientFill\n");
+#endif
+ /*
+ ** GradientFill is a Win2000 and Win98 specific call
+ ** If you link it into swt.dll, a system modal entry point not found dialog will
+ ** appear as soon as swt.dll is loaded. Here we check for the entry point and
+ ** only do the call if it exists.
+ */
+ if (! (hm = GetModuleHandle("msimg32.dll"))) hm = LoadLibrary("msimg32.dll");
+ if (hm && (fp = GetProcAddress(hm, "GradientFill"))) {
+ rc = fp((HDC)hdc, (PTRIVERTEX)pVertex, (ULONG)dwNumVertex, (PVOID)pMesh, (ULONG)dwNumMesh, (ULONG)dwMode);
+// rc = GradientFill((HDC)hdc, (PTRIVERTEX)pVertex, (ULONG)dwNumVertex, (PVOID)pMesh, (ULONG)dwNumMesh, (ULONG)dwMode);
+ }
+ return (jboolean) rc;
+}
+#endif
+
/*
* Class: org_eclipse_swt_internal_win32_OS
* Method: HeapAlloc
@@ -4357,6 +4389,29 @@ JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_win32_OS_MoveMemory__I_3II
/*
* Class: org_eclipse_swt_internal_win32_OS
* Method: MoveMemory
+ * Signature: (ILorg/eclipse/swt/internal/win32/GRADIENT_RECT;I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_win32_OS_MoveMemory__ILorg_eclipse_swt_internal_win32_GRADIENT_1RECT_2I
+ (JNIEnv *env, jclass that, jint Destination, jobject Source, jint Length)
+{
+ DECL_GLOB(pGlob)
+ GRADIENT_RECT gradientrect, *lpSource1=NULL;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "MoveMemory__ILorg_eclipse_swt_internal_win32_GRADIENT_1RECT_2I\n");
+#endif
+
+ if (Source) {
+ lpSource1 = &gradientrect;
+ cacheGradientrectFids(env, Source, &PGLOB(GradientrectFc));
+ getGradientrectFields(env, Source, lpSource1, &PGLOB(GradientrectFc));
+ }
+ MoveMemory((PVOID)Destination, lpSource1, Length);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: MoveMemory
* Signature: (ILorg/eclipse/swt/internal/win32/LOGFONT;I)V
*/
JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_win32_OS_MoveMemory__ILorg_eclipse_swt_internal_win32_LOGFONT_2I
@@ -4472,6 +4527,29 @@ JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_win32_OS_MoveMemory__ILorg_
/*
* Class: org_eclipse_swt_internal_win32_OS
* Method: MoveMemory
+ * Signature: (ILorg/eclipse/swt/internal/win32/TRIVERTEX;I)V
+ */
+JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_win32_OS_MoveMemory__ILorg_eclipse_swt_internal_win32_TRIVERTEX_2I
+ (JNIEnv *env, jclass that, jint Destination, jobject Source, jint Length)
+{
+ DECL_GLOB(pGlob)
+ TRIVERTEX trivertex, *lpSource1=NULL;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "MoveMemory__ILorg_eclipse_swt_internal_win32_TRIVERTEX_2I\n");
+#endif
+
+ if (Source) {
+ lpSource1 = &trivertex;
+ cacheTrivertexFids(env, Source, &PGLOB(TrivertexFc));
+ getTrivertexFields(env, Source, lpSource1, &PGLOB(TrivertexFc));
+ }
+ MoveMemory((PVOID)Destination, lpSource1, Length);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: MoveMemory
* Signature: (Lorg/eclipse/swt/internal/win32/DRAWITEMSTRUCT;II)V
*/
JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_win32_OS_MoveMemory__Lorg_eclipse_swt_internal_win32_DRAWITEMSTRUCT_2II
@@ -7963,4 +8041,277 @@ JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_win32_OS_MoveMemory__Lorg_e
cacheMsgFids(env, Destination, &PGLOB(MsgFc));
setMsgFields(env, Destination, lpDestination1, &PGLOB(MsgFc));
}
-} \ No newline at end of file
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: GetCharacterPlacement
+ * Signature:
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_win32_OS_GetCharacterPlacement
+ (JNIEnv *env, jclass that, jint hdc, jbyteArray lpString, jint nCount, jint nMaxExtent, jobject lpResults, jint dwFlags)
+{
+ DECL_GLOB(pGlob)
+ GCP_RESULTS results, *lpResults1=NULL;
+ LPCTSTR lpString1=NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "GetCharacterPlacement\n");
+#endif
+
+ if (lpString)
+ lpString1 = (LPCTSTR)(*env)->GetByteArrayElements(env, lpString, NULL);
+ if (lpResults) {
+ lpResults1 = &results;
+ cacheGCP_RESULTSFids(env, lpResults, &PGLOB(GCP_RESULTSFc));
+ getGCP_RESULTSFields(env, lpResults, lpResults1, &PGLOB(GCP_RESULTSFc));
+ }
+
+ rc = (jint) GetCharacterPlacement((HDC)hdc, lpString1, nCount, nMaxExtent, lpResults1, dwFlags);
+
+ if (lpString)
+ (*env)->ReleaseByteArrayElements(env, lpString, (jbyte *)lpString1, 0);
+ if (lpResults) {
+ setGCP_RESULTSFields(env, lpResults, lpResults1, &PGLOB(GCP_RESULTSFc));
+ }
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: ExtTextOut
+ * Signature:
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_win32_OS_ExtTextOut
+ (JNIEnv *env, jclass that, jint hdc, jint X, jint Y, jint fuOptions, jobject lprc, jbyteArray lpString, jint cbCount, jintArray lpDx)
+{
+ DECL_GLOB(pGlob)
+ RECT rect, *lpRect1=NULL;
+ LPCTSTR lpString1=NULL;
+ CONST INT* lpDx1 = NULL;
+ jboolean rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "ExtTextOut\n");
+#endif
+
+ if (lpString)
+ lpString1 = (LPCTSTR)(*env)->GetByteArrayElements(env, lpString, NULL);
+ if (lprc) {
+ lpRect1 = &rect;
+ cacheRectFids(env, lprc, &PGLOB(RectFc));
+ getRectFields(env, lprc, lpRect1, &PGLOB(RectFc));
+ }
+ if (lpDx)
+ lpDx1 = (CONST INT*)(*env)->GetIntArrayElements(env, lpDx, NULL);
+
+ rc = (jboolean) ExtTextOut((HDC)hdc, X, Y, fuOptions, lpRect1, lpString1, cbCount, lpDx1);
+
+ if (lpString)
+ (*env)->ReleaseByteArrayElements(env, lpString, (jbyte *)lpString1, 0);
+ if (lprc) {
+ setRectFields(env, lprc, lpRect1, &PGLOB(RectFc));
+ }
+ if (lpDx)
+ (*env)->ReleaseIntArrayElements(env, lpDx, (jint *)lpDx1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: GetFontLanguageInfo
+ * Signature:
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_win32_OS_GetFontLanguageInfo
+ (JNIEnv *env, jclass that, jint hdc)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "GetFontLanguageInfo\n");
+#endif
+
+ return (jint) GetFontLanguageInfo((HDC)hdc);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: GetKeyboardLayoutList
+ * Signature:
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_win32_OS_GetKeyboardLayoutList
+ (JNIEnv *env, jclass that, jint nBuff, jintArray lpList)
+{
+ HKL FAR *lpList1;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "GetKeyboardLayoutList\n");
+#endif
+
+ if (lpList)
+ lpList1 = (HKL FAR *)(*env)->GetIntArrayElements(env, lpList, NULL);
+
+ rc = (jint) GetKeyboardLayoutList(nBuff, lpList1);
+
+ if (lpList)
+ (*env)->ReleaseIntArrayElements(env, lpList, (jint *)lpList1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: GetKeyboardLayout
+ * Signature:
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_win32_OS_GetKeyboardLayout
+ (JNIEnv *env, jclass that, jint idThread)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "GetKeyboardLayout\n");
+#endif
+
+ return (jint) GetKeyboardLayout(idThread);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: ActivateKeyboardLayout
+ * Signature:
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_win32_OS_ActivateKeyboardLayout
+ (JNIEnv *env, jclass that, jint hkl, jint Flags)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "ActivateKeyboardLayout\n");
+#endif
+
+ return (jint) ActivateKeyboardLayout((HKL)hkl, Flags);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: SetTextAlign
+ * Signature:
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_win32_OS_SetTextAlign
+ (JNIEnv *env, jclass that, jint hdc, jint fMode)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "SetTextAlign\n");
+#endif
+
+ return (jint) SetTextAlign((HDC)hdc, fMode);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: TranslateCharsetInfo
+ * Signature:
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_win32_OS_TranslateCharsetInfo
+ (JNIEnv *env, jclass that, jint lpSrc, jintArray lpCs, jint dwFlags)
+{
+ LPCHARSETINFO lpCs1 =NULL;
+ jboolean rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "TranslateCharsetInfo\n");
+#endif
+
+ if (lpCs)
+ lpCs1 = (LPCHARSETINFO)(*env)->GetIntArrayElements(env, lpCs, NULL);
+
+ rc = (jboolean)TranslateCharsetInfo((DWORD *)lpSrc, lpCs1, dwFlags);
+
+ if (lpCs)
+ (*env)->ReleaseIntArrayElements(env, lpCs, (jint *)lpCs1, 0);
+
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: GetTextCharset
+ * Signature:
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_win32_OS_GetTextCharset
+ (JNIEnv *env, jclass that, jint hdc)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "GetTextCharset\n");
+#endif
+
+ return (jint) GetTextCharset((HDC)hdc);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: GetLocaleInfo
+ * Signature: (II[BI)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_win32_OS_GetLocaleInfo
+ (JNIEnv *env, jclass that, jint Locale, jint LCType, jbyteArray lpLCData, jint cchData)
+{
+ LPTSTR lpLCData1=NULL;
+ jint rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "GetLocaleInfo\n");
+#endif
+
+ if (lpLCData)
+ lpLCData1 = (*env)->GetByteArrayElements(env, lpLCData, NULL);
+
+ rc = (jint) GetLocaleInfo(Locale, LCType, lpLCData1, cchData);
+
+ if (lpLCData)
+ (*env)->ReleaseByteArrayElements(env, lpLCData, (jbyte *)lpLCData1, 0);
+ return rc;
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: EnumSystemLocales
+ * Signature: (II)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_win32_OS_EnumSystemLocales
+ (JNIEnv *env, jclass that, jint lpLocaleEnumProc, jint dwFlags)
+{
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "EnumSystemLocales\n");
+#endif
+
+ return (jboolean) EnumSystemLocales((LOCALE_ENUMPROC)lpLocaleEnumProc, (DWORD)dwFlags);
+}
+
+/*
+ * Class: org_eclipse_swt_internal_win32_OS
+ * Method: SystemParametersInfo
+ * Signature:
+ */
+JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_win32_OS_SystemParametersInfo
+ (JNIEnv *env, jclass that, jint uiAction, jint uiName, jobject pvParam, jint fWinIni)
+{
+ DECL_GLOB(pGlob)
+ RECT rect, *pvParam1=NULL;
+ jboolean rc;
+
+#ifdef DEBUG_CALL_PRINTS
+ fprintf(stderr, "SystemParametersInfo\n");
+#endif
+
+ if (pvParam) {
+ pvParam1 = &rect;
+ cacheRectFids(env, pvParam, &PGLOB(RectFc));
+ getRectFields(env, pvParam, pvParam1, &PGLOB(RectFc));
+ }
+
+ rc = (jboolean) SystemParametersInfo(uiAction, uiName, pvParam1, fWinIni);
+
+ if (pvParam) {
+ setRectFields(env, pvParam, pvParam1, &PGLOB(RectFc));
+ }
+
+ return rc;
+}
+
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/library/swt.rc b/bundles/org.eclipse.swt/Eclipse SWT/win32/library/swt.rc
index b875e93746..c43ae25984 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/library/swt.rc
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/library/swt.rc
@@ -34,7 +34,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//
VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,1,2,5
+ FILEVERSION 2,0,0,6
PRODUCTVERSION 0,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
@@ -52,10 +52,10 @@ BEGIN
BEGIN
VALUE "CompanyName", "IBM Corporation\0"
VALUE "FileDescription", "Standard Widget Toolkit\0"
- VALUE "FileVersion", "win32 0.125\0"
+ VALUE "FileVersion", "win32 2.006\0"
VALUE "InternalName", "SWT\0"
VALUE "LegalCopyright", "© Copyright IBM Corp. 2000, 2001. All Rights Reserved.\0"
- VALUE "OriginalFilename", "swt0125.dll\0"
+ VALUE "OriginalFilename", "swt-win32-2006.dll\0"
VALUE "ProductName", "\0"
VALUE "ProductVersion", "0, 0, 0, 0\0"
END
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 2e81321944..062f7b8fb9 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
@@ -46,7 +46,7 @@ public final class Cursor {
/**
* data used to create a HAND cursor.
*/
- static final byte[] HandSrcData = {
+ 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,
@@ -83,7 +83,7 @@ public final class Cursor {
(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,
(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff
};
- static final byte[] HandMaskData = {
+ 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,
@@ -184,7 +184,7 @@ public Cursor(Device device, int style) {
int height = OS.GetSystemMetrics(OS.SM_CYCURSOR);
if (width == 32 && height == 32) {
int hInst = OS.GetModuleHandle(null);
- handle = OS.CreateCursor(hInst, 5, 0, 32, 32, HandSrcData, HandMaskData);
+ handle = OS.CreateCursor(hInst, 5, 0, 32, 32, HAND_SOURCE, HAND_MASK);
}
}
@@ -259,6 +259,19 @@ public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int
*/
public void dispose () {
if (handle == 0) 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.
+ */
+ 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.
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 a6c06ba8bf..61cefddcda 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
@@ -404,6 +404,7 @@ public FontData [] getFontList (String faceName, boolean scalable) {
OS.EnumFontFamilies (hDC, lpFaceName, lpEnumFontFamProc, scalable ? 1 : 0);
}
} else {
+ /* Use the character encoding for the default locale */
byte [] lpFaceName = Converter.wcsToMbcs (0, faceName, true);
/**
* Bug in Windows 98. When EnumFontFamiliesEx is called with a specified face name, it
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 9b05c77236..bbffd73bc5 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
@@ -8,6 +8,7 @@ package org.eclipse.swt.graphics;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.win32.*;
import org.eclipse.swt.*;
+import java.util.Locale;
/**
* Instances of this class describe operating system fonts.
@@ -49,6 +50,12 @@ public final class FontData {
*/
public int height;
+ /**
+ * The locale of the font
+ * (Warning: This field is platform dependent)
+ */
+ Locale locale;
+
/**
* Constructs a new un-initialized font data.
*/
@@ -324,6 +331,37 @@ public boolean equals (Object object) {
data.lfFaceName31 == lf.lfFaceName31;
}
+int EnumLocalesProc(int lpLocaleString) {
+
+ /* Get the locale ID */
+ int length = 8;
+ byte[] buffer = new byte[length];
+ OS.MoveMemory(buffer, lpLocaleString, length);
+ int lcid = Integer.parseInt(new String(buffer, 0, length), 16);
+
+ /* Check the language */
+ int size = OS.GetLocaleInfo(lcid, OS.LOCALE_SISO639LANGNAME, buffer, length);
+ String lang = new String(buffer, 0, size - 1);
+ if (!locale.getLanguage().equals(lang)) return 1;
+
+ /* Check the country */
+ String javaCountry = locale.getCountry();
+ if (javaCountry.length() != 0) {
+ size = OS.GetLocaleInfo(lcid, OS.LOCALE_SISO3166CTRYNAME, buffer, length);
+ String country = new String(buffer, 0, size - 1);
+ if (!javaCountry.equals(country)) return 1;
+ }
+
+ /* Get the charset */
+ size = OS.GetLocaleInfo(lcid, OS.LOCALE_IDEFAULTANSICODEPAGE, buffer, length);
+ int cp = Integer.parseInt(new String(buffer, 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.
*
@@ -366,6 +404,7 @@ public String getName() {
System.arraycopy(bytes, 0, newBytes, 0, index);
bytes = newBytes;
}
+ /* Use the character encoding for the default locale */
char[] name = Converter.mbcsToWcs(0, bytes);
return new String(name);
}
@@ -433,6 +472,34 @@ public void setHeight(int 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 Locale of the <code>FontData</code>
+ */
+public void setLocale(Locale locale) {
+ this.locale = locale;
+ if (locale == 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
@@ -450,11 +517,12 @@ public void setHeight(int height) {
* <code>getName()</code>.
* </p>
*
- * @param name the name of the font data
+ * @param name the name of the font data (must not be null)
*
* @see #getName
*/
public void setName(String name) {
+ /* Use the character encoding for the default locale */
byte[] nameBytes = Converter.wcsToMbcs(0, name, true);
/* Pad nameBytes to 32 */
byte[] paddedNameBytes = new byte[32];
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 21b370b52d..67b27635a4 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
@@ -385,7 +385,7 @@ public void drawImage(Image image, int x, int y) {
* <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
* <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of their respective images</li>
* </ul>
- * @exception SWTError <uo>
+ * @exception SWTError <ul>
* <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li>
* </ul>
* @exception SWTException <ul>
@@ -587,8 +587,8 @@ void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHe
/* Create resources */
int srcHdc = OS.CreateCompatibleDC(handle);
int oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle);
- int memDib = createDIB(destWidth, destHeight, 32);
int memHdc = OS.CreateCompatibleDC(handle);
+ int memDib = createDIB(Math.max(srcWidth, destWidth), Math.max(srcHeight, destHeight), 32);
int oldMemBitmap = OS.SelectObject(memHdc, memDib);
BITMAP dibBM = new BITMAP();
@@ -601,23 +601,46 @@ void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHe
OS.MoveMemory(destData, dibBM.bmBits, sizeInBytes);
/* Get the foreground pixels */
- OS.SetStretchBltMode(memHdc, OS.COLORONCOLOR);
- OS.StretchBlt(memHdc, 0, 0, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, OS.SRCCOPY);
- byte[] srcData = new byte[sizeInBytes];
+ OS.BitBlt(memHdc, 0, 0, srcWidth, srcHeight, srcHdc, srcX, srcY, OS.SRCCOPY);
+ byte[] srcData = new byte[sizeInBytes];
OS.MoveMemory(srcData, dibBM.bmBits, sizeInBytes);
-
- /* Compose the pixels */
+
+ /* Merge the alpha channel in place */
int alpha = srcImage.alpha;
- byte[] alphaData = null;
- if (alpha == -1) {
- alphaData = new byte[destWidth * destHeight];
- ImageData.stretch8(srcImage.alphaData, imgWidth, srcX, srcY, srcWidth, srcHeight, alphaData, destWidth, 0, 0, destWidth, destHeight, null, false, false);
+ 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;
+ }
}
- for (int i = 0; i < sizeInBytes; i += 4) {
- if (alphaData != null) alpha = alphaData[i / 4] & 0xff;
- destData[i] += ((srcData[i] & 0xFF) - (destData[i] & 0xFF)) * alpha / 255;
- destData[i+1] += ((srcData[i+1] & 0xFF) - (destData[i+1] & 0xFF)) * alpha / 255;
- destData[i+2] += ((srcData[i+2] & 0xFF) - (destData[i+2] & 0xFF)) * alpha / 255;
+
+ /* Scale the foreground pixels with alpha */
+ OS.SetStretchBltMode(memHdc, OS.COLORONCOLOR);
+ OS.MoveMemory(dibBM.bmBits, srcData, sizeInBytes);
+ 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 */
@@ -699,10 +722,10 @@ void drawBitmapTransparent(Image srcImage, int srcX, int srcY, int srcWidth, int
/* Create the mask for the source image */
int maskHdc = OS.CreateCompatibleDC(hDC);
- int maskBitmap = OS.CreateBitmap(srcWidth, srcHeight, 1, 1, null);
+ 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, srcWidth, srcHeight, srcHdc, 0, 0, OS.SRCCOPY);
+ 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 */
@@ -790,7 +813,7 @@ public void drawOval (int x, int y, int width, int height) {
// 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,y+height);
+ OS.Ellipse(handle, x,y,x+width+1,y+height+1);
OS.SelectObject(handle,oldBrush);
}
@@ -933,7 +956,8 @@ public void drawRoundRectangle (int x, int y, int width, int height, int arcWidt
*/
public void drawString (String string, int x, int y) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- byte [] buffer = Converter.wcsToMbcs (0, string, false);
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage(), string, false);
OS.TextOut (handle, x, y, buffer, buffer.length);
}
@@ -959,7 +983,8 @@ public void drawString (String string, int x, int y) {
*/
public void drawString (String string, int x, int y, boolean isTransparent) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- byte [] buffer = Converter.wcsToMbcs (0, string, false);
+ if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage(), string, false);
if (isTransparent) {
int oldBkMode = OS.SetBkMode(handle, OS.TRANSPARENT);
OS.TextOut (handle, x, y, buffer, buffer.length);
@@ -989,9 +1014,10 @@ public void drawString (String string, int x, int y, boolean isTransparent) {
*/
public void drawText (String string, int x, int y) {
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);
- byte [] buffer = Converter.wcsToMbcs(0, string, false);
+ byte [] buffer = Converter.wcsToMbcs(getCodePage(), string, false);
OS.DrawText(handle, buffer, buffer.length, rect, OS.DT_EXPANDTABS | OS.DT_LEFT | OS.DT_NOPREFIX);
}
@@ -1017,9 +1043,10 @@ public void drawText (String string, int x, int y) {
*/
public void drawText (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);
RECT rect = new RECT();
OS.SetRect(rect, x, y, 0x7FFF, 0x7FFF);
- byte [] buffer = Converter.wcsToMbcs(0, string, false);
+ byte [] buffer = Converter.wcsToMbcs(getCodePage(), string, false);
if (isTransparent) {
int oldBkMode = OS.SetBkMode(handle, OS.TRANSPARENT);
OS.DrawText(handle, buffer, buffer.length, rect, OS.DT_EXPANDTABS | OS.DT_LEFT | OS.DT_NOPREFIX);
@@ -1126,6 +1153,98 @@ public void fillArc (int x, int y, int width, int height, int startAngle, int en
}
+/**
+ * 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 */
+ 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, gradientRect.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
@@ -1148,7 +1267,7 @@ public void fillOval (int x, int y, int width, int height) {
/* 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,y+height);
+ OS.Ellipse(handle, x,y,x+width+1,y+height+1);
OS.SelectObject(handle,oldPen);
}
@@ -1264,7 +1383,7 @@ public void fillRoundRectangle (int x, int y, int width, int height, int arcWidt
*/
public int getAdvanceWidth(char ch) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- byte[] buffer = Converter.wcsToMbcs(0, new char[] { ch });
+ byte[] buffer = Converter.wcsToMbcs(getCodePage(), new char[] { ch });
int val = 0;
for (int i = 0; i < buffer.length; i++) {
val |= (buffer[i] & 0xFF) << (i * 8);
@@ -1310,7 +1429,7 @@ public Color getBackground() {
*/
public int getCharWidth(char ch) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- byte[] buffer = Converter.wcsToMbcs(0, new char[] { ch });
+ byte[] buffer = Converter.wcsToMbcs(getCodePage(), new char[] { ch });
int val = 0;
for (int i = 0; i < buffer.length; i++) {
val |= (buffer[i] & 0xFF) << (i * 8);
@@ -1370,6 +1489,13 @@ public void getClipping (Region region) {
OS.SetRectRgn(region.handle, rect.left, rect.top, rect.right, rect.bottom);
}
+int getCodePage () {
+ 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.
@@ -1426,7 +1552,7 @@ public Color getForeground() {
* 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>.
+ * <code>SWT.LINE_DASHDOTDOT</code>.
*
* @return the style used for drawing lines
*
@@ -1715,7 +1841,7 @@ public void setForeground (Color color) {
* 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>.
+ * <code>SWT.LINE_DASHDOTDOT</code>.
*
* @param lineStyle the style to be used for drawing lines
*
@@ -1817,7 +1943,7 @@ public Point stringExtent(String string) {
OS.GetTextExtentPoint32(handle, SPACE, 1, size);
return new Point(0, size.cy);
} else {
- byte [] buffer = Converter.wcsToMbcs(0, string, false);
+ byte [] buffer = Converter.wcsToMbcs(getCodePage(), string, false);
OS.GetTextExtentPoint32(handle, buffer, buffer.length, size);
return new Point(size.cx, size.cy);
}
@@ -1851,7 +1977,7 @@ public Point textExtent(String string) {
return new Point(0, size.cy);
} else {
RECT rect = new RECT();
- byte [] buffer = Converter.wcsToMbcs(0, string, false);
+ byte [] buffer = Converter.wcsToMbcs(getCodePage(), string, false);
OS.DrawText(handle, buffer, buffer.length, rect, OS.DT_EXPANDTABS | OS.DT_LEFT | OS.DT_NOPREFIX | OS.DT_CALCRECT);
return new Point(rect.right, rect.bottom);
}
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 a321b0c87c..99fff994bb 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
@@ -40,7 +40,7 @@ import java.io.*;
* // 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);</code>
+ * Image i = new Image(device, data);
* </pre>
* <p>
* Applications which require even greater control over the image
@@ -477,6 +477,7 @@ public Image(Device device, Image srcImage, int flag) {
*
* @exception IllegalArgumentException <ul>
* <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>
*/
public Image(Device device, Rectangle bounds) {
@@ -1268,8 +1269,9 @@ void init(Device device, ImageData i) {
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, ImageData.MSB_FIRST, 0, 0, i.width, i.height, null, null, null, -1, null, 0,
- img.data, img.depth, img.bytesPerLine, ImageData.MSB_FIRST, 0, 0, img.width, img.height, null, null, null,
+ i.data, i.depth, i.bytesPerLine, i.getByteOrder(), 0, 0, i.width, i.height, null, null, null,
+ ImageData.ALPHA_OPAQUE, null, 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;
@@ -1285,15 +1287,22 @@ void init(Device device, ImageData i) {
* Windows-supported.
*/
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;
- PaletteData palette = i.palette;
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- int order = ImageData.MSB_FIRST;
+
switch (i.depth) {
+ case 8:
+ newDepth = 16;
+ newOrder = ImageData.LSB_FIRST;
+ newPalette = new PaletteData(0x7C00, 0x3E0, 0x1F);
+ break;
case 16:
- order = ImageData.LSB_FIRST;
+ newOrder = ImageData.LSB_FIRST;
if (!(redMask == 0x7C00 && greenMask == 0x3E0 && blueMask == 0x1F)) {
newPalette = new PaletteData(0x7C00, 0x3E0, 0x1F);
}
@@ -1312,10 +1321,11 @@ void init(Device device, ImageData i) {
SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
}
if (newPalette != null) {
- ImageData img = new ImageData(i.width, i.height, i.depth, newPalette);
+ ImageData img = new ImageData(i.width, i.height, newDepth, newPalette);
ImageData.blit(ImageData.BLIT_SRC,
- i.data, i.depth, i.bytesPerLine, order, 0, 0, i.width, i.height, redMask, greenMask, blueMask, -1, null, 0,
- img.data, img.depth, img.bytesPerLine, order, 0, 0, img.width, img.height, newPalette.redMask, newPalette.greenMask, newPalette.blueMask,
+ i.data, i.depth, i.bytesPerLine, i.getByteOrder(), 0, 0, i.width, i.height, redMask, greenMask, blueMask,
+ ImageData.ALPHA_OPAQUE, null, 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));
@@ -1479,6 +1489,7 @@ 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.
@@ -1549,8 +1560,15 @@ public boolean isDisposed() {
* 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
*
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 383a97d726..8a82e6cd99 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
@@ -52,6 +52,7 @@ Region(int handle) {
*
* @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>
@@ -60,6 +61,8 @@ Region(int 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);
+
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);
@@ -74,6 +77,7 @@ public void add (Rectangle rect) {
*
* @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>
@@ -82,6 +86,7 @@ public void add (Rectangle rect) {
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);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/win32/OS.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/win32/OS.java
index a48ecacad1..92f6e528d7 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/win32/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/win32/OS.java
@@ -29,6 +29,33 @@ public class OS {
/* OLE Constants */
public static final int S_OK = 0;
+ /* Charset Constants */
+// public static final int ANSI_CHARSET = 0;
+ public static final int DEFAULT_CHARSET = 1;
+// public static final int SYMBOL_CHARSET = 2;
+// public static final int SHIFTJIS_CHARSET = 128;
+// public static final int HANGEUL_CHARSET = 129;
+// public static final int GB2312_CHARSET = 134;
+// public static final int CHINESEBIG5_CHARSET = 136;
+// public static final int OEM_CHARSET = 255;
+// public static final int JOHAB_CHARSET = 130;
+// public static final int HEBREW_CHARSET = 177;
+// public static final int ARABIC_CHARSET = 178;
+// public static final int GREEK_CHARSET = 161;
+// public static final int TURKISH_CHARSET = 162;
+// public static final int VIETNAMESE_CHARSET = 163;
+// public static final int THAI_CHARSET = 222;
+// public static final int EASTEUROPE_CHARSET = 238;
+// public static final int RUSSIAN_CHARSET = 204;
+// public static final int MAC_CHARSET = 77;
+// public static final int BALTIC_CHARSET = 186;
+
+ /* Locale Constants */
+ public static final int LCID_SUPPORTED = 0x00000002;
+ public static final int LOCALE_SISO3166CTRYNAME = 0x0000005A;
+ public static final int LOCALE_SISO639LANGNAME = 0x00000059;
+ public static final int LOCALE_IDEFAULTANSICODEPAGE = 0x00001004;
+
/* Window Constants */
public static final int COLOR_BTNFACE = 15;
public static final int COLOR_BTNHIGHLIGHT = 20;
@@ -68,6 +95,159 @@ public class OS {
// public static final byte WBF_CLASS = 0x0F;
// public static final byte WBF_ISWHITE = 0x10;
+/*** BEGIN SystemParametersInfo ***/
+// public static final int SPI_GETBEEP = 1;
+// public static final int SPI_SETBEEP = 2;
+// public static final int SPI_GETMOUSE = 3;
+// public static final int SPI_SETMOUSE = 4;
+// public static final int SPI_GETBORDER = 5;
+// public static final int SPI_SETBORDER = 6;
+// public static final int SPI_GETKEYBOARDSPEED = 10;
+// public static final int SPI_SETKEYBOARDSPEED = 11;
+// public static final int SPI_LANGDRIVER = 12;
+// public static final int SPI_ICONHORIZONTALSPACING = 13;
+// public static final int SPI_GETSCREENSAVETIMEOUT = 14;
+// public static final int SPI_SETSCREENSAVETIMEOUT = 15;
+// public static final int SPI_GETSCREENSAVEACTIVE = 16;
+// public static final int SPI_SETSCREENSAVEACTIVE = 17;
+// public static final int SPI_GETGRIDGRANULARITY = 18;
+// public static final int SPI_SETGRIDGRANULARITY = 19;
+// public static final int SPI_SETDESKWALLPAPER = 20;
+// public static final int SPI_SETDESKPATTERN = 21;
+// public static final int SPI_GETKEYBOARDDELAY = 22;
+// public static final int SPI_SETKEYBOARDDELAY = 23;
+// public static final int SPI_ICONVERTICALSPACING = 24;
+// public static final int SPI_GETICONTITLEWRAP = 25;
+// public static final int SPI_SETICONTITLEWRAP = 26;
+// public static final int SPI_GETMENUDROPALIGNMENT = 27;
+// public static final int SPI_SETMENUDROPALIGNMENT = 28;
+// public static final int SPI_SETDOUBLECLKWIDTH = 29;
+// public static final int SPI_SETDOUBLECLKHEIGHT = 30;
+// public static final int SPI_GETICONTITLELOGFONT = 31;
+// public static final int SPI_SETDOUBLECLICKTIME = 32;
+// public static final int SPI_SETMOUSEBUTTONSWAP = 33;
+// public static final int SPI_SETICONTITLELOGFONT = 34;
+// public static final int SPI_GETFASTTASKSWITCH = 35;
+// public static final int SPI_SETFASTTASKSWITCH = 36;
+// public static final int SPI_SETDRAGFULLWINDOWS = 37;
+// public static final int SPI_GETDRAGFULLWINDOWS = 38;
+// public static final int SPI_GETNONCLIENTMETRICS = 41;
+// public static final int SPI_SETNONCLIENTMETRICS = 42;
+// public static final int SPI_GETMINIMIZEDMETRICS = 43;
+// public static final int SPI_SETMINIMIZEDMETRICS = 44;
+// public static final int SPI_GETICONMETRICS = 45;
+// public static final int SPI_SETICONMETRICS = 46;
+// public static final int SPI_SETWORKAREA = 47;
+ public static final int SPI_GETWORKAREA = 48;
+// public static final int SPI_SETPENWINDOWS = 49;
+// public static final int SPI_GETHIGHCONTRAST = 66;
+// public static final int SPI_SETHIGHCONTRAST = 67;
+// public static final int SPI_GETKEYBOARDPREF = 68;
+// public static final int SPI_SETKEYBOARDPREF = 69;
+// public static final int SPI_GETSCREENREADER = 70;
+// public static final int SPI_SETSCREENREADER = 71;
+// public static final int SPI_GETANIMATION = 72;
+// public static final int SPI_SETANIMATION = 73;
+// public static final int SPI_GETFONTSMOOTHING = 74;
+// public static final int SPI_SETFONTSMOOTHING = 75;
+// public static final int SPI_SETDRAGWIDTH = 76;
+// public static final int SPI_SETDRAGHEIGHT = 77;
+// public static final int SPI_SETHANDHELD = 78;
+// public static final int SPI_GETLOWPOWERTIMEOUT = 79;
+// public static final int SPI_GETPOWEROFFTIMEOUT = 80;
+// public static final int SPI_SETLOWPOWERTIMEOUT = 81;
+// public static final int SPI_SETPOWEROFFTIMEOUT = 82;
+// public static final int SPI_GETLOWPOWERACTIVE = 83;
+// public static final int SPI_GETPOWEROFFACTIVE = 84;
+// public static final int SPI_SETLOWPOWERACTIVE = 85;
+// public static final int SPI_SETPOWEROFFACTIVE = 86;
+// public static final int SPI_SETCURSORS = 87;
+// public static final int SPI_SETICONS = 88;
+// public static final int SPI_GETDEFAULTINPUTLANG = 89;
+// public static final int SPI_SETDEFAULTINPUTLANG = 90;
+// public static final int SPI_SETLANGTOGGLE = 91;
+// public static final int SPI_GETWINDOWSEXTENSION = 92;
+// public static final int SPI_SETMOUSETRAILS = 93;
+// public static final int SPI_GETMOUSETRAILS = 94;
+// public static final int SPI_SETSCREENSAVERRUNNING = 97;
+// public static final int SPI_SCREENSAVERRUNNING = SPI_SETSCREENSAVERRUNNING;
+// public static final int SPI_GETFILTERKEYS = 50;
+// public static final int SPI_SETFILTERKEYS = 51;
+// public static final int SPI_GETTOGGLEKEYS = 52;
+// public static final int SPI_SETTOGGLEKEYS = 53;
+// public static final int SPI_GETMOUSEKEYS = 54;
+// public static final int SPI_SETMOUSEKEYS = 55;
+// public static final int SPI_GETSHOWSOUNDS = 56;
+// public static final int SPI_SETSHOWSOUNDS = 57;
+// public static final int SPI_GETSTICKYKEYS = 58;
+// public static final int SPI_SETSTICKYKEYS = 59;
+// public static final int SPI_GETACCESSTIMEOUT = 60;
+// public static final int SPI_SETACCESSTIMEOUT = 61;
+// public static final int SPI_GETSERIALKEYS = 62;
+// public static final int SPI_SETSERIALKEYS = 63;
+// public static final int SPI_GETSOUNDSENTRY = 64;
+// public static final int SPI_SETSOUNDSENTRY = 65;
+// public static final int SPI_GETSNAPTODEFBUTTON = 95;
+// public static final int SPI_SETSNAPTODEFBUTTON = 96;
+// public static final int SPI_GETMOUSEHOVERWIDTH = 98;
+// public static final int SPI_SETMOUSEHOVERWIDTH = 99;
+// public static final int SPI_GETMOUSEHOVERHEIGHT = 100;
+// public static final int SPI_SETMOUSEHOVERHEIGHT = 101;
+// public static final int SPI_GETMOUSEHOVERTIME = 102;
+// public static final int SPI_SETMOUSEHOVERTIME = 103;
+// public static final int SPI_GETWHEELSCROLLLINES = 104;
+// public static final int SPI_SETWHEELSCROLLLINES = 105;
+// public static final int SPI_GETMENUSHOWDELAY = 106;
+// public static final int SPI_SETMENUSHOWDELAY = 107;
+// public static final int SPI_GETSHOWIMEUI = 110;
+// public static final int SPI_SETSHOWIMEUI = 111;
+// public static final int SPI_GETMOUSESPEED = 112;
+// public static final int SPI_SETMOUSESPEED = 113;
+// public static final int SPI_GETSCREENSAVERRUNNING = 114;
+// public static final int SPI_GETDESKWALLPAPER = 115;
+// public static final int SPI_GETACTIVEWINDOWTRACKING = 0x1000;
+// public static final int SPI_SETACTIVEWINDOWTRACKING = 0x1001;
+// public static final int SPI_GETMENUANIMATION = 0x1002;
+// public static final int SPI_SETMENUANIMATION = 0x1003;
+// public static final int SPI_GETCOMBOBOXANIMATION = 0x1004;
+// public static final int SPI_SETCOMBOBOXANIMATION = 0x1005;
+// public static final int SPI_GETLISTBOXSMOOTHSCROLLING = 0x1006;
+// public static final int SPI_SETLISTBOXSMOOTHSCROLLING = 0x1007;
+// public static final int SPI_GETGRADIENTCAPTIONS = 0x1008;
+// public static final int SPI_SETGRADIENTCAPTIONS = 0x1009;
+// public static final int SPI_GETKEYBOARDCUES = 0x100A;
+// public static final int SPI_SETKEYBOARDCUES = 0x100B;
+// public static final int SPI_GETMENUUNDERLINES = SPI_GETKEYBOARDCUES;
+// public static final int SPI_SETMENUUNDERLINES = SPI_SETKEYBOARDCUES;
+// public static final int SPI_GETACTIVEWNDTRKZORDER = 0x100C;
+// public static final int SPI_SETACTIVEWNDTRKZORDER = 0x100D;
+// public static final int SPI_GETHOTTRACKING = 0x100E;
+// public static final int SPI_SETHOTTRACKING = 0x100F;
+// public static final int SPI_GETMENUFADE = 0x1012;
+// public static final int SPI_SETMENUFADE = 0x1013;
+// public static final int SPI_GETSELECTIONFADE = 0x1014;
+// public static final int SPI_SETSELECTIONFADE = 0x1015;
+// public static final int SPI_GETTOOLTIPANIMATION = 0x1016;
+// public static final int SPI_SETTOOLTIPANIMATION = 0x1017;
+// public static final int SPI_GETTOOLTIPFADE = 0x1018;
+// public static final int SPI_SETTOOLTIPFADE = 0x1019;
+// public static final int SPI_GETCURSORSHADOW = 0x101A;
+// public static final int SPI_SETCURSORSHADOW = 0x101B;
+// public static final int SPI_GETUIEFFECTS = 0x103E;
+// public static final int SPI_SETUIEFFECTS = 0x103F;
+// public static final int SPI_GETFOREGROUNDLOCKTIMEOUT = 0x2000;
+// public static final int SPI_SETFOREGROUNDLOCKTIMEOUT = 0x2001;
+// public static final int SPI_GETACTIVEWNDTRKTIMEOUT = 0x2002;
+// public static final int SPI_SETACTIVEWNDTRKTIMEOUT = 0x2003;
+// public static final int SPI_GETFOREGROUNDFLASHCOUNT = 0x2004;
+// public static final int SPI_SETFOREGROUNDFLASHCOUNT = 0x2005;
+// public static final int SPI_GETCARETWIDTH = 0x2006;
+// public static final int SPI_SETCARETWIDTH = 0x2007;
+// public static final int SPIF_UPDATEINIFILE = 0x0001;
+// public static final int SPIF_SENDWININICHANGE = 0x0002;
+// public static final int SPIF_SENDCHANGE = SPIF_SENDWININICHANGE;
+/*** END SystemParamtersInfo ***/
+
/*** BEGIN SetWindowsHook ***/
// public static final int WH_MSGFILTER = -1;
// public static final int WH_JOURNALRECORD = 0;
@@ -156,8 +336,16 @@ public class OS {
public static final int WM_MOUSELEAVE = 0x02A3;
// public static final int WM_NCMOUSEHOVER = 0x02A0;
// public static final int WM_NCMOUSELEAVE = 0x02A2;
+ public static final int WM_MOUSEWHEEL = 0x020A;
/*** END TrackMouseEvent ***/
+/*** BEGIN GradientFill ***/
+ public static final int GRADIENT_FILL_RECT_H = 0;
+ public static final int GRADIENT_FILL_RECT_V = 1;
+// public static final int GRADIENT_FILL_TRIANGLE = 2;
+// public static final int GRADIENT_FILL_OP_FLAG = 0xff;
+/*** END GradientFill ***/
+
/*** BEGIN ICC ***/
// public static final int ICC_LISTVIEW_CLASSES = 0x00000001;
// public static final int ICC_TREEVIEW_CLASSES = 0x00000002;
@@ -819,7 +1007,6 @@ public class OS {
// public static final int DCX_PARENTCLIP = 0x20;
// public static final int DCX_VALIDATE = 0x200000;
// public static final int DCX_WINDOW = 0x1;
- public static final int DEFAULT_CHARSET = 1;
public static final int DEFAULT_GUI_FONT = 0x11;
// public static final int DEFAULT_PALETTE = 0xF;
// public static final int DEVICE_DEFAULT_FONT = 0xE;
@@ -1063,7 +1250,7 @@ public class OS {
public static final int EM_GETLIMITTEXT = 0xD5;
public static final int EM_GETLINE = 0xC4;
public static final int EM_GETLINECOUNT = 0xBA;
-// public static final int EM_GETMARGINS = 0xD4;
+ public static final int EM_GETMARGINS = 0xD4;
// public static final int EM_GETMODIFY = 0xB8;
// public static final int EM_GETOLEINTERFACE = (WM_USER + 60);
// public static final int EM_GETOPTIONS = (WM_USER + 78);
@@ -1530,7 +1717,7 @@ public class OS {
// public static final int HWND_DESKTOP = 0x0;
// public static final int HWND_NOTOPMOST = 0xFFFFFFFE;
public static final int HWND_TOP = 0x0;
-// public static final int HWND_TOPMOST = 0xFFFFFFFF;
+ public static final int HWND_TOPMOST = 0xFFFFFFFF;
// public static final int I_CHILDRENCALLBACK = -1;
// public static final int ICM_LEVEL2 = 0x0002;
// public static final int ICM_LEVEL2_5 = 0x0003;
@@ -3131,6 +3318,8 @@ public class OS {
// public static final int TC_SO_ABLE = 0x1000;
// public static final int TC_UA_ABLE = 0x800;
// public static final int TC_VA_ABLE = 0x4000;
+ public static final int TCI_SRCCHARSET = 1;
+ public static final int TCI_SRCCODEPAGE = 2;
public static final int TCIF_IMAGE = 0x0002;
// public static final int TCIF_PARAM = 0x0008;
// public static final int TCIF_RTLREADING = 0x0004;
@@ -3250,7 +3439,7 @@ public class OS {
// public static final int TTM_RELAYEVENT = (WM_USER + 7);
// public static final int TTM_SETDELAYTIME = (WM_USER + 3);
// public static final int TTM_SETMARGIN = (WM_USER + 26);
-// public static final int TTM_SETMAXTIPWIDTH = (WM_USER + 24);
+ public static final int TTM_SETMAXTIPWIDTH = (WM_USER + 24);
// public static final int TTM_SETTIPBKCOLOR = (WM_USER + 19);
// public static final int TTM_SETTIPTEXTCOLOR = (WM_USER + 20);
// public static final int TTM_SETTOOLINFO = (WM_USER + 9);
@@ -3760,7 +3949,7 @@ public class OS {
// public static final int WS_EX_RTLREADING = 0x2000;
public static final int WS_EX_STATICEDGE = 0x20000;
public static final int WS_EX_TOOLWINDOW = 0x80;
-// public static final int WS_EX_TOPMOST = 0x8;
+ public static final int WS_EX_TOPMOST = 0x8;
// public static final int WS_EX_TRANSPARENT = 0x20;
// public static final int WS_EX_WINDOWEDGE = 0x100;
// public static final int WS_GROUP = 0x20000;
@@ -4096,6 +4285,7 @@ public static final native int GlobalFree (int hMem);
public static final native int GlobalLock (int hMem);
public static final native int GlobalSize (int hMem);
public static final native boolean GlobalUnlock (int hMem);
+public static final native boolean GradientFill(int hdc, int pVertex, int dwNumVertex, int pMesh, int dwNumMesh, int dwMode);
public static final native int HeapAlloc (
int hHeap, // handle to the private heap block
int dwFlags, // heap allocation control flags
@@ -4214,6 +4404,11 @@ public static final native void MoveMemory (
int Length // size, in bytes, of block to move
);
public static final native void MoveMemory (
+ int Destination, // address of move destination
+ GRADIENT_RECT Source, // address of block to move
+ int Length // size, in bytes, of block to move
+);
+public static final native void MoveMemory (
int Destination, // address of move destination
LOGFONT Source, // address of block to move
int Length // size, in bytes, of block to move
@@ -4234,6 +4429,11 @@ public static final native void MoveMemory (
int Length // size, in bytes, of block to move
);
public static final native void MoveMemory (
+ int Destination, // address of move destination
+ TRIVERTEX Source, // address of block to move
+ int Length // size, in bytes, of block to move
+);
+public static final native void MoveMemory (
DRAWITEMSTRUCT Destination, // address of move destination
int Source, // address of block to move
int Length // size, in bytes, of block to move
@@ -4468,4 +4668,24 @@ public static final native boolean DrawState (int hdc, int hbr, int lpOutputFunc
public static final native int CreatePen (int fnPenStyle, int nWidth, int crColor);
public static final native int SetStretchBltMode(int hdc, int iStretchMode);
+
+public static final native int GetCharacterPlacement(int hdc, byte[] lpString, int nCount, int nMaxExtent, GCP_RESULTS lpResults, int dwFlags);
+public static final native boolean ExtTextOut(int hdc, int X, int Y, int fuOptions, RECT lprc, byte[] lpString, int cbCount, int[] lpDx);
+public static final native int GetFontLanguageInfo(int hdc);
+public static final native int GetKeyboardLayoutList(int nBuff, int[] lpList);
+public static final native int GetKeyboardLayout(int idThread);
+public static final native int ActivateKeyboardLayout(int hkl, int Flags);
+public static final native int SetTextAlign(int hdc, int fMode);
+
+public static final native boolean TranslateCharsetInfo(int lpSrc, int [] lpCs, int dwFlags);
+public static final native int GetTextCharset(int hdc);
+public static final native int GetLocaleInfo(int Locale, int LCType, byte[] lpLCData, int cchData);
+public static final native boolean EnumSystemLocales(int lpLocaleEnumProc, int dwFlags);
+
+public static final native boolean SystemParametersInfo (
+ int uiAction, // system parameter to retrieve or set
+ int uiParam, // depends on action to be taken
+ RECT pvParam, // depends on action to be taken
+ int fWinIni // user profile update option
+);
}
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 82d85ea684..da0f6be0cb 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
@@ -317,7 +317,7 @@ public String getText () {
if (length == 0) return "";
byte [] buffer1 = new byte [length + 1];
OS.GetWindowText (handle, buffer1, buffer1.length);
- char [] buffer2 = Converter.mbcsToWcs (0, buffer1);
+ char [] buffer2 = Converter.mbcsToWcs (getCodePage (), buffer1);
return new String (buffer2, 0, buffer2.length - 1);
}
@@ -431,6 +431,7 @@ void setDefault (boolean value) {
}
public boolean setFocus () {
+ checkWidget();
if ((style & SWT.ARROW) != 0) return false;
if (!super.setFocus ()) return false;
menuShell ().setDefaultButton (this, false);
@@ -443,6 +444,9 @@ public boolean setFocus () {
*
* @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>
@@ -452,6 +456,7 @@ 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:
@@ -541,7 +546,7 @@ public void setText (String string) {
if (newBits != oldBits) {
OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);
}
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
OS.SetWindowText (handle, buffer);
}
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 d41b4140b2..e884b3276c 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
@@ -164,8 +164,11 @@ public void scroll (int destX, int destY, int x, int y, int width, int height, b
* 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
+ * @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>
@@ -178,7 +181,10 @@ public void setCaret (Caret caret) {
this.caret = newCaret;
if (isFocusControl ()) {
if (oldCaret != null) oldCaret.killFocus ();
- if (newCaret != null) newCaret.setFocus ();
+ if (newCaret != null) {
+ if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ newCaret.setFocus ();
+ }
}
}
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 276cb08483..0788bb5ef5 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
@@ -29,6 +29,7 @@ public class Caret extends Widget {
int x, y, width, height;
boolean moved, resized;
boolean isVisible;
+ Image image;
Font font;
LOGFONT oldFont;
@@ -93,6 +94,10 @@ int defaultFont () {
*/
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);
}
@@ -119,6 +124,21 @@ public Font 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).
*
@@ -161,6 +181,10 @@ public Canvas getParent () {
*/
public Point getSize () {
checkWidget();
+ if (image != null) {
+ Rectangle rect = image.getBounds ();
+ return new Point (rect.width, rect.height);
+ }
return new Point (width, height);
}
@@ -242,6 +266,7 @@ void releaseChild () {
void releaseWidget () {
super.releaseWidget ();
parent = null;
+ image = null;
font = null;
oldFont = null;
}
@@ -250,7 +275,9 @@ void resize () {
resized = false;
int hwnd = parent.handle;
OS.DestroyCaret ();
- OS.CreateCaret (hwnd, 0, width, height);
+ int hBitmap = 0;
+ if (image != null) hBitmap = image.handle;
+ OS.CreateCaret (hwnd, hBitmap, width, height);
OS.SetCaretPos (x, y);
OS.ShowCaret (hwnd);
move ();
@@ -328,7 +355,9 @@ public void setBounds (Rectangle rect) {
void setFocus () {
int hwnd = parent.handle;
- OS.CreateCaret (hwnd, 0, width, height);
+ int hBitmap = 0;
+ if (image != null) hBitmap = image.handle;
+ OS.CreateCaret (hwnd, hBitmap, width, height);
move ();
if (font != null) {
int hFont = font.handle;
@@ -362,6 +391,24 @@ public void setFont (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 SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the 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;
+ if (isVisible && parent.hasFocus ()) resize ();
+}
+
void setIMEFont (int hFont) {
if (!IsDBLocale) return;
LOGFONT logFont = new LOGFONT ();
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 03ae84c265..6aa1958143 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
@@ -86,6 +86,7 @@ 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 */
byte [] buffer = Converter.wcsToMbcs (0, title, true);
OS.SetWindowText (hdlg, buffer);
}
@@ -97,7 +98,7 @@ int CCHookProc (int hdlg, int uiMsg, int lParam, int lpData) {
/**
* Returns the currently selected color in the receiver.
*
- * @return the RGB value for the selected color
+ * @return the RGB value for the selected color, may be null
*
* @see PaletteData#getRGBs
*/
@@ -109,7 +110,9 @@ public RGB getRGB () {
* Makes the receiver visible and brings it to the front
* of the display.
*
- * @return the selected color
+ * @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>
@@ -170,7 +173,9 @@ public RGB open () {
/**
* Returns the receiver's selected color to be the argument.
*
- * @param rgb the new RGB value for the selected color
+ * @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
*/
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 9a09f765ff..b6e750f504 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
@@ -63,7 +63,7 @@ public class Combo extends Composite {
}
static final int ComboProc;
- static final byte [] ComboClass = Converter.wcsToMbcs (0,"COMBOBOX\0", false);
+ static final byte [] ComboClass = Converter.wcsToMbcs (0,"COMBOBOX\0");
/*
* These are the undocumented control id's for the children of
* a combo box. Since there are no constants for these values,
@@ -132,7 +132,7 @@ public Combo (Composite parent, int style) {
public void add (String string) {
checkWidget ();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (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);
@@ -167,7 +167,7 @@ public void add (String string) {
public void add (String string, int index) {
checkWidget ();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (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) {
@@ -423,7 +423,7 @@ public String getItem (int index) {
byte [] buffer1 = new byte [length + 1];
int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer1);
if (result != OS.CB_ERR) {
- char [] buffer2 = Converter.mbcsToWcs (0, buffer1);
+ char [] buffer2 = Converter.mbcsToWcs (getCodePage (), buffer1);
return new String (buffer2, 0, buffer2.length - 1);
}
}
@@ -563,7 +563,7 @@ public String getText () {
if (length == 0) return "";
byte [] buffer1 = new byte [length + 1];
OS.GetWindowText (handle, buffer1, buffer1.length);
- char [] buffer2 = Converter.mbcsToWcs (0, buffer1);
+ char [] buffer2 = Converter.mbcsToWcs (getCodePage (), buffer1);
return new String (buffer2, 0, buffer2.length - 1);
}
@@ -645,7 +645,6 @@ protected boolean hasFocus () {
* </ul>
*/
public int indexOf (String string) {
- checkWidget ();
return indexOf (string, 0);
}
@@ -673,7 +672,7 @@ public int indexOf (String string, int start) {
int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
if (!((0 <= start) && (start < count))) return -1;
int index = start - 1, last;
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
do {
index = OS.SendMessage (handle, OS.CB_FINDSTRINGEXACT, last = index, buffer);
if ((index == OS.CB_ERR) || (index <= last)) return -1;
@@ -802,7 +801,6 @@ public void remove (int start, int end) {
* </ul>
*/
public void remove (String string) {
- checkWidget ();
int index = indexOf (string, 0);
if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT);
remove (index);
@@ -995,9 +993,10 @@ 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];
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (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);
@@ -1054,7 +1053,7 @@ protected boolean setTabGroupFocus () {
public void setText (String string) {
checkWidget ();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
if ((style & SWT.READ_ONLY) != 0) {
int code = OS.SendMessage (handle, OS.CB_SELECTSTRING, -1, buffer);
if (code != OS.CB_ERR) {
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 dfd48646a4..feb9e57ed9 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
@@ -314,7 +314,9 @@ boolean setTabGroupFocus () {
if (!isVisible ()) return false;
if (isTabItem ()) return setTabItemFocus ();
Control [] children = _getChildren ();
- if (children.length == 0) return setTabItemFocus ();
+ if (children.length == 0) {
+ return (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) && setTabItemFocus ();
+ }
for (int i=0; i<children.length; i++) {
Control child = children [i];
if (child.isVisible () && child.setRadioFocus ()) return true;
@@ -371,7 +373,7 @@ LRESULT WM_GETDLGCODE (int wParam, int lParam) {
if (result != null) return result;
if ((state & CANVAS) != 0) {
if ((style & SWT.NO_FOCUS) != 0) return new LRESULT (OS.DLGC_STATIC);
- if (hooks (SWT.KeyDown)) {
+ if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
int flags = OS.DLGC_WANTALLKEYS | OS.DLGC_WANTARROWS | OS.DLGC_WANTTAB;
return new LRESULT (flags);
}
@@ -410,6 +412,8 @@ LRESULT WM_NOTIFY (int wParam, int lParam) {
OS.MoveMemory (lpnmtdi, lParam, NMTTDISPINFO.sizeof);
String string = toolTipText (lpnmtdi);
if (string != null && string.length () != 0) {
+ string = Display.withCrLf (string);
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs (0, string, true);
getShell ().setToolTipText (lpnmtdi, buffer);
OS.MoveMemory (lParam, lpnmtdi, NMTTDISPINFO.sizeof);
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 abe7375db5..254377f14a 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
@@ -572,6 +572,16 @@ public Rectangle getBounds () {
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];
+ OS.TranslateCharsetInfo (cs, lpCs, OS.TCI_SRCCHARSET);
+ return lpCs [1];
+}
+
/**
* Returns the display that the receiver was created on.
*
@@ -880,7 +890,7 @@ boolean hasFocus () {
* @private
*/
public int internal_new_GC (GCData data) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ checkWidget();
int hDC;
if (data == null || data.ps == null) {
hDC = OS.GetDC (handle);
@@ -913,7 +923,7 @@ public int internal_new_GC (GCData data) {
* @private
*/
public void internal_dispose_GC (int hDC, GCData data) {
- //if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
+ checkWidget ();
if (data == null || data.ps == null) {
OS.ReleaseDC (handle, hDC);
} else {
@@ -1014,10 +1024,6 @@ boolean isTabItem () {
return true;
}
-boolean isValidWidget () {
- return handle != 0;
-}
-
/**
* Returns <code>true</code> if the receiver is visible, and
* <code>false</code> otherwise.
@@ -1061,6 +1067,9 @@ boolean mnemonicMatch (char key) {
*
* @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>
@@ -1070,10 +1079,20 @@ public void moveAbove (Control control) {
checkWidget ();
int hwndAfter = OS.HWND_TOP;
if (control != null) {
+ if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
int hwnd = control.handle;
- if ((hwnd == 0) || (hwnd == handle)) return;
+ if (hwnd == 0 || hwnd == handle) return;
hwndAfter = OS.GetWindow (hwnd, OS.GW_HWNDPREV);
- if (hwndAfter == 0) hwndAfter = OS.HWND_TOP;
+ /*
+ * 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 (hwndAfter == 0 || hwndAfter == handle) {
+ hwndAfter = OS.HWND_TOP;
+ }
}
int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
OS.SetWindowPos (handle, hwndAfter, 0, 0, 0, 0, flags);
@@ -1088,6 +1107,9 @@ public void moveAbove (Control control) {
*
* @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>
@@ -1096,8 +1118,11 @@ public void moveAbove (Control control) {
public void moveBelow (Control control) {
checkWidget ();
int hwndAfter = OS.HWND_BOTTOM;
- if (control != null) hwndAfter = control.handle;
- if (hwndAfter == 0) return;
+ if (control != null) {
+ if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
+ hwndAfter = control.handle;
+ }
+ if (hwndAfter == 0 || hwndAfter == handle) return;
int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
OS.SetWindowPos (handle, hwndAfter, 0, 0, 0, 0, flags);
}
@@ -1187,6 +1212,7 @@ public void redraw () {
*/
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 ();
int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
@@ -1465,20 +1491,21 @@ boolean sendMouseEvent (int type, int button, int msg, int wParam, int lParam) {
if (OS.GetKeyState (OS.VK_MENU) < 0) event.stateMask |= SWT.ALT;
if ((wParam & OS.MK_SHIFT) != 0) event.stateMask |= SWT.SHIFT;
if ((wParam & OS.MK_CONTROL) != 0) event.stateMask |= SWT.CONTROL;
- if (button != 1 || (type != SWT.MouseDown && type != SWT.MouseDoubleClick)) {
- if (type == SWT.MouseUp || (wParam & OS.MK_LBUTTON) != 0) {
- event.stateMask |= SWT.BUTTON1;
- }
- }
- if (button != 2 || (type != SWT.MouseDown && type != SWT.MouseDoubleClick)) {
- if (type == SWT.MouseUp || (wParam & OS.MK_MBUTTON) != 0) {
- event.stateMask |= SWT.BUTTON2;
- }
- }
- if (button != 3 || (type != SWT.MouseDown && type != SWT.MouseDoubleClick)) {
- if (type == SWT.MouseUp || (wParam & OS.MK_RBUTTON) != 0) {
- event.stateMask |= SWT.BUTTON3;
- }
+ if ((wParam & OS.MK_LBUTTON) != 0) event.stateMask |= SWT.BUTTON1;
+ if ((wParam & OS.MK_MBUTTON) != 0) event.stateMask |= SWT.BUTTON2;
+ if ((wParam & OS.MK_RBUTTON) != 0) event.stateMask |= SWT.BUTTON3;
+ switch (type) {
+ case SWT.MouseDown:
+ case SWT.MouseDoubleClick:
+ if (button == 1) event.stateMask &= ~SWT.BUTTON1;
+ if (button == 2) event.stateMask &= ~SWT.BUTTON2;
+ if (button == 3) event.stateMask &= ~SWT.BUTTON3;
+ break;
+ case SWT.MouseUp:
+ if (button == 1) event.stateMask |= SWT.BUTTON1;
+ if (button == 2) event.stateMask |= SWT.BUTTON2;
+ if (button == 3) event.stateMask |= SWT.BUTTON3;
+ break;
}
return sendMouseEvent (type, msg, wParam, lParam, event);
}
@@ -1495,6 +1522,9 @@ boolean sendMouseEvent (int type, int msg, int wParam, int lParam, Event event)
*
* @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>
@@ -1504,6 +1534,7 @@ 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);
@@ -1624,6 +1655,9 @@ public void setCapture (boolean capture) {
*
* @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>
@@ -1632,7 +1666,10 @@ public void setCapture (boolean capture) {
public void setCursor (Cursor cursor) {
checkWidget ();
hCursor = 0;
- if (cursor != null) hCursor = cursor.handle;
+ if (cursor != null) {
+ if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ hCursor = cursor.handle;
+ }
int hwndCursor = OS.GetCapture ();
if (hwndCursor == 0) {
POINT pt = new POINT ();
@@ -1721,6 +1758,9 @@ public boolean setFocus () {
*
* @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>
@@ -1729,7 +1769,10 @@ public boolean setFocus () {
public void setFont (Font font) {
checkWidget ();
int hFont = 0;
- if (font != null) hFont = font.handle;
+ 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);
}
@@ -1741,6 +1784,9 @@ public void setFont (Font font) {
*
* @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>
@@ -1750,6 +1796,7 @@ 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);
@@ -1772,29 +1819,25 @@ boolean setKeyState (Event event, int type) {
if (event.keyCode == 0 && event.character == 0) {
return false;
}
- if (OS.GetKeyState (OS.VK_MENU) < 0) {
- if (type != SWT.KeyDown || event.keyCode != SWT.ALT) {
- event.stateMask |= SWT.ALT;
- }
- }
- if (OS.GetKeyState (OS.VK_SHIFT) < 0) {
- if (type != SWT.KeyDown || event.keyCode != SWT.SHIFT) {
- event.stateMask |= SWT.SHIFT;
- }
- }
- if (OS.GetKeyState (OS.VK_CONTROL) < 0) {
- if (type != SWT.KeyDown || event.keyCode != SWT.CONTROL) {
- event.stateMask |= SWT.CONTROL;
- }
- }
- if (type == SWT.KeyUp) {
- if (event.keyCode == SWT.ALT) event.stateMask |= SWT.ALT;
- if (event.keyCode == SWT.SHIFT) event.stateMask |= SWT.SHIFT;
- if (event.keyCode == SWT.CONTROL) event.stateMask |= SWT.CONTROL;
- }
+ if (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.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;
}
@@ -1862,6 +1905,7 @@ public void setLocation (Point location) {
* @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>
@@ -1871,6 +1915,7 @@ public void setLocation (Point location) {
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);
}
@@ -1909,7 +1954,6 @@ boolean setRadioFocus () {
*/
public void setRedraw (boolean redraw) {
checkWidget ();
-
/*
* This code is intentionally commented.
*
@@ -1990,6 +2034,11 @@ boolean setTabGroupFocus () {
}
boolean setTabItemFocus () {
+ Control [] path = getPath ();
+ for (int i=0; i<path.length; i++) {
+ Point size = path [i].getSize ();
+ if (size.x == 0 || size.y == 0) return false;
+ }
return setFocus ();
}
@@ -2364,6 +2413,9 @@ int widgetStyle () {
* @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>
@@ -2372,6 +2424,7 @@ int widgetStyle () {
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;
}
@@ -2390,7 +2443,7 @@ int windowProc (int msg, int wParam, int lParam) {
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_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:
@@ -2399,18 +2452,18 @@ int windowProc (int msg, int wParam, int lParam) {
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_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_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_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_KEYDOWN: result = WM_KEYDOWN (wParam, lParam); break;
+ case OS.WM_GETFONT: result = WM_GETFONT (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;
@@ -2426,11 +2479,12 @@ int windowProc (int msg, int wParam, int lParam) {
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_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;
@@ -2441,18 +2495,18 @@ int windowProc (int msg, int wParam, int lParam) {
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_SETFONT: result = WM_SETFONT (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_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;
+ 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);
@@ -2874,6 +2928,7 @@ LRESULT WM_KEYUP (int wParam, int lParam) {
if (!hooks (SWT.KeyUp)) {
display.lastVirtual = false;
display.lastKey = display.lastAscii = 0;
+ return null;
}
/* Map the virtual key. */
@@ -2906,27 +2961,19 @@ LRESULT WM_KEYUP (int wParam, int lParam) {
}
display.lastVirtual = display.isVirtualKey (display.lastKey);
}
+
+ LRESULT result = null;
if (!sendKeyEvent (SWT.KeyUp, OS.WM_KEYUP, wParam, lParam)) {
- return LRESULT.ZERO;
+ result = LRESULT.ZERO;
}
- return null;
+ display.lastVirtual = false;
+ display.lastKey = display.lastAscii = 0;
+ return result;
}
LRESULT WM_KILLFOCUS (int wParam, int lParam) {
-
- /* Build the focus out list */
- int index = 0;
- Control [] focusOut = getPath ();
Display display = getDisplay ();
- Control control = display.findControl (wParam);
- if (control != null) {
- Control [] focusIn = control.getPath ();
- int length = Math.min (focusIn.length, focusOut.length);
- while (index < length) {
- if (focusIn [index] != focusOut [index]) break;
- index++;
- }
- }
+ Shell shell = getShell ();
/*
* It is possible (but unlikely), that application
@@ -2938,15 +2985,15 @@ LRESULT WM_KILLFOCUS (int wParam, int lParam) {
// widget could be disposed at this point
/*
- * It is possible (but unlikely), that application
- * code could have destroyed some of the widgets in
- * the focus out event or the deactivate event. If
- * this happens, keep processing those widgets that
- * are not disposed.
- */
- for (int i=focusOut.length-1; i>=index; --i) {
- if (!focusOut [i].isDisposed ()) {
- focusOut [i].sendEvent (SWT.Deactivate);
+ * 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);
}
}
@@ -3225,6 +3272,18 @@ LRESULT WM_MOUSEMOVE (int wParam, int lParam) {
return null;
}
+LRESULT WM_MOUSEWHEEL (int wParam, int lParam) {
+ /*
+ * Feature in Windows. If the WM_MOUSEWHEEL is handled by
+ * the control, it may not send WM_VSCROLL and WM_HSCROLL
+ * messages. The fix is to intercept the WM_MOUSEWHEEL message
+ * and call the DefWindowProc which will convert the message to
+ * send the appropriate WM_HSCROLL or WM_VSCROLL message.
+ */
+ int code = OS.DefWindowProc (handle, OS.WM_MOUSEWHEEL, wParam, lParam);
+ return new LRESULT (code);
+}
+
LRESULT WM_MOVE (int wParam, int lParam) {
sendEvent (SWT.Move);
// widget could be disposed at this point
@@ -3365,20 +3424,7 @@ LRESULT WM_SETCURSOR (int wParam, int lParam) {
}
LRESULT WM_SETFOCUS (int wParam, int lParam) {
-
- /* Build the focus in list */
- int index = 0;
- Control [] focusIn = getPath ();
- Display display = getDisplay ();
- Control control = display.findControl (wParam);
- if (control != null) {
- Control [] focusOut = control.getPath ();
- int length = Math.min (focusIn.length, focusOut.length);
- while (index < length) {
- if (focusIn [index] != focusOut [index]) break;
- index++;
- }
- }
+ Shell shell = getShell ();
/*
* It is possible (but unlikely), that application
@@ -3390,16 +3436,13 @@ LRESULT WM_SETFOCUS (int wParam, int lParam) {
// widget could be disposed at this point
/*
- * It is possible (but unlikely), that application
- * code could have destroyed some of the widgets in
- * the focus in event or the activate event. If
- * this happens, keep processing those widgets that
- * are not disposed.
- */
- for (int i=focusIn.length-1; i>=index; --i) {
- if (!focusIn [i].isDisposed ()) {
- focusIn [i].sendEvent (SWT.Activate);
- }
+ * 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);
}
/*
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 82d52d38da..3334b39799 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
@@ -281,7 +281,8 @@ public CoolItem [] getItems () {
* @return the index of the item
*
* @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
+ * <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>
@@ -291,6 +292,7 @@ public CoolItem [] getItems () {
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);
}
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 2f273e8017..2077fd31ec 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
@@ -32,7 +32,7 @@ public class CoolItem extends Item {
/**
* Constructs a new instance of this class given its parent
- * (which must be a <code>CoolBar</code> and a style value
+ * (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>
@@ -68,7 +68,7 @@ public CoolItem (CoolBar parent, int style) {
/**
* Constructs a new instance of this class given its parent
- * (which must be a <code>CoolBar</code>, a style value
+ * (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>
@@ -253,6 +253,9 @@ void releaseWidget () {
*
* @param control the new control
*
+ * @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>
@@ -260,8 +263,9 @@ void releaseWidget () {
*/
public void setControl (Control control) {
checkWidget ();
- if (control != null && control.parent != parent) {
- error (SWT.ERROR_INVALID_PARENT);
+ 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;
@@ -315,6 +319,7 @@ public void setPreferredSize (int width, int height) {
public void setPreferredSize (Point size) {
checkWidget ();
+ if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
setPreferredSize (size.x, size.y);
}
@@ -350,7 +355,7 @@ public void setSize (int width, int height) {
}
public void setSize (Point size) {
- checkWidget ();
+ if (size == null) error(SWT.ERROR_NULL_ARGUMENT);
setSize (size.x, size.y);
}
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 2ec2522cd6..79852d5734 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
@@ -435,6 +435,7 @@ public String getText () {
if (length == 0) return "";
byte [] buffer1 = new byte [length + 1];
OS.GetWindowText (handle, buffer1, buffer1.length);
+ /* Use the character encoding for the default locale */
char [] buffer2 = Converter.mbcsToWcs (0, buffer1);
return new String (buffer2, 0, buffer2.length - 1);
}
@@ -530,6 +531,9 @@ void setBounds (int x, int y, int width, int height, int flags) {
*
* @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>
@@ -544,6 +548,7 @@ void setDefaultButton (Button button, boolean save) {
if (button == null) {
if (defaultButton == saveDefault) return;
} else {
+ if (button.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
if ((button.style & SWT.PUSH) == 0) return;
if (button == defaultButton) return;
}
@@ -579,6 +584,9 @@ public boolean setFocus () {
*
* @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>
@@ -588,6 +596,7 @@ public void setImage (Image image) {
checkWidget ();
int hIcon = 0;
if (image != null) {
+ if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
switch (image.type) {
case SWT.BITMAP:
int hOld = OS.SendMessage (handle, OS.WM_GETICON, OS.ICON_BIG, 0);
@@ -680,6 +689,9 @@ public void setMaximized (boolean maximized) {
*
* @param menu the new menu bar
*
+ * @exception IllegalArgumentException <ul>
+ * <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>
@@ -689,6 +701,7 @@ 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);
}
@@ -815,6 +828,7 @@ void setSystemMenu () {
public void setText (String string) {
checkWidget ();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs (0, string, true);
OS.SetWindowText (handle, buffer);
}
@@ -929,6 +943,9 @@ LRESULT WM_ACTIVATE (int wParam, int lParam) {
* 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 ();
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 1b7a473892..e1bbe4384f 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
@@ -87,10 +87,12 @@ 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 */
byte [] buffer = Converter.wcsToMbcs (0, filterPath, true);
OS.SendMessage (hwnd, OS.BFFM_SETSELECTION, 1, buffer);
}
if (title != null && title.length () != 0) {
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs (0, title, true);
OS.SetWindowText (hwnd, buffer);
}
@@ -98,6 +100,7 @@ int BrowseCallbackProc (int hwnd, int uMsg, int lParam, int lpData) {
case OS.BFFM_VALIDATEFAILED:
byte [] buffer1 = new byte [256];
OS.MoveMemory (buffer1, lParam, 256);
+ /* Use the character encoding for the default locale */
char [] buffer2 = Converter.mbcsToWcs (0, buffer1);
int length = 0;
while (length < buffer2.length && buffer2 [length] != 0) length++;
@@ -108,7 +111,7 @@ int BrowseCallbackProc (int hwnd, int uMsg, int lParam, int lpData) {
}
/**
- * Returns the path which the receiver will use to filter
+ * Returns the path which the dialog will use to filter
* the directories it shows.
*
* @return the filter path
@@ -118,9 +121,9 @@ public String getFilterPath () {
}
/**
- * Returns the receiver's message, which is a description of
+ * Returns the dialog's message, which is a description of
* the purpose for which it was opened. This message will be
- * visible on the receiver while it is open.
+ * visible on the dialog while it is open.
*
* @return the message
*/
@@ -129,14 +132,15 @@ public String getMessage () {
}
/**
- * Makes the receiver visible and brings it to the front
+ * Makes the dialog visible and brings it to the front
* of the display.
*
- * @return a string describing the absolute path of the selected directory
+ * @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 receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * <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 () {
@@ -153,6 +157,7 @@ public String open () {
/* Copy the message to OS memory */
int lpszTitle = 0;
if (message != null && message.length () != 0) {
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs (0, message, true);
lpszTitle = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, buffer.length);
OS.MoveMemory (lpszTitle, buffer, buffer.length);
@@ -173,6 +178,7 @@ public String open () {
if (lpItemIdList != 0) {
byte [] buffer = new byte [256];
if (OS.SHGetPathFromIDList (lpItemIdList, buffer)) {
+ /* Use the character encoding for the default locale */
char [] path = Converter.mbcsToWcs (0, buffer);
int length = 0;
while ((length < path.length) && (path [length] != 0)) length++;
@@ -209,7 +215,7 @@ public String open () {
}
/**
- * Sets the path which the receiver will use to filter
+ * Sets the path which the dialog will use to filter
* the directories it shows to the argument, which may be
* null.
*
@@ -220,9 +226,9 @@ public void setFilterPath (String string) {
}
/**
- * Sets the receiver's message, which is a description of
+ * Sets the dialog's message, which is a description of
* the purpose for which it was opened. This message will be
- * visible on the receiver while it is open.
+ * visible on the dialog while it is open.
*
* @param string the message
*/
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 d16ccefca2..91272e4d05 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
@@ -113,6 +113,9 @@ public class Display extends Device {
int lastKey, lastAscii, lastMouse;
byte [] keyboard = new byte [256];
boolean accelKeyHit, mnemonicKeyHit;
+
+ /* Image list cache */
+ ImageList[] imageList, toolImageList, toolHotImageList, toolDisabledImageList;
/* Key Mappings */
static final int [] [] KeyTable = {
@@ -548,6 +551,15 @@ public static synchronized Display getCurrent () {
return findDisplay (Thread.currentThread ());
}
+public Rectangle getClientArea () {
+ checkDevice ();
+ 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);
+}
+
/**
* Returns the control which the on-screen pointer is currently
* over top of, or null if it is not currently over one of the
@@ -562,7 +574,7 @@ public static synchronized Display getCurrent () {
public Control getCursorControl () {
checkDevice ();
POINT pt = new POINT ();
- OS.GetCursorPos (pt);
+ if (!OS.GetCursorPos (pt)) return null;
return findControl (OS.WindowFromPoint (pt));
}
@@ -709,15 +721,18 @@ public Control getFocusControl () {
public int getIconDepth () {
checkDevice ();
int [] phkResult = new int [1];
+ /* Use the character encoding for the default locale */
byte [] buffer1 = Converter.wcsToMbcs (0, "Control Panel\\Desktop\\WindowMetrics", true);
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};
byte [] lpData = new byte [lpcbData [0]];
+ /* Use the character encoding for the default locale */
byte [] buffer2 = Converter.wcsToMbcs (0, "Shell Icon BPP", true);
result = OS.RegQueryValueEx (phkResult [0], buffer2, 0, null, lpData, lpcbData);
if (result == 0) {
+ /* Use the character encoding for the default locale */
char [] buffer3 = Converter.mbcsToWcs (0, lpData);
int length = 0;
while (length < buffer3.length && buffer3 [length] != 0) length++;
@@ -729,6 +744,114 @@ public int getIconDepth () {
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;
@@ -899,6 +1022,7 @@ public Thread getThread () {
* @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) {
@@ -931,10 +1055,12 @@ protected void init () {
threadId = OS.GetCurrentThreadId ();
processId = OS.GetCurrentProcessId ();
+ /* Use the character encoding for the default locale */
+ windowClass = Converter.wcsToMbcs (0, WindowName + windowClassCount++ + "\0");
+
/* Register the SWT window class */
int hHeap = OS.GetProcessHeap ();
int hInstance = OS.GetModuleHandle (null);
- windowClass = Converter.wcsToMbcs (0, WindowName + windowClassCount++ + "\0");
WNDCLASSEX lpWndClass = new WNDCLASSEX ();
lpWndClass.cbSize = WNDCLASSEX.sizeof;
if (OS.GetClassInfoEx (hInstance, windowClass, lpWndClass)) {
@@ -1027,9 +1153,10 @@ void postEvent (Event event) {
public boolean readAndDispatch () {
checkDevice ();
if (OS.PeekMessage (msg, 0, 0, 0, OS.PM_REMOVE)) {
- if (filterMessage (msg)) return false;
- OS.TranslateMessage (msg);
- OS.DispatchMessage (msg);
+ if (!filterMessage (msg)) {
+ OS.TranslateMessage (msg);
+ OS.DispatchMessage (msg);
+ }
runDeferredEvents ();
return true;
}
@@ -1129,6 +1256,82 @@ void releaseDisplay () {
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++;
+ }
+}
+
boolean runAsyncMessages () {
return synchronizer.runAsyncMessages ();
}
@@ -1358,6 +1561,10 @@ public boolean sleep () {
*
* @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) {
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 bab97bd83c..7b09ecf473 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
@@ -33,34 +33,130 @@ public class FileDialog extends Dialog {
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
+ * for all SWT dialog classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </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);
}
+/**
+ * Returns the path of the first file that was
+ * selected in the dialog relative to the filter path,
+ * or null if none is available.
+ *
+ * @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;
}
-public String [] getFilterNames () {
- return filterNames;
-}
-
+/**
+ * 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 path which the dialog will use to filter
+ * the files it shows.
+ *
+ * @return the filter path
+ */
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 ();
@@ -70,6 +166,7 @@ public String open () {
/* Convert the title and copy it into lpstrTitle */
if (title == null) title = "";
+ /* Use the character encoding for the default locale */
byte [] buffer3 = Converter.wcsToMbcs (0, title, true);
int lpstrTitle = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, buffer3.length);
OS.MoveMemory (lpstrTitle, buffer3, buffer3.length);
@@ -86,14 +183,17 @@ public String open () {
if (filterExtensions.length == 0) {
strFilter = strFilter + FILTER + '\0' + FILTER + '\0';
}
+ /* Use the character encoding for the default locale */
byte [] buffer4 = Converter.wcsToMbcs (0, strFilter, true);
int lpstrFilter = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, buffer4.length);
OS.MoveMemory (lpstrFilter, buffer4, buffer4.length);
/* Convert the fileName and filterName to C strings */
if (fileName == null) fileName = "";
+ /* Use the character encoding for the default locale */
byte [] name = Converter.wcsToMbcs (0, fileName, false);
if (filterPath == null) filterPath = "";
+ /* Use the character encoding for the default locale */
byte [] path = Converter.wcsToMbcs (0, filterPath, false);
/*
@@ -177,6 +277,7 @@ public String open () {
OS.MoveMemory (buffer, lpstrFile, buffer.length);
byte [] prefix = new byte [struct.nFileOffset - 1];
System.arraycopy (buffer, 0, prefix, 0, prefix.length);
+ /* Use the character encoding for the default locale */
filterPath = new String (Converter.mbcsToWcs (0, prefix));
int start = struct.nFileOffset;
do {
@@ -185,6 +286,7 @@ public String open () {
byte [] buffer1 = new byte [end - start];
System.arraycopy (buffer, start, buffer1, 0, buffer1.length);
start = end;
+ /* Use the character encoding for the default locale */
String string = new String (Converter.mbcsToWcs (0, buffer1));
if (count == fileNames.length) {
String [] newFileNames = new String [fileNames.length + 4];
@@ -233,18 +335,47 @@ public String open () {
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 path which the dialog will use to filter
+ * the files it shows to the argument, which may be
+ * null.
+ *
+ * @param string the filter path
+ */
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 953ebac445..ecf14cfb8a 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
@@ -21,20 +21,89 @@ import org.eclipse.swt.widgets.*;
public class FontDialog extends Dialog {
FontData fontData;
+/**
+ * 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
+ * for all SWT dialog classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </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);
}
+/**
+ * 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;
}
+/**
+ * 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 () {
-
/* Get the owner HWND for the dialog */
int hwndOwner = 0;
if (parent != null) hwndOwner = parent.handle;
@@ -103,6 +172,13 @@ public FontData open () {
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;
}
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 7731638c91..d738e990ff 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
@@ -31,7 +31,7 @@ import org.eclipse.swt.graphics.*;
public class Group extends Composite {
static final int GroupProc;
- static final byte [] GroupClass = Converter.wcsToMbcs (0, "BUTTON\0", false);
+ static final byte [] GroupClass = Converter.wcsToMbcs (0, "BUTTON\0");
static {
WNDCLASSEX lpWndClass = new WNDCLASSEX ();
lpWndClass.cbSize = WNDCLASSEX.sizeof;
@@ -39,6 +39,34 @@ public class Group extends Composite {
GroupProc = 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
+ * 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 Group (Composite parent, int style) {
super (parent, checkStyle (style));
}
@@ -162,7 +190,7 @@ public String getText () {
if (length == 0) return "";
byte [] buffer1 = new byte [length + 1];
OS.GetWindowText (handle, buffer1, buffer1.length);
- char [] buffer2 = Converter.mbcsToWcs (0, buffer1);
+ char [] buffer2 = Converter.mbcsToWcs (getCodePage (), buffer1);
return new String (buffer2, 0, buffer2.length - 1);
}
@@ -194,7 +222,7 @@ boolean mnemonicMatch (char key) {
public void setText (String string) {
checkWidget ();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
OS.SetWindowText (handle, buffer);
}
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 d44e28e1c5..a2bf7115a8 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
@@ -10,7 +10,7 @@ import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
class ImageList {
- int handle, background;
+ int handle, refCount;
Image [] images;
static final int CREATE_FLAGS;
static {
@@ -45,7 +45,6 @@ class ImageList {
public ImageList () {
handle = OS.ImageList_Create (32, 32, CREATE_FLAGS, 16, 16);
images = new Image [4];
- background = 0x00FFFFFF;
}
public int add (Image image) {
@@ -70,10 +69,13 @@ public int add (Image image) {
OS.ImageList_SetIconSize (handle, cx [0], cy [0]);
}
int hBitmap = copyBitmap (hImage, cx [0], cy [0]);
+ int background = -1;
+ Color color = image.getBackground ();
+ if (color != null) background = color.handle;
if (index == count) {
OS.ImageList_AddMasked (handle, hBitmap, background);
} else {
- int hMask = createMask (hBitmap, cx [0], cy [0]);
+ int hMask = createMask (hBitmap, cx [0], cy [0], background);
OS.ImageList_Replace (handle, index, hBitmap, hMask);
OS.DeleteObject (hMask);
}
@@ -109,6 +111,10 @@ public int add (Image 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);
@@ -131,18 +137,20 @@ int copyIcon (int hImage, int width, int height) {
return hIcon;
}
-int createMask (int hBitmap, int width, int height) {
- int hDC = OS.GetDC (0);
- int hdc1 = OS.CreateCompatibleDC (hDC);
- OS.SelectObject (hdc1, hBitmap);
- int hdc2 = OS.CreateCompatibleDC (hDC);
+int createMask (int hBitmap, int width, int height, int background) {
int hMask = OS.CreateBitmap (width, height, 1, 1, null);
- OS.SelectObject (hdc2, hMask);
- OS.SetBkColor (hdc1, background);
- OS.BitBlt (hdc2, 0, 0, width, height, hdc1, 0, 0, OS.SRCCOPY);
- OS.ReleaseDC (0, hDC);
- OS.DeleteDC (hdc1);
- OS.DeleteDC (hdc2);
+ if (background != -1) {
+ int hDC = OS.GetDC (0);
+ int hdc1 = OS.CreateCompatibleDC (hDC);
+ 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.ReleaseDC (0, hDC);
+ OS.DeleteDC (hdc1);
+ OS.DeleteDC (hdc2);
+ }
return hMask;
}
@@ -156,14 +164,16 @@ public Image get (int index) {
return images [index];
}
-public int getBackground () {
- return background;
-}
-
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++) {
@@ -184,8 +194,11 @@ public void put (int index, Image image) {
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]);
+ int hMask = createMask (hBitmap, cx [0], cy [0], background);
OS.ImageList_Replace (handle, index, hBitmap, hMask);
OS.DeleteObject (hBitmap);
OS.DeleteObject (hMask);
@@ -208,51 +221,8 @@ public void remove (int index) {
images [index] = null;
}
-public void setBackground (int color) {
- if (background == color) return;
- background = color;
- /*
- * This code is intentionally commented. When the background
- * color of the control changes, it is necessary to recompute
- * the masks for all bitmaps in the image list. This can look
- * really bad when the application program assumes the original
- * color of the control and makes bitmaps accordingly. Typically
- * this happens when the colors are change using the control panel.
- * Therefore, this code remains commented even though it is correct.
- */
-// int length = OS.ImageList_GetImageCount (handle);
-// if (length == 0) return;
-// int [] cx = new int [1], cy = new int [1];
-// OS.ImageList_GetIconSize (handle, cx, cy);
-// int width = cx [0], height = cy [0];
-// OS.ImageList_Destroy (handle);
-// handle = OS.ImageList_Create (width, height, CREATE_FLAGS, length, 16);
-// for (int i=0; i<length; i++) {
-// Image image = images [i];
-// if (image == null || image.isDisposed ()) {
-// images [i] = null;
-// int hBitmap = OS.CreateBitmap (width, height, 1, 1, null);
-// OS.ImageList_AddMasked (handle, hBitmap, background);
-// OS.DeleteObject (hBitmap);
-// } else {
-// int hImage = image.handle;
-// switch (image.type) {
-// case SWT.BITMAP:
-// int hBitmap = copyBitmap (hImage, width, height);
-// OS.ImageList_AddMasked (handle, hBitmap, background);
-// OS.DeleteObject (hBitmap);
-// break;
-// case SWT.ICON:
-// int hIcon = copyIcon (hImage, width, height);
-// OS.ImageList_ReplaceIcon (handle, -1, hIcon);
-// OS.DestroyIcon (hIcon);
-// break;
-// default:
-// SWT.error (SWT.ERROR_NOT_IMPLEMENTED);
-// break;
-// }
-// }
-// }
+int removeRef() {
+ return --refCount;
}
public int size () {
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 2f18c51169..072bf29ff8 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
@@ -27,7 +27,6 @@ import org.eclipse.swt.graphics.*;
* within the SWT implementation.
* </p>
*/
-
public class Label extends Control {
Image image;
int font;
@@ -221,7 +220,7 @@ public String getText () {
if (length == 0) return "";
byte [] buffer1 = new byte [length + 1];
OS.GetWindowText (handle, buffer1, buffer1.length);
- char [] buffer2 = Converter.mbcsToWcs (0, buffer1);
+ char [] buffer2 = Converter.mbcsToWcs (getCodePage (), buffer1);
return new String (buffer2, 0, buffer2.length - 1);
}
@@ -307,6 +306,7 @@ public void setAlignment (int alignment) {
}
public boolean setFocus () {
+ checkWidget();
return false;
}
@@ -316,6 +316,9 @@ public boolean setFocus () {
*
* @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>
@@ -326,6 +329,7 @@ public void setImage (Image image) {
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:
@@ -406,7 +410,7 @@ public void setText (String string) {
if (hFont != 0) OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
}
string = Display.withCrLf (string);
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
OS.SetWindowText (handle, buffer);
}
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 13901598a9..93c8cfba2c 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
@@ -29,7 +29,7 @@ import org.eclipse.swt.events.*;
public class List extends Scrollable {
static final int ListProc;
- static final byte [] ListClass = Converter.wcsToMbcs (0, "LISTBOX\0", false);
+ static final byte [] ListClass = Converter.wcsToMbcs (0, "LISTBOX\0");
static {
WNDCLASSEX lpWndClass = new WNDCLASSEX ();
lpWndClass.cbSize = WNDCLASSEX.sizeof;
@@ -89,7 +89,7 @@ public List (Composite parent, int style) {
public void add (String string) {
checkWidget ();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (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);
@@ -125,7 +125,7 @@ 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 (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (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) {
@@ -395,7 +395,7 @@ public String getItem (int index) {
byte [] buffer1 = new byte [length + 1];
int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer1);
if (result != OS.LB_ERR) {
- char [] buffer2 = Converter.mbcsToWcs (0, buffer1);
+ char [] buffer2 = Converter.mbcsToWcs (getCodePage (), buffer1);
return new String (buffer2, 0, buffer2.length - 1);
}
}
@@ -634,7 +634,6 @@ public int getTopIndex () {
* </ul>
*/
public int indexOf (String string) {
- checkWidget ();
return indexOf (string, 0);
}
@@ -682,7 +681,7 @@ public int indexOf (String string, int start) {
int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
if (!((0 <= start) && (start < count))) return -1;
int index = start - 1, last;
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
do {
index = OS.SendMessage (handle, OS.LB_FINDSTRINGEXACT, last = index, buffer);
if ((index == OS.LB_ERR) || (index <= last)) return -1;
@@ -986,12 +985,14 @@ public void select (int [] indices) {
}
return;
}
+ int focusIndex = getFocusIndex ();
for (int i=0; i<indices.length; i++) {
int index = indices [i];
if (index != -1) {
OS.SendMessage (handle, OS.LB_SETSEL, 1, index);
}
}
+ if (focusIndex != -1) setFocusIndex (focusIndex);
}
/**
@@ -1017,6 +1018,7 @@ public void select (int index) {
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) {
@@ -1025,6 +1027,7 @@ public void select (int index) {
}
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);
}
OS.SendMessage (handle, OS.LB_SETTOPINDEX, topIndex, 0);
@@ -1036,6 +1039,11 @@ public void select (int index) {
OS.InvalidateRect (handle, selectedRect, true);
}
}
+ if ((style & SWT.MULTI) != 0) {
+ if (focusIndex != -1) {
+ OS.SendMessage (handle, OS.LB_SETCARETINDEX, index, 0);
+ }
+ }
}
/**
@@ -1168,7 +1176,8 @@ public void setItem (int index, String string) {
* @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) {
+ */
+public void setItems (String [] items) {
checkWidget ();
if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC);
@@ -1202,15 +1211,16 @@ public void setItem (int index, String string) {
mbcs = new byte [unicode.length * 2];
}
string.getChars (0, nUnicode, unicode, 0);
- unicode [nUnicode] = 0;
+ unicode [nUnicode++] = 0;
int nMbcs = nUnicode, i = 0;
- while (i <= nUnicode) {
+ while (i < nUnicode) {
if (unicode [i] > 0x7F) break;
mbcs [i] = (byte) unicode [i];
i++;
}
if (i < nUnicode) {
- nMbcs = OS.WideCharToMultiByte (OS.CP_ACP, 0, unicode, nUnicode, mbcs, nUnicode * 2, null, null);
+ int cp = getCodePage ();
+ nMbcs = OS.WideCharToMultiByte (cp, 0, unicode, nUnicode, mbcs, nUnicode * 2, null, null);
}
int result = OS.SendMessage (handle, OS.LB_ADDSTRING, 0, mbcs);
if (result == OS.LB_ERR || result == OS.LB_ERRSPACE) break;
@@ -1310,8 +1320,14 @@ void setScrollWidth (int newWidth, boolean grow) {
* @see List#select(int[])
*/
public void setSelection(int [] indices) {
+ checkWidget ();
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
if ((style & SWT.MULTI) != 0) deselectAll ();
select (indices);
+ if ((style & SWT.MULTI) != 0) {
+ int focusIndex = indices [0];
+ if (focusIndex != -1) setFocusIndex (focusIndex);
+ }
}
/**
@@ -1336,18 +1352,27 @@ 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) {
- int index = 0;
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);
- if ((style & SWT.SINGLE) != 0 && isSelected (index)) return;
+ if ((style & SWT.SINGLE) != 0 && isSelected (index)) {
+ return;
+ }
index++;
}
+ if (localFocus != -1) focusIndex = localFocus;
}
}
if ((style & SWT.SINGLE) != 0) deselectAll ();
+ if ((style & SWT.MULTI) != 0) {
+ if (focusIndex != -1) setFocusIndex (focusIndex);
+ }
}
/**
@@ -1366,8 +1391,12 @@ public void setSelection (String [] items) {
* @see List#select(int)
*/
public void setSelection (int index) {
+ checkWidget ();
if ((style & SWT.MULTI) != 0) deselectAll ();
select (index);
+ if ((style & SWT.MULTI) != 0) {
+ if (index != -1) setFocusIndex (index);
+ }
}
/**
@@ -1386,8 +1415,12 @@ public void setSelection (int index) {
* @see Table#select(int,int)
*/
public void setSelection (int start, int end) {
+ checkWidget ();
if ((style & SWT.MULTI) != 0) deselectAll ();
select (start, end);
+ if ((style & SWT.MULTI) != 0) {
+ if (start != -1) setFocusIndex (start);
+ }
}
/**
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 7fb3d9af84..0a8c280f2f 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
@@ -473,10 +473,6 @@ public boolean isEnabled () {
return getEnabled () && parentMenu.isEnabled ();
}
-boolean isValidWidget () {
- return handle != 0;
-}
-
/**
* Returns <code>true</code> if the receiver is visible, and
* <code>false</code> otherwise.
@@ -609,6 +605,9 @@ public void removeMenuListener (MenuListener listener) {
*
* @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>
@@ -617,7 +616,10 @@ public void removeMenuListener (MenuListener listener) {
public void setDefaultItem (MenuItem item) {
checkWidget ();
int command = -1;
- if (item != null) command = item.id;
+ if (item != null) {
+ if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ command = item.id;
+ }
OS.SetMenuDefaultItem (handle, command, OS.MF_BYCOMMAND);
redraw ();
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java
index c5a20e530d..926908adf1 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
@@ -29,12 +29,73 @@ 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
+ * 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 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
+ * 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 MenuItem (Menu parent, int style, int index) {
super (parent, checkStyle (style));
this.parent = parent;
@@ -447,17 +508,18 @@ public void setImage (Image image) {
}
/**
- * Sets the receiver's cascade menu to the argument.
+ * 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 pop up menu
+ * @param menu the new pull down menu
*
* @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_DROP_DOWN - the menu is not a drop down menu</li>
- * <li>ERROR_MENUITEM_NOT_CASCADE - the menu item is not a <code>CASCADE</code></li>
+ * <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>
@@ -473,6 +535,7 @@ public void setMenu (Menu menu) {
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);
}
@@ -563,6 +626,7 @@ public void setText (String string) {
super.setText (string);
int hMenu = parent.handle;
int hHeap = OS.GetProcessHeap ();
+ /* Use the character encoding for the default locale */
byte [] buffer = Converter.wcsToMbcs (0, string, false);
int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, buffer.length + 1);
OS.MoveMemory (pszText, buffer, buffer.length);
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 26db85b5d5..462c109b2e 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
@@ -30,10 +30,62 @@ import org.eclipse.swt.widgets.*;
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
+ * for all SWT dialog classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </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));
}
@@ -49,10 +101,29 @@ static int checkStyle (int style) {
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 */
@@ -108,6 +179,7 @@ public int open () {
int hwndFocus = OS.GetFocus ();
/* Open the message box */
+ /* Use the character encoding for the default locale */
byte [] buffer1 = Converter.wcsToMbcs (0, message, true);
byte [] buffer2 = Converter.wcsToMbcs (0, title, true);
int code = OS.MessageBox (hwndOwner, buffer1, buffer2, bits);
@@ -150,6 +222,13 @@ public int open () {
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 50384c0c8a..ad20481118 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
@@ -34,6 +34,34 @@ public class ProgressBar extends Control {
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
+ * 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 ProgressBar (Composite parent, int style) {
super (parent, checkStyle (style));
}
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 bee0bba362..4b51821aa9 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
@@ -29,6 +29,34 @@ public class Sash extends Control {
boolean dragging;
int startX, startY, lastX, lastY;
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</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 Sash (Composite parent, int style) {
super (parent, checkStyle (style));
}
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 f9a74377c9..60a6e59ca4 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
@@ -36,6 +36,34 @@ public class Scale extends Control {
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
+ * 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 Scale (Composite parent, int style) {
super (parent, checkStyle (style));
}
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 290f65253b..d9e63bcd09 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
@@ -143,8 +143,7 @@ ScrollBar (Scrollable parent, int style) {
* @see SelectionEvent
*/
public void addSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener (SWT.Selection,typedListener);
@@ -158,6 +157,16 @@ static int checkStyle (int style) {
void createWidget () {
increment = 1;
pageIncrement = 10;
+ /*
+ * Do not set the intial values of the maximum
+ * or the thumb. These values normally default
+ * to 100 and 10 but may have been set already
+ * by the widget that owns the scroll bar. For
+ * example, a scroll bar that is created for a
+ * list widget, setting these defaults would
+ * override the initial values provided by the
+ * list widget.
+ */
}
void destroyWidget () {
@@ -204,8 +213,7 @@ public Display getDisplay () {
* </ul>
*/
public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return (state & DISABLED) == 0;
}
@@ -222,8 +230,7 @@ public boolean getEnabled () {
* </ul>
*/
public int getIncrement () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return increment;
}
@@ -238,8 +245,7 @@ public int getIncrement () {
* </ul>
*/
public int getMaximum () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
SCROLLINFO info = new SCROLLINFO ();
info.cbSize = SCROLLINFO.sizeof;
info.fMask = OS.SIF_RANGE;
@@ -260,8 +266,7 @@ public int getMaximum () {
* </ul>
*/
public int getMinimum () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
SCROLLINFO info = new SCROLLINFO ();
info.cbSize = SCROLLINFO.sizeof;
info.fMask = OS.SIF_RANGE;
@@ -284,8 +289,7 @@ public int getMinimum () {
* </ul>
*/
public int getPageIncrement () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return pageIncrement;
}
@@ -300,8 +304,7 @@ public int getPageIncrement () {
* </ul>
*/
public Scrollable getParent () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return parent;
}
@@ -316,8 +319,7 @@ public Scrollable getParent () {
* </ul>
*/
public int getSelection () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
SCROLLINFO info = new SCROLLINFO ();
info.cbSize = SCROLLINFO.sizeof;
info.fMask = OS.SIF_POS;
@@ -340,8 +342,7 @@ public int getSelection () {
* </ul>
*/
public Point getSize () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
RECT rect = new RECT ();
OS.GetClientRect (parent.handle, rect);
int width, height;
@@ -369,8 +370,7 @@ public Point getSize () {
* @see ScrollBar
*/
public int getThumb () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
SCROLLINFO info = new SCROLLINFO ();
info.cbSize = SCROLLINFO.sizeof;
info.fMask = OS.SIF_PAGE;
@@ -399,8 +399,7 @@ public int getThumb () {
* </ul>
*/
public boolean getVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return (state & HIDDEN) == 0;
}
@@ -427,8 +426,7 @@ int hwndScrollBar () {
* </ul>
*/
public boolean isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getEnabled () && parent.isEnabled ();
}
@@ -450,8 +448,7 @@ public boolean isEnabled () {
* </ul>
*/
public boolean isVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
return getVisible () && parent.isVisible ();
}
@@ -484,8 +481,7 @@ void releaseWidget () {
* @see #addSelectionListener
*/
public void removeSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) return;
eventTable.unhook (SWT.Selection, listener);
@@ -518,8 +514,7 @@ int scrollBarType () {
* </ul>
*/
public void setEnabled (boolean enabled) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int hwnd = hwndScrollBar (), type = scrollBarType ();
int flags = OS.ESB_DISABLE_BOTH;
if (enabled) flags = OS.ESB_ENABLE_BOTH;
@@ -542,8 +537,7 @@ public void setEnabled (boolean enabled) {
* </ul>
*/
public void setIncrement (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 1) return;
increment = value;
}
@@ -561,8 +555,7 @@ public void setIncrement (int value) {
* </ul>
*/
public void setMaximum (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
SCROLLINFO info = new SCROLLINFO ();
info.cbSize = SCROLLINFO.sizeof;
@@ -612,8 +605,7 @@ public void setMaximum (int value) {
* </ul>
*/
public void setMinimum (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 0) return;
SCROLLINFO info = new SCROLLINFO ();
info.cbSize = SCROLLINFO.sizeof;
@@ -664,8 +656,7 @@ public void setMinimum (int value) {
* </ul>
*/
public void setPageIncrement (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (value < 1) return;
pageIncrement = value;
}
@@ -683,8 +674,7 @@ public void setPageIncrement (int value) {
* </ul>
*/
public void setSelection (int selection) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (selection < 0) return;
SCROLLINFO info = new SCROLLINFO ();
info.cbSize = SCROLLINFO.sizeof;
@@ -709,8 +699,7 @@ public void setSelection (int selection) {
* @see ScrollBar
*/
public void setThumb (int value) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
/* Position the thumb */
if (value < 1) return;
@@ -772,8 +761,7 @@ public void setThumb (int value) {
* </ul>
*/
public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
if (selection < 0) return;
if (minimum < 0) return;
if (maximum < 0) return;
@@ -837,8 +825,7 @@ public void setValues (int selection, int minimum, int maximum, int thumb, int i
* </ul>
*/
public void setVisible (boolean visible) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ checkWidget();
int hwnd = hwndScrollBar (), type = scrollBarType ();
if (OS.ShowScrollBar (hwnd, type, visible)) {
/*
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 8417e22a43..52a0393f64 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
@@ -105,12 +105,8 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
OS.AdjustWindowRectEx (rect, bits, hasMenu, OS.GetWindowLong (handle, OS.GWL_EXSTYLE));
/* Get the size of the scroll bars */
- if ((horizontalBar != null) && (horizontalBar.getVisible ())) {
- rect.bottom += OS.GetSystemMetrics (OS.SM_CYHSCROLL);
- }
- if ((verticalBar != null) && (verticalBar.getVisible ())) {
- rect.right += OS.GetSystemMetrics (OS.SM_CXVSCROLL);
- }
+ 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) {
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 a4267d0697..4bda811abe 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
@@ -90,6 +90,7 @@ public class Shell extends Decorations {
int [] brushes;
boolean showWithParent;
int toolTipHandle, lpstrTip;
+ Control lastActive;
/**
* Constructs a new instance of this class. This is equivalent
@@ -535,7 +536,7 @@ public void open () {
bringToTop ();
setVisible (true);
if (savedFocus == null) {
- setFocus ();
+ setTabGroupFocus ();
} else {
restoreFocus ();
}
@@ -574,6 +575,7 @@ void releaseWidget () {
if (IsDBLocale) {
if (hIMC != 0) OS.ImmDestroyContext (hIMC);
}
+ lastActive = null;
}
void remove (Menu menu) {
@@ -623,6 +625,43 @@ LRESULT selectPalette (int hPalette) {
return (result > 0) ? LRESULT.ONE : LRESULT.ZERO;
}
+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.IsIconic (handle)) {
super.setBounds (x, y, width, height, flags);
@@ -711,7 +750,7 @@ void setParent () {
void setToolTipText (int hwnd, String text) {
if (toolTipHandle == 0) {
toolTipHandle = OS.CreateWindowEx (
- 0,
+ OS.WS_EX_TOPMOST,
OS.TOOLTIPS_CLASS,
null,
OS.TTS_ALWAYSTIP,
@@ -721,6 +760,14 @@ void setToolTipText (int hwnd, String text) {
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;
@@ -787,6 +834,12 @@ void updateModal () {
setItemEnabled (OS.SC_CLOSE, isActive ());
}
+int widgetExtStyle () {
+ int bits = super.widgetExtStyle ();
+ if ((style & SWT.ON_TOP) != 0) bits |= OS.WS_EX_TOPMOST;
+ return bits;
+}
+
int widgetStyle () {
int bits = super.widgetStyle () & ~OS.WS_POPUP;
if (handle != 0) return bits | OS.WS_CHILD;
@@ -822,14 +875,31 @@ LRESULT WM_MOUSEACTIVATE (int wParam, int 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 ();
- int pos = OS.GetMessagePos ();
- pt.x = (short) (pos & 0xFFFF);
- pt.y = (short) (pos >> 16);
+ 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 = WidgetTable.get (hwnd);
- if (control == null) return null;
+ Control control = display.findControl (hwnd);
+ setActiveControl (control);
+ // widget could be disposed at this point
+ if (isDisposed ()) return null;
+ if (control == null || control.isDisposed ()) return null;
Button button = null;
boolean setDefault = false;
if (OS.GetActiveWindow () == handle && this == control.getShell ()) {
@@ -858,7 +928,7 @@ LRESULT WM_MOUSEACTIVATE (int wParam, int lParam) {
// return new LRESULT (OS.MA_NOACTIVATE);
// }
// }
- return result;
+ return null;
}
LRESULT WM_NCHITTEST (int wParam, int lParam) {
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 3bf730b3ac..2823a6f64d 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
@@ -56,11 +56,10 @@ import org.eclipse.swt.events.*;
*
* @see ScrollBar
*/
-
public class Slider extends Control {
int increment, pageIncrement;
static final int ScrollBarProc;
- static final byte [] ScrollBarClass = Converter.wcsToMbcs (0, "SCROLLBAR\0", false);
+ static final byte [] ScrollBarClass = Converter.wcsToMbcs (0, "SCROLLBAR\0");
static {
WNDCLASSEX lpWndClass = new WNDCLASSEX ();
lpWndClass.cbSize = WNDCLASSEX.sizeof;
@@ -68,6 +67,34 @@ public class Slider extends Control {
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
+ * 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 Slider (Composite parent, int style) {
super (parent, checkStyle (style));
}
@@ -141,11 +168,17 @@ 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 = pageIncrement + 1;
+ info.nPage = 11;
OS.SetScrollInfo (handle, OS.SB_CTL, info, true);
}
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 a768df1577..9ac3e9de37 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
@@ -34,7 +34,6 @@ import org.eclipse.swt.events.*;
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
* </p>
*/
-
public class TabFolder extends Composite {
TabItem [] items;
ImageList imageList;
@@ -69,7 +68,34 @@ public class TabFolder extends Composite {
}
}
-
+/**
+ * Constructs a new instance of this class given its parent
+ * and a style value describing its behavior and appearance.
+ * <p>
+ * The style value is either one of the style constants defined in
+ * class <code>SWT</code> which is applicable to instances of this
+ * class, or must be built by <em>bitwise OR</em>'ing together
+ * (that is, using the <code>int</code> "|" operator) two or more
+ * of those <code>SWT</code> style constants. The class description
+ * 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));
}
@@ -197,6 +223,27 @@ void createItem (TabItem item, int index) {
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);
+
+ /*
+ * 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 tab folder
+ * 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.
+ */
+ int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOSIZE;
+ OS.SetWindowPos (hwndToolTip, OS.HWND_TOPMOST, 0, 0, 0, 0, flags);
}
void createWidget () {
@@ -221,7 +268,8 @@ void destroyItem (TabItem item) {
if (count == 0) {
if (imageList != null) {
OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, 0);
- imageList.dispose ();
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
}
imageList = null;
items = new TabItem [4];
@@ -358,12 +406,13 @@ public int getSelectionIndex () {
int imageIndex (Image image) {
if (image == null) return OS.I_IMAGENONE;
if (imageList == null) {
- imageList = new ImageList ();
- imageList.setBackground (getBackgroundPixel ());
- imageList.add (image);
+ 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 0;
+ return index;
}
int index = imageList.indexOf (image);
if (index != -1) return index;
@@ -404,12 +453,13 @@ void releaseWidget () {
if (!item.isDisposed ()) item.releaseWidget ();
}
items = null;
- super.releaseWidget ();
if (imageList != null) {
OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, 0);
- imageList.dispose ();
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
}
imageList = null;
+ super.releaseWidget ();
}
/**
@@ -578,6 +628,7 @@ LRESULT WM_NOTIFY (int wParam, int lParam) {
if (item != null) string = item.toolTipText;
}
if (string != null && string.length () != 0) {
+ string = Display.withCrLf (string);
int length = string.length ();
char [] buffer = new char [length + 1];
string.getChars (0, length, buffer, 0);
@@ -611,17 +662,6 @@ LRESULT WM_SIZE (int wParam, int lParam) {
return result;
}
-LRESULT WM_SYSCOLORCHANGE (int wParam, int lParam) {
- LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
- if (result != null) return result;
- if (imageList != null && background == -1) {
- imageList.setBackground (defaultBackground ());
- int hImageList = imageList.getHandle ();
- OS.SendMessage (handle, OS.TCM_SETIMAGELIST, 0, hImageList);
- }
- return result;
-}
-
LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) {
LRESULT result = super.WM_WINDOWPOSCHANGING (wParam, lParam);
if (result != null) return result;
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 4751b0ff42..25b75e5433 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
@@ -29,13 +29,73 @@ public class TabItem extends Item {
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
+ * 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 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
+ * 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 TabItem (TabFolder parent, int style, int index) {
super (parent, style);
this.parent = parent;
@@ -120,6 +180,9 @@ void releaseWidget () {
* <p>
* @param control the new 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>
@@ -127,8 +190,9 @@ void releaseWidget () {
*/
public void setControl (Control control) {
checkWidget();
- if (control != null && control.parent != parent) {
- error (SWT.ERROR_INVALID_PARENT);
+ if (control != null) {
+ if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
+ if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);
}
Control oldControl = this.control, newControl = control;
this.control = control;
@@ -163,7 +227,7 @@ public void setText (String string) {
super.setText (string);
int hwnd = parent.handle;
int hHeap = OS.GetProcessHeap ();
- byte [] buffer = Converter.wcsToMbcs (0, string, false);
+ byte [] buffer = Converter.wcsToMbcs (parent.getCodePage (), string, false);
int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, buffer.length + 1);
OS.MoveMemory (pszText, buffer, buffer.length);
TCITEM tcItem = new TCITEM ();
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 26d1a8ac49..5f2359978a 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
@@ -47,6 +47,34 @@ public class Table extends Composite {
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
+ * 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 Table (Composite parent, int style) {
super (parent, checkStyle (style));
}
@@ -484,7 +512,8 @@ void destroyItem (TableItem item) {
if (count == 0) {
if (imageList != null) {
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
- imageList.dispose ();
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
}
imageList = null;
items = new TableItem [4];
@@ -860,12 +889,13 @@ public int getTopIndex () {
int imageIndex (Image image) {
if (image == null) return OS.I_IMAGENONE;
if (imageList == null) {
- imageList = new ImageList ();
- imageList.setBackground (getBackgroundPixel ());
- imageList.add (image);
+ 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 0;
+ return index;
}
int index = imageList.indexOf (image);
if (index != -1) return index;
@@ -992,15 +1022,16 @@ void releaseWidget () {
// }
items = null;
- super.releaseWidget ();
if (imageList != null) {
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
- imageList.dispose ();
+ 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 ();
}
/**
@@ -1195,7 +1226,8 @@ public void removeAll () {
if (imageList != null) {
OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);
- imageList.dispose ();
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
}
imageList = null;
items = new TableItem [4];
@@ -1236,7 +1268,7 @@ public void removeSelectionListener(SelectionListener listener) {
* @param indices the array of indices for the items to select
*
* @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * <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>
@@ -1439,11 +1471,6 @@ void setBackgroundPixel (int pixel) {
if (pixel == -1) pixel = defaultBackground ();
OS.SendMessage (handle, OS.LVM_SETBKCOLOR, 0, pixel);
OS.SendMessage (handle, OS.LVM_SETTEXTBKCOLOR, 0, pixel);
- if (imageList != null) {
- imageList.setBackground (pixel);
- int hImageList = imageList.getHandle ();
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList);
- }
if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
/*
@@ -1495,6 +1522,15 @@ void setCheckboxImageList () {
if (hOldList != 0) OS.ImageList_Destroy (hOldList);
}
+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;
+ OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);
+}
+
public void setFont (Font font) {
checkWidget ();
super.setFont (font);
@@ -1682,7 +1718,7 @@ void setScrollWidth () {
* @param indices the indices of the items to select
*
* @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * <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>
@@ -1693,8 +1729,12 @@ void setScrollWidth () {
* @see Table#select(int[])
*/
public void setSelection (int [] indices) {
+ checkWidget ();
+ if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
deselectAll ();
select (indices);
+ int focusIndex = indices [0];
+ if (focusIndex != -1) setFocusIndex (focusIndex);
}
/**
@@ -1705,7 +1745,8 @@ public void setSelection (int [] indices) {
* @param items the array of items
*
* @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * <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>
@@ -1721,11 +1762,20 @@ public void setSelection (TableItem [] items) {
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 (index);
+ if (index != -1) {
+ select (focusIndex = index);
+ }
}
+ if (focusIndex != -1) setFocusIndex (focusIndex);
+}
+
+boolean setTabGroupFocus () {
+ if (super.setTabGroupFocus()) return true;
+ return setTabItemFocus();
}
/**
@@ -1743,8 +1793,10 @@ public void setSelection (TableItem [] items) {
* @see Table#select(int)
*/
public void setSelection (int index) {
+ checkWidget ();
deselectAll ();
select (index);
+ if (index != -1) setFocusIndex (index);
}
/**
@@ -1763,8 +1815,16 @@ public void setSelection (int index) {
* @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);
}
/**
@@ -1851,6 +1911,7 @@ public void setTopIndex (int index) {
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) {
OS.SendMessage (handle, OS.LVM_ENSUREVISIBLE, index, 0);
@@ -2137,11 +2198,6 @@ LRESULT WM_SETFOCUS (int wParam, int lParam) {
LRESULT WM_SYSCOLORCHANGE (int wParam, int lParam) {
LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
if (result != null) return result;
- if (imageList != null && background == -1) {
- imageList.setBackground (defaultBackground ());
- int hImageList = imageList.getHandle ();
- OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, hImageList);
- }
if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
return result;
}
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 cebb9efac4..83a7cbaa37 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
@@ -23,12 +23,40 @@ import org.eclipse.swt.events.*;
* 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
+ * 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 TableColumn (Table parent, int style) {
super (parent, checkStyle (style));
resizable = true;
@@ -36,6 +64,37 @@ public TableColumn (Table parent, int style) {
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
+ * 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 TableColumn (Table parent, int style, int index) {
super (parent, checkStyle (style));
resizable = true;
@@ -206,7 +265,7 @@ public void pack () {
int index = parent.indexOf (this);
if (index == -1) return;
int hwnd = parent.handle;
- byte [] buffer = Converter.wcsToMbcs (0, text, true);
+ byte [] buffer = Converter.wcsToMbcs (parent.getCodePage (), text, true);
int headerWidth = OS.SendMessage (hwnd, OS.LVM_GETSTRINGWIDTH, 0, buffer);
OS.SendMessage (hwnd, OS.LVM_SETCOLUMNWIDTH, index, OS.LVSCW_AUTOSIZE);
int columnWidth = OS.SendMessage (hwnd, OS.LVM_GETCOLUMNWIDTH, index, 0);
@@ -343,7 +402,7 @@ public void setText (String string) {
/* Set the column title */
int hHeap = OS.GetProcessHeap ();
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (parent.getCodePage (), string, true);
int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, buffer.length);
OS.MoveMemory (pszText, buffer, buffer.length);
lvColumn.mask |= OS.LVCF_TEXT;
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 05f41b0f21..ac9507c7af 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
@@ -27,12 +27,73 @@ import org.eclipse.swt.graphics.*;
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
+ * 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 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
+ * 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 TableItem (Table parent, int style, int index) {
super (parent, style);
this.parent = parent;
@@ -267,7 +328,7 @@ public String getText (int index) {
OS.MoveMemory (buffer1, pszText, cchTextMax);
OS.HeapFree (hHeap, 0, pszText);
if (result == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
- char [] buffer2 = Converter.mbcsToWcs (0, buffer1);
+ char [] buffer2 = Converter.mbcsToWcs (parent.getCodePage (), buffer1);
int length = 0;
while (length < buffer2.length && buffer2 [length] != 0) length++;
return new String (buffer2, 0, length);
@@ -352,10 +413,11 @@ public void setGrayed (boolean grayed) {
/**
* Sets the image for multiple columns in the Table.
*
- * @param strings the array of new images
+ * @param images the array of new images
*
* @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
+ * <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>
@@ -374,10 +436,10 @@ public void setImage (Image [] images) {
* Sets the receiver's image at a column.
*
* @param index the column index
- * @param string the new image
+ * @param image the new image
*
* @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
+ * <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>
@@ -386,6 +448,9 @@ public void setImage (Image [] images) {
*/
public void setImage (int index, Image image) {
checkWidget();
+ if (image != null && image.isDisposed ()) {
+ error(SWT.ERROR_INVALID_ARGUMENT);
+ }
if (index == 0) {
setImage (image);
return;
@@ -403,6 +468,9 @@ public void setImage (int index, Image image) {
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);
@@ -487,7 +555,7 @@ public void setText (int index, String string) {
if (itemIndex == -1) return;
int hwnd = parent.handle;
int hHeap = OS.GetProcessHeap ();
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (parent.getCodePage (), string, true);
int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, buffer.length);
LVITEM lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_TEXT;
@@ -510,7 +578,7 @@ public void setText (String string) {
lvItem.mask = OS.LVIF_TEXT;
lvItem.iItem = index;
int hHeap = OS.GetProcessHeap ();
- byte [] buffer = Converter.wcsToMbcs (0, string, false);
+ byte [] buffer = Converter.wcsToMbcs (parent.getCodePage (), string, false);
int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, buffer.length + 1);
OS.MoveMemory (pszText, buffer, buffer.length);
lvItem.pszText = pszText;
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 bb0b6d99b4..2589c00105 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
@@ -24,7 +24,6 @@ import org.eclipse.swt.events.*;
* </p>
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
*/
-
public class Text extends Scrollable {
int tabs, oldStart, oldEnd;
boolean doubleClick, ignoreVerify, ignoreCharacter;
@@ -42,7 +41,7 @@ public class Text extends Scrollable {
}
static final int EditProc;
- static final byte [] EditClass = Converter.wcsToMbcs (0, "EDIT\0", false);
+ static final byte [] EditClass = Converter.wcsToMbcs (0, "EDIT\0");
static {
WNDCLASSEX lpWndClass = new WNDCLASSEX ();
lpWndClass.cbSize = WNDCLASSEX.sizeof;
@@ -50,6 +49,34 @@ public class Text extends Scrollable {
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
+ * 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 Text (Composite parent, int style) {
super (parent, checkStyle (style));
}
@@ -175,7 +202,7 @@ public void append (String string) {
if (string == null) return;
}
OS.SendMessage (handle, OS.EM_SETSEL, length, length);
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
}
@@ -217,7 +244,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
rect.right = wHint;
}
String text = getText ();
- byte [] buffer = Converter.wcsToMbcs (0, text, false);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), text, false);
OS.DrawText (hDC, buffer, buffer.length, rect, flags);
width = rect.right - rect.left;
if ((style & SWT.WRAP) != 0 && hHint == SWT.DEFAULT) {
@@ -230,6 +257,11 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
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;
/*
* Bug in Windows. For some reason, despite the fact
@@ -245,7 +277,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
}
/*
- * The preferred size of a single-line text widget
+ * 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.
@@ -353,7 +385,6 @@ public int getCaretLineNumber () {
*/
public Point getCaretLocation () {
checkWidget ();
-
/*
* Bug in Windows. For some reason, Windows is unable
* to return the pixel coordinates of the last character
@@ -430,9 +461,11 @@ char [] getClipboardData () {
if (hMem != 0) {
int ptr = OS.GlobalLock (hMem);
if (ptr != 0) {
- int cchWideChar = OS.MultiByteToWideChar (OS.CP_ACP, OS.MB_PRECOMPOSED, ptr, -1, null, 0);
+ /* Use the character encoding for the default locale */
+ int cp = OS.CP_ACP;
+ int cchWideChar = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, ptr, -1, null, 0);
lpWideCharStr = new char [--cchWideChar];
- OS.MultiByteToWideChar (OS.CP_ACP, OS.MB_PRECOMPOSED, ptr, -1, lpWideCharStr, cchWideChar);
+ OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, ptr, -1, lpWideCharStr, cchWideChar);
}
}
OS.CloseClipboard ();
@@ -480,7 +513,7 @@ public boolean getDoubleClickEnabled () {
public char getEchoChar () {
checkWidget ();
char echo = (char) OS.SendMessage (handle, OS.EM_GETPASSWORDCHAR, 0, 0);
- if (echo != 0 && (echo = mbcsToWcs (echo)) == 0) echo = '*';
+ if (echo != 0 && (echo = mbcsToWcs (echo, getCodePage ())) == 0) echo = '*';
return echo;
}
@@ -666,7 +699,7 @@ public String getText () {
if (length == 0) return "";
byte [] buffer1 = new byte [length + 1];
OS.GetWindowText (handle, buffer1, buffer1.length);
- char [] buffer2 = Converter.mbcsToWcs (0, buffer1);
+ char [] buffer2 = Converter.mbcsToWcs (getCodePage (), buffer1);
return new String (buffer2, 0, buffer2.length - 1);
}
@@ -689,7 +722,6 @@ public String getText () {
*/
public String getText (int start, int end) {
checkWidget ();
-
/*
* NOTE: The current implementation uses substring ()
* which can reference a potentially large character
@@ -760,7 +792,6 @@ public int getTopIndex () {
*/
public int getTopPixel () {
checkWidget ();
-
/*
* Note, EM_GETSCROLLPOS is implemented in Rich Edit 3.0
* and greater. The plain text widget and previous versions
@@ -805,13 +836,13 @@ public void insert (String string) {
string = verifyText (string, start [0], end [0]);
if (string == null) return;
}
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
}
int mbcsToWcsPos (int mbcsPos) {
if (mbcsPos == 0) return 0;
- int cp = OS.GetACP ();
+ int cp = getCodePage ();
int wcsTotal = 0, mbcsTotal = 0;
byte [] buffer = new byte [128];
String delimiter = getLineDelimiter();
@@ -822,7 +853,9 @@ int mbcsToWcsPos (int mbcsPos) {
int linePos = OS.SendMessage (handle, OS.EM_LINEINDEX, line, 0);
int mbcsSize = OS.SendMessage (handle, OS.EM_LINELENGTH, linePos, 0);
if (mbcsSize != 0) {
- if (mbcsSize > buffer.length) buffer = new byte [mbcsSize + delimiterSize];
+ if (mbcsSize + delimiterSize > buffer.length) {
+ buffer = new byte [mbcsSize + delimiterSize];
+ }
buffer [0] = (byte) (mbcsSize & 0xFF);
buffer [1] = (byte) (mbcsSize >> 8);
mbcsSize = OS.SendMessage (handle, OS.EM_GETLINE, line, buffer);
@@ -1037,7 +1070,7 @@ boolean sendKeyEvent (int type, int msg, int wParam, int lParam, Event event) {
if (newText == null) return false;
if (newText == oldText) return true;
newText = Display.withCrLf (newText);
- byte [] buffer = Converter.wcsToMbcs (0, newText, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), newText, true);
OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
return false;
@@ -1080,7 +1113,9 @@ public void setDoubleClickEnabled (boolean doubleClick) {
*/
public void setEchoChar (char echo) {
checkWidget ();
- if (echo != 0 && (echo = wcsToMbcs (echo)) == 0) echo = '*';
+ if (echo != 0) {
+ if ((echo = wcsToMbcs (echo, getCodePage ())) == 0) echo = '*';
+ }
OS.SendMessage (handle, OS.EM_SETPASSWORDCHAR, echo, 0);
/*
* Bug in Windows. When the password character is changed,
@@ -1289,7 +1324,7 @@ public void setText (String string) {
string = verifyText (string, 0, length);
if (string == null) return;
}
- byte [] buffer = Converter.wcsToMbcs (0, string, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
OS.SetWindowText (handle, buffer);
/*
* Bug in Windows. When the widget is multi line
@@ -1408,7 +1443,7 @@ String verifyText (String string, int start, int end, Event keyEvent) {
int wcsToMbcsPos (int wcsPos) {
if (wcsPos == 0) return 0;
- int cp = OS.GetACP ();
+ int cp = getCodePage ();
int wcsTotal = 0, mbcsTotal = 0;
byte [] buffer = new byte [128];
String delimiter = getLineDelimiter ();
@@ -1419,7 +1454,9 @@ int wcsToMbcsPos (int wcsPos) {
int linePos = OS.SendMessage (handle, OS.EM_LINEINDEX, line, 0);
int mbcsSize = OS.SendMessage (handle, OS.EM_LINELENGTH, linePos, 0);
if (mbcsSize != 0) {
- if (mbcsSize > buffer.length) buffer = new byte [mbcsSize + delimiterSize];
+ if (mbcsSize + delimiterSize > buffer.length) {
+ buffer = new byte [mbcsSize + delimiterSize];
+ }
buffer [0] = (byte) (mbcsSize & 0xFF);
buffer [1] = (byte) (mbcsSize >> 8);
mbcsSize = OS.SendMessage (handle, OS.EM_GETLINE, line, buffer);
@@ -1504,7 +1541,7 @@ LRESULT WM_CLEAR (int wParam, int lParam) {
if (newText.length () != 0) {
result = new LRESULT (callWindowProc (OS.WM_CLEAR, 0, 0));
newText = Display.withCrLf (newText);
- byte [] buffer = Converter.wcsToMbcs (0, newText, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), newText, true);
OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
}
return result;
@@ -1524,7 +1561,7 @@ LRESULT WM_CUT (int wParam, int lParam) {
if (newText.length () != 0) {
result = new LRESULT (callWindowProc (OS.WM_CUT, 0, 0));
newText = Display.withCrLf (newText);
- byte [] buffer = Converter.wcsToMbcs (0, newText, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), newText, true);
OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
}
return result;
@@ -1608,7 +1645,7 @@ LRESULT WM_PASTE (int wParam, int lParam) {
if (newText == null) return LRESULT.ZERO;
if (newText != oldText) {
newText = Display.withCrLf (newText);
- byte [] buffer = Converter.wcsToMbcs (0, newText, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), newText, true);
OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
return LRESULT.ZERO;
}
@@ -1674,7 +1711,7 @@ LRESULT WM_UNDO (int wParam, int lParam) {
if (newText == null) return LRESULT.ZERO;
if (newText != oldText) {
newText = Display.withCrLf (newText);
- byte [] buffer = Converter.wcsToMbcs (0, newText, true);
+ byte [] buffer = Converter.wcsToMbcs (getCodePage (), newText, true);
OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer);
return LRESULT.ZERO;
}
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 8b5644cb7b..f3fd4f1534 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
@@ -180,6 +180,32 @@ void 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.TB_GETTOOLTIPS, 0, 0);
+ /*
+ * This line is intentionally commented. The tool
+ * bar currently sets this value to 300 so it is
+ * not necessary to set TTM_SETMAXTIPWIDTH.
+ */
+// OS.SendMessage (hwndToolTip, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
+
+ /*
+ * 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.
+ */
+ int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOSIZE;
+ OS.SetWindowPos (hwndToolTip, OS.HWND_TOPMOST, 0, 0, 0, 0, flags);
+
+ /*
* 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.
@@ -240,6 +266,7 @@ void createItem (ToolItem item, int index) {
if ((style & SWT.VERTICAL) != 0) {
OS.SendMessage (handle, OS.TB_SETROWS, count+1, 0);
}
+ layoutItems ();
}
void createWidget () {
@@ -272,17 +299,18 @@ void destroyItem (ToolItem item) {
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);
- imageList.dispose ();
+ display.releaseToolImageList (imageList);
}
if (hotImageList != null) {
OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, 0);
- hotImageList.dispose ();
+ display.releaseToolHotImageList (hotImageList);
}
if (disabledImageList != null) {
OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, 0);
- disabledImageList.dispose ();
+ display.releaseToolDisabledImageList (disabledImageList);
}
imageList = hotImageList = disabledImageList = null;
items = new ToolItem [4];
@@ -290,6 +318,7 @@ void destroyItem (ToolItem item) {
if ((style & SWT.VERTICAL) != 0) {
OS.SendMessage (handle, OS.TB_SETROWS, count-1, 0);
}
+ layoutItems ();
}
ImageList getDisabledImageList () {
@@ -427,7 +456,8 @@ public int getRowCount () {
* @return the index of the item
*
* @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
+ * <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>
@@ -437,31 +467,47 @@ public int getRowCount () {
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) {
+ Control control = item.control;
+ if (control != null && !control.isDisposed ()) {
+ Rectangle rect = item.getBounds ();
+ control.setLocation (rect.x, rect.y);
+ }
+ }
+ }
+}
+
void releaseWidget () {
for (int i=0; i<items.length; i++) {
ToolItem item = items [i];
if (item != null && !item.isDisposed ()) {
+ item.releaseImages ();
item.releaseWidget ();
}
}
items = null;
- super.releaseWidget ();
+ Display display = getDisplay ();
if (imageList != null) {
OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, 0);
- imageList.dispose ();
+ display.releaseToolImageList (imageList);
}
if (hotImageList != null) {
OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, 0);
- hotImageList.dispose ();
+ display.releaseToolHotImageList (hotImageList);
}
if (disabledImageList != null) {
OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, 0);
- disabledImageList.dispose ();
+ display.releaseToolDisabledImageList (disabledImageList);
}
imageList = hotImageList = disabledImageList = null;
+ super.releaseWidget ();
}
void setDefaultFont () {
@@ -475,7 +521,6 @@ void setDisabledImageList (ImageList imageList) {
int hImageList = 0;
if ((disabledImageList = imageList) != null) {
hImageList = disabledImageList.getHandle ();
- disabledImageList.setBackground (getBackgroundPixel ());
}
OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, hImageList);
}
@@ -490,7 +535,6 @@ void setHotImageList (ImageList imageList) {
int hImageList = 0;
if ((hotImageList = imageList) != null) {
hImageList = hotImageList.getHandle ();
- hotImageList.setBackground (getBackgroundPixel ());
}
OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, hImageList);
}
@@ -500,7 +544,6 @@ void setImageList (ImageList imageList) {
int hImageList = 0;
if ((this.imageList = imageList) != null) {
hImageList = imageList.getHandle ();
- imageList.setBackground (getBackgroundPixel ());
}
OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, hImageList);
}
@@ -585,6 +628,7 @@ LRESULT WM_NOTIFY (int wParam, int lParam) {
if (item != null) string = item.toolTipText;
}
if (string != null && string.length () != 0) {
+ string = Display.withCrLf (string);
int length = string.length ();
char [] buffer = new char [length + 1];
string.getChars (0, length, buffer, 0);
@@ -607,37 +651,7 @@ LRESULT WM_SIZE (int wParam, int lParam) {
* WM_SIZE message.
*/
if (isDisposed ()) return result;
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null) {
- Control control = item.control;
- if (control != null && !control.isDisposed ()) {
- Rectangle rect = item.getBounds ();
- control.setLocation (rect.x, rect.y);
- }
- }
- }
- return result;
-}
-
-LRESULT WM_SYSCOLORCHANGE (int wParam, int lParam) {
- LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
- if (result != null) return result;
- if (imageList != null && background == -1) {
- imageList.setBackground (defaultBackground ());
- int hImageList = imageList.getHandle ();
- OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, hImageList);
- }
- if (hotImageList != null && background == -1) {
- hotImageList.setBackground (defaultBackground ());
- int hImageList = hotImageList.getHandle ();
- OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, hImageList);
- }
- if (disabledImageList != null && background == -1) {
- disabledImageList.setBackground (defaultBackground ());
- int hImageList = disabledImageList.getHandle ();
- OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, hImageList);
- }
+ layoutItems ();
return result;
}
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 148304d8c2..fce2592419 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
@@ -32,12 +32,73 @@ public class ToolItem extends Item {
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
+ * 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 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
+ * 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 ToolItem (ToolBar parent, int style, int index) {
super (parent, checkStyle (style));
this.parent = parent;
@@ -316,6 +377,32 @@ void releaseWidget () {
disabledImage2 = null;
}
+void releaseImages () {
+ TBBUTTONINFO info = new TBBUTTONINFO ();
+ info.cbSize = TBBUTTONINFO.sizeof;
+ info.dwMask = OS.TBIF_IMAGE | OS.TBIF_STYLE;
+ int hwnd = parent.handle;
+ int index = 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.
@@ -347,6 +434,9 @@ public void removeSelectionListener(SelectionListener listener) {
*
* @param control the new control
*
+ * @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>
@@ -354,8 +444,9 @@ public void removeSelectionListener(SelectionListener listener) {
*/
public void setControl (Control control) {
checkWidget();
- if (control != null && control.parent != parent) {
- error (SWT.ERROR_INVALID_PARENT);
+ 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;
@@ -397,8 +488,11 @@ public void setEnabled (boolean enabled) {
* The disbled image is displayed when the receiver is disabled.
* </p>
*
- * @param image the hot image to display on the receiver (may be null)
+ * @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>
@@ -407,6 +501,7 @@ public void setEnabled (boolean enabled) {
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 ();
}
@@ -420,6 +515,9 @@ public void setDisabledImage (Image image) {
*
* @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>
@@ -428,6 +526,7 @@ public void setDisabledImage (Image image) {
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 ();
}
@@ -435,6 +534,7 @@ public void setHotImage (Image image) {
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 ();
}
@@ -471,7 +571,7 @@ public void setText (String string) {
super.setText (string);
int hwnd = parent.handle;
int hHeap = OS.GetProcessHeap ();
- byte [] buffer = Converter.wcsToMbcs (0, string, false);
+ byte [] buffer = Converter.wcsToMbcs (parent.getCodePage (), string, false);
int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, buffer.length + 1);
OS.MoveMemory (pszText, buffer, buffer.length);
TBBUTTONINFO info = new TBBUTTONINFO ();
@@ -492,6 +592,8 @@ public void setText (String string) {
*/
int hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);
OS.SendMessage (hwnd, OS.WM_SETFONT, hFont, 0);
+
+ parent.layoutItems ();
}
/**
@@ -533,6 +635,7 @@ public void setWidth (int width) {
if (control != null && !control.isDisposed ()) {
control.setBounds (getBounds ());
}
+ parent.layoutItems ();
}
void updateImages () {
@@ -546,10 +649,13 @@ void updateImages () {
ImageList hotImageList = parent.getHotImageList ();
ImageList disabledImageList = parent.getDisabledImageList();
if (info.iImage == OS.I_IMAGENONE) {
- if (imageList == null) imageList = new ImageList ();
+ 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 = new ImageList ();
+ if (disabledImageList == null) disabledImageList = display.getToolDisabledImageList (size);
Image disabled = disabledImage;
if (disabledImage == null) {
disabled = image;
@@ -560,11 +666,11 @@ void updateImages () {
}
disabledImageList.add (disabled);
parent.setDisabledImageList (disabledImageList);
- if ((parent.style & SWT.FLAT) != 0) {
- if (hotImageList == null) hotImageList = new ImageList ();
+// 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) {
@@ -591,6 +697,8 @@ void updateImages () {
if (image == null) info.iImage = OS.I_IMAGENONE;
}
OS.SendMessage (hwnd, OS.TB_SETBUTTONINFO, id, info);
+
+ parent.layoutItems ();
}
int widgetStyle () {
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 9f38cd17df..7719da0c94 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
@@ -30,12 +30,69 @@ public class Tracker extends Widget {
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 ();
@@ -196,6 +253,8 @@ public boolean open () {
* event. If this happens, return false to indicate
* that the tracking has failed.
*/
+ event.x = newX;
+ event.y = newY;
sendEvent (SWT.Move, event);
if (isDisposed ()) return false;
drawRectangles ();
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 bc471fcf39..3ee33a81ca 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
@@ -240,6 +240,7 @@ void createItem (TreeItem item, int hParent, int hInsertAfter) {
if (hItem == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
item.handle = hItem;
items [id] = item;
+
/*
* This code is intentionally commented.
*/
@@ -250,7 +251,7 @@ void createItem (TreeItem item, int hParent, int hInsertAfter) {
// }
/*
- * Bug in Windows. When a child item ss added to a parent item
+ * 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.
@@ -337,7 +338,8 @@ void destroyItem (TreeItem item) {
if (count == 0) {
if (imageList != null) {
OS.SendMessage (handle, OS.TVM_SETIMAGELIST, 0, 0);
- imageList.dispose ();
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
}
imageList = null;
items = new TreeItem [4];
@@ -586,12 +588,13 @@ int imageIndex (Image image) {
if (imageList == null) {
int hOldList = OS.SendMessage (handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0);
if (hOldList != 0) OS.ImageList_Destroy (hOldList);
- imageList = new ImageList ();
- imageList.setBackground (getBackgroundPixel ());
- imageList.add (image);
+ 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 0;
+ return index;
}
int index = imageList.indexOf (image);
if (index != -1) return index;
@@ -626,10 +629,10 @@ void releaseWidget () {
}
}
items = null;
- super.releaseWidget ();
if (imageList != null) {
OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, 0);
- imageList.dispose ();
+ 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);
@@ -639,6 +642,7 @@ void releaseWidget () {
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 ();
}
@@ -665,7 +669,8 @@ public void removeAll () {
}
if (imageList != null) {
OS.SendMessage (handle, OS.TVM_SETIMAGELIST, 0, 0);
- imageList.dispose ();
+ Display display = getDisplay ();
+ display.releaseImageList (imageList);
}
imageList = null;
items = new TreeItem [4];
@@ -730,6 +735,9 @@ public void removeTreeListener(TreeListener listener) {
* @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>
@@ -738,7 +746,10 @@ public void removeTreeListener(TreeListener listener) {
public void setInsertMark (TreeItem item, boolean before) {
checkWidget ();
int hItem = 0;
- if (item != null) hItem = item.handle;
+ if (item != null) {
+ if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ hItem = item.handle;
+ }
OS.SendMessage (handle, OS.TVM_SETINSERTMARK, (before) ? 0 : 1, hItem);
}
@@ -793,12 +804,6 @@ void setBackgroundPixel (int pixel) {
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 (pixel == -1) pixel = getBackgroundPixel ();
- if (imageList != null) {
- imageList.setBackground (pixel);
- int hImageList = imageList.getHandle ();
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, hImageList);
- }
if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
}
@@ -847,6 +852,35 @@ void setForegroundPixel (int 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
@@ -855,7 +889,8 @@ void setForegroundPixel (int pixel) {
* @param items the array of items
*
* @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * <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>
@@ -881,7 +916,10 @@ public void setSelection (TreeItem [] items) {
} else {
int hNewItem = 0;
TreeItem item = items [0];
- if (item != null) hNewItem = item.handle;
+ if (item != null) {
+ if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ hNewItem = item.handle;
+ }
ignoreSelect = true;
OS.SendMessage (handle, OS.TVM_SELECTITEM, OS.TVGN_CARET, hNewItem);
ignoreSelect = false;
@@ -912,6 +950,7 @@ public void setSelection (TreeItem [] items) {
for (int i=0; i<this.items.length; i++) {
TreeItem item = this.items [i];
if (item != null) {
+ if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
int index = 0;
while (index < items.length) {
if (items [index] == item) break;
@@ -935,6 +974,11 @@ public void setSelection (TreeItem [] items) {
OS.SetWindowLong (handle, OS.GWL_WNDPROC, oldProc);
}
+boolean setTabGroupFocus () {
+ if (super.setTabGroupFocus()) return true;
+ return setTabItemFocus();
+}
+
/**
* Shows the item. If the item is already showing in the receiver,
* this method simply returns. Otherwise, the items are scrolled
@@ -943,7 +987,8 @@ public void setSelection (TreeItem [] items) {
* @param item the item to be shown
*
* @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
+ * <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>
@@ -955,6 +1000,7 @@ public void setSelection (TreeItem [] items) {
public void showItem (TreeItem item) {
checkWidget ();
if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
+ if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
OS.SendMessage (handle, OS.TVM_ENSUREVISIBLE, 0, item.handle);
}
@@ -1076,7 +1122,9 @@ LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
* 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 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);
@@ -1088,7 +1136,7 @@ LRESULT WM_LBUTTONDOWN (int wParam, int 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) {
@@ -1156,6 +1204,24 @@ LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
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) {
@@ -1330,11 +1396,6 @@ LRESULT WM_SETFOCUS (int wParam, int lParam) {
LRESULT WM_SYSCOLORCHANGE (int wParam, int lParam) {
LRESULT result = super.WM_SYSCOLORCHANGE (wParam, lParam);
if (result != null) return result;
- if (imageList != null && background == -1) {
- imageList.setBackground (defaultBackground ());
- int hImageList = imageList.getHandle ();
- OS.SendMessage (handle, OS.TVM_SETIMAGELIST, OS.TVSIL_NORMAL, hImageList);
- }
if ((style & SWT.CHECK) != 0) setCheckboxImageList ();
return result;
}
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 2933fe5fb0..521a2a2844 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
@@ -29,21 +29,82 @@ public class TreeItem extends Item {
public int handle;
Tree parent;
+/**
+ * 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, OS.TVI_LAST);
}
-public TreeItem (Tree parent, int style, int position) {
+/**
+ * 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 (position < 0) error (SWT.ERROR_INVALID_RANGE);
+ if (index < 0) error (SWT.ERROR_INVALID_RANGE);
this.parent = parent;
int hItem = OS.TVI_FIRST;
- if (position != 0) {
+ if (index != 0) {
int count = 1, hwnd = parent.handle;
hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0);
- while (hItem != 0 && count < position) {
+ while (hItem != 0 && count < index) {
hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
count++;
}
@@ -52,6 +113,36 @@ public TreeItem (Tree parent, int style, int position) {
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
+ * for all SWT widget classes should include a comment which
+ * describes the style constants which are applicable to the class.
+ * </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;
@@ -59,16 +150,47 @@ public TreeItem (TreeItem parentItem, int style) {
parent.createItem (this, hItem, OS.TVI_LAST);
}
-public TreeItem (TreeItem parentItem, int style, int position) {
+/**
+ * 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 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 (position < 0) error (SWT.ERROR_INVALID_RANGE);
+ if (index < 0) error (SWT.ERROR_INVALID_RANGE);
parent = parentItem.parent;
int hItem = OS.TVI_FIRST;
int hParent = parentItem.handle;
- if (position != 0) {
+ if (index != 0) {
int count = 1, hwnd = parent.handle;
hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_CHILD, hParent);
- while (hItem != 0 && count < position) {
+ while (hItem != 0 && count < index) {
hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXT, hItem);
count++;
}
@@ -431,7 +553,7 @@ public void setText (String string) {
super.setText (string);
int hwnd = parent.handle;
int hHeap = OS.GetProcessHeap ();
- byte [] buffer = Converter.wcsToMbcs (0, string, false);
+ byte [] buffer = Converter.wcsToMbcs (parent.getCodePage (), string, false);
int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, buffer.length + 1);
OS.MoveMemory (pszText, buffer, buffer.length);
TVITEM tvItem = new TVITEM ();
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 a6874b5463..8fbaf377e3 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
@@ -240,6 +240,7 @@ static int checkBits (int style, int int0, int int1, int int2, int int3, int int
*
* @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>
@@ -248,6 +249,7 @@ static int checkBits (int style, int int0, int int1, int int2, int int3, int int
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);
}
/**
@@ -307,7 +309,7 @@ protected void checkSubclass () {
*/
protected void checkWidget () {
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
+ if (isDisposed ()) error (SWT.ERROR_WIDGET_DISPOSED);
}
/**
@@ -359,7 +361,7 @@ public void dispose () {
* Note: It is valid to attempt to dispose a widget
* more than once. If this happens, fail silently.
*/
- if (!isValidWidget ()) return;
+ if (isDisposed ()) return;
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
releaseChild ();
releaseWidget ();
@@ -581,30 +583,28 @@ boolean isValidThread () {
return getDisplay ().isValidThread ();
}
-/**
- * Returns <code>true</code> if the widget is not disposed,
- * and <code>false</code> otherwise.
- * <p>
- * Note: This method is no longer required and will be deprecated.
- * </p>
- *
- * @return <code>true</code> when the widget is not disposed and <code>false</code> otherwise
+/*
+ * 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.
*
- * @see #isDisposed
+ * @param ch the MBCS character
+ * @return the WCS character
*/
-boolean isValidWidget () {
- return (state & DISPOSED) == 0;
+char mbcsToWcs (char ch) {
+ return mbcsToWcs (ch, 0);
}
/*
- * Returns a single character, converted from the multi-byte
- * character set (MBCS) used by the operating system widgets
- * to a wide character set (WCS) used by Java.
+ * 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 (char ch) {
+char mbcsToWcs (char ch, int codePage) {
int key = ch & 0xFFFF;
if (key <= 0x7F) return ch;
byte [] buffer;
@@ -616,7 +616,7 @@ char mbcsToWcs (char ch) {
buffer [0] = (byte) ((key >> 8) & 0xFF);
buffer [1] = (byte) (key & 0xFF);
}
- char [] result = Converter.mbcsToWcs (0, buffer);
+ char [] result = Converter.mbcsToWcs (codePage, buffer);
if (result.length == 0) return 0;
return result [0];
}
@@ -954,16 +954,31 @@ public String toString () {
}
/*
* Returns a single character, converted from the wide
- * character set (WCS) used by Java to the multi-byte
- * character set used by the operating system widgets.
+ * 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
*/
char wcsToMbcs (char ch) {
+ return wcsToMbcs (ch, 0);
+}
+
+/*
+ * Returns a single character, converted from the wide
+ * character set (WCS) used by Java to the specified
+ * multi-byte character set used by the operating system
+ * widgets.
+ *
+ * @param ch the WCS character
+ * @param codePage the code page used to convert the character
+ * @return the MBCS character
+ */
+char wcsToMbcs (char ch, int codePage) {
int key = ch & 0xFFFF;
if (key <= 0x7F) return ch;
- byte [] buffer = Converter.wcsToMbcs (0, new char [] {ch}, false);
+ 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));
diff --git a/bundles/org.eclipse.swt/buildnotes_swt.html b/bundles/org.eclipse.swt/buildnotes_swt.html
index 7069179099..99978fa359 100755
--- a/bundles/org.eclipse.swt/buildnotes_swt.html
+++ b/bundles/org.eclipse.swt/buildnotes_swt.html
@@ -11,6 +11,183 @@
<h1>
Eclipse Platform Build Notes<br>
SWT</h1>
+SWT Build 2.0 006 - Thursday Sept 27, 2001
+
+<h2>
+<a NAME="Problem reports fixed"></a>Problem reports fixed</h2>
+
+<blockquote>
+1GHWA19: SWT:WINNT - Problem with callbacks from CCombo
+<br>1GHFDPV: SWT:WIN2000 - Setting selection in Table does not update focus item
+<br>1GF644V: ITPUI:Linux - Unzoom is changing the active editor.
+</blockquote>
+
+
+<h1>
+Eclipse Platform Build Notes<br>
+SWT</h1>
+SWT Build 2.0 005 - Friday Sept 21, 2001
+
+<h2>
+<a NAME="Problem reports fixed"></a>Problem reports fixed</h2>
+
+<blockquote>
+1GK09Z0: SWT:Linux - setEnabled(false) has no effect on aToolbar
+<br>1GJZZS6: SWT:Linux - File Dialog returns a directory
+<br>1GF7SMC: ITPUI:Linux - Wrong bg for close button on editor tab
+</blockquote>
+
+
+<h1>
+Eclipse Platform Build Notes<br>
+SWT</h1>
+SWT Build 2.0 004 - Thursday Sept 13, 2001
+
+<h2>
+<a NAME="API Behaviour change"></a>API Behaviour change</h2>
+The behaviour of dispose for GCs has been modified such that attempting to dispose of
+a GC on a control <em>after</em> the control has been disposed will generate an
+SWTException. This fixes an OS resource leak and potential GPF situation.
+
+<h2>
+<a NAME="Problem reports fixed"></a>Problem reports fixed</h2>
+
+<blockquote>
+1GJUAKL: SWT:Neutrino - Control.internal_new_GC() needs !isValidWidget() check
+<br>1GJN52N: SWT:Linux - Text prints system error message for horizontal scrollbar
+<br>1GJBOAV: SWT:ALL - ScrolledComposite bugs
+<br>1GIXELI: SWT:ALL - Need Caret to allow bitmaps so bidi caret can be created
+<br>1GI5O1T: SWT:WINNT - Composite.setFocus takes focus when it should not
+<br>1GHOND7: SWT:WIN2000 - Selection problem with single-selection trees
+<br>1GHG990: SWT:ALL - Probable bug in Slider page increment setting
+<br>1GENJ60: SWT:ALL - ScrolledComposite should include example in its class comment
+<br>1GEA7K7: ITPUI:Linux - Default button not working
+</blockquote>
+
+
+<h1>
+Eclipse Platform Build Notes<br>
+SWT</h1>
+SWT Build 2.0 003 - Friday Sept 07, 2001
+
+<h2>
+<a NAME="New APIs"></a>New APIs</h2>
+
+<blockquote>
+FontData.setLocale(java.util.Locale) added
+<br>Caret.getImage() added
+<br>Caret.setImage(Image) added
+<br>GC.fillGradientRectangle(int, int, int, int, boolean) added
+</blockquote>
+
+<h2>
+<a NAME="Problem reports fixed"></a>Problem reports fixed</h2>
+
+<blockquote>
+1GJM7KM: SWT:Linux - Table and Tree return a different size for every second call to computeSize
+<br>1GJLKHE: SWT:SPARC - GP on "Installed JREs" preference page
+<br>1GJLK63: SWT:ALL - StyledText - bidi - keyboard switching
+<br>1GJLE36: SWT:WINNT - Alpha data redrawing improperly after occlusion
+<br>1GJA2L7: SWT:WIN - Different behavior for GC.drawString() args on Win vs. Photon
+<br>1GIZ0P6: SWT:WINNT - GC.drawImage() problem with transparent pixels
+<br>1GIXELI: SWT:ALL - Need Caret to allow bitmaps so bidi caret can be created
+<br>1GI7FQF: SWT:ALL - Can't set focus to Tasks View by Keyboard
+<br>1GI7EBL: SWT:Linux - api typo: ToolItem>>getDisabledmage()
+<br>1GI3P86: SWT:ALL - Semantic differences between emulated Table and Tree codebase on Motif and Photon
+<br>1GI1WEA: SWT:Neutrino - Text selection code not working correctly
+<br>1GHWED2: SWT:WINNT - GC.stringExtent() not correct for Windows Arial font
+<br>1GHWB7G: SWT:Linux - Linux font dialog doesn't open with given values.
+<br>1GHVRFY: SWT:Neutrino - Text#ClearSelection changes the CaretPosition in a SINGLE-line widget
+<br>1GHVLV6: SWT:Neutrino - Text#SetTopIndex and getTopIndex inconsistent
+<br>1GHOJ6T: SWT:Neutrino - Text#setSelection inconsistent between SINGLE and MULTI
+<br>1GHBLRA: SWT:Neutrino - Display.getBounds() returns incorrect info
+<br>1GH48UQ: SWT:Neutrino - Enter key does not insert new line with Text.MULTI widget
+<br>1GGT0TM: SWT:Neutrino - GC#drawArc inconsistent between NT and NTO
+<br>1GG1DBT: SWT:SPARC - Solaris loses input characters
+<br>1GG07HW: SWT:Linux - Tree.getItem() modifies its argument on Motif
+<br>1GG0069: SWT:Linux - Weird layout issues seen in Control Example
+<br>1GFZZLK: SWT:Linux - ToolItems not disabled when containing ToolBar is disabled
+<br>1GFZU3X: SWT:ALL - ImageLoader.load(String) not closing file input stream
+<br>1GFZPDP: SWT:Linux - Combo box with SWT.SIMPLE style does not respect Disabled flag (visually)
+<br>1GFW85H: SWT:ALL - Printer.getPrinterData() has stale comment
+<br>1GFW6MQ: SWT:ALL - DCR: Program class needs .equals() and .hashCode()
+<br>1GFW4YN: SWT:ALL - Help KevinH add printing to Eclipse
+<br>1GFQKDT: SWT:ALL - Image.setBackground() / getBackground() asymmetry
+<br>1GFONVW: SWT:Linux - Empty Combo should not fire Selection event
+<br>1GFL0HP: SWT:Linux - Remaining items in SWT comments to fix
+<br>1GET90D: SWT:Linux - SWTExceptions bring down Eclipse
+<br>1GESQBK: ITPJUI:WINNT - How to get access to pop-up menus of the Java editor ?
+<br>1GELX4A: ITPUI:ALL - Hover help is not visible if pane is dragged out of workbench
+<br>1GEHWAF: ITPUI:WIN2000 - Can't enter text in a Swing TextField or TextArea
+<br>1GE5ECJ: ITPUI:WIN2000 - Hover help for title bar buttons appears behind detached view
+<br>1GDX7R8: ITPUI:ALL - SWT setText() does NOT have any way to avoid making mnemonics.
+<br>1GD5UHA: SWT:WIN2000 - Double-clicking on toolbar item gives double-click event on toolbar
+<br>1GBXIEO: SWT:ALL - DCR: Include cursor pos in Tracker move event
+<br>1G4IMQ3: SWT:WINNT - Table images incorrect after rapid removal and creation
+</blockquote>
+
+<h1>
+Eclipse Platform Build Notes<br>
+SWT</h1>
+SWT Build 2.0 002 - Wednesday July 18, 2001
+
+<h2>
+<a NAME="Problem reports fixed"></a>Problem reports fixed</h2>
+
+<blockquote>
+1GGZ13T: SWT:Neutrino - invalid mouse state occuring in Photon
+<br>1GGRCCS: SWT:Neutrino - Label does not wrap in SWT0125
+<br>1GGAON2: SWT:ALL - Scaling image with alphas does not work correctly
+<br>1GFZQVQ: SWT:Linux - Vertical ProgressBar grows incorrectly
+<br>1GFQA18: SWT:Linux - Cheese with GC drawRoundedRectangle() on Motif
+<br>1GFPK6G: SWT:Linux - Motif fillPolygon() specifies improper hint
+</blockquote>
+
+<h1>
+Eclipse Platform Build Notes<br>
+SWT</h1>
+SWT Build 2.0 001 - Thursday July 12, 2001
+
+<h2>
+<a NAME="Problem reports fixed"></a>Problem reports fixed</h2>
+
+<blockquote>
+1GGET76: SWT:Neutrino - Canvas does not respond to setFocus()
+<br>1GGAS5P: SWT:Neutrino - Photon on QNX 6.1.x needs SWT native changes
+<br>1GG96RO: SWT:Neutrino - drawOval and fillOval not compatible
+<br>1GG8ZLV: SWT:WINNT - drawOval behaves differently on Windows vs. other platforms
+<br>1GFKYD9: SWT:Linux - -HANG- (Xserver) When perfoming display.wake() in a DND dragStart()
+<br>1GFKK37: SWT:Linux - FileViewer examples issues
+<br>1GFBHX6: SWT:ALL - CTabItem tool tip flashing
+<br>1GF9ZMT: SWT:SPARC - 8-bit Icons are losing colors
+<br>1GF9ZJG: SWT:SPARC - Icons are being masked incorrectly on Solaris
+<br>1GF9YHD: ITPUI:WIN2000 - SWTException: help view
+<br>1GF9Y32: SWT:SPARC - 24-bit MSB Icons are wrong color (greenish)
+<br>1GF0D05: SWT:Linux - GPFs when running JUnit TestRunner in J9 AWT
+<br>1GEUZZC: SWT:ALL - "Name" of plugin inconsistant with other plugins
+<br>1GETDP5: ITPUI:Linux - NPE while closing editor on linux
+<br>1GDVRT5: SWT:Neutrino - Alpha channel memory leak
+<br>1GDRXZR: ITPJUI:Linux - SWT: Context-Menus issue under Linux
+<br>1GD0OSK: SWT:ALL - API - package javadoc for SWT packages missing
+<br>1GCHS75: SWT:WINNT - workbench exits during expand collapse
+<br>1GCFUS0: SWT:ALL - CTabFolder "floating" X sticks sometimes
+<br>1GAR95O: SWT:ALL - Remove Smalltalk comments from SWT code
+<br>1GAQRND: SWT:ALL - DOC: Write good Javadoc comments for all of SWT
+<br>1G97I28: SWT:Linux - Tool bar buttons do not always work
+<br>1G84AZB: ITPDUI:ALL - Rename truncates name
+<br>1G845EZ: SWT:WIN2000 - Spec for Layout.computeSize() is truncated
+<br>1G7YXLB: SWT:WIN - StyledText - NLS Support
+<br>1G7NSHR: SWT:ALL - Widget.addListener(int, Listener) vs. adding typed listeners
+<br>1G4XDJO: SWT:Linux - Tree needs to display an insert marker
+<br>1G0Y8NZ: SWT:ALL - Combo box doesn't send key and mouse events
+<br>1FXAVLF: SWT:WINNT - Disabled toolbar icons don't adapt to appearance changes
+<br>1FV1S18: SWT:ALL - Need more WM_* messages passed to ActiveX Control
+<br>1FTWX55: SWT:ALL - Inconsistant commenting of which SWT objects need to be disposed.
+</blockquote>
+
+<h1>
+Eclipse Platform Build Notes<br>
+SWT</h1>
SWT Build 125 - Friday June 15, 2001
<h2>
diff --git a/bundles/org.eclipse.swt/plugin.xml b/bundles/org.eclipse.swt/plugin.xml
index 2f3b714c78..3fbba1b39f 100755
--- a/bundles/org.eclipse.swt/plugin.xml
+++ b/bundles/org.eclipse.swt/plugin.xml
@@ -2,13 +2,13 @@
<!-- File written by PDE 1.0 -->
<plugin
id="org.eclipse.swt"
- name="SWT"
- version="0.9"
+ name="%pluginName"
+ version="2.0"
provider-name="Object Technology International, Inc.">
<!-- Runtime -->
<runtime>
- <library name="swt.jar">
+ <library name="$ws$/swt.jar">
<export name="*"/>
</library>
</runtime>
diff --git a/bundles/org.eclipse.swt/readme_swt.html b/bundles/org.eclipse.swt/readme_swt.html
index da2ccbe4c5..d943156051 100755
--- a/bundles/org.eclipse.swt/readme_swt.html
+++ b/bundles/org.eclipse.swt/readme_swt.html
@@ -30,72 +30,86 @@ If the correct driver is installed for the wheel mouse, the extended messages ar
cursor operations that are supported.
<h4>
-99.1.2 Resource usage on Windows 98</h4>
+99.1.2 Available Colors on 8-bit Linux</h4>
-Although SWT is not inherently a heavy consumer of Windows GDI resources, applications that make
-extensive use of images may potentially cause the system to become resource limited on Windows 98
-and Windows Me. Efforts were made to minimize the impact of this in Eclipse, however, opening
-several perspectives can still cause it to happen. Further work in this area is ongoing.
-
-<h4>
-99.1.3 Available Colors on 8-bit Linux</h4>
-
-Typically, in Gnome Linux installs running with 8 bit plain visuals (i.e. 256 color mode), before the
+Typically, in Gnome Linux installs running with 8 bitplain visuals (i.e. 256 color mode), before the
Eclipse application is started, you already do not have any free colors. This may mean that Eclipse
is unable to allocate the default widget background color causing it to display a white background.
The functionality, however, is not affected.
<h4>
-99.1.4 Motif Accelerators</h4>
+99.1.3 Motif Accelerators</h4>
Keyboard accelerators on motif are sensitive to the state of all modifier keys such as the Caps Lock,
Num Lock and Scroll Lock keys. For example, Ctrl 'S' is not the same as Ctrl 'S' with the Num Lock key on.
If keyboard accelerators appear to not be working, please check the state of all other modifier keys.
<h4>
-99.1.5 Printing Support</h4>
-
-Although printing is not used by Eclipse, SWT provides printing support on Win32 platforms.
-See org.eclipse.swt.printing for more information.
+99.1.4 XInitThreads and Linux</h4>
+
+SWT makes use of the XInitThreads system function to allow graphics routines to
+be invoked from non-user-interface threads. However, the implementation of XInitThreads
+on Linux has several issues, which cause the following SWT problems:
+
+<dl>
+<dt><b>Printing Support</b></dt>
+<dd>The X printing extension implementation on Linux currently does not work for applications
+ which are XInitThreads enabled. This makes it impossible for us to provide printing
+ support on Linux. Until this is rectified, <code>Printer.getPrinterList()</code> will
+ always return an empty array on the Linux platform.</dd>
+<dt><b>Drag and Drop</b></dt>
+<dd>On Motif, SWT only supports dragging between windows running on the same system process.
+ In particular, dragging a file between Eclipse and another application will cause the
+ drop target application to hang. This is a result of a bug in the Motif libraries for
+ applications that are running XInitThreads.</dd>
+<dt><b>IME Support</b></dt>
+<dd>The Japanese IME support provided by Linux is currently incompatible with applications
+ which are XInitThreads enabled, and will cause them to hang.</dd>
+</dl>
<h4>
-99.1.6 Drag and Drop on Motif</h4>
-
-On Motif, SWT only supports dragging between windows running on the same system process. In particular,
-dragging a file between Eclipse and another application will cause the drop target application to hang. This is a result of
-a bug in the Motif libraries for applications that are running multi-threaded (i.e. XInitThreads), which we have not yet been
-able to workaround.
-
-<h4>
-99.1.7 Disposing in a Focus Event</h4>
+99.1.5 Disposing in a Focus Event</h4>
Applications should not dispose widgets in focus changing events. Doing so on Motif may cause Eclipse to terminate,
since Motif accesses the disposed widget within their internal focus change event handler.
Similar but less serious issues exist on Windows such that occasionally an SWT exception can be thrown.
<h4>
-99.1.7 List and ComboBox on Windows NT</h4>
+99.1.6 List and ComboBox on Windows NT</h4>
On Windows NT only, you should avoid creating items in a List or ComboBox with strings longer than 1000 characters.
Doing so may result in a General Protection Fault. This has been fixed in more recent versions of Windows.
+<h4>
+99.1.7 BiDi Support</h4>
+
+The StyledText widget now provides bidirectional language support for Hebrew and Arabic locales.
+Currently, this support is available only on win32, and has several known problems. It should be
+considered to be a preliminary implementation only.
<h4>
-99.1.8 SWT Example (Standalone) - FileViewer</h4>
+99.1.8 Cursor constructor arguments</h4>
-On Motif, drag and drop in File Viewer may cause the X-Server to hang. This is due to a thread synchronization issue in the example.
-This will be fixed in a future release of the FileViewer example.
+In the constructor <code>Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY)</code>,
+when both a source and mask argument are specified (i.e. mask is not null), the meaning of the two arguments is
+reversed. That is, the "mask" argument should be the source image and the "source" argument should be the
+mask image. This problem was discovered too late in the development cycle to be fixed for R1.0. The intent is to
+fix this in a future release, potentially by introducing a new more general constructor.
<h4>
-99.1.9 SWT Example (Standalone) - Hover Help</h4>
+99.1.9 Use of the "&" character in TabFolder</h4>
-On Motif, the tooltips may not appear correctly in all instances. This will be fixed in a future release.
+The "&" character is not currently supported in TabFolder labels. Doing so on win32, will cause the
+character which follows the "&" to be underlined as if it was a mnemonic, even though mnemonics are
+not available for TabFolders. On other platforms, the "&" character will be displayed correctly, but
+for portability reasons, it should be avoided.
<h4>
-99.1.10 SWT Example (Workbench View) - Paint</h4>
+99.1.10 ToolBar on Windows</h4>
-When the polygon tool is selected and the fill mode is set to Outline or Solid, the filled region may be rendered at the wrong location
-in the Canvas. This will be fixed in a future release of the Paint example.
+On Windows, you must create all tool bars with the FLAT style bit set. If you do not do this,
+the "hot" (rollover) images of <em>all</em> toolbars may display incorrectly.
+This will be fixed in a future release.
<p><a href="hglegal.htm"><img SRC="ngibmcpy.gif" BORDER=0 height=12 width=195></a>
</body>

Back to the top