]> git.pld-linux.org Git - packages/vte.git/blob - vte-atktextselection.patch
- fixed
[packages/vte.git] / vte-atktextselection.patch
1 Index: vte/ChangeLog
2 ===================================================================
3 RCS file: /cvs/gnome/vte/ChangeLog,v
4 retrieving revision 1.524
5 diff -u -p -r1.524 ChangeLog
6 --- vte/ChangeLog       2 May 2004 06:43:01 -0000       1.524
7 +++ vte/ChangeLog       6 May 2004 08:11:36 -0000
8 @@ -1,3 +1,22 @@
9 +2004-05-06  Padraig O'Briain  <padraig.obriain@sun.com>
10 +       * src/vte.c, src/vteint.h:
11 +       Add new functions to support accessible text selection:
12 +       _vte_terminal_get_selection, _vte_terminal_get_start_selection,
13 +       _vte_terminal_get_end_selection, _vte_terminal_select_text,
14 +       _vte_terminal_remove_selection
15 +       * src/vteaccess.c:
16 +       (xy_from_offset): Fix for offset being entire text.
17 +       (vte_terminal_accessibility_selection_changed): VteTerminal's
18 +       selection-changed signal handler which emits text-selection-changed
19 +       signal.
20 +       (vte_terminal_accessible_initialize): Connect to VteTerminal's
21 +       selection-changed signal.
22 +       (vte_terminal_accessible_get_n_selections) Add implementation.
23 +       (vte_terminal_accessible_get_selection) Add implementation.
24 +       (vte_terminal_accessible_add_selection) Add implementation.
25 +       (vte_terminal_accessible_remove_selection) Add implementation.
26 +       (vte_terminal_accessible_set_selection) Add implementation.
27 +
28  2004-05-02 nalin
29         * src/reaper.c(vte_reaper_add_child): pass the global reaper in as
30         data when adding the child source, not the terminal which called us.
31 Index: vte/src/vte.c
32 ===================================================================
33 RCS file: /cvs/gnome/vte/src/vte.c,v
34 retrieving revision 1.404
35 diff -u -p -r1.404 vte.c
36 --- vte/src/vte.c       2 May 2004 06:43:01 -0000       1.404
37 +++ vte/src/vte.c       6 May 2004 08:11:37 -0000
38 @@ -15758,3 +15758,76 @@ _vte_terminal_accessible_ref(VteTerminal
39         g_return_if_fail(VTE_IS_TERMINAL(terminal));
40         terminal->pvt->accessible_emit = TRUE;
41  }
42 +
43 +char *
44 +_vte_terminal_get_selection(VteTerminal *terminal)
45 +{
46 +       g_return_val_if_fail(VTE_IS_TERMINAL(terminal), NULL);
47 +
48 +       return g_strdup (terminal->pvt->selection);
49 +}
50 +
51 +void 
52 +_vte_terminal_get_start_selection(VteTerminal *terminal, long *x, long *y)
53 +{
54 +       struct selection_cell_coords ss;
55 +
56 +       g_return_if_fail(VTE_IS_TERMINAL(terminal));
57 +
58 +       ss = terminal->pvt->selection_start;
59 +       
60 +       if (x) {
61 +               *x = ss.x;
62 +       }
63 +
64 +       if (y) {
65 +               *y = ss.y;
66 +       }
67 +}
68 +
69 +void 
70 +_vte_terminal_get_end_selection(VteTerminal *terminal, long *x, long *y)
71 +{
72 +       struct selection_cell_coords se;
73 +
74 +       g_return_if_fail(VTE_IS_TERMINAL(terminal));
75 +
76 +       se = terminal->pvt->selection_end;
77 +       
78 +       if (x) {
79 +               *x = se.x;
80 +       }
81 +
82 +       if (y) {
83 +               *y = se.y;
84 +       }
85 +}
86 +
87 +void 
88 +_vte_terminal_select_text(VteTerminal *terminal, long start_x, long start_y, long end_x, long end_y, int start_offset, int end_offset)
89 +{
90 +       g_return_if_fail(VTE_IS_TERMINAL(terminal));
91 +
92 +       terminal->pvt->selection_type = selection_type_char;
93 +       terminal->pvt->has_selection = TRUE;
94 +       terminal->pvt->selecting_had_delta = TRUE;
95 +       terminal->pvt->selection_start.x = start_x;
96 +       terminal->pvt->selection_start.y = start_y;
97 +       terminal->pvt->selection_end.x = end_x;
98 +       terminal->pvt->selection_end.y = end_y;
99 +       vte_terminal_copy(terminal,
100 +                         GDK_SELECTION_PRIMARY);
101 +       vte_invalidate_cells (terminal, 
102 +                             0,
103 +                             terminal->column_count,
104 +                             MIN (start_y, end_y),
105 +                             ABS (start_y - end_y) + 1);
106 +
107 +       vte_terminal_emit_selection_changed(terminal);
108 +}
109 +
110 +void 
111 +_vte_terminal_remove_selection(VteTerminal *terminal)
112 +{
113 +       vte_terminal_deselect_all (terminal);
114 +}
115 Index: vte/src/vteaccess.c
116 ===================================================================
117 RCS file: /cvs/gnome/vte/src/vteaccess.c,v
118 retrieving revision 1.44
119 diff -u -p -r1.44 vteaccess.c
120 --- vte/src/vteaccess.c 1 May 2004 07:12:51 -0000       1.44
121 +++ vte/src/vteaccess.c 6 May 2004 08:11:37 -0000
122 @@ -150,7 +150,7 @@ xy_from_offset (VteTerminalAccessiblePri
123                 }
124         }
125         if (i == priv->snapshot_linebreaks->len) {
126 -               if (offset < priv->snapshot_characters->len) {
127 +               if (offset <= priv->snapshot_characters->len) {
128                         cur_x = offset - cur_offset;
129                         cur_y = i - 1;
130                 }
131 @@ -735,6 +735,16 @@ vte_terminal_accessible_visibility_notif
132  }
133  
134  static void
135 +vte_terminal_accessible_selection_changed (VteTerminal *terminal,
136 +                                          gpointer data)
137 +{
138 +       g_return_if_fail(VTE_IS_TERMINAL_ACCESSIBLE(data));
139 +       g_return_if_fail(VTE_IS_TERMINAL(terminal));
140 +
141 +       g_signal_emit_by_name (data, "text_selection_changed");
142 +}
143 +
144 +static void
145  vte_terminal_initialize (AtkObject *obj, gpointer data)
146  {
147         VteTerminal *terminal;
148 @@ -777,6 +787,9 @@ vte_terminal_initialize (AtkObject *obj,
149         g_signal_connect(G_OBJECT(terminal), "visibility-notify-event",
150                          GTK_SIGNAL_FUNC(vte_terminal_accessible_visibility_notify),
151                          obj);
152 +       g_signal_connect(G_OBJECT(terminal), "selection-changed",
153 +                        GTK_SIGNAL_FUNC(vte_terminal_accessible_selection_changed),
154 +                        obj);
155  
156         if (GTK_IS_WIDGET((GTK_WIDGET(terminal))->parent)) {
157                 parent = gtk_widget_get_accessible((GTK_WIDGET(terminal))->parent);
158 @@ -1382,55 +1395,136 @@ vte_terminal_accessible_get_offset_at_po
159  static gint
160  vte_terminal_accessible_get_n_selections(AtkText *text)
161  {
162 -       g_return_val_if_fail(VTE_IS_TERMINAL_ACCESSIBLE(text), 0);
163 +       GtkWidget *widget;
164 +       VteTerminal *terminal;
165 +
166 +       g_return_val_if_fail(VTE_IS_TERMINAL_ACCESSIBLE(text), -1);
167         vte_terminal_accessible_update_private_data_if_needed(ATK_OBJECT(text),
168                                                               NULL, NULL);
169 -       /* FIXME? */
170 -       return 0;
171 +
172 +       widget = GTK_ACCESSIBLE(text)->widget;
173 +       if (widget == NULL) {
174 +               /* State is defunct */
175 +               return -1;
176 +       }
177 +       g_return_val_if_fail (VTE_IS_TERMINAL (widget), -1);
178 +       terminal = VTE_TERMINAL (widget);
179 +       return (vte_terminal_get_has_selection (terminal)) ? 1 : 0;
180  }
181  
182  static gchar *
183  vte_terminal_accessible_get_selection(AtkText *text, gint selection_number,
184                                       gint *start_offset, gint *end_offset)
185  {
186 +       GtkWidget *widget;
187 +       VteTerminal *terminal;
188 +       VteTerminalAccessiblePrivate *priv;
189 +       long start_x, start_y, end_x, end_y;
190 +
191         g_return_val_if_fail(VTE_IS_TERMINAL_ACCESSIBLE(text), NULL);
192         vte_terminal_accessible_update_private_data_if_needed(ATK_OBJECT(text),
193                                                               NULL, NULL);
194 -       /* FIXME? */
195 -       return NULL;
196 +       widget = GTK_ACCESSIBLE(text)->widget;
197 +       if (widget == NULL) {
198 +               /* State is defunct */
199 +               return NULL;
200 +       }
201 +       g_return_val_if_fail (VTE_IS_TERMINAL (widget), NULL);
202 +       terminal = VTE_TERMINAL (widget);
203 +       if (!vte_terminal_get_has_selection (terminal)) {
204 +               return NULL;
205 +       }
206 +       if (selection_number != 0) {
207 +               return NULL;
208 +       }
209 +
210 +       priv = g_object_get_data(G_OBJECT(text),
211 +                                VTE_TERMINAL_ACCESSIBLE_PRIVATE_DATA);
212 +       _vte_terminal_get_start_selection (terminal, &start_x, &start_y);
213 +       *start_offset = offset_from_xy (priv, start_x, start_y);
214 +       _vte_terminal_get_end_selection (terminal, &end_x, &end_y);
215 +       *end_offset = offset_from_xy (priv, end_x, end_y);
216 +       return _vte_terminal_get_selection (terminal);
217  }
218  
219  static gboolean
220  vte_terminal_accessible_add_selection(AtkText *text,
221                                       gint start_offset, gint end_offset)
222  {
223 +       GtkWidget *widget;
224 +       VteTerminal *terminal;
225 +       VteTerminalAccessiblePrivate *priv;
226 +       gint start_x, start_y, end_x, end_y;
227 +
228         g_return_val_if_fail(VTE_IS_TERMINAL_ACCESSIBLE(text), FALSE);
229         vte_terminal_accessible_update_private_data_if_needed(ATK_OBJECT(text),
230                                                               NULL, NULL);
231 -       /* FIXME? */
232 -       return FALSE;
233 +       widget = GTK_ACCESSIBLE(text)->widget;
234 +       if (widget == NULL) {
235 +               /* State is defunct */
236 +               return FALSE;
237 +       }
238 +       g_return_val_if_fail (VTE_IS_TERMINAL (widget), FALSE);
239 +       terminal = VTE_TERMINAL (widget);
240 +       g_return_val_if_fail (!vte_terminal_get_has_selection (terminal), FALSE);
241 +       priv = g_object_get_data(G_OBJECT(text),
242 +                                VTE_TERMINAL_ACCESSIBLE_PRIVATE_DATA);
243 +       xy_from_offset (priv, start_offset, &start_x, &start_y);
244 +       xy_from_offset (priv, end_offset, &end_x, &end_y);
245 +       _vte_terminal_select_text (terminal, start_x, start_y, end_x, end_y, start_offset, end_offset);
246 +       return TRUE;
247  }
248  
249  static gboolean
250  vte_terminal_accessible_remove_selection(AtkText *text,
251                                          gint selection_number)
252  {
253 +       GtkWidget *widget;
254 +       VteTerminal *terminal;
255 +
256         g_return_val_if_fail(VTE_IS_TERMINAL_ACCESSIBLE(text), FALSE);
257         vte_terminal_accessible_update_private_data_if_needed(ATK_OBJECT(text),
258                                                               NULL, NULL);
259 -       /* FIXME? */
260 -       return FALSE;
261 +       widget = GTK_ACCESSIBLE(text)->widget;
262 +       if (widget == NULL) {
263 +               /* State is defunct */
264 +               return FALSE;
265 +       }
266 +       g_return_val_if_fail (VTE_IS_TERMINAL (widget), FALSE);
267 +       terminal = VTE_TERMINAL (widget);
268 +       if (selection_number == 0 && vte_terminal_get_has_selection (terminal)) {
269 +               _vte_terminal_remove_selection (terminal);
270 +               return TRUE;
271 +       } else {
272 +               return FALSE;
273 +       }
274  }
275  
276  static gboolean
277  vte_terminal_accessible_set_selection(AtkText *text, gint selection_number,
278                                       gint start_offset, gint end_offset)
279  {
280 +       GtkWidget *widget;
281 +       VteTerminal *terminal;
282 +
283         g_return_val_if_fail(VTE_IS_TERMINAL_ACCESSIBLE(text), FALSE);
284         vte_terminal_accessible_update_private_data_if_needed(ATK_OBJECT(text),
285                                                               NULL, NULL);
286 -       /* FIXME? */
287 -       return FALSE;
288 +       widget = GTK_ACCESSIBLE(text)->widget;
289 +       if (widget == NULL) {
290 +               /* State is defunct */
291 +               return FALSE;
292 +       }
293 +       g_return_val_if_fail (VTE_IS_TERMINAL (widget), FALSE);
294 +       terminal = VTE_TERMINAL (widget);
295 +       if (selection_number != 0) {
296 +               return FALSE;
297 +       }
298 +       if (vte_terminal_get_has_selection (terminal)) {
299 +               _vte_terminal_remove_selection (terminal);
300 +       }
301 +
302 +       return vte_terminal_accessible_add_selection (text, start_offset, end_offset);
303  }
304  
305  static gboolean
306 @@ -1519,6 +1613,9 @@ vte_terminal_accessible_get_position(Atk
307         *x = 0;
308         *y = 0;
309         widget = (GTK_ACCESSIBLE(component))->widget;
310 +       if (widget == NULL) {
311 +               return;
312 +       }
313         if (!GTK_WIDGET_REALIZED(widget)) {
314                 return;
315         }
316 @@ -1543,6 +1640,9 @@ vte_terminal_accessible_get_size(AtkComp
317         *width = 0;
318         *height = 0;
319         widget = (GTK_ACCESSIBLE(component))->widget;
320 +       if (widget == NULL) {
321 +               return;
322 +       }
323         if (!GTK_WIDGET_REALIZED(widget)) {
324                 return;
325         }
326 @@ -1575,7 +1675,12 @@ vte_terminal_accessible_set_size(AtkComp
327  {
328         VteTerminal *terminal;
329         gint columns, rows, xpad, ypad;
330 -       terminal = VTE_TERMINAL((GTK_ACCESSIBLE(component))->widget);
331 +       GtkWidget *widget;
332 +       widget = GTK_ACCESSIBLE(component)->widget;
333 +       if (widget == NULL) {
334 +               return FALSE;
335 +       }
336 +       terminal = VTE_TERMINAL(widget);
337         vte_terminal_get_padding(terminal, &xpad, &ypad);
338         /* If the size is an exact multiple of the cell size, use that,
339          * otherwise round down. */
340 @@ -1599,6 +1704,9 @@ vte_terminal_accessible_grab_focus(AtkCo
341  {
342         GtkWidget *widget;
343         widget = (GTK_ACCESSIBLE(component))->widget;
344 +       if (widget == NULL) {
345 +               return FALSE;
346 +       }
347         if (GTK_WIDGET_HAS_FOCUS(widget)) {
348                 return TRUE;
349         }
350 Index: vte/src/vteint.h
351 ===================================================================
352 RCS file: /cvs/gnome/vte/src/vteint.h,v
353 retrieving revision 1.1
354 diff -u -p -r1.1 vteint.h
355 --- vte/src/vteint.h    16 Jun 2003 21:16:33 -0000      1.1
356 +++ vte/src/vteint.h    6 May 2004 08:11:37 -0000
357 @@ -26,6 +26,11 @@
358  G_BEGIN_DECLS
359  
360  void _vte_terminal_accessible_ref(VteTerminal *terminal);
361 +char* _vte_terminal_get_selection(VteTerminal *terminal);
362 +void _vte_terminal_get_start_selection(VteTerminal *terminal, long *x, long *y);
363 +void _vte_terminal_get_end_selection(VteTerminal *terminal, long *x, long *y);
364 +void _vte_terminal_select_text(VteTerminal *terminal, long start_x, long start_y, long end_x, long end_y, int start_offset, int end_offset);
365 +void _vte_terminal_remove_selection(VteTerminal *terminal);
366  
367  G_END_DECLS
368  
This page took 0.088009 seconds and 3 git commands to generate.