From: Mattia Barbon Date: Mon, 3 Feb 2003 22:39:02 +0000 (+0000) Subject: Make wxr resources work in Unicode mode. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/bf60426831535738b1b784629f08e9dd00bf9ecc?hp=94311eef78b66304c9a2f78bcbdd396c798f19a6 Make wxr resources work in Unicode mode. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19093 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/resource.h b/include/wx/resource.h index 37c4e86456..981760505f 100644 --- a/include/wx/resource.h +++ b/include/wx/resource.h @@ -183,8 +183,10 @@ WXDLLEXPORT extern wxIcon wxResourceCreateIcon(const wxString& resource, wxResou WXDLLEXPORT extern wxMenuBar* wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *table = (wxResourceTable *) NULL, wxMenuBar *menuBar = (wxMenuBar *) NULL); WXDLLEXPORT extern wxMenu* wxResourceCreateMenu(const wxString& resource, wxResourceTable *table = (wxResourceTable *) NULL); WXDLLEXPORT extern bool wxResourceParseData(const wxString& resource, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern bool wxResourceParseData(const char* resource, wxResourceTable *table = (wxResourceTable *) NULL); WXDLLEXPORT extern bool wxResourceParseFile(const wxString& filename, wxResourceTable *table = (wxResourceTable *) NULL); WXDLLEXPORT extern bool wxResourceParseString(char* s, wxResourceTable *table = (wxResourceTable *) NULL); +WXDLLEXPORT extern bool wxResourceParseString(const wxString& s, wxResourceTable *table = (wxResourceTable *) NULL); WXDLLEXPORT extern void wxResourceClear(wxResourceTable *table = (wxResourceTable *) NULL); // Register XBM/XPM data WXDLLEXPORT extern bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, int height, wxResourceTable *table = (wxResourceTable *) NULL); diff --git a/include/wx/wxexpr.h b/include/wx/wxexpr.h index 7df1bf9b54..304aeb09c9 100644 --- a/include/wx/wxexpr.h +++ b/include/wx/wxexpr.h @@ -82,7 +82,7 @@ class WXDLLEXPORT wxExpr wxExpr(wxExprType the_type, wxChar *word_or_string, bool allocate); wxExpr(const wxString& functor); // Assume this is a new clause - pass functor - wxExpr(wxExprType the_type, const wxString& word_or_string = ""); + wxExpr(wxExprType the_type, const wxString& word_or_string = wxT("")); wxExpr(long the_integer); wxExpr(double the_real); wxExpr(wxList *the_list); @@ -246,7 +246,10 @@ public: // Compatibility inline bool ReadProlog(wxChar *filename) { return Read(wxString(filename)); } - inline bool ReadPrologFromString(char *buffer) { return ReadFromString(wxString(buffer)); } + inline bool ReadPrologFromString(char *buffer) + { + return ReadFromString(wxString(buffer, wxConvLibc)); + } inline void WriteProlog(FILE* stream) { Write(stream); } private: diff --git a/samples/resource/resource.cpp b/samples/resource/resource.cpp index f076602f16..23fe977100 100644 --- a/samples/resource/resource.cpp +++ b/samples/resource/resource.cpp @@ -29,7 +29,7 @@ #endif #if wxUSE_UNICODE - #error "This sample can't be compiled in Unicode mode." +// #error "This sample can't be compiled in Unicode mode." #endif // wxUSE_UNICODE #include "wx/resource.h" @@ -56,7 +56,7 @@ // the TEXT resource, for some reason, so either run-time file loading // or file inclusion should be used. -#if defined(__WXMSW__) +#if defined(__WXMSW__) && !wxUSE_UNICODE // Under Windows, some compilers can't include // a whole .wxr file. So we use a .rc user-defined resource // instead. dialog1 will point to the whole .wxr 'file'. @@ -83,8 +83,9 @@ MyApp::MyApp() // main frame bool MyApp::OnInit(void) { -#if defined(__WXMSW__) +#if defined(__WXMSW__) && !wxUSE_UNICODE // Load the .wxr 'file' from a .rc resource, under Windows. + // note that the resource really is a char*, not a wxChar*! dialog1 = wxLoadUserResource(wxT("dialog1"), wxT("WXRDATA")); menu1 = wxLoadUserResource(wxT("menu1"), wxT("WXRDATA")); // All resources in the file (only one in this case) get parsed @@ -101,20 +102,20 @@ bool MyApp::OnInit(void) // Create the main frame window frame = new MyFrame( (wxFrame *) NULL, -1, - (char *) "wxWindows Resource Sample", + wxT("wxWindows Resource Sample"), wxPoint(-1, -1), wxSize(300, 250) ); // Give it a status line frame->CreateStatusBar(2); - wxMenuBar *menu_bar = wxResourceCreateMenuBar("menu1"); + wxMenuBar *menu_bar = wxResourceCreateMenuBar(wxT("menu1")); // Associate the menu bar with the frame frame->SetMenuBar(menu_bar); // Make a panel frame->panel = new MyPanel( frame, -1, wxPoint(0, 0), wxSize(400, 400), - 0, "MyMainFrame" ); + 0, wxT("MyMainFrame") ); frame->Show(TRUE); SetTopWindow(frame); @@ -124,7 +125,7 @@ bool MyApp::OnInit(void) MyApp::~MyApp() { -#if defined(__WXMSW__) +#if defined(__WXMSW__) && !wxUSE_UNICODE delete dialog1; delete menu1; #endif @@ -169,8 +170,8 @@ MyFrame::MyFrame void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) { - wxMessageBox("wxWindows resource sample.\n" - "(c) Julian Smart", "About wxWindows sample", + wxMessageBox(wxT("wxWindows resource sample.\n") + wxT("(c) Julian Smart"), wxT("About wxWindows sample"), wxICON_INFORMATION | wxOK); } @@ -183,12 +184,12 @@ void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event) ) { MyDialog *dialog = new MyDialog; - if (dialog->LoadFromResource(this, "dialog1")) + if (dialog->LoadFromResource(this, wxT("dialog1"))) { - wxTextCtrl *text = (wxTextCtrl *)wxFindWindowByName("multitext3", dialog); + wxTextCtrl *text = (wxTextCtrl *)wxFindWindowByName(wxT("multitext3"), dialog); if (text) { - text->SetValue("wxWindows resource demo"); + text->SetValue(wxT("wxWindows resource demo")); } dialog->ShowModal(); diff --git a/src/common/resource.cpp b/src/common/resource.cpp index c20116ff03..1cf86bc56a 100644 --- a/src/common/resource.cpp +++ b/src/common/resource.cpp @@ -119,23 +119,25 @@ void wxCleanUpResourceSystem() delete[] wxResourceBuffer; } +#if 0 void wxLogWarning(char *msg) { wxMessageBox(msg, _("Warning"), wxOK); } +#endif IMPLEMENT_DYNAMIC_CLASS(wxItemResource, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxResourceTable, wxHashTable) wxItemResource::wxItemResource() { - m_itemType = ""; - m_title = ""; - m_name = ""; + m_itemType = wxT(""); + m_title = wxT(""); + m_name = wxT(""); m_windowStyle = 0; m_x = m_y = m_width = m_height = 0; m_value1 = m_value2 = m_value3 = m_value5 = 0; - m_value4 = ""; + m_value4 = wxT(""); m_windowId = 0; m_exStyle = 0; } @@ -230,7 +232,7 @@ bool wxResourceTable::ParseResourceFile(const wxString& filename) { wxExprDatabase db; - FILE *fd = wxFopen(filename, _T("r")); + FILE *fd = wxFopen(filename, wxT("r")); if (!fd) return FALSE; bool eof = FALSE; @@ -341,7 +343,7 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* c // bitmap.LoadFile(wxCROSS_BITMAP, wxBITMAP_TYPE_BMP_RESOURCE); #else - bitmap.LoadFile("cross_bmp", wxBITMAP_TYPE_BMP_RESOURCE); + bitmap.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE); #endif control = new wxBitmapButton(parent, id, bitmap, pos, size, childResource->GetStyle() | wxBU_AUTODRAW, wxDefaultValidator, childResource->GetName()); @@ -367,7 +369,7 @@ wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* c #ifdef __WXMSW__ // Use a default bitmap if (!bitmap.Ok()) - bitmap.LoadFile("cross_bmp", wxBITMAP_TYPE_BMP_RESOURCE); + bitmap.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE); #endif if (bitmap.Ok()) @@ -2735,6 +2737,15 @@ bool wxResourceParseData(const wxString& resource, wxResourceTable *table) return table->ParseResourceData(resource); } +bool wxResourceParseData(const char* resource, wxResourceTable *table) +{ + wxString str(resource, wxConvLibc); + if (!table) + table = wxDefaultResourceTable; + + return table->ParseResourceData(str); +} + bool wxResourceParseFile(const wxString& filename, wxResourceTable *table) { if (!table) @@ -2798,7 +2809,7 @@ bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table) if (!table) table = wxDefaultResourceTable; - FILE *fd = wxFopen(f, _T("r")); + FILE *fd = wxFopen(f, wxT("r")); if (!fd) { return FALSE; @@ -3100,6 +3111,15 @@ bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxR return TRUE; } +bool wxResourceParseString(const wxString& s, wxResourceTable *table) +{ +#if wxUSE_UNICODE + return wxResourceParseString( (char*)s.mb_str().data() ); +#else + return wxResourceParseString( (char*)s.c_str() ); +#endif +} + bool wxResourceParseString(char *s, wxResourceTable *table) { if (!table) diff --git a/src/common/wxexpr.cpp b/src/common/wxexpr.cpp index 3db96de17a..b470a98ecc 100644 --- a/src/common/wxexpr.cpp +++ b/src/common/wxexpr.cpp @@ -608,7 +608,7 @@ void wxExpr::AddAttributeValueStringList(const wxString& attribute, wxList *stri wxNode *node = string_list->First(); while (node) { - char *string = (char *)node->Data(); + wxChar *string = (wxChar*)node->GetData(); wxExpr *expr = new wxExpr(wxExprString, wxString(string)); listExpr->Append(expr); node = node->Next(); @@ -920,7 +920,7 @@ wxExpr *wxExprDatabase::FindClause(long id) // Find a term based on an integer if (term->Type() == wxExprList) { - wxExpr *value = term->AttributeValue("id"); + wxExpr *value = term->AttributeValue(wxT("id")); if (value->Type() == wxExprInteger && value->IntegerValue() == id) found = term; } @@ -1196,7 +1196,7 @@ char *wxmake_exp2(char *str1, char *str2, char *str3) char *wxmake_word(char *str) { - wxExpr *x = new wxExpr(wxExprWord, str); + wxExpr *x = new wxExpr(wxExprWord, wxString(str, wxConvLibc).c_str()); return (char *)x; }