Thanks for your quick response!
Strings are not binary-safe.
Some characters are not allowed.
Can you explain what you mean - when they are being set from Ruby to the control (eg TextCtrl#value=) or retrieving user input from the GUI?
Ideally a short test case or example bit of code which shows what’s going on.
This script shows the different behavior for starting Wx::TextCtrl
values.
…
require “wx”
class TheApp < Wx::App
def on_init
frame = Wx::Frame.new(nil, -1, “TheApp”)
sizer = Wx::FlexGridSizer.new(2,4)
string = "fooboo"
string = “foo\xC2\xA5boo”
string = “foo\xE2\x90\x80boo”
string = “foo\x1Fboo”
string = “foo\x0boo”
string = “foo\x95boo”
puts "ruby string:\t#{string.length} #{string.inspect}
#{string.unpack(‘H2’ * string.length).join(" “).upcase}”
@text = Wx::TextCtrl.new(frame, -1, string, :style =>
Wx::TE_MULTILINE)
sizer.add(@text, 0, Wx::GROW|Wx::ALL, 4)
value = @text.get_value
puts “starting value:\t#{value.length} #{value.inspect}
#{value.unpack(‘H2’ * value.length).join(” “).upcase}”
saveButton = Wx::Button.new(frame, -1, 'Save')
saveButton.evt_button(saveButton.get_id) { | e | on_do_save }
sizer.add(saveButton, 0, Wx::ALL, 4)
frame.set_sizer(sizer)
sizer.set_size_hints(frame)
sizer.fit(frame)
frame.show
end
def on_do_save
value = @text.get_value
puts “saved value:\t#{value.length} #{value.inspect}
#{value.unpack(‘H2’ * value.length).join(” “).upcase}”
end
end
TheApp.new.main_loop
…
C:>ruby script.rb
(different strings uncommented)
ruby string: 6 “fooboo” 66 6F 6F 62 6F 6F
starting value: 6 “fooboo” 66 6F 6F 62 6F 6F
saved value: 6 “fooboo” 66 6F 6F 62 6F 6F
ruby string: 8 “foo\302\245boo” 66 6F 6F C2 A5 62 6F 6F
starting value: 8 “foo\302\245boo” 66 6F 6F C2 A5 62 6F 6F
saved value: 8 “foo\302\245boo” 66 6F 6F C2 A5 62 6F 6F
ruby string: 9 “foo\342\220\200boo” 66 6F 6F E2 90 80 62 6F 6F
starting value: 9 “foo\342\220\200boo” 66 6F 6F E2 90 80 62 6F 6F
saved value: 9 “foo\342\220\200boo” 66 6F 6F E2 90 80 62 6F 6F
ruby string: 7 “foo\037boo” 66 6F 6F 1F 62 6F 6F
starting value: 7 “foo\037boo” 66 6F 6F 1F 62 6F 6F
saved value: 7 “foo\037boo” 66 6F 6F 1F 62 6F 6F
ruby string: 7 “foo\000boo” 66 6F 6F 00 62 6F 6F
starting value: 3 “foo” 66 6F 6F
saved value: 3 “foo” 66 6F 6F
ruby string: 7 “foo\225boo” 66 6F 6F 95 62 6F 6F
starting value: 0 “”
saved value: 0 “”
…
Some control characters work fine (e.g. \x1F).
Other control characters (e.g., \x00) cause the value to be truncated
before the character.
Still other control characters (e.g., \x95) cause the value to be
altogether empty.
Is this behavior on purpose? Is there a list of which control characters
do what?
If you want a code-oriented text editor, you probably want to use Wx::StyledTextCtrl as the base for your text control. It’s the same editing/highlighting component used by Scite.
I guess my noob side shown through. Thanks for pointing me to that
control.
I guess I need to read up before I open my mouth. Let the character
testing begin.
Wx::Clipboard
what DataObject, what platform, what version
Wx::DF_TEXT
Windows API: CF_OEMTEXT, CF_TEXT, CF_UNICODETEXT
Windows XP
I was just testing someone elses script. This object is complex! I
suspect it’s a combination of how Windows implements clipboard data
formats and the Wx UTF-8 requirement.
From tests of Windows native clipboard API calls, it seems they get
themselves confused about text display versus binary value.
It seems this is a hot issue for general wxWidgets as well.
Thanks.
-AH