]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/gtk+/gtk+-2.6.4-1.osso7/gtkscrolledwindow.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 / gtkscrolledwindow.c.diff
1 --- gtk+-2.6.4/gtk/gtkscrolledwindow.c  2004-08-09 19:59:52.000000000 +0300
2 +++ gtk+-2.6.4/gtk/gtkscrolledwindow.c  2005-04-06 16:19:37.898776872 +0300
3 @@ -289,6 +289,13 @@
4                                                              DEFAULT_SCROLLBAR_SPACING,
5                                                              G_PARAM_READABLE));
6  
7 +  gtk_widget_class_install_style_property (widget_class,
8 +                                          g_param_spec_boolean ("scrollbar_dislocation",
9 +                                                                P_("Scrollbar dislocation"),
10 +                                                                P_("Flag for having scrollbar at the outer border or container padding instead of at the inner border"),
11 +                                                                FALSE,
12 +                                                                G_PARAM_READABLE));
13 +
14    signals[SCROLL_CHILD] =
15      g_signal_new ("scroll_child",
16                    G_TYPE_FROM_CLASS (object_class),
17 @@ -1062,6 +1069,73 @@
18      }
19  }
20  
21 +static gdouble
22 +gtk_scrolled_window_get_focus_movement (GtkScrolledWindow *scrolled_window)
23 +{
24 +  GtkWidget *focus_child;
25 +  GtkRange *range;
26 +  GtkAdjustment *adj;
27 +  gdouble value, new_value;
28 +  gint x, y;
29 +
30 +  focus_child = GTK_CONTAINER(scrolled_window)->focus_child;
31 +  if (focus_child == NULL)
32 +     return 0;
33 +
34 +  while (GTK_IS_CONTAINER (focus_child) &&
35 +        GTK_CONTAINER (focus_child)->focus_child)
36 +    {
37 +      focus_child = GTK_CONTAINER (focus_child)->focus_child;
38 +    }
39 +
40 +  range = GTK_RANGE (scrolled_window->vscrollbar);
41 +  adj = range->adjustment;
42 +  value = gtk_adjustment_get_value (adj);
43 +
44 +  gtk_widget_translate_coordinates (focus_child->parent,
45 +                                   GTK_WIDGET(scrolled_window),
46 +                                   focus_child->allocation.x,
47 +                                   focus_child->allocation.y, &x, &y);
48 +
49 +  if (y < 0)
50 +    {
51 +      /* scroll up */
52 +      new_value = value + y;
53 +      if (new_value < adj->lower)
54 +       new_value = adj->lower;
55 +    }
56 +  else if (y + focus_child->allocation.height > adj->page_size)
57 +    {
58 +      /* scroll down */
59 +      new_value = value + y + focus_child->allocation.height - adj->page_size;
60 +      if (new_value > adj->upper - adj->page_size)
61 +        new_value = adj->upper - adj->page_size;
62 +    }
63 +  else
64 +    {
65 +      new_value = value;
66 +    }
67 +
68 +  return new_value - value;
69 +}
70 +
71 +static void
72 +gtk_scrolled_window_scroll_to_focus (GtkScrolledWindow *scrolled_window)
73 +{
74 +  GtkAdjustment *adj;
75 +  gdouble diff;
76 +
77 +  diff = gtk_scrolled_window_get_focus_movement (scrolled_window);
78 +  if (diff != 0)
79 +    {
80 +      adj = GTK_RANGE (scrolled_window->vscrollbar)->adjustment;
81 +
82 +      gtk_adjustment_set_value (adj, gtk_adjustment_get_value (adj) + diff);
83 +      gtk_scrolled_window_set_vadjustment (scrolled_window,
84 +                                          GTK_ADJUSTMENT (adj));
85 +    }
86 +}
87 +
88  static void
89  gtk_scrolled_window_size_allocate (GtkWidget     *widget,
90                                    GtkAllocation *allocation)
91 @@ -1071,17 +1145,32 @@
92    GtkAllocation relative_allocation;
93    GtkAllocation child_allocation;
94    gint scrollbar_spacing;
95 -  
96 +  gboolean is_focus_visible, dislocate;
97 +  gint dislocation;
98 +
99    g_return_if_fail (GTK_IS_SCROLLED_WINDOW (widget));
100    g_return_if_fail (allocation != NULL);
101  
102    scrolled_window = GTK_SCROLLED_WINDOW (widget);
103    bin = GTK_BIN (scrolled_window);
104  
105 +  is_focus_visible =
106 +    gtk_scrolled_window_get_focus_movement (scrolled_window) == 0;
107 +
108    scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
109  
110    widget->allocation = *allocation;
111  
112 +  /* See how much scrollbar needs be "dislocated" (to get it to the other
113 +   * edge of the border). Does not apply to all occasions. */
114 +  gtk_widget_style_get (GTK_WIDGET (scrolled_window),
115 +                       "scrollbar_dislocation", &dislocate,
116 +                       NULL);
117 +  if (dislocate)
118 +    dislocation = GTK_CONTAINER (scrolled_window)->border_width;
119 +  else
120 +    dislocation = 0;
121 +
122    if (scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
123      scrolled_window->hscrollbar_visible = TRUE;
124    else if (scrolled_window->hscrollbar_policy == GTK_POLICY_NEVER)
125 @@ -1150,10 +1239,12 @@
126         child_allocation.y = (relative_allocation.y +
127                               relative_allocation.height +
128                               scrollbar_spacing +
129 +                             dislocation +
130                               (scrolled_window->shadow_type == GTK_SHADOW_NONE ?
131                                0 : widget->style->ythickness));
132        else
133 -       child_allocation.y = GTK_CONTAINER (scrolled_window)->border_width;
134 +       child_allocation.y = GTK_CONTAINER (scrolled_window)->border_width -
135 +         dislocation;
136  
137        child_allocation.width = relative_allocation.width;
138        child_allocation.height = hscrollbar_requisition.height;
139 @@ -1189,10 +1280,12 @@
140         child_allocation.x = (relative_allocation.x +
141                               relative_allocation.width +
142                               scrollbar_spacing +
143 +                             dislocation +
144                               (scrolled_window->shadow_type == GTK_SHADOW_NONE ?
145                                0 : widget->style->xthickness));
146        else
147 -       child_allocation.x = GTK_CONTAINER (scrolled_window)->border_width;
148 +       child_allocation.x = GTK_CONTAINER (scrolled_window)->border_width -
149 +         dislocation;
150  
151        child_allocation.y = relative_allocation.y;
152        child_allocation.width = vscrollbar_requisition.width;
153 @@ -1207,6 +1300,9 @@
154         }
155  
156        gtk_widget_size_allocate (scrolled_window->vscrollbar, &child_allocation);
157 +
158 +      if (is_focus_visible)
159 +       gtk_scrolled_window_scroll_to_focus (scrolled_window);
160      }
161    else if (GTK_WIDGET_VISIBLE (scrolled_window->vscrollbar))
162      gtk_widget_hide (scrolled_window->vscrollbar);