Eliminate -Wcast-qual warnings with GCC and Clang

Use const_cast, mutable, and various other changes to avoid -Wcast-qual
This commit is contained in:
Paul Cornett
2020-02-02 22:50:32 -08:00
parent 6724f8c052
commit 948ddc6e0f
115 changed files with 273 additions and 303 deletions

View File

@@ -711,7 +711,7 @@ static void gtk_assert_dialog_init(GTypeInstance* instance, void*)
/* icon */
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
image = gtk_image_new_from_stock("gtk-dialog-error", GTK_ICON_SIZE_DIALOG);
wxGCC_WARNING_RESTORE()
gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 12);
@@ -768,15 +768,11 @@ static void gtk_assert_dialog_init(GTypeInstance* instance, void*)
gtk_button_box_set_layout (GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END);
/* add the buttons */
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
button = gtk_assert_dialog_add_button_to (GTK_BOX(hbox), "Save to _file", GTK_STOCK_SAVE);
wxGCC_WARNING_RESTORE()
button = gtk_assert_dialog_add_button_to(GTK_BOX(hbox), "Save to _file", "gtk-save");
g_signal_connect (button, "clicked",
G_CALLBACK(gtk_assert_dialog_save_backtrace_callback), dlg);
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
button = gtk_assert_dialog_add_button_to (GTK_BOX(hbox), "Copy to clip_board", GTK_STOCK_COPY);
wxGCC_WARNING_RESTORE()
button = gtk_assert_dialog_add_button_to(GTK_BOX(hbox), "Copy to clip_board", "gtk-copy");
g_signal_connect (button, "clicked", G_CALLBACK(gtk_assert_dialog_copy_callback), dlg);
}
#endif // wxUSE_STACKWALKER
@@ -789,14 +785,10 @@ static void gtk_assert_dialog_init(GTypeInstance* instance, void*)
wxGCC_WARNING_RESTORE()
/* add the stop button */
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
gtk_assert_dialog_add_button (dlg, "_Stop", GTK_STOCK_QUIT, GTK_ASSERT_DIALOG_STOP);
wxGCC_WARNING_RESTORE()
gtk_assert_dialog_add_button(dlg, "_Stop", "gtk-quit", GTK_ASSERT_DIALOG_STOP);
/* add the continue button */
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
continuebtn = gtk_assert_dialog_add_button (dlg, "_Continue", GTK_STOCK_YES, GTK_ASSERT_DIALOG_CONTINUE);
wxGCC_WARNING_RESTORE()
continuebtn = gtk_assert_dialog_add_button(dlg, "_Continue", "gtk-yes", GTK_ASSERT_DIALOG_CONTINUE);
gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_ASSERT_DIALOG_CONTINUE);
g_signal_connect (continuebtn, "clicked", G_CALLBACK(gtk_assert_dialog_continue_callback), dlg);

View File

@@ -87,7 +87,7 @@ wxGDIRefData *wxBrush::CreateGDIRefData() const
wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
{
return new wxBrushRefData(*(wxBrushRefData *)data);
return new wxBrushRefData(*static_cast<const wxBrushRefData*>(data));
}
bool wxBrush::operator==(const wxBrush& brush) const

View File

@@ -184,7 +184,7 @@ wxSize wxButtonBase::GetDefaultSize(wxWindow* WXUNUSED(win))
GtkWidget *btn = gtk_button_new_with_mnemonic(labelGTK.utf8_str());
#else
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
GtkWidget *btn = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
GtkWidget* btn = gtk_button_new_from_stock("gtk-cancel");
wxGCC_WARNING_RESTORE()
#endif
gtk_container_add(GTK_CONTAINER(box), btn);

View File

@@ -160,7 +160,7 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
clip.GetId().c_str() );
// the atoms we received, holding a list of targets (= formats)
const GdkAtom* const atoms = (GdkAtom*)gtk_selection_data_get_data(selection_data);
const GdkAtom* const atoms = reinterpret_cast<const GdkAtom*>(gtk_selection_data_get_data(selection_data));
for (size_t i = 0; i < selection_data_length / sizeof(GdkAtom); i++)
{
const wxDataFormat format(atoms[i]);
@@ -406,7 +406,7 @@ async_targets_selection_received( GtkWidget *WXUNUSED(widget),
clip.GetId().c_str() );
// the atoms we received, holding a list of targets (= formats)
const GdkAtom* const atoms = (GdkAtom*)gtk_selection_data_get_data(selection_data);
const GdkAtom* const atoms = reinterpret_cast<const GdkAtom*>(gtk_selection_data_get_data(selection_data));
for (size_t i = 0; i < selection_data_length / sizeof(GdkAtom); i++)
{
const wxDataFormat format(atoms[i]);

View File

@@ -745,7 +745,7 @@ void wxWindowDCImpl::DoDrawLines( int n, const wxPoint points[], wxCoord xoffset
}
if (m_gdkwindow)
gdk_draw_lines( m_gdkwindow, m_penGC, (GdkPoint*) gpts, n);
gdk_draw_lines(m_gdkwindow, m_penGC, const_cast<GdkPoint*>(gpts), n);
delete[] gpts_alloc;
}
@@ -791,7 +791,7 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[],
bool originChanged;
DrawingSetup(gc, originChanged);
gdk_draw_polygon(m_gdkwindow, gc, true, (GdkPoint*) gdkpoints, n);
gdk_draw_polygon(m_gdkwindow, gc, true, const_cast<GdkPoint*>(gdkpoints), n);
if (originChanged)
gdk_gc_set_ts_origin(gc, 0, 0);
@@ -809,7 +809,7 @@ void wxWindowDCImpl::DoDrawPolygon( int n, const wxPoint points[],
gdkpoints[(i+1)%n].y);
}
*/
gdk_draw_polygon( m_gdkwindow, m_penGC, FALSE, (GdkPoint*) gdkpoints, n );
gdk_draw_polygon(m_gdkwindow, m_penGC, false, const_cast<GdkPoint*>(gdkpoints), n);
}
}

View File

@@ -85,9 +85,6 @@ bool wxDirDialog::Create(wxWindow* parent,
if (parent)
gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) );
#ifndef __WXGTK4__
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
#endif
m_widget = gtk_file_chooser_dialog_new(
wxGTK_CONV(m_message),
gtk_parent,
@@ -95,19 +92,17 @@ bool wxDirDialog::Create(wxWindow* parent,
#ifdef __WXGTK4__
static_cast<const char*>(wxGTK_CONV(wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_CANCEL)))),
#else
GTK_STOCK_CANCEL,
"gtk-cancel",
#endif
GTK_RESPONSE_CANCEL,
#ifdef __WXGTK4__
static_cast<const char*>(wxGTK_CONV(wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_OPEN)))),
#else
GTK_STOCK_OPEN,
"gtk-open",
#endif
GTK_RESPONSE_ACCEPT,
NULL);
#ifndef __WXGTK4__
wxGCC_WARNING_RESTORE()
#endif
g_object_ref(m_widget);
gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT);

View File

@@ -213,9 +213,6 @@ bool wxFileDialog::Create(wxWindow *parent, const wxString& message,
if (parent)
gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) );
#ifndef __WXGTK4__
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
#endif
wxString ok_btn_stock;
if ( style & wxFD_SAVE )
{
@@ -223,7 +220,7 @@ bool wxFileDialog::Create(wxWindow *parent, const wxString& message,
#ifdef __WXGTK4__
ok_btn_stock = wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_SAVE));
#else
ok_btn_stock = GTK_STOCK_SAVE;
ok_btn_stock = "gtk-save";
#endif
}
else
@@ -232,7 +229,7 @@ bool wxFileDialog::Create(wxWindow *parent, const wxString& message,
#ifdef __WXGTK4__
ok_btn_stock = wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_OPEN));
#else
ok_btn_stock = GTK_STOCK_OPEN;
ok_btn_stock = "gtk-open";
#endif
}
@@ -243,14 +240,12 @@ bool wxFileDialog::Create(wxWindow *parent, const wxString& message,
#ifdef __WXGTK4__
static_cast<const gchar*>(wxGTK_CONV(wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_CANCEL)))),
#else
GTK_STOCK_CANCEL,
"gtk-cancel",
#endif
GTK_RESPONSE_CANCEL,
static_cast<const gchar*>(wxGTK_CONV(ok_btn_stock)), GTK_RESPONSE_ACCEPT,
NULL);
#ifndef __WXGTK4__
wxGCC_WARNING_RESTORE()
#endif
g_object_ref(m_widget);
GtkFileChooser* file_chooser = GTK_FILE_CHOOSER(m_widget);

View File

@@ -1349,6 +1349,7 @@ wxGetGtkAccel(const wxMenuItem* item, guint* accel_key, GdkModifierType* accel_m
#ifndef __WXGTK4__
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
wxGCC_WARNING_SUPPRESS(cast-qual)
const char *wxGetStockGtkID(wxWindowID id)
{
#define STOCKITEM(wx,gtk) \
@@ -1451,6 +1452,7 @@ const char *wxGetStockGtkID(wxWindowID id)
return NULL;
}
wxGCC_WARNING_RESTORE(cast-qual)
wxGCC_WARNING_RESTORE()
#endif // !__WXGTK4__

View File

@@ -52,9 +52,7 @@ wxString wxMessageDialog::GetDefaultYesLabel() const
#ifdef __WXGTK4__
return wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_YES));
#else
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
return GTK_STOCK_YES;
wxGCC_WARNING_RESTORE()
return "gtk-yes";
#endif
}
@@ -63,9 +61,7 @@ wxString wxMessageDialog::GetDefaultNoLabel() const
#ifdef __WXGTK4__
return wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_NO));
#else
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
return GTK_STOCK_NO;
wxGCC_WARNING_RESTORE()
return "gtk-no";
#endif
}
@@ -74,9 +70,7 @@ wxString wxMessageDialog::GetDefaultOKLabel() const
#ifdef __WXGTK4__
return wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_OK));
#else
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
return GTK_STOCK_OK;
wxGCC_WARNING_RESTORE()
return "gtk-ok";
#endif
}
@@ -85,9 +79,7 @@ wxString wxMessageDialog::GetDefaultCancelLabel() const
#ifdef __WXGTK4__
return wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_CANCEL));
#else
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
return GTK_STOCK_CANCEL;
wxGCC_WARNING_RESTORE()
return "gtk-cancel";
#endif
}
@@ -96,9 +88,7 @@ wxString wxMessageDialog::GetDefaultHelpLabel() const
#ifdef __WXGTK4__
return wxConvertMnemonicsToGTK(wxGetStockLabel(wxID_HELP));
#else
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
return GTK_STOCK_HELP;
wxGCC_WARNING_RESTORE()
return "gtk-help";
#endif
}

View File

@@ -127,7 +127,7 @@ wxGDIRefData *wxPen::CreateGDIRefData() const
wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
{
return new wxPenRefData(*(wxPenRefData *)data);
return new wxPenRefData(*static_cast<const wxPenRefData*>(data));
}
bool wxPen::operator == ( const wxPen& pen ) const
@@ -193,7 +193,7 @@ int wxPen::GetDashes( wxDash **ptr ) const
{
wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
*ptr = (wxDash*)M_PENDATA->m_dash;
*ptr = const_cast<wxDash*>(M_PENDATA->m_dash);
return M_PENDATA->m_countDashes;
}
@@ -208,7 +208,7 @@ wxDash* wxPen::GetDash() const
{
wxCHECK_MSG( IsOk(), NULL, wxT("invalid pen") );
return (wxDash*)M_PENDATA->m_dash;
return const_cast<wxDash*>(M_PENDATA->m_dash);
}
wxPenCap wxPen::GetCap() const

View File

@@ -188,13 +188,13 @@ void wxSpinButton::DoEnable(bool enable)
void wxSpinButton::GtkDisableEvents() const
{
g_signal_handlers_block_by_func(m_widget,
(gpointer)gtk_value_changed, (void*) this);
(void*)gtk_value_changed, const_cast<wxSpinButton*>(this));
}
void wxSpinButton::GtkEnableEvents() const
{
g_signal_handlers_unblock_by_func(m_widget,
(gpointer)gtk_value_changed, (void*) this);
(void*)gtk_value_changed, const_cast<wxSpinButton*>(this));
}
GdkWindow *wxSpinButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED_IN_GTK2(windows)) const

View File

@@ -291,22 +291,16 @@ void wxSpinCtrlGTKBase::DoSetIncrement(double inc)
gtk_spin_button_set_increments( GTK_SPIN_BUTTON(m_widget), inc, page);
}
void wxSpinCtrlGTKBase::GtkDisableEvents() const
void wxSpinCtrlGTKBase::GtkDisableEvents()
{
g_signal_handlers_block_by_func( m_widget,
(gpointer)gtk_value_changed, (void*) this);
g_signal_handlers_block_by_func(m_widget,
(gpointer)gtk_changed, (void*) this);
g_signal_handlers_block_by_func(m_widget, (void*)gtk_value_changed, this);
g_signal_handlers_block_by_func(m_widget, (void*)gtk_changed, this);
}
void wxSpinCtrlGTKBase::GtkEnableEvents() const
void wxSpinCtrlGTKBase::GtkEnableEvents()
{
g_signal_handlers_unblock_by_func(m_widget,
(gpointer)gtk_value_changed, (void*) this);
g_signal_handlers_unblock_by_func(m_widget,
(gpointer)gtk_changed, (void*) this);
g_signal_handlers_unblock_by_func(m_widget, (void*)gtk_value_changed, this);
g_signal_handlers_unblock_by_func(m_widget, (void*)gtk_changed, this);
}
void wxSpinCtrlGTKBase::OnChar( wxKeyEvent &event )

View File

@@ -66,7 +66,7 @@ wxGtkTextRemoveTagsWithPrefix(GtkTextBuffer *text_buffer,
text_buffer,
"remove_tag",
G_CALLBACK(wxGtkOnRemoveTag),
gpointer(prefix)
const_cast<void*>(static_cast<const void*>(prefix))
);
gtk_text_buffer_remove_all_tags(text_buffer, start, end);
g_signal_handler_disconnect(text_buffer, remove_handler_id);

View File

@@ -5182,7 +5182,7 @@ void wxWindowGTK::GTKSendPaintEvents(const GdkRegion* region)
GTK_SHADOW_NONE,
&rect,
parent->m_widget,
(char *)"base",
const_cast<char*>("base"),
0, 0, w, h);
#endif // !__WXGTK3__
}