From 505ae08df2cf0e3de5271569586ae4592967d765 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 2 May 2016 10:24:49 +0100 Subject: [PATCH] update cocoa frontend to not use depricated warn_user API --- cocoa/BookmarksController.m | 2 +- cocoa/BrowserView.m | 6 ++-- cocoa/BrowserViewController.m | 4 +-- cocoa/BrowserWindowController.m | 2 +- cocoa/NetSurfAppDelegate.m | 8 ++--- cocoa/NetsurfApp.m | 2 +- cocoa/gui.h | 2 ++ cocoa/gui.m | 57 +++++++++++++++++++++------------ 8 files changed, 50 insertions(+), 33 deletions(-) diff --git a/cocoa/BookmarksController.m b/cocoa/BookmarksController.m index 4b15d3740..9aec9e534 100644 --- a/cocoa/BookmarksController.m +++ b/cocoa/BookmarksController.m @@ -162,7 +162,7 @@ static const char *cocoa_hotlist_path( void ) nsurl_unref(url); } if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } } diff --git a/cocoa/BrowserView.m b/cocoa/BrowserView.m index ceb21ef0c..4e34efa1f 100644 --- a/cocoa/BrowserView.m +++ b/cocoa/BrowserView.m @@ -587,7 +587,7 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) nsurl_unref(url); } if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } } @@ -607,7 +607,7 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) nsurl_unref(url); } if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } } @@ -678,7 +678,7 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) error = nsurl_create([urlstr UTF8String], &url); if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } else { browser_window_navigate(browser, url, diff --git a/cocoa/BrowserViewController.m b/cocoa/BrowserViewController.m index 559f99894..a951ce954 100644 --- a/cocoa/BrowserViewController.m +++ b/cocoa/BrowserViewController.m @@ -78,7 +78,7 @@ error = nsurl_create([url UTF8String], &urlns); if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } else { browser_window_navigate(browser, urlns, @@ -167,7 +167,7 @@ nsurl_unref(urlns); } if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } } diff --git a/cocoa/BrowserWindowController.m b/cocoa/BrowserWindowController.m index cfc45cd7c..686e37bbd 100644 --- a/cocoa/BrowserWindowController.m +++ b/cocoa/BrowserWindowController.m @@ -171,7 +171,7 @@ nsurl_unref(url); } if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } } diff --git a/cocoa/NetSurfAppDelegate.m b/cocoa/NetSurfAppDelegate.m index 34605a95c..afa25592b 100644 --- a/cocoa/NetSurfAppDelegate.m +++ b/cocoa/NetSurfAppDelegate.m @@ -60,7 +60,7 @@ nsurl_unref(url); } if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } } @@ -83,7 +83,7 @@ nsurl_unref(u); } if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } } } @@ -105,7 +105,7 @@ nsurl_unref(url); } if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } } @@ -188,7 +188,7 @@ nsurl_unref(url); } if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } return YES; diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index ec798be61..6fb856098 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -290,7 +290,7 @@ int main( int argc, char **argv ) nsurl_unref(url); } if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); + cocoa_warning(messages_get_errorcode(error), 0); } } diff --git a/cocoa/gui.h b/cocoa/gui.h index b0ff648f6..b34e9b702 100644 --- a/cocoa/gui.h +++ b/cocoa/gui.h @@ -31,3 +31,5 @@ extern NSString * const kAlwaysCancelDownload; extern NSString * const kAlwaysCloseMultipleTabs; void cocoa_autorelease( void ); + +nserror cocoa_warning(const char *warning, const char *detail); diff --git a/cocoa/gui.m b/cocoa/gui.m index 78b4147a6..afd4905be 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -52,13 +52,16 @@ NSString * const kAlwaysCloseMultipleTabs = @"AlwaysCloseMultipleTabs"; struct browser_window; -static nserror cocoa_warn_user(const char *warning, const char *detail) +/* exported function docuemnted in cocoa/gui.h */ +nserror cocoa_warning(const char *warning, const char *detail) { - NSRunAlertPanel( NSLocalizedString( @"Warning", @"Warning title" ), - NSLocalizedString( @"Warning %s%s%s", @"Warning message" ), - NSLocalizedString( @"OK", @"" ), nil, nil, - warning, detail != NULL ? ": " : "", - detail != NULL ? detail : "" ); + NSRunAlertPanel( NSLocalizedString( @"Warning", + @"Warning title" ), + NSLocalizedString( @"Warning %s%s%s", + @"Warning message" ), + NSLocalizedString( @"OK", @"" ), nil, nil, + warning, detail != NULL ? ": " : "", + detail != NULL ? detail : "" ); return NSERROR_OK; } @@ -69,13 +72,14 @@ gui_window_create(struct browser_window *bw, gui_window_create_flags flags) { BrowserWindowController *window = nil; + BrowserViewController *result; browser_window_set_scale(bw, (float)nsoption_int(scale) / 100, false); if (existing != NULL) { window = [(BrowserViewController *)(existing) windowController]; } - BrowserViewController *result = [[BrowserViewController alloc] initWithBrowser: bw]; + result = [[BrowserViewController alloc] initWithBrowser: bw]; if (!(flags & GW_CREATE_TAB) || nil == window) { window = [[[BrowserWindowController alloc] init] autorelease]; @@ -162,7 +166,8 @@ static void gui_window_update_extent(struct gui_window *g) browser_window_get_extents(browser, false, &width, &height); - [[window browserView] setMinimumSize: cocoa_scaled_size( browser_window_get_scale(browser), width, height )]; + [[window browserView] setMinimumSize: + cocoa_scaled_size( browser_window_get_scale(browser), width, height )]; } static void gui_window_set_status(struct gui_window *g, const char *text) @@ -205,7 +210,7 @@ static void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape static nserror gui_window_set_url(struct gui_window *g, struct nsurl *url) { - [(BrowserViewController *)g setUrl: [NSString stringWithUTF8String: nsurl_access(url)]]; + [(BrowserViewController *)g setUrl: [NSString stringWithUTF8String: nsurl_access(url)]]; return NSERROR_OK; } @@ -223,9 +228,13 @@ static void gui_window_stop_throbber(struct gui_window *g) static void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) { - NSBitmapImageRep *bmp = icon != NULL ? (NSBitmapImageRep *)content_get_bitmap( icon ) : NULL; - + NSBitmapImageRep *bmp = NULL; NSImage *image = nil; + + if (icon != NULL) { + bmp = (NSBitmapImageRep *)content_get_bitmap( icon ); + } + if (bmp != nil) { image = [[NSImage alloc] initWithSize: NSMakeSize( 32, 32 )]; [image addRepresentation: bmp]; @@ -238,11 +247,13 @@ static void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) [image release]; } -static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, - const struct rect *clip) +static void +gui_window_place_caret(struct gui_window *g, int x, int y, int height, + const struct rect *clip) { - [[(BrowserViewController *)g browserView] addCaretAt: cocoa_point( x, y ) - height: cocoa_px_to_pt( height )]; + [[(BrowserViewController *)g browserView] + addCaretAt: cocoa_point( x, y ) + height: cocoa_px_to_pt( height )]; } static void gui_window_remove_caret(struct gui_window *g) @@ -257,10 +268,12 @@ static void gui_window_new_content(struct gui_window *g) static void gui_create_form_select_menu(struct gui_window *g, - struct form_control *control) + struct form_control *control) { BrowserViewController * const window = (BrowserViewController *)g; - FormSelectMenu *menu = [[FormSelectMenu alloc] initWithControl: control forWindow: [window browser]]; + FormSelectMenu *menu = [[FormSelectMenu alloc] + initWithControl: control + forWindow: [window browser]]; [menu runInView: [window browserView]]; [menu release]; } @@ -273,9 +286,11 @@ static nserror gui_launch_url(nsurl *url) struct ssl_cert_info; -static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs, - unsigned long num, nserror (*cb)(bool proceed, void *pw), - void *cbpw) +static void +gui_cert_verify(nsurl *url, + const struct ssl_cert_info *certs, + unsigned long num, + nserror (*cb)(bool proceed,void *pw), void *cbpw) { cb( false, cbpw ); } @@ -310,7 +325,7 @@ struct gui_window_table *cocoa_window_table = &window_table; static struct gui_misc_table browser_table = { .schedule = cocoa_schedule, - .warning = cocoa_warn_user, + .warning = cocoa_warning, .launch_url = gui_launch_url, .cert_verify = gui_cert_verify,