aboutsummaryrefslogtreecommitdiffstats
path: root/packages/gtk+/gtk+-2.6.4-1.osso7/gtktoolbar.c.diff
blob: b99d346f4b3c79ead0abb916f0b3971ded1eddf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
--- gtk+-2.6.4/gtk/gtktoolbar.c	2004-11-23 06:11:15.000000000 +0200
+++ gtk+-2.6.4/gtk/gtktoolbar.c	2005-04-06 16:19:38.166736136 +0300
@@ -67,7 +67,9 @@
 
 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
+#define DEFAULT_ANIMATION_STATE FALSE
 
+#define DEFAULT_MAX_CHILD_SPACING   G_MAXINT
 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
 				    * in the homogeneous game. In units of
 				    * pango_font_get_estimated_char_width().
@@ -140,10 +142,14 @@
   
   GTimer *	timer;
   
+  guint   animation_connection;
+
   guint		show_arrow : 1;
   guint		need_sync : 1;
   guint		is_sliding : 1;
   guint		need_rebuild : 1;	/* whether the overflow menu should be regenerated */
+  guint   animation_set : 1;
+  guint   animation : 1;
 };
 
 static void       gtk_toolbar_init                 (GtkToolbar          *toolbar);
@@ -225,9 +231,11 @@
 static void       gtk_toolbar_reconfigured         (GtkToolbar          *toolbar);
 static gboolean   gtk_toolbar_check_new_api        (GtkToolbar          *toolbar);
 static gboolean   gtk_toolbar_check_old_api        (GtkToolbar          *toolbar);
+static void       gtk_toolbar_update_animation_state (GtkToolbar         *toolbar);
 
 static GtkReliefStyle       get_button_relief    (GtkToolbar *toolbar);
 static gint                 get_internal_padding (GtkToolbar *toolbar);
+static gint                 get_max_child_expand (GtkToolbar *toolbar);
 static GtkShadowType        get_shadow_type      (GtkToolbar *toolbar);
 static gint                 get_space_size       (GtkToolbar *toolbar);
 static GtkToolbarSpaceStyle get_space_style      (GtkToolbar *toolbar);
@@ -563,6 +571,15 @@
                                                              G_PARAM_READABLE));
   
   gtk_widget_class_install_style_property (widget_class,
+					   g_param_spec_int ("max_child_expand",
+							     P_("Maximum toolbar item spacing"),
+							     P_("Maximum space between the toolbar items."),
+							     0,
+							     G_MAXINT,
+                                                             DEFAULT_MAX_CHILD_SPACING,
+                                                             G_PARAM_READABLE));
+  
+  gtk_widget_class_install_style_property (widget_class,
 					   g_param_spec_enum ("space_style",
 							      P_("Space style"),
 							      P_("Whether spacers are vertical lines or just blank"),
@@ -598,6 +615,12 @@
                                                     GTK_TYPE_ICON_SIZE,
                                                     DEFAULT_ICON_SIZE,
                                                     G_PARAM_READWRITE));  
+
+  gtk_settings_install_property (g_param_spec_boolean ("gtk-toolbar-animation",
+                                                    P_("Toolbar animation"),
+                                                    P_("Are we using toolbar animation"),
+                                                    DEFAULT_ANIMATION_STATE,
+                                                    G_PARAM_READWRITE));  
   
   binding_set = gtk_binding_set_by_class (klass);
   
@@ -638,6 +661,7 @@
   toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
   toolbar->style = DEFAULT_TOOLBAR_STYLE;
   toolbar->icon_size = DEFAULT_ICON_SIZE;
+  priv->animation = DEFAULT_ANIMATION_STATE;
   toolbar->tooltips = gtk_tooltips_new ();
   g_object_ref (toolbar->tooltips);
   gtk_object_sink (GTK_OBJECT (toolbar->tooltips));
@@ -960,7 +984,7 @@
 }
 
 static gint
-position (gint from, gint to, gdouble elapsed)
+position (GtkToolbar *toolbar, gint from, gint to, gdouble elapsed)
 {
   gint n_pixels;
 
@@ -978,11 +1002,20 @@
       n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
 	SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
     }
-  
-  if (to > from)
-    return MIN (from + n_pixels, to);
-  else
-    return MAX (from - n_pixels, to);
+  if (GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation) {
+    if (to > from)
+      return MIN (from + n_pixels, to);
+    else
+      return MAX (from - n_pixels, to);
+  }
+  return to;
+}
+
+static GtkSettings *
+toolbar_get_settings (GtkToolbar *toolbar)
+{
+   GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+   return priv->settings;
 }
 
 static void
@@ -994,12 +1027,12 @@
   GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
   gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
   
-  intermediate->x = position (start->x, goal->x, elapsed);
-  intermediate->y = position (start->y, goal->y, elapsed);
+  intermediate->x = position (toolbar, start->x, goal->x, elapsed);
+  intermediate->y = position (toolbar, start->y, goal->y, elapsed);
   intermediate->width =
-    position (start->x + start->width, goal->x + goal->width, elapsed) - intermediate->x;
+    position (toolbar, start->x + start->width, goal->x + goal->width, elapsed) - intermediate->x;
   intermediate->height =
-    position (start->y + start->height, goal->y + goal->height, elapsed) - intermediate->y;
+    position (toolbar, start->y + start->height, goal->y + goal->height, elapsed) - intermediate->y;
 }
 
 static void
@@ -1047,6 +1080,32 @@
     }
 }
 
+static void
+gtk_toolbar_update_animation_state (GtkToolbar *toolbar)
+{
+  gboolean animation_state;
+  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+  
+  g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
+  
+  if (priv->animation_set)
+    {
+      GtkSettings *settings = toolbar_get_settings (toolbar);
+      
+      if (settings)
+      	{
+      	  g_object_get (settings,
+      			"gtk-toolbar-animation", &animation_state,
+      			NULL);
+        }
+      else
+      	animation_state = DEFAULT_ANIMATION_STATE;
+
+      priv->animation = animation_state;
+      priv->animation_set = FALSE;
+    }
+}
+
 static gboolean
 slide_idle_handler (gpointer data)
 {
@@ -1537,10 +1596,14 @@
 	  
 	  if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
 	    {
+	      gint mexpand = get_max_child_expand(toolbar);
 	      gint extra = size / n_expand_items;
 	      if (size % n_expand_items != 0)
 		extra++;
-	      
+	      if (extra > mexpand) {
+		extra = mexpand;
+	      }
+
 	      allocations[i].width += extra;
 	      size -= extra;
 	      n_expand_items--;
@@ -1932,11 +1995,16 @@
     }
 }
 
-static GtkSettings *
-toolbar_get_settings (GtkToolbar *toolbar)
+static void
+animation_change_notify (GtkToolbar *toolbar)
 {
   GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
-  return priv->settings;
+  if (!priv->animation_set)
+    {
+      /* pretend it was set, then unset, thus reverting to new default */
+      priv->animation_set = TRUE; 
+      gtk_toolbar_update_animation_state (toolbar);
+    }
 }
 
 static void
@@ -1960,6 +2028,7 @@
     {
       g_signal_handler_disconnect (old_settings, toolbar->style_set_connection);
       g_signal_handler_disconnect (old_settings, toolbar->icon_size_connection);
+      g_signal_handler_disconnect (old_settings, priv->animation_connection);
       
       g_object_unref (old_settings);
     }
@@ -1976,6 +2045,11 @@
 				  "notify::gtk-toolbar-icon-size",
 				  G_CALLBACK (icon_size_change_notify),
 				  toolbar);
+      priv->animation_connection =
+	g_signal_connect_swapped (settings,
+				  "notify::gtk-toolbar-animation",
+				  G_CALLBACK (animation_change_notify),
+				  toolbar);
       
       g_object_ref (settings);
       priv->settings = settings;
@@ -1985,6 +2059,7 @@
   
   style_change_notify (toolbar);
   icon_size_change_notify (toolbar);
+  animation_change_notify (toolbar);
 }
 
 static int
@@ -2913,7 +2988,7 @@
  * gtk_toolbar_get_icon_size:
  * @toolbar: a #GtkToolbar
  *
- * Retrieves the icon size fo the toolbar. See gtk_toolbar_set_icon_size().
+ * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
  *
  * Return value: the current icon size for the icons on the toolbar.
  **/
@@ -4642,6 +4717,17 @@
   return ipadding;
 }
 
+static gint
+get_max_child_expand (GtkToolbar *toolbar)
+{
+  gint mexpand = DEFAULT_MAX_CHILD_SPACING;
+  
+  gtk_widget_style_get (GTK_WIDGET (toolbar),
+		  	"max_child_expand", &mexpand,
+			NULL);
+  return mexpand;
+}
+
 static GtkShadowType
 get_shadow_type (GtkToolbar *toolbar)
 {