Fix build with LTO
[geeqie.git] / src / layout-config.cc
index 46da2f3..ab98a54 100644 (file)
 #include "intl.h"
 #include "ui-misc.h"
 
+namespace
+{
 
 enum {
        COLUMN_TEXT = 0,
        COLUMN_KEY
 };
 
-
 struct LayoutStyle
 {
        LayoutLocation a, b, c;
@@ -55,8 +56,10 @@ struct LayoutConfig
        gint a, b, c;
 };
 
+constexpr gint LAYOUT_STYLE_SIZE = 48;
 
-static LayoutStyle layout_config_styles[] = {
+// @todo Use std::array
+constexpr LayoutStyle layout_config_styles[] = {
        /* 1, 2, 3 */
        { static_cast<LayoutLocation>(LAYOUT_LEFT | LAYOUT_TOP), static_cast<LayoutLocation>(LAYOUT_LEFT | LAYOUT_BOTTOM), LAYOUT_RIGHT },
        { static_cast<LayoutLocation>(LAYOUT_LEFT | LAYOUT_TOP), static_cast<LayoutLocation>(LAYOUT_RIGHT | LAYOUT_TOP), LAYOUT_BOTTOM },
@@ -64,12 +67,12 @@ static LayoutStyle layout_config_styles[] = {
        { LAYOUT_TOP, static_cast<LayoutLocation>(LAYOUT_LEFT | LAYOUT_BOTTOM), static_cast<LayoutLocation>(LAYOUT_RIGHT | LAYOUT_BOTTOM) }
 };
 
-static gint layout_config_style_count = sizeof(layout_config_styles) / sizeof(LayoutStyle);
+constexpr gint layout_config_style_count = sizeof(layout_config_styles) / sizeof(LayoutStyle);
 
-static const gchar *layout_titles[] = { N_("Tools"), N_("Files"), N_("Image") };
+const gchar *layout_titles[] = { N_("Tools"), N_("Files"), N_("Image") };
 
 
-static void layout_config_destroy(GtkWidget *, gpointer data)
+void layout_config_destroy(GtkWidget *, gpointer data)
 {
        auto lc = static_cast<LayoutConfig *>(data);
 
@@ -77,7 +80,7 @@ static void layout_config_destroy(GtkWidget *, gpointer data)
        g_free(lc);
 }
 
-static void layout_config_set_order(LayoutLocation l, gint n,
+void layout_config_set_order(LayoutLocation l, gint n,
                                    LayoutLocation *a, LayoutLocation *b, LayoutLocation *c)
 {
        switch (n)
@@ -94,7 +97,7 @@ static void layout_config_set_order(LayoutLocation l, gint n,
                }
 }
 
-static void layout_config_from_data(gint style, gint oa, gint ob, gint oc,
+void layout_config_from_data(gint style, gint oa, gint ob, gint oc,
                                    LayoutLocation *la, LayoutLocation *lb, LayoutLocation *lc)
 {
        LayoutStyle ls;
@@ -108,18 +111,7 @@ static void layout_config_from_data(gint style, gint oa, gint ob, gint oc,
        layout_config_set_order(ls.c, oc, la, lb, lc);
 }
 
-void layout_config_parse(gint style, const gchar *order,
-                        LayoutLocation *a, LayoutLocation *b, LayoutLocation *c)
-{
-       gint na;
-       gint nb;
-       gint nc;
-
-       layout_config_order_from_text(order, &na, &nb, &nc);
-       layout_config_from_data(style, na, nb, nc, a, b, c);
-}
-
-static void layout_config_list_order_set(LayoutConfig *lc, gint src, gint dest)
+void layout_config_list_order_set(LayoutConfig *lc, gint src, gint dest)
 {
        GtkListStore *store;
        GtkTreeIter iter;
@@ -142,7 +134,7 @@ static void layout_config_list_order_set(LayoutConfig *lc, gint src, gint dest)
                }
 }
 
-static gint layout_config_list_order_get(LayoutConfig *lc, gint n)
+gint layout_config_list_order_get(LayoutConfig *lc, gint n)
 {
        GtkTreeModel *store;
        GtkTreeIter iter;
@@ -166,50 +158,7 @@ static gint layout_config_list_order_get(LayoutConfig *lc, gint n)
        return 0;
 }
 
-void layout_config_set(GtkWidget *widget, gint style, const gchar *order)
-{
-       LayoutConfig *lc;
-       GtkWidget *button;
-       gint a;
-       gint b;
-       gint c;
-
-       lc = static_cast<LayoutConfig *>(g_object_get_data(G_OBJECT(widget), "layout_config"));
-
-       if (!lc) return;
-
-       style = CLAMP(style, 0, layout_config_style_count);
-       button = static_cast<GtkWidget *>(g_list_nth_data(lc->style_widgets, style));
-       if (!button) return;
-
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
-
-       layout_config_order_from_text(order, &a, &b, &c);
-
-       layout_config_list_order_set(lc, a, 0);
-       layout_config_list_order_set(lc, b, 1);
-       layout_config_list_order_set(lc, c, 2);
-}
-
-gchar *layout_config_get(GtkWidget *widget, gint *style)
-{
-       LayoutConfig *lc;
-
-       lc = static_cast<LayoutConfig *>(g_object_get_data(G_OBJECT(widget), "layout_config"));
-
-       /* this should not happen */
-       if (!lc) return nullptr;
-
-       *style = lc->style;
-
-       lc->a = layout_config_list_order_get(lc, 0);
-       lc->b = layout_config_list_order_get(lc, 1);
-       lc->c = layout_config_list_order_get(lc, 2);
-
-       return layout_config_order_to_text(lc->a, lc->b, lc->c);
-}
-
-static void layout_config_widget_click_cb(GtkWidget *widget, gpointer data)
+void layout_config_widget_click_cb(GtkWidget *widget, gpointer data)
 {
        LayoutConfig *lc;
 
@@ -218,7 +167,7 @@ static void layout_config_widget_click_cb(GtkWidget *widget, gpointer data)
        if (lc) lc->style = GPOINTER_TO_INT(data);
 }
 
-static void layout_config_table_button(GtkWidget *table, LayoutLocation l, const gchar *text)
+void layout_config_table_button(GtkWidget *table, LayoutLocation l, const gchar *text)
 {
        GtkWidget *button;
 
@@ -244,11 +193,7 @@ static void layout_config_table_button(GtkWidget *table, LayoutLocation l, const
        gtk_widget_show(button);
 }
 
-enum {
-       LAYOUT_STYLE_SIZE = 48
-};
-
-static GtkWidget *layout_config_widget(GtkWidget *group, GtkWidget *box, gint style, LayoutConfig *lc)
+GtkWidget *layout_config_widget(GtkWidget *group, GtkWidget *box, gint style, LayoutConfig *lc)
 {
        GtkWidget *table;
        LayoutStyle ls;
@@ -274,7 +219,7 @@ static GtkWidget *layout_config_widget(GtkWidget *group, GtkWidget *box, gint st
                }
        g_object_set_data(G_OBJECT(group), "layout_config", lc);
        g_signal_connect(G_OBJECT(group), "clicked",
-                        G_CALLBACK(layout_config_widget_click_cb), GINT_TO_POINTER(style));
+                        G_CALLBACK(layout_config_widget_click_cb), GINT_TO_POINTER(style));
        gq_gtk_box_pack_start(GTK_BOX(box), group, FALSE, FALSE, 0);
 
        table = gtk_grid_new();
@@ -292,8 +237,8 @@ static GtkWidget *layout_config_widget(GtkWidget *group, GtkWidget *box, gint st
        return group;
 }
 
-static void layout_config_number_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
-                                   GtkTreeModel *store, GtkTreeIter *iter, gpointer)
+void layout_config_number_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
+                    GtkTreeModel *store, GtkTreeIter *iter, gpointer)
 {
        GtkTreePath *tpath;
        gint *indices;
@@ -307,6 +252,112 @@ static void layout_config_number_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
        g_free(buf);
 }
 
+gchar num_to_text_char(gint n)
+{
+       switch (n)
+               {
+               case 1:
+                       return '2';
+                       break;
+               case 2:
+                       return '3';
+                       break;
+               }
+       return '1';
+}
+
+gchar *layout_config_order_to_text(gint a, gint b, gint c)
+{
+       gchar *text;
+
+       text = g_strdup("   ");
+
+       text[0] = num_to_text_char(a);
+       text[1] = num_to_text_char(b);
+       text[2] = num_to_text_char(c);
+
+       return text;
+}
+
+gint text_char_to_num(const gchar *text, gint n)
+{
+       if (text[n] == '3') return 2;
+       if (text[n] == '2') return 1;
+       return 0;
+}
+
+void layout_config_order_from_text(const gchar *text, gint *a, gint *b, gint *c)
+{
+       if (!text || strlen(text) < 3)
+               {
+               *a = 0;
+               *b = 1;
+               *c = 2;
+               }
+       else
+               {
+               *a = text_char_to_num(text, 0);
+               *b = text_char_to_num(text, 1);
+               *c = text_char_to_num(text, 2);
+               }
+}
+
+} // namespace
+
+void layout_config_parse(gint style, const gchar *order,
+                        LayoutLocation *a, LayoutLocation *b, LayoutLocation *c)
+{
+       gint na;
+       gint nb;
+       gint nc;
+
+       layout_config_order_from_text(order, &na, &nb, &nc);
+       layout_config_from_data(style, na, nb, nc, a, b, c);
+}
+
+void layout_config_set(GtkWidget *widget, gint style, const gchar *order)
+{
+       LayoutConfig *lc;
+       GtkWidget *button;
+       gint a;
+       gint b;
+       gint c;
+
+       lc = static_cast<LayoutConfig *>(g_object_get_data(G_OBJECT(widget), "layout_config"));
+
+       if (!lc) return;
+
+       style = CLAMP(style, 0, layout_config_style_count);
+       button = static_cast<GtkWidget *>(g_list_nth_data(lc->style_widgets, style));
+       if (!button) return;
+
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
+
+       layout_config_order_from_text(order, &a, &b, &c);
+
+       layout_config_list_order_set(lc, a, 0);
+       layout_config_list_order_set(lc, b, 1);
+       layout_config_list_order_set(lc, c, 2);
+}
+
+gchar *layout_config_get(GtkWidget *widget, gint *style)
+{
+       LayoutConfig *lc;
+
+       lc = static_cast<LayoutConfig *>(g_object_get_data(G_OBJECT(widget), "layout_config"));
+
+       /* this should not happen */
+       if (!lc) return nullptr;
+
+       *style = lc->style;
+
+       lc->a = layout_config_list_order_get(lc, 0);
+       lc->b = layout_config_list_order_get(lc, 1);
+       lc->c = layout_config_list_order_get(lc, 2);
+
+       return layout_config_order_to_text(lc->a, lc->b, lc->c);
+}
+
 GtkWidget *layout_config_new()
 {
        LayoutConfig *lc;
@@ -378,54 +429,4 @@ GtkWidget *layout_config_new()
 
        return lc->box;
 }
-
-static gchar num_to_text_char(gint n)
-{
-       switch (n)
-               {
-               case 1:
-                       return '2';
-                       break;
-               case 2:
-                       return '3';
-                       break;
-               }
-       return '1';
-}
-
-gchar *layout_config_order_to_text(gint a, gint b, gint c)
-{
-       gchar *text;
-
-       text = g_strdup("   ");
-
-       text[0] = num_to_text_char(a);
-       text[1] = num_to_text_char(b);
-       text[2] = num_to_text_char(c);
-
-       return text;
-}
-
-static gint text_char_to_num(const gchar *text, gint n)
-{
-       if (text[n] == '3') return 2;
-       if (text[n] == '2') return 1;
-       return 0;
-}
-
-void layout_config_order_from_text(const gchar *text, gint *a, gint *b, gint *c)
-{
-       if (!text || strlen(text) < 3)
-               {
-               *a = 0;
-               *b = 1;
-               *c = 2;
-               }
-       else
-               {
-               *a = text_char_to_num(text, 0);
-               *b = text_char_to_num(text, 1);
-               *c = text_char_to_num(text, 2);
-               }
-}
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */