Mercurial > dwindows
comparison gtk3/dw.c @ 2006:6f1adc77de02
GTK: Added DW_SIGNAL_HTML_CHANGED and DW_SIGNAL_HTML_RESULT.
Added dw_html_javascript_run(). Full support on GTK3 using
WebKit2 and partial support for WebKit1. Will port to
GTK2 when WebKit1 support is complete. Mac and Windows
versions coming soon.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 06 Nov 2019 13:09:31 +0000 |
parents | a17cc1958369 |
children | 3a26e6f6691d |
comparison
equal
deleted
inserted
replaced
2005:a17cc1958369 | 2006:6f1adc77de02 |
---|---|
158 static gint _value_changed_event(GtkWidget *widget, gpointer user_data); | 158 static gint _value_changed_event(GtkWidget *widget, gpointer user_data); |
159 static gint _tree_select_event(GtkTreeSelection *sel, gpointer data); | 159 static gint _tree_select_event(GtkTreeSelection *sel, gpointer data); |
160 static gint _tree_expand_event(GtkTreeView *treeview, GtkTreeIter *arg1, GtkTreePath *arg2, gpointer data); | 160 static gint _tree_expand_event(GtkTreeView *treeview, GtkTreeIter *arg1, GtkTreePath *arg2, gpointer data); |
161 static gint _switch_page_event(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer data); | 161 static gint _switch_page_event(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer data); |
162 static gint _column_click_event(GtkWidget *widget, gpointer data); | 162 static gint _column_click_event(GtkWidget *widget, gpointer data); |
163 static void _html_result_event(GObject *object, GAsyncResult *result, gpointer script_data); | |
164 #ifdef USE_WEBKIT | |
165 #ifdef USE_WEBKIT2 | |
166 static void _html_changed_event(WebKitWebView *web_view, WebKitLoadEvent load_event, gpointer data); | |
167 #else | |
168 static void _html_changed_event(WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data); | |
169 #endif | |
170 #endif | |
163 static void _dw_signal_disconnect(gpointer data, GClosure *closure); | 171 static void _dw_signal_disconnect(gpointer data, GClosure *closure); |
164 | 172 |
165 GObject *_DWObject = NULL; | 173 GObject *_DWObject = NULL; |
166 char *_DWDefaultFont = NULL; | 174 char *_DWDefaultFont = NULL; |
167 static char _dw_share_path[PATH_MAX+1] = { 0 }; | 175 static char _dw_share_path[PATH_MAX+1] = { 0 }; |
181 gint cid; | 189 gint cid; |
182 void *intfunc; | 190 void *intfunc; |
183 | 191 |
184 } SignalHandler; | 192 } SignalHandler; |
185 | 193 |
186 #define SIGNALMAX 18 | 194 #define SIGNALMAX 20 |
187 | 195 |
188 /* A list of signal forwarders, to account for paramater differences. */ | 196 /* A list of signal forwarders, to account for paramater differences. */ |
189 static SignalList SignalTranslate[SIGNALMAX] = { | 197 static SignalList SignalTranslate[SIGNALMAX] = { |
190 { _configure_event, DW_SIGNAL_CONFIGURE }, | 198 { _configure_event, DW_SIGNAL_CONFIGURE }, |
191 { _key_press_event, DW_SIGNAL_KEY_PRESS }, | 199 { _key_press_event, DW_SIGNAL_KEY_PRESS }, |
202 { _tree_select_event, DW_SIGNAL_ITEM_SELECT }, | 210 { _tree_select_event, DW_SIGNAL_ITEM_SELECT }, |
203 { _set_focus_event, DW_SIGNAL_SET_FOCUS }, | 211 { _set_focus_event, DW_SIGNAL_SET_FOCUS }, |
204 { _value_changed_event, DW_SIGNAL_VALUE_CHANGED }, | 212 { _value_changed_event, DW_SIGNAL_VALUE_CHANGED }, |
205 { _switch_page_event, DW_SIGNAL_SWITCH_PAGE }, | 213 { _switch_page_event, DW_SIGNAL_SWITCH_PAGE }, |
206 { _column_click_event, DW_SIGNAL_COLUMN_CLICK }, | 214 { _column_click_event, DW_SIGNAL_COLUMN_CLICK }, |
207 { _tree_expand_event, DW_SIGNAL_TREE_EXPAND } | 215 { _tree_expand_event, DW_SIGNAL_TREE_EXPAND }, |
216 #ifdef USE_WEBKIT | |
217 { _html_changed_event, DW_SIGNAL_HTML_CHANGED }, | |
218 #else | |
219 { _generic_event, DW_SIGNAL_HTML_CHANGED }, | |
220 #endif | |
221 { _html_result_event, DW_SIGNAL_HTML_RESULT } | |
208 }; | 222 }; |
209 | 223 |
210 /* Alignment flags */ | 224 /* Alignment flags */ |
211 #define DW_CENTER 0.5f | 225 #define DW_CENTER 0.5f |
212 #define DW_LEFT 0.0f | 226 #define DW_LEFT 0.0f |
1182 char text[100]; | 1196 char text[100]; |
1183 | 1197 |
1184 sprintf(text, "_dw_sigcid%d", counter); | 1198 sprintf(text, "_dw_sigcid%d", counter); |
1185 g_object_set_data(G_OBJECT(widget), text, GINT_TO_POINTER(cid)); | 1199 g_object_set_data(G_OBJECT(widget), text, GINT_TO_POINTER(cid)); |
1186 } | 1200 } |
1201 | |
1202 static void _html_result_event(GObject *object, GAsyncResult *result, gpointer script_data) | |
1203 { | |
1204 #if USE_WEBKIT2 | |
1205 WebKitJavascriptResult *js_result; | |
1206 JSCValue *value; | |
1207 GError *error = NULL; | |
1208 int (*htmlresultfunc)(HWND, int, char *, void *, void *) = NULL; | |
1209 gint handlerdata = GPOINTER_TO_INT(g_object_get_data(object, "_dw_html_result_id")); | |
1210 void *user_data = NULL; | |
1211 | |
1212 if(handlerdata) | |
1213 { | |
1214 SignalHandler work; | |
1215 void *params[3] = { GINT_TO_POINTER(handlerdata-1), 0, object }; | |
1216 | |
1217 work = _get_signal_handler(params); | |
1218 | |
1219 if(work.window) | |
1220 { | |
1221 htmlresultfunc = work.func; | |
1222 user_data = work.data; | |
1223 } | |
1224 } | |
1225 | |
1226 if(!(js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object), result, &error))) | |
1227 { | |
1228 if(htmlresultfunc) | |
1229 htmlresultfunc((HWND)object, DW_ERROR_UNKNOWN, error->message, user_data, script_data); | |
1230 g_error_free (error); | |
1231 return; | |
1232 } | |
1233 | |
1234 value = webkit_javascript_result_get_js_value(js_result); | |
1235 if(jsc_value_is_string(value)) | |
1236 { | |
1237 gchar *str_value = jsc_value_to_string(value); | |
1238 JSCException *exception = jsc_context_get_exception(jsc_value_get_context(value)); | |
1239 | |
1240 if(htmlresultfunc) | |
1241 { | |
1242 if(exception) | |
1243 htmlresultfunc((HWND)object, DW_ERROR_UNKNOWN, (char *)jsc_exception_get_message(exception), user_data, script_data); | |
1244 else | |
1245 htmlresultfunc((HWND)object, DW_ERROR_NONE, str_value, user_data, script_data); | |
1246 } | |
1247 g_free (str_value); | |
1248 } | |
1249 else if(htmlresultfunc) | |
1250 htmlresultfunc((HWND)object, DW_ERROR_UNKNOWN, "Unknown javascript error", user_data, script_data); | |
1251 webkit_javascript_result_unref (js_result); | |
1252 #endif | |
1253 } | |
1254 | |
1255 #ifdef USE_WEBKIT | |
1256 #ifdef USE_WEBKIT2 | |
1257 static void _html_changed_event(WebKitWebView *web_view, WebKitLoadEvent load_event, gpointer data) | |
1258 { | |
1259 SignalHandler work = _get_signal_handler(data); | |
1260 char *location = (char *)webkit_web_view_get_uri(web_view); | |
1261 int status = 0; | |
1262 | |
1263 switch (load_event) { | |
1264 case WEBKIT_LOAD_STARTED: | |
1265 status = DW_HTML_CHANGE_STARTED; | |
1266 break; | |
1267 case WEBKIT_LOAD_REDIRECTED: | |
1268 status = DW_HTML_CHANGE_REDIRECT; | |
1269 break; | |
1270 case WEBKIT_LOAD_COMMITTED: | |
1271 status = DW_HTML_CHANGE_LOADING; | |
1272 break; | |
1273 case WEBKIT_LOAD_FINISHED: | |
1274 status = DW_HTML_CHANGE_COMPLETE; | |
1275 break; | |
1276 } | |
1277 if(status && location && work.window && work.func) | |
1278 { | |
1279 int (*htmlchangedfunc)(HWND, int, char *, void *) = work.func; | |
1280 | |
1281 htmlchangedfunc(work.window, status, location, work.data); | |
1282 } | |
1283 } | |
1284 #else | |
1285 static void _html_changed_event(WebKitWebView *web_view, WebKitWebFrame *frame, gpointer data) | |
1286 { | |
1287 SignalHandler work = _get_signal_handler(data); | |
1288 char *location = (char *)webkit_web_view_get_uri(web_view); | |
1289 int status = 0; | |
1290 void **params = data; | |
1291 | |
1292 if(params) | |
1293 status = DW_POINTER_TO_INT(params[1]); | |
1294 | |
1295 if(status && location && work.window && work.func) | |
1296 { | |
1297 int (*htmlchangedfunc)(HWND, int, char *, void *) = work.func; | |
1298 | |
1299 htmlchangedfunc(work.window, status, location, work.data); | |
1300 } | |
1301 } | |
1302 #endif | |
1303 #endif | |
1187 | 1304 |
1188 static gint _set_focus_event(GtkWindow *window, GtkWidget *widget, gpointer data) | 1305 static gint _set_focus_event(GtkWindow *window, GtkWidget *widget, gpointer data) |
1189 { | 1306 { |
1190 SignalHandler work = _get_signal_handler(data); | 1307 SignalHandler work = _get_signal_handler(data); |
1191 int retval = FALSE; | 1308 int retval = FALSE; |
11300 case DW_HTML_PRINT: | 11417 case DW_HTML_PRINT: |
11301 { | 11418 { |
11302 #ifdef USE_WEBKIT2 | 11419 #ifdef USE_WEBKIT2 |
11303 WebKitPrintOperation *operation = webkit_print_operation_new(web_view); | 11420 WebKitPrintOperation *operation = webkit_print_operation_new(web_view); |
11304 webkit_print_operation_run_dialog(operation, NULL); | 11421 webkit_print_operation_run_dialog(operation, NULL); |
11422 g_object_unref(operation); | |
11305 #else | 11423 #else |
11306 WebKitWebFrame *frame = webkit_web_view_get_focused_frame(web_view); | 11424 WebKitWebFrame *frame = webkit_web_view_get_focused_frame(web_view); |
11307 webkit_web_frame_print(frame); | 11425 webkit_web_frame_print(frame); |
11308 #endif | 11426 #endif |
11309 } | 11427 } |
11369 #else | 11487 #else |
11370 webkit_web_view_open(web_view, url); | 11488 webkit_web_view_open(web_view, url); |
11371 #endif | 11489 #endif |
11372 gtk_widget_show(GTK_WIDGET(handle)); | 11490 gtk_widget_show(GTK_WIDGET(handle)); |
11373 } | 11491 } |
11492 DW_MUTEX_UNLOCK; | |
11493 return DW_ERROR_NONE; | |
11494 #else | |
11495 return DW_ERROR_UNKNOWN; | |
11496 #endif | |
11497 } | |
11498 | |
11499 /* | |
11500 * Executes the javascript contained in "script" in the HTML window. | |
11501 * Parameters: | |
11502 * handle: Handle to the HTML window. | |
11503 * script: Javascript code to execute. | |
11504 * scriptdata: Data passed to the signal handler. | |
11505 * Notes: A DW_SIGNAL_HTML_RESULT event will be raised with scriptdata. | |
11506 * Returns: | |
11507 * DW_ERROR_NONE (0) on success. | |
11508 */ | |
11509 int dw_html_javascript_run(HWND handle, char *script, void *scriptdata) | |
11510 { | |
11511 #ifdef USE_WEBKIT2 | |
11512 int _locked_by_me = FALSE; | |
11513 WebKitWebView *web_view; | |
11514 | |
11515 DW_MUTEX_LOCK; | |
11516 if((web_view = _dw_html_web_view(handle))) | |
11517 webkit_web_view_run_javascript (web_view, script, NULL, _html_result_event, scriptdata); | |
11374 DW_MUTEX_UNLOCK; | 11518 DW_MUTEX_UNLOCK; |
11375 return DW_ERROR_NONE; | 11519 return DW_ERROR_NONE; |
11376 #else | 11520 #else |
11377 return DW_ERROR_UNKNOWN; | 11521 return DW_ERROR_UNKNOWN; |
11378 #endif | 11522 #endif |
11900 { | 12044 { |
11901 thisname = "focus-in-event"; | 12045 thisname = "focus-in-event"; |
11902 if (GTK_IS_COMBO_BOX(thiswindow)) | 12046 if (GTK_IS_COMBO_BOX(thiswindow)) |
11903 thiswindow = gtk_bin_get_child(GTK_BIN(thiswindow)); | 12047 thiswindow = gtk_bin_get_child(GTK_BIN(thiswindow)); |
11904 } | 12048 } |
12049 #ifdef USE_WEBKIT | |
12050 else if (WEBKIT_IS_WEB_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_HTML_CHANGED) == 0) | |
12051 { | |
12052 #ifdef USE_WEBKIT2 | |
12053 thisname = "load-changed"; | |
12054 #else | |
12055 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc, discfunc); | |
12056 params[0] = GINT_TO_POINTER(sigid); | |
12057 params[1] = GINT_TO_POINTER(DW_HTML_CHANGE_STARTED); | |
12058 params[2] = (void *)thiswindow; | |
12059 cid = g_signal_connect_data(G_OBJECT(thiswindow), "load-started", G_CALLBACK(thisfunc), params, _dw_signal_disconnect, 0); | |
12060 _set_signal_handler_id(thiswindow, sigid, cid); | |
12061 | |
12062 params = calloc(sizeof(void *), 3); | |
12063 | |
12064 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc, discfunc); | |
12065 params[0] = GINT_TO_POINTER(sigid); | |
12066 params[1] = GINT_TO_POINTER(DW_HTML_CHANGE_LOADING); | |
12067 params[2] = (void *)thiswindow; | |
12068 cid = g_signal_connect_data(G_OBJECT(thiswindow), "load-committed", G_CALLBACK(thisfunc), params, _dw_signal_disconnect, 0); | |
12069 _set_signal_handler_id(thiswindow, sigid, cid); | |
12070 | |
12071 params = calloc(sizeof(void *), 3); | |
12072 params[1] = GINT_TO_POINTER(DW_HTML_CHANGE_COMPLETE); | |
12073 | |
12074 thisname = "load-finished"; | |
12075 #endif | |
12076 } | |
12077 else if (WEBKIT_IS_WEB_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_HTML_RESULT) == 0) | |
12078 { | |
12079 /* We don't actually need a signal handler here... just need to assign the handler ID | |
12080 * Since the handler is created in dw_html_javasript_run() | |
12081 */ | |
12082 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, _html_result_event, discfunc); | |
12083 g_object_set_data(G_OBJECT(thiswindow), "_dw_html_result_id", GINT_TO_POINTER(sigid+1)); | |
12084 DW_MUTEX_UNLOCK; | |
12085 return; | |
12086 } | |
12087 #endif | |
11905 #if 0 | 12088 #if 0 |
11906 else if (strcmp(signame, DW_SIGNAL_LOSE_FOCUS) == 0) | 12089 else if (strcmp(signame, DW_SIGNAL_LOSE_FOCUS) == 0) |
11907 { | 12090 { |
11908 thisname = "focus-out-event"; | 12091 thisname = "focus-out-event"; |
11909 if(GTK_IS_COMBO_BOX(thiswindow)) | 12092 if(GTK_IS_COMBO_BOX(thiswindow)) |