wxWidgets UNICODE 版の test †
UNICODE なので、基本的に source 中に任意の UNICODE 文字を直接埋め込むことが可能である(はず)。 そこで、日本語を表示する program を同一 source で Windows 2000 (wxMSW)と Linux(wxGTK=1) とで生成できるかどうか試してみた。 結論から言えば、ほぼ動いた。「ほぼ」というのは、細かく見ると 問題が無いわけではないということで、その点については後で触れる。 Test環境 †いずれも wxWidgets は 2.8.10 である。
である。Linux 1 の方は、 ../configure --enable-unicode --with-gtk=1 --enable-std_string --enable-std_iostream --disable-shared で configure; make; make install した。gtk は 2 が入っている(みたいだ)が、 なぜか configure で package 云々の error が出るので、1 にした。 また、最初 --disable-shared をつけなかったら、日本語 program の時に font library の so が無いとか何とか文句を言うので、--disable-shared にした。 Linux 2 の方は ../configure --enable-unicode --enable-std_string --enable_iostream --disable-shared で install した。 Test program †Test program は以下に示すように
重要な点は、target system が どんな文字 code を使っていようと(Shift-JIS だろうが、EUC-JP だろうが)、 この一つの source で同一の文字表示が行われる(はず)ということである。 Build 方法は Linux でも Windows (MSYS/MinGW) でも全く同じで、 g++ jworld.cpp `wx-config --cxxflags` `wx-conig --libs` -o jworld である。 // jworld.cpp #include <wx/wx.h> #include <string> class MyApp: public wxApp { virtual bool OnInit(); }; class MyFrame: public wxFrame { public: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); DECLARE_EVENT_TABLE() }; class MyText { public: static const wchar_t m_frame_title[]; static const wchar_t m_menu_file[]; static const wchar_t m_menu_about[]; static const wchar_t m_menu_exit[]; static const wchar_t m_status[]; static const wchar_t m_about_title[]; static const wchar_t m_about[]; }; enum { ID_Quit = 1, ID_About, }; BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(ID_Quit, MyFrame::OnQuit) EVT_MENU(ID_About, MyFrame::OnAbout) END_EVENT_TABLE() IMPLEMENT_APP(MyApp) const wchar_t MyText::m_frame_title[] = {0x4e16,0x754c,0x3088,0x4eca,0x65e5,0x306f,0x0000}; const wchar_t MyText::m_menu_file[] = {0x30d5,0x30a1,0x30a4,0x30eb,0x0000}; const wchar_t MyText::m_menu_about[] = {0x6982,0x8981,0x0000}; const wchar_t MyText::m_menu_exit[] = {0x7d42,0x4e86,0x0000}; const wchar_t MyText::m_status[] = {0x0077,0x0078,0x0057,0x0069,0x0064,0x0067,0x0065,0x0074,0x0073, 0x0020, 0x306b,0x3088,0x3046,0x3053,0x305d,0x0021,0x0000}; const wchar_t MyText::m_about_title[] = {0x0077,0x0078,0x0057,0x0069,0x0064,0x0067,0x0065,0x0074,0x0073, 0x0020, 0x306b,0x3064,0x3044,0x3066,0x0000}; const wchar_t MyText::m_about[] = {0x3053,0x308c,0x306f,0x0020, 0x0077,0x0078,0x0057,0x0069,0x0064,0x0067,0x0065,0x0074,0x0073, 0x0020, 0x306b,0x3088,0x308b,0x300c, 0x4e16,0x754c,0x3088,0x4eca,0x65e5,0x306f, 0x300d,0x306e,0x4f8b,0x3067,0x3059,0x3002,0x0000}; bool MyApp::OnInit() { MyFrame* frame = new MyFrame( MyText::m_frame_title, wxPoint(50,50), wxSize(450,340)); frame->Show(TRUE); SetTopWindow(frame); return true; } MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame((wxFrame*)0, -1, title, pos, size) { wxMenu* menuFile = new wxMenu; menuFile->Append(ID_About, MyText::m_menu_about); menuFile->AppendSeparator(); menuFile->Append(ID_Quit, MyText::m_menu_exit); wxMenuBar* menuBar = new wxMenuBar; menuBar->Append(menuFile, MyText::m_menu_file); SetMenuBar(menuBar); CreateStatusBar(); SetStatusText(MyText::m_status); } void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(true); } void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxMessageBox(MyText::m_about, MyText::m_about_title, wxOK | wxICON_INFORMATION, this); } 結果の画像 †結果の画像を示す。いずれも Windows XP(SP3) で表示したもので、 MSYS/MinGW 版は Windows 2000(SP4) で build して XP に copy して 実行したもの、Linux 1 (GTK1) と Linux 2 (GTK2) は、Xserver として Xming を使って表示させたものである。 画像は、上から順に、起動直後、メニュー選択中、概要のダイアログである。 同一 source 同一 build command で、ここまでできるのは、確かに素晴らしい。 が、、よく見ると、Linux 版では GTK1 でも GTK2 でも frame window の title が出ていない。同様に dialog window (最下段)の title も 日本語の部分が出ていない(多分日本語が表示できていないのであろう)。 また、MSYS/MinGW 版では、メニュー選択直後に status window が消えて、復活しない。 |