Mercurial > dwindows
comparison mac/dw.m @ 2013:7303b35a9f4d
Mac: Added DW_SIGNAL_HTML support on Mac when using WKWebView.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 07 Nov 2019 07:00:32 +0000 |
parents | 75c6eb796e91 |
children | b1838dd5509a |
comparison
equal
deleted
inserted
replaced
2012:75c6eb796e91 | 2013:7303b35a9f4d |
---|---|
336 HMTX DWThreadMutex; | 336 HMTX DWThreadMutex; |
337 HMTX DWThreadMutex2; | 337 HMTX DWThreadMutex2; |
338 DWTID _dw_mutex_locked = (DWTID)-1; | 338 DWTID _dw_mutex_locked = (DWTID)-1; |
339 #endif | 339 #endif |
340 | 340 |
341 /* Apparently the WKWebKit API is only enabled on intel 64bit... | |
342 * Causing build failures on 32bit builds, so this should allow | |
343 * WKWebKit on intel 64 and the old WebKit on intel 32 bit and earlier. | |
344 */ | |
345 #if WK_API_ENABLED | |
346 #define DWWebView WKWebView | |
347 #else | |
348 #define DWWebView WebView | |
349 #endif | |
350 | |
351 unsigned long _colors[] = | 341 unsigned long _colors[] = |
352 { | 342 { |
353 0x00000000, /* 0 black */ | 343 0x00000000, /* 0 black */ |
354 0x000000bb, /* 1 red */ | 344 0x000000bb, /* 1 red */ |
355 0x0000bb00, /* 2 green */ | 345 0x0000bb00, /* 2 green */ |
516 char name[30]; | 506 char name[30]; |
517 | 507 |
518 } SignalList; | 508 } SignalList; |
519 | 509 |
520 /* List of signals */ | 510 /* List of signals */ |
521 #define SIGNALMAX 17 | 511 #define SIGNALMAX 19 |
522 | 512 |
523 SignalList SignalTranslate[SIGNALMAX] = { | 513 SignalList SignalTranslate[SIGNALMAX] = { |
524 { 1, DW_SIGNAL_CONFIGURE }, | 514 { 1, DW_SIGNAL_CONFIGURE }, |
525 { 2, DW_SIGNAL_KEY_PRESS }, | 515 { 2, DW_SIGNAL_KEY_PRESS }, |
526 { 3, DW_SIGNAL_BUTTON_PRESS }, | 516 { 3, DW_SIGNAL_BUTTON_PRESS }, |
535 { 12, DW_SIGNAL_ITEM_SELECT }, | 525 { 12, DW_SIGNAL_ITEM_SELECT }, |
536 { 13, DW_SIGNAL_SET_FOCUS }, | 526 { 13, DW_SIGNAL_SET_FOCUS }, |
537 { 14, DW_SIGNAL_VALUE_CHANGED }, | 527 { 14, DW_SIGNAL_VALUE_CHANGED }, |
538 { 15, DW_SIGNAL_SWITCH_PAGE }, | 528 { 15, DW_SIGNAL_SWITCH_PAGE }, |
539 { 16, DW_SIGNAL_TREE_EXPAND }, | 529 { 16, DW_SIGNAL_TREE_EXPAND }, |
540 { 17, DW_SIGNAL_COLUMN_CLICK } | 530 { 17, DW_SIGNAL_COLUMN_CLICK }, |
531 { 18, DW_SIGNAL_HTML_RESULT }, | |
532 { 19, DW_SIGNAL_HTML_CHANGED } | |
541 }; | 533 }; |
542 | 534 |
543 int _event_handler1(id object, NSEvent *event, int message) | 535 int _event_handler1(id object, NSEvent *event, int message) |
544 { | 536 { |
545 SignalHandler *handler = _get_handler(object, message); | 537 SignalHandler *handler = _get_handler(object, message); |
770 int (* API switchpagefunc)(HWND, unsigned long, void *) = (int (* API)(HWND, unsigned long, void *))handler->signalfunction; | 762 int (* API switchpagefunc)(HWND, unsigned long, void *) = (int (* API)(HWND, unsigned long, void *))handler->signalfunction; |
771 int pageid = DW_POINTER_TO_INT(event); | 763 int pageid = DW_POINTER_TO_INT(event); |
772 | 764 |
773 return switchpagefunc(handler->window, pageid, handler->data); | 765 return switchpagefunc(handler->window, pageid, handler->data); |
774 } | 766 } |
767 /* Tree expand event */ | |
775 case 16: | 768 case 16: |
776 { | 769 { |
777 int (* API treeexpandfunc)(HWND, HTREEITEM, void *) = (int (* API)(HWND, HTREEITEM, void *))handler->signalfunction; | 770 int (* API treeexpandfunc)(HWND, HTREEITEM, void *) = (int (* API)(HWND, HTREEITEM, void *))handler->signalfunction; |
778 | 771 |
779 return treeexpandfunc(handler->window, (HTREEITEM)event, handler->data); | 772 return treeexpandfunc(handler->window, (HTREEITEM)event, handler->data); |
780 } | 773 } |
774 /* Column click event */ | |
781 case 17: | 775 case 17: |
782 { | 776 { |
783 int (*clickcolumnfunc)(HWND, int, void *) = handler->signalfunction; | 777 int (* API clickcolumnfunc)(HWND, int, void *) = handler->signalfunction; |
784 int column_num = DW_POINTER_TO_INT(event); | 778 int column_num = DW_POINTER_TO_INT(event); |
785 | 779 |
786 return clickcolumnfunc(handler->window, column_num, handler->data); | 780 return clickcolumnfunc(handler->window, column_num, handler->data); |
781 } | |
782 /* HTML result event */ | |
783 case 18: | |
784 { | |
785 } | |
786 /* HTML changed event */ | |
787 case 19: | |
788 { | |
789 int (* API htmlchangedfunc)(HWND, int, char *, void *) = handler->signalfunction; | |
790 void **params = (void **)event; | |
791 NSString *uri = params[1]; | |
792 | |
793 return htmlchangedfunc(handler->window, DW_POINTER_TO_INT(params[0]), (char *)[uri UTF8String], handler->data); | |
787 } | 794 } |
788 } | 795 } |
789 } | 796 } |
790 return -1; | 797 return -1; |
791 } | 798 } |
1322 #endif | 1329 #endif |
1323 { | 1330 { |
1324 } | 1331 } |
1325 -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; | 1332 -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; |
1326 @end | 1333 @end |
1334 | |
1335 /* Apparently the WKWebKit API is only enabled on intel 64bit... | |
1336 * Causing build failures on 32bit builds, so this should allow | |
1337 * WKWebKit on intel 64 and the old WebKit on intel 32 bit and earlier. | |
1338 */ | |
1339 #if WK_API_ENABLED | |
1340 @interface DWWebView : WKWebView <WKNavigationDelegate> { } | |
1341 -(void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation; | |
1342 -(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation; | |
1343 -(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation; | |
1344 -(void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation; | |
1345 @end | |
1346 | |
1347 @implementation DWWebView : WKWebView { } | |
1348 -(void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation | |
1349 { | |
1350 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), [[self URL] absoluteString] }; | |
1351 _event_handler(self, (NSEvent *)params, 19); | |
1352 } | |
1353 -(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation | |
1354 { | |
1355 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), [[self URL] absoluteString] }; | |
1356 _event_handler(self, (NSEvent *)params, 19); | |
1357 } | |
1358 -(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation | |
1359 { | |
1360 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), [[self URL] absoluteString] }; | |
1361 _event_handler(self, (NSEvent *)params, 19); | |
1362 } | |
1363 -(void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation | |
1364 { | |
1365 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_REDIRECT), [[self URL] absoluteString] }; | |
1366 _event_handler(self, (NSEvent *)params, 19); | |
1367 } | |
1368 @end | |
1369 #else | |
1370 @interface DWWebView : WebView { } | |
1371 @end | |
1372 | |
1373 @implementation DWWebView : WebView { } | |
1374 @end | |
1375 #endif | |
1376 | |
1327 | 1377 |
1328 @implementation DWAppDel | 1378 @implementation DWAppDel |
1329 -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender | 1379 -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender |
1330 { | 1380 { |
1331 if(_event_handler(sender, nil, 6) > 0) | 1381 if(_event_handler(sender, nil, 6) > 0) |
8738 #if WK_API_ENABLED | 8788 #if WK_API_ENABLED |
8739 DWWebView *html = handle; | 8789 DWWebView *html = handle; |
8740 [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:nil]; | 8790 [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:nil]; |
8741 return DW_ERROR_NONE; | 8791 return DW_ERROR_NONE; |
8742 #else | 8792 #else |
8743 return DW_ERROR_UKNOWN; | 8793 return DW_ERROR_UNKNOWN; |
8744 #endif | 8794 #endif |
8745 } | 8795 } |
8746 | 8796 |
8747 /* | 8797 /* |
8748 * Create a new HTML window (widget) to be packed. | 8798 * Create a new HTML window (widget) to be packed. |
8756 DW_FUNCTION_RETURN(dw_html_new, HWND) | 8806 DW_FUNCTION_RETURN(dw_html_new, HWND) |
8757 DW_FUNCTION_RESTORE_PARAM1(__DW_UNUSED__ cid, ULONG) | 8807 DW_FUNCTION_RESTORE_PARAM1(__DW_UNUSED__ cid, ULONG) |
8758 { | 8808 { |
8759 DW_FUNCTION_INIT; | 8809 DW_FUNCTION_INIT; |
8760 DWWebView *web = [[DWWebView alloc] init]; | 8810 DWWebView *web = [[DWWebView alloc] init]; |
8811 #if WK_API_ENABLED | |
8812 web.navigationDelegate = web; | |
8813 #endif | |
8761 /* [web setTag:cid]; Why doesn't this work? */ | 8814 /* [web setTag:cid]; Why doesn't this work? */ |
8762 DW_FUNCTION_RETURN_THIS(web); | 8815 DW_FUNCTION_RETURN_THIS(web); |
8763 } | 8816 } |
8764 | 8817 |
8765 /* | 8818 /* |