static void cb (Fl_Widget*, void* obj)
{
Fl_Output* x = static_cast<Fl_Output*> (obj);
Fl_Native_File_Chooser* dialog = new Fl_Native_File_Chooser (
Fl_Native_File_Chooser::BROWSE_DIRECTORY);
if (!dialog->show()) {
x->value (dialog->filename());
}
}
int main()
{
Fl_Window* win = new Fl_Window (400, 30, "non-ASCII");
Fl_Output* field = new Fl_Output (1, 1, 300, 29);
Fl_Button* btn = new Fl_Button (field->x() + field->w(), field->y(),
win->w() - field->w() - 2, field->h(), "Browse");
btn->callback (cb, field);
win->end();
win->show();
return Fl::run();
}
/* fl_codepage = CP_ACP; */
fl_codepage = 1251;
static void cb (Fl_Widget*, void* obj)
{
Fl_Output* x = static_cast<Fl_Output*> (obj);
Fl_Native_File_Chooser* dialog = new Fl_Native_File_Chooser (
Fl_Native_File_Chooser::BROWSE_DIRECTORY);
if (!dialog->show()) {
/*
x->value (dialog->filename());
Instead of the simple solutions do little hack =)
*/
const char* acp_name = dialog->filename();
char* utf8_name = fl_locale_to_utf8(acp_name, strlen(acp_name), 1251);
x->value (utf8_name);
}
}
int main()
{
Fl_Window* win = new Fl_Window (400, 30, "non-ASCII");
Fl_Output* field = new Fl_Output (1, 1, 300, 29);
Fl_Button* btn = new Fl_Button (field->x() + field->w(), field->y(),
win->w() - field->w() - 2, field->h(), "Browse");
btn->callback (cb, field);
win->end();
win->show();
return Fl::run();
}
Nikita (et al),
We need to be careful here about conflating multiple features into the one bug; I think there are in fact several (related) things going on here:-
0: Recall that, internally, fltk now uses UTF8 encoded strings exclusively, not code-page encoded strings (though there may be bugs…)
1: Fl_Native_File_Chooser_WIN32 attempts to convert any strings it reads from the OS into UTF8 before returning them to fltk, BUT in the BROWSE_DIRECTORY case it is getting that wrong (a fltk bug) and returning the codepage string instead – which we then try and display as if it were UTF8 and it looks like garbage!
2: Nikita’s example code is “wrong” in so far as when the label is set on the button, a codepage encoded string is passed to a button that expects a UTF8 label. I don’t know if it is possible to get the VS editor to wrote UTF8 encoded strings, I don’t use it because I couldn’t get UTF8 out of it many years ago. I use Sublime2 at present and it handles UTF8 strings OK.
3: There appears to be another bug in that fltk is NOT converting the dialog title correctly. Again, this is supposed to be a UTF8 string, not a codepage string…
So, in summary; we need to make sure all strings are UTF8 encoded. Then we need to fix fltk so that is actually does UTF8 correctly on WIN32…
Hello, Eduard!
Unfortunately Fl_Native_File_Chooser has bugs. Often it works with characters in native Windows encoding instead of UTF8.
At the moment to display filename you first have to convert string to UTF8. I changed your code and it works correctly now. (VS2010, Windows7 64)
Selex ES Ltd
Or I can just modify the function of the event, and the main left untouched. I like this version more, because smaller patches.
I think the better
option would be to fix Fl_Native_File_Chooser_WIN32 however, rather than making non-portable workarounds in
you own code.