Fixed wrong use of g_error()
[dia.git] / app / dynamic_refresh.c
blob1393367f13c1f4abc6b0719f6f2c9a8e14014596
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * List of "dynamic" (animated) objects, and their refresh rates
5 * Copyright (C) 2002 Cyrille Chépélov
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "dynamic_refresh.h"
22 #include "dynamic_obj.h"
23 #include "diagram.h"
24 #include "diagramdata.h"
25 #include "object_ops.h"
26 #include "app/connectionpoint_ops.h"
27 #include <glib.h>
29 static guint timeout = 0;
30 static guint idle_id = 0;
31 static guint timer_id = 0;
33 static void foreach_dynobj(DiaObject* obj, gpointer data) {
34 gboolean moved = FALSE;
35 GList* list = dia_open_diagrams();
37 while (list != NULL) {
38 Diagram* dia;
39 DiagramData* obj_ddata;
40 Layer* layer;
42 dia = (Diagram*)list->data;
43 list = g_list_next(list);
45 layer = dia_object_get_parent_layer(obj);
46 if (!layer) continue;
48 obj_ddata = layer_get_parent_diagram(layer);
49 if (!obj_ddata) continue;
51 if (dia->data == obj_ddata) {
52 if (!moved) {
53 obj->ops->move(obj,&obj->position);
54 moved = TRUE;
56 object_add_updates(obj,dia);
57 diagram_update_connections_object(dia,obj, TRUE);
62 static gboolean timer_handler(gpointer data) {
63 GList* list;
65 dynobj_list_foreach(foreach_dynobj,data);
67 list = dia_open_diagrams();
68 while (list != NULL) {
69 Diagram* dia = (Diagram*)list->data;
70 list = g_list_next(list);
72 diagram_flush(dia);
75 dynobj_refresh_kick();
76 return TRUE;
79 static gboolean idle_handler(gpointer data) {
80 guint new_timeout;
82 new_timeout = dynobj_list_get_dynobj_rate();
83 if (timeout != new_timeout) {
84 if (timer_id) {
85 gtk_timeout_remove(timer_id);
86 timer_id = 0;
88 timeout = new_timeout;
89 if (timeout) {
90 timer_id = gtk_timeout_add(timeout,timer_handler,NULL);
93 idle_id = 0;
94 return FALSE;
97 void dynobj_refresh_kick(void) {
98 if (!idle_id)
99 idle_id = gtk_idle_add_priority(GTK_PRIORITY_LOW,idle_handler,NULL);
102 void dynobj_refresh_init(void) {
103 /* NOP */
106 void dynobj_refresh_finish(void) {
107 if (timer_id) gtk_timeout_remove(timer_id);
108 if (idle_id) gtk_idle_remove(idle_id);