[gtk+/refactor: 2/7] Create a private header to access some GtkButton variables



commit dec57f8ce963f459adb21a33bb766c8864a68ea9
Author: Javier Jardón <jjardon gnome org>
Date:   Tue Oct 19 02:01:31 2010 +0200

    Create a private header to access some GtkButton variables

 gtk/Makefile.am        |    1 +
 gtk/gtkbutton.c        |   37 +++----------------------------
 gtk/gtkbuttonprivate.h |   55 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcheckbutton.c   |    5 ++-
 gtk/gtkradiobutton.c   |   19 +++++++++-------
 gtk/gtktogglebutton.c  |   25 ++++++++++++---------
 6 files changed, 88 insertions(+), 54 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 36c02ce..dae90cd 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -351,6 +351,7 @@ gtk_semi_private_h_sources =    \
 
 # GTK+ header files that don't get installed
 gtk_private_h_sources =		\
+	gtkbuttonprivate.h	\
 	gtkquery.h		\
 	gtksearchengine.h	\
 	gtksearchenginesimple.h	\
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index c341ccb..8fd97ad 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -39,9 +39,12 @@
  */
 
 #include "config.h"
+
+#include "gtkbutton.h"
+#include "gtkbuttonprivate.h"
+
 #include <string.h>
 #include "gtkalignment.h"
-#include "gtkbutton.h"
 #include "gtklabel.h"
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
@@ -56,38 +59,6 @@
 #include "gtkintl.h"
 
 
-struct _GtkButtonPrivate
-{
-  GtkAction             *action;
-  GtkPositionType        image_position;
-  GtkWidget             *image;
-
-  GdkDevice             *grab_keyboard;
-  GdkWindow             *event_window;
-
-  gchar         *label_text;
-
-  gfloat         xalign;
-  gfloat         yalign;
-
-  guint          activate_timeout;
-  guint32        grab_time;
-
-  guint          align_set             : 1;
-  guint          button_down           : 1;
-  guint          constructed           : 1;
-  guint          depressed             : 1;
-  guint          depress_on_activate   : 1;
-  guint          focus_on_click        : 1;
-  guint          image_is_stock        : 1;
-  guint          in_button             : 1;
-  guint          relief                : 2;
-  guint          use_action_appearance : 1;
-  guint          use_stock             : 1;
-  guint          use_underline         : 1;
-};
-
-
 static const GtkBorder default_default_border = { 1, 1, 1, 1 };
 static const GtkBorder default_default_outside_border = { 0, 0, 0, 0 };
 static const GtkBorder default_inner_border = { 1, 1, 1, 1 };
diff --git a/gtk/gtkbuttonprivate.h b/gtk/gtkbuttonprivate.h
new file mode 100644
index 0000000..b6007cd
--- /dev/null
+++ b/gtk/gtkbuttonprivate.h
@@ -0,0 +1,55 @@
+/* GTK - The GIMP Toolkit
+ *
+ * Copyright (C) 2010 Javier Jardón
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_BUTTON_PRIVATE_H__
+#define __GTK_BUTTON_PRIVATE_H__
+
+#include "gtkaction.h"
+
+struct _GtkButtonPrivate
+{
+  GtkAction             *action;
+  GtkPositionType        image_position;
+  GtkWidget             *image;
+
+  GdkDevice             *grab_keyboard;
+  GdkWindow             *event_window;
+
+  gchar         *label_text;
+
+  gfloat         xalign;
+  gfloat         yalign;
+
+  guint          activate_timeout;
+  guint32        grab_time;
+
+  guint          align_set             : 1;
+  guint          button_down           : 1;
+  guint          constructed           : 1;
+  guint          depressed             : 1;
+  guint          depress_on_activate   : 1;
+  guint          focus_on_click        : 1;
+  guint          image_is_stock        : 1;
+  guint          in_button             : 1;
+  guint          relief                : 2;
+  guint          use_action_appearance : 1;
+  guint          use_stock             : 1;
+  guint          use_underline         : 1;
+};
+
+#endif /* __GTK_BUTTON_PRIVATE_H__ */
diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c
index 9a9b344..f07ecf1 100644
--- a/gtk/gtkcheckbutton.c
+++ b/gtk/gtkcheckbutton.c
@@ -28,6 +28,7 @@
 
 #include "gtkcheckbutton.h"
 
+#include "gtkbuttonprivate.h"
 #include "gtklabel.h"
 
 #include "gtkprivate.h"
@@ -452,9 +453,9 @@ gtk_real_check_button_draw_indicator (GtkCheckButton *check_button,
   else
     shadow_type = GTK_SHADOW_OUT;
 
-  if (button->activate_timeout || (button->button_down && button->in_button))
+  if (button->priv->activate_timeout || (button->priv->button_down && button->priv->in_button))
     state_type = GTK_STATE_ACTIVE;
-  else if (button->in_button)
+  else if (button->priv->in_button)
     state_type = GTK_STATE_PRELIGHT;
   else if (!gtk_widget_is_sensitive (widget))
     state_type = GTK_STATE_INSENSITIVE;
diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c
index b412044..e22adf6 100644
--- a/gtk/gtkradiobutton.c
+++ b/gtk/gtkradiobutton.c
@@ -25,9 +25,12 @@
  */
 
 #include "config.h"
+
+#include "gtkradiobutton.h"
+
+#include "gtkbuttonprivate.h"
 #include "gtklabel.h"
 #include "gtkmarshalers.h"
-#include "gtkradiobutton.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
 
@@ -209,7 +212,7 @@ gtk_radio_button_init (GtkRadioButton *radio_button)
 
   _gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), TRUE);
 
-  GTK_BUTTON (radio_button)->depress_on_activate = FALSE;
+  GTK_BUTTON (radio_button)->priv->depress_on_activate = FALSE;
 
   priv->group = g_slist_prepend (NULL, radio_button);
 
@@ -814,14 +817,14 @@ gtk_radio_button_clicked (GtkButton *button)
 
       if (!tmp_button)
 	{
-	  new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_ACTIVE);
+	  new_state = (button->priv->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_ACTIVE);
 	}
       else
 	{
 	  toggled = TRUE;
           _gtk_toggle_button_set_active (toggle_button,
                                          !gtk_toggle_button_get_active (toggle_button));
-	  new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL);
+	  new_state = (button->priv->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL);
 	}
     }
   else
@@ -843,12 +846,12 @@ gtk_radio_button_clicked (GtkButton *button)
 	    }
 	}
 
-      new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_ACTIVE);
+      new_state = (button->priv->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_ACTIVE);
     }
 
   if (gtk_toggle_button_get_inconsistent (toggle_button))
     depressed = FALSE;
-  else if (button->in_button && button->button_down)
+  else if (button->priv->in_button && button->priv->button_down)
     depressed = !gtk_toggle_button_get_active (toggle_button);
   else
     depressed = gtk_toggle_button_get_active (toggle_button);
@@ -923,9 +926,9 @@ gtk_radio_button_draw_indicator (GtkCheckButton *check_button,
   else
     shadow_type = GTK_SHADOW_OUT;
 
-  if (button->activate_timeout || (button->button_down && button->in_button))
+  if (button->priv->activate_timeout || (button->priv->button_down && button->priv->in_button))
     state_type = GTK_STATE_ACTIVE;
-  else if (button->in_button)
+  else if (button->priv->in_button)
     state_type = GTK_STATE_PRELIGHT;
   else if (!gtk_widget_is_sensitive (widget))
     state_type = GTK_STATE_INSENSITIVE;
diff --git a/gtk/gtktogglebutton.c b/gtk/gtktogglebutton.c
index a60ffeb..a4979b3 100644
--- a/gtk/gtktogglebutton.c
+++ b/gtk/gtktogglebutton.c
@@ -25,10 +25,13 @@
  */
 
 #include "config.h"
+
+#include "gtktogglebutton.h"
+
+#include "gtkbuttonprivate.h"
 #include "gtklabel.h"
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
-#include "gtktogglebutton.h"
 #include "gtktoggleaction.h"
 #include "gtkactivatable.h"
 #include "gtkprivate.h"
@@ -164,7 +167,7 @@ gtk_toggle_button_init (GtkToggleButton *toggle_button)
 
   priv->active = FALSE;
   priv->draw_indicator = FALSE;
-  GTK_BUTTON (toggle_button)->depress_on_activate = TRUE;
+  GTK_BUTTON (toggle_button)->priv->depress_on_activate = TRUE;
 }
 
 static void
@@ -327,8 +330,8 @@ gtk_toggle_button_set_mode (GtkToggleButton *toggle_button,
   if (priv->draw_indicator != draw_indicator)
     {
       priv->draw_indicator = draw_indicator;
-      GTK_BUTTON (toggle_button)->depress_on_activate = !draw_indicator;
-      
+      GTK_BUTTON (toggle_button)->priv->depress_on_activate = !draw_indicator;
+
       if (gtk_widget_get_visible (GTK_WIDGET (toggle_button)))
 	gtk_widget_queue_resize (GTK_WIDGET (toggle_button));
 
@@ -468,7 +471,7 @@ gtk_toggle_button_draw (GtkWidget *widget,
       shadow_type = GTK_SHADOW_ETCHED_IN;
     }
   else
-    shadow_type = button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
+    shadow_type = button->priv->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
 
   _gtk_button_paint (button, cr,
                      gtk_widget_get_allocated_width (widget),
@@ -503,7 +506,7 @@ gtk_toggle_button_mnemonic_activate (GtkWidget *widget,
 static void
 gtk_toggle_button_pressed (GtkButton *button)
 {
-  button->button_down = TRUE;
+  button->priv->button_down = TRUE;
 
   gtk_toggle_button_update_state (button);
   gtk_widget_queue_draw (GTK_WIDGET (button));
@@ -512,11 +515,11 @@ gtk_toggle_button_pressed (GtkButton *button)
 static void
 gtk_toggle_button_released (GtkButton *button)
 {
-  if (button->button_down)
+  if (button->priv->button_down)
     {
-      button->button_down = FALSE;
+      button->priv->button_down = FALSE;
 
-      if (button->in_button)
+      if (button->priv->in_button)
 	gtk_button_clicked (button);
 
       gtk_toggle_button_update_state (button);
@@ -556,12 +559,12 @@ gtk_toggle_button_update_state (GtkButton *button)
 
   if (priv->inconsistent)
     depressed = FALSE;
-  else if (button->in_button && button->button_down)
+  else if (button->priv->in_button && button->priv->button_down)
     depressed = TRUE;
   else
     depressed = priv->active;
 
-  if (!touchscreen && button->in_button && (!button->button_down || priv->draw_indicator))
+  if (!touchscreen && button->priv->in_button && (!button->priv->button_down || priv->draw_indicator))
     new_state = GTK_STATE_PRELIGHT;
   else
     new_state = depressed ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL;



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