List Info

Thread: string handling in wx.NET




string handling in wx.NET
user name
2006-11-18 21:27:33
 Hi all,

I've been looking at string handling in wx.NET
and I wonder how this can work  

In my opinion wx.NET should not expose wxString
at all unless there is a very good reason to so.
As you know, wxWidgets basically has two character
modes, Unicode vs. "ANSI". There has been some
progress and partial success in using UTF8 in
ANSI mode, but this has not been thoroughly tested,
AFAIK. I'm not sure what the current policy is,
but I'd suggest that wx.NET should either separately
support a version of wxWidgets and wxC in Unicode
and a version in ANSI mode, or just only the Unicode
version, since C# also always uses Unicode in the
form of UTF16. This would be particurlarly easy under
Windows, where wxWidgets uses the same representation
anyways, but would require a conversion of the 4 byte
wchar_t to the 2 byte "char" in C#. 

Currently "wxString wxTextCtrl::GetValue()" is
made to

> wxString *wxTextCtrl_GetValue( wxTextCtrl *self )
> {
>     return new wxString( self->GetValue().c_str() );
> }

which does nothing but copy the whole string in memory
without any value (or sense). I'd say the function
should just be

> wxChar *wxTextCtrl_GetValue( wxTextCtrl *self )
> {
>     return self->GetValue().c_str();
> }

and in the "Value" accessor in TextCtrl a string
object should be constructor directly from that.
Since this will only work directly (without any
conversion) when wchar_t is 2-byte, we'd probably
need a conversion there otherwise, maybe like this

> void *wxTextCtrl_GetValue( wxTextCtrl *self )
> {
> #if (sizeof(wchar_t) == 2)
>     return (void*) self->GetValue().c_str();
> #else
>     return (void*) (wxCharBuffer)
>             wxMBConvUTF16.cWX3MB(
self->GetValue().c_str() );
> #endif
> }

which again should be put into a macro. And roughly
the same code for the reverse conversion in SetValue.

Regards,

  Robert



------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief surveys -
and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wxnet-developers mailing list
Wxnet-developerslists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxnet-
developers
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )