comparison gtk3/dw.c @ 874:18eab415ff0c

Rewrote the timers for GTK3. Due to the removal of the timer remove by ID function.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 06 Apr 2011 05:37:13 +0000
parents 8f2722696a8e
children e1afa43261d9
comparison
equal deleted inserted replaced
873:fe7a8dc9392c 874:18eab415ff0c
220 unsigned long width, height; 220 unsigned long width, height;
221 } DWPrivatePixmap; 221 } DWPrivatePixmap;
222 222
223 static DWPrivatePixmap *_PixmapArray = NULL; 223 static DWPrivatePixmap *_PixmapArray = NULL;
224 static int _PixmapCount = 0; 224 static int _PixmapCount = 0;
225 GObject *_DWObject = NULL;
225 226
226 typedef struct 227 typedef struct
227 { 228 {
228 void *func; 229 void *func;
229 char name[30]; 230 char name[30];
2086 if(tmp) 2087 if(tmp)
2087 _dw_border_height = atoi(tmp); 2088 _dw_border_height = atoi(tmp);
2088 2089
2089 for(z=0;z<DW_THREAD_LIMIT;z++) 2090 for(z=0;z<DW_THREAD_LIMIT;z++)
2090 _dw_thread_list[z] = (DWTID)-1; 2091 _dw_thread_list[z] = (DWTID)-1;
2092
2093 /* Create a global object for glib activities */
2094 _DWObject = g_object_new(G_TYPE_OBJECT, NULL);
2091 2095
2092 gtk_rc_parse_string("style \"gtk-tooltips-style\" { bg[NORMAL] = \"#eeee00\" } widget \"gtk-tooltips\" style \"gtk-tooltips-style\""); 2096 gtk_rc_parse_string("style \"gtk-tooltips-style\" { bg[NORMAL] = \"#eeee00\" } widget \"gtk-tooltips\" style \"gtk-tooltips-style\"");
2093 2097
2094 #ifdef USE_GTKMOZEMBED 2098 #ifdef USE_GTKMOZEMBED
2095 init_mozembed(); 2099 init_mozembed();
10353 ret = (void *)g_object_get_data(G_OBJECT(thiswindow), dataname); 10357 ret = (void *)g_object_get_data(G_OBJECT(thiswindow), dataname);
10354 DW_MUTEX_UNLOCK; 10358 DW_MUTEX_UNLOCK;
10355 return ret; 10359 return ret;
10356 } 10360 }
10357 10361
10362 /* Internal function to get the state of the timer before firing */
10363 gboolean _dw_timer_func(gpointer data)
10364 {
10365 void (*sigfunc)(void *data) = NULL;
10366 void *sdata;
10367 char tmpbuf[30];
10368 int *tag = data;
10369
10370 if(tag)
10371 {
10372 snprintf(tmpbuf, 30, "_dw_timer%d", *tag);
10373 sigfunc = g_object_get_data(G_OBJECT(_DWObject), tmpbuf);
10374 snprintf(tmpbuf, 30, "_dw_timerdata%d", *tag);
10375 sdata = g_object_get_data(G_OBJECT(_DWObject), tmpbuf);
10376 }
10377 if(!sigfunc)
10378 {
10379 if(tag)
10380 free(tag);
10381 return FALSE;
10382 }
10383 sigfunc(sdata);
10384 return TRUE;
10385 }
10386
10358 /* 10387 /*
10359 * Add a callback to a timer event. 10388 * Add a callback to a timer event.
10360 * Parameters: 10389 * Parameters:
10361 * interval: Milliseconds to delay between calls. 10390 * interval: Milliseconds to delay between calls.
10362 * sigfunc: The pointer to the function to be used as the callback. 10391 * sigfunc: The pointer to the function to be used as the callback.
10364 * Returns: 10393 * Returns:
10365 * Timer ID for use with dw_timer_disconnect(), 0 on error. 10394 * Timer ID for use with dw_timer_disconnect(), 0 on error.
10366 */ 10395 */
10367 int API dw_timer_connect(int interval, void *sigfunc, void *data) 10396 int API dw_timer_connect(int interval, void *sigfunc, void *data)
10368 { 10397 {
10369 int tag, _locked_by_me = FALSE; 10398 int *tag, _locked_by_me = FALSE;
10370 10399 char tmpbuf[30];
10371 DW_MUTEX_LOCK; 10400
10372 tag = g_timeout_add(interval, (GSourceFunc)sigfunc, data); 10401 tag = calloc(1, sizeof(int));
10373 DW_MUTEX_UNLOCK; 10402
10374 return tag; 10403 DW_MUTEX_LOCK;
10404 *tag = g_timeout_add(interval, (GSourceFunc)_dw_timer_func, (gpointer)tag);
10405 snprintf(tmpbuf, 30, "_dw_timer%d", *tag);
10406 g_object_set_data(G_OBJECT(_DWObject), tmpbuf, sigfunc);
10407 snprintf(tmpbuf, 30, "_dw_timerdata%d", *tag);
10408 g_object_set_data(G_OBJECT(_DWObject), tmpbuf, data);
10409 DW_MUTEX_UNLOCK;
10410 return *tag;
10375 } 10411 }
10376 10412
10377 /* 10413 /*
10378 * Removes timer callback. 10414 * Removes timer callback.
10379 * Parameters: 10415 * Parameters:
10380 * id: Timer ID returned by dw_timer_connect(). 10416 * id: Timer ID returned by dw_timer_connect().
10381 */ 10417 */
10382 void API dw_timer_disconnect(int id) 10418 void API dw_timer_disconnect(int id)
10383 { 10419 {
10384 #if 0 /* TODO: Can't remove by ID anymore apparently... 10420 int _locked_by_me = FALSE;
10385 * need to rewrite it to return FALSE from the signal handler to stop. 10421 char tmpbuf[20];
10386 */ 10422
10387 int _locked_by_me = FALSE; 10423 snprintf(tmpbuf, 20, "_dw_timer%d", id);
10388 10424 DW_MUTEX_LOCK;
10389 DW_MUTEX_LOCK; 10425 g_object_set_data(G_OBJECT(_DWObject), tmpbuf, NULL);
10390 g_timeout_remove(id); 10426 DW_MUTEX_UNLOCK;
10391 DW_MUTEX_UNLOCK;
10392 #endif
10393 } 10427 }
10394 10428
10395 /* Get the actual signal window handle not the user window handle 10429 /* Get the actual signal window handle not the user window handle
10396 * Should mimic the code in dw_signal_connect() below. 10430 * Should mimic the code in dw_signal_connect() below.
10397 */ 10431 */