digitalmars.D.dwt - More very strange results regarding pasting into Text widgets
- Deewiant (61/61) May 21 2006 In my previous thread I posted a program into which I had trouble pastin...
In my previous thread I posted a program into which I had trouble pasting text. A workaround was present, though the problem was quite odd. Now, the same program gives very strange results when _certain_ strings are pasted into the text box. Here's a version of that program which better shows the results: -- import dwt.all, std.string; pragma (lib, "dwt" ); pragma (lib, "advapi32" ); pragma (lib, "comctl32" ); pragma (lib, "ole32" ); pragma (lib, "uuid" ); pragma (lib, "imm32_dwt" ); pragma (lib, "msimg32_dwt" ); pragma (lib, "usp10_dwt" ); pragma (lib, "oleaut32_dwt"); pragma (lib, "oleacc_dwt" ); const void delegate(Event) onTextInput; static this() { onTextInput = delegate(Event e) { char[] txt = e.text.toString(); MessageBox.showMsg(format("Got string of length %d: XXX %s XXX", txt.length, txt)); }; } void main() { Display display = Display.getDefault(); Shell shell = new Shell(display); Text input = new Text(shell, DWT.WRAP); input.handleEvent(null, DWT.Verify, onTextInput); input.setSize(200, 200); shell.pack(); shell.open(); while (!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep(); display.dispose(); } -- Generally, whenever something is pasted into the text box in the above program, the Verify event fires off and the message box pops up informing you of what you pasted. However, this does not always occur. Try the following string, a modified pair of lines from the program's source code: -- ("Got string of length %d: XXX %s XXX", txt.length, txt }; -- Note that everything, including the beginning whitespace (two tab characters), does matter. I tried to minimise the string or make it something smarter, but didn't succeed. Changing the string at all causes everything to work normally. Anyway, what happens when the above is pasted to the text box is simply that the MessageBox does not pop up - the event does not occur at all. However, if you first type/paste something else into the box, and then paste the above, the event does occur - but only for the first time you paste it. Pasting again causes the event not to fire again. I got it to work with a few other lines from another program's source code too, and there's only one thing I'm relatively sure about: the string has to have at least one line break in it - single line strings never trigger the bug. Have I or my computer been licking too many frogs lately, or what the C++ is going on? This is probably the oddest bug/glitch I can recall ever having run into.
May 21 2006