comparison gtk3/dw.c @ 1892:c4a6ef8291be

Fix deprecation warnings by switching to newly available methods for 3.10. Also avoid unfixable deprecation warnings about gdk_threads_*() by using dlsym() to load those functions and call them without warnings.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 17 Oct 2013 22:59:53 +0000
parents 11a16c117748
children ed377fd16360
comparison
equal deleted inserted replaced
1891:11a16c117748 1892:c4a6ef8291be
7 * (C) 2003-2011 Mark Hessling <mark@rexx.org> 7 * (C) 2003-2011 Mark Hessling <mark@rexx.org>
8 * (C) 2002 Nickolay V. Shmyrev <shmyrev@yandex.ru> 8 * (C) 2002 Nickolay V. Shmyrev <shmyrev@yandex.ru>
9 */ 9 */
10 #include "config.h" 10 #include "config.h"
11 #include "dw.h" 11 #include "dw.h"
12 #include <glib/gi18n.h>
12 #include <string.h> 13 #include <string.h>
13 #include <stdlib.h> 14 #include <stdlib.h>
14 #if !defined(GDK_WINDOWING_WIN32) 15 #if !defined(GDK_WINDOWING_WIN32)
15 # include <sys/utsname.h> 16 # include <sys/utsname.h>
16 # include <sys/socket.h> 17 # include <sys/socket.h>
119 GtkWidget *last_window = NULL, *popup = NULL; 120 GtkWidget *last_window = NULL, *popup = NULL;
120 121
121 static int _dw_ignore_click = 0, _dw_ignore_expand = 0; 122 static int _dw_ignore_click = 0, _dw_ignore_expand = 0;
122 static pthread_t _dw_thread = (pthread_t)-1; 123 static pthread_t _dw_thread = (pthread_t)-1;
123 124
124 #define DW_MUTEX_LOCK { if(pthread_self() != _dw_thread && !pthread_getspecific(_dw_mutex_key)) { gdk_threads_enter(); pthread_setspecific(_dw_mutex_key, (void *)1); _locked_by_me = TRUE; } } 125 void (*_dw_gdk_threads_init)(void) = NULL;
125 #define DW_MUTEX_UNLOCK { if(pthread_self() != _dw_thread && _locked_by_me == TRUE) { gdk_threads_leave(); pthread_setspecific(_dw_mutex_key, NULL); _locked_by_me = FALSE; } } 126 void (*_dw_gdk_threads_enter)(void) = NULL;
127 void (*_dw_gdk_threads_leave)(void) = NULL;
128
129 #define DW_MUTEX_LOCK { if(pthread_self() != _dw_thread && !pthread_getspecific(_dw_mutex_key)) { _dw_gdk_threads_enter(); pthread_setspecific(_dw_mutex_key, (void *)1); _locked_by_me = TRUE; } }
130 #define DW_MUTEX_UNLOCK { if(pthread_self() != _dw_thread && _locked_by_me == TRUE) { _dw_gdk_threads_leave(); pthread_setspecific(_dw_mutex_key, NULL); _locked_by_me = FALSE; } }
126 131
127 #define DEFAULT_SIZE_WIDTH 12 132 #define DEFAULT_SIZE_WIDTH 12
128 #define DEFAULT_SIZE_HEIGHT 6 133 #define DEFAULT_SIZE_HEIGHT 6
129 #define DEFAULT_TITLEBAR_HEIGHT 22 134 #define DEFAULT_TITLEBAR_HEIGHT 22
130 135
1860 _dw_share_path[0] = '/'; 1865 _dw_share_path[0] = '/';
1861 1866
1862 #if !GLIB_CHECK_VERSION(2,31,0) 1867 #if !GLIB_CHECK_VERSION(2,31,0)
1863 g_thread_init(NULL); 1868 g_thread_init(NULL);
1864 #endif 1869 #endif
1865 gdk_threads_init(); 1870
1871 /* Load these functions via dlsym to avoid deprecation warnings */
1872 _dw_gdk_threads_init = dlsym(RTLD_DEFAULT, "gdk_threads_init");
1873 _dw_gdk_threads_enter = dlsym(RTLD_DEFAULT, "gdk_threads_enter");
1874 _dw_gdk_threads_leave = dlsym(RTLD_DEFAULT, "gdk_threads_leave");
1875
1876 _dw_gdk_threads_init();
1866 1877
1867 gtk_init(argc, argv); 1878 gtk_init(argc, argv);
1868 1879
1869 pthread_key_create(&_dw_fg_color_key, NULL); 1880 pthread_key_create(&_dw_fg_color_key, NULL);
1870 pthread_key_create(&_dw_bg_color_key, NULL); 1881 pthread_key_create(&_dw_bg_color_key, NULL);
1885 /* 1896 /*
1886 * Runs a message loop for Dynamic Windows. 1897 * Runs a message loop for Dynamic Windows.
1887 */ 1898 */
1888 void API dw_main(void) 1899 void API dw_main(void)
1889 { 1900 {
1890 gdk_threads_enter(); 1901 _dw_gdk_threads_enter();
1891 _dw_thread = pthread_self(); 1902 _dw_thread = pthread_self();
1892 gtk_main(); 1903 gtk_main();
1893 _dw_thread = (pthread_t)-1; 1904 _dw_thread = (pthread_t)-1;
1894 gdk_threads_leave(); 1905 _dw_gdk_threads_leave();
1895 } 1906 }
1896 1907
1897 /* 1908 /*
1898 * Causes running dw_main() to return. 1909 * Causes running dw_main() to return.
1899 */ 1910 */
1926 1937
1927 if(orig == (pthread_t)-1) 1938 if(orig == (pthread_t)-1)
1928 { 1939 {
1929 if(!pthread_getspecific(_dw_mutex_key)) 1940 if(!pthread_getspecific(_dw_mutex_key))
1930 { 1941 {
1931 gdk_threads_enter(); 1942 _dw_gdk_threads_enter();
1932 pthread_setspecific(_dw_mutex_key, (void *)1); 1943 pthread_setspecific(_dw_mutex_key, (void *)1);
1933 _locked_by_me = TRUE; 1944 _locked_by_me = TRUE;
1934 } 1945 }
1935 _dw_thread = curr; 1946 _dw_thread = curr;
1936 } 1947 }
1942 { 1953 {
1943 _dw_thread = orig; 1954 _dw_thread = orig;
1944 if(_locked_by_me) 1955 if(_locked_by_me)
1945 { 1956 {
1946 pthread_setspecific(_dw_mutex_key, NULL); 1957 pthread_setspecific(_dw_mutex_key, NULL);
1947 gdk_threads_leave(); 1958 _dw_gdk_threads_leave();
1948 } 1959 }
1949 } 1960 }
1950 gettimeofday(&tv, NULL); 1961 gettimeofday(&tv, NULL);
1951 } 1962 }
1952 } 1963 }
1965 1976
1966 if(_dw_thread == (pthread_t)-1) 1977 if(_dw_thread == (pthread_t)-1)
1967 { 1978 {
1968 if(!pthread_getspecific(_dw_mutex_key)) 1979 if(!pthread_getspecific(_dw_mutex_key))
1969 { 1980 {
1970 gdk_threads_enter(); 1981 _dw_gdk_threads_enter();
1971 pthread_setspecific(_dw_mutex_key, (void *)1); 1982 pthread_setspecific(_dw_mutex_key, (void *)1);
1972 _locked_by_me = TRUE; 1983 _locked_by_me = TRUE;
1973 } 1984 }
1974 _dw_thread = curr; 1985 _dw_thread = curr;
1975 } 1986 }
1981 { 1992 {
1982 _dw_thread = orig; 1993 _dw_thread = orig;
1983 if(_locked_by_me) 1994 if(_locked_by_me)
1984 { 1995 {
1985 pthread_setspecific(_dw_mutex_key, NULL); 1996 pthread_setspecific(_dw_mutex_key, NULL);
1986 gdk_threads_leave(); 1997 _dw_gdk_threads_leave();
1987 } 1998 }
1988 } 1999 }
1989 } 2000 }
1990 2001
1991 /* 2002 /*
2055 /* _dw_thread will be -1 if dw_main hasn't been run yet. */ 2066 /* _dw_thread will be -1 if dw_main hasn't been run yet. */
2056 if(_dw_thread == (pthread_t)-1) 2067 if(_dw_thread == (pthread_t)-1)
2057 { 2068 {
2058 _dw_thread = pthread_self(); 2069 _dw_thread = pthread_self();
2059 newprocess = 1; 2070 newprocess = 1;
2060 gdk_threads_enter(); 2071 _dw_gdk_threads_enter();
2061 } 2072 }
2062 2073
2063 if(pthread_self() == _dw_thread) 2074 if(pthread_self() == _dw_thread)
2064 { 2075 {
2065 dialog->method = TRUE; 2076 dialog->method = TRUE;
2072 } 2083 }
2073 2084
2074 if(newprocess) 2085 if(newprocess)
2075 { 2086 {
2076 _dw_thread = (pthread_t)-1; 2087 _dw_thread = (pthread_t)-1;
2077 gdk_threads_leave(); 2088 _dw_gdk_threads_leave();
2078 } 2089 }
2079 2090
2080 dw_event_close(&dialog->eve); 2091 dw_event_close(&dialog->eve);
2081 tmp = dialog->result; 2092 tmp = dialog->result;
2082 free(dialog); 2093 free(dialog);
3058 g_object_set_data(G_OBJECT(box), "_dw_eventbox", (gpointer)eventbox); 3069 g_object_set_data(G_OBJECT(box), "_dw_eventbox", (gpointer)eventbox);
3059 g_object_set_data(G_OBJECT(box), "_dw_boxtype", GINT_TO_POINTER(type)); 3070 g_object_set_data(G_OBJECT(box), "_dw_boxtype", GINT_TO_POINTER(type));
3060 g_object_set_data(G_OBJECT(box), "_dw_boxpad", GINT_TO_POINTER(pad)); 3071 g_object_set_data(G_OBJECT(box), "_dw_boxpad", GINT_TO_POINTER(pad));
3061 g_object_set_data(G_OBJECT(tmp), "_dw_boxhandle", (gpointer)box); 3072 g_object_set_data(G_OBJECT(tmp), "_dw_boxhandle", (gpointer)box);
3062 3073
3074 #if GTK_CHECK_VERSION(3,8,0)
3075 gtk_container_add(GTK_CONTAINER(tmp), box);
3076 #else
3063 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(tmp),box); 3077 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(tmp),box);
3078 #endif
3064 g_object_set_data(G_OBJECT(tmp), "_dw_user", box); 3079 g_object_set_data(G_OBJECT(tmp), "_dw_user", box);
3065 gtk_widget_show(box); 3080 gtk_widget_show(box);
3066 gtk_widget_show(tmp); 3081 gtk_widget_show(tmp);
3067 3082
3068 DW_MUTEX_UNLOCK; 3083 DW_MUTEX_UNLOCK;
3648 3663
3649 GtkWidget *_tree_setup(GtkWidget *tmp, GtkTreeModel *store) 3664 GtkWidget *_tree_setup(GtkWidget *tmp, GtkTreeModel *store)
3650 { 3665 {
3651 GtkWidget *tree = gtk_tree_view_new_with_model(store); 3666 GtkWidget *tree = gtk_tree_view_new_with_model(store);
3652 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), FALSE); 3667 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), FALSE);
3668 #if GTK_CHECK_VERSION(3,8,0)
3669 gtk_container_add(GTK_CONTAINER(tmp), tree);
3670 #else
3653 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(tmp), tree); 3671 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(tmp), tree);
3672 #endif
3654 g_object_set_data(G_OBJECT(tmp), "_dw_user", (gpointer)tree); 3673 g_object_set_data(G_OBJECT(tmp), "_dw_user", (gpointer)tree);
3655 return tree; 3674 return tree;
3656 } 3675 }
3657 3676
3658 /* 3677 /*
7848 { 7867 {
7849 /* If we are being called from an event handler we must release 7868 /* If we are being called from an event handler we must release
7850 * the GTK mutex so we don't deadlock. 7869 * the GTK mutex so we don't deadlock.
7851 */ 7870 */
7852 if(pthread_self() == _dw_thread) 7871 if(pthread_self() == _dw_thread)
7853 gdk_threads_leave(); 7872 _dw_gdk_threads_leave();
7854 7873
7855 pthread_mutex_lock(mutex); 7874 pthread_mutex_lock(mutex);
7856 7875
7857 /* And of course relock it when we have acquired the mutext */ 7876 /* And of course relock it when we have acquired the mutext */
7858 if(pthread_self() == _dw_thread) 7877 if(pthread_self() == _dw_thread)
7859 gdk_threads_enter(); 7878 _dw_gdk_threads_enter();
7860 } 7879 }
7861 7880
7862 /* 7881 /*
7863 * Tries to gain access to the semaphore. 7882 * Tries to gain access to the semaphore.
7864 * Parameters: 7883 * Parameters:
10705 10724
10706 switch (flags ) 10725 switch (flags )
10707 { 10726 {
10708 case DW_DIRECTORY_OPEN: 10727 case DW_DIRECTORY_OPEN:
10709 action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; 10728 action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
10710 button = GTK_STOCK_OPEN; 10729 button = _("_Open");
10711 break; 10730 break;
10712 case DW_FILE_OPEN: 10731 case DW_FILE_OPEN:
10713 action = GTK_FILE_CHOOSER_ACTION_OPEN; 10732 action = GTK_FILE_CHOOSER_ACTION_OPEN;
10714 button = GTK_STOCK_OPEN; 10733 button = _("_Open");
10715 break; 10734 break;
10716 case DW_FILE_SAVE: 10735 case DW_FILE_SAVE:
10717 action = GTK_FILE_CHOOSER_ACTION_SAVE; 10736 action = GTK_FILE_CHOOSER_ACTION_SAVE;
10718 button = GTK_STOCK_SAVE; 10737 button = _("_Save");
10719 break; 10738 break;
10720 default: 10739 default:
10721 dw_messagebox( "Coding error", DW_MB_OK|DW_MB_ERROR, "dw_file_browse() flags argument invalid."); 10740 dw_messagebox( "Coding error", DW_MB_OK|DW_MB_ERROR, "dw_file_browse() flags argument invalid.");
10722 return NULL; 10741 return NULL;
10723 break; 10742 break;
10724 } 10743 }
10725 10744
10726 filew = gtk_file_chooser_dialog_new ( title, 10745 filew = gtk_file_chooser_dialog_new ( title,
10727 NULL, 10746 NULL,
10728 action, 10747 action,
10729 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 10748 _("_Cancel"), GTK_RESPONSE_CANCEL,
10730 button, GTK_RESPONSE_ACCEPT, 10749 button, GTK_RESPONSE_ACCEPT,
10731 NULL); 10750 NULL);
10732 10751
10733 if ( flags == DW_FILE_SAVE ) 10752 if ( flags == DW_FILE_SAVE )
10734 gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER( filew ), TRUE ); 10753 gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER( filew ), TRUE );
11033 * We add a "Print" menu item to enable printing 11052 * We add a "Print" menu item to enable printing
11034 * user_data is not used 11053 * user_data is not used
11035 */ 11054 */
11036 static void _dw_html_populate_popup_cb( WebKitWebView *web_view, GtkMenu *menu, gpointer user_data ) 11055 static void _dw_html_populate_popup_cb( WebKitWebView *web_view, GtkMenu *menu, gpointer user_data )
11037 { 11056 {
11038 GtkWidget *image = gtk_image_new_from_stock( GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU ); 11057 GtkWidget *item = gtk_menu_item_new_with_mnemonic( _("_Print") );
11039 GtkWidget *item = gtk_image_menu_item_new_with_label( "Print" ); 11058
11040
11041 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(item), image );
11042 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); 11059 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
11043 g_signal_connect( item, "activate", G_CALLBACK(_dw_html_print_cb), web_view ); 11060 g_signal_connect( item, "activate", G_CALLBACK(_dw_html_print_cb), web_view );
11044 gtk_widget_show(item); 11061 gtk_widget_show(item);
11045 } 11062 }
11046 #endif 11063 #endif