Mercurial > dwindows
comparison gtk/dw.c @ 2005:a17cc1958369
GTK: Added WebKit2 support for GTK3. Remove dead code from GTK2.
Use linker to pull in webkit libraries instead of dlopen() etc.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 06 Nov 2019 08:48:49 +0000 |
parents | 758f49e54566 |
children | 2dfce1ced00f |
comparison
equal
deleted
inserted
replaced
2004:ebbdb2120659 | 2005:a17cc1958369 |
---|---|
1 /* | 1 /* |
2 * Dynamic Windows: | 2 * Dynamic Windows: |
3 * A GTK like cross-platform GUI | 3 * A GTK like cross-platform GUI |
4 * GTK forwarder module for portabilty. | 4 * GTK forwarder module for portabilty. |
5 * | 5 * |
6 * (C) 2000-2017 Brian Smith <brian@dbsoft.org> | 6 * (C) 2000-2019 Brian Smith <brian@dbsoft.org> |
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" |
32 #include <gdk/gdkkeysyms.h> | 32 #include <gdk/gdkkeysyms.h> |
33 #ifdef USE_IMLIB | 33 #ifdef USE_IMLIB |
34 #include <gdk_imlib.h> | 34 #include <gdk_imlib.h> |
35 #endif | 35 #endif |
36 | 36 |
37 #ifdef USE_GTKMOZEMBED | |
38 # include <gtkmozembed.h> | |
39 # undef GTK_TYPE_MOZ_EMBED | |
40 # define GTK_TYPE_MOZ_EMBED (_dw_moz_embed_get_type()) | |
41 #endif | |
42 | |
43 #ifdef USE_LIBGTKHTML2 | |
44 # include <libgtkhtml/gtkhtml.h> | |
45 #endif | |
46 | |
47 #ifdef USE_WEBKIT | 37 #ifdef USE_WEBKIT |
48 # if defined(USE_WEBKIT10) || defined(USE_WEBKIT11) | 38 # if defined(USE_WEBKIT10) || defined(USE_WEBKIT11) |
49 # include <webkit/webkit.h> | 39 # include <webkit/webkit.h> |
50 # else | 40 # else |
51 # include <webkit.h> | 41 # include <webkit.h> |
66 | 56 |
67 #include "gtk/messagebox_error.xpm" | 57 #include "gtk/messagebox_error.xpm" |
68 #include "gtk/messagebox_warning.xpm" | 58 #include "gtk/messagebox_warning.xpm" |
69 #include "gtk/messagebox_information.xpm" | 59 #include "gtk/messagebox_information.xpm" |
70 #include "gtk/messagebox_question.xpm" | 60 #include "gtk/messagebox_question.xpm" |
71 | |
72 #ifdef USE_GTKMOZEMBED | |
73 extern gint mozilla_get_mouse_event_button(gpointer event); | |
74 extern gint mozilla_get_mouse_location( gpointer event, glong *x, glong *y); | |
75 #endif | |
76 | 61 |
77 /* These are used for resource management */ | 62 /* These are used for resource management */ |
78 #if defined(DW_RESOURCES) && !defined(BUILD_DLL) | 63 #if defined(DW_RESOURCES) && !defined(BUILD_DLL) |
79 extern DWResources _resources; | 64 extern DWResources _resources; |
80 #endif | 65 #endif |
176 static gint _tree_expand_event(GtkTreeItem *treeitem, gpointer data); | 161 static gint _tree_expand_event(GtkTreeItem *treeitem, gpointer data); |
177 #endif | 162 #endif |
178 static gint _switch_page_event(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer data); | 163 static gint _switch_page_event(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer data); |
179 static gint _column_click_event(GtkWidget *widget, gint column_num, gpointer data); | 164 static gint _column_click_event(GtkWidget *widget, gint column_num, gpointer data); |
180 static void _dw_signal_disconnect(gpointer data, GClosure *closure); | 165 static void _dw_signal_disconnect(gpointer data, GClosure *closure); |
181 | |
182 /* Embedable Mozilla functions*/ | |
183 #ifdef USE_GTKMOZEMBED | |
184 void (*_gtk_moz_embed_go_back)(GtkMozEmbed *) = NULL; | |
185 void (*_gtk_moz_embed_go_forward)(GtkMozEmbed *) = NULL; | |
186 void (*_gtk_moz_embed_load_url)(GtkMozEmbed *, const char *) = NULL; | |
187 void (*_gtk_moz_embed_reload)(GtkMozEmbed *, guint32) = NULL; | |
188 void (*_gtk_moz_embed_stop_load)(GtkMozEmbed *) = NULL; | |
189 void (*_gtk_moz_embed_render_data)(GtkMozEmbed *, const char *, guint32, const char *, const char *) = NULL; | |
190 GtkWidget *(*_gtk_moz_embed_new)(void) = NULL; | |
191 GtkType (*_dw_moz_embed_get_type)(void) = NULL; | |
192 gboolean (*_gtk_moz_embed_can_go_back)(GtkMozEmbed *) = NULL; | |
193 gboolean (*_gtk_moz_embed_can_go_forward)(GtkMozEmbed *) = NULL; | |
194 void (*_gtk_moz_embed_set_comp_path)(const char *) = NULL; | |
195 void (*_gtk_moz_embed_set_profile_path)(const char *, const char *) = NULL; | |
196 void (*_gtk_moz_embed_push_startup)(void) = NULL; | |
197 #endif | |
198 | |
199 #ifdef USE_LIBGTKHTML2 | |
200 GtkHtmlContext *(*_gtk_html_context_get)(void) = NULL; | |
201 HtmlDocument *(*_html_document_new)(void) = NULL; | |
202 GtkWidget *(*_html_view_new)(void) = NULL; | |
203 #endif | |
204 | 166 |
205 #ifdef USE_WEBKIT | 167 #ifdef USE_WEBKIT |
206 /* | 168 /* |
207 * we need to add these equivalents from webkitwebview.h so we can refer to | 169 * we need to add these equivalents from webkitwebview.h so we can refer to |
208 * our own pointers to functions (we don't link with the webkit libraries | 170 * our own pointers to functions (we don't link with the webkit libraries |
1981 XSetWMNormalHints (GDK_DISPLAY(),GDK_WINDOW_XWINDOW (GTK_WIDGET (window)->window),&sizehints); | 1943 XSetWMNormalHints (GDK_DISPLAY(),GDK_WINDOW_XWINDOW (GTK_WIDGET (window)->window),&sizehints); |
1982 gdk_flush (); | 1944 gdk_flush (); |
1983 } | 1945 } |
1984 #endif | 1946 #endif |
1985 | 1947 |
1986 /* Try to load the mozilla embed shared libary */ | |
1987 #ifdef USE_GTKMOZEMBED | |
1988 #include <ctype.h> | |
1989 | |
1990 void init_mozembed(void) | |
1991 { | |
1992 void *handle = NULL; | |
1993 gchar *profile; | |
1994 handle = dlopen( "libgtkembedmoz.so", RTLD_LAZY ); | |
1995 | |
1996 /* If we loaded it, grab the symbols we want */ | |
1997 if ( handle ) | |
1998 { | |
1999 _gtk_moz_embed_go_back = dlsym(handle, "gtk_moz_embed_go_back"); | |
2000 _gtk_moz_embed_go_forward = dlsym(handle, "gtk_moz_embed_go_forward"); | |
2001 _gtk_moz_embed_load_url = dlsym(handle, "gtk_moz_embed_load_url"); | |
2002 _gtk_moz_embed_reload = dlsym(handle, "gtk_moz_embed_reload"); | |
2003 _gtk_moz_embed_stop_load = dlsym(handle, "gtk_moz_embed_stop_load"); | |
2004 _gtk_moz_embed_render_data = dlsym(handle, "gtk_moz_embed_render_data"); | |
2005 _dw_moz_embed_get_type = dlsym(handle, "gtk_moz_embed_get_type"); | |
2006 _gtk_moz_embed_new = dlsym(handle, "gtk_moz_embed_new"); | |
2007 _gtk_moz_embed_can_go_back = dlsym(handle, "gtk_moz_embed_can_go_back"); | |
2008 _gtk_moz_embed_can_go_forward = dlsym(handle, "gtk_moz_embed_can_go_forward"); | |
2009 _gtk_moz_embed_set_comp_path = dlsym(handle, "gtk_moz_embed_set_comp_path"); | |
2010 _gtk_moz_embed_set_profile_path = dlsym(handle, "gtk_moz_embed_set_profile_path"); | |
2011 _gtk_moz_embed_push_startup = dlsym(handle, "gtk_moz_embed_push_startup"); | |
2012 _gtk_moz_embed_set_comp_path( "/usr/lib/mozilla"); | |
2013 _gtk_moz_embed_set_comp_path( "/usr/lib/firefox"); | |
2014 profile = g_build_filename(g_get_home_dir(), ".dwindows/mozilla", NULL); | |
2015 | |
2016 /* initialize profile */ | |
2017 _gtk_moz_embed_set_profile_path(profile, "dwindows"); | |
2018 g_free(profile); | |
2019 | |
2020 /* startup done */ | |
2021 _gtk_moz_embed_push_startup(); | |
2022 } | |
2023 } | |
2024 #endif | |
2025 | |
2026 /* Try to load the libgtkhtml2 shared libary */ | |
2027 #ifdef USE_LIBGTKHTML2 | |
2028 #include <ctype.h> | |
2029 | |
2030 void init_libgtkhtml2 (void) | |
2031 { | |
2032 void *handle = NULL; | |
2033 handle = dlopen( "libgtkhtml-2.so", RTLD_LAZY ); | |
2034 | |
2035 /* If we loaded it, grab the symbols we want */ | |
2036 if ( handle ) | |
2037 { | |
2038 _html_document_new = dlsym(handle, "html_document_new"); | |
2039 _html_view_new = dlsym(handle, "html_view_new"); | |
2040 //... | |
2041 _gtk_html_context_get = dlsym(handle, "gtk_html_context_get" ); | |
2042 g_object_set( G_OBJECT(_gtk_html_context_get()), "debug_painting", FALSE, NULL ); | |
2043 } | |
2044 } | |
2045 #endif | |
2046 | |
2047 /* Try to load the WebKitGtk shared libary */ | |
2048 #ifdef USE_WEBKIT | |
2049 void init_webkit(void) | |
2050 { | |
2051 char libname[101] = {0}; | |
2052 void *handle = NULL; | |
2053 | |
2054 snprintf( libname, 100, "lib%s.so", WEBKIT_LIB); | |
2055 handle = dlopen( libname, RTLD_LAZY ); | |
2056 | |
2057 /* If we loaded it, grab the symbols we want */ | |
2058 if ( handle ) | |
2059 { | |
2060 _webkit_web_view_get_type = dlsym( handle, "webkit_web_view_get_type" ); | |
2061 _webkit_web_view_load_html_string = dlsym( handle, "webkit_web_view_load_html_string" ); | |
2062 _webkit_web_view_open = dlsym( handle, "webkit_web_view_open" ); | |
2063 _webkit_web_view_new = dlsym( handle, "webkit_web_view_new" ); | |
2064 _webkit_web_view_go_back = dlsym( handle, "webkit_web_view_go_back" ); | |
2065 _webkit_web_view_go_forward = dlsym( handle, "webkit_web_view_go_forward" ); | |
2066 _webkit_web_view_reload = dlsym( handle, "webkit_web_view_reload" ); | |
2067 _webkit_web_view_stop_loading = dlsym( handle, "webkit_web_view_stop_loading" ); | |
2068 # ifdef WEBKIT_CHECK_VERSION | |
2069 # if WEBKIT_CHECK_VERSION(1,1,5) | |
2070 _webkit_web_frame_print = dlsym( handle, "webkit_web_frame_print" ); | |
2071 _webkit_web_view_get_focused_frame = dlsym( handle, "webkit_web_view_get_focused_frame" ); | |
2072 # endif | |
2073 # endif | |
2074 } | |
2075 } | |
2076 #endif | |
2077 | |
2078 #if GLIB_CHECK_VERSION(2,32,0) | 1948 #if GLIB_CHECK_VERSION(2,32,0) |
2079 static GRecMutex _dw_gdk_lock; | 1949 static GRecMutex _dw_gdk_lock; |
2080 | 1950 |
2081 static void _dw_gdk_lock_enter(void) | 1951 static void _dw_gdk_lock_enter(void) |
2082 { | 1952 { |
2187 pthread_key_create(&_dw_mutex_key, NULL); | 2057 pthread_key_create(&_dw_mutex_key, NULL); |
2188 | 2058 |
2189 _dw_init_thread(); | 2059 _dw_init_thread(); |
2190 | 2060 |
2191 gtk_rc_parse_string("style \"gtk-tooltips-style\" { bg[NORMAL] = \"#eeee00\" } widget \"gtk-tooltips\" style \"gtk-tooltips-style\""); | 2061 gtk_rc_parse_string("style \"gtk-tooltips-style\" { bg[NORMAL] = \"#eeee00\" } widget \"gtk-tooltips\" style \"gtk-tooltips-style\""); |
2192 | |
2193 #ifdef USE_GTKMOZEMBED | |
2194 init_mozembed(); | |
2195 #endif | |
2196 | |
2197 #ifdef USE_LIBGTKHTML2 | |
2198 init_libgtkhtml2(); | |
2199 #endif | |
2200 | |
2201 #ifdef USE_WEBKIT | |
2202 init_webkit(); | |
2203 #endif | |
2204 | 2062 |
2205 /* Create place holder pixmap/bitmap when one is needed by the API... | 2063 /* Create place holder pixmap/bitmap when one is needed by the API... |
2206 * but we don't really want to display anything. | 2064 * but we don't really want to display anything. |
2207 */ | 2065 */ |
2208 #if GTK_MAJOR_VERSION > 1 | 2066 #if GTK_MAJOR_VERSION > 1 |
6942 } | 6800 } |
6943 | 6801 |
6944 static int _dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator, int extra) | 6802 static int _dw_container_setup(HWND handle, unsigned long *flags, char **titles, int count, int separator, int extra) |
6945 { | 6803 { |
6946 GtkWidget *clist; | 6804 GtkWidget *clist; |
6947 char numbuf[11] = {0}; | 6805 char numbuf[25] = {0}; |
6948 int z, multi; | 6806 int z, multi; |
6949 int _locked_by_me = FALSE; | 6807 int _locked_by_me = FALSE; |
6950 GtkJustification justification; | 6808 GtkJustification justification; |
6951 | 6809 |
6952 DW_MUTEX_LOCK; | 6810 DW_MUTEX_LOCK; |
6976 | 6834 |
6977 for(z=0;z<count;z++) | 6835 for(z=0;z<count;z++) |
6978 { | 6836 { |
6979 if(!extra || z > 1) | 6837 if(!extra || z > 1) |
6980 gtk_clist_set_column_width(GTK_CLIST(clist), z, 50); | 6838 gtk_clist_set_column_width(GTK_CLIST(clist), z, 50); |
6981 snprintf(numbuf, 10, "%d", z); | 6839 snprintf(numbuf, 24, "%d", z); |
6982 gtk_object_set_data(GTK_OBJECT(clist), numbuf, GINT_TO_POINTER(flags[z])); | 6840 gtk_object_set_data(GTK_OBJECT(clist), numbuf, GINT_TO_POINTER(flags[z])); |
6983 if(flags[z]&DW_CFA_RIGHT) | 6841 if(flags[z]&DW_CFA_RIGHT) |
6984 justification = GTK_JUSTIFY_RIGHT; | 6842 justification = GTK_JUSTIFY_RIGHT; |
6985 else if(flags[z]&DW_CFA_CENTER) | 6843 else if(flags[z]&DW_CFA_CENTER) |
6986 justification = GTK_JUSTIFY_CENTER; | 6844 justification = GTK_JUSTIFY_CENTER; |
12951 * handle: Handle to the window. | 12809 * handle: Handle to the window. |
12952 * action: One of the DW_HTML_* constants. | 12810 * action: One of the DW_HTML_* constants. |
12953 */ | 12811 */ |
12954 void dw_html_action(HWND handle, int action) | 12812 void dw_html_action(HWND handle, int action) |
12955 { | 12813 { |
12956 #ifdef USE_GTKMOZEMBED | 12814 #ifdef USE_WEBKIT |
12957 int _locked_by_me = FALSE; | |
12958 | |
12959 if(!_gtk_moz_embed_new) | |
12960 return; | |
12961 | |
12962 DW_MUTEX_LOCK; | |
12963 switch(action) | |
12964 { | |
12965 case DW_HTML_GOBACK: | |
12966 _gtk_moz_embed_go_back(GTK_MOZ_EMBED(handle)); | |
12967 break; | |
12968 case DW_HTML_GOFORWARD: | |
12969 _gtk_moz_embed_go_forward(GTK_MOZ_EMBED(handle)); | |
12970 break; | |
12971 case DW_HTML_GOHOME: | |
12972 _gtk_moz_embed_load_url(GTK_MOZ_EMBED(handle), "http://dwindows.netlabs.org"); | |
12973 break; | |
12974 case DW_HTML_RELOAD: | |
12975 _gtk_moz_embed_reload(GTK_MOZ_EMBED(handle), 0); | |
12976 break; | |
12977 case DW_HTML_STOP: | |
12978 _gtk_moz_embed_stop_load(GTK_MOZ_EMBED(handle)); | |
12979 break; | |
12980 } | |
12981 DW_MUTEX_UNLOCK; | |
12982 #elif defined(USE_WEBKIT) | |
12983 int _locked_by_me = FALSE; | 12815 int _locked_by_me = FALSE; |
12984 WebKitWebView *web_view; | 12816 WebKitWebView *web_view; |
12985 WebKitWebFrame *frame; | |
12986 | |
12987 if (!_webkit_web_view_open) | |
12988 return; | |
12989 | 12817 |
12990 DW_MUTEX_LOCK; | 12818 DW_MUTEX_LOCK; |
12991 web_view = (WebKitWebView *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_web_view"); | 12819 web_view = (WebKitWebView *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_web_view"); |
12992 if ( web_view ) | 12820 if(web_view) |
12993 { | 12821 { |
12994 switch( action ) | 12822 WebKitWebFrame *frame; |
12823 | |
12824 switch(action) | |
12995 { | 12825 { |
12996 case DW_HTML_GOBACK: | 12826 case DW_HTML_GOBACK: |
12997 _webkit_web_view_go_back( web_view ); | 12827 webkit_web_view_go_back(web_view); |
12998 break; | 12828 break; |
12999 case DW_HTML_GOFORWARD: | 12829 case DW_HTML_GOFORWARD: |
13000 _webkit_web_view_go_forward( web_view ); | 12830 webkit_web_view_go_forward(web_view); |
13001 break; | 12831 break; |
13002 case DW_HTML_GOHOME: | 12832 case DW_HTML_GOHOME: |
13003 _webkit_web_view_open( web_view, "http://dwindows.netlabs.org" ); | 12833 webkit_web_view_open(web_view, DW_HOME_URL); |
13004 break; | 12834 break; |
13005 case DW_HTML_RELOAD: | 12835 case DW_HTML_RELOAD: |
13006 _webkit_web_view_reload( web_view ); | 12836 webkit_web_view_reload(web_view); |
13007 break; | 12837 break; |
13008 case DW_HTML_STOP: | 12838 case DW_HTML_STOP: |
13009 _webkit_web_view_stop_loading( web_view ); | 12839 webkit_web_view_stop_loading(web_view); |
13010 break; | 12840 break; |
13011 # ifdef WEBKIT_CHECK_VERSION | 12841 # ifdef WEBKIT_CHECK_VERSION |
13012 # if WEBKIT_CHECK_VERSION(1,1,5) | 12842 # if WEBKIT_CHECK_VERSION(1,1,5) |
13013 case DW_HTML_PRINT: | 12843 case DW_HTML_PRINT: |
13014 frame = _webkit_web_view_get_focused_frame( web_view ); | 12844 frame = webkit_web_view_get_focused_frame(web_view); |
13015 _webkit_web_frame_print( frame ); | 12845 webkit_web_frame_print(frame); |
13016 break; | 12846 break; |
13017 # endif | 12847 # endif |
13018 # endif | 12848 # endif |
13019 } | 12849 } |
13020 } | 12850 } |
13021 DW_MUTEX_UNLOCK; | 12851 DW_MUTEX_UNLOCK; |
13022 #endif | 12852 #endif |
13023 } | 12853 } |
13024 | 12854 |
13025 #ifdef USE_LIBGTKHTML2 | |
13026 void _dw_html_render_data( HWND handle, char *string, int i ) | |
13027 { | |
13028 HtmlDocument *document; | |
13029 | |
13030 html_view_set_document (HTML_VIEW(handle), NULL); | |
13031 document = (HtmlDocument *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_html_document" ); | |
13032 /* html_document_clear (document);*/ | |
13033 if ( document ) | |
13034 { | |
13035 html_view_set_document (HTML_VIEW(handle), document); | |
13036 if ( html_document_open_stream( document, "text/html" ) ) | |
13037 { | |
13038 html_document_write_stream( document, string, i ); | |
13039 } | |
13040 html_document_close_stream (document); | |
13041 } | |
13042 } | |
13043 #endif | |
13044 /* | 12855 /* |
13045 * Render raw HTML code in the embedded HTML widget.. | 12856 * Render raw HTML code in the embedded HTML widget.. |
13046 * Parameters: | 12857 * Parameters: |
13047 * handle: Handle to the window. | 12858 * handle: Handle to the window. |
13048 * string: String buffer containt HTML code to | 12859 * string: String buffer containt HTML code to |
13050 * Returns: | 12861 * Returns: |
13051 * 0 on success. | 12862 * 0 on success. |
13052 */ | 12863 */ |
13053 int dw_html_raw(HWND handle, char *string) | 12864 int dw_html_raw(HWND handle, char *string) |
13054 { | 12865 { |
13055 #ifdef USE_GTKMOZEMBED | 12866 #ifdef USE_WEBKIT |
13056 int _locked_by_me = FALSE; | |
13057 | |
13058 if (!_gtk_moz_embed_new) | |
13059 return -1; | |
13060 | |
13061 DW_MUTEX_LOCK; | |
13062 _gtk_moz_embed_render_data(GTK_MOZ_EMBED(handle), string, strlen(string), "file:///", "text/html"); | |
13063 gtk_widget_show(GTK_WIDGET(handle)); | |
13064 DW_MUTEX_UNLOCK; | |
13065 return 0; | |
13066 #elif defined(USE_LIBGTKHTML2) | |
13067 int _locked_by_me = FALSE; | |
13068 | |
13069 if ( !_html_document_new ) | |
13070 return -1; | |
13071 | |
13072 DW_MUTEX_LOCK; | |
13073 _dw_html_render_data( handle, string, strlen(string) ); | |
13074 gtk_widget_show( GTK_WIDGET(handle) ); | |
13075 DW_MUTEX_UNLOCK; | |
13076 return 0; | |
13077 #elif defined(USE_WEBKIT) | |
13078 int _locked_by_me = FALSE; | 12867 int _locked_by_me = FALSE; |
13079 WebKitWebView *web_view; | 12868 WebKitWebView *web_view; |
13080 | 12869 |
13081 if (!_webkit_web_view_open) | |
13082 return -1; | |
13083 | |
13084 DW_MUTEX_LOCK; | 12870 DW_MUTEX_LOCK; |
13085 web_view = (WebKitWebView *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_web_view"); | 12871 web_view = (WebKitWebView *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_web_view"); |
13086 if ( web_view ) | 12872 if(web_view) |
13087 { | 12873 { |
13088 _webkit_web_view_load_html_string( web_view, string, "file:///"); | 12874 webkit_web_view_load_html_string( web_view, string, "file:///"); |
13089 gtk_widget_show( GTK_WIDGET(handle) ); | 12875 gtk_widget_show( GTK_WIDGET(handle) ); |
13090 } | 12876 } |
13091 DW_MUTEX_UNLOCK; | 12877 DW_MUTEX_UNLOCK; |
13092 return 0; | 12878 return DW_ERROR_NONE; |
13093 #endif | 12879 #endif |
13094 return -1; | 12880 return DW_ERROR_UNKNOWN; |
13095 } | 12881 } |
13096 | 12882 |
13097 /* | 12883 /* |
13098 * Render file or web page in the embedded HTML widget.. | 12884 * Render file or web page in the embedded HTML widget.. |
13099 * Parameters: | 12885 * Parameters: |
13103 * Returns: | 12889 * Returns: |
13104 * 0 on success. | 12890 * 0 on success. |
13105 */ | 12891 */ |
13106 int dw_html_url(HWND handle, char *url) | 12892 int dw_html_url(HWND handle, char *url) |
13107 { | 12893 { |
13108 #ifdef USE_GTKMOZEMBED | 12894 #ifdef USE_WEBKIT |
13109 int _locked_by_me = FALSE; | |
13110 | |
13111 if (!_gtk_moz_embed_new) | |
13112 return -1; | |
13113 | |
13114 DW_MUTEX_LOCK; | |
13115 _gtk_moz_embed_load_url( GTK_MOZ_EMBED(handle), url ); | |
13116 gtk_widget_show(GTK_WIDGET(handle)); | |
13117 DW_MUTEX_UNLOCK; | |
13118 return 0; | |
13119 #elif defined( USE_WEBKIT ) | |
13120 int _locked_by_me = FALSE; | 12895 int _locked_by_me = FALSE; |
13121 WebKitWebView *web_view; | 12896 WebKitWebView *web_view; |
13122 | 12897 |
13123 if (!_webkit_web_view_open) | |
13124 return -1; | |
13125 | |
13126 DW_MUTEX_LOCK; | 12898 DW_MUTEX_LOCK; |
13127 web_view = (WebKitWebView *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_web_view"); | 12899 web_view = (WebKitWebView *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_web_view"); |
13128 if ( web_view ) | 12900 if(web_view) |
13129 { | 12901 { |
13130 _webkit_web_view_open( web_view, url ); | 12902 webkit_web_view_open(web_view, url); |
13131 gtk_widget_show(GTK_WIDGET(handle)); | 12903 gtk_widget_show(GTK_WIDGET(handle)); |
13132 } | 12904 } |
13133 DW_MUTEX_UNLOCK; | 12905 DW_MUTEX_UNLOCK; |
13134 return 0; | 12906 return DW_ERROR_NONE; |
13135 #endif | 12907 #endif |
13136 return -1; | 12908 return DW_ERROR_UNKNOWN; |
13137 } | 12909 } |
13138 | |
13139 #ifdef USE_GTKMOZEMBED | |
13140 /* | |
13141 * Callback for a HTML widget when the "Forward" menu item is selected | |
13142 */ | |
13143 static int _dw_html_forward_callback(HWND window, void *data) | |
13144 { | |
13145 HWND handle=(HWND)data; | |
13146 dw_html_action( handle, DW_HTML_GOFORWARD ); | |
13147 return TRUE; | |
13148 } | |
13149 | |
13150 /* | |
13151 * Callback for a HTML widget when the "Back" menu item is selected | |
13152 */ | |
13153 static int _dw_html_backward_callback(HWND window, void *data) | |
13154 { | |
13155 HWND handle=(HWND)data; | |
13156 dw_html_action( handle, DW_HTML_GOBACK ); | |
13157 return TRUE; | |
13158 } | |
13159 | |
13160 /* | |
13161 * Callback for a HTML widget when the "Reload" menu item is selected | |
13162 */ | |
13163 static int _dw_html_reload_callback(HWND window, void *data) | |
13164 { | |
13165 HWND handle=(HWND)data; | |
13166 dw_html_action( handle, DW_HTML_RELOAD ); | |
13167 return TRUE; | |
13168 } | |
13169 | |
13170 /* | |
13171 * Callback for a HTML widget when a page has completed loading | |
13172 * Once the page has finished loading, show the widget. | |
13173 */ | |
13174 void _dw_html_net_stop_cb( GtkMozEmbed *embed, gpointer data ) | |
13175 { | |
13176 gtk_widget_show(GTK_WIDGET(data)); | |
13177 } | |
13178 | |
13179 /* | |
13180 * Callback for a HTML widget when a mouse button is clicked inside the widget | |
13181 * If the right mouse button is clicked, popup a context menu | |
13182 */ | |
13183 static gint _dw_dom_mouse_click_cb (GtkMozEmbed *dummy, gpointer dom_event, gpointer embed) | |
13184 { | |
13185 gint button,rc; | |
13186 glong x,y; | |
13187 int flags; | |
13188 | |
13189 button = mozilla_get_mouse_event_button( dom_event ); | |
13190 if ( button == 2 ) | |
13191 { | |
13192 HWND menuitem; | |
13193 HMENUI popup; | |
13194 /* | |
13195 * Right mouse button; display context menu | |
13196 */ | |
13197 rc = mozilla_get_mouse_location( dom_event, &x, &y); | |
13198 popup = dw_menu_new( 0 ); | |
13199 if ( _gtk_moz_embed_can_go_forward(GTK_MOZ_EMBED(embed) ) ) | |
13200 flags = DW_MIS_ENABLED; | |
13201 else | |
13202 flags = DW_MIS_DISABLED; | |
13203 menuitem = dw_menu_append_item( popup, "Forward", 1, flags, TRUE, FALSE, 0 ); | |
13204 dw_signal_connect( menuitem, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_html_forward_callback), embed ); | |
13205 | |
13206 if ( _gtk_moz_embed_can_go_back(GTK_MOZ_EMBED(embed) ) ) | |
13207 flags = DW_MIS_ENABLED; | |
13208 else | |
13209 flags = DW_MIS_DISABLED; | |
13210 menuitem = dw_menu_append_item( popup, "Back", 2, flags, TRUE, FALSE, 0 ); | |
13211 dw_signal_connect( menuitem, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_html_backward_callback), embed ); | |
13212 | |
13213 dw_menu_append_item( popup, DW_MENU_SEPARATOR, 99, 0, TRUE, FALSE, 0 ); | |
13214 | |
13215 menuitem = dw_menu_append_item( popup, "Reload", 3, 0, TRUE, FALSE, 0 ); | |
13216 dw_signal_connect( menuitem, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_html_reload_callback), embed ); | |
13217 | |
13218 dw_menu_popup( &popup, embed, x, y ); | |
13219 rc = TRUE; | |
13220 } | |
13221 else | |
13222 { | |
13223 rc = FALSE; | |
13224 } | |
13225 return rc; | |
13226 } | |
13227 #endif | |
13228 | |
13229 #ifdef USE_LIBGTKHTML2 | |
13230 static gboolean dom_mouse_down( HtmlDocument *doc, DomMouseEvent *event, gpointer data ) | |
13231 { | |
13232 fprintf(stderr,"mouse down\n"); | |
13233 return TRUE; | |
13234 } | |
13235 static gboolean dom_mouse_up( HtmlDocument *doc, DomMouseEvent *event, gpointer data ) | |
13236 { | |
13237 fprintf(stderr,"mouse up\n"); | |
13238 return TRUE; | |
13239 } | |
13240 static gboolean dom_mouse_click( HtmlDocument *doc, DomMouseEvent *event, gpointer data ) | |
13241 { | |
13242 fprintf(stderr,"mouse click\n"); | |
13243 return TRUE; | |
13244 } | |
13245 static gboolean url_requested (HtmlDocument *doc, const gchar *url, HtmlStream *stream) | |
13246 { | |
13247 fprintf(stderr,"URL IS REQUESTED: %s\n",url); | |
13248 return TRUE; | |
13249 } | |
13250 static void link_clicked (HtmlDocument *doc, const gchar *url) | |
13251 { | |
13252 fprintf(stderr,"link clicked: %s!\n", url); | |
13253 } | |
13254 #endif | |
13255 | 12910 |
13256 #ifdef USE_WEBKIT | 12911 #ifdef USE_WEBKIT |
13257 # ifdef WEBKIT_CHECK_VERSION | 12912 # ifdef WEBKIT_CHECK_VERSION |
13258 # if WEBKIT_CHECK_VERSION(1,1,5) | 12913 # if WEBKIT_CHECK_VERSION(1,1,5) |
13259 static void _dw_html_print_cb( GtkWidget *widget, gpointer *data ) | 12914 static void _dw_html_print_cb(GtkWidget *widget, gpointer *data) |
13260 { | 12915 { |
13261 WebKitWebView *web_view = DW_WEBKIT_WEB_VIEW(data); | 12916 WebKitWebView *web_view = WEBKIT_WEB_VIEW(data); |
13262 WebKitWebFrame *frame; | 12917 WebKitWebFrame *frame; |
13263 | 12918 |
13264 frame = _webkit_web_view_get_focused_frame( web_view ); | 12919 frame = webkit_web_view_get_focused_frame(web_view); |
13265 _webkit_web_frame_print( frame ); | 12920 webkit_web_frame_print(frame); |
13266 } | 12921 } |
13267 /* | 12922 /* |
13268 * Fired when the user right-clicks to get the popup-menu on the HTML widget | 12923 * Fired when the user right-clicks to get the popup-menu on the HTML widget |
13269 * We add a "Print" menu item to enable printing | 12924 * We add a "Print" menu item to enable printing |
13270 * user_data is not used | 12925 * user_data is not used |
13271 */ | 12926 */ |
13272 static void _dw_html_populate_popup_cb( WebKitWebView *web_view, GtkMenu *menu, gpointer user_data ) | 12927 static void _dw_html_populate_popup_cb(WebKitWebView *web_view, GtkMenu *menu, gpointer user_data) |
13273 { | 12928 { |
13274 GtkWidget *image = gtk_image_new_from_stock( GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU ); | 12929 GtkWidget *image = gtk_image_new_from_stock( GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU ); |
13275 GtkWidget *item = gtk_image_menu_item_new_with_label( "Print" ); | 12930 GtkWidget *item = gtk_image_menu_item_new_with_label("Print"); |
13276 | 12931 |
13277 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(item), image ); | 12932 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); |
13278 gtk_menu_append( GTK_MENU(menu), item); | 12933 gtk_menu_append( GTK_MENU(menu), item); |
13279 g_signal_connect( item, "activate", G_CALLBACK(_dw_html_print_cb), web_view ); | 12934 g_signal_connect(item, "activate", G_CALLBACK(_dw_html_print_cb), web_view); |
13280 gtk_widget_show(item); | 12935 gtk_widget_show(item); |
13281 } | 12936 } |
13282 # endif | 12937 # endif |
13283 # endif | 12938 # endif |
13284 #endif | 12939 #endif |
13290 * id: An ID to be used with dw_window_from_id() or 0L. | 12945 * id: An ID to be used with dw_window_from_id() or 0L. |
13291 */ | 12946 */ |
13292 HWND dw_html_new(unsigned long id) | 12947 HWND dw_html_new(unsigned long id) |
13293 { | 12948 { |
13294 GtkWidget *widget = NULL; | 12949 GtkWidget *widget = NULL; |
13295 int _locked_by_me = FALSE; | 12950 #ifdef USE_WEBKIT |
13296 | 12951 int _locked_by_me = FALSE; |
13297 DW_MUTEX_LOCK; | 12952 WebKitWebView *web_view; |
13298 #ifdef USE_GTKMOZEMBED | 12953 |
13299 if (!_gtk_moz_embed_new) | 12954 DW_MUTEX_LOCK; |
13300 { | 12955 widget = gtk_scrolled_window_new(NULL, NULL); |
13301 dw_debug( "HTML widget not available; you do not have access to gtkmozembed.\n" ); | 12956 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
13302 } | 12957 web_view = (WebKitWebView *)_webkit_web_view_new(); |
13303 else | 12958 gtk_container_add(GTK_CONTAINER (widget), GTK_WIDGET(web_view)); |
13304 { | 12959 gtk_widget_show( GTK_WIDGET(web_view) ); |
13305 widget = _gtk_moz_embed_new(); | 12960 gtk_object_set_data(GTK_OBJECT(widget), "_dw_web_view", (gpointer)web_view); |
13306 /* | |
13307 * Connect some signals | |
13308 */ | |
13309 gtk_signal_connect( GTK_OBJECT(widget), "net-stop", GTK_SIGNAL_FUNC(_dw_html_net_stop_cb), widget ); | |
13310 gtk_signal_connect( GTK_OBJECT(widget), "dom_mouse_click", GTK_SIGNAL_FUNC(_dw_dom_mouse_click_cb), widget ); | |
13311 gtk_widget_show(widget); | |
13312 } | |
13313 #elif defined(USE_LIBGTKHTML2) | |
13314 if ( !_html_document_new ) | |
13315 { | |
13316 dw_debug( "HTML widget not available; you do not have access to libgtkhtml-2.\n" ); | |
13317 } | |
13318 else | |
13319 { | |
13320 HtmlDocument *document; | |
13321 document = html_document_new (); | |
13322 g_signal_connect (G_OBJECT (document), "dom_mouse_down", G_CALLBACK (dom_mouse_down), NULL); | |
13323 g_signal_connect (G_OBJECT (document), "dom_mouse_up", G_CALLBACK (dom_mouse_up), NULL); | |
13324 g_signal_connect (G_OBJECT (document), "dom_mouse_click", G_CALLBACK (dom_mouse_click), NULL); | |
13325 g_signal_connect (G_OBJECT (document), "request_url", G_CALLBACK (url_requested), NULL); | |
13326 g_signal_connect (G_OBJECT (document), "link_clicked", G_CALLBACK (link_clicked), NULL); | |
13327 widget = _html_view_new(); | |
13328 gtk_object_set_data(GTK_OBJECT(widget), "_dw_html_document", (gpointer)document); | |
13329 gtk_widget_show(widget); | |
13330 } | |
13331 #elif defined(USE_WEBKIT) | |
13332 if (!_webkit_web_view_open) | |
13333 { | |
13334 dw_debug( "HTML widget not available; you do not have access to webkit.\n" ); | |
13335 } | |
13336 else | |
13337 { | |
13338 WebKitWebView *web_view; | |
13339 widget = gtk_scrolled_window_new (NULL, NULL); | |
13340 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW (widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); | |
13341 web_view = (WebKitWebView *)_webkit_web_view_new(); | |
13342 gtk_container_add( GTK_CONTAINER (widget), GTK_WIDGET(web_view) ); | |
13343 gtk_widget_show( GTK_WIDGET(web_view) ); | |
13344 gtk_object_set_data( GTK_OBJECT(widget), "_dw_web_view", (gpointer)web_view ); | |
13345 # ifdef WEBKIT_CHECK_VERSION | 12961 # ifdef WEBKIT_CHECK_VERSION |
13346 # if WEBKIT_CHECK_VERSION(1,1,5) | 12962 # if WEBKIT_CHECK_VERSION(1,1,5) |
13347 g_signal_connect( web_view, "populate-popup", G_CALLBACK(_dw_html_populate_popup_cb), NULL ); | 12963 g_signal_connect(web_view, "populate-popup", G_CALLBACK(_dw_html_populate_popup_cb), NULL); |
13348 # endif | 12964 # endif |
13349 # endif | 12965 # endif |
13350 gtk_widget_show(widget); | 12966 gtk_widget_show(widget); |
13351 } | 12967 DW_MUTEX_UNLOCK; |
13352 #else | 12968 #else |
13353 dw_debug( "HTML widget not available; you do not have access to gtkmozembed, webkit nor libgtkhtml-2.\n" ); | 12969 dw_debug( "HTML widget not available; you do not have access to webkit.\n" ); |
13354 #endif | 12970 #endif |
13355 DW_MUTEX_UNLOCK; | |
13356 return widget; | 12971 return widget; |
13357 } | 12972 } |
13358 | 12973 |
13359 /* | 12974 /* |
13360 * Gets the contents of the default clipboard as text. | 12975 * Gets the contents of the default clipboard as text. |