Mercurial > dwindows
comparison gtk3/dw.c @ 2008:74facb490f5a
GTK: Fix html changed callbacks when using webkit1.
Fix the code to disable javascript, it only worked on webkit2.
Add code to the test program to demonstrate the callback.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 07 Nov 2019 00:37:23 +0000 |
parents | 3a26e6f6691d |
children | 617a78dc70aa |
comparison
equal
deleted
inserted
replaced
2007:3a26e6f6691d | 2008:74facb490f5a |
---|---|
1288 char *location = (char *)webkit_web_view_get_uri(web_view); | 1288 char *location = (char *)webkit_web_view_get_uri(web_view); |
1289 int status = 0; | 1289 int status = 0; |
1290 void **params = data; | 1290 void **params = data; |
1291 | 1291 |
1292 if(params) | 1292 if(params) |
1293 status = DW_POINTER_TO_INT(params[1]); | 1293 status = DW_POINTER_TO_INT(params[3]); |
1294 | 1294 |
1295 if(status && location && work.window && work.func) | 1295 if(status && location && work.window && work.func) |
1296 { | 1296 { |
1297 int (*htmlchangedfunc)(HWND, int, char *, void *) = work.func; | 1297 int (*htmlchangedfunc)(HWND, int, char *, void *) = work.func; |
1298 | 1298 |
11560 { | 11560 { |
11561 GtkWidget *widget = NULL; | 11561 GtkWidget *widget = NULL; |
11562 #ifdef USE_WEBKIT | 11562 #ifdef USE_WEBKIT |
11563 int _locked_by_me = FALSE; | 11563 int _locked_by_me = FALSE; |
11564 WebKitWebView *web_view; | 11564 WebKitWebView *web_view; |
11565 #ifdef USE_WEBKIT2 | |
11565 WebKitSettings *settings; | 11566 WebKitSettings *settings; |
11567 #else | |
11568 WebKitWebSettings *settings; | |
11569 #endif | |
11566 | 11570 |
11567 DW_MUTEX_LOCK; | 11571 DW_MUTEX_LOCK; |
11568 web_view = (WebKitWebView *)webkit_web_view_new(); | 11572 web_view = (WebKitWebView *)webkit_web_view_new(); |
11569 settings = webkit_web_view_get_settings(web_view); | |
11570 /* Make sure java script is enabled */ | |
11571 webkit_settings_set_enable_javascript(settings, TRUE); | |
11572 webkit_web_view_set_settings(web_view, settings); | |
11573 /* WebKit2 no longer requires a scrolled window... | 11573 /* WebKit2 no longer requires a scrolled window... |
11574 * So only create a scrolled window and pack it in older versions. | 11574 * So only create a scrolled window and pack it in older versions. |
11575 */ | 11575 */ |
11576 #ifndef USE_WEBKIT2 | 11576 #ifndef USE_WEBKIT2 |
11577 widget = gtk_scrolled_window_new(NULL, NULL); | 11577 widget = gtk_scrolled_window_new(NULL, NULL); |
11578 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | 11578 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
11579 gtk_container_add(GTK_CONTAINER (widget), GTK_WIDGET(web_view)); | 11579 gtk_container_add(GTK_CONTAINER (widget), GTK_WIDGET(web_view)); |
11580 gtk_widget_show(GTK_WIDGET(web_view)); | 11580 gtk_widget_show(GTK_WIDGET(web_view)); |
11581 g_object_set_data(G_OBJECT(widget), "_dw_web_view", (gpointer)web_view); | 11581 g_object_set_data(G_OBJECT(widget), "_dw_web_view", (gpointer)web_view); |
11582 g_signal_connect(web_view, "populate-popup", G_CALLBACK(_dw_html_populate_popup_cb), NULL); | 11582 g_signal_connect(web_view, "populate-popup", G_CALLBACK(_dw_html_populate_popup_cb), NULL); |
11583 /* Create a new websettings and enable java script */ | |
11584 settings = webkit_web_settings_new(); | |
11585 g_object_set(G_OBJECT(settings), "enable-scripts", TRUE, NULL); | |
11586 webkit_web_view_set_settings(WEBKIT_WEB_VIEW(web_view), settings); | |
11583 #else | 11587 #else |
11588 settings = webkit_web_view_get_settings(web_view); | |
11589 /* Make sure java script is enabled */ | |
11590 webkit_settings_set_enable_javascript(settings, TRUE); | |
11591 webkit_web_view_set_settings(web_view, settings); | |
11584 widget = (GtkWidget *)web_view; | 11592 widget = (GtkWidget *)web_view; |
11585 #endif | 11593 #endif |
11586 gtk_widget_show(widget); | 11594 gtk_widget_show(widget); |
11587 DW_MUTEX_UNLOCK; | 11595 DW_MUTEX_UNLOCK; |
11588 #else | 11596 #else |
11945 } | 11953 } |
11946 free(data); | 11954 free(data); |
11947 } | 11955 } |
11948 } | 11956 } |
11949 | 11957 |
11958 #define _DW_INTERNAL_CALLBACK_PARAMS 4 | |
11959 | |
11950 /* | 11960 /* |
11951 * Add a callback to a window event with a closure callback. | 11961 * Add a callback to a window event with a closure callback. |
11952 * Parameters: | 11962 * Parameters: |
11953 * window: Window handle of signal to be called back. | 11963 * window: Window handle of signal to be called back. |
11954 * signame: A string pointer identifying which signal to be hooked. | 11964 * signame: A string pointer identifying which signal to be hooked. |
11960 { | 11970 { |
11961 void *thisfunc = _findsigfunc(signame); | 11971 void *thisfunc = _findsigfunc(signame); |
11962 char *thisname = signame; | 11972 char *thisname = signame; |
11963 HWND thiswindow = window; | 11973 HWND thiswindow = window; |
11964 int sigid, _locked_by_me = FALSE; | 11974 int sigid, _locked_by_me = FALSE; |
11965 void **params = calloc(3, sizeof(void *)); | 11975 void **params = calloc(_DW_INTERNAL_CALLBACK_PARAMS, sizeof(void *)); |
11966 gint cid; | 11976 gint cid; |
11967 | 11977 |
11968 /* Save the disconnect function pointer */ | 11978 /* Save the disconnect function pointer */ |
11969 params[1] = discfunc; | 11979 params[1] = discfunc; |
11970 | 11980 |
11971 DW_MUTEX_LOCK; | 11981 DW_MUTEX_LOCK; |
11972 /* | 11982 /* |
11973 * If the window we are setting the signal on is a scrolled window we need to get | 11983 * If the window we are setting the signal on is a scrolled window we need to get |
11974 * the "real" widget type. thiswindow is the "real" widget type | 11984 * the "real" widget type. thiswindow is the "real" widget type |
11975 */ | 11985 */ |
11976 if (GTK_IS_SCROLLED_WINDOW(thiswindow)) | 11986 if (GTK_IS_SCROLLED_WINDOW(thiswindow) |
11987 #ifdef USE_WEBKIT | |
11988 && !(thiswindow = (HWND)_dw_html_web_view(thiswindow)) | |
11989 #endif | |
11990 ) | |
11977 { | 11991 { |
11978 thiswindow = (HWND)g_object_get_data(G_OBJECT(window), "_dw_user"); | 11992 thiswindow = (HWND)g_object_get_data(G_OBJECT(window), "_dw_user"); |
11979 } | 11993 } |
11980 | 11994 |
11981 if (strcmp(signame, DW_SIGNAL_EXPOSE) == 0) | 11995 if (strcmp(signame, DW_SIGNAL_EXPOSE) == 0) |
12032 params[0] = GINT_TO_POINTER(sigid); | 12046 params[0] = GINT_TO_POINTER(sigid); |
12033 params[2] = (void *)thiswindow; | 12047 params[2] = (void *)thiswindow; |
12034 cid = g_signal_connect_data(G_OBJECT(thiswindow), "key_press_event", G_CALLBACK(_container_enter_event), params, _dw_signal_disconnect, 0); | 12048 cid = g_signal_connect_data(G_OBJECT(thiswindow), "key_press_event", G_CALLBACK(_container_enter_event), params, _dw_signal_disconnect, 0); |
12035 _set_signal_handler_id(thiswindow, sigid, cid); | 12049 _set_signal_handler_id(thiswindow, sigid, cid); |
12036 | 12050 |
12037 params = calloc(sizeof(void *), 3); | 12051 params = calloc(sizeof(void *), _DW_INTERNAL_CALLBACK_PARAMS); |
12038 | 12052 |
12039 thisname = "button_press_event"; | 12053 thisname = "button_press_event"; |
12040 thisfunc = _findsigfunc(DW_SIGNAL_ITEM_ENTER); | 12054 thisfunc = _findsigfunc(DW_SIGNAL_ITEM_ENTER); |
12041 } | 12055 } |
12042 else if (GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_COLUMN_CLICK) == 0) | 12056 else if (GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_COLUMN_CLICK) == 0) |
12061 #ifdef USE_WEBKIT2 | 12075 #ifdef USE_WEBKIT2 |
12062 thisname = "load-changed"; | 12076 thisname = "load-changed"; |
12063 #else | 12077 #else |
12064 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc, discfunc); | 12078 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc, discfunc); |
12065 params[0] = GINT_TO_POINTER(sigid); | 12079 params[0] = GINT_TO_POINTER(sigid); |
12066 params[1] = GINT_TO_POINTER(DW_HTML_CHANGE_STARTED); | |
12067 params[2] = (void *)thiswindow; | 12080 params[2] = (void *)thiswindow; |
12081 params[3] = GINT_TO_POINTER(DW_HTML_CHANGE_STARTED); | |
12068 cid = g_signal_connect_data(G_OBJECT(thiswindow), "load-started", G_CALLBACK(thisfunc), params, _dw_signal_disconnect, 0); | 12082 cid = g_signal_connect_data(G_OBJECT(thiswindow), "load-started", G_CALLBACK(thisfunc), params, _dw_signal_disconnect, 0); |
12069 _set_signal_handler_id(thiswindow, sigid, cid); | 12083 _set_signal_handler_id(thiswindow, sigid, cid); |
12070 | 12084 |
12071 params = calloc(sizeof(void *), 3); | 12085 params = calloc(sizeof(void *), _DW_INTERNAL_CALLBACK_PARAMS); |
12072 | 12086 |
12073 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc, discfunc); | 12087 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc, discfunc); |
12074 params[0] = GINT_TO_POINTER(sigid); | 12088 params[0] = GINT_TO_POINTER(sigid); |
12075 params[1] = GINT_TO_POINTER(DW_HTML_CHANGE_LOADING); | |
12076 params[2] = (void *)thiswindow; | 12089 params[2] = (void *)thiswindow; |
12090 params[3] = GINT_TO_POINTER(DW_HTML_CHANGE_LOADING); | |
12077 cid = g_signal_connect_data(G_OBJECT(thiswindow), "load-committed", G_CALLBACK(thisfunc), params, _dw_signal_disconnect, 0); | 12091 cid = g_signal_connect_data(G_OBJECT(thiswindow), "load-committed", G_CALLBACK(thisfunc), params, _dw_signal_disconnect, 0); |
12078 _set_signal_handler_id(thiswindow, sigid, cid); | 12092 _set_signal_handler_id(thiswindow, sigid, cid); |
12079 | 12093 |
12080 params = calloc(sizeof(void *), 3); | 12094 params = calloc(sizeof(void *), _DW_INTERNAL_CALLBACK_PARAMS); |
12081 params[1] = GINT_TO_POINTER(DW_HTML_CHANGE_COMPLETE); | 12095 params[3] = GINT_TO_POINTER(DW_HTML_CHANGE_COMPLETE); |
12082 | 12096 |
12083 thisname = "load-finished"; | 12097 thisname = "load-finished"; |
12084 #endif | 12098 #endif |
12085 } | 12099 } |
12086 else if (WEBKIT_IS_WEB_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_HTML_RESULT) == 0) | 12100 else if (WEBKIT_IS_WEB_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_HTML_RESULT) == 0) |