From d3a80c922c7f0932f0b3985846e58ef48e3a6da7 Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Fri, 14 Mar 2003 20:07:03 +0000 Subject: [PATCH 1/1] Remove explicit casts to (const char *), and replace it with .c_str(); use wxConstCast instead of explicit casts to char*. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19577 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/motif/app.cpp | 12 +++++++----- src/motif/bitmap.cpp | 8 +++++--- src/motif/checkbox.cpp | 1 + src/motif/combobox.cpp | 8 +++++--- src/motif/combobox_native.cpp | 4 ++-- src/motif/cursor.cpp | 3 ++- src/motif/dcclient.cpp | 13 +++++++++---- src/motif/dialog.cpp | 3 ++- src/motif/filedlg.cpp | 11 +++++++---- src/motif/listbox.cpp | 11 ++++++----- src/motif/menu.cpp | 4 ++-- src/motif/radiobox.cpp | 2 +- src/motif/stattext.cpp | 6 +----- src/motif/textctrl.cpp | 22 ++++++++++++---------- 14 files changed, 62 insertions(+), 46 deletions(-) diff --git a/src/motif/app.cpp b/src/motif/app.cpp index b40531cea5..3dd27a1a8c 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -464,7 +464,7 @@ bool wxApp::OnInitGui() XtAppSetFallbackResources((XtAppContext) wxTheApp->m_appContext, fallbackResources); Display *dpy = XtOpenDisplay((XtAppContext) wxTheApp->m_appContext,(String)NULL,NULL, - (const char*) wxTheApp->GetClassName(), NULL, 0, + wxTheApp->GetClassName().c_str(), NULL, 0, # if XtSpecificationRelease < 5 (Cardinal*) &argc, # else @@ -477,7 +477,7 @@ bool wxApp::OnInitGui() delete wxLog::SetActiveTarget(new wxLogStderr); wxString className(wxTheApp->GetClassName()); wxLogError(_("wxWindows could not open display for '%s': exiting."), - (const char*) className); + className.c_str()); exit(-1); } m_initialDisplay = (WXDisplay*) dpy; @@ -487,9 +487,11 @@ bool wxApp::OnInitGui() gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler); #endif // __WXDEBUG__ - wxTheApp->m_topLevelWidget = (WXWidget) XtAppCreateShell((String)NULL, (const char*) wxTheApp->GetClassName(), - applicationShellWidgetClass,dpy, - NULL,0) ; + wxTheApp->m_topLevelWidget = + (WXWidget) XtAppCreateShell((String)NULL, + wxTheApp->GetClassName().c_str(), + applicationShellWidgetClass,dpy, + NULL,0) ; // Add general resize proc XtActionsRec rec; diff --git a/src/motif/bitmap.cpp b/src/motif/bitmap.cpp index 7f8e568cd6..4e380b6df2 100644 --- a/src/motif/bitmap.cpp +++ b/src/motif/bitmap.cpp @@ -429,7 +429,7 @@ bool wxXBMFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, M_BITMAPDATA->m_display = (WXDisplay*) dpy; int value = XReadBitmapFile (dpy, RootWindow (dpy, DefaultScreen (dpy)), - (char*) (const char*) name, &w, &h, &pixmap, &hotX, &hotY); + wxConstCast(name.c_str(), char), &w, &h, &pixmap, &hotX, &hotY); M_BITMAPHANDLERDATA->m_width = w; M_BITMAPHANDLERDATA->m_height = h; M_BITMAPHANDLERDATA->m_depth = 1; @@ -569,7 +569,8 @@ bool wxXPMFileHandler::LoadFile( wxBitmap *bitmap, const wxString& name, xpmAttr.valuemask = XpmReturnInfos | XpmCloseness; xpmAttr.closeness = 40000; int errorStatus = XpmReadFileToPixmap(dpy, - RootWindow(dpy, DefaultScreen(dpy)), (char*) (const char*) name, + RootWindow(dpy, DefaultScreen(dpy)), + wxConstCast(name.c_str(), char), &pixmap, &mask, &xpmAttr); if (errorStatus == XpmSuccess) @@ -624,7 +625,8 @@ bool wxXPMFileHandler::SaveFile( const wxBitmap *bitmap, const wxString& name, if (M_BITMAPHANDLERDATA->m_ok && M_BITMAPHANDLERDATA->m_pixmap) { Display *dpy = (Display*) M_BITMAPHANDLERDATA->m_display; - int errorStatus = XpmWriteFileFromPixmap(dpy, (char*) (const char*) name, + int errorStatus = XpmWriteFileFromPixmap(dpy, + wxConstCast(name.c_str(), char), (Pixmap) M_BITMAPHANDLERDATA->m_pixmap, (M_BITMAPHANDLERDATA->m_bitmapMask ? (Pixmap) M_BITMAPHANDLERDATA->m_bitmapMask->GetPixmap() : (Pixmap) 0), (XpmAttributes *) NULL); diff --git a/src/motif/checkbox.cpp b/src/motif/checkbox.cpp index 8d89b52531..cd2b57c5b8 100644 --- a/src/motif/checkbox.cpp +++ b/src/motif/checkbox.cpp @@ -61,6 +61,7 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, xmToggleButtonWidgetClass, parentWidget, wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)), XmNlabelString, text(), + XmNrecomputeSize, False, NULL); XtAddCallback( (Widget)m_mainWidget, diff --git a/src/motif/combobox.cpp b/src/motif/combobox.cpp index 5e81729e67..fb3e685bf1 100644 --- a/src/motif/combobox.cpp +++ b/src/motif/combobox.cpp @@ -126,7 +126,8 @@ void wxComboBox::SetValue(const wxString& value) { m_inSetValue = TRUE; if( !value.empty() ) - XmComboBoxSetString( (Widget)m_mainWidget, (char*)value.c_str() ); + XmComboBoxSetString( (Widget)m_mainWidget, + wxConstCast(value.c_str(), char) ); m_inSetValue = FALSE; } @@ -253,8 +254,9 @@ long wxComboBox::GetLastPosition() const void wxComboBox::Replace(long from, long to, const wxString& value) { - XmComboBoxReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, - (char*) (const char*) value); + XmComboBoxReplace ((Widget) m_mainWidget, (XmTextPosition) from, + (XmTextPosition) to, + wxConstCast(value.c_str(), char)); } void wxComboBox::Remove(long from, long to) diff --git a/src/motif/combobox_native.cpp b/src/motif/combobox_native.cpp index aa8eac0f0d..9a96177941 100644 --- a/src/motif/combobox_native.cpp +++ b/src/motif/combobox_native.cpp @@ -180,7 +180,7 @@ void wxComboBox::SetValue(const wxString& value) m_inSetValue = true; XtVaSetValues( GetXmText(this), - XmNvalue, (char *)value.c_str(), + XmNvalue, wxConstCast(value.c_str(), char), NULL); m_inSetValue = false; @@ -304,7 +304,7 @@ long wxComboBox::GetLastPosition() const void wxComboBox::Replace(long from, long to, const wxString& value) { XmTextReplace( GetXmText(this), (XmTextPosition)from, (XmTextPosition)to, - (char*)value.c_str() ); + wxConstCast(value.c_str(), char) ); } void wxComboBox::Remove(long from, long to) diff --git a/src/motif/cursor.cpp b/src/motif/cursor.cpp index 7e7fa61066..c8ea7b6b56 100644 --- a/src/motif/cursor.cpp +++ b/src/motif/cursor.cpp @@ -315,7 +315,8 @@ wxCursor::wxCursor(const wxString& name, long flags, int hotSpotX, int hotSpotY) int screen_num = DefaultScreen (dpy); int value = XReadBitmapFile (dpy, RootWindow (dpy, DefaultScreen (dpy)), - (char*) (const char*) name, &w, &h, &pixmap, &hotX, &hotY); + wxConstCast(name.c_str(), char), + &w, &h, &pixmap, &hotX, &hotY); M_BITMAPDATA->m_width = w; M_BITMAPDATA->m_height = h; diff --git a/src/motif/dcclient.cpp b/src/motif/dcclient.cpp index e4f7c3282a..de005e664d 100644 --- a/src/motif/dcclient.cpp +++ b/src/motif/dcclient.cpp @@ -1130,7 +1130,9 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) &ascent, &descent, &overall_return); else #endif // 0 - (void)XTextExtents((XFontStruct*) pFontStruct, (char*) (const char*) text, slen, &direction, + (void)XTextExtents((XFontStruct*) pFontStruct, + wxConstCast(text.c_str(), char), + slen, &direction, &ascent, &descent, &overall_return); cx = overall_return.width; @@ -1222,7 +1224,8 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) else #endif // 0 XDrawString((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(), (GC) m_gcBacking, - XLOG2DEV_2 (x), YLOG2DEV_2 (y) + ascent, (char*) (const char*) text, slen); + XLOG2DEV_2 (x), YLOG2DEV_2 (y) + ascent, + wxConstCast(text.c_str(), char), slen); } // restore fill style @@ -1291,7 +1294,8 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, else #endif // 0 (void)XTextExtents((XFontStruct*) pFontStruct, - (char*)text.c_str(), slen, &direction, + wxConstCast(text.c_str(), char), + slen, &direction, &ascent, &descent, &overall_return); cx = overall_return.width; @@ -1437,7 +1441,8 @@ void wxWindowDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoor &ascent, &descent2, &overall); else #endif // 0 - XTextExtents((XFontStruct*) pFontStruct, (char*) (const char*) string, slen, &direction, + XTextExtents((XFontStruct*) pFontStruct, + wxConstCast(string.c_str(), char), slen, &direction, &ascent, &descent2, &overall); if (width) *width = XDEV2LOGREL (overall.width); diff --git a/src/motif/dialog.cpp b/src/motif/dialog.cpp index 1e3191c27e..def4c93d14 100644 --- a/src/motif/dialog.cpp +++ b/src/motif/dialog.cpp @@ -168,7 +168,8 @@ bool wxDialog::DoCreate( wxWindow* parent, wxWindowID id, XtSetArg (args[0], XmNdefaultPosition, False); XtSetArg (args[1], XmNautoUnmanage, False); Widget dialogShell = - XmCreateBulletinBoardDialog( parentWidget, (char*)name.c_str(), + XmCreateBulletinBoardDialog( parentWidget, + wxConstCast(name.c_str(), char), args, 2); m_mainWidget = (WXWidget) dialogShell; diff --git a/src/motif/filedlg.cpp b/src/motif/filedlg.cpp index 9336136f94..988efef176 100644 --- a/src/motif/filedlg.cpp +++ b/src/motif/filedlg.cpp @@ -262,7 +262,9 @@ int wxFileDialog::ShowModal() Widget shell = XtParent(fileSel); if (!m_message.IsNull()) - XtVaSetValues(shell, XmNtitle, (char*) (const char*) m_message, NULL); + XtVaSetValues(shell, + XmNtitle, wxConstCast(m_message.c_str(), char), + NULL); wxString entirePath(""); @@ -289,7 +291,7 @@ int wxFileDialog::ShowModal() else filter = wildCard; - XmTextSetString(filterWidget, (char*)filter.c_str()); + XmTextSetString(filterWidget, wxConstCast(filter.c_str(), char)); XmFileSelectionDoSearch(fileSel, NULL); } @@ -306,7 +308,8 @@ int wxFileDialog::ShowModal() if (entirePath != "") { - XmTextSetString(selectionWidget, (char*)entirePath.c_str()); + XmTextSetString(selectionWidget, + wxConstCast(entirePath.c_str(), char)); } XtAddCallback(fileSel, XmNcancelCallback, (XtCallbackProc)wxFileSelCancel, (XtPointer)NULL); @@ -381,7 +384,7 @@ int wxFileDialog::ShowModal() static wxString wxDefaultFileSelector(bool load, const char *what, const char *extension, const char *default_name, wxWindow *parent) { - char *ext = (char *)extension; + char *ext = wxConstCast(extension, char); wxString prompt; wxString str; diff --git a/src/motif/listbox.cpp b/src/motif/listbox.cpp index a88b74149d..dc8cf4c10a 100644 --- a/src/motif/listbox.cpp +++ b/src/motif/listbox.cpp @@ -118,8 +118,9 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, ++count; } - Widget listWidget = XmCreateScrolledList(parentWidget, - (char*)name.c_str(), args, count); + Widget listWidget = + XmCreateScrolledList(parentWidget, + wxConstCast(name.c_str(), char), args, count); m_mainWidget = (WXWidget) listWidget; @@ -256,7 +257,7 @@ void wxListBox::DoSetItems(const wxArrayString& items, void** clientData) XmString *text = new XmString[items.GetCount()]; size_t i; for (i = 0; i < items.GetCount(); ++i) - text[i] = XmStringCreateSimple ((char*)items[i].c_str()); + text[i] = wxStringToXmString (items[i]); if ( clientData ) for (i = 0; i < items.GetCount(); ++i) @@ -486,12 +487,12 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos) // Corrected by Sergey Krasnov from Steve Hammes' code #if XmVersion > 1001 for (i = 0; i < items.GetCount(); i++) - text[i] = XmStringCreateSimple((char*)items[i].c_str()); + text[i] = wxStringToXmString(items[i]); XmListAddItemsUnselected(listBox, text, items.GetCount(), pos+1); #else for (i = 0; i < items.GetCount(); i++) { - text[i] = XmStringCreateSimple((char*)items[i].c_str()); + text[i] = wxStringToXmString(items[i]); // Another Sergey correction XmListAddItemUnselected(listBox, text[i], pos+i+1); } diff --git a/src/motif/menu.cpp b/src/motif/menu.cpp index 6ed70d67d9..06ad86e72d 100644 --- a/src/motif/menu.cpp +++ b/src/motif/menu.cpp @@ -327,12 +327,12 @@ int wxMenuBar::FindMenuItem (const wxString& menuString, const wxString& itemStr { char buf1[200]; char buf2[200]; - wxStripMenuCodes ((char *)(const char *)menuString, buf1); + wxStripMenuCodes (wxConstCast(menuString.c_str(), char), buf1); size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) { - wxStripMenuCodes ((char *)(const char *)m_titles[i], buf2); + wxStripMenuCodes (wxConstCast(m_titles[i].c_str(), char), buf2); if (strcmp (buf1, buf2) == 0) return m_menus[i]->FindItem (itemString); } diff --git a/src/motif/radiobox.cpp b/src/motif/radiobox.cpp index 94708cf8bb..98368633fc 100644 --- a/src/motif/radiobox.cpp +++ b/src/motif/radiobox.cpp @@ -146,7 +146,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title, { wxString str(wxStripMenuCodes(choices[i])); m_radioButtonLabels[i] = str; - m_radioButtons[i] = (WXWidget) XtVaCreateManagedWidget ((char*) (const char*) str, + m_radioButtons[i] = (WXWidget) XtVaCreateManagedWidget (wxConstCast(str.c_str(), char), #if wxUSE_GADGETS xmToggleButtonGadgetClass, radioBoxWidget, #else diff --git a/src/motif/stattext.cpp b/src/motif/stattext.cpp index 4a8e765be4..ead5cd99b5 100644 --- a/src/motif/stattext.cpp +++ b/src/motif/stattext.cpp @@ -58,10 +58,6 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, m_windowStyle = style; m_font = parent->GetFont(); -#if 0 // gcc 2.95 doesn't like this apparently - char* label1 = (label.IsNull() ? "" : (char*) (const char*) label); -#endif - Widget parentWidget = (Widget) parent->GetClientWidget(); Widget borderWidget = NULL; @@ -108,7 +104,7 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, WXFontType fontType = m_font.GetFontType(XtDisplay(parentWidget)); - m_labelWidget = XtVaCreateManagedWidget ((char*) (const char*) name, + m_labelWidget = XtVaCreateManagedWidget (wxConstCast(name.c_str(), char), xmLabelWidgetClass, borderWidget ? borderWidget : parentWidget, wxFont::GetFontTag(), fontType, diff --git a/src/motif/textctrl.cpp b/src/motif/textctrl.cpp index 1f616b7201..ced2808927 100644 --- a/src/motif/textctrl.cpp +++ b/src/motif/textctrl.cpp @@ -130,7 +130,7 @@ bool wxTextCtrl::Create(wxWindow *parent, XtSetArg (args[1], XmNwordWrap, wantWordWrap ? True : False); m_mainWidget = (WXWidget) XmCreateScrolledText(parentWidget, - (char*)name.c_str(), + wxConstCast(name.c_str(), char), args, 2); XtVaSetValues ((Widget) m_mainWidget, @@ -143,7 +143,7 @@ bool wxTextCtrl::Create(wxWindow *parent, { m_mainWidget = (WXWidget)XtVaCreateManagedWidget ( - (char*)name.c_str(), + wxConstCast(name.c_str(), char), xmTextWidgetClass, parentWidget, NULL @@ -175,7 +175,7 @@ bool wxTextCtrl::Create(wxWindow *parent, // do this instead... MB // XtVaSetValues( (Widget) m_mainWidget, - XmNvalue, (char *)value.c_str(), + XmNvalue, wxConstCast(value.c_str(), char), NULL); } @@ -250,7 +250,7 @@ void wxTextCtrl::SetValue(const wxString& value) // do this instead... MB // XtVaSetValues( (Widget) m_mainWidget, - XmNvalue, (char *)value.c_str(), + XmNvalue, wxConstCast(value.c_str(), char), NULL); m_inSetValue = FALSE; @@ -362,7 +362,7 @@ long wxTextCtrl::GetLastPosition() const void wxTextCtrl::Replace(long from, long to, const wxString& value) { XmTextReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to, - (char*) (const char*) value); + wxConstCast(value.c_str(), char)); } void wxTextCtrl::Remove(long from, long to) @@ -394,8 +394,8 @@ bool wxTextCtrl::LoadFile(const wxString& file) FILE *fp = 0; struct stat statb; - if ((stat ((char*) (const char*) file, &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG || - !(fp = fopen ((char*) (const char*) file, "r"))) + if ((stat (wxConstCast(file.c_str(), char), &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG || + !(fp = fopen (wxConstCast(file.c_str(), char), "r"))) { return FALSE; } @@ -436,7 +436,7 @@ bool wxTextCtrl::SaveFile(const wxString& file) Widget textWidget = (Widget) m_mainWidget; FILE *fp; - if (!(fp = fopen ((char*) (const char*) theFile, "w"))) + if (!(fp = fopen (wxConstCast(theFile.c_str(), char), "w"))) { return FALSE; } @@ -463,7 +463,8 @@ bool wxTextCtrl::SaveFile(const wxString& file) void wxTextCtrl::WriteText(const wxString& text) { long textPosition = GetInsertionPoint() + strlen (text); - XmTextInsert ((Widget) m_mainWidget, GetInsertionPoint(), (char*) (const char*) text); + XmTextInsert ((Widget) m_mainWidget, GetInsertionPoint(), + wxConstCast(text.c_str(), char)); XtVaSetValues ((Widget) m_mainWidget, XmNcursorPosition, textPosition, NULL); SetInsertionPoint(textPosition); XmTextShowPosition ((Widget) m_mainWidget, textPosition); @@ -473,7 +474,8 @@ void wxTextCtrl::WriteText(const wxString& text) void wxTextCtrl::AppendText(const wxString& text) { long textPosition = GetLastPosition() + strlen(text); - XmTextInsert ((Widget) m_mainWidget, GetLastPosition(), (char*) (const char*) text); + XmTextInsert ((Widget) m_mainWidget, GetLastPosition(), + wxConstCast(text.c_str(), char)); XtVaSetValues ((Widget) m_mainWidget, XmNcursorPosition, textPosition, NULL); SetInsertionPoint(textPosition); XmTextShowPosition ((Widget) m_mainWidget, textPosition); -- 2.45.2