[gnome-flashback/wip/segeiger/gnome-3-18-inputmethods] Area: Extend GtkBox instead of GObject



commit b01844324810736586633faeca2dee9ac00aeebc
Author: Sebastian Geiger <sbastig gmx net>
Date:   Wed Jan 13 15:25:07 2016 +0100

    Area: Extend GtkBox instead of GObject

 .../libinput-sources/gf-candidate-area.c           |   25 ++++--------
 .../libinput-sources/gf-candidate-area.h           |   28 +++++++-------
 .../libinput-sources/gf-candidate-popup.c          |   40 ++++++++-----------
 3 files changed, 40 insertions(+), 53 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/gf-candidate-area.c 
b/gnome-flashback/libinput-sources/gf-candidate-area.c
index 8e53b24..5833e8a 100644
--- a/gnome-flashback/libinput-sources/gf-candidate-area.c
+++ b/gnome-flashback/libinput-sources/gf-candidate-area.c
@@ -24,9 +24,8 @@ const char* DEFAULT_INDEX_LABELS[] = { "1", "2", "3", "4", "5", "6", "7", "8",
 
 struct _GfCandidateArea
 {
-  GObject parent;
+  GtkBox            parent;
 
-  GtkWidget        *box_layout;
   GtkWidget        *button_box;
   GtkWidget        *prev_button;
   GtkWidget        *next_button;
@@ -48,7 +47,7 @@ enum
 
 static guint signals[SIGNAL_LAST] = { 0 };
 
-G_DEFINE_TYPE (GfCandidateArea, gf_candidate_area, G_TYPE_OBJECT)
+G_DEFINE_TYPE (GfCandidateArea, gf_candidate_area, GTK_TYPE_BOX)
 
 static gboolean
 button_clicked_cb (GtkWidget *widget,
@@ -194,12 +193,6 @@ gf_candidate_area_update_buttons (GfCandidateArea *area,
                             wraps_around || page < n_pages - 1);
 }
 
-GtkWidget *
-gf_candidate_area_get_box_layout (GfCandidateArea *area)
-{
-  return area->box_layout;
-}
-
 static void
 gf_candidate_area_class_init (GfCandidateAreaClass *area_class)
 {
@@ -223,8 +216,6 @@ gf_candidate_area_init (GfCandidateArea *area)
   GtkStyleContext *context;
   int i;
 
-  area->box_layout = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-
   for (i = 0; i < MAX_CANDIDATES_PER_PAGE; i++)
     {
       GtkWidget *box,
@@ -234,7 +225,7 @@ gf_candidate_area_init (GfCandidateArea *area)
       box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
       context = gtk_widget_get_style_context (box);
       gtk_style_context_add_class (context, "candidate-box");
-      gtk_container_add (GTK_CONTAINER (area->box_layout), box);
+      gtk_container_add (GTK_CONTAINER (area), box);
 
       index_label = gtk_label_new ("");
       context = gtk_widget_get_style_context (index_label);
@@ -259,7 +250,7 @@ gf_candidate_area_init (GfCandidateArea *area)
   context = gtk_widget_get_style_context (area->button_box);
   gtk_style_context_add_class (context, "candidate-page-button-box");
 
-  gtk_container_add (GTK_CONTAINER (area->box_layout), area->button_box);
+  gtk_container_add (GTK_CONTAINER (area), area->button_box);
 
   area->prev_button = gtk_button_new_with_label ("Prev");
   context = gtk_widget_get_style_context (area->prev_button);
@@ -272,7 +263,7 @@ gf_candidate_area_init (GfCandidateArea *area)
   gtk_container_add (GTK_CONTAINER (area->button_box), area->prev_button);
   gtk_container_add (GTK_CONTAINER (area->button_box), area->next_button);
 
-  gtk_widget_show_all (area->box_layout);
+  gtk_widget_show_all (GTK_WIDGET (area));
 
   g_signal_connect (area->prev_button, "clicked",
                     G_CALLBACK (prev_button_clicked_cb), area);
@@ -283,8 +274,10 @@ gf_candidate_area_init (GfCandidateArea *area)
   area->cursor_position = 0;
 }
 
-GfCandidateArea*
+GtkWidget*
 gf_candidate_area_new (void)
 {
-    return g_object_new (GF_TYPE_CANDIDATE_AREA, NULL);
+    return g_object_new (GF_TYPE_CANDIDATE_AREA,
+                         "orientation", GTK_ORIENTATION_VERTICAL,
+                         NULL);
 }
diff --git a/gnome-flashback/libinput-sources/gf-candidate-area.h 
b/gnome-flashback/libinput-sources/gf-candidate-area.h
index 0c862ae..f8d57e2 100644
--- a/gnome-flashback/libinput-sources/gf-candidate-area.h
+++ b/gnome-flashback/libinput-sources/gf-candidate-area.h
@@ -26,25 +26,25 @@ G_BEGIN_DECLS
 
 #define GF_TYPE_CANDIDATE_AREA gf_candidate_area_get_type ()
 G_DECLARE_FINAL_TYPE (GfCandidateArea, gf_candidate_area,
-                      GF, CANDIDATE_AREA, GObject)
+                      GF, CANDIDATE_AREA, GtkBox)
 
-GfCandidateArea *gf_candidate_area_new             (void);
+GtkWidget* gf_candidate_area_new             (void);
 
-void             gf_candidate_area_set_orientation (GfCandidateArea *area,
-                                                    IBusOrientation  orientation);
+void       gf_candidate_area_set_orientation (GfCandidateArea *area,
+                                              IBusOrientation  orientation);
 
-void             gf_candidate_area_set_candidates  (GfCandidateArea *area,
-                                                    GList           *indexes,
-                                                    GList           *candidates,
-                                                    int              cursor_position,
-                                                    gboolean         cursor_visible);
+void       gf_candidate_area_set_candidates  (GfCandidateArea *area,
+                                              GList           *indexes,
+                                              GList           *candidates,
+                                              int              cursor_position,
+                                              gboolean         cursor_visible);
 
-void             gf_candidate_area_update_buttons  (GfCandidateArea *area,
-                                                    gboolean wraps_around,
-                                                    gint page,
-                                                    gint n_pages);
+void       gf_candidate_area_update_buttons  (GfCandidateArea *area,
+                                              gboolean wraps_around,
+                                              gint page,
+                                              gint n_pages);
 
-GtkWidget       *gf_candidate_area_get_box_layout  (GfCandidateArea *area);
+GtkWidget* gf_candidate_area_get_box_layout  (GfCandidateArea *area);
 
 G_END_DECLS
 
diff --git a/gnome-flashback/libinput-sources/gf-candidate-popup.c 
b/gnome-flashback/libinput-sources/gf-candidate-popup.c
index 48cb7a6..7673990 100644
--- a/gnome-flashback/libinput-sources/gf-candidate-popup.c
+++ b/gnome-flashback/libinput-sources/gf-candidate-popup.c
@@ -31,17 +31,13 @@ struct _GfCandidatePopup
 
   IBusPanelService *service;
 
-  GfCandidateArea  *candidateArea;
   GtkWidget        *window;
 
-  GtkWidget        *pre_edit_text;
-  GtkWidget        *aux_text;
-
   GtkWidget        *box_layout;
 
-  gboolean          pre_edit_text_visible;
-  gboolean          aux_text_visible;
-  gboolean          candidate_area_visible;
+  GtkWidget        *pre_edit_text;
+  GtkWidget        *aux_text;
+  GtkWidget        *candidate_area;
 };
 
 G_DEFINE_TYPE (GfCandidatePopup, gf_candidate_popup, G_TYPE_OBJECT)
@@ -49,9 +45,9 @@ G_DEFINE_TYPE (GfCandidatePopup, gf_candidate_popup, G_TYPE_OBJECT)
 static void
 update_visibility (GfCandidatePopup *popup)
 {
-  gboolean visible = popup->pre_edit_text_visible ||
-                     popup->aux_text_visible ||
-                     popup->candidate_area_visible;
+  gboolean visible = gtk_widget_is_visible (popup->pre_edit_text) ||
+                     gtk_widget_is_visible (popup->aux_text) ||
+                     gtk_widget_is_visible (popup->candidate_area);
 
   if (visible)
     {
@@ -97,12 +93,12 @@ set_cursor_location_cb (IBusPanelService *service,
 
   if (x + width > rectangle.width)
     {
-      x = x - height - h;
+      x = x - width - w;
     }
 
   if (y + height > rectangle.height)
     {
-      y = y - width - h;
+      y = y - height - h;
     }
 
   gtk_window_move (GTK_WINDOW (popup->window), x, y);
@@ -251,7 +247,9 @@ update_lookup_table_cb (IBusPanelService *service,
       candidates = g_list_append (candidates, text);
     }
 
-  gf_candidate_area_set_candidates (popup->candidateArea, indexes, candidates, cursor_position, visible);
+  gf_candidate_area_set_candidates (GF_CANDIDATE_AREA (popup->candidate_area),
+                                    indexes, candidates, cursor_position,
+                                    visible);
 
   //TODO: free the stuff
 }
@@ -358,9 +356,7 @@ gf_candidate_popup_class_init (GfCandidatePopupClass *popup_class)
 static void
 gf_candidate_popup_init (GfCandidatePopup *popup)
 {
-  GtkWidget *candidate_area_widget;
-
-  popup->candidateArea = gf_candidate_area_new();
+  popup->candidate_area = gf_candidate_area_new();
 
   popup->box_layout = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 
@@ -375,19 +371,17 @@ gf_candidate_popup_init (GfCandidatePopup *popup)
   gtk_container_add (GTK_CONTAINER (popup->box_layout), popup->pre_edit_text);
   gtk_container_add (GTK_CONTAINER (popup->box_layout), popup->aux_text);
 
-  candidate_area_widget = gf_candidate_area_get_box_layout (popup->candidateArea);
-
   gtk_container_add (GTK_CONTAINER (popup->box_layout),
-                     candidate_area_widget);
+                     popup->candidate_area);
 
   gtk_widget_show (popup->box_layout);
-  gtk_widget_show (candidate_area_widget);
+  gtk_widget_show (popup->candidate_area);
 
-  g_signal_connect (popup->candidateArea, "previous-page",
+  g_signal_connect (popup->candidate_area, "previous-page",
                     G_CALLBACK (area_page_prev_cb), popup);
-  g_signal_connect (popup->candidateArea, "next-page",
+  g_signal_connect (popup->candidate_area, "next-page",
                     G_CALLBACK (area_page_next_cb), popup);
-  g_signal_connect (popup->candidateArea, "candidate-clicked",
+  g_signal_connect (popup->candidate_area, "candidate-clicked",
                     G_CALLBACK (area_candidate_clicked_cb), popup);
 }
 


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