Sort headers using clang-tidy
[geeqie.git] / src / bar-comment.cc
index d84a15a..28c9a54 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "bar-comment.h"
 
+#include <config.h>
+
 #include "bar.h"
-#include "metadata.h"
+#include "compat.h"
+#include "debug.h"
 #include "filedata.h"
+#include "intl.h"
+#include "layout.h"
+#include "main-defines.h"
+#include "metadata.h"
+#include "rcfile.h"
 #include "ui-menu.h"
 #include "ui-misc.h"
-#include "rcfile.h"
-#include "layout.h"
 
 #ifdef HAVE_SPELL
 #include <gspell/gspell.h>
@@ -44,8 +49,7 @@ static void bar_pane_comment_changed(GtkTextBuffer *buffer, gpointer data);
 
 
 
-typedef struct _PaneCommentData PaneCommentData;
-struct _PaneCommentData
+struct PaneCommentData
 {
        PaneData pane;
        GtkWidget *widget;
@@ -53,6 +57,9 @@ struct _PaneCommentData
        FileData *fd;
        gchar *key;
        gint height;
+#ifdef HAVE_SPELL
+       GspellTextView *gspell_view;
+#endif
 };
 
 
@@ -71,9 +78,9 @@ static void bar_pane_comment_write(PaneCommentData *pcd)
 
 static void bar_pane_comment_update(PaneCommentData *pcd)
 {
-       gchar *comment = NULL;
-       gchar *orig_comment = NULL;
-       gchar *comment_not_null;
+       gchar *comment = nullptr;
+       gchar *orig_comment = nullptr;
+       const gchar *comment_not_null;
        gshort rating;
        GtkTextBuffer *comment_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pcd->comment_view));
 
@@ -98,24 +105,24 @@ static void bar_pane_comment_update(PaneCommentData *pcd)
        g_free(comment);
        g_free(orig_comment);
 
-       gtk_widget_set_sensitive(pcd->comment_view, (pcd->fd != NULL));
+       gtk_widget_set_sensitive(pcd->comment_view, (pcd->fd != nullptr));
 }
 
 static void bar_pane_comment_set_selection(PaneCommentData *pcd, gboolean append)
 {
-       GList *list = NULL;
+       GList *list = nullptr;
        GList *work;
-       gchar *comment = NULL;
+       gchar *comment = nullptr;
 
        comment = text_widget_text_pull(pcd->comment_view);
 
        list = layout_selection_list(pcd->pane.lw);
-       list = file_data_process_groups_in_selection(list, FALSE, NULL);
+       list = file_data_process_groups_in_selection(list, FALSE, nullptr);
 
        work = list;
        while (work)
                {
-               FileData *fd = (FileData *)work->data;
+               auto fd = static_cast<FileData *>(work->data);
                work = work->next;
                if (fd == pcd->fd) continue;
 
@@ -133,16 +140,16 @@ static void bar_pane_comment_set_selection(PaneCommentData *pcd, gboolean append
        g_free(comment);
 }
 
-static void bar_pane_comment_sel_add_cb(GtkWidget *UNUSED(button), gpointer data)
+static void bar_pane_comment_sel_add_cb(GtkWidget *, gpointer data)
 {
-       PaneCommentData *pcd = (PaneCommentData *)data;
+       auto pcd = static_cast<PaneCommentData *>(data);
 
        bar_pane_comment_set_selection(pcd, TRUE);
 }
 
-static void bar_pane_comment_sel_replace_cb(GtkWidget *UNUSED(button), gpointer data)
+static void bar_pane_comment_sel_replace_cb(GtkWidget *, gpointer data)
 {
-       PaneCommentData *pcd = (PaneCommentData *)data;
+       auto pcd = static_cast<PaneCommentData *>(data);
 
        bar_pane_comment_set_selection(pcd, FALSE);
 }
@@ -152,7 +159,7 @@ static void bar_pane_comment_set_fd(GtkWidget *bar, FileData *fd)
 {
        PaneCommentData *pcd;
 
-       pcd = g_object_get_data(G_OBJECT(bar), "pane_data");
+       pcd = static_cast<PaneCommentData *>(g_object_get_data(G_OBJECT(bar), "pane_data"));
        if (!pcd) return;
 
        file_data_unref(pcd->fd);
@@ -165,7 +172,7 @@ static gint bar_pane_comment_event(GtkWidget *bar, GdkEvent *event)
 {
        PaneCommentData *pcd;
 
-       pcd = g_object_get_data(G_OBJECT(bar), "pane_data");
+       pcd = static_cast<PaneCommentData *>(g_object_get_data(G_OBJECT(bar), "pane_data"));
        if (!pcd) return FALSE;
 
        if (gtk_widget_has_focus(pcd->comment_view)) return gtk_widget_event(pcd->comment_view, event);
@@ -176,9 +183,10 @@ static gint bar_pane_comment_event(GtkWidget *bar, GdkEvent *event)
 static void bar_pane_comment_write_config(GtkWidget *pane, GString *outstr, gint indent)
 {
        PaneCommentData *pcd;
-       gint w, h;
+       gint w;
+       gint h;
 
-       pcd = g_object_get_data(G_OBJECT(pane), "pane_data");
+       pcd = static_cast<PaneCommentData *>(g_object_get_data(G_OBJECT(pane), "pane_data"));
        if (!pcd) return;
 
        gtk_widget_get_size_request(GTK_WIDGET(pane), &w, &h);
@@ -211,7 +219,7 @@ static void bar_pane_comment_write_config(GtkWidget *pane, GString *outstr, gint
 
 static void bar_pane_comment_notify_cb(FileData *fd, NotifyType type, gpointer data)
 {
-       PaneCommentData *pcd = (PaneCommentData *)data;
+       auto pcd = static_cast<PaneCommentData *>(data);
        if ((type & (NOTIFY_REREAD | NOTIFY_CHANGE | NOTIFY_METADATA)) && fd == pcd->fd)
                {
                DEBUG_1("Notify pane_comment: %s %04x", fd->path, type);
@@ -220,29 +228,31 @@ static void bar_pane_comment_notify_cb(FileData *fd, NotifyType type, gpointer d
                }
 }
 
-static void bar_pane_comment_changed(GtkTextBuffer *UNUSED(buffer), gpointer data)
+static void bar_pane_comment_changed(GtkTextBuffer *, gpointer data)
 {
-       PaneCommentData *pcd = (PaneCommentData *)data;
+       auto pcd = static_cast<PaneCommentData *>(data);
 
        bar_pane_comment_write(pcd);
 }
 
 
-static void bar_pane_comment_populate_popup(GtkTextView *UNUSED(textview), GtkMenu *menu, gpointer data)
+static void bar_pane_comment_populate_popup(GtkTextView *, GtkMenu *menu, gpointer data)
 {
-       PaneCommentData *pcd = (PaneCommentData *)data;
+       auto pcd = static_cast<PaneCommentData *>(data);
 
        menu_item_add_divider(GTK_WIDGET(menu));
-       menu_item_add_stock(GTK_WIDGET(menu), _("Add text to selected files"), GTK_STOCK_ADD, G_CALLBACK(bar_pane_comment_sel_add_cb), pcd);
-       menu_item_add_stock(GTK_WIDGET(menu), _("Replace existing text in selected files"), GTK_STOCK_CONVERT, G_CALLBACK(bar_pane_comment_sel_replace_cb), data);
+       menu_item_add_icon(GTK_WIDGET(menu), _("Add text to selected files"), GQ_ICON_ADD, G_CALLBACK(bar_pane_comment_sel_add_cb), pcd);
+       menu_item_add_icon(GTK_WIDGET(menu), _("Replace existing text in selected files"), GQ_ICON_REPLACE, G_CALLBACK(bar_pane_comment_sel_replace_cb), data);
 }
 
-static void bar_pane_comment_destroy(GtkWidget *UNUSED(widget), gpointer data)
+static void bar_pane_comment_destroy(GtkWidget *, gpointer data)
 {
-       PaneCommentData *pcd = (PaneCommentData *)data;
+       auto pcd = static_cast<PaneCommentData *>(data);
 
        file_data_unregister_notify_func(bar_pane_comment_notify_cb, pcd);
-
+#ifdef HAVE_SPELL
+       g_object_unref(pcd->gspell_view);
+#endif
        file_data_unref(pcd->fd);
        g_free(pcd->key);
 
@@ -257,9 +267,6 @@ static GtkWidget *bar_pane_comment_new(const gchar *id, const gchar *title, cons
        PaneCommentData *pcd;
        GtkWidget *scrolled;
        GtkTextBuffer *buffer;
-#ifdef HAVE_SPELL
-       GspellTextView *gspell_view;
-#endif
 
        pcd = g_new0(PaneCommentData, 1);
 
@@ -269,20 +276,22 @@ static GtkWidget *bar_pane_comment_new(const gchar *id, const gchar *title, cons
        pcd->pane.title = bar_pane_expander_title(title);
        pcd->pane.id = g_strdup(id);
        pcd->pane.type = PANE_COMMENT;
-
+#ifdef HAVE_SPELL
+       pcd->gspell_view = nullptr;
+#endif
        pcd->pane.expanded = expanded;
 
        pcd->key = g_strdup(key);
        pcd->height = height;
 
-       scrolled = gtk_scrolled_window_new(NULL, NULL);
+       scrolled = gq_gtk_scrolled_window_new(nullptr, nullptr);
 
        pcd->widget = scrolled;
        g_object_set_data(G_OBJECT(pcd->widget), "pane_data", pcd);
        g_signal_connect(G_OBJECT(pcd->widget), "destroy",
                         G_CALLBACK(bar_pane_comment_destroy), pcd);
 
-       gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
+       gq_gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
                                       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 
@@ -291,7 +300,7 @@ static GtkWidget *bar_pane_comment_new(const gchar *id, const gchar *title, cons
 
        pcd->comment_view = gtk_text_view_new();
        gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(pcd->comment_view), GTK_WRAP_WORD);
-       gtk_container_add(GTK_CONTAINER(scrolled), pcd->comment_view);
+       gq_gtk_container_add(GTK_WIDGET(scrolled), pcd->comment_view);
        g_signal_connect(G_OBJECT(pcd->comment_view), "populate-popup",
                         G_CALLBACK(bar_pane_comment_populate_popup), pcd);
        gtk_widget_show(pcd->comment_view);
@@ -301,8 +310,8 @@ static GtkWidget *bar_pane_comment_new(const gchar *id, const gchar *title, cons
                {
                if (options->metadata.check_spelling)
                        {
-                       gspell_view = gspell_text_view_get_from_gtk_text_view(GTK_TEXT_VIEW(pcd->comment_view));
-                       gspell_text_view_basic_setup(gspell_view);
+                       pcd->gspell_view = gspell_text_view_get_from_gtk_text_view(GTK_TEXT_VIEW(pcd->comment_view));
+                       gspell_text_view_basic_setup(pcd->gspell_view);
                        }
        }
 #endif
@@ -319,7 +328,7 @@ static GtkWidget *bar_pane_comment_new(const gchar *id, const gchar *title, cons
 
 GtkWidget *bar_pane_comment_new_from_config(const gchar **attribute_names, const gchar **attribute_values)
 {
-       gchar *title = NULL;
+       gchar *title = nullptr;
        gchar *key = g_strdup(COMMENT_KEY);
        gboolean expanded = TRUE;
        gint height = 50;
@@ -370,10 +379,10 @@ void bar_pane_comment_update_from_config(GtkWidget *pane, const gchar **attribut
 {
        PaneCommentData *pcd;
 
-       pcd = g_object_get_data(G_OBJECT(pane), "pane_data");
+       pcd = static_cast<PaneCommentData *>(g_object_get_data(G_OBJECT(pane), "pane_data"));
        if (!pcd) return;
 
-       gchar *title = NULL;
+       gchar *title = nullptr;
 
        while (*attribute_names)
                {