From 6991087b08355e652866e97d3a8211103864ed8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sat, 21 Jul 2007 16:43:31 +0000 Subject: [PATCH] fixed wxMotif to compile in Unicode mode (this is not full Unicode support, all strings must be representable in current locale's charset, similarly to MSLU) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47623 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- configure | 8 +---- configure.in | 4 --- include/wx/motif/chkconf.h | 8 ----- include/wx/motif/private.h | 10 ++++++- include/wx/x11/private.h | 4 +-- src/motif/accel.cpp | 2 +- src/motif/app.cpp | 56 +++++++++++++++++++++++++++++++++++ src/motif/clipbrd.cpp | 6 ++-- src/motif/combobox_native.cpp | 4 +-- src/motif/cursor.cpp | 4 +-- src/motif/dcclient.cpp | 4 +-- src/motif/dialog.cpp | 6 ++-- src/motif/filedlg.cpp | 7 ++--- src/motif/font.cpp | 2 +- src/motif/frame.cpp | 4 +-- src/motif/listbox.cpp | 2 +- src/motif/radiobox.cpp | 2 +- src/motif/stattext.cpp | 2 +- src/motif/textctrl.cpp | 16 +++++----- src/motif/utils.cpp | 5 ---- src/motif/window.cpp | 3 +- 21 files changed, 100 insertions(+), 59 deletions(-) diff --git a/configure b/configure index eb91305089..f1b12d5219 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Id: configure.in 47617 2007-07-21 13:01:28Z VZ . +# From configure.in Id: configure.in 47621 2007-07-21 13:09:57Z VZ . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for wxWidgets 2.9.0. # @@ -33755,12 +33755,6 @@ done fi if test "$wxUSE_MOTIF" = 1; then - if test "$wxUSE_UNICODE" = "yes"; then - { { echo "$as_me:$LINENO: error: Unicode configuration not supported with Motif" >&5 -echo "$as_me: error: Unicode configuration not supported with Motif" >&2;} - { (exit 1); exit 1; }; } - fi - { echo "$as_me:$LINENO: checking for Motif/Lesstif headers" >&5 echo $ECHO_N "checking for Motif/Lesstif headers... $ECHO_C" >&6; } diff --git a/configure.in b/configure.in index 6f43c592a8..8a0fc61bf0 100644 --- a/configure.in +++ b/configure.in @@ -3077,10 +3077,6 @@ libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config fi if test "$wxUSE_MOTIF" = 1; then - if test "$wxUSE_UNICODE" = "yes"; then - AC_MSG_ERROR([Unicode configuration not supported with Motif]) - fi - AC_MSG_CHECKING(for Motif/Lesstif headers) WX_PATH_FIND_INCLUDES($SEARCH_INCLUDE, Xm/Xm.h) if test "$ac_find_includes" != "" ; then diff --git a/include/wx/motif/chkconf.h b/include/wx/motif/chkconf.h index 35534f93ed..4238e36874 100644 --- a/include/wx/motif/chkconf.h +++ b/include/wx/motif/chkconf.h @@ -11,14 +11,6 @@ /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */ -#if wxUSE_UNICODE -# ifdef wxABORT_ON_CONFIG_ERROR -# error "wxUSE_UNICODE is not supported with wxMotif" -# else -# define wxUSE_UNICODE 0 -# endif -#endif - #if wxUSE_NOTEBOOK && !wxUSE_TAB_DIALOG # undef wxUSE_TAB_DIALOG # define wxUSE_TAB_DIALOG 1 diff --git a/include/wx/motif/private.h b/include/wx/motif/private.h index 816fc71fcc..3301bbfc39 100644 --- a/include/wx/motif/private.h +++ b/include/wx/motif/private.h @@ -128,8 +128,11 @@ extern XColor itemColors[5] ; // ---------------------------------------------------------------------------- wxString wxXmStringToString( const XmString& xmString ); -XmString wxStringToXmString( const wxString& string ); XmString wxStringToXmString( const char* string ); +inline XmString wxStringToXmString( const wxCharBuffer& string ) + { return wxStringToXmString(string.data()); } +inline XmString wxStringToXmString( const wxString& string ) + { return wxStringToXmString((const char*)string.mb_str()); } // XmString made easy to use in wxWidgets (and has an added benefit of // cleaning up automatically) @@ -146,6 +149,11 @@ public: Init(str); } + wxXmString(const wchar_t* str) + { + Init(wxConvLibc.cWC2MB(str)); + } + wxXmString(const wxString& str) { Init(str.mb_str()); diff --git a/include/wx/x11/private.h b/include/wx/x11/private.h index d1b3a1be5e..955152cb34 100644 --- a/include/wx/x11/private.h +++ b/include/wx/x11/private.h @@ -28,8 +28,8 @@ // Include common declarations #include "wx/x11/privx.h" -#if wxUSE_UNICODE -#include "pango/pango.h" +#if wxUSE_PANGO +#include #endif class WXDLLIMPEXP_FWD_CORE wxMouseEvent; diff --git a/src/motif/accel.cpp b/src/motif/accel.cpp index 1a2f7fd393..4f8cd0311c 100644 --- a/src/motif/accel.cpp +++ b/src/motif/accel.cpp @@ -25,7 +25,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData { - friend class WXDLLEXPORT wxAcceleratorTable; + friend class wxAcceleratorTable; public: wxAcceleratorRefData(); virtual ~wxAcceleratorRefData(); diff --git a/src/motif/app.cpp b/src/motif/app.cpp index c635bb4a19..b9ac5cc2be 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -260,6 +260,60 @@ bool wxApp::OnInitGui() if ( clsname.empty() ) clsname = _T("wx"); + // FIXME-UTF8: This code is taken from wxGTK and duplicated here. This + // is just a temporary fix to make wxX11 compile in Unicode + // build, the real fix is to change Initialize()'s signature + // to use char* on Unix. +#if wxUSE_UNICODE + // XtOpenDisplay() wants char*, not wchar_t*, so convert + int i; + char **argvX11 = new char *[argc + 1]; + for ( i = 0; i < argc; i++ ) + { + argvX11[i] = strdup(wxConvLibc.cWX2MB(argv[i])); + } + + argvX11[argc] = NULL; + + int argcX11 = argc; + + Display *dpy = XtOpenDisplay((XtAppContext) wxTheApp->m_appContext, + (String)NULL, + appname.c_str(), + clsname.c_str(), + NULL, 0, // no options +# if XtSpecificationRelease < 5 + (Cardinal*) &argcX11, +# else + &argcX11, +# endif + argvX11); + + if ( argcX11 != argc ) + { + // we have to drop the parameters which were consumed by X11+ + for ( i = 0; i < argcX11; i++ ) + { + while ( strcmp(wxConvLibc.cWX2MB(argv[i]), argvX11[i]) != 0 ) + { + memmove(argv + i, argv + i + 1, (argc - i)*sizeof(*argv)); + } + } + + argc = argcX11; + } + //else: XtOpenDisplay() didn't modify our parameters + + // free our copy + for ( i = 0; i < argcX11; i++ ) + { + free(argvX11[i]); + } + + delete [] argvX11; + +#else // ANSI + Display *dpy = XtOpenDisplay((XtAppContext) wxTheApp->m_appContext, (String)NULL, appname.c_str(), @@ -272,6 +326,8 @@ bool wxApp::OnInitGui() # endif argv); +#endif // Unicode/ANSI + if (!dpy) { // if you don't log to stderr, nothing will be shown... delete wxLog::SetActiveTarget(new wxLogStderr); diff --git a/src/motif/clipbrd.cpp b/src/motif/clipbrd.cpp index d52fca5d5f..df66c9c417 100644 --- a/src/motif/clipbrd.cpp +++ b/src/motif/clipbrd.cpp @@ -312,7 +312,7 @@ bool wxClipboard::AddData( wxDataObject *data ) wxString id = dfarr[i].GetId(); while( ( retval = XmClipboardCopy( xdisplay, xwindow, itemId, - wxConstCast(id.mb_str(), char), + id.char_str(), NULL, size, i, &data_id ) ) == XmClipboardLocked ); @@ -461,7 +461,7 @@ bool wxClipboard::GetData( wxDataObject& data ) wxString id = chosenFormat.GetId(); while( ( retval = XmClipboardInquireLength( xdisplay, xwindow, - wxConstCast(id.mb_str(), char), + id.char_str(), &length ) ) == XmClipboardLocked ); if( retval != XmClipboardSuccess ) @@ -470,7 +470,7 @@ bool wxClipboard::GetData( wxDataObject& data ) wxCharBuffer buf(length); while( ( retval = XmClipboardRetrieve( xdisplay, xwindow, - wxConstCast(id.mb_str(), char), + id.char_str(), (XtPointer)buf.data(), length, &dummy1, &dummy2 ) ) == XmClipboardLocked ); diff --git a/src/motif/combobox_native.cpp b/src/motif/combobox_native.cpp index 242a507bd9..0caced91fd 100644 --- a/src/motif/combobox_native.cpp +++ b/src/motif/combobox_native.cpp @@ -196,7 +196,7 @@ void wxComboBox::SetValue(const wxString& value) m_inSetValue = true; XtVaSetValues( GetXmText(this), - XmNvalue, value.mb_str(), + XmNvalue, (const char*)value.mb_str(), NULL); m_inSetValue = false; @@ -341,7 +341,7 @@ wxTextPos wxComboBox::GetLastPosition() const void wxComboBox::Replace(long from, long to, const wxString& value) { XmTextReplace( GetXmText(this), (XmTextPosition)from, (XmTextPosition)to, - wxConstCast(value.mb_str(), char) ); + value.char_str() ); } void wxComboBox::Remove(long from, long to) diff --git a/src/motif/cursor.cpp b/src/motif/cursor.cpp index 0e70f27bcf..6d32080afd 100644 --- a/src/motif/cursor.cpp +++ b/src/motif/cursor.cpp @@ -51,7 +51,7 @@ WX_DEFINE_LIST(wxXCursorList) class WXDLLEXPORT wxCursorRefData: public wxObjectRefData { - friend class WXDLLEXPORT wxCursor; + friend class wxCursor; public: wxCursorRefData(); virtual ~wxCursorRefData(); @@ -259,7 +259,7 @@ wxCursor::wxCursor(const wxString& name, long flags, int hotSpotX, int hotSpotY) int screen_num = DefaultScreen (dpy); int value = XReadBitmapFile (dpy, RootWindow (dpy, screen_num), - wxConstCast(name.mb_str(), char), + name.mb_str(), &w, &h, &pixmap, &hotX, &hotY); if (value == BitmapSuccess) diff --git a/src/motif/dcclient.cpp b/src/motif/dcclient.cpp index fa5f8beb89..d9d24aeb46 100644 --- a/src/motif/dcclient.cpp +++ b/src/motif/dcclient.cpp @@ -1134,11 +1134,11 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) #if wxMOTIF_NEW_FONT_HANDLING XmbDrawString((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(), fset, (GC) m_gcBacking, XLOG2DEV_2 (x), YLOG2DEV_2 (y) + ascent, - wxConstCast(text.mb_str(), char), slen); + text.mb_str(), slen); #else XDrawString((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(), (GC) m_gcBacking, XLOG2DEV_2 (x), YLOG2DEV_2 (y) + ascent, - wxConstCast(text.mb_str(), char), slen); + text.mb_str(), slen); #endif } diff --git a/src/motif/dialog.cpp b/src/motif/dialog.cpp index b34a7ae801..95abbae57c 100644 --- a/src/motif/dialog.cpp +++ b/src/motif/dialog.cpp @@ -155,7 +155,7 @@ bool wxDialog::XmDoCreateTLW(wxWindow* parent, XtSetArg (args[1], XmNautoUnmanage, False); Widget dialogShell = XmCreateBulletinBoardDialog( parentWidget, - wxConstCast(name.mb_str(), char), + name.char_str(), args, 2); m_mainWidget = (WXWidget) dialogShell; @@ -236,9 +236,9 @@ void wxDialog::SetTitle(const wxString& title) { wxXmString str( title ); XtVaSetValues( (Widget)m_mainWidget, - XmNtitle, title.mb_str(), + XmNtitle, (const char*)title.mb_str(), XmNdialogTitle, str(), - XmNiconName, title.mb_str(), + XmNiconName, (const char*)title.mb_str(), NULL ); } } diff --git a/src/motif/filedlg.cpp b/src/motif/filedlg.cpp index 6ab59b0205..889ee87e14 100644 --- a/src/motif/filedlg.cpp +++ b/src/motif/filedlg.cpp @@ -237,7 +237,7 @@ int wxFileDialog::ShowModal() if (!m_message.IsNull()) XtVaSetValues(shell, - XmNtitle, wxConstCast(m_message.mb_str(), char), + XmNtitle, (const char*)m_message.mb_str(), NULL); if (!m_wildCard.empty()) @@ -250,7 +250,7 @@ int wxFileDialog::ShowModal() else filter = wildCard; - XmTextSetString(filterWidget, wxConstCast(filter.mb_str(), char)); + XmTextSetString(filterWidget, filter.char_str()); XmFileSelectionDoSearch(fileSel, NULL); } @@ -278,8 +278,7 @@ int wxFileDialog::ShowModal() if (!entirePath.empty()) { - XmTextSetString(selectionWidget, - wxConstCast(entirePath.mb_str(), char)); + XmTextSetString(selectionWidget, entirePath.char_str()); } XtAddCallback(fileSel, XmNcancelCallback, diff --git a/src/motif/font.cpp b/src/motif/font.cpp index 42e6e1e70f..07db51f0ab 100644 --- a/src/motif/font.cpp +++ b/src/motif/font.cpp @@ -550,7 +550,7 @@ wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const int count = 0; #if wxMOTIF_NEW_FONT_HANDLING - wxChar* fontSpec = wxStrdup( xFontSpec.mb_str() ); + char* fontSpec = wxStrdup(xFontSpec.mb_str()); XtSetArg( args[count], XmNfontName, fontSpec ); ++count; XtSetArg( args[count], XmNfontType, XmFONT_IS_FONTSET ); ++count; #else diff --git a/src/motif/frame.cpp b/src/motif/frame.cpp index d0d2f3b70c..c81a189d97 100644 --- a/src/motif/frame.cpp +++ b/src/motif/frame.cpp @@ -452,8 +452,8 @@ void wxFrame::SetTitle(const wxString& title) if( !title.empty() ) XtVaSetValues( (Widget)m_frameShell, - XmNtitle, title.mb_str(), - XmNiconName, title.mb_str(), + XmNtitle, (const char*)title.mb_str(), + XmNiconName, (const char*)title.mb_str(), NULL ); } diff --git a/src/motif/listbox.cpp b/src/motif/listbox.cpp index 74b891b293..fc729fba27 100644 --- a/src/motif/listbox.cpp +++ b/src/motif/listbox.cpp @@ -122,7 +122,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, Widget listWidget = XmCreateScrolledList(parentWidget, - wxConstCast(name.mb_str(), char), args, count); + name.char_str(), args, count); m_mainWidget = (WXWidget) listWidget; diff --git a/src/motif/radiobox.cpp b/src/motif/radiobox.cpp index e6a71ba4fb..00bcec5189 100644 --- a/src/motif/radiobox.cpp +++ b/src/motif/radiobox.cpp @@ -125,7 +125,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title, wxString str(GetLabelText(choices[i])); m_radioButtonLabels.push_back(str); Widget radioItem = XtVaCreateManagedWidget ( - wxConstCast(str.mb_str(), char), + str.mb_str(), #if wxUSE_GADGETS xmToggleButtonGadgetClass, radioBoxWidget, #else diff --git a/src/motif/stattext.cpp b/src/motif/stattext.cpp index f233a51080..3526a2bf2d 100644 --- a/src/motif/stattext.cpp +++ b/src/motif/stattext.cpp @@ -51,7 +51,7 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, (Widget) wxCreateBorderWidget( (WXWidget)parentWidget, style ); m_labelWidget = - XtVaCreateManagedWidget (wxConstCast(name.mb_str(), char), + XtVaCreateManagedWidget (name.mb_str(), xmLabelWidgetClass, borderWidget ? borderWidget : parentWidget, wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay(parentWidget)), diff --git a/src/motif/textctrl.cpp b/src/motif/textctrl.cpp index 1fd22c3af5..82624d53e8 100644 --- a/src/motif/textctrl.cpp +++ b/src/motif/textctrl.cpp @@ -138,14 +138,14 @@ bool wxTextCtrl::Create(wxWindow *parent, XtSetArg (args[count], (String) wxFont::GetFontTag(), m_font.GetFontType( XtDisplay(parentWidget) ) ); ++count; XtSetArg (args[count], XmNwordWrap, wantWordWrap); ++count; - XtSetArg (args[count], XmNvalue, value.mb_str()); ++count; + XtSetArg (args[count], XmNvalue, (const char*)value.mb_str()); ++count; XtSetArg (args[count], XmNeditable, style & wxTE_READONLY ? False : True); ++count; XtSetArg (args[count], XmNeditMode, XmMULTI_LINE_EDIT ); ++count; m_mainWidget = (WXWidget) XmCreateScrolledText(parentWidget, - wxConstCast(name.mb_str(), char), + name.char_str(), args, count); XtManageChild ((Widget) m_mainWidget); @@ -154,11 +154,11 @@ bool wxTextCtrl::Create(wxWindow *parent, { m_mainWidget = (WXWidget)XtVaCreateManagedWidget ( - wxConstCast(name.mb_str(), char), + name.mb_str(), xmTextWidgetClass, parentWidget, wxFont::GetFontTag(), m_font.GetFontType( XtDisplay(parentWidget) ), - XmNvalue, value.mb_str(), + XmNvalue, (const char*)value.mb_str(), XmNeditable, (style & wxTE_READONLY) ? False : True, NULL @@ -243,7 +243,7 @@ void wxTextCtrl::DoSetValue(const wxString& text, int flags) { m_inSetValue = true; - XmTextSetString ((Widget) m_mainWidget, wxConstCast(text.mb_str(), char)); + XmTextSetString ((Widget) m_mainWidget, text.char_str()); XtVaSetValues ((Widget) m_mainWidget, XmNcursorPosition, text.length(), NULL); @@ -364,7 +364,7 @@ wxTextPos wxTextCtrl::GetLastPosition() const void wxTextCtrl::Replace(long from, long to, const wxString& value) { XmTextReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, - wxConstCast(value.mb_str(), char)); + value.char_str()); } void wxTextCtrl::Remove(long from, long to) @@ -387,7 +387,7 @@ void wxTextCtrl::WriteText(const wxString& text) { long textPosition = GetInsertionPoint() + text.length(); XmTextInsert ((Widget) m_mainWidget, GetInsertionPoint(), - wxConstCast(text.mb_str(), char)); + text.char_str()); XtVaSetValues ((Widget) m_mainWidget, XmNcursorPosition, textPosition, NULL); SetInsertionPoint(textPosition); XmTextShowPosition ((Widget) m_mainWidget, textPosition); @@ -398,7 +398,7 @@ void wxTextCtrl::AppendText(const wxString& text) { wxTextPos textPosition = GetLastPosition() + text.length(); XmTextInsert ((Widget) m_mainWidget, GetLastPosition(), - wxConstCast(text.mb_str(), char)); + text.char_str()); XtVaSetValues ((Widget) m_mainWidget, XmNcursorPosition, textPosition, NULL); SetInsertionPoint(textPosition); XmTextShowPosition ((Widget) m_mainWidget, textPosition); diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp index b56aa96fe7..73bbf916ea 100644 --- a/src/motif/utils.cpp +++ b/src/motif/utils.cpp @@ -601,11 +601,6 @@ wxString wxXmStringToString( const XmString& xmString ) return wxEmptyString; } -XmString wxStringToXmString( const wxString& str ) -{ - return wxStringToXmString(str.mb_str()); -} - XmString wxStringToXmString( const char* str ) { return XmStringCreateLtoR((char *)str, XmSTRING_DEFAULT_CHARSET); diff --git a/src/motif/window.cpp b/src/motif/window.cpp index 3063917e61..efc13e5273 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -629,7 +629,8 @@ void wxWindow::Lower() void wxWindow::SetLabel(const wxString& label) { - XtVaSetValues((Widget)GetMainWidget(), XmNtitle, label.mb_str(), NULL); + XtVaSetValues((Widget)GetMainWidget(), XmNtitle, + (const char*)label.mb_str(), NULL); } wxString wxWindow::GetLabel() const -- 2.45.2