]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/gtk+/gtk+-2.6.4-1.osso7/gtkcontainer.c.diff
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / gtk+ / gtk+-2.6.4-1.osso7 / gtkcontainer.c.diff
1 --- gtk+-2.6.4/gtk/gtkcontainer.c       2005-03-01 08:28:55.000000000 +0200
2 +++ gtk+-2.6.4/gtk/gtkcontainer.c       2005-04-06 16:19:36.410003200 +0300
3 @@ -37,10 +37,13 @@
4  #include "gtkwindow.h"
5  #include "gtkintl.h"
6  #include "gtktoolbar.h"
7 +#include "gtkmenu.h"
8 +#include "gtkentry.h"
9 +#include "gtktextview.h"
10 +#include "gtkwidget.h"
11  #include <gobject/gobjectnotifyqueue.c>
12  #include <gobject/gvaluecollector.h>
13  
14 -
15  enum {
16    ADD,
17    REMOVE,
18 @@ -56,6 +59,19 @@
19    PROP_CHILD
20  };
21  
22 +enum {
23 +  FOCUS_MOVE_OK,
24 +  FOCUS_MOVE_OK_NO_MOVE,
25 +  FOCUS_MOVE_FAIL_NO_TEXT
26 +};
27 +
28 +typedef struct
29 +{
30 +  GtkWidget *menu;
31 +  void *func;
32 +  GtkWidgetTapAndHoldFlags flags;
33 +} GtkContainerTAH;
34 +
35  #define PARAM_SPEC_PARAM_ID(pspec)              ((pspec)->param_id)
36  #define PARAM_SPEC_SET_PARAM_ID(pspec, id)      ((pspec)->param_id = (id))
37  
38 @@ -87,6 +103,9 @@
39  static gboolean gtk_container_focus_move           (GtkContainer      *container,
40                                                     GList             *children,
41                                                     GtkDirectionType   direction);
42 +static gint gtk_container_focus_move_with_tab  (GtkContainer        *container,
43 +                                                GtkDirectionType    direction,
44 +                                                GtkWidget           **fallback);
45  static void     gtk_container_children_callback    (GtkWidget         *widget,
46                                                     gpointer           client_data);
47  static void     gtk_container_show_all             (GtkWidget         *widget);
48 @@ -95,10 +114,14 @@
49                                                     GdkEventExpose    *event);
50  static void     gtk_container_map                  (GtkWidget         *widget);
51  static void     gtk_container_unmap                (GtkWidget         *widget);
52 -
53 +static void gtk_container_tap_and_hold_setup (GtkWidget *widget,
54 +               GtkWidget *menu, GtkCallback func, GtkWidgetTapAndHoldFlags flags);
55  static gchar* gtk_container_child_default_composite_name (GtkContainer *container,
56                                                           GtkWidget    *child);
57 +static void gtk_container_tap_and_hold_setup_forall( GtkWidget *widget,
58 +                                                     GtkContainerTAH *tah );
59  
60 +static void gtk_container_grab_focus( GtkWidget *focus_widget );
61  
62  /* --- variables --- */
63  static const gchar           vadjustment_key[] = "gtk-vadjustment";
64 @@ -190,7 +213,9 @@
65    widget_class->map = gtk_container_map;
66    widget_class->unmap = gtk_container_unmap;
67    widget_class->focus = gtk_container_focus;
68 -  
69 +  widget_class->tap_and_hold_setup = gtk_container_tap_and_hold_setup;
70 +  widget_class->grab_focus = gtk_container_grab_focus;
71 +
72    class->add = gtk_container_add_unimplemented;
73    class->remove = gtk_container_remove_unimplemented;
74    class->check_resize = gtk_container_real_check_resize;
75 @@ -2011,6 +2036,24 @@
76    GtkWidget *focus_child;
77    GtkWidget *child;
78  
79 +  /*
80 +   * If there's an item focus already and tab was pressed, only go thru
81 +   * GtkEntries and GtkTextviews. Do _not_ jump from last widget to the first
82 +   * one and vice verca.
83 +   */
84 +  if ((direction == GTK_DIR_TAB_FORWARD || direction == GTK_DIR_TAB_BACKWARD) &&
85 +      container->focus_child != NULL)
86 +    {
87 +      GtkWidget *fallback;
88 +      fallback = NULL;
89 +      if (gtk_container_focus_move_with_tab (container, direction, &fallback)
90 +              != FOCUS_MOVE_FAIL_NO_TEXT)
91 +        return TRUE;
92 +
93 +      if (fallback && gtk_widget_child_focus (fallback, direction))
94 +        return TRUE;
95 +    }
96 +
97    focus_child = container->focus_child;
98  
99    while (children)
100 @@ -2019,7 +2062,7 @@
101        children = children->next;
102  
103        if (!child)
104 -       continue;
105 +        continue;
106        
107        if (focus_child)
108          {
109 @@ -2027,8 +2070,8 @@
110              {
111                focus_child = NULL;
112  
113 -               if (gtk_widget_child_focus (child, direction))
114 -                 return TRUE;
115 +              if (gtk_widget_child_focus (child, direction))
116 +                return TRUE;
117              }
118          }
119        else if (GTK_WIDGET_DRAWABLE (child) &&
120 @@ -2042,6 +2085,105 @@
121    return FALSE;
122  }
123  
124 +static gint
125 +gtk_container_focus_move_with_tab (GtkContainer     *container,
126 +                                   GtkDirectionType direction,
127 +                                   GtkWidget        **fallback)
128 +{
129 +  GList *children, *sorted_children;
130 +  GtkWidget *child;
131 +  GtkWidget *focus_child;
132 +  gboolean found_text;
133 +  gint ret;
134 +
135 +  found_text = FALSE;
136 +  focus_child = container->focus_child;
137 +
138 +  /* This part is copied from gtk_container_focus() */
139 +  if (container->has_focus_chain)
140 +    children = g_list_copy (get_focus_chain (container));
141 +  else
142 +    children = gtk_container_get_all_children (container);
143 +
144 +  if (container->has_focus_chain &&
145 +      (direction == GTK_DIR_TAB_FORWARD ||
146 +       direction == GTK_DIR_TAB_BACKWARD))
147 +    {
148 +      sorted_children = g_list_copy (children);
149 +
150 +      if (direction == GTK_DIR_TAB_BACKWARD)
151 +        sorted_children = g_list_reverse (sorted_children);
152 +    }
153 +  else
154 +    sorted_children = _gtk_container_focus_sort (container, children,
155 +                                                 direction, NULL);
156 +  g_list_free(children);
157 +  children = sorted_children;
158 +
159 +  while (children)
160 +    {
161 +      child = children->data;
162 +      children = children->next;
163 +
164 +      if (!child)
165 +        continue;
166 +
167 +      if (GTK_IS_ENTRY (child) || GTK_IS_TEXT_VIEW (child))
168 +        found_text = TRUE;
169 +
170 +      if (focus_child)
171 +        {
172 +          if (child == focus_child)
173 +            {
174 +              focus_child = NULL;
175 +              if (GTK_IS_CONTAINER (child))
176 +                {
177 +                  ret = gtk_container_focus_move_with_tab (GTK_CONTAINER (child),
178 +                                                           direction,
179 +                                                           fallback);
180 +                  if (ret == FOCUS_MOVE_OK)
181 +                    {
182 +                      g_list_free (sorted_children);
183 +                      return FOCUS_MOVE_OK;
184 +                    }
185 +                  else if (ret == FOCUS_MOVE_OK_NO_MOVE)
186 +                    found_text = TRUE;
187 +                }
188 +            }
189 +        }
190 +      else if (GTK_WIDGET_DRAWABLE (child) &&
191 +               gtk_widget_is_ancestor (child, GTK_WIDGET (container)))
192 +        {
193 +          if (GTK_IS_ENTRY (child) || GTK_IS_TEXT_VIEW (child))
194 +            {
195 +              if (gtk_widget_child_focus (child, direction))
196 +                {
197 +                  g_list_free (sorted_children);
198 +                  return FOCUS_MOVE_OK;
199 +                }
200 +            }
201 +          else if (GTK_IS_CONTAINER (child))
202 +            {
203 +              ret = gtk_container_focus_move_with_tab (GTK_CONTAINER (child),
204 +                                                       direction,
205 +                                                       fallback);
206 +              if (ret == FOCUS_MOVE_OK)
207 +                {
208 +                  g_list_free (sorted_children);
209 +                  return FOCUS_MOVE_OK;
210 +                }
211 +              else if (ret == FOCUS_MOVE_OK_NO_MOVE)
212 +                found_text = TRUE;
213 +            }
214 +          if (GTK_WIDGET_CAN_FOCUS (child) && *fallback == NULL)
215 +            *fallback = child;
216 +        }
217 +    }
218 +
219 +  g_list_free (sorted_children);
220 +
221 +  return found_text ? FOCUS_MOVE_OK_NO_MOVE : FOCUS_MOVE_FAIL_NO_TEXT;
222 +}
223  
224  static void
225  gtk_container_children_callback (GtkWidget *widget,
226 @@ -2463,3 +2605,58 @@
227        gdk_event_free (child_event);
228      }
229  }
230 +
231 +static void gtk_container_tap_and_hold_setup_forall( GtkWidget *widget,
232 +                                                     GtkContainerTAH *tah )
233 +{
234 +  gtk_widget_tap_and_hold_setup( widget, tah->menu, tah->func,
235 +                                 tah->flags );
236 +}
237 +
238 +static void gtk_container_tap_and_hold_setup( GtkWidget *widget,
239 +            GtkWidget *menu, GtkCallback func, GtkWidgetTapAndHoldFlags flags )
240 +{
241 +  GtkContainerTAH tah;
242 +  g_return_if_fail( GTK_IS_WIDGET(widget));
243 +  g_return_if_fail( menu == NULL || GTK_IS_MENU(menu) );
244 +  tah.menu = menu;
245 +  tah.func = func;
246 +  tah.flags = flags;
247 +  if (flags & GTK_TAP_AND_HOLD_NO_INTERNALS)
248 +    gtk_container_foreach( GTK_CONTAINER(widget),
249 +                (GtkCallback)gtk_container_tap_and_hold_setup_forall, &tah );
250 +  else
251 +    gtk_container_forall( GTK_CONTAINER(widget),
252 +                (GtkCallback)gtk_container_tap_and_hold_setup_forall, &tah );
253 +  parent_class->tap_and_hold_setup (widget, menu, func, flags);
254 +}
255 +
256 +static void gtk_container_grab_focus( GtkWidget *focus_widget )
257 +{
258 +  if( GTK_WIDGET_CAN_FOCUS(focus_widget) )
259 +    parent_class->grab_focus( focus_widget );
260 +  else
261 +  {
262 +    GList *first = NULL;
263 +    GList *children = NULL;
264 +    GtkWidget *old_focus = NULL;
265 +    GtkWidget *toplevel = NULL;
266 +
267 +    toplevel = gtk_widget_get_toplevel( focus_widget );
268 +    if( !GTK_IS_WINDOW(toplevel) )
269 +      return;
270 +
271 +    old_focus = GTK_WINDOW(toplevel)->focus_widget;
272 +    first = gtk_container_get_all_children(
273 +                               GTK_CONTAINER(focus_widget) );
274 +    children = g_list_last( first );
275 +    
276 +    while( children && GTK_WINDOW(toplevel)->focus_widget == old_focus )
277 +    {
278 +      gtk_widget_grab_focus( GTK_WIDGET(children->data) );
279 +      children = children->prev;
280 +    }
281 +    g_list_free( first );
282 +  }
283 +}
284 +