[planner: 31/61] cell-renderer-date: Port constraint chooser to GtkComboBoxText




commit 68cf715accbb1fd44bdc9a20ea9781599538d78e
Author: Mart Raudsepp <leio gentoo org>
Date:   Sun Dec 27 01:06:59 2020 +0200

    cell-renderer-date: Port constraint chooser to GtkComboBoxText

 src/planner-cell-renderer-date.c | 97 +++++++++++++---------------------------
 src/planner-cell-renderer-date.h |  2 +-
 2 files changed, 31 insertions(+), 68 deletions(-)
---
diff --git a/src/planner-cell-renderer-date.c b/src/planner-cell-renderer-date.c
index 4048a677..a2657776 100644
--- a/src/planner-cell-renderer-date.c
+++ b/src/planner-cell-renderer-date.c
@@ -56,8 +56,8 @@ static void     mcrd_ok_clicked              (GtkWidget               *popup_win
                                              PlannerCellRendererDate      *cell);
 static void     mcrd_day_selected            (GtkWidget               *popup_window,
                                              PlannerCellRendererDate      *cell);
-static void     mcrd_constraint_activated_cb (GtkWidget               *widget,
-                                             PlannerCellRendererDate      *cell);
+static void     mcrd_constraint_activated_cb (GtkComboBox             *combo,
+                                             PlannerCellRendererDate *cell);
 GtkCellEditable *mcrd_start_editing          (GtkCellRenderer         *cell,
                                              GdkEvent                *event,
                                              GtkWidget               *widget,
@@ -72,10 +72,6 @@ static void     mcrd_show                    (PlannerCellRendererPopup     *cell
                                              gint                     x2,
                                              gint                     y2);
 static void     mcrd_hide                    (PlannerCellRendererPopup     *cell);
-static void     mcrd_setup_option_menu       (GtkWidget               *option_menu,
-                                             GCallback                func,
-                                             gpointer                 user_data,
-                                             gpointer                 str1, ...);
 
 
 static PlannerCellRendererPopupClass *parent_class;
@@ -139,15 +135,18 @@ mcrd_init (PlannerCellRendererDate *date)
        gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (_("Schedule:")),
                            FALSE, FALSE, 0);
 
-       date->option_menu = gtk_option_menu_new ();
-       mcrd_setup_option_menu (date->option_menu,
-                               G_CALLBACK (mcrd_constraint_activated_cb),
-                               date,
-                               _("As soon as possible"), MRP_CONSTRAINT_ASAP,
-                               _("No earlier than"), MRP_CONSTRAINT_SNET,
-                               _("On fixed date"), MRP_CONSTRAINT_MSO,
-                               NULL);
-       gtk_box_pack_end (GTK_BOX (hbox), date->option_menu, TRUE, TRUE, 0);
+       date->combo_box = gtk_combo_box_text_new ();
+       gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (date->combo_box),
+                                       _("As soon as possible"));
+       gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (date->combo_box),
+                                       _("No earlier than"));
+       gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (date->combo_box),
+                                       _("On fixed date"));
+       g_signal_connect (date->combo_box, "changed",
+                         G_CALLBACK (mcrd_constraint_activated_cb),
+                         date);
+
+       gtk_box_pack_end (GTK_BOX (hbox), date->combo_box, TRUE, TRUE, 0);
 
        gtk_box_pack_start (GTK_BOX (date->constraint_vbox), hbox, TRUE, TRUE, 0);
 
@@ -358,8 +357,7 @@ mcrd_show (PlannerCellRendererPopup *cell,
        gtk_calendar_select_day (GTK_CALENDAR (date->calendar), day);
        gtk_calendar_mark_day (GTK_CALENDAR (date->calendar), day);
 
-       gtk_option_menu_set_history (GTK_OPTION_MENU (date->option_menu),
-                                    index);
+       gtk_combo_box_set_active (GTK_COMBO_BOX (date->combo_box), index);
 }
 
 GtkCellRenderer *
@@ -476,15 +474,25 @@ mcrd_grab_on_window (GdkWindow *window,
 }
 
 static void
-mcrd_constraint_activated_cb (GtkWidget               *widget,
+mcrd_constraint_activated_cb (GtkComboBox             *combo,
                              PlannerCellRendererDate *cell)
 {
-       gpointer data;
        gboolean sensitive;
+       gint idx;
 
-       data = g_object_get_data (G_OBJECT (widget), "data");
-
-       cell->type = GPOINTER_TO_INT (data);
+       idx = gtk_combo_box_get_active (combo);
+       switch (idx) {
+       default:
+       case 0:
+               cell->type = MRP_CONSTRAINT_ASAP;
+               break;
+       case 1:
+               cell->type = MRP_CONSTRAINT_SNET;
+               break;
+       case 2:
+               cell->type = MRP_CONSTRAINT_MSO;
+               break;
+       }
 
        sensitive = (!cell->use_constraint ||
                     (cell->type != MRP_CONSTRAINT_ASAP &&
@@ -500,48 +508,3 @@ mcrd_constraint_activated_cb (GtkWidget               *widget,
        mcrd_grab_on_window (PLANNER_CELL_RENDERER_POPUP (cell)->popup_window->window,
                             gtk_get_current_event_time ());
 }
-
-/* Utility function to use before optionmenus work with libglade again.
- */
-
-static void
-mcrd_setup_option_menu (GtkWidget     *option_menu,
-                       GCallback      func,
-                       gpointer       user_data,
-                       gpointer       str1, ...)
-{
-       GtkWidget *menu, *menu_item;
-       gint       i;
-       va_list    args;
-       gpointer   str;
-       gint       type;
-
-               menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option_menu));
-       if (menu) {
-               gtk_widget_destroy (menu);
-       }
-
-       menu = gtk_menu_new ();
-
-       va_start (args, str1);
-       for (str = str1, i = 0; str != NULL; str = va_arg (args, gpointer), i++) {
-               menu_item = gtk_menu_item_new_with_label (str);
-               gtk_widget_show (menu_item);
-               gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
-
-               type = va_arg (args, gint);
-
-               g_object_set_data (G_OBJECT (menu_item),
-                                  "data",
-                                  GINT_TO_POINTER (type));
-               g_signal_connect (G_OBJECT (menu_item),
-                                   "activate",
-                                   func,
-                                   user_data);
-       }
-       va_end (args);
-
-       gtk_widget_show (menu);
-       gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
-}
-
diff --git a/src/planner-cell-renderer-date.h b/src/planner-cell-renderer-date.h
index 17aee48e..2400270c 100644
--- a/src/planner-cell-renderer-date.h
+++ b/src/planner-cell-renderer-date.h
@@ -44,7 +44,7 @@ struct _PlannerCellRendererDate
 {
        PlannerCellRendererPopup  parent;
        GtkWidget                *calendar;
-       GtkWidget                *option_menu;
+       GtkWidget                *combo_box;
        GtkWidget                *today_button;
 
        gboolean                  use_constraint;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]