comparison mac/dw.m @ 2014:b1838dd5509a

Mac: Added support on MacOS versions that only support WebView.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 07 Nov 2019 08:11:28 +0000
parents 7303b35a9f4d
children 59dfb86fb3b1
comparison
equal deleted inserted replaced
2013:7303b35a9f4d 2014:b1838dd5509a
780 return clickcolumnfunc(handler->window, column_num, handler->data); 780 return clickcolumnfunc(handler->window, column_num, handler->data);
781 } 781 }
782 /* HTML result event */ 782 /* HTML result event */
783 case 18: 783 case 18:
784 { 784 {
785 int (* API htmlresultfunc)(HWND, int, char *, void *, void *) = handler->signalfunction;
786 void **params = (void **)event;
787 NSString *result = params[0];
788
789 return htmlresultfunc(handler->window, [result length] ? DW_ERROR_NONE : DW_ERROR_UNKNOWN, [result length] ? (char *)[result UTF8String] : NULL, params[1], handler->data);
785 } 790 }
786 /* HTML changed event */ 791 /* HTML changed event */
787 case 19: 792 case 19:
788 { 793 {
789 int (* API htmlchangedfunc)(HWND, int, char *, void *) = handler->signalfunction; 794 int (* API htmlchangedfunc)(HWND, int, char *, void *) = handler->signalfunction;
1365 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_REDIRECT), [[self URL] absoluteString] }; 1370 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_REDIRECT), [[self URL] absoluteString] };
1366 _event_handler(self, (NSEvent *)params, 19); 1371 _event_handler(self, (NSEvent *)params, 19);
1367 } 1372 }
1368 @end 1373 @end
1369 #else 1374 #else
1370 @interface DWWebView : WebView { } 1375 @interface DWWebView : WebView
1376 { }
1377 -(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame;
1378 -(void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame;
1379 -(void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame;
1371 @end 1380 @end
1372 1381
1373 @implementation DWWebView : WebView { } 1382 @implementation DWWebView : WebView { }
1383 -(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
1384 {
1385 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), [self mainFrameURL] };
1386 _event_handler(self, (NSEvent *)params, 19);
1387 }
1388 -(void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame
1389 {
1390 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), [self mainFrameURL] };
1391 _event_handler(self, (NSEvent *)params, 19);
1392 }
1393 -(void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
1394 {
1395 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), [self mainFrameURL] };
1396 _event_handler(self, (NSEvent *)params, 19);
1397 }
1374 @end 1398 @end
1375 #endif 1399 #endif
1376 1400
1377 1401
1378 @implementation DWAppDel 1402 @implementation DWAppDel
8748 #if WK_API_ENABLED 8772 #if WK_API_ENABLED
8749 [html loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil]; 8773 [html loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil];
8750 #else 8774 #else
8751 [[html mainFrame] loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil]; 8775 [[html mainFrame] loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil];
8752 #endif 8776 #endif
8753 return 0; 8777 return DW_ERROR_NONE;
8754 } 8778 }
8755 8779
8756 /* 8780 /*
8757 * Render file or web page in the embedded HTML widget.. 8781 * Render file or web page in the embedded HTML widget..
8758 * Parameters: 8782 * Parameters:
8768 #if WK_API_ENABLED 8792 #if WK_API_ENABLED
8769 [html loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]]; 8793 [html loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]];
8770 #else 8794 #else
8771 [[html mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]]; 8795 [[html mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]];
8772 #endif 8796 #endif
8773 return 0; 8797 return DW_ERROR_NONE;
8774 } 8798 }
8775 8799
8776 /* 8800 /*
8777 * Executes the javascript contained in "script" in the HTML window. 8801 * Executes the javascript contained in "script" in the HTML window.
8778 * Parameters: 8802 * Parameters:
8783 * Returns: 8807 * Returns:
8784 * DW_ERROR_NONE (0) on success. 8808 * DW_ERROR_NONE (0) on success.
8785 */ 8809 */
8786 int dw_html_javascript_run(HWND handle, char *script, void *scriptdata) 8810 int dw_html_javascript_run(HWND handle, char *script, void *scriptdata)
8787 { 8811 {
8812 DWWebView *html = handle;
8813 DW_LOCAL_POOL_IN;
8814
8788 #if WK_API_ENABLED 8815 #if WK_API_ENABLED
8789 DWWebView *html = handle;
8790 [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:nil]; 8816 [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:nil];
8817 #else
8818 NSString *result = [html stringByEvaluatingJavaScriptFromString:[NSString stringWithUTF8String:script]];
8819 _event_handler(html, (NSEvent *)result, 18);
8820 #endif
8821 DW_LOCAL_POOL_OUT;
8791 return DW_ERROR_NONE; 8822 return DW_ERROR_NONE;
8792 #else
8793 return DW_ERROR_UNKNOWN;
8794 #endif
8795 } 8823 }
8796 8824
8797 /* 8825 /*
8798 * Create a new HTML window (widget) to be packed. 8826 * Create a new HTML window (widget) to be packed.
8799 * Not available under OS/2, eCS 8827 * Not available under OS/2, eCS
8808 { 8836 {
8809 DW_FUNCTION_INIT; 8837 DW_FUNCTION_INIT;
8810 DWWebView *web = [[DWWebView alloc] init]; 8838 DWWebView *web = [[DWWebView alloc] init];
8811 #if WK_API_ENABLED 8839 #if WK_API_ENABLED
8812 web.navigationDelegate = web; 8840 web.navigationDelegate = web;
8841 #else
8842 web.frameLoadDelegate = web;
8813 #endif 8843 #endif
8814 /* [web setTag:cid]; Why doesn't this work? */ 8844 /* [web setTag:cid]; Why doesn't this work? */
8815 DW_FUNCTION_RETURN_THIS(web); 8845 DW_FUNCTION_RETURN_THIS(web);
8816 } 8846 }
8817 8847