[gtk] examples: Take advantage of user_data passed



commit 8fcc401e05b9db074fbdf2cc83c497aae1df477b
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date:   Tue May 8 18:17:54 2018 +0530

    examples: Take advantage of user_data passed
    
    The last parameter of the signal callback from .ui
    is the template's object from which the class is
    derived.
    
    And so, we already have access to the window object.
    Let's just use it.

 examples/application10/exampleappwin.c | 14 +++++---------
 examples/application7/exampleappwin.c  | 15 +++++----------
 examples/application8/exampleappwin.c  | 15 +++++----------
 examples/application9/exampleappwin.c  | 14 +++++---------
 4 files changed, 20 insertions(+), 38 deletions(-)
---
diff --git a/examples/application10/exampleappwin.c b/examples/application10/exampleappwin.c
index d5d9be19d6..1e8eaf7327 100644
--- a/examples/application10/exampleappwin.c
+++ b/examples/application10/exampleappwin.c
@@ -22,9 +22,9 @@ struct _ExampleAppWindow
 G_DEFINE_TYPE (ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW)
 
 static void
-search_text_changed (GtkEntry *entry)
+search_text_changed (GtkEntry         *entry,
+                     ExampleAppWindow *win)
 {
-  ExampleAppWindow *win;
   const gchar *text;
   GtkWidget *tab;
   GtkWidget *view;
@@ -36,8 +36,6 @@ search_text_changed (GtkEntry *entry)
   if (text[0] == '\0')
     return;
 
-  win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (entry)));
-
   tab = gtk_stack_get_visible_child (GTK_STACK (win->stack));
   view = gtk_bin_get_child (GTK_BIN (tab));
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@@ -153,15 +151,13 @@ update_lines (ExampleAppWindow *win)
 }
 
 static void
-visible_child_changed (GObject    *stack,
-                       GParamSpec *pspec)
+visible_child_changed (GObject          *stack,
+                       GParamSpec       *pspec,
+                       ExampleAppWindow *win)
 {
-  ExampleAppWindow *win;
-
   if (gtk_widget_in_destruction (GTK_WIDGET (stack)))
     return;
 
-  win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (stack)));
   gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (win->searchbar), FALSE);
   update_words (win);
   update_lines (win);
diff --git a/examples/application7/exampleappwin.c b/examples/application7/exampleappwin.c
index f7f7d15d88..38ec027128 100644
--- a/examples/application7/exampleappwin.c
+++ b/examples/application7/exampleappwin.c
@@ -16,9 +16,9 @@ struct _ExampleAppWindow
 G_DEFINE_TYPE (ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW)
 
 static void
-search_text_changed (GtkEntry *entry)
+search_text_changed (GtkEntry         *entry,
+                     ExampleAppWindow *win)
 {
-  ExampleAppWindow *win;
   const gchar *text;
   GtkWidget *tab;
   GtkWidget *view;
@@ -30,8 +30,6 @@ search_text_changed (GtkEntry *entry)
   if (text[0] == '\0')
     return;
 
-  win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (entry)));
-
   tab = gtk_stack_get_visible_child (GTK_STACK (win->stack));
   view = gtk_bin_get_child (GTK_BIN (tab));
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@@ -48,16 +46,13 @@ search_text_changed (GtkEntry *entry)
 }
 
 static void
-visible_child_changed (GObject    *stack,
-                       GParamSpec *pspec)
+visible_child_changed (GObject          *stack,
+                       GParamSpec       *pspec,
+                       ExampleAppWindow *win)
 {
-  ExampleAppWindow *win;
-
   if (gtk_widget_in_destruction (GTK_WIDGET (stack)))
     return;
 
-  win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (stack)));
-
   gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (win->searchbar), FALSE);
 }
 
diff --git a/examples/application8/exampleappwin.c b/examples/application8/exampleappwin.c
index d299f341fe..41d4df657b 100644
--- a/examples/application8/exampleappwin.c
+++ b/examples/application8/exampleappwin.c
@@ -20,9 +20,9 @@ struct _ExampleAppWindow
 G_DEFINE_TYPE (ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW)
 
 static void
-search_text_changed (GtkEntry *entry)
+search_text_changed (GtkEntry         *entry,
+                     ExampleAppWindow *win)
 {
-  ExampleAppWindow *win;
   const gchar *text;
   GtkWidget *tab;
   GtkWidget *view;
@@ -34,8 +34,6 @@ search_text_changed (GtkEntry *entry)
   if (text[0] == '\0')
     return;
 
-  win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (entry)));
-
   tab = gtk_stack_get_visible_child (GTK_STACK (win->stack));
   view = gtk_bin_get_child (GTK_BIN (tab));
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@@ -119,16 +117,13 @@ done:
 }
 
 static void
-visible_child_changed (GObject    *stack,
-                       GParamSpec *pspec)
+visible_child_changed (GObject          *stack,
+                       GParamSpec       *pspec,
+                       ExampleAppWindow *win)
 {
-  ExampleAppWindow *win;
-
   if (gtk_widget_in_destruction (GTK_WIDGET (stack)))
     return;
 
-  win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (stack)));
-
   gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (win->searchbar), FALSE);
   update_words (win);
 }
diff --git a/examples/application9/exampleappwin.c b/examples/application9/exampleappwin.c
index 8911fa52f9..7d19b980e2 100644
--- a/examples/application9/exampleappwin.c
+++ b/examples/application9/exampleappwin.c
@@ -22,9 +22,9 @@ struct _ExampleAppWindow
 G_DEFINE_TYPE (ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW)
 
 static void
-search_text_changed (GtkEntry *entry)
+search_text_changed (GtkEntry         *entry,
+                     ExampleAppWindow *win)
 {
-  ExampleAppWindow *win;
   const gchar *text;
   GtkWidget *tab;
   GtkWidget *view;
@@ -36,8 +36,6 @@ search_text_changed (GtkEntry *entry)
   if (text[0] == '\0')
     return;
 
-  win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (entry)));
-
   tab = gtk_stack_get_visible_child (GTK_STACK (win->stack));
   view = gtk_bin_get_child (GTK_BIN (tab));
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@@ -153,15 +151,13 @@ update_lines (ExampleAppWindow *win)
 }
 
 static void
-visible_child_changed (GObject    *stack,
-                       GParamSpec *pspec)
+visible_child_changed (GObject          *stack,
+                       GParamSpec       *pspec,
+                       ExampleAppWindow *win)
 {
-  ExampleAppWindow *win;
-
   if (gtk_widget_in_destruction (GTK_WIDGET (stack)))
     return;
 
-  win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (stack)));
   gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (win->searchbar), FALSE);
   update_words (win);
   update_lines (win);


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