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