Mercurial > pidgin
annotate src/gtkticker.c @ 4539:05476ef20d58
[gaim-migrate @ 4818]
Added gaim_xfer_is_completed()
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 06 Feb 2003 08:42:38 +0000 |
parents | ebfb80bbe1ed |
children |
rev | line source |
---|---|
430 | 1 /* GTK - The GIMP Toolkit |
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald | |
3 * | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Library General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Library General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Library General Public | |
15 * License along with this library; if not, write to the | |
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 * Boston, MA 02111-1307, USA. | |
18 */ | |
19 | |
20 /* | |
21 * GtkTicker Copyright 2000 Syd Logan | |
22 */ | |
23 | |
24 #include "gtkticker.h" | |
2725
f3c094e78609
[gaim-migrate @ 2738]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1114
diff
changeset
|
25 #include <gtk/gtk.h> |
430 | 26 |
27 static void gtk_ticker_compute_offsets (GtkTicker *ticker); | |
28 static void gtk_ticker_class_init (GtkTickerClass *klass); | |
29 static void gtk_ticker_init (GtkTicker *ticker); | |
30 static void gtk_ticker_map (GtkWidget *widget); | |
31 static void gtk_ticker_realize (GtkWidget *widget); | |
32 static void gtk_ticker_size_request (GtkWidget *widget, | |
33 GtkRequisition *requisition); | |
34 static void gtk_ticker_size_allocate (GtkWidget *widget, | |
35 GtkAllocation *allocation); | |
36 static void gtk_ticker_paint (GtkWidget *widget, | |
37 GdkRectangle *area); | |
38 static void gtk_ticker_draw (GtkWidget *widget, | |
39 GdkRectangle *area); | |
40 static gint gtk_ticker_expose (GtkWidget *widget, | |
41 GdkEventExpose *event); | |
42 static void gtk_ticker_add_real (GtkContainer *container, | |
43 GtkWidget *widget); | |
44 static void gtk_ticker_remove_real (GtkContainer *container, | |
45 GtkWidget *widget); | |
46 static void gtk_ticker_forall (GtkContainer *container, | |
47 gboolean include_internals, | |
48 GtkCallback callback, | |
49 gpointer callback_data); | |
50 static GtkType gtk_ticker_child_type (GtkContainer *container); | |
51 | |
52 | |
53 static GtkContainerClass *parent_class = NULL; | |
54 | |
55 | |
56 GtkType | |
57 gtk_ticker_get_type (void) | |
58 { | |
59 static GtkType ticker_type = 0; | |
60 | |
61 if (!ticker_type) | |
62 { | |
63 static const GtkTypeInfo ticker_info = | |
64 { | |
65 "GtkTicker", | |
66 sizeof (GtkTicker), | |
67 sizeof (GtkTickerClass), | |
68 (GtkClassInitFunc) gtk_ticker_class_init, | |
69 (GtkObjectInitFunc) gtk_ticker_init, | |
70 /* reserved_1 */ NULL, | |
71 /* reserved_2 */ NULL, | |
72 (GtkClassInitFunc) NULL, | |
73 }; | |
74 | |
75 ticker_type = gtk_type_unique (GTK_TYPE_CONTAINER, &ticker_info); | |
76 } | |
77 | |
78 return ticker_type; | |
79 } | |
80 | |
81 static void | |
82 gtk_ticker_class_init (GtkTickerClass *class) | |
83 { | |
84 GtkObjectClass *object_class; | |
85 GtkWidgetClass *widget_class; | |
86 GtkContainerClass *container_class; | |
87 | |
88 object_class = (GtkObjectClass*) class; | |
89 widget_class = (GtkWidgetClass*) class; | |
90 container_class = (GtkContainerClass*) class; | |
91 | |
92 parent_class = gtk_type_class (GTK_TYPE_CONTAINER); | |
93 | |
94 widget_class->map = gtk_ticker_map; | |
95 widget_class->realize = gtk_ticker_realize; | |
96 widget_class->size_request = gtk_ticker_size_request; | |
97 widget_class->size_allocate = gtk_ticker_size_allocate; | |
2725
f3c094e78609
[gaim-migrate @ 2738]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1114
diff
changeset
|
98 #if ! GTK_CHECK_VERSION(1,3,0) |
430 | 99 widget_class->draw = gtk_ticker_draw; |
2725
f3c094e78609
[gaim-migrate @ 2738]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1114
diff
changeset
|
100 #endif |
430 | 101 widget_class->expose_event = gtk_ticker_expose; |
102 | |
103 container_class->add = gtk_ticker_add_real; | |
104 container_class->remove = gtk_ticker_remove_real; | |
105 container_class->forall = gtk_ticker_forall; | |
106 container_class->child_type = gtk_ticker_child_type; | |
107 } | |
108 | |
109 static GtkType | |
110 gtk_ticker_child_type (GtkContainer *container) | |
111 { | |
112 return GTK_TYPE_WIDGET; | |
113 } | |
114 | |
115 static void | |
116 gtk_ticker_init (GtkTicker *ticker) | |
117 { | |
118 GTK_WIDGET_UNSET_FLAGS (ticker, GTK_NO_WINDOW); | |
119 | |
120 ticker->interval = (guint) 200; | |
121 ticker->scootch = (guint) 2; | |
122 ticker->children = NULL; | |
123 ticker->timer = 0; | |
124 ticker->dirty = TRUE; | |
125 } | |
126 | |
127 GtkWidget* | |
128 gtk_ticker_new (void) | |
129 { | |
130 GtkTicker *ticker; | |
131 | |
132 ticker = gtk_type_new (GTK_TYPE_TICKER); | |
133 return GTK_WIDGET (ticker); | |
134 } | |
135 | |
136 static void | |
137 gtk_ticker_put (GtkTicker *ticker, | |
138 GtkWidget *widget) | |
139 { | |
140 GtkTickerChild *child_info; | |
141 | |
142 g_return_if_fail (ticker != NULL); | |
143 g_return_if_fail (GTK_IS_TICKER (ticker)); | |
144 g_return_if_fail (widget != NULL); | |
145 | |
146 child_info = g_new(GtkTickerChild, 1); | |
147 child_info->widget = widget; | |
148 child_info->x = 0; | |
149 | |
150 gtk_widget_set_parent(widget, GTK_WIDGET (ticker)); | |
151 | |
152 ticker->children = g_list_append (ticker->children, child_info); | |
153 | |
154 if (GTK_WIDGET_REALIZED (ticker)) | |
155 gtk_widget_realize (widget); | |
156 | |
157 if (GTK_WIDGET_VISIBLE (ticker) && GTK_WIDGET_VISIBLE (widget)) | |
158 { | |
159 if (GTK_WIDGET_MAPPED (ticker)) | |
160 gtk_widget_map (widget); | |
161 | |
162 gtk_widget_queue_resize (GTK_WIDGET (ticker)); | |
163 } | |
164 } | |
165 | |
166 void | |
167 gtk_ticker_set_interval (GtkTicker *ticker, gint interval ) | |
168 { | |
169 g_return_if_fail (ticker != NULL); | |
170 g_return_if_fail (GTK_IS_TICKER (ticker)); | |
171 | |
172 if ( interval < 0 ) | |
173 interval = 200; | |
174 ticker->interval = interval; | |
175 | |
176 } | |
177 | |
178 guint | |
179 gtk_ticker_get_interval (GtkTicker *ticker ) | |
180 { | |
181 g_return_val_if_fail (ticker != NULL, -1); | |
182 g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); | |
183 | |
184 return ticker->interval; | |
185 } | |
186 | |
187 void | |
188 gtk_ticker_set_scootch (GtkTicker *ticker, gint scootch ) | |
189 { | |
190 g_return_if_fail (ticker != NULL); | |
191 g_return_if_fail (GTK_IS_TICKER (ticker)); | |
192 | |
193 if ( scootch <= 0 ) | |
194 scootch = 2; | |
195 ticker->scootch = scootch; | |
196 ticker->dirty = TRUE; | |
197 } | |
198 | |
199 guint | |
200 gtk_ticker_get_scootch (GtkTicker *ticker ) | |
201 { | |
202 g_return_val_if_fail (ticker != NULL, -1); | |
203 g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); | |
204 | |
205 return ticker->scootch; | |
206 } | |
207 | |
208 void | |
209 gtk_ticker_set_spacing (GtkTicker *ticker, gint spacing ) | |
210 { | |
211 g_return_if_fail (ticker != NULL); | |
212 g_return_if_fail (GTK_IS_TICKER (ticker)); | |
213 | |
214 if ( spacing < 0 ) | |
215 spacing = 0; | |
216 ticker->spacing = spacing; | |
217 ticker->dirty = TRUE; | |
218 | |
219 } | |
220 | |
221 static int | |
222 ticker_timeout( gpointer data ) | |
223 { | |
224 GtkTicker *ticker = (GtkTicker *) data; | |
225 | |
226 if (GTK_WIDGET_VISIBLE (ticker)) | |
227 gtk_widget_queue_resize (GTK_WIDGET (ticker)); | |
228 | |
229 return( TRUE ); | |
230 } | |
231 | |
232 void | |
233 gtk_ticker_start_scroll(GtkTicker *ticker) | |
234 { | |
235 g_return_if_fail (ticker != NULL); | |
236 g_return_if_fail (GTK_IS_TICKER (ticker)); | |
237 if ( ticker->timer != 0 ) | |
238 return; | |
4168 | 239 ticker->timer = g_timeout_add(ticker->interval, |
430 | 240 ticker_timeout, ticker); |
241 } | |
242 | |
243 void | |
244 gtk_ticker_stop_scroll(GtkTicker *ticker) | |
245 { | |
246 g_return_if_fail (ticker != NULL); | |
247 g_return_if_fail (GTK_IS_TICKER (ticker)); | |
248 if ( ticker->timer == 0 ) | |
249 return; | |
4168 | 250 g_source_remove(ticker->timer); |
430 | 251 ticker->timer = 0; |
252 | |
253 } | |
254 | |
255 guint | |
256 gtk_ticker_get_spacing (GtkTicker *ticker ) | |
257 { | |
258 g_return_val_if_fail (ticker != NULL, -1); | |
259 g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); | |
260 | |
261 return ticker->spacing; | |
262 } | |
263 | |
264 static void | |
265 gtk_ticker_map (GtkWidget *widget) | |
266 { | |
267 GtkTicker *ticker; | |
268 GtkTickerChild *child; | |
269 GList *children; | |
270 | |
271 g_return_if_fail (widget != NULL); | |
272 g_return_if_fail (GTK_IS_TICKER (widget)); | |
273 | |
274 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); | |
275 ticker = GTK_TICKER (widget); | |
276 | |
277 children = ticker->children; | |
278 while (children) | |
279 { | |
280 child = children->data; | |
281 children = children->next; | |
282 | |
283 if (GTK_WIDGET_VISIBLE (child->widget) && | |
284 !GTK_WIDGET_MAPPED (child->widget)) | |
285 gtk_widget_map (child->widget); | |
286 } | |
287 | |
288 gdk_window_show (widget->window); | |
289 } | |
290 | |
291 static void | |
292 gtk_ticker_realize (GtkWidget *widget) | |
293 { | |
294 GdkWindowAttr attributes; | |
295 gint attributes_mask; | |
296 | |
297 g_return_if_fail (widget != NULL); | |
298 g_return_if_fail (GTK_IS_TICKER (widget)); | |
299 | |
300 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); | |
301 | |
302 attributes.window_type = GDK_WINDOW_CHILD; | |
303 attributes.x = widget->allocation.x; | |
304 attributes.y = widget->allocation.y; | |
305 attributes.width = widget->allocation.width; | |
306 attributes.height = widget->allocation.height; | |
307 attributes.wclass = GDK_INPUT_OUTPUT; | |
308 attributes.visual = gtk_widget_get_visual (widget); | |
309 attributes.colormap = gtk_widget_get_colormap (widget); | |
310 attributes.event_mask = gtk_widget_get_events (widget); | |
311 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK; | |
312 | |
313 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; | |
314 | |
315 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), | |
316 &attributes, attributes_mask); | |
317 gdk_window_set_user_data (widget->window, widget); | |
318 | |
319 widget->style = gtk_style_attach (widget->style, widget->window); | |
320 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); | |
321 } | |
322 | |
323 static void | |
324 gtk_ticker_size_request (GtkWidget *widget, | |
325 GtkRequisition *requisition) | |
326 { | |
327 GtkTicker *ticker; | |
328 GtkTickerChild *child; | |
329 GList *children; | |
330 GtkRequisition child_requisition; | |
331 | |
332 g_return_if_fail (widget != NULL); | |
333 g_return_if_fail (GTK_IS_TICKER (widget)); | |
334 g_return_if_fail (requisition != NULL); | |
335 | |
336 ticker = GTK_TICKER (widget); | |
337 requisition->width = 0; | |
338 requisition->height = 0; | |
339 | |
340 children = ticker->children; | |
341 while (children) | |
342 { | |
343 child = children->data; | |
344 children = children->next; | |
345 | |
346 if (GTK_WIDGET_VISIBLE (child->widget)) | |
347 { | |
348 gtk_widget_size_request (child->widget, &child_requisition); | |
349 | |
350 requisition->height = MAX (requisition->height, | |
351 child_requisition.height); | |
352 requisition->width += child_requisition.width + ticker->spacing; | |
353 } | |
354 } | |
355 if ( requisition->width > ticker->spacing ) | |
356 requisition->width -= ticker->spacing; | |
357 | |
358 requisition->height += GTK_CONTAINER (ticker)->border_width * 2; | |
359 requisition->width += GTK_CONTAINER (ticker)->border_width * 2; | |
360 } | |
361 | |
362 static void | |
363 gtk_ticker_compute_offsets (GtkTicker *ticker) | |
364 { | |
365 GtkTickerChild *child; | |
366 GtkRequisition child_requisition; | |
367 GList *children; | |
368 guint16 border_width; | |
369 | |
370 g_return_if_fail (ticker != NULL); | |
371 g_return_if_fail (GTK_IS_TICKER(ticker)); | |
372 | |
373 border_width = GTK_CONTAINER (ticker)->border_width; | |
374 | |
375 ticker->width = GTK_WIDGET(ticker)->allocation.width; | |
376 ticker->total = 0; | |
377 children = ticker->children; | |
378 while (children) { | |
379 child = children->data; | |
380 | |
381 child->x = 0; | |
382 if (GTK_WIDGET_VISIBLE (child->widget)) { | |
383 gtk_widget_get_child_requisition (child->widget, &child_requisition); | |
384 child->offset = ticker->total; | |
385 ticker->total += | |
386 child_requisition.width + border_width + ticker->spacing; | |
387 } | |
388 children = children->next; | |
389 } | |
390 ticker->dirty = FALSE; | |
391 } | |
392 | |
393 static void | |
394 gtk_ticker_size_allocate (GtkWidget *widget, | |
395 GtkAllocation *allocation) | |
396 { | |
397 GtkTicker *ticker; | |
398 GtkTickerChild *child; | |
399 GtkAllocation child_allocation; | |
400 GtkRequisition child_requisition; | |
401 GList *children; | |
402 guint16 border_width; | |
403 | |
404 g_return_if_fail (widget != NULL); | |
405 g_return_if_fail (GTK_IS_TICKER(widget)); | |
406 g_return_if_fail (allocation != NULL); | |
407 | |
408 ticker = GTK_TICKER (widget); | |
409 | |
410 if ( GTK_WIDGET(ticker)->allocation.width != ticker->width ) | |
411 ticker->dirty = TRUE; | |
412 | |
413 if ( ticker->dirty == TRUE ) { | |
414 gtk_ticker_compute_offsets( ticker ); | |
415 } | |
416 | |
417 widget->allocation = *allocation; | |
418 if (GTK_WIDGET_REALIZED (widget)) | |
419 gdk_window_move_resize (widget->window, | |
420 allocation->x, | |
421 allocation->y, | |
422 allocation->width, | |
423 allocation->height); | |
424 | |
425 border_width = GTK_CONTAINER (ticker)->border_width; | |
426 | |
427 children = ticker->children; | |
428 while (children) | |
429 { | |
430 child = children->data; | |
431 child->x -= ticker->scootch; | |
432 | |
433 if (GTK_WIDGET_VISIBLE (child->widget)) { | |
434 gtk_widget_get_child_requisition (child->widget, &child_requisition); | |
435 child_allocation.width = child_requisition.width; | |
436 child_allocation.x = child->offset + border_width + child->x; | |
437 if ( ( child_allocation.x + child_allocation.width ) < GTK_WIDGET(ticker)->allocation.x ) { | |
438 if ( ticker->total >= GTK_WIDGET(ticker)->allocation.width ) { | |
439 child->x += GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width + ( ticker->total - ( GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width ) ); | |
440 } | |
441 else { | |
442 child->x += GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width; | |
443 } | |
444 } | |
445 child_allocation.y = border_width; | |
446 child_allocation.height = child_requisition.height; | |
447 gtk_widget_size_allocate (child->widget, &child_allocation); | |
448 } | |
449 children = children->next; | |
450 } | |
451 } | |
452 | |
453 static void | |
454 gtk_ticker_paint (GtkWidget *widget, | |
455 GdkRectangle *area) | |
456 { | |
457 g_return_if_fail (widget != NULL); | |
458 g_return_if_fail (GTK_IS_TICKER (widget)); | |
459 g_return_if_fail (area != NULL); | |
460 | |
461 if (GTK_WIDGET_DRAWABLE (widget)) | |
462 gdk_window_clear_area (widget->window, 0, 0, widget->allocation.width, | |
463 widget->allocation.height); | |
464 } | |
465 | |
466 static void | |
467 gtk_ticker_draw (GtkWidget *widget, | |
468 GdkRectangle *area) | |
469 { | |
470 GtkTicker *ticker; | |
471 GtkTickerChild *child; | |
472 GList *children; | |
473 | |
474 g_return_if_fail (widget != NULL); | |
475 g_return_if_fail (GTK_IS_TICKER (widget)); | |
476 | |
477 if (GTK_WIDGET_DRAWABLE (widget)) | |
478 { | |
479 ticker = GTK_TICKER (widget); | |
480 gtk_ticker_paint (widget, area); | |
481 | |
482 children = ticker->children; | |
483 while (children) | |
484 { | |
485 child = children->data; | |
486 children = children->next; | |
487 gtk_widget_draw (child->widget, NULL); | |
488 } | |
489 } | |
490 } | |
491 | |
492 static gint | |
493 gtk_ticker_expose (GtkWidget *widget, GdkEventExpose *event) | |
494 { | |
495 GtkTicker *ticker; | |
496 GtkTickerChild *child; | |
497 GdkEventExpose child_event; | |
498 GList *children; | |
499 | |
500 g_return_val_if_fail (widget != NULL, FALSE); | |
501 g_return_val_if_fail (GTK_IS_TICKER (widget), FALSE); | |
502 g_return_val_if_fail (event != NULL, FALSE); | |
503 | |
504 if (GTK_WIDGET_DRAWABLE (widget)) | |
505 { | |
506 ticker = GTK_TICKER (widget); | |
507 | |
508 child_event = *event; | |
509 | |
510 children = ticker->children; | |
511 while (children) | |
512 { | |
513 child = children->data; | |
514 children = children->next; | |
515 | |
516 if (GTK_WIDGET_NO_WINDOW (child->widget) && | |
517 gtk_widget_intersect (child->widget, &event->area, | |
518 &child_event.area)) | |
519 gtk_widget_event (child->widget, (GdkEvent*) &child_event); | |
520 } | |
521 } | |
522 | |
523 return FALSE; | |
524 } | |
525 | |
526 void | |
527 gtk_ticker_add(GtkTicker *ticker, GtkWidget *widget) | |
528 { | |
529 gtk_ticker_add_real( GTK_CONTAINER( ticker ), widget ); | |
530 ticker->dirty = TRUE; | |
531 } | |
532 | |
533 void | |
534 gtk_ticker_remove(GtkTicker *ticker, GtkWidget *widget) | |
535 { | |
536 gtk_ticker_remove_real( GTK_CONTAINER( ticker ), widget ); | |
537 ticker->dirty = TRUE; | |
538 } | |
539 | |
540 static void | |
541 gtk_ticker_add_real(GtkContainer *container, | |
542 GtkWidget *widget) | |
543 { | |
544 g_return_if_fail (container != NULL); | |
545 g_return_if_fail (GTK_IS_TICKER (container)); | |
546 g_return_if_fail (widget != NULL); | |
547 | |
548 gtk_ticker_put(GTK_TICKER (container), widget); | |
549 } | |
550 | |
551 static void | |
552 gtk_ticker_remove_real(GtkContainer *container, | |
553 GtkWidget *widget) | |
554 { | |
555 GtkTicker *ticker; | |
556 GtkTickerChild *child; | |
557 GList *children; | |
558 | |
559 g_return_if_fail (container != NULL); | |
560 g_return_if_fail (GTK_IS_TICKER (container)); | |
561 g_return_if_fail (widget != NULL); | |
562 | |
563 ticker = GTK_TICKER (container); | |
564 | |
565 children = ticker->children; | |
566 while (children) | |
567 { | |
568 child = children->data; | |
569 | |
570 if (child->widget == widget) | |
571 { | |
572 gboolean was_visible = GTK_WIDGET_VISIBLE (widget); | |
573 | |
574 gtk_widget_unparent (widget); | |
575 | |
576 ticker->children = g_list_remove_link (ticker->children, children); | |
577 g_list_free (children); | |
578 g_free (child); | |
579 | |
580 if (was_visible && GTK_WIDGET_VISIBLE (container)) | |
581 gtk_widget_queue_resize (GTK_WIDGET (container)); | |
582 | |
583 break; | |
584 } | |
585 | |
586 children = children->next; | |
587 } | |
588 } | |
589 | |
590 static void | |
591 gtk_ticker_forall (GtkContainer *container, | |
592 gboolean include_internals, | |
593 GtkCallback callback, | |
594 gpointer callback_data) | |
595 { | |
596 GtkTicker *ticker; | |
597 GtkTickerChild *child; | |
598 GList *children; | |
599 | |
600 g_return_if_fail (container != NULL); | |
601 g_return_if_fail (GTK_IS_TICKER (container)); | |
602 g_return_if_fail (callback != NULL); | |
603 | |
604 ticker = GTK_TICKER (container); | |
605 | |
606 children = ticker->children; | |
607 while (children) | |
608 { | |
609 child = children->data; | |
610 children = children->next; | |
611 | |
612 (* callback) (child->widget, callback_data); | |
613 } | |
614 } |