From e808cf8a0a77ced81143e9b27283a3b2a907a747 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Tue, 3 Oct 2006 16:01:18 +0000 Subject: [PATCH] Don't free a string that is managed by wxGtkString, that's the whole _point_ of wxGtkString. While we're at it, lets use it some more. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41597 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/dataobj.cpp | 8 +++----- src/gtk/dirdlg.cpp | 26 +++++++------------------- src/gtk/filedlg.cpp | 33 +++++++++++---------------------- src/gtk/filepicker.cpp | 7 ++----- src/gtk/fontdlg.cpp | 4 +--- src/gtk/listbox.cpp | 3 +-- src/gtk/textctrl.cpp | 22 +++++++++------------- 7 files changed, 34 insertions(+), 69 deletions(-) diff --git a/src/gtk/dataobj.cpp b/src/gtk/dataobj.cpp index 88ba70ce97..ef24cfe8af 100644 --- a/src/gtk/dataobj.cpp +++ b/src/gtk/dataobj.cpp @@ -23,7 +23,7 @@ #include "wx/mstream.h" #include "wx/uri.h" -#include +#include "wx/gtk/private.h" //------------------------------------------------------------------------- // global data @@ -110,10 +110,8 @@ wxDataFormatId wxDataFormat::GetType() const wxString wxDataFormat::GetId() const { - gchar* atom_name = gdk_atom_name( m_format ); - wxString ret = wxString::FromAscii( atom_name ); - g_free(atom_name); - return ret; + wxGtkString atom_name(gdk_atom_name(m_format)); + return wxString::FromAscii(atom_name); } void wxDataFormat::SetId( NativeFormat format ) diff --git a/src/gtk/dirdlg.cpp b/src/gtk/dirdlg.cpp index 84f672f95d..70faf33d0c 100644 --- a/src/gtk/dirdlg.cpp +++ b/src/gtk/dirdlg.cpp @@ -29,18 +29,10 @@ #include "wx/filedlg.h" #endif -#include #include "wx/gtk/private.h" #include // chdir - -//----------------------------------------------------------------------------- -// idle system -//----------------------------------------------------------------------------- - -extern void wxapp_install_idle_handler(); - //----------------------------------------------------------------------------- // "clicked" for OK-button //----------------------------------------------------------------------------- @@ -48,13 +40,12 @@ extern void wxapp_install_idle_handler(); extern "C" { static void gtk_dirdialog_ok_callback(GtkWidget *widget, wxDirDialog *dialog) { - gchar* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); - // change to the directory where the user went if asked if (dialog->HasFlag(wxDD_CHANGE_DIR)) + { + wxGtkString filename(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget))); chdir(filename); - - g_free(filename); + } wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); event.SetEventObject(dialog); @@ -213,14 +204,11 @@ wxString wxDirDialog::GetPath() const { if (!gtk_check_version(2,4,0)) { - gchar *str = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(m_widget) ); - wxString ret = wxConvFileName->cMB2WX(str); - if (str) g_free(str); - - return ret; + wxGtkString str(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(m_widget))); + return wxConvFileName->cMB2WX(str); } - else - return wxGenericDirDialog::GetPath(); + + return wxGenericDirDialog::GetPath(); } #endif // wxUSE_DIRDLG diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index 81e12219e4..16cc0b0c56 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -42,7 +42,7 @@ extern "C" { static void gtk_filedialog_ok_callback(GtkWidget *widget, wxFileDialog *dialog) { int style = dialog->GetWindowStyle(); - gchar* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); + wxGtkString filename(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget))); // gtk version numbers must be identical with the one in ctor (that calls set_do_overwrite_confirmation) #if GTK_CHECK_VERSION(2,7,3) @@ -69,13 +69,10 @@ static void gtk_filedialog_ok_callback(GtkWidget *widget, wxFileDialog *dialog) if (style & wxFD_CHANGE_DIR) { // Use chdir to not care about filename encodings - gchar* folder = g_path_get_dirname(filename); + wxGtkString folder(g_path_get_dirname(filename)); chdir(folder); - g_free(folder); } - g_free(filename); - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); event.SetEventObject(dialog); dialog->GetEventHandler()->ProcessEvent(event); @@ -114,9 +111,7 @@ static void gtk_filedialog_update_preview_callback(GtkFileChooser *chooser, #if GTK_CHECK_VERSION(2,4,0) GtkWidget *preview = GTK_WIDGET(user_data); - gchar *str = gtk_file_chooser_get_preview_filename(chooser); - wxGtkString filename(str); - if (str) g_free(str); + wxGtkString filename(gtk_file_chooser_get_preview_filename(chooser)); if ( !filename ) return; @@ -310,14 +305,11 @@ wxString wxFileDialog::GetPath() const { if (!gtk_check_version(2,4,0)) { - gchar *str = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(m_widget)); - wxString ret = wxConvFileName->cMB2WX(str); - if (str) g_free(str); - - return ret; + wxGtkString str(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(m_widget))); + return wxConvFileName->cMB2WX(str); } - else - return wxGenericFileDialog::GetPath(); + + return wxGenericFileDialog::GetPath(); } void wxFileDialog::GetFilenames(wxArrayString& files) const @@ -401,14 +393,11 @@ wxString wxFileDialog::GetDirectory() const { if (!gtk_check_version(2,4,0)) { - gchar *str = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(m_widget) ); - wxString ret = wxConvFileName->cMB2WX(str); - if (str) g_free(str); - - return ret; + wxGtkString str(gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(m_widget))); + return wxConvFileName->cMB2WX(str); } - else - return wxGenericFileDialog::GetDirectory(); + + return wxGenericFileDialog::GetDirectory(); } void wxFileDialog::SetFilename(const wxString& name) diff --git a/src/gtk/filepicker.cpp b/src/gtk/filepicker.cpp index 6779e75111..cec62bdeb1 100644 --- a/src/gtk/filepicker.cpp +++ b/src/gtk/filepicker.cpp @@ -22,9 +22,7 @@ #include "wx/filepicker.h" #include "wx/tooltip.h" -#include - - +#include "wx/gtk/private.h" // ============================================================================ // implementation @@ -162,7 +160,7 @@ static void gtk_dirbutton_currentfolderchanged_callback(GtkFileChooserButton *wi // NB: it's important to use gtk_file_chooser_get_filename instead of // gtk_file_chooser_get_current_folder (see GTK docs) ! - gchar* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); + wxGtkString filename(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget))); p->UpdatePath(filename); // since GtkFileChooserButton when used to pick directories also uses a combobox, @@ -172,7 +170,6 @@ static void gtk_dirbutton_currentfolderchanged_callback(GtkFileChooserButton *wi // style was given. if (p->HasFlag(wxDIRP_CHANGE_DIR)) chdir(filename); - g_free(filename); // ...and fire an event wxFileDirPickerEvent event(wxEVT_COMMAND_DIRPICKER_CHANGED, p, p->GetId(), p->GetPath()); diff --git a/src/gtk/fontdlg.cpp b/src/gtk/fontdlg.cpp index 8c6f452f53..f6059b9e63 100644 --- a/src/gtk/fontdlg.cpp +++ b/src/gtk/fontdlg.cpp @@ -60,11 +60,9 @@ void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dial GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget); - gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg); + wxGtkString fontname(gtk_font_selection_dialog_get_font_name(fontdlg)); dialog->SetChosenFont( fontname); - g_free( fontname ); - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); event.SetEventObject( dialog ); dialog->GetEventHandler()->ProcessEvent( event ); diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index f38d62d070..c8d292fb4d 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -392,12 +392,11 @@ static gboolean gtk_listbox_searchequal_callback(GtkTreeModel* model, WXLISTBOX_DATACOLUMN_ARG(listbox), &entry, -1); wxCHECK_MSG(entry, 0, wxT("Could not get entry")); - gchar* keycollatekey = g_utf8_collate_key(key, -1); + wxGtkString keycollatekey(g_utf8_collate_key(key, -1)); int ret = strcasecmp(keycollatekey, gtk_tree_entry_get_collate_key(entry)); - g_free(keycollatekey); g_object_unref (entry); return ret != 0; diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 703ceccd9c..79cdce6465 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -69,10 +69,9 @@ static void wxGtkTextApplyTagsFromAttr(GtkTextBuffer *text_buffer, if (attr.HasFont()) { - char *font_string; PangoFontDescription *font_description = attr.GetFont().GetNativeFontInfo()->description; - font_string = pango_font_description_to_string(font_description); - g_snprintf(buf, sizeof(buf), "WXFONT %s", font_string); + wxGtkString font_string(pango_font_description_to_string(font_description)); + g_snprintf(buf, sizeof(buf), "WXFONT %s", font_string.c_str()); tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ), buf ); if (!tag) @@ -80,7 +79,6 @@ static void wxGtkTextApplyTagsFromAttr(GtkTextBuffer *text_buffer, "font-desc", font_description, NULL ); gtk_text_buffer_apply_tag (text_buffer, tag, start, end); - g_free (font_string); if (attr.GetFont().GetUnderlined()) { @@ -787,13 +785,11 @@ wxString wxTextCtrl::GetValue() const gtk_text_buffer_get_start_iter( m_buffer, &start ); GtkTextIter end; gtk_text_buffer_get_end_iter( m_buffer, &end ); - gchar *text = gtk_text_buffer_get_text( m_buffer, &start, &end, TRUE ); + wxGtkString text(gtk_text_buffer_get_text(m_buffer, &start, &end, true)); const wxWxCharBuffer buf = wxGTK_CONV_BACK(text); if ( buf ) tmp = buf; - - g_free( text ); } else { @@ -942,22 +938,22 @@ void wxTextCtrl::AppendText( const wxString &text ) wxString wxTextCtrl::GetLineText( long lineNo ) const { + wxString result; if ( IsMultiLine() ) { GtkTextIter line; gtk_text_buffer_get_iter_at_line(m_buffer,&line,lineNo); GtkTextIter end = line; gtk_text_iter_forward_to_line_end(&end); - gchar *text = gtk_text_buffer_get_text(m_buffer,&line,&end,TRUE); - wxString result(wxGTK_CONV_BACK(text)); - g_free(text); - return result; + wxGtkString text(gtk_text_buffer_get_text(m_buffer, &line, &end, true)); + result = wxGTK_CONV_BACK(text); } else { - if (lineNo == 0) return GetValue(); - return wxEmptyString; + if (lineNo == 0) + result = GetValue(); } + return result; } void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) ) -- 2.45.2